Search in sources :

Example 51 with DOMException

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

the class ElementSetAttributeNS method testSetAttributeNS4.

public void testSetAttributeNS4() throws Throwable {
    Document doc;
    Element element;
    String qualifiedName;
    List<String> qualifiedNames = new ArrayList<String>();
    qualifiedNames.add("/");
    qualifiedNames.add("//");
    qualifiedNames.add("\\");
    qualifiedNames.add(";");
    qualifiedNames.add("&");
    qualifiedNames.add("*");
    qualifiedNames.add("]]");
    qualifiedNames.add(">");
    qualifiedNames.add("<");
    doc = (Document) load("staffNS", builder);
    element = doc.createElementNS("http://www.w3.org/DOM/Test/L2", "dom:elem");
    for (int indexN10058 = 0; indexN10058 < qualifiedNames.size(); indexN10058++) {
        qualifiedName = (String) qualifiedNames.get(indexN10058);
        {
            boolean success = false;
            try {
                element.setAttributeNS("http://www.w3.org/DOM/Test/L2", qualifiedName, "test");
            } catch (DOMException ex) {
                success = (ex.code == DOMException.INVALID_CHARACTER_ERR);
            }
            assertTrue("elementsetattributens04", success);
        }
    }
}
Also used : DOMException(org.w3c.dom.DOMException) Element(org.w3c.dom.Element) ArrayList(java.util.ArrayList) Document(org.w3c.dom.Document)

Example 52 with DOMException

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

the class ElementSetAttributeNS method testSetAttributeNS8.

public void testSetAttributeNS8() throws Throwable {
    Document doc;
    Element element;
    doc = (Document) load("staffNS", builder);
    element = doc.createElementNS("http://www.w3.org/DOMTest/level2", "dom:elem");
    {
        boolean success = false;
        try {
            element.setAttributeNS("http://www.w3.org/DOMTest/level2", "xmlns", "test");
        } catch (DOMException ex) {
            success = (ex.code == DOMException.NAMESPACE_ERR);
        }
        assertTrue("elementsetattributens08_Err1", success);
    }
    {
        boolean success = false;
        try {
            element.setAttributeNS("http://www.w3.org/DOMTest/level2", "xmlns:root", "test");
        } catch (DOMException ex) {
            success = (ex.code == DOMException.NAMESPACE_ERR);
        }
        assertTrue("elementsetattributens08_Err2", success);
    }
}
Also used : DOMException(org.w3c.dom.DOMException) Element(org.w3c.dom.Element) Document(org.w3c.dom.Document)

Example 53 with DOMException

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

the class DocumentImportNode method testImportNode7.

public void testImportNode7() throws Throwable {
    Document doc;
    DocumentType docType;
    doc = (Document) load("staffNS", builder);
    docType = doc.getDoctype();
    {
        boolean success = false;
        try {
            doc.importNode(docType, true);
        } catch (DOMException ex) {
            success = (ex.code == DOMException.NOT_SUPPORTED_ERR);
        }
        assertTrue("throw_NOT_SUPPORTED_ERR", success);
    }
}
Also used : DOMException(org.w3c.dom.DOMException) DocumentType(org.w3c.dom.DocumentType) Document(org.w3c.dom.Document)

Example 54 with DOMException

use of org.w3c.dom.DOMException in project XobotOS by xamarin.

the class DocumentImpl method shallowCopy.

/**
     * Returns a shallow copy of the given node. If the node is an element node,
     * its attributes are always copied.
     *
     * @param node a node belonging to any document or DOM implementation.
     * @param operation the operation type to use when notifying user data
     *     handlers of copied element attributes. It is the caller's
     *     responsibility to notify user data handlers of the returned node.
     * @return a new node whose document is this document and whose DOM
     *     implementation is this DOM implementation.
     */
