Search in sources :

Example 1 with EntityReference

use of org.w3c.dom.EntityReference in project karaf by apache.

the class NamespaceHandler method getTextValue.

private static String getTextValue(Element element) {
    StringBuffer value = new StringBuffer();
    NodeList nl = element.getChildNodes();
    for (int i = 0; i < nl.getLength(); i++) {
        Node item = nl.item(i);
        if ((item instanceof CharacterData && !(item instanceof Comment)) || item instanceof EntityReference) {
            value.append(item.getNodeValue());
        }
    }
    return value.toString();
}
Also used : Comment(org.w3c.dom.Comment) CharacterData(org.w3c.dom.CharacterData) NodeList(org.w3c.dom.NodeList) Node(org.w3c.dom.Node) EntityReference(org.w3c.dom.EntityReference)

Example 2 with EntityReference

use of org.w3c.dom.EntityReference in project robovm by robovm.

the class DomTest method testGetWholeTextWithEntityReference.

public void testGetWholeTextWithEntityReference() {
    EntityReference spReference = document.createEntityReference("sp");
    description.insertBefore(spReference, descriptionText2);
    assertEquals("This implementation doesn't resolve entity references in getWholeText()", "BelgianMaple Syrup waffles & strawberries (< 5g of fat)", descriptionText1.getWholeText());
}
Also used : EntityReference(org.w3c.dom.EntityReference)

Example 3 with EntityReference

use of org.w3c.dom.EntityReference in project robovm by robovm.

the class DomTest method testExpandingEntityReferencesOff.

public void testExpandingEntityReferencesOff() throws Exception {
    String xml = "<!DOCTYPE foo [ <!ENTITY def \"DEF\"> ]>" + "<foo>abc&def;ghi</foo>";
    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
    factory.setExpandEntityReferences(false);
    document = factory.newDocumentBuilder().parse(new InputSource(new StringReader(xml)));
    Element documentElement = document.getDocumentElement();
    Text abc = (Text) documentElement.getFirstChild();
    assertEquals("abc", abc.getTextContent());
    EntityReference def = (EntityReference) abc.getNextSibling();
    assertEquals("def", def.getNodeName());
    Text ghi = (Text) def.getNextSibling();
    assertNull(ghi.getNextSibling());
    /*
         * We expect the entity reference to contain one child Text node "DEF".
         * The RI's entity reference contains no children. Instead it stashes
         * "DEF" in the next sibling node.
         */
    assertEquals("Expected text value only and no expanded entity data", "ghi", ghi.getTextContent());
    NodeList defChildren = def.getChildNodes();
    assertEquals("This implementation doesn't include children in entity references", 1, defChildren.getLength());
    assertEquals("DEF", defChildren.item(0).getTextContent());
}
Also used : InputSource(org.xml.sax.InputSource) DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) Element(org.w3c.dom.Element) NodeList(org.w3c.dom.NodeList) StringReader(java.io.StringReader) EntityReference(org.w3c.dom.EntityReference) Text(org.w3c.dom.Text)

Example 4 with EntityReference

use of org.w3c.dom.EntityReference in project robovm by robovm.

the class NodeIsSupported method testIsSupported4.

public void testIsSupported4() throws Throwable {
    Document doc;
    EntityReference entRef;
    boolean success;
    doc = (Document) load("staffNS", builder);
    entRef = doc.createEntityReference("ent1");
    assertNotNull("createdEntRefNotNull", entRef);
    success = entRef.isSupported("XML CORE", "");
    assertFalse("nodeissupported04", success);
}
Also used : EntityReference(org.w3c.dom.EntityReference) Document(org.w3c.dom.Document)

Example 5 with EntityReference

use of org.w3c.dom.EntityReference in project robovm by robovm.

the class NodeNormalize method testNormalize.

/**
     * Runs the test case.
     *
     * @throws Throwable
     *             Any uncaught exception causes test to fail
     */
