List of usage examples for org.w3c.dom Node getClass
@HotSpotIntrinsicCandidate public final native Class<?> getClass();
From source file:org.apache.ode.bpel.runtime.ASSIGN.java
/** * Get the r-value. There are several possibilities: * <ul>/*from w w w . ja v a 2 s. com*/ * <li>a message is selected - an element representing the whole message is * returned.</li> * <li>a (element) message part is selected - the element is returned. * </li> * <li>a (typed) message part is select - a wrapper element is returned. * </li> * <li>an attribute is selected - an attribute node is returned. </li> * <li>a text node/string expression is selected - a text node is returned. * </li> * </ul> * * @param from * * @return Either {@link Element}, {@link org.w3c.dom.Text}, or * {@link org.w3c.dom.Attr} node representing the r-value. * * @throws FaultException * DOCUMENTME * @throws UnsupportedOperationException * DOCUMENTME * @throws IllegalStateException * DOCUMENTME */ private Node evalRValue(OAssign.RValue from) throws FaultException, ExternalVariableModuleException { if (__log.isDebugEnabled()) __log.debug("Evaluating FROM expression \"" + from + "\"."); Node retVal; if (from instanceof DirectRef) { OAssign.DirectRef dref = (OAssign.DirectRef) from; sendVariableReadEvent(_scopeFrame.resolve(dref.variable)); Node data = fetchVariableData(_scopeFrame.resolve(dref.variable), false); retVal = DOMUtils.findChildByName((Element) data, dref.elName); } else if (from instanceof OAssign.VariableRef) { OAssign.VariableRef varRef = (OAssign.VariableRef) from; sendVariableReadEvent(_scopeFrame.resolve(varRef.variable)); Node data = fetchVariableData(_scopeFrame.resolve(varRef.variable), false); retVal = evalQuery(data, varRef.part != null ? varRef.part : varRef.headerPart, varRef.location, getEvaluationContext()); } else if (from instanceof OAssign.PropertyRef) { OAssign.PropertyRef propRef = (OAssign.PropertyRef) from; sendVariableReadEvent(_scopeFrame.resolve(propRef.variable)); Node data = fetchVariableData(_scopeFrame.resolve(propRef.variable), false); retVal = evalQuery(data, propRef.propertyAlias.part, propRef.propertyAlias.location, getEvaluationContext()); } else if (from instanceof OAssign.PartnerLinkRef) { OAssign.PartnerLinkRef pLinkRef = (OAssign.PartnerLinkRef) from; PartnerLinkInstance pLink = _scopeFrame.resolve(pLinkRef.partnerLink); Node tempVal = pLinkRef.isMyEndpointReference ? getBpelRuntimeContext().fetchMyRoleEndpointReferenceData(pLink) : getBpelRuntimeContext().fetchPartnerRoleEndpointReferenceData(pLink); if (__log.isDebugEnabled()) __log.debug("RValue is a partner link, corresponding endpoint " + tempVal.getClass().getName() + " has value " + DOMUtils.domToString(tempVal)); retVal = tempVal; } else if (from instanceof OAssign.Expression) { List<Node> l; OExpression expr = ((OAssign.Expression) from).expression; try { l = getBpelRuntimeContext().getExpLangRuntime().evaluate(expr, getEvaluationContext()); if (l.size() == 0 || l.get(0) == null || !(l.get(0) instanceof Element)) { if (__log.isTraceEnabled()) { __log.trace("evalRValue: OAssign.Expression: eval reult not Element or node=null"); } } else { Element element = (Element) l.get(0); for (Map.Entry<String, String> entry : DOMUtils.getMyNSContext(element).toMap().entrySet()) { String key = entry.getKey(); String value = entry.getValue(); if (entry.getKey() == null || entry.getKey().length() == 0) { element.setAttributeNS(DOMUtils.NS_URI_XMLNS, "xmlns", value); } else { element.setAttributeNS(DOMUtils.NS_URI_XMLNS, "xmlns:" + key, value); } } } } catch (EvaluationException e) { String msg = __msgs.msgEvalException(from.toString(), e.getMessage()); if (__log.isDebugEnabled()) __log.debug(from + ": " + msg); if (e.getCause() instanceof FaultException) throw (FaultException) e.getCause(); throw new FaultException(getOAsssign().getOwner().constants.qnSelectionFailure, msg); } if (l.size() == 0) { String msg = __msgs.msgRValueNoNodesSelected(expr.toString()); if (__log.isDebugEnabled()) __log.debug(from + ": " + msg); throw new FaultException(getOAsssign().getOwner().constants.qnSelectionFailure, msg, new Throwable("ignoreMissingFromData")); } else if (l.size() > 1) { String msg = __msgs.msgRValueMultipleNodesSelected(expr.toString()); if (__log.isDebugEnabled()) __log.debug(from + ": " + msg); throw new FaultException(getOAsssign().getOwner().constants.qnSelectionFailure, msg); } retVal = (Node) l.get(0); } else if (from instanceof OAssign.Literal) { String literal = ((OAssign.Literal) from).getXmlLiteral(); Element literalRoot; try { literalRoot = DOMUtils.stringToDOM(literal); } catch (Exception e) { throw new RuntimeException("XML literal parsing failed " + literal, e); } assert literalRoot.getLocalName().equals("literal"); // We'd like a single text node... literalRoot.normalize(); retVal = literalRoot.getFirstChild(); // Adjust for whitespace before an element. if (retVal != null && retVal.getNodeType() == Node.TEXT_NODE && retVal.getTextContent().trim().length() == 0 && retVal.getNextSibling() != null) { retVal = retVal.getNextSibling(); } if (retVal == null) { // Special case, no children --> empty TII retVal = literalRoot.getOwnerDocument().createTextNode(""); } else if (retVal.getNodeType() == Node.ELEMENT_NODE) { // Make sure there is no more elements. Node x = retVal.getNextSibling(); while (x != null) { if (x.getNodeType() == Node.ELEMENT_NODE) { String msg = __msgs.msgLiteralContainsMultipleEIIs(); if (__log.isDebugEnabled()) __log.debug(from + ": " + msg); throw new FaultException(getOAsssign().getOwner().constants.qnSelectionFailure, msg); } x = x.getNextSibling(); } } else if (retVal.getNodeType() == Node.TEXT_NODE) { // Make sure there are no elements following this text node. Node x = retVal.getNextSibling(); while (x != null) { if (x.getNodeType() == Node.ELEMENT_NODE) { String msg = __msgs.msgLiteralContainsMixedContent(); if (__log.isDebugEnabled()) __log.debug(from + ": " + msg); throw new FaultException(getOAsssign().getOwner().constants.qnSelectionFailure, msg); } x = x.getNextSibling(); } } if (retVal == null) { String msg = __msgs.msgLiteralMustContainTIIorEII(); if (__log.isDebugEnabled()) __log.debug(from + ": " + msg); throw new FaultException(getOAsssign().getOwner().constants.qnSelectionFailure, msg); } } else { String msg = __msgs.msgInternalError("Unknown RVALUE type: " + from); if (__log.isErrorEnabled()) __log.error(from + ": " + msg); throw new FaultException(getOAsssign().getOwner().constants.qnSelectionFailure, msg); } // Now verify we got something. if (retVal == null) { String msg = __msgs.msgEmptyRValue(); if (__log.isDebugEnabled()) __log.debug(from + ": " + msg); throw new FaultException(getOAsssign().getOwner().constants.qnSelectionFailure, msg); } // Now check that we got the right thing. switch (retVal.getNodeType()) { case Node.TEXT_NODE: case Node.ATTRIBUTE_NODE: case Node.ELEMENT_NODE: case Node.CDATA_SECTION_NODE: break; default: String msg = __msgs.msgInvalidRValue(); if (__log.isDebugEnabled()) __log.debug(from + ": " + msg); throw new FaultException(getOAsssign().getOwner().constants.qnSelectionFailure, msg); } return retVal; }
From source file:org.apache.ode.bpel.runtime.AssignHelper.java
/** * Get the r-value. There are several possibilities: * <ul>/* w w w . j a v a 2 s . c o m*/ * <li>a message is selected - an element representing the whole message is * returned.</li> * <li>a (element) message part is selected - the element is returned. * </li> * <li>a (typed) message part is select - a wrapper element is returned. * </li> * <li>an attribute is selected - an attribute node is returned. </li> * <li>a text node/string expression is selected - a text node is returned. * </li> * </ul> * * @param from * * @return Either {@link Element}, {@link org.w3c.dom.Text}, or * {@link org.w3c.dom.Attr} node representing the r-value. * * @throws FaultException * DOCUMENTME * @throws UnsupportedOperationException * DOCUMENTME * @throws IllegalStateException * DOCUMENTME */ private Node evalRValue(OAssign.RValue from) throws FaultException, ExternalVariableModuleException { if (__log.isDebugEnabled()) __log.debug("Evaluating FROM expression \"" + from + "\"."); Node retVal; if (from instanceof DirectRef) { OAssign.DirectRef dref = (OAssign.DirectRef) from; sendVariableReadEvent(_scopeFrame.resolve(dref.variable)); Node data = fetchVariableData(_scopeFrame.resolve(dref.variable), false); retVal = DOMUtils.findChildByName((Element) data, dref.elName); } else if (from instanceof OAssign.VariableRef) { OAssign.VariableRef varRef = (OAssign.VariableRef) from; sendVariableReadEvent(_scopeFrame.resolve(varRef.variable)); Node data = fetchVariableData(_scopeFrame.resolve(varRef.variable), false); retVal = evalQuery(data, varRef.part != null ? varRef.part : varRef.headerPart, varRef.location, getEvaluationContext()); } else if (from instanceof OAssign.PropertyRef) { OAssign.PropertyRef propRef = (OAssign.PropertyRef) from; sendVariableReadEvent(_scopeFrame.resolve(propRef.variable)); Node data = fetchVariableData(_scopeFrame.resolve(propRef.variable), false); retVal = evalQuery(data, propRef.propertyAlias.part, propRef.propertyAlias.location, getEvaluationContext()); } else if (from instanceof OAssign.PartnerLinkRef) { OAssign.PartnerLinkRef pLinkRef = (OAssign.PartnerLinkRef) from; PartnerLinkInstance pLink = _scopeFrame.resolve(pLinkRef.partnerLink); Node tempVal = pLinkRef.isMyEndpointReference ? getBpelRuntimeContext().fetchMyRoleEndpointReferenceData(pLink) : getBpelRuntimeContext().fetchPartnerRoleEndpointReferenceData(pLink); if (__log.isDebugEnabled()) __log.debug("RValue is a partner link, corresponding endpoint " + tempVal.getClass().getName() + " has value " + DOMUtils.domToString(tempVal)); retVal = tempVal; } else if (from instanceof OAssign.Expression) { List<Node> l; OExpression expr = ((OAssign.Expression) from).expression; try { l = getBpelRuntimeContext().getExpLangRuntime().evaluate(expr, getEvaluationContext()); } catch (EvaluationException e) { String msg = __msgs.msgEvalException(from.toString(), e.getMessage()); if (__log.isDebugEnabled()) __log.debug(from + ": " + msg); if (e.getCause() instanceof FaultException) throw (FaultException) e.getCause(); throw new FaultException(getOActivity().getOwner().constants.qnSelectionFailure, msg); } if (l.size() == 0) { String msg = __msgs.msgRValueNoNodesSelected(expr.toString()); if (__log.isDebugEnabled()) __log.debug(from + ": " + msg); throw new FaultException(getOActivity().getOwner().constants.qnSelectionFailure, msg, new Throwable("ignoreMissingFromData")); } else if (l.size() > 1) { String msg = __msgs.msgRValueMultipleNodesSelected(expr.toString()); if (__log.isDebugEnabled()) __log.debug(from + ": " + msg); throw new FaultException(getOActivity().getOwner().constants.qnSelectionFailure, msg); } retVal = (Node) l.get(0); } else if (from instanceof OAssign.Literal) { String literal = ((OAssign.Literal) from).getXmlLiteral(); Element literalRoot; try { literalRoot = DOMUtils.stringToDOM(literal); } catch (Exception e) { throw new RuntimeException("XML literal parsing failed " + literal, e); } assert literalRoot.getLocalName().equals("literal"); // We'd like a single text node... literalRoot.normalize(); retVal = literalRoot.getFirstChild(); // Adjust for whitespace before an element. if (retVal != null && retVal.getNodeType() == Node.TEXT_NODE && retVal.getTextContent().trim().length() == 0 && retVal.getNextSibling() != null) { retVal = retVal.getNextSibling(); } if (retVal == null) { // Special case, no children --> empty TII retVal = literalRoot.getOwnerDocument().createTextNode(""); } else if (retVal.getNodeType() == Node.ELEMENT_NODE) { // Make sure there is no more elements. Node x = retVal.getNextSibling(); while (x != null) { if (x.getNodeType() == Node.ELEMENT_NODE) { String msg = __msgs.msgLiteralContainsMultipleEIIs(); if (__log.isDebugEnabled()) __log.debug(from + ": " + msg); throw new FaultException(getOActivity().getOwner().constants.qnSelectionFailure, msg); } x = x.getNextSibling(); } } else if (retVal.getNodeType() == Node.TEXT_NODE) { // Make sure there are no elements following this text node. Node x = retVal.getNextSibling(); while (x != null) { if (x.getNodeType() == Node.ELEMENT_NODE) { String msg = __msgs.msgLiteralContainsMixedContent(); if (__log.isDebugEnabled()) __log.debug(from + ": " + msg); throw new FaultException(getOActivity().getOwner().constants.qnSelectionFailure, msg); } x = x.getNextSibling(); } } if (retVal == null) { String msg = __msgs.msgLiteralMustContainTIIorEII(); if (__log.isDebugEnabled()) __log.debug(from + ": " + msg); throw new FaultException(getOActivity().getOwner().constants.qnSelectionFailure, msg); } } else { String msg = __msgs.msgInternalError("Unknown RVALUE type: " + from); if (__log.isErrorEnabled()) __log.error(from + ": " + msg); throw new FaultException(getOActivity().getOwner().constants.qnSelectionFailure, msg); } // Now verify we got something. if (retVal == null) { String msg = __msgs.msgEmptyRValue(); if (__log.isDebugEnabled()) __log.debug(from + ": " + msg); throw new FaultException(getOActivity().getOwner().constants.qnSelectionFailure, msg); } // Now check that we got the right thing. switch (retVal.getNodeType()) { case Node.TEXT_NODE: case Node.ATTRIBUTE_NODE: case Node.ELEMENT_NODE: case Node.CDATA_SECTION_NODE: break; default: String msg = __msgs.msgInvalidRValue(); if (__log.isDebugEnabled()) __log.debug(from + ": " + msg); throw new FaultException(getOActivity().getOwner().constants.qnSelectionFailure, msg); } return retVal; }
From source file:org.apache.struts2.views.xslt.ProxyNodeAdapter.java
public ProxyNodeAdapter(AdapterFactory factory, AdapterNode parent, Node value) { setContext(factory, parent, "document"/*propname unused*/, value); log.debug("proxied node is: " + value); log.debug("node class is: " + value.getClass()); log.debug("node type is: " + value.getNodeType()); log.debug("node name is: " + value.getNodeName()); }
From source file:org.atricore.idbus.idojos.memoryidentitystore.MemoryIdentityStore.java
protected String getTextContent(Node node) { try {/* w w w.j a v a 2 s . c o m*/ // Only supported in earlier versions of DOM Method getTextContent = node.getClass().getMethod("getTextContent"); return (String) getTextContent.invoke(node); } catch (NoSuchMethodException e) { logger.debug("Using old DOM Java Api to get Node text content"); } catch (InvocationTargetException e) { logger.warn(e.getMessage(), e); } catch (IllegalAccessException e) { logger.warn(e.getMessage(), e); } // Old DOM API usage to get node's text content NodeList children = node.getChildNodes(); for (int i = 0; i < children.getLength(); i++) { Node child = children.item(i); if (child.getNodeType() == Node.TEXT_NODE) { return child.getNodeValue(); } } return null; }
From source file:org.broadleafcommerce.common.extensibility.context.merge.handlers.NodeReplaceInsert.java
private List<Node> matchNodes(List<Node> exhaustedNodes, Node[] primaryNodes, ArrayList<Node> list) { List<Node> usedNodes = new ArrayList<Node>(20); Iterator<Node> itr = list.iterator(); Node parentNode = primaryNodes[0].getParentNode(); Document ownerDocument = parentNode.getOwnerDocument(); while (itr.hasNext()) { Node node = itr.next(); if (Element.class.isAssignableFrom(node.getClass()) && !exhaustedNodesContains(exhaustedNodes, node)) { if (LOG.isDebugEnabled()) { StringBuffer sb = new StringBuffer(); sb.append("matching node for replacement: "); sb.append(node.getNodeName()); int attrLength = node.getAttributes().getLength(); for (int j = 0; j < attrLength; j++) { sb.append(" : ("); sb.append(node.getAttributes().item(j).getNodeName()); sb.append("/"); sb.append(node.getAttributes().item(j).getNodeValue()); sb.append(")"); }//from w w w. java 2 s . com LOG.debug(sb.toString()); } if (!checkNode(usedNodes, primaryNodes, node)) { //simply append the node if all the above fails Node newNode = ownerDocument.importNode(node.cloneNode(true), true); parentNode.appendChild(newNode); usedNodes.add(node); } } } return usedNodes; }
From source file:org.docx4j.openpackaging.parts.XmlPart.java
/** * Set the value of the node referenced in the xpath expression. * //from ww w .j a va 2s . c om * @param xpath * @param value * @param prefixMappings a string such as "xmlns:ns0='http://schemas.medchart'" * @return * @throws Docx4JException */ public boolean setNodeValueAtXPath(String xpath, String value, String prefixMappings) throws Docx4JException { try { getNamespaceContext().registerPrefixMappings(prefixMappings); Node n = (Node) xPath.evaluate(xpath, doc, XPathConstants.NODE); if (n == null) { log.debug("xpath returned null"); return false; } log.debug(n.getClass().getName()); // Method 1: Crimson throws error // Could avoid with System.setProperty("javax.xml.parsers.DocumentBuilderFactory", // "com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderFactoryImpl"); //n.setTextContent(value); // Method 2: crimson ignores // n.setNodeValue(value); // Method 3: createTextNode, then append it // First, need to delete/replace existing text node if (n.getChildNodes() != null && n.getChildNodes().getLength() > 0) { NodeList nodes = n.getChildNodes(); for (int i = nodes.getLength(); i > 0; i--) { n.removeChild(nodes.item(i - 1)); } } Text t = n.getOwnerDocument().createTextNode(value); n.appendChild(t); // cache is now invalid return true; } catch (Exception e) { throw new Docx4JException("Problem setting value at xpath " + xpath); } }
From source file:org.exist.dom.ElementImpl.java
/** ? @see org.w3c.dom.Node#isSameNode(org.w3c.dom.Node) *///from w ww . j a va 2s . c om @Override public boolean isSameNode(Node other) { // This function is used by Saxon in some circumstances, and this partial implementation is required for proper Saxon operation. if (other instanceof StoredNode) { return (this.nodeId == ((StoredNode) other).nodeId && this.ownerDocument.getDocId() == ((StoredNode) other).ownerDocument.getDocId()); } throw new DOMException(DOMException.NOT_SUPPORTED_ERR, "isSameNode(Node other) not implemented on other class " + other.getClass().getName()); }
From source file:org.jboss.bpm.console.server.util.DOMUtils.java
public static Element sourceToElement(Source source) throws IOException { Element retElement = null;/*from w ww .j a va2 s. c om*/ try { if (source instanceof StreamSource) { StreamSource streamSource = (StreamSource) source; InputStream ins = streamSource.getInputStream(); if (ins != null) { retElement = DOMUtils.parse(ins); } else { Reader reader = streamSource.getReader(); retElement = DOMUtils.parse(new InputSource(reader)); } } else if (source instanceof DOMSource) { DOMSource domSource = (DOMSource) source; Node node = domSource.getNode(); if (node instanceof Element) { retElement = (Element) node; } else if (node instanceof Document) { retElement = ((Document) node).getDocumentElement(); } else { throw new RuntimeException("Unsupported Node type: " + node.getClass().getName()); } } else if (source instanceof SAXSource) { // The fact that JAXBSource derives from SAXSource is an implementation detail. // Thus in general applications are strongly discouraged from accessing methods defined on SAXSource. // The XMLReader object obtained by the getXMLReader method shall be used only for parsing the InputSource object returned by the getInputSource method. TransformerFactory tf = TransformerFactory.newInstance(); ByteArrayOutputStream baos = new ByteArrayOutputStream(1024); Transformer transformer = tf.newTransformer(); transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes"); transformer.setOutputProperty(OutputKeys.METHOD, "xml"); transformer.transform(source, new StreamResult(baos)); retElement = DOMUtils.parse(new ByteArrayInputStream(baos.toByteArray())); } else { throw new RuntimeException("Source type not implemented: " + source.getClass().getName()); } } catch (TransformerException ex) { IOException ioex = new IOException(); ioex.initCause(ex); throw ioex; } return retElement; }
From source file:org.opensingular.internal.lib.commons.xml.TestMElement.java
License:asdf
/** * Verifica se ambos os nos so iguais fazendo uma comparao em * profundidade./*from w w w . ja v a2 s . c o m*/ * * @param n1 - * @param n2 - * @throws Exception Se nbo forem iguais */ public static void isIgual(Node n1, Node n2) throws Exception { if (n1 == n2) { return; } isIgual(n1, n2, "NodeName", n1.getNodeName(), n2.getNodeName()); isIgual(n1, n2, "NodeValue", n1.getNodeValue(), n2.getNodeValue()); isIgual(n1, n2, "Namespace", n1.getNamespaceURI(), n2.getNamespaceURI()); isIgual(n1, n2, "Prefix", n1.getPrefix(), n2.getPrefix()); isIgual(n1, n2, "LocalName", n1.getLocalName(), n2.getLocalName()); if (isMesmaClasse(Element.class, n1, n2)) { Element e1 = (Element) n1; Element e2 = (Element) n2; //Verifica se possuem os mesmos atributos NamedNodeMap nn1 = e1.getAttributes(); NamedNodeMap nn2 = e2.getAttributes(); if (nn1.getLength() != nn2.getLength()) { fail("O nmero atributos em " + XPathToolkit.getFullPath(n1) + " (qtd=" + nn1.getLength() + " diferente de n2 (qtd=" + nn2.getLength() + ")"); } for (int i = 0; i < nn1.getLength(); i++) { isIgual((Attr) nn1.item(i), (Attr) nn2.item(i)); } //Verifica se possuem os mesmos filhos Node filho1 = e1.getFirstChild(); Node filho2 = e2.getFirstChild(); int count = 0; while ((filho1 != null) && (filho2 != null)) { isIgual(filho1, filho2); filho1 = filho1.getNextSibling(); filho2 = filho2.getNextSibling(); count++; } if (filho1 != null) { fail("H mais node [" + count + "] " + XPathToolkit.getNomeTipo(filho1) + " (" + XPathToolkit.getFullPath(filho1) + ") em n1:" + XPathToolkit.getFullPath(n1)); } if (filho2 != null) { fail("H mais node [" + count + "] " + XPathToolkit.getNomeTipo(filho2) + " (" + XPathToolkit.getFullPath(filho2) + ") em n2:" + XPathToolkit.getFullPath(n2)); } } else if (isMesmaClasse(Attr.class, n1, n2)) { //Ok } else if (isMesmaClasse(Text.class, n1, n2)) { //Ok } else { fail("Tipo de n " + n1.getClass() + " no tratado"); } }
From source file:sf.net.experimaestro.utils.JSUtils.java
/** * Transforms a DOM node to a E4X scriptable object * * @param node/*from w ww .j a va 2 s . co m*/ * @param cx * @param scope * @return */ public static Object domToE4X(Node node, Context cx, Scriptable scope) { if (node == null) { LOGGER.info("XML is null"); return Context.getUndefinedValue(); } if (node instanceof Document) node = ((Document) node).getDocumentElement(); if (node instanceof DocumentFragment) { final Document document = node.getOwnerDocument(); Element root = document.createElement("root"); document.appendChild(root); Scriptable xml = cx.newObject(scope, "XML", new Node[] { root }); final Scriptable list = (Scriptable) xml.get("*", xml); int count = 0; for (Node child : XMLUtils.children(node)) { list.put(count++, list, cx.newObject(scope, "XML", new Node[] { child })); } return list; } LOGGER.debug("XML is of type %s [%s]; %s", node.getClass(), XMLUtils.toStringObject(node), node.getUserData("org.mozilla.javascript.xmlimpl.XmlNode")); return cx.newObject(scope, "XML", new Node[] { node }); }