Java 类javax.swing.text.DefaultStyledDocument.ElementSpec 实例源码

项目:swingbox-javahelp-viewer    文件:ContentReader.java   
private void buildText(List<ElementSpec> elements, TextBox box)
{
    String text = box.getText();
    VisualContext vc = box.getVisualContext();
    MutableAttributeSet attr = new SimpleAttributeSet();

    attr.addAttribute(Constants.ATTRIBUTE_FONT_VARIANT, vc.getFontVariant());
    attr.addAttribute(Constants.ATTRIBUTE_TEXT_DECORATION, vc.getTextDecoration());
    attr.addAttribute(Constants.ATTRIBUTE_FONT, vc.getFont());
    attr.addAttribute(Constants.ATTRIBUTE_FOREGROUND, vc.getColor());

    attr.addAttribute(SwingBoxDocument.ElementNameAttribute, Constants.TEXT_BOX);
    attr.addAttribute(Constants.ATTRIBUTE_ANCHOR_REFERENCE, new Anchor());
    attr.addAttribute(Constants.ATTRIBUTE_BOX_REFERENCE, box);

    // elements.add(new ElementSpec(attr, ElementSpec.StartTagType));
    elements.add(new ElementSpec(attr, ElementSpec.ContentType, text.toCharArray(), 0, text.length()));
    // elements.add(new ElementSpec(attr, ElementSpec.EndTagType));

}
项目:swingbox-javahelp-viewer    文件:ContentReader.java   
private void buildInlineReplacedBox(List<ElementSpec> elements,
        InlineReplacedBox box)
{
    org.w3c.dom.Element elem = box.getElement();
    String text = "";
    // add some textual info, if picture
    if ("img".equalsIgnoreCase(elem.getTagName()))
    {
        text = " [" + elem.getAttribute("alt") + " Location: "
                + elem.getAttribute("src") + "] ";
    }

    MutableAttributeSet attr = new SimpleAttributeSet();
    attr.addAttribute(SwingBoxDocument.ElementNameAttribute,
            Constants.INLINE_REPLACED_BOX);
    attr.addAttribute(Constants.ATTRIBUTE_BOX_REFERENCE, box);
    attr.addAttribute(Constants.ATTRIBUTE_ANCHOR_REFERENCE, new Anchor());
    attr.addAttribute(Constants.ATTRIBUTE_REPLACED_CONTENT,
            box.getContentObj());

    elements.add(new ElementSpec(attr, ElementSpec.ContentType, text.toCharArray(), 0, text.length()));
}
项目:swingbox-javahelp-viewer    文件:ContentReader.java   
private void buildBlockReplacedBox(List<ElementSpec> elements, BlockReplacedBox box)
{
    // some content
    org.w3c.dom.Element elem = box.getElement();
    String text = "";
    // add some textual info, if picture
    if ("img".equalsIgnoreCase(elem.getTagName()))
    {
        text = " [" + elem.getAttribute("alt") + " Location: "
                + elem.getAttribute("src") + "] ";
    }

    MutableAttributeSet attr = new SimpleAttributeSet();
    attr.addAttribute(SwingBoxDocument.ElementNameAttribute, Constants.BLOCK_REPLACED_BOX);
    attr.addAttribute(Constants.ATTRIBUTE_BOX_REFERENCE, box);
    attr.addAttribute(Constants.ATTRIBUTE_ANCHOR_REFERENCE, new Anchor());
    attr.addAttribute(Constants.ATTRIBUTE_REPLACED_CONTENT,
            box.getContentObj());

    elements.add(new ElementSpec(attr, ElementSpec.ContentType, text.toCharArray(), 0, text.length()));
}
项目:swingbox-javahelp-viewer    文件:ContentReader.java   
private final void commonBuild(List<ElementSpec> elements, ElementBox box, Object elementNameValue)
{
    // when there are no special requirements to build an element, use this
    // one
    SimpleAttributeSet attr = new SimpleAttributeSet();
    attr.addAttribute(SwingBoxDocument.ElementNameAttribute,
            elementNameValue);
    attr.addAttribute(Constants.ATTRIBUTE_ANCHOR_REFERENCE, new Anchor());
    attr.addAttribute(Constants.ATTRIBUTE_BOX_REFERENCE, box);
    attr.addAttribute(Constants.ATTRIBUTE_ELEMENT_ID, box.getElement().getAttribute("id"));

    elements.add(new ElementSpec(attr, ElementSpec.StartTagType));

    buildElements(elements, box);

    elements.add(new ElementSpec(attr, ElementSpec.EndTagType));
}
项目:cn1    文件:HTMLDocument_ReaderTest.java   
public void testFlush_Insert_PushPopTag_Wierd() throws Exception {
    final String text = "tag";
    editable = false;
    SimpleAttributeSet attr = new SimpleAttributeSet();
    attr.addAttribute(StyleConstants.NameAttribute, Tag.CONTENT);
    reader = (HTMLReader)doc.getReader(1000, -15, 330, Tag.HTML);
    reader.parseBuffer.add(new ElementSpec(attr, ElementSpec.EndTagType));
    reader.parseBuffer.add(new ElementSpec(attr, ElementSpec.StartTagType));
    reader.parseBuffer.add(new ElementSpec(new SimpleAttributeSet(), ElementSpec.ContentType, text.toCharArray(), 0, 3));
    reader.parseBuffer.add(new ElementSpec(attr, ElementSpec.EndTagType));
    reader.parseBuffer.add(new ElementSpec(attr, ElementSpec.EndTagType));
    reader.parseBuffer.add(new ElementSpec(attr, ElementSpec.StartTagType));
    assertEquals(6, reader.parseBuffer.size());
    reader.flush();
    assertEquals(0, reader.parseBuffer.size());
    assertFalse(createMarker.isOccurred());
    assertTrue(insertMarker.isOccurred());
    assertEquals(6, ((ElementSpec[])insertMarker.getAuxiliary()).length);
}
项目:cn1    文件:HTMLDocument_ReaderTest.java   
public void testHTMLReaderIntIntIntTag_PushPopParameter_JoinPrevSpec5() throws Exception {
    final Tag[] tags = HTML.getAllTags();
    Tag[] oddTags;
    if (!isHarmony()) {
        oddTags = new Tag[] {Tag.AREA, Tag.BASE, Tag.MAP, Tag.OPTION, Tag.PARAM, Tag.STYLE};
    } else {
        oddTags = new Tag[] {Tag.AREA, Tag.APPLET, Tag.IFRAME, Tag.LEGEND, Tag.COL, Tag.COLGROUP, Tag.SCRIPT, Tag.BASE, Tag.MAP, Tag.OPTION, Tag.OPTGROUP, Tag.PARAM, Tag.STYLE};
    }

    for (int i = 0; i < tags.length; i++) {
        final Tag tag = tags[i];
        if (foundInArray(oddTags, tag)) {
            continue;
        }
        init();
        editable = false;
        HTMLReader reader = (HTMLReader)doc.getReader(0, 1, 0, tag);
        reader.handleStartTag(tag, new SimpleAttributeSet(), 0);
        assertTrue(tag.toString(), reader.parseBuffer.size() > 0);
        ElementSpec firstSpec = (ElementSpec)reader.parseBuffer.get(0);
        assertEquals(tag.toString(), ElementSpec.ContentType, firstSpec.getType());
        assertEquals(tag.toString(), ElementSpec.JoinPreviousDirection, firstSpec.getDirection());
        assertEquals(tag.toString(), '\n', firstSpec.getArray()[0]);
    }
}
项目:cn1    文件:DefaultStyledDocument_ElementBuffer_InsertNewLineTest.java   
/**
 * Inserting text with the same attributes into the beginning of
 * the document.
 * <p>
 * This test is equivalent to
 * <code>doc.insertString(insertOffset, newLine, null)</code>,
 * where <code>insertOffset = 0</code>.
 */
