List of usage examples for org.w3c.dom Node ATTRIBUTE_NODE
short ATTRIBUTE_NODE
To view the source code for org.w3c.dom Node ATTRIBUTE_NODE.
Click Source Link
Attr
. From source file:org.wso2.carbon.bpel.analytics.publisher.AnalyticsPublisherExtensionOperation.java
private String evaluateXPathExpression(ExtensionContext context, String xpath, Element element) throws FaultException { String result = ""; QName qnVariableData = new QName(Namespaces.BPEL11_NS, "getVariableData"); QName qnGetVariableProperty = new QName(Namespaces.BPEL11_NS, "getVariableProperty"); QName qnGetLinkStatus = new QName(Namespaces.BPEL11_NS, "getLinkStatus"); QName qnDoXslTransform = new QName(Namespaces.BPEL11_NS, "getDoXslTransform"); OXPath20ExpressionBPEL20 oexpr = new OXPath20ExpressionBPEL20( context.getInternalInstance().getProcessModel().getOwner(), qnVariableData, qnGetVariableProperty, qnGetLinkStatus, qnDoXslTransform, false); OExpressionLanguage oExpressionLanguage = new OExpressionLanguage(context.getProcessModel().getOwner(), null);//from w ww . j a v a2 s. c o m oExpressionLanguage.expressionLanguageUri = "urn:oasis:names:tc:wsbpel:2.0:sublang:xpath2.0"; oexpr.expressionLanguage = oExpressionLanguage; oExpressionLanguage.properties.put("runtime-class", "org.apache.ode.bpel.elang.xpath20.runtime.XPath20ExpressionRuntime"); try { context.getInternalInstance().getExpLangRuntime().registerRuntime(oExpressionLanguage); } catch (ConfigurationException ex) { String errMsg = "Error when trying to register xpath runtime"; log.error(errMsg, ex); handleException(errMsg, ex); } oexpr.insertMissingData = true; ScopeFrame scopeFrame = ((ExtensionContextImpl) context).getScopeFrame(); ExprEvaluationContextImpl exprEvaluationContext = new ExprEvaluationContextImpl(scopeFrame, context.getInternalInstance()); oexpr.vars = (HashMap) context.getVisibleVariables(); oexpr.namespaceCtx = context.getProcessModel().namespaceContext; try { oexpr.xpath = xpath; List resultList = context.getInternalInstance().getExpLangRuntime().evaluate(oexpr, exprEvaluationContext); if (result != null) { Iterator iterator = resultList.iterator(); /** for analytics publishing to work, there should only be a single node here */ while (iterator.hasNext()) { Node node = ((Node) iterator.next()); if (node.getNodeType() == Node.ELEMENT_NODE) { result += node.getTextContent(); } else if (node.getNodeType() == Node.ATTRIBUTE_NODE) { result += node.getNodeValue(); } } } } catch (EvaluationException e) { String errMsg = "Xpath evaluation failed"; log.error(errMsg); handleException(errMsg, e); } return result; }
From source file:org.wso2.carbon.bpel.bam.publisher.BAMPublisherExtensionOperation.java
private String evaluateXPathExpression(ExtensionContext context, String xpath, Element element) throws FaultException { String result = ""; QName qnVariableData = new QName(Namespaces.BPEL11_NS, "getVariableData"); QName qnGetVariableProperty = new QName(Namespaces.BPEL11_NS, "getVariableProperty"); QName qnGetLinkStatus = new QName(Namespaces.BPEL11_NS, "getLinkStatus"); QName qnDoXslTransform = new QName(Namespaces.BPEL11_NS, "getDoXslTransform"); OXPath20ExpressionBPEL20 oexpr = new OXPath20ExpressionBPEL20( context.getInternalInstance().getProcessModel().getOwner(), qnVariableData, qnGetVariableProperty, qnGetLinkStatus, qnDoXslTransform, false); OExpressionLanguage oExpressionLanguage = new OExpressionLanguage(context.getProcessModel().getOwner(), null);//from w w w . ja v a2 s .c om oExpressionLanguage.expressionLanguageUri = "urn:oasis:names:tc:wsbpel:2.0:sublang:xpath2.0"; oexpr.expressionLanguage = oExpressionLanguage; oExpressionLanguage.properties.put("runtime-class", "org.apache.ode.bpel.elang.xpath20.runtime.XPath20ExpressionRuntime"); try { context.getInternalInstance().getExpLangRuntime().registerRuntime(oExpressionLanguage); } catch (ConfigurationException ex) { String errMsg = "Error when trying to register xpath runtime"; log.error(errMsg, ex); handleException(errMsg, ex); } oexpr.insertMissingData = true; ScopeFrame scopeFrame = ((ExtensionContextImpl) context).getScopeFrame(); ExprEvaluationContextImpl exprEvaluationContext = new ExprEvaluationContextImpl(scopeFrame, context.getInternalInstance()); oexpr.vars = (HashMap) context.getVisibleVariables(); oexpr.namespaceCtx = context.getProcessModel().namespaceContext; try { oexpr.xpath = xpath; List resultList = context.getInternalInstance().getExpLangRuntime().evaluate(oexpr, exprEvaluationContext); if (result != null) { Iterator iterator = resultList.iterator(); /** for bam publishing to work, there should only be a single node here */ while (iterator.hasNext()) { Node node = ((Node) iterator.next()); if (node.getNodeType() == Node.ELEMENT_NODE) { result += node.getTextContent(); } else if (node.getNodeType() == Node.ATTRIBUTE_NODE) { result += node.getNodeValue(); } } } } catch (EvaluationException e) { String errMsg = "Xpath evaluation failed"; log.error(errMsg); handleException(errMsg, e); } return result; }
From source file:org.wso2.carbon.lcm.core.util.LifecycleUtils.java
private static void validateSCXMLDataModel(Document lcConfig) throws LifecycleException { NodeList stateList = lcConfig.getElementsByTagName(LifecycleConstants.STATE_TAG); for (int i = 0; i < stateList.getLength(); i++) { List<String> targetValues = new ArrayList<>(); if (stateList.item(i).getNodeType() == Node.ELEMENT_NODE) { Element state = (Element) stateList.item(i); String stateName = state.getAttribute("id"); NodeList targetList = state.getElementsByTagName(LifecycleConstants.TRANSITION_ATTRIBUTE); for (int targetCount = 0; targetCount < targetList.getLength(); targetCount++) { if (targetList.item(targetCount).getNodeType() == Node.ELEMENT_NODE) { Element target = (Element) targetList.item(targetCount); targetValues.add(target.getAttribute(LifecycleConstants.TARGET_ATTRIBUTE)); }//from w w w .j ava2s . c o m } XPath xPathInstance = XPathFactory.newInstance().newXPath(); String xpathQuery = "//state[@id='" + stateName + "']//@forTarget"; try { XPathExpression exp = xPathInstance.compile(xpathQuery); NodeList forTargetNodeList = (NodeList) exp.evaluate(state, XPathConstants.NODESET); for (int forTargetCount = 0; forTargetCount < forTargetNodeList.getLength(); forTargetCount++) { if (forTargetNodeList.item(forTargetCount).getNodeType() == Node.ATTRIBUTE_NODE) { Attr attr = (Attr) forTargetNodeList.item(forTargetCount); if (!"".equals(attr.getValue()) && !targetValues.contains(attr.getValue())) { throw new LifecycleException("forTarget attribute value " + attr.getValue() + " does not included as target state in the state object " + stateName); } } } } catch (XPathExpressionException e) { throw new LifecycleException("Error while reading for target attributes ", e); } } } }
From source file:psidev.psi.mi.filemakers.xmlFlattener.structure.XsdTreeStructImpl.java
/** * //from w w w . j av a2s. c om * @param element * an element of the XML document * @return value of this element if it exists, an empty String else */ public String getElementValue(Element element) { try { NodeList children = element.getChildNodes(); String value = ""; for (int i = 0; i < children.getLength(); i++) { if (children.item(i).getNodeType() == Node.ATTRIBUTE_NODE) { if (elementFilters.containsKey(children.item(i))) { try { String value2 = children.item(i).getNodeValue(); /** TODO: done for managing filter */ if (false == value2.matches((String) elementFilters.get(children.item(i)))) { return ""; } } catch (NullPointerException e) { log.debug(e); return ""; } } } if (children.item(i).getNodeName() == "#text") value = children.item(i).getNodeValue(); } return value; } catch (NullPointerException e) { /** element is null */ return ""; } }
From source file:sf.net.experimaestro.utils.JSUtils.java
public static Object toDOM(Scriptable scope, Object object, OptionalDocument document) { // Unwrap if needed (if this is not a JSBaseObject) if (object instanceof Wrapper && !(object instanceof JSBaseObject)) object = ((Wrapper) object).unwrap(); // It is already a DOM node if (object instanceof Node) return object; if (object instanceof XMLObject) { final XMLObject xmlObject = (XMLObject) object; String className = xmlObject.getClassName(); if (className.equals("XMLList")) { LOGGER.debug("Transforming from XMLList [%s]", object); final Object[] ids = xmlObject.getIds(); if (ids.length == 1) return toDOM(scope, xmlObject.get((Integer) ids[0], xmlObject), document); Document doc = XMLUtils.newDocument(); DocumentFragment fragment = doc.createDocumentFragment(); for (int i = 0; i < ids.length; i++) { Node node = (Node) toDOM(scope, xmlObject.get((Integer) ids[i], xmlObject), document); if (node instanceof Document) node = ((Document) node).getDocumentElement(); fragment.appendChild(doc.adoptNode(node)); }/*from w ww . j a v a 2s .c om*/ return fragment; } // XML node if (className.equals("XML")) { // FIXME: this strips all whitespaces! Node node = XMLLibImpl.toDomNode(object); LOGGER.debug("Got node from JavaScript [%s / %s] from [%s]", node.getClass(), XMLUtils.toStringObject(node), object.toString()); if (node instanceof Document) node = ((Document) node).getDocumentElement(); node = document.get().adoptNode(node.cloneNode(true)); return node; } throw new RuntimeException(format("Not implemented: convert %s to XML", className)); } if (object instanceof NativeArray) { NativeArray array = (NativeArray) object; ArrayNodeList list = new ArrayNodeList(); for (Object x : array) { Object o = toDOM(scope, x, document); if (o instanceof Node) list.add(document.cloneAndAdopt((Node) o)); else { for (Node node : XMLUtils.iterable((NodeList) o)) { list.add(document.cloneAndAdopt(node)); } } } return list; } if (object instanceof NativeObject) { // JSON case: each key of the JS object is an XML element NativeObject json = (NativeObject) object; ArrayNodeList list = new ArrayNodeList(); for (Object _id : json.getIds()) { String jsQName = JSUtils.toString(_id); if (jsQName.length() == 0) { final Object seq = toDOM(scope, json.get(jsQName, json), document); for (Node node : XMLUtils.iterable(seq)) { if (node instanceof Document) node = ((Document) node).getDocumentElement(); list.add(document.cloneAndAdopt(node)); } } else if (jsQName.charAt(0) == '@') { final QName qname = QName.parse(jsQName.substring(1), null, new JSNamespaceBinder(scope)); Attr attribute = document.get().createAttributeNS(qname.getNamespaceURI(), qname.getLocalPart()); StringBuilder sb = new StringBuilder(); for (Node node : XMLUtils.iterable(toDOM(scope, json.get(jsQName, json), document))) { sb.append(node.getTextContent()); } attribute.setTextContent(sb.toString()); list.add(attribute); } else { final QName qname = QName.parse(jsQName, null, new JSNamespaceBinder(scope)); Element element = qname.hasNamespace() ? document.get().createElementNS(qname.getNamespaceURI(), qname.getLocalPart()) : document.get().createElement(qname.getLocalPart()); list.add(element); final Object seq = toDOM(scope, json.get(jsQName, json), document); for (Node node : XMLUtils.iterable(seq)) { if (node instanceof Document) node = ((Document) node).getDocumentElement(); node = document.get().adoptNode(node.cloneNode(true)); if (node.getNodeType() == Node.ATTRIBUTE_NODE) element.setAttributeNodeNS((Attr) node); else element.appendChild(node); } } } return list; } if (object instanceof Double) { // Wrap a double final Double x = (Double) object; if (x.longValue() == x.doubleValue()) return document.get().createTextNode(Long.toString(x.longValue())); return document.get().createTextNode(Double.toString(x)); } if (object instanceof Integer) { return document.get().createTextNode(Integer.toString((Integer) object)); } if (object instanceof CharSequence) { return document.get().createTextNode(object.toString()); } if (object instanceof UniqueTag) throw new XPMRuntimeException("Undefined cannot be converted to XML", object.getClass()); if (object instanceof JSNode) { Node node = ((JSNode) object).getNode(); if (document.has()) { if (node instanceof Document) node = ((Document) node).getDocumentElement(); return document.get().adoptNode(node); } return node; } if (object instanceof JSNodeList) { return ((JSNodeList) object).getList(); } if (object instanceof Scriptable) { ((Scriptable) object).getDefaultValue(String.class); } // By default, convert to string return document.get().createTextNode(object.toString()); }
From source file:tufts.vue.ds.XMLIngest.java
private static final String getNodeType(int t) { if (t == Node.ATTRIBUTE_NODE) return "attr"; if (t == Node.CDATA_SECTION_NODE) return "cdata"; if (t == Node.COMMENT_NODE) return "comment"; if (t == Node.DOCUMENT_NODE) return "document"; if (t == Node.ELEMENT_NODE) return "element"; if (t == Node.ENTITY_NODE) return "entity"; if (t == Node.TEXT_NODE) return "text"; return "" + t; }
From source file:tufts.vue.ds.XMLIngest.java
private static void scanNode(XmlSchema schema, org.w3c.dom.Node n, String parentPath, String parentName) { final int type = n.getNodeType(); final String value = n.getNodeValue(); final boolean isAttribute = (type == Node.ATTRIBUTE_NODE); String name = n.getNodeName(); scanNode(schema, n, type, parentPath, parentName, name, value); }
From source file:tufts.vue.ds.XMLIngest.java
private static void scanNode(final XmlSchema schema, final org.w3c.dom.Node node, final int type, final String parentPath, final String parentName, final String nodeName, final String value) { final boolean isAttribute = (type == Node.ATTRIBUTE_NODE); final boolean isMergedText = FOLD_TEXT && isText(type); final boolean hasAttributes = (!isAttribute && node != null && node.hasAttributes()); Node firstChild = null, lastChild = null; if (node != null) { firstChild = node.getFirstChild(); lastChild = node.getLastChild(); }// w w w.ja v a2s. c o m final String XMLName; if (isAttribute) XMLName = parentName + ATTR_SEPARATOR + nodeName; else XMLName = nodeName; final String fullName; if (parentPath != null) { // should only be null first time in at the top root if (isMergedText) fullName = parentPath; else if (isAttribute) fullName = parentPath + ATTR_SEPARATOR + nodeName; else fullName = parentPath + '.' + nodeName; } else { fullName = nodeName; } if (type == Node.ELEMENT_NODE) schema.trackNodeOpen(fullName); if (depth < REPORT_THRESH) { if (depth < REPORT_THRESH - 1) { if (type == Node.TEXT_NODE) eoutln(String.format("node(%s) {%s} (len=%d)", getNodeType(type), fullName, value.length())); else eoutln(String.format("NODE(%s) {%s} %.192s", getNodeType(type), fullName, node, Util.tags(firstChild))); } //eoutln("NODE: " + type + " name=" + name + " " + Util.tags(n) + " firstChild=" + Util.tags(firstChild)); //System.err.println(name); else if (XML_DEBUG) System.err.print("."); } if (hasAttributes && ATTRIBUTES_IMMEDIATE) scanAttributes(schema, fullName, nodeName, node.getAttributes()); String outputValue = null; if (value != null) { outputValue = value.trim(); if (outputValue.length() > 0) { schema.trackFieldValuePair(fullName, outputValue); } else outputValue = null; } final NodeList children = node == null ? null : node.getChildNodes(); final boolean DO_TAG; if (isMergedText) { DO_TAG = false; } else if (outputValue == null && node != null) { if (!node.hasChildNodes()) { DO_TAG = false; } else if (children.getLength() == 1 && isText(firstChild) && firstChild.getNodeValue().trim().length() == 0) { DO_TAG = false; } else DO_TAG = true; // if (!DO_TAG) ioutln("<!-- empty: " + nodeName + " -->"); } else DO_TAG = true; boolean closeOnSameLine = false; if (DO_TAG) { iout("<"); out(XMLName); //if (node.hasChildNodes()) out(" children=" + node.getChildNodes().getLength() + " first=" + node.getFirstChild()); out(">"); if (firstChild == null || (isText(firstChild) && firstChild == lastChild)) { // if (firstChild != null && firstChild.getNodeType() == Node.CDATA_SECTION_NODE) // ; // else closeOnSameLine = true; } else if (XML_OUTPUT) System.out.print('\n'); if (FOLD_TEXT && (type != Node.ELEMENT_NODE && type != Node.ATTRIBUTE_NODE)) { final String err = "UNHANDLED TYPE=" + type + "; " + nodeName; outln("<" + err + ">"); errout(err); } } if (outputValue != null) { if (type == Node.CDATA_SECTION_NODE) { out("<![CDATA["); out(outputValue); out("]]>"); } else { out(XMLEntityEncode(outputValue)); } } if (!isAttribute && node != null) { // god knows why, but attributes have themselves as children? (or is that // the #text entry?) Anyway, if we allow this for an attribute dump, the // value of the attribute will literally appear twice in the output, // back-to-back as one string. depth++; if (FOLD_KEYS || schema.isXMLKeyFold()) { scanFoldedChildren(schema, children, fullName, nodeName); } else { for (int i = 0; i < children.getLength(); i++) scanNode(schema, children.item(i), fullName, nodeName); } depth--; } if (DO_TAG) { if (closeOnSameLine) outln("</" + XMLName + ">"); else ioutln("</" + XMLName + ">"); } if (type == Node.ELEMENT_NODE) schema.trackNodeClose(fullName); if (hasAttributes && !ATTRIBUTES_IMMEDIATE) scanAttributes(schema, fullName, nodeName, node.getAttributes()); //iout("children: " + Util.tags(n.getChildNodes())); }