private NodeImpl shallowCopy(short operation, Node node) {
    switch(node.getNodeType()) {
        case Node.ATTRIBUTE_NODE:
            AttrImpl attr = (AttrImpl) node;
            AttrImpl attrCopy;
            if (attr.namespaceAware) {
                attrCopy = createAttributeNS(attr.getNamespaceURI(), attr.getLocalName());
                attrCopy.setPrefix(attr.getPrefix());
            } else {
                attrCopy = createAttribute(attr.getName());
            }
            attrCopy.setNodeValue(attr.getValue());
            return attrCopy;
        case Node.CDATA_SECTION_NODE:
            return createCDATASection(((CharacterData) node).getData());
        case Node.COMMENT_NODE:
            return createComment(((Comment) node).getData());
        case Node.DOCUMENT_FRAGMENT_NODE:
            return createDocumentFragment();
        case Node.DOCUMENT_NODE:
        case Node.DOCUMENT_TYPE_NODE:
            throw new DOMException(DOMException.NOT_SUPPORTED_ERR, "Cannot copy node of type " + node.getNodeType());
        case Node.ELEMENT_NODE:
            ElementImpl element = (ElementImpl) node;
            ElementImpl elementCopy;
            if (element.namespaceAware) {
                elementCopy = createElementNS(element.getNamespaceURI(), element.getLocalName());
                elementCopy.setPrefix(element.getPrefix());
            } else {
                elementCopy = createElement(element.getTagName());
            }
            NamedNodeMap attributes = element.getAttributes();
            for (int i = 0; i < attributes.getLength(); i++) {
                AttrImpl elementAttr = (AttrImpl) attributes.item(i);
                AttrImpl elementAttrCopy = (AttrImpl) shallowCopy(operation, elementAttr);
                notifyUserDataHandlers(operation, elementAttr, elementAttrCopy);
                if (elementAttr.namespaceAware) {
                    elementCopy.setAttributeNodeNS(elementAttrCopy);
                } else {
                    elementCopy.setAttributeNode(elementAttrCopy);
                }
            }
            return elementCopy;
        case Node.ENTITY_NODE:
        case Node.NOTATION_NODE:
            // TODO: implement this when we support these node types
            throw new UnsupportedOperationException();
        case Node.ENTITY_REFERENCE_NODE:
            /*
             * When we support entities in the doctype, this will need to
             * behave differently for clones vs. imports. Clones copy
             * entities by value, copying the referenced subtree from the
             * original document. Imports copy entities by reference,
             * possibly referring to a different subtree in the new
             * document.
             */
            return createEntityReference(node.getNodeName());
        case Node.PROCESSING_INSTRUCTION_NODE:
            ProcessingInstruction pi = (ProcessingInstruction) node;
            return createProcessingInstruction(pi.getTarget(), pi.getData());
        case Node.TEXT_NODE:
            return createTextNode(((Text) node).getData());
        default:
            throw new DOMException(DOMException.NOT_SUPPORTED_ERR, "Unsupported node type " + node.getNodeType());
    }
}
Also used : DOMException(org.w3c.dom.DOMException) NamedNodeMap(org.w3c.dom.NamedNodeMap) ProcessingInstruction(org.w3c.dom.ProcessingInstruction)

Example 55 with DOMException

use of org.w3c.dom.DOMException in project XobotOS by xamarin.

the class InnerNodeImpl method insertChildAt.

/**
     * Inserts {@code newChild} at {@code index}. If it is already child of
     * another node, it is removed from there.
     */
Node insertChildAt(Node newChild, int index) throws DOMException {
    if (newChild instanceof DocumentFragment) {
        NodeList toAdd = newChild.getChildNodes();
        for (int i = 0; i < toAdd.getLength(); i++) {
            insertChildAt(toAdd.item(i), index + i);
        }
        return newChild;
    }
    LeafNodeImpl toInsert = (LeafNodeImpl) newChild;
    if (toInsert.document != null && document != null && toInsert.document != document) {
        throw new DOMException(DOMException.WRONG_DOCUMENT_ERR, null);
    }
    if (toInsert.isParentOf(this)) {
        throw new DOMException(DOMException.HIERARCHY_REQUEST_ERR, null);
    }
    if (toInsert.parent != null) {
        int oldIndex = toInsert.index;
        toInsert.parent.children.remove(oldIndex);
        toInsert.parent.refreshIndices(oldIndex);
    }
    children.add(index, toInsert);
    toInsert.parent = this;
    refreshIndices(index);
    return newChild;
}
Also used : DOMException(org.w3c.dom.DOMException) NodeList(org.w3c.dom.NodeList) DocumentFragment(org.w3c.dom.DocumentFragment)

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