public void testInsertSameAttrsDocStart() throws Exception {
    insertOffset = 0;
    // doc.insertString(insertOffset, newLine, null);
    content.insertString(insertOffset, newLine);
    event = doc.new DefaultDocumentEvent(insertOffset, newLineLen, EventType.INSERT);
    ElementSpec[] specs = { new ElementSpec(null, ElementSpec.ContentType, newLineLen),
            new ElementSpec(null, ElementSpec.EndTagType),
            new ElementSpec(null, ElementSpec.StartTagType) };
    specs[0].setDirection(ElementSpec.JoinPreviousDirection);
    specs[2].setDirection(ElementSpec.JoinFractureDirection);
    buf.insert(insertOffset, newLineLen, specs, event);
    List<?> edits = getEdits(event);
    assertEquals(2, edits.size());
    assertChange(edits.get(0), new int[] { 0, 6, 6, 10, 10, 16, 16, 17 },
            new int[] { 0, 1 });
    assertChange(edits.get(1), new int[] {}, new int[] { 1, 17 });
    assertChildren(root.getElement(0), new int[] { 0, 1 }, new AttributeSet[] { null });
    assertChildren(root.getElement(1), new int[] { 1, 6, 6, 10, 10, 16, 16, 17 },
            new AttributeSet[] { null, bold, italic, null });
    assertEquals("\n", getText(doc.getCharacterElement(insertOffset)));
    assertEquals("plain", getText(doc.getCharacterElement(insertOffset + newLineLen)));
}
项目:cn1    文件:HTMLDocument_ReaderTest.java   
public void testAddContent_CharAttr() {
    String text = "data";
    assertEquals(0, reader.parseBuffer.size());
    final SimpleAttributeSet initialSet = new SimpleAttributeSet();
    initialSet.addAttribute("aaaa", "bbbb");
    reader.charAttr = initialSet; 
    reader.addContent(text.toCharArray(), 1, 3);
    assertEquals(2, reader.parseBuffer.size());
    ElementSpec spec = (ElementSpec)reader.parseBuffer.get(1);
    final AttributeSet specAttr = spec.getAttributes();
    assertEquals(2, specAttr.getAttributeCount());
    checkAttributes(specAttr, StyleConstants.NameAttribute, Tag.CONTENT);
    checkAttributes(specAttr, "aaaa", "bbbb");

    assertEquals(2, reader.charAttr.getAttributeCount());
    checkAttributes(reader.charAttr, StyleConstants.NameAttribute, Tag.CONTENT);
    checkAttributes(reader.charAttr, "aaaa", "bbbb");
    reader.charAttr = null;
    reader.popCharacterStyle();
    assertNull(reader.charAttr);
}
项目:cn1    文件:DefaultStyledDocument_ElementBuffer_Specs1Test.java   
/**
 * Bold attribute on character, text 'one' with italic, doc is empty.
 */
public void testInsertString51() throws Exception {
    doc.setCharacterAttributes(0, 1, bold, false);
    doc.insertString(0, "one", italic);
    List<?> edits = getEdits(insertEvent);
    assertEquals(2, edits.size());
    assertChange(edits.get(1), root.getElement(0), 1, 2);
    Element charElem = doc.getCharacterElement(0);
    assertTrue(charElem.getAttributes().isEqual(italic));
    charElem = doc.getCharacterElement(doc.getLength());
    assertTrue(charElem.getAttributes().isEqual(bold));
    assertEquals(1, specs.length);
    assertSpec(specs[0], ElementSpec.ContentType, ElementSpec.OriginateDirection, 0, 3);
    /*
     * createLeaf(paragraph[0, 4], , 0, 3)
     *      The word 'one'
     * createLeaf(paragraph[0, 4], bold=true , 3, 4)
     *      The attributed newline char
     */
}
项目:cn1    文件:DefaultStyledDocument_ElementBuffer_Specs1Test.java   
/**
 * Bold attribute on paragraph, text '\none' with no attributes, doc is
 * empty.
 */
public void testInsertString13() throws Exception {
    doc.setParagraphAttributes(0, 1, bold, false);
    doc.insertString(0, "\none", null);
    List<?> edits = getEdits(insertEvent);
    assertEquals(4, edits.size());
    assertChange(edits.get(1), root.getElement(0), 1, 1);
    assertChange(edits.get(2), root.getElement(1), 1, 1);
    assertChange(edits.get(3), root, 0, 1);
    assertTrue(root.getElement(0).getAttributes().containsAttributes(bold));
    assertTrue(root.getElement(1).getAttributes().containsAttributes(bold));
    assertEquals(4, specs.length);
    assertSpec(specs[0], ElementSpec.ContentType, ElementSpec.JoinPreviousDirection, 0, 1);
    assertSpec(specs[1], ElementSpec.EndTagType, ElementSpec.OriginateDirection, 0, 0);
    assertSpec(specs[2], ElementSpec.StartTagType, ElementSpec.JoinFractureDirection, 0, 0);
    assertSpec(specs[3], ElementSpec.ContentType, ElementSpec.JoinNextDirection, 0, 3);
}
项目:cn1    文件:HTMLDocument_ReaderTest.java   
public void testAddSpecialElement() {
    SimpleAttributeSet attr = new SimpleAttributeSet();
    attr.addAttribute("aaaa", "bbbb");
    reader.handleStartTag(Tag.P, attr, 0);
    assertEquals(1, reader.parseBuffer.size());
    assertEquals(0, reader.charAttr.getAttributeCount());
    assertFalse(createMarker.isOccurred());
    assertFalse(insertMarker.isOccurred());

    reader.addSpecialElement(Tag.HTML, attr);
    assertEquals(2, reader.parseBuffer.size());
    assertFalse(createMarker.isOccurred());
    assertFalse(insertMarker.isOccurred());
    ElementSpec spec = (ElementSpec)reader.parseBuffer.get(1);
    assertSpec(spec, ElementSpec.ContentType, ElementSpec.OriginateDirection, 0, new char[] {' '});
    AttributeSet specAttr = spec.getAttributes();
    assertEquals(2, specAttr.getAttributeCount());
    checkAttributes(specAttr, StyleConstants.NameAttribute, Tag.HTML);
    checkAttributes(specAttr, "aaaa", "bbbb");

    assertNotSame(specAttr, attr);
    assertEquals(2, attr.getAttributeCount());
    checkAttributes(attr, StyleConstants.NameAttribute, Tag.HTML);
    checkAttributes(attr, "aaaa", "bbbb");
}
项目:cn1    文件:DefaultStyledDocument_ElementBuffer_InsertTextTest.java   
/**
 * Inserting text into the start of a paragraph with the same attributes.
 * <p>
 * This test is equivalent to
 * <code>doc.insertString(insertOffset, caps, null)</code>,
 * where <code>insertOffset = paragraph.getEndOffset()</code>.
 */
