Search in sources :

Example 71 with DOMException

use of org.w3c.dom.DOMException in project webservices-axiom by apache.

the class TestAppendChildForbidden method runTest.

@Override
protected void runTest() throws Throwable {
    OMDocument omDocument = OMXMLBuilderFactory.createOMBuilder(metaFactory.getOMFactory(), new StringReader("<test/>")).getDocument();
    if (build) {
        omDocument.build();
    }
    Document document = (Document) omDocument;
    try {
        document.appendChild(document.createElementNS(null, "test"));
        fail("Expected DOMException");
    } catch (DOMException ex) {
        assertThat(ex.code).isEqualTo(DOMException.HIERARCHY_REQUEST_ERR);
    }
}
Also used : DOMException(org.w3c.dom.DOMException) StringReader(java.io.StringReader) Document(org.w3c.dom.Document) OMDocument(org.apache.axiom.om.OMDocument) OMDocument(org.apache.axiom.om.OMDocument)

Example 72 with DOMException

use of org.w3c.dom.DOMException in project webservices-axiom by apache.

the class TestInsertBeforeForbidden method runTest.

@Override
protected void runTest() throws Throwable {
    OMDocument omDocument = OMXMLBuilderFactory.createOMBuilder(metaFactory.getOMFactory(), new StringReader("<!--test--><test/>")).getDocument();
    if (build) {
        omDocument.build();
    }
    Document document = (Document) omDocument;
    Comment comment = (Comment) document.getFirstChild();
    try {
        document.insertBefore(document.createElementNS(null, "test"), comment);
        fail("Expected DOMException");
    } catch (DOMException ex) {
        assertThat(ex.code).isEqualTo(DOMException.HIERARCHY_REQUEST_ERR);
    }
}
Also used : Comment(org.w3c.dom.Comment) DOMException(org.w3c.dom.DOMException) StringReader(java.io.StringReader) Document(org.w3c.dom.Document) OMDocument(org.apache.axiom.om.OMDocument) OMDocument(org.apache.axiom.om.OMDocument)

Example 73 with DOMException

use of org.w3c.dom.DOMException in project webservices-axiom by apache.

the class DOMExceptionTranslatorTest method testMessage.

@Test
public void testMessage() {
    DOMException ex = DOMExceptionUtil.newDOMException(DOMException.NOT_FOUND_ERR);
    assertThat(ex.getMessage()).isEqualTo("NOT_FOUND_ERR: An attempt is made to reference a node in a context where it does not exist.");
}
Also used : DOMException(org.w3c.dom.DOMException) Test(org.junit.Test)

Example 74 with DOMException

use of org.w3c.dom.DOMException in project webservices-axiom by apache.

the class TestReplaceChildWrongDocument method runTest.

protected void runTest() throws Throwable {
    DocumentBuilder db = dbf.newDocumentBuilder();
    Document document1 = db.newDocument();
    Document document2 = db.newDocument();
    Element parent = document1.createElementNS(null, "parent");
    Element child1 = document1.createElementNS(null, "child1");
    Element child2 = document1.createElementNS(null, "child2");
    Element child3 = document1.createElementNS(null, "child3");
    parent.appendChild(child1);
    parent.appendChild(child2);
    parent.appendChild(child3);
    Element replacementChild = document2.createElementNS(null, "newchild");
    try {
        parent.replaceChild(replacementChild, child2);
        fail("Expected DOMException");
    } catch (DOMException ex) {
        assertEquals(DOMException.WRONG_DOCUMENT_ERR, ex.code);
    }
}
Also used : DOMException(org.w3c.dom.DOMException) DocumentBuilder(javax.xml.parsers.DocumentBuilder) Element(org.w3c.dom.Element) Document(org.w3c.dom.Document)

Example 75 with DOMException

use of org.w3c.dom.DOMException in project webservices-axiom by apache.

the class TestSetAttributeNSInvalid method runTest.

protected void runTest() throws Throwable {
    Document document = dbf.newDocumentBuilder().newDocument();
    Element element = document.createElementNS(null, "test");
    try {
        element.setAttributeNS(DOMUtils.getNamespaceURI(qname), DOMUtils.getQualifiedName(qname), "value");
        fail("Expected DOMException");
    } catch (DOMException ex) {
        assertEquals(DOMException.NAMESPACE_ERR, ex.code);
    }
}
Also used : DOMException(org.w3c.dom.DOMException) Element(org.w3c.dom.Element) Document(org.w3c.dom.Document)

Aggregations

DOMException (org.w3c.dom.DOMException)323 Document (org.w3c.dom.Document)165 Element (org.w3c.dom.Element)131 Node (org.w3c.dom.Node)73 NodeList (org.w3c.dom.NodeList)57 DocumentBuilder (javax.xml.parsers.DocumentBuilder)42 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)42 Attr (org.w3c.dom.Attr)40 DOMImplementation (org.w3c.dom.DOMImplementation)37 DocumentBuilderFactory (javax.xml.parsers.DocumentBuilderFactory)28 FrameworkException (org.structr.common.error.FrameworkException)27 IOException (java.io.IOException)26 NamedNodeMap (org.w3c.dom.NamedNodeMap)25 DocumentType (org.w3c.dom.DocumentType)19 ArrayList (java.util.ArrayList)17 Text (org.w3c.dom.Text)17 DOMNode (org.structr.web.entity.dom.DOMNode)16 XPathExpressionException (javax.xml.xpath.XPathExpressionException)15 SAXException (org.xml.sax.SAXException)13 TransformerException (javax.xml.transform.TransformerException)12