Search in sources :

Example 21 with DTM

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

the class NodeTest method execute.

/**
   * Tell what the test score is for the given node.
   *
   *
   * @param xctxt XPath runtime context.
   * @param context The node being tested.
   *
   * @return {@link org.apache.xpath.patterns.NodeTest#SCORE_NODETEST},
   *         {@link org.apache.xpath.patterns.NodeTest#SCORE_NONE},
   *         {@link org.apache.xpath.patterns.NodeTest#SCORE_NSWILD},
   *         {@link org.apache.xpath.patterns.NodeTest#SCORE_QNAME}, or
   *         {@link org.apache.xpath.patterns.NodeTest#SCORE_OTHER}.
   *
   * @throws javax.xml.transform.TransformerException
   */
public XObject execute(XPathContext xctxt, int context) throws javax.xml.transform.TransformerException {
    DTM dtm = xctxt.getDTM(context);
    short nodeType = dtm.getNodeType(context);
    if (m_whatToShow == DTMFilter.SHOW_ALL)
        return m_score;
    int nodeBit = (m_whatToShow & (0x00000001 << (nodeType - 1)));
    switch(nodeBit) {
        case DTMFilter.SHOW_DOCUMENT_FRAGMENT:
        case DTMFilter.SHOW_DOCUMENT:
            return SCORE_OTHER;
        case DTMFilter.SHOW_COMMENT:
            return m_score;
        case DTMFilter.SHOW_CDATA_SECTION:
        case DTMFilter.SHOW_TEXT:
            //       ? m_score : SCORE_NONE;
            return m_score;
        case DTMFilter.SHOW_PROCESSING_INSTRUCTION:
            return subPartMatch(dtm.getNodeName(context), m_name) ? m_score : SCORE_NONE;
        // the prefix expands, regardless of the local part of the name."
        case DTMFilter.SHOW_NAMESPACE:
            {
                String ns = dtm.getLocalName(context);
                return (subPartMatch(ns, m_name)) ? m_score : SCORE_NONE;
            }
        case DTMFilter.SHOW_ATTRIBUTE:
        case DTMFilter.SHOW_ELEMENT:
            {
                return (m_isTotallyWild || (subPartMatchNS(dtm.getNamespaceURI(context), m_namespace) && subPartMatch(dtm.getLocalName(context), m_name))) ? m_score : SCORE_NONE;
            }
        default:
            return SCORE_NONE;
    }
// end switch(testType)
}
Also used : DTM(org.apache.xml.dtm.DTM)

Example 22 with DTM

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

the class StepPattern method getProximityPosition.

/**
   * Get the proximity position index of the current node based on this
   * node test.
   *
   *
   * @param xctxt XPath runtime context.
   * @param predPos Which predicate we're evaluating of foo[1][2][3].
   * @param findLast If true, don't terminate when the context node is found.
   *
   * @return the proximity position index of the current node based on the
   *         node test.
   */
private final int getProximityPosition(XPathContext xctxt, int predPos, boolean findLast) {
    int pos = 0;
    int context = xctxt.getCurrentNode();
    DTM dtm = xctxt.getDTM(context);
    int parent = dtm.getParent(context);
    try {
        DTMAxisTraverser traverser = dtm.getAxisTraverser(Axis.CHILD);
        for (int child = traverser.first(parent); DTM.NULL != child; child = traverser.next(parent, child)) {
            try {
                xctxt.pushCurrentNode(child);
                if (NodeTest.SCORE_NONE != super.execute(xctxt, child)) {
                    boolean pass = true;
                    try {
                        xctxt.pushSubContextList(this);
                        for (int i = 0; i < predPos; i++) {
                            xctxt.pushPredicatePos(i);
                            try {
                                XObject pred = m_predicates[i].execute(xctxt);
                                try {
                                    if (XObject.CLASS_NUMBER == pred.getType()) {
                                        if ((pos + 1) != (int) pred.numWithSideEffects()) {
                                            pass = false;
                                            break;
                                        }
                                    } else if (!pred.boolWithSideEffects()) {
                                        pass = false;
                                        break;
                                    }
                                } finally {
                                    pred.detach();
                                }
                            } finally {
                                xctxt.popPredicatePos();
                            }
                        }
                    } finally {
                        xctxt.popSubContextList();
                    }
                    if (pass)
                        pos++;
                    if (!findLast && child == context) {
                        return pos;
                    }
                }
            } finally {
                xctxt.popCurrentNode();
            }
        }
    } catch (javax.xml.transform.TransformerException se) {
        // TODO: should keep throw sax exception...
        throw new java.lang.RuntimeException(se.getMessage());
    }
    return pos;
}
Also used : DTMAxisTraverser(org.apache.xml.dtm.DTMAxisTraverser) DTM(org.apache.xml.dtm.DTM) XObject(org.apache.xpath.objects.XObject)

Example 23 with DTM

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

the class XString method rtf.

/**
   * Cast result object to a result tree fragment.
   *
   * @param support Xpath context to use for the conversion
   *
   * @return A document fragment with this string as a child node
   */
public int rtf(XPathContext support) {
    DTM frag = support.createDocumentFragment();
    frag.appendTextChild(str());
    return frag.getDocument();
}
Also used : DTM(org.apache.xml.dtm.DTM)

Example 24 with DTM

use of org.apache.xml.dtm.DTM in project j2objc by google.

the class ChildIterator method asNode.

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

Example 25 with DTM

use of org.apache.xml.dtm.DTM in project j2objc by google.

the class DescendantIterator method asNode.

/**
   * 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 {
    if (getPredicateCount() > 0)
        return super.asNode(xctxt);
    int current = xctxt.getCurrentNode();
    DTM dtm = xctxt.getDTM(current);
    DTMAxisTraverser traverser = dtm.getAxisTraverser(m_axis);
    String localName = getLocalName();
    String namespace = getNamespace();
    int what = m_whatToShow;
    // NodeTest.debugWhatToShow(what);
    if (DTMFilter.SHOW_ALL == what || localName == NodeTest.WILD || namespace == NodeTest.WILD) {
        return traverser.first(current);
    } else {
        int type = getNodeTypeTest(what);
        int extendedType = dtm.getExpandedTypeID(namespace, localName, type);
        return traverser.first(current, extendedType);
    }
}
Also used : DTMAxisTraverser(org.apache.xml.dtm.DTMAxisTraverser) 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