public void testInsertSameAttrsParStart() throws Exception {
    insertOffset = paragraph.getEndOffset();
    // doc.insertString(insertOffset, caps, null);
    content.insertString(insertOffset, caps);
    event = doc.new DefaultDocumentEvent(insertOffset, capsLen, EventType.INSERT);
    ElementSpec[] specs = { new ElementSpec(null, ElementSpec.EndTagType),
            new ElementSpec(null, ElementSpec.StartTagType),
            new ElementSpec(null, ElementSpec.ContentType, capsLen), };
    specs[1].setDirection(ElementSpec.JoinNextDirection);
    specs[2].setDirection(ElementSpec.JoinNextDirection);
    buf.insert(insertOffset, capsLen, specs, event);
    List<?> edits = getEdits(event);
    assertEquals(2, edits.size());
    assertChange(edits.get(0), new int[] { 15, 19 }, new int[] { 15, 16 });
    assertChange(edits.get(1), new int[] { 19, 24 }, new int[] { 16, 24 });
    assertChildren(paragraph, new int[] { 0, 5, 5, 9, 9, 15, 15, 16 }, new AttributeSet[] {
            null, bold, italic, null });
    assertChildren(root.getElement(1), new int[] { 16, 24 }, new AttributeSet[] { null });
    assertEquals("^^^text\n", getText(doc.getCharacterElement(insertOffset)));
}
项目:cn1    文件:DefaultStyledDocument_ElementBuffer_InsertTextTest.java   
/**
 * Inserting text into the start of a paragraph with different attributes.
 * <p>
 * This test is equivalent to
 * <code>doc.insertString(insertOffset, caps, italic)</code>,
 * where <code>insertOffset = paragraph.getEndOffset()</code>.
 */
public void testInsertDiffAttrsParStart() throws Exception {
    insertOffset = paragraph.getEndOffset();
    // doc.insertString(insertOffset, caps, italic);
    content.insertString(insertOffset, caps);
    event = doc.new DefaultDocumentEvent(insertOffset, capsLen, EventType.INSERT);
    ElementSpec[] specs = { new ElementSpec(null, ElementSpec.EndTagType),
            new ElementSpec(null, ElementSpec.StartTagType),
            new ElementSpec(italic, ElementSpec.ContentType, capsLen), };
    specs[1].setDirection(ElementSpec.JoinNextDirection);
    buf.insert(insertOffset, capsLen, specs, event);
    List<?> edits = getEdits(event);
    assertEquals(2, edits.size());
    assertChange(edits.get(0), new int[] { 15, 19 }, new int[] { 15, 16 });
    assertChange(edits.get(1), new int[] {}, new int[] { 16, 19 });
    assertChildren(paragraph, new int[] { 0, 5, 5, 9, 9, 15, 15, 16 }, new AttributeSet[] {
            null, bold, italic, null });
    assertChildren(root.getElement(1), new int[] { 16, 19, 19, 24 }, new AttributeSet[] {
            italic, null });
    assertEquals("^^^", getText(doc.getCharacterElement(insertOffset)));
    assertEquals("text\n", getText(doc.getCharacterElement(insertOffset + capsLen)));
}
项目:cn1    文件:HTMLDocument_ReaderTest.java   
public void testHTMLReaderIntIntIntTag_PushPopParameter_BlockParagraph() throws Exception {
    // trailing specs cutting for block and paragraph tags
    if (!isHarmony()) { 
        return;
    }
    final String str = "<P>link</P>";
    init();
    editable = false;
    ParserCallback reader = doc.getReader(0, 2, 3, Tag.P);
    SimpleAttributeSet attr = new SimpleAttributeSet();
    attr.addAttribute(StyleConstants.NameAttribute, Tag.S.toString());
    doc.insertString(0, "0000", attr);
    assertFalse(insertMarker.isOccurred());
    parse(str, reader);
    reader.flush();
    assertTrue(insertMarker.isOccurred());
    ElementSpec[] specs = (ElementSpec[])insertMarker.getAuxiliary();
    String specsDescr = "cpeoeosnsnsnsoco";
    assertEquals(specsDescr.length()/2, specs.length);
    insertMarker.reset();
    for (int i = 0; i < specs.length; i++) {
        checkSpecType(specsDescr, i, (ElementSpec)specs[i]);
    }
}
项目:cn1    文件:DefaultStyledDocument_ElementBuffer_InsertNewLineTest.java   
/**
 * Inserting text into the start of a paragraph with different attributes.
 * <p>
 * This test is equivalent to
 * <code>doc.insertString(insertOffset, newLine, italic)</code>,
 * where <code>insertOffset = paragraph.getEndOffset()</code>.
 */
public void testInsertDiffAttrsParStart() throws Exception {
    insertOffset = paragraph.getEndOffset();
    // doc.insertString(insertOffset, newLine, italic);
    content.insertString(insertOffset, newLine);
    event = doc.new DefaultDocumentEvent(insertOffset, newLineLen, EventType.INSERT);
    ElementSpec[] specs = { new ElementSpec(null, ElementSpec.EndTagType),
            new ElementSpec(null, ElementSpec.StartTagType),
            new ElementSpec(italic, ElementSpec.ContentType, newLineLen),
            new ElementSpec(null, ElementSpec.EndTagType),
            new ElementSpec(null, ElementSpec.StartTagType) };
    specs[4].setDirection(ElementSpec.JoinNextDirection);
    buf.insert(insertOffset, newLineLen, specs, event);
    List<?> edits = getEdits(event);
    assertEquals(3, edits.size());
    assertChange(edits.get(0), new int[] { 15, 17 }, new int[] { 15, 16 });
    assertChange(edits.get(1), new int[] {}, new int[] { 16, 17 });
    assertChange(edits.get(2), new int[] {}, new int[] { 16, 17 });
    assertChildren(root.getElement(0), new int[] { 0, 5, 5, 9, 9, 15, 15, 16 },
            new AttributeSet[] { null, bold, italic, null });
    assertChildren(root.getElement(1), new int[] { 16, 17 }, new AttributeSet[] { italic });
    assertChildren(root.getElement(2), new int[] { 17, 22 }, new AttributeSet[] { null });
    assertEquals("\n", getText(doc.getCharacterElement(insertOffset)));
    assertEquals("text\n", getText(doc.getCharacterElement(insertOffset + newLineLen)));
}
项目:cn1    文件:DefaultStyledDocument_ElementBuffer_InsertNewLineTest.java   
/**
 * Inserting text into middle of an element with the same attributes.
 * <p>
 * This test is equivalent to
 * <code>doc.insertString(insertOffset, newLine, bold)</code>,
 * where <code>insertOffset</code> has default value from
 * <code>setUp()</code>.
 */
