org.w3c.dom.traversal.NodeFilter Java Examples
The following examples show how to use
org.w3c.dom.traversal.NodeFilter.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: TreeWalkerImpl.java From jdk8u60 with GNU General Public License v2.0 | 6 votes |
/** Internal function. * Return the parent Node, from the input node * after applying filter, whatToshow. * The current node is not consulted or set. */ Node getParentNode(Node node) { if (node == null || node == fRoot) return null; Node newNode = node.getParentNode(); if (newNode == null) return null; int accept = acceptNode(newNode); if (accept == NodeFilter.FILTER_ACCEPT) return newNode; else //if (accept == NodeFilter.SKIP_NODE) // and REJECT too. { return getParentNode(newNode); } }
Example #2
Source File: TreeWalkerImpl.java From openjdk-jdk9 with GNU General Public License v2.0 | 6 votes |
/** Internal function. * Return the parent Node, from the input node * after applying filter, whatToshow. * The current node is not consulted or set. */ Node getParentNode(Node node) { if (node == null || node == fRoot) return null; Node newNode = node.getParentNode(); if (newNode == null) return null; int accept = acceptNode(newNode); if (accept == NodeFilter.FILTER_ACCEPT) return newNode; else //if (accept == NodeFilter.SKIP_NODE) // and REJECT too. { return getParentNode(newNode); } }
Example #3
Source File: TreeWalkerImpl.java From hottub with GNU General Public License v2.0 | 6 votes |
/** Internal function. * Return the parent Node, from the input node * after applying filter, whatToshow. * The current node is not consulted or set. */ Node getParentNode(Node node) { if (node == null || node == fRoot) return null; Node newNode = node.getParentNode(); if (newNode == null) return null; int accept = acceptNode(newNode); if (accept == NodeFilter.FILTER_ACCEPT) return newNode; else //if (accept == NodeFilter.SKIP_NODE) // and REJECT too. { return getParentNode(newNode); } }
Example #4
Source File: DocumentImpl.java From hottub with GNU General Public License v2.0 | 6 votes |
/** * Create and return a NodeIterator. The NodeIterator is * added to a list of NodeIterators so that it can be * removed to free up the DOM Nodes it references. * * @param root The root of the iterator. * @param whatToShow The whatToShow mask. * @param filter The NodeFilter installed. Null means no filter. * @param entityReferenceExpansion true to expand the contents of * EntityReference nodes * @since WD-DOM-Level-2-19990923 */ public NodeIterator createNodeIterator(Node root, int whatToShow, NodeFilter filter, boolean entityReferenceExpansion) { if (root == null) { String msg = DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN, "NOT_SUPPORTED_ERR", null); throw new DOMException(DOMException.NOT_SUPPORTED_ERR, msg); } NodeIterator iterator = new NodeIteratorImpl(this, root, whatToShow, filter, entityReferenceExpansion); if (iterators == null) { iterators = new ArrayList<>(); } iterators.add(iterator); return iterator; }
Example #5
Source File: DocumentImpl.java From openjdk-jdk8u with GNU General Public License v2.0 | 6 votes |
/** * Create and return a NodeIterator. The NodeIterator is * added to a list of NodeIterators so that it can be * removed to free up the DOM Nodes it references. * * @param root The root of the iterator. * @param whatToShow The whatToShow mask. * @param filter The NodeFilter installed. Null means no filter. * @param entityReferenceExpansion true to expand the contents of * EntityReference nodes * @since WD-DOM-Level-2-19990923 */ public NodeIterator createNodeIterator(Node root, int whatToShow, NodeFilter filter, boolean entityReferenceExpansion) { if (root == null) { String msg = DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN, "NOT_SUPPORTED_ERR", null); throw new DOMException(DOMException.NOT_SUPPORTED_ERR, msg); } NodeIterator iterator = new NodeIteratorImpl(this, root, whatToShow, filter, entityReferenceExpansion); if (iterators == null) { iterators = new ArrayList<>(); } iterators.add(iterator); return iterator; }
Example #6
Source File: TreeWalkerImpl.java From jdk1.8-source-analysis with Apache License 2.0 | 6 votes |
/** Internal function. * Return the parent Node, from the input node * after applying filter, whatToshow. * The current node is not consulted or set. */ Node getParentNode(Node node) { if (node == null || node == fRoot) return null; Node newNode = node.getParentNode(); if (newNode == null) return null; int accept = acceptNode(newNode); if (accept == NodeFilter.FILTER_ACCEPT) return newNode; else //if (accept == NodeFilter.SKIP_NODE) // and REJECT too. { return getParentNode(newNode); } }
Example #7
Source File: DOM3TreeWalker.java From openjdk-jdk9 with GNU General Public License v2.0 | 6 votes |
/** * Serializes a Comment Node. * * @param node The Comment Node to serialize */ protected void serializeComment(Comment node) throws SAXException { // comments=true if ((fFeatures & COMMENTS) != 0) { String data = node.getData(); // well-formed=true if ((fFeatures & WELLFORMED) != 0) { isCommentWellFormed(data); } if (fLexicalHandler != null) { // apply the LSSerializer filter after the operations requested by the // DOMConfiguration parameters have been applied if (!applyFilter(node, NodeFilter.SHOW_COMMENT)) { return; } fLexicalHandler.comment(data.toCharArray(), 0, data.length()); } } }
Example #8
Source File: TreeWalkerImpl.java From openjdk-8-source with GNU General Public License v2.0 | 6 votes |
/** Internal function. * Return the parent Node, from the input node * after applying filter, whatToshow. * The current node is not consulted or set. */ Node getParentNode(Node node) { if (node == null || node == fRoot) return null; Node newNode = node.getParentNode(); if (newNode == null) return null; int accept = acceptNode(newNode); if (accept == NodeFilter.FILTER_ACCEPT) return newNode; else //if (accept == NodeFilter.SKIP_NODE) // and REJECT too. { return getParentNode(newNode); } }
Example #9
Source File: GenericTreeWalker.java From jStyleParser with GNU Lesser General Public License v3.0 | 6 votes |
/** * Internal function. Return the first child Node, from the input node after * applying filter, whatToshow. The current node is not consulted or set. */ private Node getFirstChild(Node node) { if (node == null) return null; Node newNode = node.getFirstChild(); if (newNode == null) return null; int accept = acceptNode(newNode); if (accept == NodeFilter.FILTER_ACCEPT) return newNode; else if (accept == NodeFilter.FILTER_SKIP && newNode.hasChildNodes()) return getFirstChild(newNode); // if (accept == NodeFilter.REJECT_NODE) return getNextSibling(newNode); }
Example #10
Source File: DOM3TreeWalker.java From openjdk-jdk9 with GNU General Public License v2.0 | 6 votes |
/** * Serializes an ProcessingInstruction Node. * * @param node The ProcessingInstruction Node to serialize */ protected void serializePI(ProcessingInstruction node) throws SAXException { ProcessingInstruction pi = node; String name = pi.getNodeName(); // well-formed=true if ((fFeatures & WELLFORMED) != 0) { isPIWellFormed(node); } // apply the LSSerializer filter if (!applyFilter(node, NodeFilter.SHOW_PROCESSING_INSTRUCTION)) { return; } // String data = pi.getData(); if (name.equals("xslt-next-is-raw")) { fNextIsRaw = true; } else { this.fSerializer.processingInstruction(name, pi.getData()); } }
Example #11
Source File: TreeWalkerImpl.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 5 votes |
/** Internal function. * Return the last child Node, from the input node * after applying filter, whatToshow. * The current node is not consulted or set. */ Node getLastChild(Node node) { if (node == null) return null; if ( !fEntityReferenceExpansion && node.getNodeType() == Node.ENTITY_REFERENCE_NODE) return null; Node newNode = node.getLastChild(); if (newNode == null) return null; int accept = acceptNode(newNode); if (accept == NodeFilter.FILTER_ACCEPT) return newNode; else if (accept == NodeFilter.FILTER_SKIP && newNode.hasChildNodes()) { Node lChild = getLastChild(newNode); if (lChild == null) { return getPreviousSibling(newNode, node); } return lChild; } else //if (accept == NodeFilter.REJECT_NODE) { return getPreviousSibling(newNode, node); } }
Example #12
Source File: XMLSerializer.java From openjdk-8-source with GNU General Public License v2.0 | 5 votes |
/** * Prints attribute. * NOTE: xml:space attribute modifies output format * * @param name * @param value * @param isSpecified * @exception IOException */ private void printAttribute (String name, String value, boolean isSpecified, Attr attr) throws IOException{ if (isSpecified || (features & DOMSerializerImpl.DISCARDDEFAULT) == 0) { if (fDOMFilter !=null && (fDOMFilter.getWhatToShow() & NodeFilter.SHOW_ATTRIBUTE)!= 0) { short code = fDOMFilter.acceptNode(attr); switch (code) { case NodeFilter.FILTER_REJECT: case NodeFilter.FILTER_SKIP: { return; } default: { // fall through } } } _printer.printSpace(); _printer.printText( name ); _printer.printText( "=\"" ); printEscaped( value ); _printer.printText( '"' ); } // If the attribute xml:space exists, determine whether // to preserve spaces in this and child nodes based on // its value. if (name.equals( "xml:space" )) { if (value.equals( "preserve" )) fPreserveSpace = true; else fPreserveSpace = _format.getPreserveSpace(); } }
Example #13
Source File: TreeWalkerImpl.java From hottub with GNU General Public License v2.0 | 5 votes |
/** Internal function. * Return the previousSibling Node, from the input node * after applying filter, whatToshow. * NEVER TRAVERSES ABOVE THE SPECIFIED ROOT NODE. * The current node is not consulted or set. */ Node getPreviousSibling(Node node, Node root) { if (node == null || node == root) return null; Node newNode = node.getPreviousSibling(); if (newNode == null) { newNode = node.getParentNode(); if (newNode == null || newNode == root) return null; int parentAccept = acceptNode(newNode); if (parentAccept==NodeFilter.FILTER_SKIP) { return getPreviousSibling(newNode, root); } return null; } int accept = acceptNode(newNode); if (accept == NodeFilter.FILTER_ACCEPT) return newNode; else if (accept == NodeFilter.FILTER_SKIP) { Node fChild = getLastChild(newNode); if (fChild == null) { return getPreviousSibling(newNode, root); } return fChild; } else //if (accept == NodeFilter.REJECT_NODE) { return getPreviousSibling(newNode, root); } }
Example #14
Source File: AddSpringBeanFilter.java From citrus-admin with Apache License 2.0 | 5 votes |
/** * {@inheritDoc} */ public short accept(Element element) { if (DomUtils.nodeNameEquals(element, "beans")) { element.appendChild(element.getOwnerDocument().createTextNode("\n ")); //TODO make indentation configurable element.appendChild(element.getOwnerDocument().importNode(beanDefinition, true)); } return NodeFilter.FILTER_ACCEPT; }
Example #15
Source File: TreeWalkerImpl.java From jdk1.8-source-analysis with Apache License 2.0 | 5 votes |
/** Internal function. * Return the previousSibling Node, from the input node * after applying filter, whatToshow. * NEVER TRAVERSES ABOVE THE SPECIFIED ROOT NODE. * The current node is not consulted or set. */ Node getPreviousSibling(Node node, Node root) { if (node == null || node == root) return null; Node newNode = node.getPreviousSibling(); if (newNode == null) { newNode = node.getParentNode(); if (newNode == null || newNode == root) return null; int parentAccept = acceptNode(newNode); if (parentAccept==NodeFilter.FILTER_SKIP) { return getPreviousSibling(newNode, root); } return null; } int accept = acceptNode(newNode); if (accept == NodeFilter.FILTER_ACCEPT) return newNode; else if (accept == NodeFilter.FILTER_SKIP) { Node fChild = getLastChild(newNode); if (fChild == null) { return getPreviousSibling(newNode, root); } return fChild; } else //if (accept == NodeFilter.REJECT_NODE) { return getPreviousSibling(newNode, root); } }
Example #16
Source File: XMLSerializer.java From JDKSourceCode1.8 with MIT License | 5 votes |
/** * Prints attribute. * NOTE: xml:space attribute modifies output format * * @param name * @param value * @param isSpecified * @exception IOException */ private void printAttribute (String name, String value, boolean isSpecified, Attr attr) throws IOException{ if (isSpecified || (features & DOMSerializerImpl.DISCARDDEFAULT) == 0) { if (fDOMFilter !=null && (fDOMFilter.getWhatToShow() & NodeFilter.SHOW_ATTRIBUTE)!= 0) { short code = fDOMFilter.acceptNode(attr); switch (code) { case NodeFilter.FILTER_REJECT: case NodeFilter.FILTER_SKIP: { return; } default: { // fall through } } } _printer.printSpace(); _printer.printText( name ); _printer.printText( "=\"" ); printEscaped( value ); _printer.printText( '"' ); } // If the attribute xml:space exists, determine whether // to preserve spaces in this and child nodes based on // its value. if (name.equals( "xml:space" )) { if (value.equals( "preserve" )) fPreserveSpace = true; else fPreserveSpace = _format.getPreserveSpace(); } }
Example #17
Source File: TreeWalkerImpl.java From JDKSourceCode1.8 with MIT License | 5 votes |
/** Internal function. * Return the nextSibling Node, from the input node * after applying filter, whatToshow. * NEVER TRAVERSES ABOVE THE SPECIFIED ROOT NODE. * The current node is not consulted or set. */ Node getNextSibling(Node node, Node root) { if (node == null || node == root) return null; Node newNode = node.getNextSibling(); if (newNode == null) { newNode = node.getParentNode(); if (newNode == null || newNode == root) return null; int parentAccept = acceptNode(newNode); if (parentAccept==NodeFilter.FILTER_SKIP) { return getNextSibling(newNode, root); } return null; } int accept = acceptNode(newNode); if (accept == NodeFilter.FILTER_ACCEPT) return newNode; else if (accept == NodeFilter.FILTER_SKIP) { Node fChild = getFirstChild(newNode); if (fChild == null) { return getNextSibling(newNode, root); } return fChild; } else //if (accept == NodeFilter.REJECT_NODE) { return getNextSibling(newNode, root); } }
Example #18
Source File: TreeWalkerImpl.java From openjdk-8 with GNU General Public License v2.0 | 5 votes |
/** Public constructor */ public TreeWalkerImpl(Node root, int whatToShow, NodeFilter nodeFilter, boolean entityReferenceExpansion) { fCurrentNode = root; fRoot = root; fWhatToShow = whatToShow; fNodeFilter = nodeFilter; fEntityReferenceExpansion = entityReferenceExpansion; }
Example #19
Source File: MBUtils.java From container with Apache License 2.0 | 5 votes |
/** * Transfers the properties document to a map. * * @param propertiesDocument to be transfered to a map. * @return transfered map. */ public static HashMap<String, String> docToMap(final Document propertiesDocument, final boolean allowEmptyEntries) { final HashMap<String, String> reponseMap = new HashMap<>(); final DocumentTraversal traversal = (DocumentTraversal) propertiesDocument; final NodeIterator iterator = traversal.createNodeIterator(propertiesDocument.getDocumentElement(), NodeFilter.SHOW_ELEMENT, null, true); for (Node node = iterator.nextNode(); node != null; node = iterator.nextNode()) { final String name = ((Element) node).getLocalName(); final StringBuilder content = new StringBuilder(); final NodeList children = node.getChildNodes(); for (int i = 0; i < children.getLength(); i++) { final Node child = children.item(i); if (child.getNodeType() == Node.TEXT_NODE) { content.append(child.getTextContent()); } } if (allowEmptyEntries) { reponseMap.put(name, content.toString()); } else { if (!content.toString().trim().isEmpty()) { reponseMap.put(name, content.toString()); } } } return reponseMap; }
Example #20
Source File: TreeWalkerImpl.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
/** Public constructor */ public TreeWalkerImpl(Node root, int whatToShow, NodeFilter nodeFilter, boolean entityReferenceExpansion) { fCurrentNode = root; fRoot = root; fWhatToShow = whatToShow; fNodeFilter = nodeFilter; fEntityReferenceExpansion = entityReferenceExpansion; }
Example #21
Source File: LSParserTCKTest.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
/** * Equivalence class partitioning * with state, input and output values orientation * for public Document parse(LSInput is), * <br><b>pre-conditions</b>: set filter that REJECTs any CHILD* node, * <br><b>is</b>: xml1 * <br><b>output</b>: XML document with ELEMNENT1 and ELEMENT2 only. */ @Test public void testfilter0001() { LSParser parser = createLSParser(); if (parser == null) { Assert.fail("Unable to create LSParser!"); } // set filter parser.setFilter(new LSParserFilter() { public short startElement(Element elt) { return FILTER_ACCEPT; } public short acceptNode(Node enode) { if (enode.getNodeName().startsWith("CHILD")) { return FILTER_REJECT; } return FILTER_ACCEPT; } public int getWhatToShow() { return NodeFilter.SHOW_ALL; } }); String expected = "<?xml version=\"1.0\"?><ROOT><ELEMENT1></ELEMENT1><ELEMENT2>test1</ELEMENT2></ROOT>"; Document doc = parser.parse(getXmlSource(xml1)); if (!match(expected, doc)) { Assert.fail("DOM structure after parsing is not equal to a structure of XML document, that being parsed"); } System.out.println("OKAY"); }
Example #22
Source File: TreeWalkerImpl.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 5 votes |
/** Internal function. * Return the first child Node, from the input node * after applying filter, whatToshow. * The current node is not consulted or set. */ Node getFirstChild(Node node) { if (node == null) return null; if ( !fEntityReferenceExpansion && node.getNodeType() == Node.ENTITY_REFERENCE_NODE) return null; Node newNode = node.getFirstChild(); if (newNode == null) return null; int accept = acceptNode(newNode); if (accept == NodeFilter.FILTER_ACCEPT) return newNode; else if (accept == NodeFilter.FILTER_SKIP && newNode.hasChildNodes()) { Node fChild = getFirstChild(newNode); if (fChild == null) { return getNextSibling(newNode, node); } return fChild; } else //if (accept == NodeFilter.REJECT_NODE) { return getNextSibling(newNode, node); } }
Example #23
Source File: XMLSerializer.java From Bytecoder with Apache License 2.0 | 5 votes |
/** * Prints attribute. * NOTE: xml:space attribute modifies output format * * @param name * @param value * @param isSpecified * @exception IOException */ private void printAttribute (String name, String value, boolean isSpecified, Attr attr) throws IOException{ if (isSpecified || (features & DOMSerializerImpl.DISCARDDEFAULT) == 0) { if (fDOMFilter !=null && (fDOMFilter.getWhatToShow() & NodeFilter.SHOW_ATTRIBUTE)!= 0) { short code = fDOMFilter.acceptNode(attr); switch (code) { case NodeFilter.FILTER_REJECT: case NodeFilter.FILTER_SKIP: { return; } default: { // fall through } } } _printer.printSpace(); _printer.printText( name ); _printer.printText( "=\"" ); printEscaped( value ); _printer.printText( '"' ); } // If the attribute xml:space exists, determine whether // to preserve spaces in this and child nodes based on // its value. if (name.equals( "xml:space" )) { if (value.equals( "preserve" )) fPreserveSpace = true; else fPreserveSpace = _format.getPreserveSpace(); } }
Example #24
Source File: NodeTest.java From xmlunit with Apache License 2.0 | 5 votes |
/** * NodeFilter method. * @param aNode * @return */ public short acceptNode(Node aNode) { if (acceptNodeType(aNode.getNodeType())) { return NodeFilter.FILTER_ACCEPT; } return NodeFilter.FILTER_REJECT; }
Example #25
Source File: XMLSerializer.java From openjdk-8 with GNU General Public License v2.0 | 5 votes |
/** * Prints attribute. * NOTE: xml:space attribute modifies output format * * @param name * @param value * @param isSpecified * @exception IOException */ private void printAttribute (String name, String value, boolean isSpecified, Attr attr) throws IOException{ if (isSpecified || (features & DOMSerializerImpl.DISCARDDEFAULT) == 0) { if (fDOMFilter !=null && (fDOMFilter.getWhatToShow() & NodeFilter.SHOW_ATTRIBUTE)!= 0) { short code = fDOMFilter.acceptNode(attr); switch (code) { case NodeFilter.FILTER_REJECT: case NodeFilter.FILTER_SKIP: { return; } default: { // fall through } } } _printer.printSpace(); _printer.printText( name ); _printer.printText( "=\"" ); printEscaped( value ); _printer.printText( '"' ); } // If the attribute xml:space exists, determine whether // to preserve spaces in this and child nodes based on // its value. if (name.equals( "xml:space" )) { if (value.equals( "preserve" )) fPreserveSpace = true; else fPreserveSpace = _format.getPreserveSpace(); } }
Example #26
Source File: TreeWalkerImpl.java From openjdk-jdk8u with GNU General Public License v2.0 | 5 votes |
/** Public constructor */ public TreeWalkerImpl(Node root, int whatToShow, NodeFilter nodeFilter, boolean entityReferenceExpansion) { fCurrentNode = root; fRoot = root; fWhatToShow = whatToShow; fNodeFilter = nodeFilter; fEntityReferenceExpansion = entityReferenceExpansion; }
Example #27
Source File: TreeWalkerImpl.java From openjdk-8-source with GNU General Public License v2.0 | 5 votes |
/** Internal function. * Return the nextSibling Node, from the input node * after applying filter, whatToshow. * NEVER TRAVERSES ABOVE THE SPECIFIED ROOT NODE. * The current node is not consulted or set. */ Node getNextSibling(Node node, Node root) { if (node == null || node == root) return null; Node newNode = node.getNextSibling(); if (newNode == null) { newNode = node.getParentNode(); if (newNode == null || newNode == root) return null; int parentAccept = acceptNode(newNode); if (parentAccept==NodeFilter.FILTER_SKIP) { return getNextSibling(newNode, root); } return null; } int accept = acceptNode(newNode); if (accept == NodeFilter.FILTER_ACCEPT) return newNode; else if (accept == NodeFilter.FILTER_SKIP) { Node fChild = getFirstChild(newNode); if (fChild == null) { return getNextSibling(newNode, root); } return fChild; } else //if (accept == NodeFilter.REJECT_NODE) { return getNextSibling(newNode, root); } }
Example #28
Source File: TreeWalkerImpl.java From jdk8u60 with GNU General Public License v2.0 | 5 votes |
/** Internal function. * Return the first child Node, from the input node * after applying filter, whatToshow. * The current node is not consulted or set. */ Node getFirstChild(Node node) { if (node == null) return null; if ( !fEntityReferenceExpansion && node.getNodeType() == Node.ENTITY_REFERENCE_NODE) return null; Node newNode = node.getFirstChild(); if (newNode == null) return null; int accept = acceptNode(newNode); if (accept == NodeFilter.FILTER_ACCEPT) return newNode; else if (accept == NodeFilter.FILTER_SKIP && newNode.hasChildNodes()) { Node fChild = getFirstChild(newNode); if (fChild == null) { return getNextSibling(newNode, node); } return fChild; } else //if (accept == NodeFilter.REJECT_NODE) { return getNextSibling(newNode, node); } }
Example #29
Source File: DomTreeWalker.java From htmlunit with Apache License 2.0 | 5 votes |
/** * Returns whether the node is visible by the TreeWalker. */ private boolean isNodeVisible(final Node n) { if (acceptNode(n) == NodeFilter.FILTER_ACCEPT) { if (filter_ == null || filter_.acceptNode(n) == NodeFilter.FILTER_ACCEPT) { return expandEntityReferences_ || n.getParentNode() == null || n.getParentNode().getNodeType() != Node.ENTITY_REFERENCE_NODE; } } return false; }
Example #30
Source File: NodeIteratorImpl.java From JDKSourceCode1.8 with MIT License | 5 votes |
/** The node is accepted if it passes the whatToShow and the filter. */ boolean acceptNode(Node node) { if (fNodeFilter == null) { return ( fWhatToShow & (1 << node.getNodeType()-1)) != 0 ; } else { return ((fWhatToShow & (1 << node.getNodeType()-1)) != 0 ) && fNodeFilter.acceptNode(node) == NodeFilter.FILTER_ACCEPT; } }