com.sun.org.apache.xpath.internal.objects.XObject Java Examples
The following examples show how to use
com.sun.org.apache.xpath.internal.objects.XObject.
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: VariableStack.java From JDKSourceCode1.8 with MIT License | 6 votes |
/** * Get a local variable or parameter in the current stack frame. * * * @param xctxt The XPath context, which must be passed in order to * lazy evaluate variables. * * @param index Local variable index relative to the current stack * frame bottom. * * @return The value of the variable. * * @throws TransformerException */ public XObject getLocalVariable(XPathContext xctxt, int index) throws TransformerException { index += _currentFrameBottom; XObject val = _stackFrames[index]; if(null == val) throw new TransformerException(XSLMessages.createXPATHMessage(XPATHErrorResources.ER_VARIABLE_ACCESSED_BEFORE_BIND, null), xctxt.getSAXLocator()); // "Variable accessed before it is bound!", xctxt.getSAXLocator()); // Lazy execution of variables. if (val.getType() == XObject.CLASS_UNRESOLVEDVARIABLE) return (_stackFrames[index] = val.execute(xctxt)); return val; }
Example #2
Source File: FuncCount.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 6 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 { // DTMIterator nl = m_arg0.asIterator(xctxt, xctxt.getCurrentNode()); // // We should probably make a function on the iterator for this, // // as a given implementation could optimize. // int i = 0; // // while (DTM.NULL != nl.nextNode()) // { // i++; // } // nl.detach(); DTMIterator nl = m_arg0.asIterator(xctxt, xctxt.getCurrentNode()); int i = nl.getLength(); nl.detach(); return new XNumber((double) i); }
Example #3
Source File: FuncGenerateId.java From TencentKona-8 with GNU General Public License v2.0 | 6 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 { int which = getArg0AsNode(xctxt); if (DTM.NULL != which) { // Note that this is a different value than in previous releases // of Xalan. It's sensitive to the exact encoding of the node // handle anyway, so fighting to maintain backward compatability // really didn't make sense; it may change again as we continue // to experiment with balancing document and node numbers within // that value. return new XString("N" + Integer.toHexString(which).toUpperCase()); } else return XString.EMPTYSTRING; }
Example #4
Source File: FuncCurrent.java From openjdk-jdk9 with GNU General Public License v2.0 | 6 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 { SubContextList subContextList = xctxt.getCurrentNodeList(); int currentNode = DTM.NULL; if (null != subContextList) { if (subContextList instanceof PredicatedNodeTest) { LocPathIterator iter = ((PredicatedNodeTest)subContextList) .getLocPathIterator(); currentNode = iter.getCurrentContextNode(); } else if(subContextList instanceof StepPattern) { throw new RuntimeException(XSLMessages.createMessage( XSLTErrorResources.ER_PROCESSOR_ERROR,null)); } } else { // not predicate => ContextNode == CurrentNode currentNode = xctxt.getContextNode(); } return new XNodeSet(currentNode, xctxt.getDTMManager()); }
Example #5
Source File: FuncQname.java From Bytecoder with Apache License 2.0 | 6 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 { int context = getArg0AsNode(xctxt); XObject val; if (DTM.NULL != context) { DTM dtm = xctxt.getDTM(context); String qname = dtm.getNodeNameX(context); val = (null == qname) ? XString.EMPTYSTRING : new XString(qname); } else { val = XString.EMPTYSTRING; } return val; }
Example #6
Source File: FuncGenerateId.java From jdk8u60 with GNU General Public License v2.0 | 6 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 { int which = getArg0AsNode(xctxt); if (DTM.NULL != which) { // Note that this is a different value than in previous releases // of Xalan. It's sensitive to the exact encoding of the node // handle anyway, so fighting to maintain backward compatability // really didn't make sense; it may change again as we continue // to experiment with balancing document and node numbers within // that value. return new XString("N" + Integer.toHexString(which).toUpperCase()); } else return XString.EMPTYSTRING; }
Example #7
Source File: StepPattern.java From jdk8u60 with GNU General Public License v2.0 | 6 votes |
/** * Get the match score of the given node. * * @param xctxt The XPath runtime context. * @param context The node to be tested. * * @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 double getMatchScore(XPathContext xctxt, int context) throws javax.xml.transform.TransformerException { xctxt.pushCurrentNode(context); xctxt.pushCurrentExpressionNode(context); try { XObject score = execute(xctxt); return score.num(); } finally { xctxt.popCurrentNode(); xctxt.popCurrentExpressionNode(); } // return XPath.MATCH_SCORE_NONE; }
Example #8
Source File: FuncQname.java From jdk1.8-source-analysis with Apache License 2.0 | 6 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 { int context = getArg0AsNode(xctxt); XObject val; if (DTM.NULL != context) { DTM dtm = xctxt.getDTM(context); String qname = dtm.getNodeNameX(context); val = (null == qname) ? XString.EMPTYSTRING : new XString(qname); } else { val = XString.EMPTYSTRING; } return val; }
Example #9
Source File: VariableStack.java From jdk8u60 with GNU General Public License v2.0 | 6 votes |
/** * Get a local variable or parameter in the current stack frame. * * * @param xctxt The XPath context, which must be passed in order to * lazy evaluate variables. * * @param index Local variable index relative to the current stack * frame bottom. * * @return The value of the variable. * * @throws TransformerException */ public XObject getLocalVariable(XPathContext xctxt, int index, boolean destructiveOK) throws TransformerException { index += _currentFrameBottom; XObject val = _stackFrames[index]; if(null == val) throw new TransformerException(XSLMessages.createXPATHMessage(XPATHErrorResources.ER_VARIABLE_ACCESSED_BEFORE_BIND, null), xctxt.getSAXLocator()); // "Variable accessed before it is bound!", xctxt.getSAXLocator()); // Lazy execution of variables. if (val.getType() == XObject.CLASS_UNRESOLVEDVARIABLE) return (_stackFrames[index] = val.execute(xctxt)); return destructiveOK ? val : val.getFresh(); }
Example #10
Source File: XPathResultImpl.java From openjdk-8-source with GNU General Public License v2.0 | 6 votes |
/** * Given an XObject, determine the corresponding DOM XPath type * * @return type string */ private short getTypeFromXObject(XObject object) { switch (object.getType()) { case XObject.CLASS_BOOLEAN: return BOOLEAN_TYPE; case XObject.CLASS_NODESET: return UNORDERED_NODE_ITERATOR_TYPE; case XObject.CLASS_NUMBER: return NUMBER_TYPE; case XObject.CLASS_STRING: return STRING_TYPE; // XPath 2.0 types // case XObject.CLASS_DATE: // case XObject.CLASS_DATETIME: // case XObject.CLASS_DTDURATION: // case XObject.CLASS_GDAY: // case XObject.CLASS_GMONTH: // case XObject.CLASS_GMONTHDAY: // case XObject.CLASS_GYEAR: // case XObject.CLASS_GYEARMONTH: // case XObject.CLASS_TIME: // case XObject.CLASS_YMDURATION: return STRING_TYPE; // treat all date types as strings? case XObject.CLASS_RTREEFRAG: return UNORDERED_NODE_ITERATOR_TYPE; case XObject.CLASS_NULL: return ANY_TYPE; // throw exception ? default: return ANY_TYPE; // throw exception ? } }
Example #11
Source File: XPathResultImpl.java From openjdk-jdk8u with GNU General Public License v2.0 | 6 votes |
/** * Given an XObject, determine the corresponding DOM XPath type * * @return type string */ private short getTypeFromXObject(XObject object) { switch (object.getType()) { case XObject.CLASS_BOOLEAN: return BOOLEAN_TYPE; case XObject.CLASS_NODESET: return UNORDERED_NODE_ITERATOR_TYPE; case XObject.CLASS_NUMBER: return NUMBER_TYPE; case XObject.CLASS_STRING: return STRING_TYPE; // XPath 2.0 types // case XObject.CLASS_DATE: // case XObject.CLASS_DATETIME: // case XObject.CLASS_DTDURATION: // case XObject.CLASS_GDAY: // case XObject.CLASS_GMONTH: // case XObject.CLASS_GMONTHDAY: // case XObject.CLASS_GYEAR: // case XObject.CLASS_GYEARMONTH: // case XObject.CLASS_TIME: // case XObject.CLASS_YMDURATION: return STRING_TYPE; // treat all date types as strings? case XObject.CLASS_RTREEFRAG: return UNORDERED_NODE_ITERATOR_TYPE; case XObject.CLASS_NULL: return ANY_TYPE; // throw exception ? default: return ANY_TYPE; // throw exception ? } }
Example #12
Source File: Arg.java From jdk1.8-source-analysis with Apache License 2.0 | 5 votes |
/** * Construct a parameter argument. * * @param qname Name of the argument, expressed as a QName object. * @param val Value of the argument, expressed as an XObject * @param isFromWithParam True if this is a parameter variable. */ public Arg(QName qname, XObject val, boolean isFromWithParam) { m_qname = qname; m_val = val; m_isFromWithParam = isFromWithParam; m_isVisible = !isFromWithParam; m_expression = null; }
Example #13
Source File: FunctionPattern.java From Bytecoder with Apache License 2.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, int context) throws javax.xml.transform.TransformerException { 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(); } nl.detach(); return score; }
Example #14
Source File: FunctionPattern.java From hottub 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, int context, DTM dtm, int expType) throws javax.xml.transform.TransformerException { 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 #15
Source File: UnionChildIterator.java From jdk8u60 with GNU General Public License v2.0 | 5 votes |
/** * Test whether a specified node is visible in the logical view of a * TreeWalker or NodeIterator. This function will be called by the * implementation of TreeWalker and NodeIterator; it is not intended to * be called directly from user code. * @param n The node to check to see if it passes the filter or not. * @return a constant to determine whether the node is accepted, * rejected, or skipped, as defined above . */ public short acceptNode(int n) { XPathContext xctxt = getXPathContext(); try { xctxt.pushCurrentNode(n); for (int i = 0; i < m_nodeTests.length; i++) { PredicatedNodeTest pnt = m_nodeTests[i]; XObject score = pnt.execute(xctxt, n); if (score != NodeTest.SCORE_NONE) { // Note that we are assuming there are no positional predicates! if (pnt.getPredicateCount() > 0) { if (pnt.executePredicates(n, xctxt)) return DTMIterator.FILTER_ACCEPT; } else return DTMIterator.FILTER_ACCEPT; } } } catch (javax.xml.transform.TransformerException se) { // TODO: Fix this. throw new RuntimeException(se.getMessage()); } finally { xctxt.popCurrentNode(); } return DTMIterator.FILTER_SKIP; }
Example #16
Source File: FuncLang.java From openjdk-jdk9 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 #17
Source File: XPathAPI.java From JDKSourceCode1.8 with MIT License | 5 votes |
/** * Use an XPath string to select a nodelist. * XPath namespace prefixes are resolved from the namespaceNode. * * @param contextNode The node to start searching from. * @param str A valid XPath string. * @param namespaceNode The node from which prefixes in the XPath will be resolved to namespaces. * @return A NodeIterator, should never be null. * * @throws TransformerException */ public static NodeIterator selectNodeIterator( Node contextNode, String str, Node namespaceNode) throws TransformerException { // Execute the XPath, and have it return the result XObject list = eval(contextNode, str, namespaceNode); // Have the XObject return its result as a NodeSetDTM. return list.nodeset(); }
Example #18
Source File: FuncNamespace.java From openjdk-8-source 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 { int context = getArg0AsNode(xctxt); String s; if(context != DTM.NULL) { DTM dtm = xctxt.getDTM(context); int t = dtm.getNodeType(context); if(t == DTM.ELEMENT_NODE) { s = dtm.getNamespaceURI(context); } else if(t == DTM.ATTRIBUTE_NODE) { // This function always returns an empty string for namespace nodes. // We check for those here. Fix inspired by Davanum Srinivas. s = dtm.getNodeName(context); if(s.startsWith("xmlns:") || s.equals("xmlns")) return XString.EMPTYSTRING; s = dtm.getNamespaceURI(context); } else return XString.EMPTYSTRING; } else return XString.EMPTYSTRING; return ((null == s) ? XString.EMPTYSTRING : new XString(s)); }
Example #19
Source File: XPathAPI.java From jdk1.8-source-analysis with Apache License 2.0 | 5 votes |
/** * Use an XPath string to select a nodelist. * XPath namespace prefixes are resolved from the namespaceNode. * * @param contextNode The node to start searching from. * @param str A valid XPath string. * @param namespaceNode The node from which prefixes in the XPath will be resolved to namespaces. * @return A NodeIterator, should never be null. * * @throws TransformerException */ public static NodeList selectNodeList( Node contextNode, String str, Node namespaceNode) throws TransformerException { // Execute the XPath, and have it return the result XObject list = eval(contextNode, str, namespaceNode); // Return a NodeList. return list.nodelist(); }
Example #20
Source File: XPathAPI.java From TencentKona-8 with GNU General Public License v2.0 | 5 votes |
/** * Use an XPath string to select a nodelist. * XPath namespace prefixes are resolved from the namespaceNode. * * @param contextNode The node to start searching from. * @param str A valid XPath string. * @param namespaceNode The node from which prefixes in the XPath will be resolved to namespaces. * @return A NodeIterator, should never be null. * * @throws TransformerException */ public static NodeIterator selectNodeIterator( Node contextNode, String str, Node namespaceNode) throws TransformerException { // Execute the XPath, and have it return the result XObject list = eval(contextNode, str, namespaceNode); // Have the XObject return its result as a NodeSetDTM. return list.nodeset(); }
Example #21
Source File: XPathResultImpl.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
/** * Read the XObject and set values in accordance with the result type * @param resultObject internal XPath result object * @throws TransformerException if there is an error reading the XPath * result. */ private void getResult(XObject resultObject) throws TransformerException { switch (resultType) { case XObject.CLASS_BOOLEAN: boolValue = resultObject.bool(); mapToType = XPathResultType.BOOLEAN; break; case XObject.CLASS_NUMBER: numValue = resultObject.num(); mapToType = XPathResultType.NUMBER; break; case XObject.CLASS_STRING: strValue = resultObject.str(); mapToType = XPathResultType.STRING; break; case XObject.CLASS_NODESET: mapToType = XPathResultType.NODESET; nodeList = resultObject.nodelist(); break; case XObject.CLASS_RTREEFRAG: //NODE mapToType = XPathResultType.NODE; NodeIterator ni = resultObject.nodeset(); //Return the first node, or null node = ni.nextNode(); break; } }
Example #22
Source File: VariableStack.java From hottub with GNU General Public License v2.0 | 5 votes |
/** * Reset the stack to a start position. * * @return the total size of the execution stack. */ public void reset() { _frameTop = 0; _linksTop = 0; // Adding one here to the stack of frame positions will allow us always // to look one under without having to check if we're at zero. // (As long as the caller doesn't screw up link/unlink.) _links[_linksTop++] = 0; _stackFrames = new XObject[_stackFrames.length]; }
Example #23
Source File: XPathImpl.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 5 votes |
private Object getResultAsType( XObject resultObject, QName returnType ) throws javax.xml.transform.TransformerException { // XPathConstants.STRING if ( returnType.equals( XPathConstants.STRING ) ) { return resultObject.str(); } // XPathConstants.NUMBER if ( returnType.equals( XPathConstants.NUMBER ) ) { return new Double ( resultObject.num()); } // XPathConstants.BOOLEAN if ( returnType.equals( XPathConstants.BOOLEAN ) ) { return new Boolean( resultObject.bool()); } // XPathConstants.NODESET ---ORdered, UNOrdered??? if ( returnType.equals( XPathConstants.NODESET ) ) { return resultObject.nodelist(); } // XPathConstants.NODE if ( returnType.equals( XPathConstants.NODE ) ) { NodeIterator ni = resultObject.nodeset(); //Return the first node, or null return ni.nextNode(); } String fmsg = XSLMessages.createXPATHMessage( XPATHErrorResources.ER_UNSUPPORTED_RETURN_TYPE, new Object[] { returnType.toString()}); throw new IllegalArgumentException( fmsg ); }
Example #24
Source File: StepPattern.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
/** * Execute the match pattern step relative to another step. * * * @param xctxt The XPath runtime context. * @param dtm The DTM of the current node. * @param currentNode The current node 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 */ protected final XObject executeRelativePathPattern( XPathContext xctxt, DTM dtm, int currentNode) throws javax.xml.transform.TransformerException { XObject score = NodeTest.SCORE_NONE; int context = currentNode; DTMAxisTraverser traverser; traverser = dtm.getAxisTraverser(m_axis); for (int relative = traverser.first(context); DTM.NULL != relative; relative = traverser.next(context, relative)) { try { xctxt.pushCurrentNode(relative); score = execute(xctxt); if (score != NodeTest.SCORE_NONE) break; } finally { xctxt.popCurrentNode(); } } return score; }
Example #25
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, int context, DTM dtm, int expType) throws javax.xml.transform.TransformerException { 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 #26
Source File: FuncLang.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 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 #27
Source File: Equals.java From hottub with GNU General Public License v2.0 | 5 votes |
/** * Execute a binary operation by calling execute on each of the operands, * and then calling the operate method on the derived class. * * * @param xctxt The runtime execution context. * * @return The XObject result of the operation. * * @throws javax.xml.transform.TransformerException */ public boolean bool(XPathContext xctxt) throws javax.xml.transform.TransformerException { XObject left = m_left.execute(xctxt, true); XObject right = m_right.execute(xctxt, true); boolean result = left.equals(right) ? true : false; left.detach(); right.detach(); return result; }
Example #28
Source File: UnionChildIterator.java From openjdk-8-source with GNU General Public License v2.0 | 5 votes |
/** * Test whether a specified node is visible in the logical view of a * TreeWalker or NodeIterator. This function will be called by the * implementation of TreeWalker and NodeIterator; it is not intended to * be called directly from user code. * @param n The node to check to see if it passes the filter or not. * @return a constant to determine whether the node is accepted, * rejected, or skipped, as defined above . */ public short acceptNode(int n) { XPathContext xctxt = getXPathContext(); try { xctxt.pushCurrentNode(n); for (int i = 0; i < m_nodeTests.length; i++) { PredicatedNodeTest pnt = m_nodeTests[i]; XObject score = pnt.execute(xctxt, n); if (score != NodeTest.SCORE_NONE) { // Note that we are assuming there are no positional predicates! if (pnt.getPredicateCount() > 0) { if (pnt.executePredicates(n, xctxt)) return DTMIterator.FILTER_ACCEPT; } else return DTMIterator.FILTER_ACCEPT; } } } catch (javax.xml.transform.TransformerException se) { // TODO: Fix this. throw new RuntimeException(se.getMessage()); } finally { xctxt.popCurrentNode(); } return DTMIterator.FILTER_SKIP; }
Example #29
Source File: XPath.java From jdk8u60 with GNU General Public License v2.0 | 5 votes |
/** * Get the match score of the given node. * * @param xctxt XPath runtime context. * @param context The current source tree context node. * * @return score, one of {@link #MATCH_SCORE_NODETEST}, * {@link #MATCH_SCORE_NONE}, {@link #MATCH_SCORE_OTHER}, * or {@link #MATCH_SCORE_QNAME}. * * @throws javax.xml.transform.TransformerException */ public double getMatchScore(XPathContext xctxt, int context) throws javax.xml.transform.TransformerException { xctxt.pushCurrentNode(context); xctxt.pushCurrentExpressionNode(context); try { XObject score = m_mainExp.execute(xctxt); if (DEBUG_MATCHES) { DTM dtm = xctxt.getDTM(context); System.out.println("score: " + score.num() + " for " + dtm.getNodeName(context) + " for xpath " + this.getPatternString()); } return score.num(); } finally { xctxt.popCurrentNode(); xctxt.popCurrentExpressionNode(); } // return XPath.MATCH_SCORE_NONE; }
Example #30
Source File: UnionPattern.java From openjdk-jdk8u with GNU General Public License v2.0 | 5 votes |
/** * Test a node to see if it matches any of the patterns in the union. * * @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 { XObject bestScore = null; int n = m_patterns.length; for (int i = 0; i < n; i++) { XObject score = m_patterns[i].execute(xctxt); if (score != NodeTest.SCORE_NONE) { if (null == bestScore) bestScore = score; else if (score.num() > bestScore.num()) bestScore = score; } } if (null == bestScore) { bestScore = NodeTest.SCORE_NONE; } return bestScore; }