public void testInsertSameAttrsMiddle() throws Exception {
    // doc.insertString(insertOffset, newLine, bold);
    content.insertString(insertOffset, newLine);
    event = doc.new DefaultDocumentEvent(insertOffset, newLineLen, EventType.INSERT);
    ElementSpec[] specs = { new ElementSpec(null, ElementSpec.ContentType, newLineLen),
            new ElementSpec(null, ElementSpec.EndTagType),
            new ElementSpec(null, ElementSpec.StartTagType) };
    specs[0].setDirection(ElementSpec.JoinPreviousDirection);
    specs[2].setDirection(ElementSpec.JoinFractureDirection);
    buf.insert(insertOffset, newLineLen, specs, event);
    List<?> edits = getEdits(event);
    assertEquals(2, edits.size());
    assertChange(edits.get(0), new int[] { 5, 10, 10, 16, 16, 17 }, new int[] { 5, 8 });
    assertChange(edits.get(1), new int[] {}, new int[] { 8, 17 });
    assertChildren(root.getElement(0), new int[] { 0, 5, 5, 8 }, new AttributeSet[] { null,
            bold });
    assertChildren(root.getElement(1), new int[] { 8, 10, 10, 16, 16, 17 },
            new AttributeSet[] { bold, italic, null });
    assertEquals("bo\n", getText(doc.getCharacterElement(insertOffset)));
    assertEquals("ld", getText(doc.getCharacterElement(insertOffset + newLineLen)));
}
项目:cn1    文件:DefaultStyledDocument_ElementBuffer_InsertNewLineTest.java   
/**
 * Inserting text into end of the an element with the same attributes;
 * the following element has different attributes.
 * <p>
 * This test is equivalent to
 * <code>doc.insertString(insertOffset, newLine, bold)</code>,
 * where 2 is added to default value of <code>insertOffset</code>.
 */
public void testInsertSameAttrsEnd() throws Exception {
    insertOffset += 2;
    // doc.insertString(insertOffset, newLine, bold);
    content.insertString(insertOffset, newLine);
    event = doc.new DefaultDocumentEvent(insertOffset, newLineLen, EventType.INSERT);
    ElementSpec[] specs = { new ElementSpec(null, ElementSpec.ContentType, newLineLen),
            new ElementSpec(null, ElementSpec.EndTagType),
            new ElementSpec(null, ElementSpec.StartTagType) };
    specs[0].setDirection(ElementSpec.JoinPreviousDirection);
    specs[2].setDirection(ElementSpec.JoinFractureDirection);
    // Spec [0] has wrong attributes (should be bold) but everything works
    // the way it supposed to.
    buf.insert(insertOffset, newLineLen, specs, event);
    List<?> edits = getEdits(event);
    assertEquals(2, edits.size());
    assertChange(edits.get(0), new int[] { 10, 16, 16, 17 }, new int[] {});
    assertChange(edits.get(1), new int[] {}, new int[] { 10, 17 });
    assertChildren(root.getElement(0), new int[] { 0, 5, 5, 10 }, new AttributeSet[] {
            null, bold });
    assertChildren(root.getElement(1), new int[] { 10, 16, 16, 17 }, new AttributeSet[] {
            italic, null });
    assertEquals("bold\n", getText(doc.getCharacterElement(insertOffset)));
    assertEquals("italic", getText(doc.getCharacterElement(insertOffset + newLineLen)));
}
项目:cn1    文件:DefaultStyledDocument_ElementBuffer_Specs3Test.java   
/**
 * Puts 'one\ntwo' with bold attributes (the same as in the portion
 * where text is inserted).
 */
public void testInsertString05() throws Exception {
    doc.insertString(insertOffset, "one\ntwo", bold);
    List<?> edits = getEdits(insertEvent);
    assertEquals(4, edits.size());
    assertChange(edits.get(1), root.getElement(0), 3, 1);
    assertChange(edits.get(2), root.getElement(1), 1, 1);
    assertChange(edits.get(3), root, 0, 1);
    assertEquals(4, specs.length);
    assertSpec(specs[0], ElementSpec.ContentType, ElementSpec.JoinPreviousDirection, 0, 4);
    assertSpec(specs[1], ElementSpec.EndTagType, ElementSpec.OriginateDirection, 0, 0);
    assertSpec(specs[2], ElementSpec.StartTagType, ElementSpec.JoinFractureDirection, 0, 0);
    assertSpec(specs[3], ElementSpec.ContentType, ElementSpec.JoinNextDirection, 0, 3);
    // These actions are performed:
    //      createLeaf(paragraph[0, 23], bold=true , 5, 11)
    //      createBranch(section[0, 23], resolver=**AttributeSet** )
    //      createLeaf(paragraph[N/A], bold=true , 14, 16)
    //      createLeaf(paragraph[N/A], italic=true , 16, 22)
    //      createLeaf(paragraph[N/A], , 22, 23)
    //      createLeaf(paragraph[14, 23], bold=true , 11, 16)
}
项目:cn1    文件:DefaultStyledDocument_ElementBuffer_Specs1Test.java   
/**
 * Bold attribute on paragraph, text 'one\ntwo' with no attributes, doc is
 * empty.
 */
