Search in sources :

Example 16 with DTM

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

the class FuncLang 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 {
    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;
}
Also used : DTM(org.apache.xml.dtm.DTM)

Example 17 with DTM

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

the class FuncLocalPart 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 = 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);
}
Also used : XString(org.apache.xpath.objects.XString) XString(org.apache.xpath.objects.XString) DTM(org.apache.xml.dtm.DTM)

Example 18 with DTM

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

the class FuncNamespace 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 = 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));
}
Also used : XString(org.apache.xpath.objects.XString) XString(org.apache.xpath.objects.XString) DTM(org.apache.xml.dtm.DTM)

Example 19 with DTM

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

the class FuncNormalizeSpace method executeCharsToContentHandler.

/**
   * Execute an expression in the XPath runtime context, and return the 
   * result of the expression.
   *
   *
   * @param xctxt The XPath runtime context.
   *
   * @return The result of the expression in the form of a <code>XObject</code>.
   *
   * @throws javax.xml.transform.TransformerException if a runtime exception 
   *         occurs.
   */
public void executeCharsToContentHandler(XPathContext xctxt, ContentHandler handler) throws javax.xml.transform.TransformerException, org.xml.sax.SAXException {
    if (Arg0IsNodesetExpr()) {
        int node = getArg0AsNode(xctxt);
        if (DTM.NULL != node) {
            DTM dtm = xctxt.getDTM(node);
            dtm.dispatchCharactersEvents(node, handler, true);
        }
    } else {
        XObject obj = execute(xctxt);
        obj.dispatchCharactersEvents(handler);
    }
}
Also used : DTM(org.apache.xml.dtm.DTM) XObject(org.apache.xpath.objects.XObject)

Example 20 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)

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