Search in sources :

Example 56 with NodeList

use of org.w3c.dom.NodeList in project buck by facebook.

the class XmlPrettyPrinter method visitNode.

/** Visit the given node at the given depth */
private void visitNode(int depth, Node node) {
    if (node == mStartNode) {
        mInRange = true;
    }
    if (mInRange) {
        visitBeforeChildren(depth, node);
        if (mOpenTagOnly && mStartNode == node) {
            mInRange = false;
            return;
        }
    }
    NodeList children = node.getChildNodes();
    for (int i = 0, n = children.getLength(); i < n; i++) {
        Node child = children.item(i);
        visitNode(depth + 1, child);
    }
    if (mInRange) {
        visitAfterChildren(depth, node);
    }
    if (node == mEndNode) {
        mInRange = false;
    }
}
Also used : NodeList(org.w3c.dom.NodeList) Node(org.w3c.dom.Node)

Example 57 with NodeList

use of org.w3c.dom.NodeList in project buck by facebook.

the class PositionXmlParser method findNodeAtLineAndCol.

@Nullable
private static Node findNodeAtLineAndCol(@NonNull Node node, int line, int column) {
    Position p = getPositionHelper(node, -1, -1);
    if (p != null) {
        if (line < p.getLine() || line == p.getLine() && column != -1 && column < p.getColumn()) {
            return null;
        }
        Position end = p.getEnd();
        if (end != null) {
            if (line > end.getLine() || line == end.getLine() && column != -1 && column >= end.getColumn()) {
                return null;
            }
        }
    } else {
        return null;
    }
    NodeList children = node.getChildNodes();
    for (int i = 0, n = children.getLength(); i < n; i++) {
        Node item = children.item(i);
        Node match = findNodeAtLineAndCol(item, line, column);
        if (match != null) {
            return match;
        }
    }
    NamedNodeMap attributes = node.getAttributes();
    if (attributes != null) {
        for (int i = 0, n = attributes.getLength(); i < n; i++) {
            Node item = attributes.item(i);
            Node match = findNodeAtLineAndCol(item, line, column);
            if (match != null) {
                return match;
            }
        }
    }
    return node;
}
Also used : NamedNodeMap(org.w3c.dom.NamedNodeMap) SourcePosition(com.android.common.ide.common.blame.SourcePosition) NodeList(org.w3c.dom.NodeList) Node(org.w3c.dom.Node) Nullable(com.android.annotations.Nullable)

Example 58 with NodeList

use of org.w3c.dom.NodeList in project camel by apache.

the class XMLSecurityDataFormatTest method testAsymmetricEncryptionNoKeyValue.

@Test
public void testAsymmetricEncryptionNoKeyValue() throws Exception {
    KeyStoreParameters tsParameters = new KeyStoreParameters();
    tsParameters.setPassword("password");
    tsParameters.setResource("sender.ts");
    final XMLSecurityDataFormat xmlEncDataFormat = new XMLSecurityDataFormat();
    xmlEncDataFormat.setKeyOrTrustStoreParameters(tsParameters);
    xmlEncDataFormat.setXmlCipherAlgorithm(testCypherAlgorithm);
    xmlEncDataFormat.setRecipientKeyAlias("recipient");
    xmlEncDataFormat.setAddKeyValueForEncryptedKey(false);
    context.addRoutes(new RouteBuilder() {

        public void configure() {
            from("direct:start").marshal(xmlEncDataFormat).to("mock:encrypted");
        }
    });
    Document doc = xmlsecTestHelper.testEncryption(TestHelper.XML_FRAGMENT, context);
    NodeList nodeList = doc.getElementsByTagNameNS("http://www.w3.org/2000/09/xmldsig#", "RSAKeyValue");
    Assert.assertTrue(nodeList.getLength() == 0);
}
Also used : RouteBuilder(org.apache.camel.builder.RouteBuilder) NodeList(org.w3c.dom.NodeList) KeyStoreParameters(org.apache.camel.util.jsse.KeyStoreParameters) Document(org.w3c.dom.Document) Test(org.junit.Test)

Example 59 with NodeList

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

the class DocumentImpl method changeDocumentToThis.

/**
     * Recursively change the document of {@code node} without also changing its
     * parent node. Only adoptNode() should invoke this method, otherwise nodes
     * will be left in an inconsistent state.
     */
private void changeDocumentToThis(NodeImpl node) {
    Map<String, UserData> userData = node.document.getUserDataMapForRead(node);
    if (!userData.isEmpty()) {
        getUserDataMap(node).putAll(userData);
    }
    node.document = this;
    // change the document on all child nodes
    NodeList list = node.getChildNodes();
    for (int i = 0; i < list.getLength(); i++) {
        changeDocumentToThis((NodeImpl) list.item(i));
    }
    // change the document on all attribute nodes
    if (node.getNodeType() == Node.ELEMENT_NODE) {
        NamedNodeMap attributes = node.getAttributes();
        for (int i = 0; i < attributes.getLength(); i++) {
            changeDocumentToThis((AttrImpl) attributes.item(i));
        }
    }
}
Also used : NamedNodeMap(org.w3c.dom.NamedNodeMap) NodeList(org.w3c.dom.NodeList)

Example 60 with NodeList

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

NodeList (org.w3c.dom.NodeList)2090 Node (org.w3c.dom.Node)1217 Element (org.w3c.dom.Element)1061 Document (org.w3c.dom.Document)705 ArrayList (java.util.ArrayList)356 DocumentBuilder (javax.xml.parsers.DocumentBuilder)304 DocumentBuilderFactory (javax.xml.parsers.DocumentBuilderFactory)237 IOException (java.io.IOException)217 NamedNodeMap (org.w3c.dom.NamedNodeMap)171 InputSource (org.xml.sax.InputSource)145 SAXException (org.xml.sax.SAXException)145 Test (org.junit.Test)138 HashMap (java.util.HashMap)135 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)126 XPath (javax.xml.xpath.XPath)118 StringReader (java.io.StringReader)111 Attr (org.w3c.dom.Attr)88 XPathExpressionException (javax.xml.xpath.XPathExpressionException)85 File (java.io.File)76 InputStream (java.io.InputStream)70