Search in sources :

Example 46 with DTM

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

the class FuncSum 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 {
    DTMIterator nodes = m_arg0.asIterator(xctxt, xctxt.getCurrentNode());
    double sum = 0.0;
    int pos;
    while (DTM.NULL != (pos = nodes.nextNode())) {
        DTM dtm = nodes.getDTM(pos);
        XMLString s = dtm.getStringValue(pos);
        if (null != s)
            sum += s.toDouble();
    }
    nodes.detach();
    return new XNumber(sum);
}
Also used : XNumber(org.apache.xpath.objects.XNumber) DTM(org.apache.xml.dtm.DTM) XMLString(org.apache.xml.utils.XMLString) DTMIterator(org.apache.xml.dtm.DTMIterator)

Example 47 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 48 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 49 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 50 with DTM

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

the class FuncSum 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 {
    DTMIterator nodes = m_arg0.asIterator(xctxt, xctxt.getCurrentNode());
    double sum = 0.0;
    int pos;
    while (DTM.NULL != (pos = nodes.nextNode())) {
        DTM dtm = nodes.getDTM(pos);
        XMLString s = dtm.getStringValue(pos);
        if (null != s)
            sum += s.toDouble();
    }
    nodes.detach();
    return new XNumber(sum);
}
Also used : XNumber(org.apache.xpath.objects.XNumber) DTM(org.apache.xml.dtm.DTM) XMLString(org.apache.xml.utils.XMLString) DTMIterator(org.apache.xml.dtm.DTMIterator)

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