public void testInsertString14() throws Exception {
    doc.setParagraphAttributes(0, 1, bold, false);
    doc.insertString(0, "one\ntwo", null);
    List<?> edits = getEdits(insertEvent);
    assertEquals(4, edits.size());
    assertChange(edits.get(1), root.getElement(0), 1, 1);
    assertChange(edits.get(2), root.getElement(1), 1, 1);
    assertChange(edits.get(3), root, 0, 1);
    assertTrue(root.getElement(0).getAttributes().containsAttributes(bold));
    assertTrue(root.getElement(1).getAttributes().containsAttributes(bold));
    assertEquals(4, specs.length);
    assertSpec(specs[0], ElementSpec.ContentType, ElementSpec.JoinPreviousDirection, 0, 4);
    assertSpec(specs[1], ElementSpec.EndTagType, ElementSpec.OriginateDirection, 0, 0);
    assertSpec(specs[2], ElementSpec.StartTagType, ElementSpec.JoinFractureDirection, 0, 0);
    assertSpec(specs[3], ElementSpec.ContentType, ElementSpec.JoinNextDirection, 0, 3);
}
项目:cn1    文件:HTMLDocument_ReaderTest.java   
private void checkConstructorTagParameter(final Tag tag, final String str, final int numSpecs) throws Exception {
    init();
    editable = false;
    ParserCallback reader = doc.getReader(0, 0, 0, tag);
    SimpleAttributeSet attr = new SimpleAttributeSet();
    attr.addAttribute(StyleConstants.NameAttribute, Tag.B.toString());
    doc.insertString(0, "0000", attr);
    assertFalse("no inserts", insertMarker.isOccurred());
    parse(str, reader);
    reader.flush();
    if (numSpecs == 0 && isHarmony()) {
        assertFalse("inserted", insertMarker.isOccurred());
    } else {
        assertTrue("inserted", insertMarker.isOccurred());
        ElementSpec[] specs = (ElementSpec[])insertMarker.getAuxiliary();
        assertEquals("number of specs inserted", numSpecs, specs.length);
        insertMarker.reset();
    }
}
项目:cn1    文件:DefaultStyledDocumentRTest.java   
public void testDeepTreeInsert02() throws Exception {
    initStructure();
    ElementSpec[] specs = { new ElementSpec(null, ElementSpec.EndTagType), // 0
            new ElementSpec(null, ElementSpec.EndTagType), // 1
            new ElementSpec(null, ElementSpec.StartTagType), // 2
            new ElementSpec(null, ElementSpec.StartTagType), // 3
            new ElementSpec(null, ElementSpec.ContentType, // 4
                    "^".toCharArray(), 0, 1), };
    specs[2].setDirection(ElementSpec.JoinNextDirection);
    specs[3].setDirection(ElementSpec.JoinNextDirection);
    doc.insert(1, specs);
    final Element html = doc.getDefaultRootElement();
    assertEquals(2, html.getElementCount());
    final Element head = html.getElement(0);
    assertEquals(1, head.getElementCount());
    Element p = head.getElement(0);
    assertChildren(p, new int[] { 0, 1 });
    final Element body = html.getElement(1);
    assertEquals(1, body.getElementCount());
    p = body.getElement(0);
    assertEquals("p1", p.getName());
    assertChildren(p, new int[] { 1, 2, 2, 6, 6, 7 });
}
项目:cn1    文件:DefaultStyledDocumentRTest.java   
public void testDeepTreeInsertSpecs() throws Exception {
    initStructure();
    ElementSpec[] specs = {
            new ElementSpec(null, ElementSpec.ContentType, "\n".toCharArray(), 0, 1),
            new ElementSpec(null, ElementSpec.EndTagType),
            new ElementSpec(null, ElementSpec.EndTagType), };
    doc.insert(0, specs);
    final Element html = doc.getDefaultRootElement();
    assertEquals(2, html.getElementCount());
    final Element head = html.getElement(0);
    assertEquals(1, head.getElementCount());
    Element p = head.getElement(0);
    assertChildren(p, new int[] { 0, 1, 1, 2 });
    assertEquals("\n\n", doc.getText(0, 2));
    final Element body = html.getElement(1);
    assertEquals(1, body.getElementCount());
    p = body.getElement(0);
    assertEquals("p1", p.getName());
    assertChildren(p, new int[] { 2, 6, 6, 7 });
}
项目:cn1    文件:DefaultStyledDocumentRTest.java   
public void testHTMLInsert() throws Exception {
    createEmptyHTMLStructure();
    doc.insertString(0, "0000", DefStyledDoc_Helpers.bold);
    ElementSpec[] specs = { new ElementSpec(null, ElementSpec.EndTagType),
            new ElementSpec(null, ElementSpec.ContentType, "^^^^".toCharArray(), 0, 4), };
    doc.insert(0, specs);
    final Element html = doc.getDefaultRootElement();
    assertEquals(1, html.getElementCount());
    final Element body = html.getElement(0);
    assertEquals(2, body.getElementCount());
    Element child = body.getElement(0);
    assertEquals("content", child.getName());
    assertTrue(child.isLeaf());
    child = body.getElement(1);
    assertEquals("p", child.getName());
    assertChildren(child, new int[] { 4, 8, 8, 9 });
}
项目:cn1    文件:DefaultStyledDocument_ElementBuffer_Specs1Test.java   
/**
 * No attributes, text 'one\n' with italic, doc is empty.
 */
public void testInsertString32() throws Exception {
    doc.insertString(0, "one\n", italic);
    List<?> edits = getEdits(insertEvent);
    assertEquals(3, edits.size());
    assertChange(edits.get(1), root.getElement(0), 1, 1);
    assertChange(edits.get(2), root, 0, 1);
    Element charElem = doc.getCharacterElement(0);
    assertTrue(charElem.getAttributes().isEqual(italic));
    assertEquals(0, charElem.getStartOffset());
    assertEquals(4, charElem.getEndOffset());
    charElem = doc.getCharacterElement(doc.getLength());
    assertEquals(0, charElem.getAttributes().getAttributeCount());
    assertEquals(4, charElem.getStartOffset());
    assertEquals(5, charElem.getEndOffset());
    assertEquals(3, specs.length);
    assertSpec(specs[0], ElementSpec.ContentType, ElementSpec.OriginateDirection, 0, 4);
    assertSpec(specs[1], ElementSpec.EndTagType, ElementSpec.OriginateDirection, 0, 0);
    assertSpec(specs[2], ElementSpec.StartTagType, ElementSpec.JoinFractureDirection, 0, 0);
}
项目:cn1    文件:HTMLDocument_ReaderTest.java   
public void testHandleText() throws Exception {
    String text = "data";
    reader.handleText(text.toCharArray(), 0);
    assertEquals(0, reader.charAttr.getAttributeCount());
    assertEquals(0, reader.parseBuffer.size());
    assertFalse(createMarker.isOccurred());
    assertFalse(insertMarker.isOccurred());

    reader.handleStartTag(Tag.P, new SimpleAttributeSet(), 0);
    assertEquals(0, reader.charAttr.getAttributeCount());
    assertEquals(1, reader.parseBuffer.size());
    reader.handleText(text.toCharArray(), 0);
    assertEquals(1, reader.charAttr.getAttributeCount());
    checkAttributes(reader.charAttr, StyleConstants.NameAttribute, Tag.CONTENT);
    assertEquals(2, reader.parseBuffer.size());
    ElementSpec spec = (ElementSpec)reader.parseBuffer.get(1);
    assertSpec(spec, ElementSpec.ContentType, ElementSpec.OriginateDirection, 0, text.toCharArray());
    final AttributeSet specAttr = spec.getAttributes();
    assertEquals(1, specAttr.getAttributeCount());
    checkAttributes(specAttr, StyleConstants.NameAttribute, Tag.CONTENT);
    assertFalse(createMarker.isOccurred());
    assertFalse(insertMarker.isOccurred());
}
项目:cn1    文件:HTMLDocument_ReaderTest.java   
public void testFlush_Insert_Offset() throws Exception {
    final String text = "tag";
    final String initialText = "text";
    reader = (HTMLReader)doc.getReader(initialText.length());
    doc.insertString(0, initialText, new SimpleAttributeSet());
    SimpleAttributeSet attr = new SimpleAttributeSet();
    attr.addAttribute(StyleConstants.NameAttribute, Tag.B.toString());
    reader.parseBuffer.add(new ElementSpec(attr, ElementSpec.StartTagType));
    reader.parseBuffer.add(new ElementSpec(new SimpleAttributeSet(), ElementSpec.ContentType, text.toCharArray(), 0, 3));
    reader.parseBuffer.add(new ElementSpec(attr, ElementSpec.EndTagType));
    assertEquals(3, reader.parseBuffer.size());
    reader.flush();
    assertEquals(0, reader.parseBuffer.size());
    assertFalse(createMarker.isOccurred());
    assertTrue(insertMarker.isOccurred());
    assertEquals(3, ((ElementSpec[])insertMarker.getAuxiliary()).length);
    assertEquals(initialText + text, doc.getText(0, doc.getLength()));
}
项目:cn1    文件:DefaultStyledDocument_ElementBuffer_InsertNewLineTest.java   
/**
 * Inserting text into the middle of an element with different attributes.
 * <p>
 * This test is equivalent to
 * <code>doc.insertString(insertOffset, newLine, null)</code>,
 * where <code>insertOffset</code> has default value from
 * <code>setUp()</code>.
 */
