List of usage examples for org.w3c.dom Node getNextSibling
public Node getNextSibling();
From source file:uk.co.markfrimston.tasktree.TaskTree.java
protected boolean nodesEqual(Node a, Node b) { if ((a == null) != (b == null)) { return false; }/*w ww .j a va2 s . c o m*/ if (a != null) { if (a.getNodeType() != b.getNodeType()) { return false; } if ((a.getNodeName() == null) != (b.getNodeName() == null)) { return false; } if (a.getNodeName() != null && !a.getNodeName().equals(b.getNodeName())) { return false; } if ((a.getNodeValue() == null) != (b.getNodeValue() == null)) { return false; } if (a.getNodeValue() != null && !a.getNodeValue().equals(b.getNodeValue())) { return false; } NamedNodeMap attrsA = a.getAttributes(); Map<String, String> attrMapA = new HashMap<String, String>(); if (attrsA != null) { for (int i = 0; i < attrsA.getLength(); i++) { Attr att = (Attr) attrsA.item(i); attrMapA.put(att.getName(), att.getValue()); } } NamedNodeMap attrsB = b.getAttributes(); Map<String, String> attrMapB = new HashMap<String, String>(); if (attrsB != null) { for (int i = 0; i < attrsB.getLength(); i++) { Attr att = (Attr) attrsB.item(i); attrMapB.put(att.getName(), att.getValue()); } } if (!attrMapA.equals(attrMapB)) { return false; } Node childA = a.getFirstChild(); Node childB = b.getFirstChild(); while (childA != null) { if (!nodesEqual(childA, childB)) { return false; } childA = childA.getNextSibling(); childB = childB.getNextSibling(); } if (childB != null) { return false; } } return true; }
From source file:DomPrintUtil.java
private Node getVisibleNextSibling(Node target, Node root) { if (target == root) { return null; }// w w w . jav a 2 s . co m Node tmpN = target.getNextSibling(); if (null == tmpN) { Node tmpP = target.getParentNode(); if (eval(tmpP) == NodeFilter.FILTER_SKIP) { return getVisibleNextSibling(tmpP, root); } return null; } switch (eval(tmpN)) { case NodeFilter.FILTER_ACCEPT: return tmpN; case NodeFilter.FILTER_SKIP: Node tmpC = getVisibleFirstChild(tmpN); if (null != tmpC) { return tmpC; } // case NodeFilter.FILTER_REJECT: default: return getVisibleNextSibling(tmpN, root); } }
From source file:it.cnr.icar.eric.server.common.Utility.java
public org.w3c.dom.Element getSignatureElement(SOAPMessage msg) throws javax.xml.soap.SOAPException, javax.xml.transform.TransformerException { org.w3c.dom.Element sigElement = null; javax.xml.transform.Transformer xFormer = javax.xml.transform.TransformerFactory.newInstance() .newTransformer();/*from w w w . j ava 2 s .c o m*/ // grab info out of msg javax.xml.soap.SOAPPart msgPart = msg.getSOAPPart(); javax.xml.transform.Source msgSource = msgPart.getContent(); // transform javax.xml.transform.dom.DOMResult domResult = new javax.xml.transform.dom.DOMResult(); xFormer.transform(msgSource, domResult); //root node is the soap:Envelope Node envelopeNode = domResult.getNode(); //now you have the node. the following code strips off the envelope of //the soap message to get to the actual content // Advance to envelope node in case of text nodes preceding it while ((envelopeNode.getLocalName() == null) || (!envelopeNode.getLocalName().equalsIgnoreCase("envelope"))) { envelopeNode = envelopeNode.getFirstChild(); } // Advance to header within envelope node Node headerNode = envelopeNode.getFirstChild(); while ((headerNode.getLocalName() == null) || (!headerNode.getLocalName().equalsIgnoreCase("header"))) { headerNode = headerNode.getNextSibling(); } //System.err.println("headerNode name is: " + headerNode.getLocalName()); // Advance to signature node within header Node sigNode = headerNode.getFirstChild(); if (sigNode == null) { return null; } //System.err.println("sigNode: " + sigNode); while ((sigNode.getLocalName() == null) || (!sigNode.getLocalName().equalsIgnoreCase("signature"))) { sigNode = sigNode.getNextSibling(); if (sigNode == null) { return null; } } //Desired Signature element may be inside a SOAP-SEC signature element if (!sigNode.getNamespaceURI().equals("http://www.w3.org/2000/09/xmldsig#")) { sigNode = sigNode.getFirstChild(); while ((sigNode.getLocalName() == null) || (!sigNode.getLocalName().equalsIgnoreCase("signature"))) { sigNode = sigNode.getNextSibling(); } } if (sigNode.getNamespaceURI().equals("http://www.w3.org/2000/09/xmldsig#")) { if (sigNode instanceof org.w3c.dom.Element) { sigElement = (org.w3c.dom.Element) sigNode; } } return sigElement; }
From source file:org.apache.solr.kelvin.responseanalyzers.LegacyResponseAnalyzer.java
public void decode(Map<String, Object> previousResponses) throws Exception { ObjectMapper mapper = new ObjectMapper(); ArrayNode response = mapper.createArrayNode(); if (!previousResponses.containsKey(XmlResponseAnalyzer.XML_DOM)) { previousResponses.put(XmlDoclistExtractorResponseAnalyzer.DOC_LIST, response); //empty return;/*www . jav a 2 s . com*/ } NodeList nodeList = (NodeList) expr.evaluate((Document) previousResponses.get(XmlResponseAnalyzer.XML_DOM), XPathConstants.NODESET); for (int i = 0; i < nodeList.getLength(); i++) { Node doc = nodeList.item(i); ObjectNode oDoc = mapper.createObjectNode(); Node subel = doc.getFirstChild(); while (subel != null) { String localName = subel.getNodeName(); if (localName == "field") { String fieldName = subel.getAttributes().getNamedItem("name").getNodeValue(); if (!"infoold".equals(fieldName)) { String value = subel.getTextContent(); oDoc.put(fieldName, value); } } else if (localName == "slug_preferenziale") { NodeList slugNodes = subel.getChildNodes(); oDoc.put("slug_preferenziale", slugNodes.item(slugNodes.getLength() - 1).getAttributes() .getNamedItem("path").getTextContent()); } subel = subel.getNextSibling(); } response.add(oDoc); } previousResponses.put(XmlDoclistExtractorResponseAnalyzer.DOC_LIST, response); }
From source file:org.jasig.portal.security.provider.saml.SAMLDelegatedAuthenticationService.java
private void removeAllChildren(Element element) { Node child = element.getFirstChild(); while (child != null) { Node next = child.getNextSibling(); element.removeChild(child);//from www . j ava 2 s .c o m child = next; } }
From source file:it.polito.tellmefirst.web.rest.clients.ClientEpub.java
private void getFirstChildElement(Node navMap) { LOG.debug("[getFirstChildElement] - BEGIN"); Node navPoint = navMap.getFirstChild(); while (navPoint != null) { if (navPoint.getNodeType() == Node.ELEMENT_NODE) { Node navLabel = navPoint.getFirstChild(); Node text = navLabel.getFirstChild(); String title = text.getTextContent().toString(); Node content = navLabel.getNextSibling(); String link = content.getAttributes().getNamedItem("src").getNodeValue().toString(); epub.put(title, link);//from w w w . j a va 2s. c o m } navPoint = navPoint.getNextSibling(); } LOG.debug("[getFirstChildElement] - END"); }
From source file:com.centeractive.ws.builder.soap.XmlUtils.java
private static int findNodeIndex(Node node) { String nm = node.getLocalName(); String ns = node.getNamespaceURI(); short nt = node.getNodeType(); Node parentNode = node.getParentNode(); if (parentNode.getNodeType() != Node.ELEMENT_NODE) return 1; Node child = parentNode.getFirstChild(); int ix = 0;/*from w w w . j av a 2s. co m*/ while (child != null) { if (child == node) return ix + 1; if (child.getNodeType() == nt && nm.equals(child.getLocalName()) && ((ns == null && child.getNamespaceURI() == null) || (ns != null && ns.equals(child.getNamespaceURI())))) ix++; child = child.getNextSibling(); } throw new SoapBuilderException("Child node not found in parent!?"); }
From source file:com.l2jfree.gameserver.datatables.MultisellTable.java
private MultiSellEntry parseEntry(Node n, int entryId) { //int entryId = Integer.parseInt(n.getAttributes().getNamedItem("id").getNodeValue()); Node first = n.getFirstChild(); MultiSellEntry entry = new MultiSellEntry(entryId); for (n = first; n != null; n = n.getNextSibling()) { if ("ingredient".equalsIgnoreCase(n.getNodeName())) { Node attribute;/*from www . jav a2s . c om*/ int id = Integer.parseInt(n.getAttributes().getNamedItem("id").getNodeValue()); long count = Long.parseLong(n.getAttributes().getNamedItem("count").getNodeValue()); boolean isTaxIngredient = false, maintainIngredient = false; attribute = n.getAttributes().getNamedItem("isTaxIngredient"); if (attribute != null) isTaxIngredient = Boolean.parseBoolean(attribute.getNodeValue()); attribute = n.getAttributes().getNamedItem("maintain"); if (attribute != null) maintainIngredient = Boolean.parseBoolean(attribute.getNodeValue()); MultiSellIngredient e = new MultiSellIngredient(id, count, isTaxIngredient, maintainIngredient); entry.addIngredient(e); validateItemId(id); } else if ("production".equalsIgnoreCase(n.getNodeName())) { int id = Integer.parseInt(n.getAttributes().getNamedItem("id").getNodeValue()); long count = Long.parseLong(n.getAttributes().getNamedItem("count").getNodeValue()); MultiSellIngredient e = new MultiSellIngredient(id, count); entry.addProduct(e); validateItemId(id); } } return entry; }
From source file:com.bstek.dorado.view.config.XmlDocumentPreprocessor.java
private Element doFindElementById(Element element, String id) { Element result = null;/*from ww w .j a va 2s . c o m*/ Node child = element.getFirstChild(); while (child != null) { if (child instanceof Element) { Element childElement = (Element) child; if (id.equals(childElement.getAttribute(ViewXmlConstants.ATTRIBUTE_ID))) { result = childElement; break; } } child = child.getNextSibling(); } if (result == null) { child = element.getFirstChild(); while (child != null) { if (child instanceof Element) { result = doFindElementById((Element) child, id); if (result != null) break; } child = child.getNextSibling(); } } return result; }
From source file:com.haulmont.cuba.restapi.XMLConverter.java
private String getRefId(Node refNode) { Node childNode = refNode.getFirstChild(); do {/*from w w w.j a v a 2 s.c o m*/ if (ELEMENT_REF.equals(childNode.getNodeName())) { Node idNode = childNode.getAttributes().getNamedItem(ATTR_ID); return idNode != null ? idNode.getTextContent() : null; } childNode = childNode.getNextSibling(); } while (childNode != null); return null; }