List of usage examples for org.w3c.dom Node DOCUMENT_NODE
short DOCUMENT_NODE
To view the source code for org.w3c.dom Node DOCUMENT_NODE.
Click Source Link
Document
. From source file:org.adl.validator.contentpackage.CPValidator.java
/** * This method tracks all identifier values found in the manifest for the * organization elements only. Tracking of organization identifiers is * performed in order to verify that default attribute points to valid * organization identifier value. These identifers are tracked recursively * by walking through test subject dom and adding the identifier elements * found to a list.// www. j av a 2s . c o m * * @param iParentNode * Root node of the test subject */ private void trackOrgIdentifiers(Node iParentNode) { // recursively find the organization ids and add them to the List mLogger.debug("CPValidator trackOrgIdentifiers()"); String msgText = ""; if (iParentNode != null) { int type = iParentNode.getNodeType(); switch (type) { case Node.DOCUMENT_NODE: { Node rootNode = ((Document) iParentNode).getDocumentElement(); trackOrgIdentifiers(rootNode); break; } case Node.ELEMENT_NODE: { String nodeName = iParentNode.getLocalName(); if (nodeName.equals("manifest")) { Node orgsNode = DOMTreeUtility.getNode(iParentNode, "organizations"); if (orgsNode != null) { List<Node> orgNodes = DOMTreeUtility.getNodes(orgsNode, "organization"); // Loop through the oganization elements to retrieve the // identifier attribute values int orgNodesSize = orgNodes.size(); for (int i = 0; i < orgNodesSize; i++) { Node currentChild = orgNodes.get(i); String orgIdentifier = DOMTreeUtility.getAttributeValue(currentChild, "identifier"); mOrganizationIdentifierList.add(orgIdentifier); msgText = "Just added " + orgIdentifier + "to the org List"; mLogger.debug(msgText); } } } // Get (sub)manifests and make call recursively List<Node> subManifestList = DOMTreeUtility.getNodes(iParentNode, "manifest"); int subManifestListSize = subManifestList.size(); for (int j = 0; j < subManifestListSize; j++) { Node currentSubManifest = subManifestList.get(j); trackOrgIdentifiers(currentSubManifest); } break; } default: { // Do nothing - no defined requirements to process any other // type of node type break; } } } mLogger.debug("CPValidator trackOrgIdentifiers()"); }
From source file:org.adl.validator.contentpackage.ManifestMap.java
/** * This method populates the ManifestMap object by traversing down * the document node and storing all information necessary for the validation * of (Sub) manifests. Information stored for each manifest element includes: * manifest identifiers,item identifers, item identifierrefs, and * resource identifiers/*from w ww . j ava2s . c o m*/ * * @param iNode the node being checked. All checks will depend on the type of node * being evaluated * * @return - The boolean describing if the ManifestMap object(s) has been * populated properly. */ public boolean populateManifestMap(Node iNode) { // looks exactly like prunetree as we walk down the tree log.debug("populateManifestMap"); boolean result = true; // is there anything to do? if (iNode == null) { result = false; return result; } int type = iNode.getNodeType(); switch (type) { case Node.PROCESSING_INSTRUCTION_NODE: { break; } case Node.DOCUMENT_NODE: { Node rootNode = ((Document) iNode).getDocumentElement(); result = populateManifestMap(rootNode) && result; break; } case Node.ELEMENT_NODE: { String parentNodeName = iNode.getLocalName(); if (parentNodeName.equalsIgnoreCase("manifest")) { // We are dealing with an IMS <manifest> element, get the IMS // CP identifier for the <manifest> elememnt mManifestId = DOMTreeUtility.getAttributeValue(iNode, "identifier"); log.debug( "ManifestMap:populateManifestMap, " + "Just stored a Manifest Id value of " + mManifestId); // Recurse to populate mItemIdrefs and mItemIds // Find the <organization> elements Node orgsNode = DOMTreeUtility.getNode(iNode, "organizations"); if (orgsNode != null) { List<Node> orgElems = DOMTreeUtility.getNodes(orgsNode, "organization"); log.debug("ManifestMap:populateManifestMap, " + "Number of <organization> elements: " + orgElems.size()); if (!orgElems.isEmpty()) { int orgElemsSize = orgElems.size(); for (int i = 0; i < orgElemsSize; i++) { List<Node> itemElems = DOMTreeUtility.getNodes(orgElems.get(i), "item"); log.debug("ManifestMap:populateManifestMap, " + "Number of <item> elements: " + itemElems.size()); if (!itemElems.isEmpty()) { int itemElemsSize = itemElems.size(); for (int j = 0; j < itemElemsSize; j++) { result = populateManifestMap((itemElems.get(j))) && result; } } } } } //recurse to populate mResourceIds Node resourcesNode = DOMTreeUtility.getNode(iNode, "resources"); if (resourcesNode != null) { List<Node> resourceElems = DOMTreeUtility.getNodes(resourcesNode, "resource"); log.debug("ManifestMap:populateManifestMap, " + "Number of <resource> elements: " + resourceElems.size()); int resourceElemsSize = resourceElems.size(); for (int k = 0; k < resourceElemsSize; k++) { result = populateManifestMap((resourceElems.get(k))) && result; } } //recurse to populate mManifestMaps //find the <manifest> elements (a.k.a sub-manifests) List<Node> subManifests = DOMTreeUtility.getNodes(iNode, "manifest"); log.debug("ManifestMap:populateManifestMap, " + "Number of (Sub) manifest elements: " + subManifests.size()); if (!subManifests.isEmpty()) { mDoSubmanifestExist = true; int subManifestSize = subManifests.size(); for (int l = 0; l < subManifestSize; l++) { ManifestMap manifestMapObject = new ManifestMap(); result = manifestMapObject.populateManifestMap(subManifests.get(l)) && result; mManifestMaps.add(manifestMapObject); } } } else if (parentNodeName.equalsIgnoreCase("item")) { //store item identifier value String itemId = DOMTreeUtility.getAttributeValue(iNode, "identifier"); mItemIds.add(itemId); log.debug("ManifestMap:populateManifestMap, " + "Just stored an Item Id value of " + itemId); //store item identifier reference value String itemIdref = DOMTreeUtility.getAttributeValue(iNode, "identifierref"); mItemIdrefs.add(itemIdref); log.debug("ManifestMap:populateManifestMap, " + "Just stored an Item Idref value of " + itemIdref); //recurse to populate all child item elements List<Node> items = DOMTreeUtility.getNodes(iNode, "item"); if (!items.isEmpty()) { int itemsSize = items.size(); for (int z = 0; z < itemsSize; z++) { result = populateManifestMap(items.get(z)) && result; } } } else if (parentNodeName.equalsIgnoreCase("resource")) { //store resource identifier value String resourceId = DOMTreeUtility.getAttributeValue(iNode, "identifier"); // convert to lower so case sensativity does not play a role mResourceIds.add(resourceId); log.debug("ManifestMap:populateManifestMap, " + "Just stored a Resource Id value of " + resourceId); // populate <dependency> element List<Node> dependencyElems = DOMTreeUtility.getNodes(iNode, "dependency"); int dependencyElemsSize = dependencyElems.size(); for (int w = 0; w < dependencyElemsSize; w++) { Node dependencyElem = dependencyElems.get(w); //store resource identifier value String dependencyIdref = DOMTreeUtility.getAttributeValue(dependencyElem, "identifierref"); mDependencyIdrefs.add(dependencyIdref); log.debug("ManifestMap:populateManifestMap, " + "Just stored a Dependency Idref value of " + mDependencyIdrefs); } } break; } // handle entity reference nodes case Node.ENTITY_REFERENCE_NODE: { break; } // text case Node.COMMENT_NODE: { break; } case Node.CDATA_SECTION_NODE: { break; } case Node.TEXT_NODE: { break; } } log.debug("populateManifestMap"); return result; }
From source file:org.apache.camel.component.xmlsecurity.api.XAdESSignatureProperties.java
@Override public Output get(Input input) throws Exception { //NOPMD XmlSignatureProperties.Output result = new Output(); if (!isAddSignedSignatureProperties() && !isAddSignedDataObjectPropeties()) { LOG.debug(/*from ww w . j av a 2 s.co m*/ "XAdES signature properties are empty. Therefore no XAdES element will be added to the signature."); return result; } String signedPropertiesId = "_" + UUID.randomUUID().toString(); Reference ref = input.getSignatureFactory().newReference("#" + signedPropertiesId, input.getSignatureFactory().newDigestMethod(input.getContentDigestAlgorithm(), null), Collections.emptyList(), "http://uri.etsi.org/01903#SignedProperties", null); Node parent = input.getParent(); Document doc; if (Node.DOCUMENT_NODE == parent.getNodeType()) { doc = (Document) parent; // enveloping } else { doc = parent.getOwnerDocument(); // enveloped } Element qualifyingProperties = createElement("QualifyingProperties", doc, input); setIdAttributeFromHeader(XmlSignatureConstants.HEADER_XADES_QUALIFYING_PROPERTIES_ID, qualifyingProperties, input); String signatureId = input.getSignatureId(); if (signatureId == null || signatureId.isEmpty()) { LOG.debug("No signature Id configured. Therefore a value is generated."); // generate one signatureId = "_" + UUID.randomUUID().toString(); // and set to output result.setSignatureId(signatureId); } setAttribute(qualifyingProperties, "Target", "#" + signatureId); Element signedProperties = createElement("SignedProperties", doc, input); qualifyingProperties.appendChild(signedProperties); setAttribute(signedProperties, "Id", signedPropertiesId); signedProperties.setIdAttribute("Id", true); addSignedSignatureProperties(doc, signedProperties, input); String contentReferenceId = addSignedDataObjectProperties(doc, signedProperties, input); result.setContentReferenceId(contentReferenceId); DOMStructure structure = new DOMStructure(qualifyingProperties); XMLObject propertiesObject = input.getSignatureFactory().newXMLObject(Collections.singletonList(structure), null, null, null); result.setReferences(Collections.singletonList(ref)); result.setObjects(Collections.singletonList(propertiesObject)); return result; }
From source file:org.apache.cocoon.xml.dom.DOMUtil.java
/** * Get the owner of the DOM document belonging to the node. * This works even if the node is the document itself. * * @param node The node./*from w w w . j a v a 2 s .c o m*/ * @return The corresponding document. */ public static Document getOwnerDocument(Node node) { if (node.getNodeType() == Node.DOCUMENT_NODE) { return (Document) node; } else { return node.getOwnerDocument(); } }
From source file:org.apache.hise.utils.DOMUtils.java
/** * Convert a DOM node to a stringified XML representation. *///from w w w. j a v a 2s . com static public String domToString(Node node) { if (node == null) { throw new IllegalArgumentException("Cannot stringify null Node!"); } String value = null; short nodeType = node.getNodeType(); if (nodeType == Node.ELEMENT_NODE || nodeType == Node.DOCUMENT_NODE) { // serializer doesn't handle Node type well, only Element DOMSerializerImpl ser = new DOMSerializerImpl(); ser.setParameter(Constants.DOM_NAMESPACES, Boolean.TRUE); ser.setParameter(Constants.DOM_WELLFORMED, Boolean.FALSE); ser.setParameter(Constants.DOM_VALIDATE, Boolean.FALSE); // create a proper XML encoding header based on the input document; // default to UTF-8 if the parent document's encoding is not accessible String usedEncoding = "UTF-8"; Document parent = node.getOwnerDocument(); if (parent != null) { String parentEncoding = parent.getXmlEncoding(); if (parentEncoding != null) { usedEncoding = parentEncoding; } } // the receiver of the DOM DOMOutputImpl out = new DOMOutputImpl(); out.setEncoding(usedEncoding); // we write into a String StringWriter writer = new StringWriter(4096); out.setCharacterStream(writer); // out, ye characters! ser.write(node, out); writer.flush(); // finally get the String value = writer.toString(); } else { value = node.getNodeValue(); } return value; }
From source file:org.apache.jmeter.protocol.http.parser.JTidyHTMLParser.java
/** * Scan nodes recursively, looking for embedded resources * * @param node -/* w w w .java 2s . c om*/ * initial node * @param urls - * container for URLs * @param baseUrl - * used to create absolute URLs * * @return new base URL */ private URL scanNodes(Node node, URLCollection urls, URL baseUrl) throws HTMLParseException { if (node == null) { return baseUrl; } String name = node.getNodeName(); int type = node.getNodeType(); switch (type) { case Node.DOCUMENT_NODE: scanNodes(((Document) node).getDocumentElement(), urls, baseUrl); break; case Node.ELEMENT_NODE: NamedNodeMap attrs = node.getAttributes(); if (name.equalsIgnoreCase(TAG_BASE)) { String tmp = getValue(attrs, ATT_HREF); if (tmp != null) { try { baseUrl = ConversionUtils.makeRelativeURL(baseUrl, tmp); } catch (MalformedURLException e) { throw new HTMLParseException(e); } } break; } if (name.equalsIgnoreCase(TAG_IMAGE) || name.equalsIgnoreCase(TAG_EMBED)) { urls.addURL(getValue(attrs, ATT_SRC), baseUrl); break; } if (name.equalsIgnoreCase(TAG_APPLET)) { urls.addURL(getValue(attrs, "code"), baseUrl); break; } if (name.equalsIgnoreCase(TAG_OBJECT)) { String data = getValue(attrs, "codebase"); if (!StringUtils.isEmpty(data)) { urls.addURL(data, baseUrl); } data = getValue(attrs, "data"); if (!StringUtils.isEmpty(data)) { urls.addURL(data, baseUrl); } break; } if (name.equalsIgnoreCase(TAG_INPUT)) { String src = getValue(attrs, ATT_SRC); String typ = getValue(attrs, ATT_TYPE); if ((src != null) && (typ.equalsIgnoreCase(ATT_IS_IMAGE))) { urls.addURL(src, baseUrl); } break; } if (name.equalsIgnoreCase(TAG_LINK) && getValue(attrs, ATT_REL).equalsIgnoreCase(STYLESHEET)) { urls.addURL(getValue(attrs, ATT_HREF), baseUrl); break; } if (name.equalsIgnoreCase(TAG_SCRIPT)) { urls.addURL(getValue(attrs, ATT_SRC), baseUrl); break; } if (name.equalsIgnoreCase(TAG_FRAME)) { urls.addURL(getValue(attrs, ATT_SRC), baseUrl); break; } if (name.equalsIgnoreCase(TAG_IFRAME)) { urls.addURL(getValue(attrs, ATT_SRC), baseUrl); break; } String back = getValue(attrs, ATT_BACKGROUND); if (back != null) { urls.addURL(back, baseUrl); } if (name.equalsIgnoreCase(TAG_BGSOUND)) { urls.addURL(getValue(attrs, ATT_SRC), baseUrl); break; } String style = getValue(attrs, ATT_STYLE); if (style != null) { HtmlParsingUtils.extractStyleURLs(baseUrl, urls, style); } NodeList children = node.getChildNodes(); if (children != null) { int len = children.getLength(); for (int i = 0; i < len; i++) { baseUrl = scanNodes(children.item(i), urls, baseUrl); } } break; // case Node.TEXT_NODE: // break; default: // ignored break; } return baseUrl; }
From source file:org.apache.ode.bpel.elang.xpath20.runtime.XPath20ExpressionRuntime.java
/** * @see org.apache.ode.bpel.explang.ExpressionLanguageRuntime#evaluate(org.apache.ode.bpel.o.OExpression, org.apache.ode.bpel.explang.EvaluationContext) */// w w w.j a v a 2s . c o m @SuppressWarnings("unchecked") public List evaluate(OExpression cexp, EvaluationContext ctx) throws FaultException, EvaluationException { List result; Object someRes = null; try { someRes = evaluate(cexp, ctx, XPathConstants.NODESET); } catch (Exception e) { someRes = evaluate(cexp, ctx, XPathConstants.STRING); } if (someRes instanceof List) { result = (List) someRes; if (__log.isDebugEnabled()) { __log.debug("Returned list of size " + result.size()); } if ((result.size() == 1) && !(result.get(0) instanceof Node)) { // Dealing with a Java class Object simpleType = result.get(0); // Dates get a separate treatment as we don't want to call toString on them String textVal; if (simpleType instanceof Date) { textVal = ISO8601DateParser.format((Date) simpleType); } else if (simpleType instanceof DurationValue) { textVal = ((DurationValue) simpleType).getStringValue(); } else { textVal = simpleType.toString(); } // Wrapping in a document Document document = DOMUtils.newDocument(); // Giving our node a parent just in case it's an LValue expression Element wrapper = document.createElement("wrapper"); Text text = document.createTextNode(textVal); wrapper.appendChild(text); document.appendChild(wrapper); result = Collections.singletonList(text); } } else if (someRes instanceof NodeList) { NodeList retVal = (NodeList) someRes; if (__log.isDebugEnabled()) { __log.debug("Returned node list of size " + retVal.getLength()); } result = new ArrayList(retVal.getLength()); for (int m = 0; m < retVal.getLength(); ++m) { Node val = retVal.item(m); if (val.getNodeType() == Node.DOCUMENT_NODE) { val = ((Document) val).getDocumentElement(); } result.add(val); } } else if (someRes instanceof String) { // Wrapping in a document Document document = DOMUtils.newDocument(); Element wrapper = document.createElement("wrapper"); Text text = document.createTextNode((String) someRes); wrapper.appendChild(text); document.appendChild(wrapper); result = Collections.singletonList(text); } else { result = null; } return result; }
From source file:org.apache.ode.bpel.elang.xquery10.runtime.XQuery10ExpressionRuntime.java
/** * * @see org.apache.ode.bpel.explang.ExpressionLanguageRuntime#evaluate(org.apache.ode.bpel.o.OExpression, * org.apache.ode.bpel.explang.EvaluationContext) *///from w ww . j av a2 s . c o m public List evaluate(OExpression cexp, EvaluationContext ctx) throws FaultException, EvaluationException { List result; Object someRes = evaluate(cexp, ctx, XPathConstants.NODESET); if (someRes instanceof List) { result = (List) someRes; if (__log.isDebugEnabled()) { __log.debug("Returned list of size " + result.size()); } if ((result.size() == 1) && !(result.get(0) instanceof Node)) { // Dealing with a Java class Object simpleType = result.get(0); // Dates get a separate treatment as we don't want to call toString on them String textVal; if (simpleType instanceof Date) { textVal = ISO8601DateParser.format((Date) simpleType); } else if (simpleType instanceof DurationValue) { textVal = ((DurationValue) simpleType).getStringValue(); } else { textVal = simpleType.toString(); } // Wrapping in a document Document d = DOMUtils.newDocument(); // Giving our node a parent just in case it's an LValue expression Element wrapper = d.createElement("wrapper"); Text text = d.createTextNode(textVal); wrapper.appendChild(text); d.appendChild(wrapper); result = Collections.singletonList(text); } } else if (someRes instanceof NodeList) { NodeList retVal = (NodeList) someRes; if (__log.isDebugEnabled()) { __log.debug("Returned node list of size " + retVal.getLength()); } result = new ArrayList(retVal.getLength()); for (int m = 0; m < retVal.getLength(); ++m) { Node val = retVal.item(m); if (val.getNodeType() == Node.DOCUMENT_NODE) { val = ((Document) val).getDocumentElement(); } result.add(val); } } else { result = null; } return result; }
From source file:org.apache.ode.bpel.rtrep.v1.ASSIGN.java
private void copy(OAssign.Copy ocopy) throws FaultException, ExternalVariableModuleException { if (__log.isDebugEnabled()) __log.debug("Assign.copy(" + ocopy + ")"); ScopeEvent se;//from w w w. j a v a 2 s . co m // Check for message to message - copy, we can do this efficiently in // the database. if ((ocopy.to instanceof VariableRef && ((VariableRef) ocopy.to).isMessageRef()) || (ocopy.from instanceof VariableRef && ((VariableRef) ocopy.from).isMessageRef())) { if ((ocopy.to instanceof VariableRef && ((VariableRef) ocopy.to).isMessageRef()) && ocopy.from instanceof VariableRef && ((VariableRef) ocopy.from).isMessageRef()) { final VariableInstance lval = _scopeFrame.resolve(ocopy.to.getVariable()); final VariableInstance rval = _scopeFrame.resolve(((VariableRef) ocopy.from).getVariable()); Element lvalue = (Element) fetchVariableData(rval, false); initializeVariable(lval, lvalue); se = new VariableModificationEvent(lval.declaration.name); ((VariableModificationEvent) se).setNewValue(lvalue); } else { // This really should have been caught by the compiler. __log.fatal("Message/Non-Message Assignment, should be caught by compiler:" + ocopy); throw new FaultException(ocopy.getOwner().constants.qnSelectionFailure, "Message/Non-Message Assignment: " + ocopy); } } else { // Conventional Assignment logic. Node rvalue = evalRValue(ocopy.from); Node lvalue = evalLValue(ocopy.to); if (__log.isDebugEnabled()) { __log.debug("lvalue after eval " + lvalue); if (lvalue != null) __log.debug("content " + DOMUtils.domToString(lvalue)); } // Get a pointer within the lvalue. Node lvaluePtr = lvalue; boolean headerAssign = false; if (ocopy.to instanceof OAssign.DirectRef) { DirectRef dref = ((DirectRef) ocopy.to); Element el = DOMUtils.findChildByName((Element) lvalue, dref.elName); if (el == null) { el = (Element) ((Element) lvalue).appendChild(lvalue.getOwnerDocument() .createElementNS(dref.elName.getNamespaceURI(), dref.elName.getLocalPart())); } lvaluePtr = el; } else if (ocopy.to instanceof OAssign.VariableRef) { VariableRef varRef = ((VariableRef) ocopy.to); if (varRef.headerPart != null) headerAssign = true; lvaluePtr = evalQuery(lvalue, varRef.part != null ? varRef.part : varRef.headerPart, varRef.location, new EvaluationContextProxy(varRef.getVariable(), lvalue)); } else if (ocopy.to instanceof OAssign.PropertyRef) { PropertyRef propRef = ((PropertyRef) ocopy.to); lvaluePtr = evalQuery(lvalue, propRef.propertyAlias.part, propRef.propertyAlias.location, new EvaluationContextProxy(propRef.getVariable(), lvalue)); } else if (ocopy.to instanceof OAssign.LValueExpression) { LValueExpression lexpr = (LValueExpression) ocopy.to; lvaluePtr = evalQuery(lvalue, null, lexpr.expression, new EvaluationContextProxy(lexpr.getVariable(), lvalue)); if (__log.isDebugEnabled()) __log.debug("lvaluePtr expr res " + lvaluePtr); } // For partner link assignmenent, the whole content is assigned. if (ocopy.to instanceof OAssign.PartnerLinkRef) { OAssign.PartnerLinkRef pLinkRef = ((OAssign.PartnerLinkRef) ocopy.to); PartnerLinkInstance plval = _scopeFrame.resolve(pLinkRef.partnerLink); replaceEndpointRefence(plval, rvalue); se = new PartnerLinkModificationEvent(((OAssign.PartnerLinkRef) ocopy.to).partnerLink.getName()); } else { // Sneakily converting the EPR if it's not the format expected by the lvalue if (ocopy.from instanceof OAssign.PartnerLinkRef) { rvalue = getBpelRuntime().convertEndpointReference((Element) rvalue, lvaluePtr); if (rvalue.getNodeType() == Node.DOCUMENT_NODE) rvalue = ((Document) rvalue).getDocumentElement(); } if (headerAssign && lvaluePtr.getParentNode().getNodeName().equals("message") && rvalue.getNodeType() == Node.ELEMENT_NODE) { lvalue = copyInto((Element) lvalue, (Element) lvaluePtr, (Element) rvalue); } else if (rvalue.getNodeType() == Node.ELEMENT_NODE && lvaluePtr.getNodeType() == Node.ELEMENT_NODE) { lvalue = replaceElement((Element) lvalue, (Element) lvaluePtr, (Element) rvalue, ocopy.keepSrcElementName); } else { lvalue = replaceContent(lvalue, lvaluePtr, rvalue.getTextContent()); } final VariableInstance lval = _scopeFrame.resolve(ocopy.to.getVariable()); if (__log.isDebugEnabled()) __log.debug("ASSIGN Writing variable '" + lval.declaration.name + "' value '" + DOMUtils.domToString(lvalue) + "'"); commitChanges(lval, lvalue); se = new VariableModificationEvent(lval.declaration.name); ((VariableModificationEvent) se).setNewValue(lvalue); } } if (ocopy.debugInfo != null) se.setLineNo(ocopy.debugInfo.startLine); sendEvent(se); }
From source file:org.apache.ode.bpel.rtrep.v1.xpath10.jaxp.JaxpXPath10ExpressionRuntime.java
public List evaluate(OExpression cexp, EvaluationContext ctx) throws FaultException { List result;/* w w w. j a v a 2s .c o m*/ Object someRes = null; try { someRes = evaluate(cexp, ctx, XPathConstants.NODESET); } catch (FaultException ex) { try { // JDK implementation of evaluation seems to be more strict about result types than Saxon: // basic return types are not converted to lists automatically. // this simulates Saxon behaviour: get a string result and put it in a list. List resultList = new ArrayList(1); resultList.add(evaluateAsString(cexp, ctx)); someRes = resultList; } catch (Exception ex2) { // re-throw original exception if workaround does not work. throw ex; } } if (someRes instanceof List) { result = (List) someRes; __log.debug("Returned list of size " + result.size()); if ((result.size() == 1) && !(result.get(0) instanceof Node)) { // Dealing with a Java class Object simpleType = result.get(0); // Dates get a separate treatment as we don't want to call toString on them String textVal; if (simpleType instanceof Date) textVal = ISO8601DateParser.format((Date) simpleType); else textVal = simpleType.toString(); // Wrapping in a document Document d = DOMUtils.newDocument(); // Giving our node a parent just in case it's an LValue expression Element wrapper = d.createElement("wrapper"); Text text = d.createTextNode(textVal); wrapper.appendChild(text); d.appendChild(wrapper); result = Collections.singletonList(text); } } else if (someRes instanceof NodeList) { NodeList retVal = (NodeList) someRes; __log.debug("Returned node list of size " + retVal.getLength()); result = new ArrayList(retVal.getLength()); for (int m = 0; m < retVal.getLength(); ++m) { Node val = retVal.item(m); if (val.getNodeType() == Node.DOCUMENT_NODE) val = ((Document) val).getDocumentElement(); result.add(val); } } else { result = null; } return result; }