Search in sources :

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

Example 42 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 43 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 44 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 45 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)

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