Java Code Examples for com.sun.org.apache.xpath.internal.XPathContext#getCurrentNode()
The following examples show how to use
com.sun.org.apache.xpath.internal.XPathContext#getCurrentNode() .
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: FunctionDef1Arg.java From Bytecoder with Apache License 2.0 | 6 votes |
/** * Execute the first argument expression that is expected to return a * string. If the argument is null, then get the string value from the * current context node. * * @param xctxt Runtime XPath context. * * @return The string value of the first argument, or the string value of the * current context node if the first argument is null. * * @throws javax.xml.transform.TransformerException if an error occurs while * executing the argument expression. */ protected XMLString getArg0AsString(XPathContext xctxt) throws javax.xml.transform.TransformerException { if(null == m_arg0) { int currentNode = xctxt.getCurrentNode(); if(DTM.NULL == currentNode) return XString.EMPTYSTRING; else { DTM dtm = xctxt.getDTM(currentNode); return dtm.getStringValue(currentNode); } } else return m_arg0.execute(xctxt).xstr(); }
Example 2
Source File: LocPathIterator.java From openjdk-8 with GNU General Public License v2.0 | 6 votes |
/** * Execute an expression in the XPath runtime context, and return the * result of the expression. * * * @param xctxt The XPath runtime context. * @param handler The target content handler. * * @return The result of the expression in the form of a <code>XObject</code>. * * @throws javax.xml.transform.TransformerException if a runtime exception * occurs. * @throws org.xml.sax.SAXException */ public void executeCharsToContentHandler( XPathContext xctxt, org.xml.sax.ContentHandler handler) throws javax.xml.transform.TransformerException, org.xml.sax.SAXException { LocPathIterator clone = (LocPathIterator)m_clones.getInstance(); int current = xctxt.getCurrentNode(); clone.setRoot(current, xctxt); int node = clone.nextNode(); DTM dtm = clone.getDTM(node); clone.detach(); if(node != DTM.NULL) { dtm.dispatchCharactersEvents(node, handler, false); } }
Example 3
Source File: LocPathIterator.java From openjdk-jdk9 with GNU General Public License v2.0 | 6 votes |
/** * Execute an expression in the XPath runtime context, and return the * result of the expression. * * * @param xctxt The XPath runtime context. * @param handler The target content handler. * * @return The result of the expression in the form of a <code>XObject</code>. * * @throws javax.xml.transform.TransformerException if a runtime exception * occurs. * @throws org.xml.sax.SAXException */ public void executeCharsToContentHandler( XPathContext xctxt, org.xml.sax.ContentHandler handler) throws javax.xml.transform.TransformerException, org.xml.sax.SAXException { LocPathIterator clone = (LocPathIterator)m_clones.getInstance(); int current = xctxt.getCurrentNode(); clone.setRoot(current, xctxt); int node = clone.nextNode(); DTM dtm = clone.getDTM(node); clone.detach(); if(node != DTM.NULL) { dtm.dispatchCharactersEvents(node, handler, false); } }
Example 4
Source File: FunctionDef1Arg.java From JDKSourceCode1.8 with MIT License | 6 votes |
/** * Execute the first argument expression that is expected to return a * number. If the argument is null, then get the number value from the * current context node. * * @param xctxt Runtime XPath context. * * @return The number value of the first argument, or the number value of the * current context node if the first argument is null. * * @throws javax.xml.transform.TransformerException if an error occurs while * executing the argument expression. */ protected double getArg0AsNumber(XPathContext xctxt) throws javax.xml.transform.TransformerException { if(null == m_arg0) { int currentNode = xctxt.getCurrentNode(); if(DTM.NULL == currentNode) return 0; else { DTM dtm = xctxt.getDTM(currentNode); XMLString str = dtm.getStringValue(currentNode); return str.toDouble(); } } else return m_arg0.execute(xctxt).num(); }
Example 5
Source File: ChildIterator.java From openjdk-8-source with GNU General Public License v2.0 | 5 votes |
/** * Return the first node out of the nodeset, if this expression is * a nodeset expression. This is the default implementation for * nodesets. * <p>WARNING: Do not mutate this class from this function!</p> * @param xctxt The XPath runtime context. * @return the first node out of the nodeset, or DTM.NULL. */ public int asNode(XPathContext xctxt) throws javax.xml.transform.TransformerException { int current = xctxt.getCurrentNode(); DTM dtm = xctxt.getDTM(current); return dtm.getFirstChild(current); }
Example 6
Source File: ChildIterator.java From TencentKona-8 with GNU General Public License v2.0 | 5 votes |
/** * Return the first node out of the nodeset, if this expression is * a nodeset expression. This is the default implementation for * nodesets. * <p>WARNING: Do not mutate this class from this function!</p> * @param xctxt The XPath runtime context. * @return the first node out of the nodeset, or DTM.NULL. */ public int asNode(XPathContext xctxt) throws javax.xml.transform.TransformerException { int current = xctxt.getCurrentNode(); DTM dtm = xctxt.getDTM(current); return dtm.getFirstChild(current); }
Example 7
Source File: FuncLang.java From JDKSourceCode1.8 with MIT License | 5 votes |
/** * Execute the function. The function must return * a valid object. * @param xctxt The current execution context. * @return A valid XObject. * * @throws javax.xml.transform.TransformerException */ public XObject execute(XPathContext xctxt) throws javax.xml.transform.TransformerException { String lang = m_arg0.execute(xctxt).str(); int parent = xctxt.getCurrentNode(); boolean isLang = false; DTM dtm = xctxt.getDTM(parent); while (DTM.NULL != parent) { if (DTM.ELEMENT_NODE == dtm.getNodeType(parent)) { int langAttr = dtm.getAttributeNode(parent, "http://www.w3.org/XML/1998/namespace", "lang"); if (DTM.NULL != langAttr) { String langVal = dtm.getNodeValue(langAttr); // %OPT% if (langVal.toLowerCase().startsWith(lang.toLowerCase())) { int valLen = lang.length(); if ((langVal.length() == valLen) || (langVal.charAt(valLen) == '-')) { isLang = true; } } break; } } parent = dtm.getParent(parent); } return isLang ? XBoolean.S_TRUE : XBoolean.S_FALSE; }
Example 8
Source File: FuncUnparsedEntityURI.java From Bytecoder with Apache License 2.0 | 5 votes |
/** * Execute the function. The function must return * a valid object. * @param xctxt The current execution context. * @return A valid XObject. * * @throws javax.xml.transform.TransformerException */ public XObject execute(XPathContext xctxt) throws javax.xml.transform.TransformerException { String name = m_arg0.execute(xctxt).str(); int context = xctxt.getCurrentNode(); DTM dtm = xctxt.getDTM(context); int doc = dtm.getDocument(); String uri = dtm.getUnparsedEntityURI(name); return new XString(uri); }
Example 9
Source File: FunctionPattern.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
/** * Test a node to see if it matches the given node test. * * @param xctxt XPath runtime context. * * @return {@link com.sun.org.apache.xpath.internal.patterns.NodeTest#SCORE_NODETEST}, * {@link com.sun.org.apache.xpath.internal.patterns.NodeTest#SCORE_NONE}, * {@link com.sun.org.apache.xpath.internal.patterns.NodeTest#SCORE_NSWILD}, * {@link com.sun.org.apache.xpath.internal.patterns.NodeTest#SCORE_QNAME}, or * {@link com.sun.org.apache.xpath.internal.patterns.NodeTest#SCORE_OTHER}. * * @throws javax.xml.transform.TransformerException */ public XObject execute(XPathContext xctxt) throws javax.xml.transform.TransformerException { int context = xctxt.getCurrentNode(); DTMIterator nl = m_functionExpr.asIterator(xctxt, context); XNumber score = SCORE_NONE; if (null != nl) { int n; while (DTM.NULL != (n = nl.nextNode())) { score = (n == context) ? SCORE_OTHER : SCORE_NONE; if (score == SCORE_OTHER) { context = n; break; } } nl.detach(); } return score; }
Example 10
Source File: LocPathIterator.java From jdk8u60 with GNU General Public License v2.0 | 5 votes |
/** * Return the first node out of the nodeset, if this expression is * a nodeset expression. This is the default implementation for * nodesets. Derived classes should try and override this and return a * value without having to do a clone operation. * @param xctxt The XPath runtime context. * @return the first node out of the nodeset, or DTM.NULL. */ public int asNode(XPathContext xctxt) throws javax.xml.transform.TransformerException { DTMIterator iter = (DTMIterator)m_clones.getInstance(); int current = xctxt.getCurrentNode(); iter.setRoot(current, xctxt); int next = iter.nextNode(); // m_clones.freeInstance(iter); iter.detach(); return next; }
Example 11
Source File: FuncLang.java From TencentKona-8 with GNU General Public License v2.0 | 5 votes |
/** * Execute the function. The function must return * a valid object. * @param xctxt The current execution context. * @return A valid XObject. * * @throws javax.xml.transform.TransformerException */ public XObject execute(XPathContext xctxt) throws javax.xml.transform.TransformerException { String lang = m_arg0.execute(xctxt).str(); int parent = xctxt.getCurrentNode(); boolean isLang = false; DTM dtm = xctxt.getDTM(parent); while (DTM.NULL != parent) { if (DTM.ELEMENT_NODE == dtm.getNodeType(parent)) { int langAttr = dtm.getAttributeNode(parent, "http://www.w3.org/XML/1998/namespace", "lang"); if (DTM.NULL != langAttr) { String langVal = dtm.getNodeValue(langAttr); // %OPT% if (langVal.toLowerCase().startsWith(lang.toLowerCase())) { int valLen = lang.length(); if ((langVal.length() == valLen) || (langVal.charAt(valLen) == '-')) { isLang = true; } } break; } } parent = dtm.getParent(parent); } return isLang ? XBoolean.S_TRUE : XBoolean.S_FALSE; }
Example 12
Source File: FuncHere.java From openjdk-8 with GNU General Public License v2.0 | 4 votes |
/** * The here function returns a node-set containing the attribute or * processing instruction node or the parent element of the text node * that directly bears the XPath expression. This expression results * in an error if the containing XPath expression does not appear in the * same XML document against which the XPath expression is being evaluated. * * @param xctxt * @return the xobject * @throws javax.xml.transform.TransformerException */ @Override public XObject execute(XPathContext xctxt) throws javax.xml.transform.TransformerException { Node xpathOwnerNode = (Node) xctxt.getOwnerObject(); if (xpathOwnerNode == null) { return null; } int xpathOwnerNodeDTM = xctxt.getDTMHandleFromNode(xpathOwnerNode); int currentNode = xctxt.getCurrentNode(); DTM dtm = xctxt.getDTM(currentNode); int docContext = dtm.getDocument(); if (DTM.NULL == docContext) { error(xctxt, XPATHErrorResources.ER_CONTEXT_HAS_NO_OWNERDOC, null); } { // check whether currentNode and the node containing the XPath expression // are in the same document Document currentDoc = XMLUtils.getOwnerDocument(dtm.getNode(currentNode)); Document xpathOwnerDoc = XMLUtils.getOwnerDocument(xpathOwnerNode); if (currentDoc != xpathOwnerDoc) { throw new TransformerException(I18n.translate("xpath.funcHere.documentsDiffer")); } } XNodeSet nodes = new XNodeSet(xctxt.getDTMManager()); NodeSetDTM nodeSet = nodes.mutableNodeset(); { int hereNode = DTM.NULL; switch (dtm.getNodeType(xpathOwnerNodeDTM)) { case Node.ATTRIBUTE_NODE : case Node.PROCESSING_INSTRUCTION_NODE : { // returns a node-set containing the attribute / processing instruction node hereNode = xpathOwnerNodeDTM; nodeSet.addNode(hereNode); break; } case Node.TEXT_NODE : { // returns a node-set containing the parent element of the // text node that directly bears the XPath expression hereNode = dtm.getParent(xpathOwnerNodeDTM); nodeSet.addNode(hereNode); break; } default : break; } } /** $todo$ Do I have to do this detach() call? */ nodeSet.detach(); return nodes; }
Example 13
Source File: FuncHere.java From openjdk-8-source with GNU General Public License v2.0 | 4 votes |
/** * The here function returns a node-set containing the attribute or * processing instruction node or the parent element of the text node * that directly bears the XPath expression. This expression results * in an error if the containing XPath expression does not appear in the * same XML document against which the XPath expression is being evaluated. * * @param xctxt * @return the xobject * @throws javax.xml.transform.TransformerException */ @Override public XObject execute(XPathContext xctxt) throws javax.xml.transform.TransformerException { Node xpathOwnerNode = (Node) xctxt.getOwnerObject(); if (xpathOwnerNode == null) { return null; } int xpathOwnerNodeDTM = xctxt.getDTMHandleFromNode(xpathOwnerNode); int currentNode = xctxt.getCurrentNode(); DTM dtm = xctxt.getDTM(currentNode); int docContext = dtm.getDocument(); if (DTM.NULL == docContext) { error(xctxt, XPATHErrorResources.ER_CONTEXT_HAS_NO_OWNERDOC, null); } { // check whether currentNode and the node containing the XPath expression // are in the same document Document currentDoc = XMLUtils.getOwnerDocument(dtm.getNode(currentNode)); Document xpathOwnerDoc = XMLUtils.getOwnerDocument(xpathOwnerNode); if (currentDoc != xpathOwnerDoc) { throw new TransformerException(I18n.translate("xpath.funcHere.documentsDiffer")); } } XNodeSet nodes = new XNodeSet(xctxt.getDTMManager()); NodeSetDTM nodeSet = nodes.mutableNodeset(); { int hereNode = DTM.NULL; switch (dtm.getNodeType(xpathOwnerNodeDTM)) { case Node.ATTRIBUTE_NODE : case Node.PROCESSING_INSTRUCTION_NODE : { // returns a node-set containing the attribute / processing instruction node hereNode = xpathOwnerNodeDTM; nodeSet.addNode(hereNode); break; } case Node.TEXT_NODE : { // returns a node-set containing the parent element of the // text node that directly bears the XPath expression hereNode = dtm.getParent(xpathOwnerNodeDTM); nodeSet.addNode(hereNode); break; } default : break; } } /** $todo$ Do I have to do this detach() call? */ nodeSet.detach(); return nodes; }
Example 14
Source File: ContextMatchStepPattern.java From hottub with GNU General Public License v2.0 | 3 votes |
/** * Execute this pattern step, including predicates. * * * @param xctxt XPath runtime context. * * @return {@link com.sun.org.apache.xpath.internal.patterns.NodeTest#SCORE_NODETEST}, * {@link com.sun.org.apache.xpath.internal.patterns.NodeTest#SCORE_NONE}, * {@link com.sun.org.apache.xpath.internal.patterns.NodeTest#SCORE_NSWILD}, * {@link com.sun.org.apache.xpath.internal.patterns.NodeTest#SCORE_QNAME}, or * {@link com.sun.org.apache.xpath.internal.patterns.NodeTest#SCORE_OTHER}. * * @throws javax.xml.transform.TransformerException */ public XObject execute(XPathContext xctxt) throws javax.xml.transform.TransformerException { if (xctxt.getIteratorRoot() == xctxt.getCurrentNode()) return getStaticScore(); else return this.SCORE_NONE; }
Example 15
Source File: ContextMatchStepPattern.java From TencentKona-8 with GNU General Public License v2.0 | 3 votes |
/** * Execute this pattern step, including predicates. * * * @param xctxt XPath runtime context. * * @return {@link com.sun.org.apache.xpath.internal.patterns.NodeTest#SCORE_NODETEST}, * {@link com.sun.org.apache.xpath.internal.patterns.NodeTest#SCORE_NONE}, * {@link com.sun.org.apache.xpath.internal.patterns.NodeTest#SCORE_NSWILD}, * {@link com.sun.org.apache.xpath.internal.patterns.NodeTest#SCORE_QNAME}, or * {@link com.sun.org.apache.xpath.internal.patterns.NodeTest#SCORE_OTHER}. * * @throws javax.xml.transform.TransformerException */ public XObject execute(XPathContext xctxt) throws javax.xml.transform.TransformerException { if (xctxt.getIteratorRoot() == xctxt.getCurrentNode()) return getStaticScore(); else return this.SCORE_NONE; }
Example 16
Source File: FunctionDef1Arg.java From openjdk-jdk8u with GNU General Public License v2.0 | 3 votes |
/** * Execute the first argument expression that is expected to return a * nodeset. If the argument is null, then return the current context node. * * @param xctxt Runtime XPath context. * * @return The first node of the executed nodeset, or the current context * node if the first argument is null. * * @throws javax.xml.transform.TransformerException if an error occurs while * executing the argument expression. */ protected int getArg0AsNode(XPathContext xctxt) throws javax.xml.transform.TransformerException { return (null == m_arg0) ? xctxt.getCurrentNode() : m_arg0.asNode(xctxt); }
Example 17
Source File: SelfIteratorNoPredicate.java From openjdk-jdk9 with GNU General Public License v2.0 | 2 votes |
/** * Return the first node out of the nodeset, if this expression is * a nodeset expression. This is the default implementation for * nodesets. Derived classes should try and override this and return a * value without having to do a clone operation. * @param xctxt The XPath runtime context. * @return the first node out of the nodeset, or DTM.NULL. */ public int asNode(XPathContext xctxt) throws javax.xml.transform.TransformerException { return xctxt.getCurrentNode(); }
Example 18
Source File: SelfIteratorNoPredicate.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 2 votes |
/** * Return the first node out of the nodeset, if this expression is * a nodeset expression. This is the default implementation for * nodesets. Derived classes should try and override this and return a * value without having to do a clone operation. * @param xctxt The XPath runtime context. * @return the first node out of the nodeset, or DTM.NULL. */ public int asNode(XPathContext xctxt) throws javax.xml.transform.TransformerException { return xctxt.getCurrentNode(); }
Example 19
Source File: SelfIteratorNoPredicate.java From openjdk-jdk8u with GNU General Public License v2.0 | 2 votes |
/** * Return the first node out of the nodeset, if this expression is * a nodeset expression. This is the default implementation for * nodesets. Derived classes should try and override this and return a * value without having to do a clone operation. * @param xctxt The XPath runtime context. * @return the first node out of the nodeset, or DTM.NULL. */ public int asNode(XPathContext xctxt) throws javax.xml.transform.TransformerException { return xctxt.getCurrentNode(); }
Example 20
Source File: SelfIteratorNoPredicate.java From Bytecoder with Apache License 2.0 | 2 votes |
/** * Return the first node out of the nodeset, if this expression is * a nodeset expression. This is the default implementation for * nodesets. Derived classes should try and override this and return a * value without having to do a clone operation. * @param xctxt The XPath runtime context. * @return the first node out of the nodeset, or DTM.NULL. */ public int asNode(XPathContext xctxt) throws javax.xml.transform.TransformerException { return xctxt.getCurrentNode(); }