public void testInsertDiffAttrsMiddle() throws Exception {
    // doc.insertString(insertOffset, newLine, null);
    content.insertString(insertOffset, newLine);
    event = doc.new DefaultDocumentEvent(insertOffset, newLineLen, EventType.INSERT);
    ElementSpec[] specs = { new ElementSpec(null, ElementSpec.ContentType, newLineLen),
            new ElementSpec(null, ElementSpec.EndTagType),
            new ElementSpec(null, ElementSpec.StartTagType) };
    specs[2].setDirection(ElementSpec.JoinFractureDirection);
    buf.insert(insertOffset, newLineLen, specs, event);
    List<?> edits = getEdits(event);
    assertEquals(2, edits.size());
    assertChange(edits.get(0), new int[] { 5, 10, 10, 16, 16, 17 },
            new int[] { 5, 7, 7, 8 });
    assertChange(edits.get(1), new int[] {}, new int[] { 8, 17 });
    assertChildren(root.getElement(0), new int[] { 0, 5, 5, 7, 7, 8 }, new AttributeSet[] {
            null, bold, null });
    assertChildren(root.getElement(1), new int[] { 8, 10, 10, 16, 16, 17 },
            new AttributeSet[] { bold, italic, null });
    assertEquals("\n", getText(doc.getCharacterElement(insertOffset)));
    assertEquals("ld", getText(doc.getCharacterElement(insertOffset + newLineLen)));
}
项目:cn1    文件:HTMLDocument_ReaderTest.java   
public void testFlush_Insert_PushPopTag() throws Exception {
    final String text = "tag";
    editable = false;
    SimpleAttributeSet attr = new SimpleAttributeSet();
    attr.addAttribute(StyleConstants.NameAttribute, Tag.B);
    reader = (HTMLReader)doc.getReader(0, 15, 33, Tag.B);
    reader.parseBuffer.add(new ElementSpec(attr, ElementSpec.StartTagType));
    reader.parseBuffer.add(new ElementSpec(new SimpleAttributeSet(), ElementSpec.ContentType, text.toCharArray(), 0, 3));
    reader.parseBuffer.add(new ElementSpec(attr, ElementSpec.EndTagType));
    assertEquals(3, reader.parseBuffer.size());
    reader.flush();
    assertEquals(0, reader.parseBuffer.size());
    assertFalse(createMarker.isOccurred());
    assertTrue(insertMarker.isOccurred());
    assertEquals(3, ((ElementSpec[])insertMarker.getAuxiliary()).length);
}
项目:cn1    文件:DefaultStyledDocument_ElementBuffer_InsertNewLineTest.java   
/**
 * Inserting text into element boundary; the attributes of the text and
 * the following element are the same, the attributes of the previous
 * element are different.
 * <p>
 * This test is equivalent to
 * <code>doc.insertString(insertOffset, newLine, italic)</code>,
 * where 2 is added to default value of <code>insertOffset</code>.
 */
public void testInsertDiffSameAttrsEnd() throws Exception {
    insertOffset += 2;
    // doc.insertString(insertOffset, newLine, italic);
    content.insertString(insertOffset, newLine);
    event = doc.new DefaultDocumentEvent(insertOffset, newLineLen, EventType.INSERT);
    ElementSpec[] specs = { new ElementSpec(italic, ElementSpec.ContentType, newLineLen),
            new ElementSpec(null, ElementSpec.EndTagType),
            new ElementSpec(null, ElementSpec.StartTagType) };
    specs[2].setDirection(ElementSpec.JoinFractureDirection);
    buf.insert(insertOffset, newLineLen, specs, event);
    List<?> edits = getEdits(event);
    assertEquals(2, edits.size());
    assertChange(edits.get(0), new int[] { 5, 10, 10, 16, 16, 17 },
            new int[] { 5, 9, 9, 10 });
    assertChange(edits.get(1), new int[] {}, new int[] { 10, 17 });
    assertChildren(root.getElement(0), new int[] { 0, 5, 5, 9, 9, 10 }, new AttributeSet[] {
            null, bold, italic });
    assertChildren(root.getElement(1), new int[] { 10, 16, 16, 17 }, new AttributeSet[] {
            italic, null });
    assertEquals("\n", getText(doc.getCharacterElement(insertOffset)));
    assertEquals("italic", getText(doc.getCharacterElement(insertOffset + newLineLen)));
}
项目:cn1    文件:DefaultStyledDocument_ElementBuffer_Specs2Test.java   
/**
 * No attributes, text '\none' with italic, doc is empty.
 */