public void testNormalize() throws Throwable {
    Document doc;
    Document newDoc;
    DOMImplementation domImpl;
    DocumentType docTypeNull = null;
    Element documentElement;
    Element element1;
    Element element2;
    Element element3;
    Element element4;
    Element element5;
    Element element6;
    Element element7;
    Text text1;
    Text text2;
    Text text3;
    ProcessingInstruction pi;
    CDATASection cData;
    Comment comment;
    EntityReference entRef;
    NodeList elementList;
    doc = (Document) load("staffNS", builder);
    domImpl = doc.getImplementation();
    newDoc = domImpl.createDocument("http://www.w3.org/DOM/Test", "dom:root", docTypeNull);
    element1 = newDoc.createElement("element1");
    element2 = newDoc.createElement("element2");
    element3 = newDoc.createElement("element3");
    element4 = newDoc.createElement("element4");
    element5 = newDoc.createElement("element5");
    element6 = newDoc.createElement("element6");
    element7 = newDoc.createElement("element7");
    text1 = newDoc.createTextNode("text1");
    text2 = newDoc.createTextNode("text2");
    text3 = newDoc.createTextNode("text3");
    cData = newDoc.createCDATASection("Cdata");
    comment = newDoc.createComment("comment");
    pi = newDoc.createProcessingInstruction("PITarget", "PIData");
    entRef = newDoc.createEntityReference("EntRef");
    assertNotNull("createdEntRefNotNull", entRef);
    documentElement = newDoc.getDocumentElement();
    documentElement.appendChild(element1);
    element2.appendChild(text1);
    element2.appendChild(text2);
    element2.appendChild(text3);
    element1.appendChild(element2);
    text1 = (Text) text1.cloneNode(false);
    text2 = (Text) text2.cloneNode(false);
    element3.appendChild(entRef);
    element3.appendChild(text1);
    element3.appendChild(text2);
    element1.appendChild(element3);
    text1 = (Text) text1.cloneNode(false);
    text2 = (Text) text2.cloneNode(false);
    element4.appendChild(cData);
    element4.appendChild(text1);
    element4.appendChild(text2);
    element1.appendChild(element4);
    text2 = (Text) text2.cloneNode(false);
    text3 = (Text) text3.cloneNode(false);
    element5.appendChild(comment);
    element5.appendChild(text2);
    element5.appendChild(text3);
    element1.appendChild(element5);
    text2 = (Text) text2.cloneNode(false);
    text3 = (Text) text3.cloneNode(false);
    element6.appendChild(pi);
    element6.appendChild(text2);
    element6.appendChild(text3);
    element1.appendChild(element6);
    entRef = (EntityReference) entRef.cloneNode(false);
    text1 = (Text) text1.cloneNode(false);
    text2 = (Text) text2.cloneNode(false);
    text3 = (Text) text3.cloneNode(false);
    element7.appendChild(entRef);
    element7.appendChild(text1);
    element7.appendChild(text2);
    element7.appendChild(text3);
    element1.appendChild(element7);
    elementList = element1.getChildNodes();
    assertEquals("nodeNormalize01_1Bef", 6, elementList.getLength());
    elementList = element2.getChildNodes();
    assertEquals("nodeNormalize01_2Bef", 3, elementList.getLength());
    elementList = element3.getChildNodes();
    assertEquals("nodeNormalize01_3Bef", 3, elementList.getLength());
    elementList = element4.getChildNodes();
    assertEquals("nodeNormalize01_4Bef", 3, elementList.getLength());
    elementList = element5.getChildNodes();
    assertEquals("nodeNormalize01_5Bef", 3, elementList.getLength());
    elementList = element6.getChildNodes();
    assertEquals("nodeNormalize01_6Bef", 3, elementList.getLength());
    elementList = element7.getChildNodes();
    assertEquals("nodeNormalize01_7Bef", 4, elementList.getLength());
    newDoc.normalize();
    elementList = element1.getChildNodes();
    assertEquals("nodeNormalize01_1Aft", 6, elementList.getLength());
    elementList = element2.getChildNodes();
    assertEquals("nodeNormalize01_2Aft", 1, elementList.getLength());
    elementList = element3.getChildNodes();
    assertEquals("nodeNormalize01_3Aft", 2, elementList.getLength());
    elementList = element4.getChildNodes();
    assertEquals("nodeNormalize01_4Aft", 2, elementList.getLength());
    elementList = element5.getChildNodes();
    assertEquals("nodeNormalize01_5Aft", 2, elementList.getLength());
    elementList = element6.getChildNodes();
    assertEquals("nodeNormalize01_6Aft", 2, elementList.getLength());
    elementList = element7.getChildNodes();
    assertEquals("nodeNormalize01_7Aft", 2, elementList.getLength());
}
Also used : Comment(org.w3c.dom.Comment) CDATASection(org.w3c.dom.CDATASection) Element(org.w3c.dom.Element) NodeList(org.w3c.dom.NodeList) EntityReference(org.w3c.dom.EntityReference) DOMImplementation(org.w3c.dom.DOMImplementation) DocumentType(org.w3c.dom.DocumentType) Text(org.w3c.dom.Text) Document(org.w3c.dom.Document) ProcessingInstruction(org.w3c.dom.ProcessingInstruction)

Aggregations

EntityReference (org.w3c.dom.EntityReference)32 Node (org.w3c.dom.Node)24 NodeList (org.w3c.dom.NodeList)17 Element (org.w3c.dom.Element)14 Comment (org.w3c.dom.Comment)12 CharacterData (org.w3c.dom.CharacterData)10 NamedNodeMap (org.w3c.dom.NamedNodeMap)8 LexicalHandler (org.xml.sax.ext.LexicalHandler)8 Document (org.w3c.dom.Document)7 ProcessingInstruction (org.w3c.dom.ProcessingInstruction)7 Locator (org.xml.sax.Locator)4 Text (org.w3c.dom.Text)3 DocumentBuilderFactory (javax.xml.parsers.DocumentBuilderFactory)2 AttList (org.apache.xml.serializer.utils.AttList)2 DOMException (org.w3c.dom.DOMException)2 DocumentType (org.w3c.dom.DocumentType)2 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 StringReader (java.io.StringReader)1 ArrayDeque (java.util.ArrayDeque)1