Search in sources :

Example 16 with DOMImplementation

use of org.w3c.dom.DOMImplementation 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)

Example 17 with DOMImplementation

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

the class NamedNodeMapSetNamedItemNS method testSetNamedItemNS4.

public void testSetNamedItemNS4() throws Throwable {
    Document doc;
    DOMImplementation domImpl;
    Document docAlt;
    DocumentType docType = null;
    NamedNodeMap attributes;
    NodeList elementList;
    Element element;
    Attr attrAlt;
    String nullNS = null;
    doc = (Document) load("staffNS", builder);
    elementList = doc.getElementsByTagNameNS("*", "address");
    element = (Element) elementList.item(1);
    attributes = element.getAttributes();
    domImpl = doc.getImplementation();
    docAlt = domImpl.createDocument(nullNS, "newDoc", docType);
    attrAlt = docAlt.createAttributeNS(nullNS, "street");
    {
        boolean success = false;
        try {
            attributes.setNamedItemNS(attrAlt);
        } catch (DOMException ex) {
            success = (ex.code == DOMException.WRONG_DOCUMENT_ERR);
        }
        assertTrue("throw_WRONG_DOCUMENT_ERR", success);
    }
}
Also used : DOMException(org.w3c.dom.DOMException) NamedNodeMap(org.w3c.dom.NamedNodeMap) NodeList(org.w3c.dom.NodeList) Element(org.w3c.dom.Element) DOMImplementation(org.w3c.dom.DOMImplementation) DocumentType(org.w3c.dom.DocumentType) Document(org.w3c.dom.Document) Attr(org.w3c.dom.Attr)

Example 18 with DOMImplementation

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

the class NodeGetOwnerDocument method testGetOwnerDocument1.

/**
     * Runs the test case.
     *
     * @throws Throwable
     *             Any uncaught exception causes test to fail
     */
public void testGetOwnerDocument1() throws Throwable {
    Document doc;
    Document ownerDoc;
    DOMImplementation domImpl;
    DocumentType docType;
    String nullID = null;
    doc = (Document) load("staff", builder);
    domImpl = doc.getImplementation();
    docType = domImpl.createDocumentType("mydoc", nullID, nullID);
    ownerDoc = docType.getOwnerDocument();
    assertNull("nodegetownerdocument01", ownerDoc);
}
Also used : DOMImplementation(org.w3c.dom.DOMImplementation) DocumentType(org.w3c.dom.DocumentType) Document(org.w3c.dom.Document)

Example 19 with DOMImplementation

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

the class NodeGetOwnerDocument method testGetOwnerDocument2.

public void testGetOwnerDocument2() throws Throwable {
    Document doc;
    Document newDoc;
    Element newElem;
    Document ownerDocDoc;
    Document ownerDocElem;
    DOMImplementation domImpl;
    DocumentType docType;
    String nullNS = null;
    doc = (Document) load("staff", builder);
    domImpl = doc.getImplementation();
    docType = domImpl.createDocumentType("mydoc", nullNS, nullNS);
    newDoc = domImpl.createDocument("http://www.w3.org/DOM/Test", "mydoc", docType);
    ownerDocDoc = newDoc.getOwnerDocument();
    assertNull("nodegetownerdocument02_1", ownerDocDoc);
    newElem = newDoc.createElementNS("http://www.w3.org/DOM/Test", "myelem");
    ownerDocElem = newElem.getOwnerDocument();
    assertNotNull("nodegetownerdocument02_2", ownerDocElem);
}
Also used : Element(org.w3c.dom.Element) DOMImplementation(org.w3c.dom.DOMImplementation) DocumentType(org.w3c.dom.DocumentType) Document(org.w3c.dom.Document)

Example 20 with DOMImplementation

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

the class NodeHasAttributes method testHasAttributes4.

public void testHasAttributes4() throws Throwable {
    Document doc;
    Document newDoc;
    DocumentType docType = null;
    DOMImplementation domImpl;
    Element element;
    Element elementTest;
    Element elementDoc;
    Attr attribute;
    NodeList elementList;
    boolean hasAttributes;
    doc = (Document) load("staffNS", builder);
    domImpl = doc.getImplementation();
    newDoc = domImpl.createDocument("http://www.w3.org/DOM/Test", "test", docType);
    element = newDoc.createElementNS("http://www.w3.org/DOM/Test", "dom:elem");
    attribute = newDoc.createAttribute("attr");
    element.setAttributeNode(attribute);
    elementDoc = newDoc.getDocumentElement();
    elementDoc.appendChild(element);
    elementList = newDoc.getElementsByTagNameNS("http://www.w3.org/DOM/Test", "elem");
    elementTest = (Element) elementList.item(0);
    hasAttributes = elementTest.hasAttributes();
    assertTrue("nodehasattributes04", hasAttributes);
}
Also used : Element(org.w3c.dom.Element) NodeList(org.w3c.dom.NodeList) DocumentType(org.w3c.dom.DocumentType) DOMImplementation(org.w3c.dom.DOMImplementation) Document(org.w3c.dom.Document) Attr(org.w3c.dom.Attr)

Aggregations

DOMImplementation (org.w3c.dom.DOMImplementation)73 Document (org.w3c.dom.Document)61 DOMException (org.w3c.dom.DOMException)35 Element (org.w3c.dom.Element)32 DocumentType (org.w3c.dom.DocumentType)28 DocumentBuilder (javax.xml.parsers.DocumentBuilder)23 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)22 DocumentBuilderFactory (javax.xml.parsers.DocumentBuilderFactory)20 ArrayList (java.util.ArrayList)7 TransformerException (javax.xml.transform.TransformerException)6 Transformer (javax.xml.transform.Transformer)4 DOMSource (javax.xml.transform.dom.DOMSource)4 StreamResult (javax.xml.transform.stream.StreamResult)4 NodeList (org.w3c.dom.NodeList)4 DOMImplementationRegistry (org.w3c.dom.bootstrap.DOMImplementationRegistry)4 ByteArrayOutputStream (java.io.ByteArrayOutputStream)3 IOException (java.io.IOException)3 Node (org.w3c.dom.Node)3 DOMImplementationLS (org.w3c.dom.ls.DOMImplementationLS)3 BufferedImage (java.awt.image.BufferedImage)2