/** * 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! * * @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); }
/** * 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; }
/** * 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); if (DTM.NULL == context) return XString.EMPTYSTRING; DTM dtm = xctxt.getDTM(context); String s = (context != DTM.NULL) ? dtm.getLocalName(context) : ""; if (s.startsWith("#") || s.equals("xmlns")) return XString.EMPTYSTRING; return new XString(s); }
/** * 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(); }
/** * 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(); }
/** * Try to create a DOM source tree from the input source. * * @param source The Source object that identifies the source node. * @param locator The location of the caller, for diagnostic purposes. * @return non-null reference to node identified by the source argument. * @throws TransformerException if the source argument can not be resolved to a source node. */ public int parseToNode(Source source, SourceLocator locator, XPathContext xctxt) throws TransformerException { try { Object xowner = xctxt.getOwnerObject(); DTM dtm; if (null != xowner && xowner instanceof com.sun.org.apache.xml.internal.dtm.DTMWSFilter) { dtm = xctxt.getDTM( source, false, (com.sun.org.apache.xml.internal.dtm.DTMWSFilter) xowner, false, true); } else { dtm = xctxt.getDTM(source, false, null, false, true); } return dtm.getDocument(); } catch (Exception e) { // e.printStackTrace(); throw new TransformerException(e.getMessage(), locator, e); } }
/** * Set the root node of the TreeWalker. (Not part of the DOM2 TreeWalker interface). * * @param root The context node of this step. */ public void setRoot(int root) { // %OPT% Get this directly from the lpi. XPathContext xctxt = wi().getXPathContext(); m_dtm = xctxt.getDTM(root); m_traverser = m_dtm.getAxisTraverser(m_axis); m_isFresh = true; m_foundLast = false; m_root = root; m_currentNode = root; if (DTM.NULL == root) { throw new RuntimeException( XSLMessages.createXPATHMessage( XPATHErrorResources.ER_SETTING_WALKER_ROOT_TO_NULL, null)); // "\n !!!! Error! Setting the root of a walker to null!!!"); } resetProximityPositions(); }
/** * 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 whereNode = getArg0AsNode(xctxt); String fileLocation = null; if (DTM.NULL != whereNode) { DTM dtm = xctxt.getDTM(whereNode); // %REVIEW% if (DTM.DOCUMENT_FRAGMENT_NODE == dtm.getNodeType(whereNode)) { whereNode = dtm.getFirstChild(whereNode); } if (DTM.NULL != whereNode) { fileLocation = dtm.getDocumentBaseURI(); // int owner = dtm.getDocument(); // fileLocation = xctxt.getSourceTreeManager().findURIFromDoc(owner); } } return new XString((null != fileLocation) ? fileLocation : ""); }