public void testInsertString33() throws Exception {
    doc.insertString(insertOffset, "\none", italic);
    List<?> edits = getEdits(insertEvent);
    assertEquals(4, edits.size());
    assertSame(modified, root.getElement(modifiedIndex));
    assertChange(edits.get(1), root.getElement(modifiedIndex), 1, 2);
    assertChange(edits.get(2), root.getElement(modifiedIndex + 1), 0, 1);
    assertChange(edits.get(3), root, 0, 1);
    assertEquals(2, modified.getElementCount());
    assertEquals(0, modified.getElement(0).getAttributes().getAttributeCount());
    final Element charElem = modified.getElement(1);
    assertTrue(charElem.getAttributes().isEqual(italic));
    assertEquals(1, charElem.getEndOffset() - charElem.getStartOffset());
    final Element newPar = root.getElement(modifiedIndex + 1);
    assertEquals(2, newPar.getElementCount());
    assertTrue(newPar.getElement(0).getAttributes().isEqual(italic));
    assertEquals(0, newPar.getElement(1).getAttributes().getAttributeCount());
    assertEquals(4, specs.length);
    assertSpec(specs[0], ElementSpec.ContentType, ElementSpec.OriginateDirection, 0, 1);
    assertSpec(specs[1], ElementSpec.EndTagType, ElementSpec.OriginateDirection, 0, 0);
    assertSpec(specs[2], ElementSpec.StartTagType, ElementSpec.JoinFractureDirection, 0, 0);
    assertSpec(specs[3], ElementSpec.ContentType, ElementSpec.OriginateDirection, 0, 3);
}
项目:cn1    文件:HTMLDocument_Reader_ActionsTest.java   
public void testHiddenEnd() {
    SimpleAttributeSet attr = new SimpleAttributeSet();
    attr.addAttribute("aaaa", "bbbb");
    action = reader.new HiddenAction();

    action.start(Tag.SCRIPT, attr);
    assertEquals(0, reader.charAttr.getAttributeCount());
    assertEquals(2, reader.parseBuffer.size());
    action.end(Tag.SCRIPT);
    assertEquals(0, reader.charAttr.getAttributeCount());
    assertEquals(3, reader.parseBuffer.size());

    ElementSpec spec = (ElementSpec)reader.parseBuffer.get(2);
    AttributeSet specAttr = spec.getAttributes();
    assertEquals(2, specAttr.getAttributeCount());
    checkAttributes(specAttr, StyleConstants.NameAttribute, Tag.SCRIPT);
    checkAttributes(specAttr, HTML.Attribute.ENDTAG, Boolean.TRUE);
    checkImplicitContentSpec(spec);
}
项目:cn1    文件:HTMLDocument_Reader_ActionsTest.java   
public void testTitleEnd() throws Exception {
    SimpleAttributeSet attr = new SimpleAttributeSet();
    reader.handleStartTag(Tag.TITLE, attr, 0);
    assertEquals(0, reader.charAttr.getAttributeCount());
    assertEquals(2, reader.parseBuffer.size());
    reader.handleEndTag(Tag.TITLE, 0);

    assertEquals(0, reader.charAttr.getAttributeCount());
    assertEquals(3, reader.parseBuffer.size());
    ElementSpec spec = (ElementSpec)reader.parseBuffer.get(2);
    AttributeSet specAttr = spec.getAttributes();
    assertEquals(2, specAttr.getAttributeCount());
    checkAttributes(specAttr, StyleConstants.NameAttribute, Tag.TITLE);
    checkAttributes(specAttr, HTML.Attribute.ENDTAG, Boolean.TRUE);
    checkImplicitContentSpec(spec);
}
项目:cn1    文件:DefaultStyledDocument_ElementBuffer_Specs2Test.java   
/**
 * Bold attribute on paragraph, text '\none' with italic, doc is empty.
 */
public void testInsertString43() throws Exception {
    doc.setParagraphAttributes(insertOffset, 1, bold, false);
    doc.insertString(insertOffset, "\none", italic);
    List<?> edits = getEdits(insertEvent);
    assertEquals(4, edits.size());
    assertSame(modified, root.getElement(modifiedIndex));
    assertChange(edits.get(1), root.getElement(modifiedIndex), 1, 2);
    assertChange(edits.get(2), root.getElement(modifiedIndex + 1), 0, 1);
    assertChange(edits.get(3), root, 0, 1);
    assertTrue(root.getElement(modifiedIndex).getAttributes().containsAttributes(bold));
    assertTrue(root.getElement(modifiedIndex + 1).getAttributes().containsAttributes(bold));
    assertEquals(2, modified.getElementCount());
    assertEquals(0, modified.getElement(0).getAttributes().getAttributeCount());
    assertTrue(modified.getElement(1).getAttributes().isEqual(italic));
    assertEquals(2, root.getElement(modifiedIndex + 1).getElementCount());
    assertEquals(4, specs.length);
    assertSpec(specs[0], ElementSpec.ContentType, ElementSpec.OriginateDirection, 0, 1);
    assertSpec(specs[1], ElementSpec.EndTagType, ElementSpec.OriginateDirection, 0, 0);
    assertSpec(specs[2], ElementSpec.StartTagType, ElementSpec.JoinFractureDirection, 0, 0);
    assertSpec(specs[3], ElementSpec.ContentType, ElementSpec.OriginateDirection, 0, 3);
}
项目:cn1    文件:DefaultStyledDocument_ElementBuffer_Specs2Test.java   
/**
 * Bold attribute on paragraph, text 'one\ntwo' with italic, doc is empty.
 */
public void testInsertString44() throws Exception {
    doc.setParagraphAttributes(insertOffset, 1, bold, false);
    doc.insertString(insertOffset, "one\ntwo", italic);
    List<?> edits = getEdits(insertEvent);
    assertSame(modified, root.getElement(modifiedIndex));
    assertEquals(4, edits.size());
    assertChange(edits.get(1), root.getElement(modifiedIndex), 1, 2);
    assertChange(edits.get(2), root.getElement(modifiedIndex + 1), 0, 1);
    assertChange(edits.get(3), root, 0, 1);
    assertTrue(root.getElement(modifiedIndex).getAttributes().containsAttributes(bold));
    assertTrue(root.getElement(modifiedIndex + 1).getAttributes().containsAttributes(bold));
    assertEquals(2, modified.getElementCount());
    assertEquals(2, root.getElement(modifiedIndex + 1).getElementCount());
    assertEquals(4, specs.length);
    assertSpec(specs[0], ElementSpec.ContentType, ElementSpec.OriginateDirection, 0, 4);
    assertSpec(specs[1], ElementSpec.EndTagType, ElementSpec.OriginateDirection, 0, 0);
    assertSpec(specs[2], ElementSpec.StartTagType, ElementSpec.JoinFractureDirection, 0, 0);
    assertSpec(specs[3], ElementSpec.ContentType, ElementSpec.OriginateDirection, 0, 3);
}
项目:cn1    文件:DefaultStyledDocument_ElementBuffer_Specs2Test.java   
/**
 * Bold attribute on character, text 'one' with italic, doc is empty.
 */
