Java Code Examples for org.w3c.dom.Node#ELEMENT_NODE
The following examples show how to use
org.w3c.dom.Node#ELEMENT_NODE .
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: KeyInfo.java From openjdk-8-source with GNU General Public License v2.0 | 6 votes |
/** * Method lengthUnknownElement * NOTE possibly buggy. * @return the number of the UnknownElement tags */ public int lengthUnknownElement() { int res = 0; NodeList nl = this.constructionElement.getChildNodes(); for (int i = 0; i < nl.getLength(); i++) { Node current = nl.item(i); /** * $todo$ using this method, we don't see unknown Elements * from Signature NS; revisit */ if ((current.getNodeType() == Node.ELEMENT_NODE) && current.getNamespaceURI().equals(Constants.SignatureSpecNS)) { res++; } } return res; }
Example 2
Source File: KeyInfo.java From openjdk-8 with GNU General Public License v2.0 | 6 votes |
/** * Method lengthUnknownElement * NOTE possibly buggy. * @return the number of the UnknownElement tags */ public int lengthUnknownElement() { int res = 0; NodeList nl = this.constructionElement.getChildNodes(); for (int i = 0; i < nl.getLength(); i++) { Node current = nl.item(i); /** * $todo$ using this method, we don't see unknown Elements * from Signature NS; revisit */ if ((current.getNodeType() == Node.ELEMENT_NODE) && current.getNamespaceURI().equals(Constants.SignatureSpecNS)) { res++; } } return res; }
Example 3
Source File: DOMDocumentSerializer.java From TencentKona-8 with GNU General Public License v2.0 | 6 votes |
/** * Serialize a {@link Document}. * * @param d the document to serialize. */ public final void serialize(Document d) throws IOException { reset(); encodeHeader(false); encodeInitialVocabulary(); final NodeList nl = d.getChildNodes(); for (int i = 0; i < nl.getLength(); i++) { final Node n = nl.item(i); switch (n.getNodeType()) { case Node.ELEMENT_NODE: serializeElement(n); break; case Node.COMMENT_NODE: serializeComment(n); break; case Node.PROCESSING_INSTRUCTION_NODE: serializeProcessingInstruction(n); break; } } encodeDocumentTermination(); }
Example 4
Source File: MyBatisGeneratorConfigurationParser.java From mybatis-generator-core-fix with Apache License 2.0 | 6 votes |
private void parseJavaTypeResolver(Context context, Node node) { JavaTypeResolverConfiguration javaTypeResolverConfiguration = new JavaTypeResolverConfiguration(); context.setJavaTypeResolverConfiguration(javaTypeResolverConfiguration); Properties attributes = parseAttributes(node); String type = attributes.getProperty("type"); //$NON-NLS-1$ if (stringHasValue(type)) { javaTypeResolverConfiguration.setConfigurationType(type); } NodeList nodeList = node.getChildNodes(); for (int i = 0; i < nodeList.getLength(); i++) { Node childNode = nodeList.item(i); if (childNode.getNodeType() != Node.ELEMENT_NODE) { continue; } if ("property".equals(childNode.getNodeName())) { //$NON-NLS-1$ parseProperty(javaTypeResolverConfiguration, childNode); } } }
Example 5
Source File: ActionMappingScanner.java From netbeans with Apache License 2.0 | 6 votes |
/** * Scan through Element named apply-for. */ void visitElement_apply_for(Element element) { // <apply-for> // element.getValue(); withPlugins = new LinkedHashSet<>(); String plugins = element.getAttribute("plugins"); if (plugins != null) { withPlugins.addAll(Arrays.asList(plugins.split(",\\s*"))); } NodeList nodes = element.getChildNodes(); for (int i = 0; i < nodes.getLength(); i++) { Node node = nodes.item(i); if (node.getNodeType() == Node.ELEMENT_NODE) { Element nodeElement = (Element) node; if (nodeElement.getTagName().equals("action")) { visitElement_action(nodeElement); } } } withPlugins = Collections.<String>emptySet(); }
Example 6
Source File: Xml.java From RADL with Apache License 2.0 | 6 votes |
private static void append(Node node, int indentationLevel, Map<String, String> namespaces, StringBuilder builder) { switch (node.getNodeType()) { case Node.DOCUMENT_NODE: appendDocument(node, indentationLevel, namespaces, builder); break; case Node.ELEMENT_NODE: appendElement(node, indentationLevel, namespaces, builder); break; case Node.ATTRIBUTE_NODE: appendAttribute(node, namespaces, builder); break; case Node.TEXT_NODE: appendText(node, builder); break; case Node.COMMENT_NODE: appendComment(node, indentationLevel, builder); break; default: throw new UnsupportedOperationException("Unhandled node type: " + node.getNodeType()); } }
Example 7
Source File: XmlElement.java From buck with Apache License 2.0 | 5 votes |
private Optional<String> findAndCompareNode( @NonNull XmlElement otherElement, @NonNull List<Node> otherElementChildren, @NonNull XmlElement childNode) { Optional<String> message = Optional.absent(); for (Node potentialNode : otherElementChildren) { if (potentialNode.getNodeType() == Node.ELEMENT_NODE) { @NonNull XmlElement otherChildNode = new XmlElement((Element) potentialNode, mDocument); if (childNode.getType() == otherChildNode.getType()) { // check if this element uses a key. if (childNode.getType().getNodeKeyResolver().getKeyAttributesNames() .isEmpty()) { // no key... try all the other elements, if we find one equal, we are done. message = childNode.compareTo(otherChildNode); if (!message.isPresent()) { return Optional.absent(); } } else { // key... if (childNode.getKey() == null) { // other key MUST also be null. if (otherChildNode.getKey() == null) { return childNode.compareTo(otherChildNode); } } else { if (childNode.getKey().equals(otherChildNode.getKey())) { return childNode.compareTo(otherChildNode); } } } } } } return message.isPresent() ? message : Optional.of(String.format("Child %1$s not found in document %2$s", childNode.getId(), otherElement.printPosition())); }
Example 8
Source File: ManifestMerger.java From java-n-IDE-for-Android with Apache License 2.0 | 5 votes |
/** * Checks whether the given element has a tools:merge=override or tools:merge=remove attribute. * @param node The node to check. * @return True if the element has a tools:merge=override or tools:merge=remove attribute. */ private boolean hasOverrideOrRemoveTag(@Nullable Node node) { if (node == null || node.getNodeType() != Node.ELEMENT_NODE) { return false; } NamedNodeMap attrs = node.getAttributes(); Node merge = attrs.getNamedItemNS(TOOLS_URI, MERGE_ATTR); String value = merge == null ? null : merge.getNodeValue(); return MERGE_OVERRIDE.equals(value) || MERGE_REMOVE.equals(value); }
Example 9
Source File: TorqueXmlParser.java From xenon with Apache License 2.0 | 5 votes |
/** * Parses job info from "qstat -x" * * @param data * the stream to get the xml data from * @return a list containing all queue names found * @throws XenonException * if the file could not be parsed * @throws XenonException * if the server version is not compatible with this adaptor */ protected Map<String, Map<String, String>> parseJobInfos(String data) throws XenonException { if (data.trim().isEmpty()) { return new HashMap<>(); } Document document = parseDocument(data); LOGGER.debug("root node of xml file: " + document.getDocumentElement().getNodeName()); NodeList nodes = document.getDocumentElement().getChildNodes(); int numNodes = nodes.getLength(); Map<String, Map<String, String>> result = new HashMap<>(); for (int i = 0; i < numNodes; i++) { Node node = nodes.item(i); if (node.getNodeType() == Node.ELEMENT_NODE) { Map<String, String> jobInfo = new HashMap<>(); recursiveMapFromElement(node, jobInfo); String jobId = jobInfo.get("Job_Id"); if (jobId == null || jobId.isEmpty()) { throw new XenonException(ADAPTOR_NAME, "found job in queue with no job number"); } result.put(jobId, jobInfo); } } return result; }
Example 10
Source File: RelTagParser.java From anthelion with Apache License 2.0 | 5 votes |
void parse(Node node) { if (node.getNodeType() == Node.ELEMENT_NODE) { // Look for <a> tag if ("a".equalsIgnoreCase(node.getNodeName())) { NamedNodeMap attrs = node.getAttributes(); Node hrefNode = attrs.getNamedItem("href"); // Checks that it contains a href attribute if (hrefNode != null) { Node relNode = attrs.getNamedItem("rel"); // Checks that it contains a rel attribute too if (relNode != null) { // Finaly checks that rel=tag if ("tag".equalsIgnoreCase(relNode.getNodeValue())) { String tag = parseTag(hrefNode.getNodeValue()); if (!StringUtil.isEmpty(tag)) { tags.add(tag); } } } } } } // Recurse NodeList children = node.getChildNodes(); for (int i=0; children != null && i<children.getLength(); i++) { parse(children.item(i)); } }
Example 11
Source File: Body1_2Impl.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
private boolean hasAnyChildElement() { Node currentNode = getFirstChild(); while (currentNode != null) { if (currentNode.getNodeType() == Node.ELEMENT_NODE) return true; currentNode = currentNode.getNextSibling(); } return false; }
Example 12
Source File: ClientODataDeserializerImpl.java From olingo-odata4 with Apache License 2.0 | 4 votes |
private List<List<String>> getAllSchemaNameSpace(InputStream inputStream) throws ParserConfigurationException, SAXException, IOException{ List<List<String>> schemaNameSpaces = new ArrayList <>(); DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance(); dbFactory.setFeature( "http://xml.org/sax/features/namespaces", true); dbFactory.setFeature( "http://apache.org/xml/features/validation/schema", false); dbFactory.setFeature( "http://apache.org/xml/features/validation/schema-full-checking", true); dbFactory.setFeature( "http://xml.org/sax/features/external-general-entities", false); dbFactory.setFeature( "http://xml.org/sax/features/external-parameter-entities", false); dbFactory.setFeature( "http://apache.org/xml/features/disallow-doctype-decl", true); dbFactory.setFeature( "http://javax.xml.XMLConstants/feature/secure-processing", true); DocumentBuilder dBuilder = dbFactory.newDocumentBuilder(); Document doc = dBuilder.parse(inputStream); doc.getDocumentElement().normalize(); NodeList nList = doc.getElementsByTagName(SCHEMA); for (int temp = 0; temp < nList.getLength(); temp++) { Node nNode = nList.item(temp); List<String> nameSpaces = new ArrayList <>(); if (nNode.getNodeType() == Node.ELEMENT_NODE) { Element eElement = (Element) nNode; NamedNodeMap attributes = eElement.getAttributes(); int len = attributes.getLength(); for(int i =0;i<len;i++){ // check for all atributes begining with name xmlns or xmlns: String attrName = attributes.item(i).getNodeName(); if( XMLNS.equals(attrName) || attrName.startsWith(XMLNS+":")){ nameSpaces.add(attributes.item(i).getNodeValue()); } } } schemaNameSpaces.add(nameSpaces); } return schemaNameSpaces; }
Example 13
Source File: DOM2DTMdefaultNamespaceDeclarationNode.java From openjdk-jdk9 with GNU General Public License v2.0 | 4 votes |
/** * * DOM Level 3 - Experimental: * Look up the prefix associated to the given namespace URI, starting from this node. * * @param namespaceURI * @return the prefix for the namespace */ public String lookupPrefix(String namespaceURI){ // REVISIT: When Namespaces 1.1 comes out this may not be true // Prefix can't be bound to null namespace if (namespaceURI == null) { return null; } short type = this.getNodeType(); switch (type) { /* case Node.ELEMENT_NODE: { String namespace = this.getNamespaceURI(); // to flip out children return lookupNamespacePrefix(namespaceURI, (ElementImpl)this); } case Node.DOCUMENT_NODE:{ return((NodeImpl)((Document)this).getDocumentElement()).lookupPrefix(namespaceURI); } */ case Node.ENTITY_NODE : case Node.NOTATION_NODE: case Node.DOCUMENT_FRAGMENT_NODE: case Node.DOCUMENT_TYPE_NODE: // type is unknown return null; case Node.ATTRIBUTE_NODE:{ if (this.getOwnerElement().getNodeType() == Node.ELEMENT_NODE) { return getOwnerElement().lookupPrefix(namespaceURI); } return null; } default:{ /* NodeImpl ancestor = (NodeImpl)getElementAncestor(this); if (ancestor != null) { return ancestor.lookupPrefix(namespaceURI); } */ return null; } } }
Example 14
Source File: DTMNodeProxy.java From JDKSourceCode1.8 with MIT License | 4 votes |
/** * * DOM Level 3 * Look up the prefix associated to the given namespace URI, starting from this node. * * @param namespaceURI * @return the prefix for the namespace */ @Override public String lookupPrefix(String namespaceURI){ // REVISIT: When Namespaces 1.1 comes out this may not be true // Prefix can't be bound to null namespace if (namespaceURI == null) { return null; } short type = this.getNodeType(); switch (type) { /* case Node.ELEMENT_NODE: { String namespace = this.getNamespaceURI(); // to flip out children return lookupNamespacePrefix(namespaceURI, (ElementImpl)this); } case Node.DOCUMENT_NODE:{ return((NodeImpl)((Document)this).getDocumentElement()).lookupPrefix(namespaceURI); } */ case Node.ENTITY_NODE : case Node.NOTATION_NODE: case Node.DOCUMENT_FRAGMENT_NODE: case Node.DOCUMENT_TYPE_NODE: // type is unknown return null; case Node.ATTRIBUTE_NODE:{ if (this.getOwnerElement().getNodeType() == Node.ELEMENT_NODE) { return getOwnerElement().lookupPrefix(namespaceURI); } return null; } default:{ /* NodeImpl ancestor = (NodeImpl)getElementAncestor(this); if (ancestor != null) { return ancestor.lookupPrefix(namespaceURI); } */ return null; } } }
Example 15
Source File: ResourceItem.java From javaide with GNU General Public License v3.0 | 4 votes |
@NonNull private static String getMarkupText(@NonNull NodeList children) { StringBuilder sb = new StringBuilder(); for (int i = 0, n = children.getLength(); i < n; i++) { Node child = children.item(i); short nodeType = child.getNodeType(); switch (nodeType) { case Node.ELEMENT_NODE: { Element element = (Element) child; String tagName = element.getTagName(); sb.append('<'); sb.append(tagName); NamedNodeMap attributes = element.getAttributes(); int attributeCount = attributes.getLength(); if (attributeCount > 0) { for (int j = 0; j < attributeCount; j++) { Node attribute = attributes.item(j); sb.append(' '); sb.append(attribute.getNodeName()); sb.append('=').append('"'); XmlUtils.appendXmlAttributeValue(sb, attribute.getNodeValue()); sb.append('"'); } } sb.append('>'); NodeList childNodes = child.getChildNodes(); if (childNodes.getLength() > 0) { sb.append(getMarkupText(childNodes)); } sb.append('<'); sb.append('/'); sb.append(tagName); sb.append('>'); break; } case Node.TEXT_NODE: sb.append(child.getNodeValue()); break; case Node.CDATA_SECTION_NODE: sb.append(child.getNodeValue()); break; } } return sb.toString(); }
Example 16
Source File: XMLUtils.java From hottub with GNU General Public License v2.0 | 4 votes |
/** * This method is a tree-search to help prevent against wrapping attacks. It checks that no other * Element than the given "knownElement" argument has an ID attribute that matches the "value" * argument, which is the ID value of "knownElement". If this is the case then "false" is returned. */ public static boolean protectAgainstWrappingAttack( Node startNode, Element knownElement, String value ) { Node startParent = startNode.getParentNode(); Node processedNode = null; String id = value.trim(); if (!id.isEmpty() && id.charAt(0) == '#') { id = id.substring(1); } while (startNode != null) { if (startNode.getNodeType() == Node.ELEMENT_NODE) { Element se = (Element) startNode; NamedNodeMap attributes = se.getAttributes(); if (attributes != null) { for (int i = 0; i < attributes.getLength(); i++) { Attr attr = (Attr)attributes.item(i); if (attr.isId() && id.equals(attr.getValue()) && se != knownElement) { log.log(java.util.logging.Level.FINE, "Multiple elements with the same 'Id' attribute value!"); return false; } } } } processedNode = startNode; startNode = startNode.getFirstChild(); // no child, this node is done. if (startNode == null) { // close node processing, get sibling startNode = processedNode.getNextSibling(); } // no more siblings, get parent, all children // of parent are processed. while (startNode == null) { processedNode = processedNode.getParentNode(); if (processedNode == startParent) { return true; } // close parent node processing (processed node now) startNode = processedNode.getNextSibling(); } } return true; }
Example 17
Source File: DTMNodeProxy.java From jdk8u60 with GNU General Public License v2.0 | 4 votes |
/** * DOM Level 3 * Look up the namespace URI associated to the given prefix, starting from this node. * Use lookupNamespaceURI(null) to lookup the default namespace * * @param namespaceURI * @return th URI for the namespace * @since DOM Level 3 */ @Override public String lookupNamespaceURI(String specifiedPrefix) { short type = this.getNodeType(); switch (type) { case Node.ELEMENT_NODE : { String namespace = this.getNamespaceURI(); String prefix = this.getPrefix(); if (namespace !=null) { // REVISIT: is it possible that prefix is empty string? if (specifiedPrefix== null && prefix==specifiedPrefix) { // looking for default namespace return namespace; } else if (prefix != null && prefix.equals(specifiedPrefix)) { // non default namespace return namespace; } } if (this.hasAttributes()) { NamedNodeMap map = this.getAttributes(); int length = map.getLength(); for (int i=0;i<length;i++) { Node attr = map.item(i); String attrPrefix = attr.getPrefix(); String value = attr.getNodeValue(); namespace = attr.getNamespaceURI(); if (namespace !=null && namespace.equals("http://www.w3.org/2000/xmlns/")) { // at this point we are dealing with DOM Level 2 nodes only if (specifiedPrefix == null && attr.getNodeName().equals("xmlns")) { // default namespace return value; } else if (attrPrefix !=null && attrPrefix.equals("xmlns") && attr.getLocalName().equals(specifiedPrefix)) { // non default namespace return value; } } } } /* NodeImpl ancestor = (NodeImpl)getElementAncestor(this); if (ancestor != null) { return ancestor.lookupNamespaceURI(specifiedPrefix); } */ return null; } /* case Node.DOCUMENT_NODE : { return((NodeImpl)((Document)this).getDocumentElement()).lookupNamespaceURI(specifiedPrefix) ; } */ case Node.ENTITY_NODE : case Node.NOTATION_NODE: case Node.DOCUMENT_FRAGMENT_NODE: case Node.DOCUMENT_TYPE_NODE: // type is unknown return null; case Node.ATTRIBUTE_NODE:{ if (this.getOwnerElement().getNodeType() == Node.ELEMENT_NODE) { return getOwnerElement().lookupNamespaceURI(specifiedPrefix); } return null; } default:{ /* NodeImpl ancestor = (NodeImpl)getElementAncestor(this); if (ancestor != null) { return ancestor.lookupNamespaceURI(specifiedPrefix); } */ return null; } } }
Example 18
Source File: CDANarrativeFormat.java From org.hl7.fhir.core with Apache License 2.0 | 4 votes |
private void processChildNode(Node n, XhtmlNode xn) throws FHIRException { switch (n.getNodeType()) { case Node.ATTRIBUTE_NODE: case Node.CDATA_SECTION_NODE: case Node.DOCUMENT_FRAGMENT_NODE: case Node.DOCUMENT_TYPE_NODE: case Node.DOCUMENT_NODE: case Node.ENTITY_NODE: case Node.PROCESSING_INSTRUCTION_NODE: case Node.NOTATION_NODE: return; case Node.ENTITY_REFERENCE_NODE: throw new Error("Not handled yet"); case Node.COMMENT_NODE: xn.addComment(n.getTextContent()); return; case Node.TEXT_NODE: if (!Utilities.isWhitespace(n.getTextContent())) xn.addText(n.getTextContent()); return; case Node.ELEMENT_NODE: Element e = (Element) n; if (n.getNodeName().equals("br")) processBreak(e, xn); else if (n.getNodeName().equals("caption")) processCaption(e, xn); else if (n.getNodeName().equals("col")) processCol(e, xn); else if (n.getNodeName().equals("colgroup")) processColGroup(e, xn); else if (n.getNodeName().equals("content")) processContent(e, xn); else if (n.getNodeName().equals("footnote")) processFootNote(e, xn); else if (n.getNodeName().equals("footnoteRef")) processFootNodeRef(e, xn); else if (n.getNodeName().equals("item")) processItem(e, xn); else if (n.getNodeName().equals("linkHtml")) processlinkHtml(e, xn); else if (n.getNodeName().equals("list")) processList(e, xn); else if (n.getNodeName().equals("paragraph")) processParagraph(e, xn); else if (n.getNodeName().equals("renderMultiMedia")) processRenderMultiMedia(e, xn); else if (n.getNodeName().equals("sub")) processSub(e, xn); else if (n.getNodeName().equals("sup")) processSup(e, xn); else if (n.getNodeName().equals("table")) processTable(e, xn); else if (n.getNodeName().equals("tbody")) processTBody(e, xn); else if (n.getNodeName().equals("td")) processTd(e, xn); else if (n.getNodeName().equals("tfoot")) processTFoot(e, xn); else if (n.getNodeName().equals("th")) processTh(e, xn); else if (n.getNodeName().equals("thead")) processTHead(e, xn); else if (n.getNodeName().equals("tr")) processTr(e, xn); else throw new FHIRException("Unknown element "+n.getNodeName()); } }
Example 19
Source File: DOMKeyInfo.java From openjdk-jdk8u with GNU General Public License v2.0 | 4 votes |
/** * Creates a <code>DOMKeyInfo</code> from XML. * * @param kiElem KeyInfo element */ public DOMKeyInfo(Element kiElem, XMLCryptoContext context, Provider provider) throws MarshalException { // get Id attribute, if specified Attr attr = kiElem.getAttributeNodeNS(null, "Id"); if (attr != null) { id = attr.getValue(); kiElem.setIdAttributeNode(attr, true); } else { id = null; } // get all children nodes NodeList nl = kiElem.getChildNodes(); int length = nl.getLength(); if (length < 1) { throw new MarshalException ("KeyInfo must contain at least one type"); } List<XMLStructure> content = new ArrayList<XMLStructure>(length); for (int i = 0; i < length; i++) { Node child = nl.item(i); // ignore all non-Element nodes if (child.getNodeType() != Node.ELEMENT_NODE) { continue; } Element childElem = (Element)child; String localName = childElem.getLocalName(); if (localName.equals("X509Data")) { content.add(new DOMX509Data(childElem)); } else if (localName.equals("KeyName")) { content.add(new DOMKeyName(childElem)); } else if (localName.equals("KeyValue")) { content.add(DOMKeyValue.unmarshal(childElem)); } else if (localName.equals("RetrievalMethod")) { content.add(new DOMRetrievalMethod(childElem, context, provider)); } else if (localName.equals("PGPData")) { content.add(new DOMPGPData(childElem)); } else { //may be MgmtData, SPKIData or element from other namespace content.add(new javax.xml.crypto.dom.DOMStructure((childElem))); } } keyInfoTypes = Collections.unmodifiableList(content); }
Example 20
Source File: DOMUtils.java From openjdk-jdk9 with GNU General Public License v2.0 | 3 votes |
/** * Returns the last child element of the specified node, or null if there * is no such element. * * @param node the node * @return the last child element of the specified node, or null if there * is no such element * @throws NullPointerException if <code>node == null</code> */ public static Element getLastChildElement(Node node) { Node child = node.getLastChild(); while (child != null && child.getNodeType() != Node.ELEMENT_NODE) { child = child.getPreviousSibling(); } return (Element)child; }