Search in sources :

Example 11 with DTM

use of org.apache.xml.dtm.DTM in project robovm by robovm.

the class XPath method getMatchScore.

/**
   * 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;
}
Also used : DTM(org.apache.xml.dtm.DTM) XObject(org.apache.xpath.objects.XObject)

Example 12 with DTM

use of org.apache.xml.dtm.DTM in project robovm by robovm.

the class FunctionDef1Arg method getArg0AsNumber.

/**
   * 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();
}
Also used : DTM(org.apache.xml.dtm.DTM) XMLString(org.apache.xml.utils.XMLString)

Example 13 with DTM

use of org.apache.xml.dtm.DTM in project robovm by robovm.

the class FuncDoclocation method execute.

/**
   * 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 : "");
}
Also used : XString(org.apache.xpath.objects.XString) XString(org.apache.xpath.objects.XString) DTM(org.apache.xml.dtm.DTM)

Example 14 with DTM

use of org.apache.xml.dtm.DTM in project robovm by robovm.

the class FuncId method execute.

/**
   * 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 = xctxt.getCurrentNode();
    DTM dtm = xctxt.getDTM(context);
    int docContext = dtm.getDocument();
    if (DTM.NULL == docContext)
        error(xctxt, XPATHErrorResources.ER_CONTEXT_HAS_NO_OWNERDOC, null);
    XObject arg = m_arg0.execute(xctxt);
    int argType = arg.getType();
    XNodeSet nodes = new XNodeSet(xctxt.getDTMManager());
    NodeSetDTM nodeSet = nodes.mutableNodeset();
    if (XObject.CLASS_NODESET == argType) {
        DTMIterator ni = arg.iter();
        StringVector usedrefs = null;
        int pos = ni.nextNode();
        while (DTM.NULL != pos) {
            DTM ndtm = ni.getDTM(pos);
            String refval = ndtm.getStringValue(pos).toString();
            pos = ni.nextNode();
            usedrefs = getNodesByID(xctxt, docContext, refval, usedrefs, nodeSet, DTM.NULL != pos);
        }
    // ni.detach();
    } else if (XObject.CLASS_NULL == argType) {
        return nodes;
    } else {
        String refval = arg.str();
        getNodesByID(xctxt, docContext, refval, null, nodeSet, false);
    }
    return nodes;
}
Also used : NodeSetDTM(org.apache.xpath.NodeSetDTM) StringVector(org.apache.xml.utils.StringVector) NodeSetDTM(org.apache.xpath.NodeSetDTM) DTM(org.apache.xml.dtm.DTM) XObject(org.apache.xpath.objects.XObject) XNodeSet(org.apache.xpath.objects.XNodeSet) DTMIterator(org.apache.xml.dtm.DTMIterator)

Example 15 with DTM

use of org.apache.xml.dtm.DTM in project robovm by robovm.

the class FuncId method getNodesByID.

/**
   * Fill in a list with nodes that match a space delimited list if ID 
   * ID references.
   *
   * @param xctxt The runtime XPath context.
   * @param docContext The document where the nodes are being looked for.
   * @param refval A space delimited list of ID references.
   * @param usedrefs List of references for which nodes were found.
   * @param nodeSet Node set where the nodes will be added to.
   * @param mayBeMore true if there is another set of nodes to be looked for.
   *
   * @return The usedrefs value.
   */
private StringVector getNodesByID(XPathContext xctxt, int docContext, String refval, StringVector usedrefs, NodeSetDTM nodeSet, boolean mayBeMore) {
    if (null != refval) {
        String ref = null;
        //      DOMHelper dh = xctxt.getDOMHelper();
        StringTokenizer tokenizer = new StringTokenizer(refval);
        boolean hasMore = tokenizer.hasMoreTokens();
        DTM dtm = xctxt.getDTM(docContext);
        while (hasMore) {
            ref = tokenizer.nextToken();
            hasMore = tokenizer.hasMoreTokens();
            if ((null != usedrefs) && usedrefs.contains(ref)) {
                ref = null;
                continue;
            }
            int node = dtm.getElementById(ref);
            if (DTM.NULL != node)
                nodeSet.addNodeInDocOrder(node, xctxt);
            if ((null != ref) && (hasMore || mayBeMore)) {
                if (null == usedrefs)
                    usedrefs = new StringVector();
                usedrefs.addElement(ref);
            }
        }
    }
    return usedrefs;
}
Also used : StringTokenizer(java.util.StringTokenizer) StringVector(org.apache.xml.utils.StringVector) NodeSetDTM(org.apache.xpath.NodeSetDTM) DTM(org.apache.xml.dtm.DTM)

Aggregations

DTM (org.apache.xml.dtm.DTM)100 XObject (org.apache.xpath.objects.XObject)24 DTMIterator (org.apache.xml.dtm.DTMIterator)23 NodeSetDTM (org.apache.xpath.NodeSetDTM)20 TransformerException (javax.xml.transform.TransformerException)17 XPathContext (org.apache.xpath.XPathContext)16 XMLString (org.apache.xml.utils.XMLString)12 XString (org.apache.xpath.objects.XString)10 SAXException (org.xml.sax.SAXException)10 XNodeSet (org.apache.xpath.objects.XNodeSet)8 XPath (org.apache.xpath.XPath)7 IOException (java.io.IOException)6 Vector (java.util.Vector)6 TransformerImpl (org.apache.xalan.transformer.TransformerImpl)6 DTMAxisTraverser (org.apache.xml.dtm.DTMAxisTraverser)6 SerializationHandler (org.apache.xml.serializer.SerializationHandler)6 QName (org.apache.xml.utils.QName)6 DOMSource (javax.xml.transform.dom.DOMSource)5 Hashtable (java.util.Hashtable)4 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)4