public void testInsertString51() throws Exception {
    doc.setCharacterAttributes(modified.getStartOffset(), modified.getEndOffset()
            - modified.getStartOffset(), bold, false);
    doc.insertString(insertOffset, "one", italic);
    List<?> edits = getEdits(insertEvent);
    assertEquals(2, edits.size());
    assertSame(modified, root.getElement(modifiedIndex));
    assertChange(edits.get(1), root.getElement(modifiedIndex), 1, 3);
    assertEquals(3, modified.getElementCount());
    assertTrue(modified.getElement(0).getAttributes().isEqual(bold));
    assertTrue(modified.getElement(1).getAttributes().isEqual(italic));
    assertTrue(modified.getElement(2).getAttributes().isEqual(bold));
    assertEquals(1, specs.length);
    assertSpec(specs[0], ElementSpec.ContentType, ElementSpec.OriginateDirection, 0, 3);
}
项目:cn1    文件:DefaultStyledDocument_ElementBuffer_Specs1Test.java   
/**
 * Bold attribute on character, text 'one' with no attributes, doc is empty.
 */
public void testInsertString21() throws Exception {
    doc.setCharacterAttributes(0, 1, bold, false);
    doc.insertString(0, "one", null);
    List<?> edits = getEdits(insertEvent);
    assertEquals(2, edits.size());
    assertChange(edits.get(1), root.getElement(0), 1, 2);
    Element charElem = doc.getCharacterElement(0);
    assertEquals(0, charElem.getAttributes().getAttributeCount());
    charElem = doc.getCharacterElement(doc.getLength());
    assertTrue(charElem.getAttributes().isEqual(bold));
    assertEquals(1, specs.length);
    assertSpec(specs[0], ElementSpec.ContentType, ElementSpec.OriginateDirection, 0, 3);
    /*
     * createLeaf(paragraph[0, 4], , 0, 3)
     *      The word 'one'
     * createLeaf(paragraph[0, 4], bold=true , 3, 4)
     *      The attributed newline char
     */
}
项目:cn1    文件:DefaultStyledDocument_ElementBuffer_Specs1Test.java   
/**
 * No attributes, text 'one\ntwo' with italic, doc is empty.
 */
public void testInsertString34() throws Exception {
    doc.insertString(0, "one\ntwo", italic);
    List<?> edits = getEdits(insertEvent);
    assertEquals(4, edits.size());
    assertChange(edits.get(1), root.getElement(0), 1, 1);
    assertChange(edits.get(2), root.getElement(1), 0, 1);
    assertChange(edits.get(3), root, 0, 1);
    Element charElem = doc.getCharacterElement(0);
    assertTrue(charElem.getAttributes().isEqual(italic));
    assertEquals(0, charElem.getStartOffset());
    assertEquals(4, charElem.getEndOffset());
    charElem = doc.getCharacterElement(4);
    assertTrue(charElem.getAttributes().isEqual(italic));
    assertEquals(4, charElem.getStartOffset());
    assertEquals(7, charElem.getEndOffset());
    charElem = doc.getCharacterElement(doc.getLength());
    assertEquals(0, charElem.getAttributes().getAttributeCount());
    assertEquals(7, charElem.getStartOffset());
    assertEquals(8, charElem.getEndOffset());
    assertEquals(4, specs.length);
    assertSpec(specs[0], ElementSpec.ContentType, ElementSpec.OriginateDirection, 0, 4);
    assertSpec(specs[1], ElementSpec.EndTagType, ElementSpec.OriginateDirection, 0, 0);
    assertSpec(specs[2], ElementSpec.StartTagType, ElementSpec.JoinFractureDirection, 0, 0);
    assertSpec(specs[3], ElementSpec.ContentType, ElementSpec.OriginateDirection, 0, 3);
}
项目:cn1    文件:HTMLDocument_ReaderTest.java   
public void testBlockOpen() {
    SimpleAttributeSet attr = new SimpleAttributeSet();
    attr.addAttribute("aaaa", "bbbb");
    reader.blockOpen(Tag.B, attr);
    assertEquals(0, reader.charAttr.getAttributeCount());
    assertEquals(1, reader.parseBuffer.size());
    final ElementSpec spec = (ElementSpec)reader.parseBuffer.get(0);
    final AttributeSet specAttr = spec.getAttributes();
    assertEquals(2, specAttr.getAttributeCount());
    checkAttributes(specAttr, StyleConstants.NameAttribute, Tag.B);
    checkAttributes(specAttr, "aaaa", "bbbb");
    assertSpec(spec, ElementSpec.StartTagType, ElementSpec.OriginateDirection, 0, null);

    assertNotSame(attr, specAttr);
    assertEquals(2, attr.getAttributeCount());
    checkAttributes(attr, StyleConstants.NameAttribute, Tag.B);
}
项目:cn1    文件:HTMLDocument_InsertsTest.java   
public void testInsertAfterStart_Specs2() throws Exception {
    htmlDoc.setParser(new ParserDelegator());
    htmlDoc.setEditable(false);

    Element root = htmlDoc.getDefaultRootElement();
    Element body = root.getElement(0);
    Element p = body.getElement(0);

    htmlDoc.insertAfterStart(p, "<a>link</a>");
    Marker insertMarker = htmlDoc.getInsertMarker();
    assertEquals(new Integer(0), getInsertInfo(insertMarker).get(1));
    ElementSpec[] specs = (ElementSpec[])(getInsertInfo(insertMarker).get(0));
    insertMarker.reset();
    assertEquals(1, specs.length);
    assertSpec(specs[0], ElementSpec.ContentType, ElementSpec.OriginateDirection, 0, "link".toCharArray());
    AttributeSet specAttr = specs[0].getAttributes();
    assertEquals(2, specAttr.getAttributeCount());
    checkAttributes(specAttr, StyleConstants.NameAttribute, Tag.CONTENT);
}
项目:cn1    文件:HTMLDocument_InsertsTest.java   
public void testInsertBeforeEnd_Specs2() throws Exception {
    htmlDoc.setParser(new ParserDelegator());
    htmlDoc.setEditable(false);

    Element root = htmlDoc.getDefaultRootElement();
    Element body = root.getElement(0);
    Element p = body.getElement(0);

    htmlDoc.insertBeforeEnd(p, "<a>link</a>");
    Marker insertMarker = htmlDoc.getInsertMarker();
    assertEquals(new Integer(0), getInsertInfo(insertMarker).get(1));
    ElementSpec[] specs = (ElementSpec[])(getInsertInfo(insertMarker).get(0));
    insertMarker.reset();
    assertEquals(1, specs.length);
    assertSpec(specs[0], ElementSpec.ContentType, ElementSpec.OriginateDirection, 0, "link".toCharArray());
    AttributeSet specAttr = specs[0].getAttributes();
    assertEquals(2, specAttr.getAttributeCount());
    checkAttributes(specAttr, StyleConstants.NameAttribute, Tag.CONTENT);
}