Search in sources :

Example 36 with XPathContext

use of org.apache.xpath.XPathContext in project robovm by robovm.

the class TreeWalker2Result method startNode.

/**
   * Start traversal of the tree at the given node
   *
   *
   * @param node Starting node for traversal
   *
   * @throws TransformerException
   */
protected void startNode(int node) throws org.xml.sax.SAXException {
    XPathContext xcntxt = m_transformer.getXPathContext();
    try {
        if (DTM.ELEMENT_NODE == m_dtm.getNodeType(node)) {
            xcntxt.pushCurrentNode(node);
            if (m_startNode != node) {
                super.startNode(node);
            } else {
                String elemName = m_dtm.getNodeName(node);
                String localName = m_dtm.getLocalName(node);
                String namespace = m_dtm.getNamespaceURI(node);
                //xcntxt.pushCurrentNode(node);       
                // SAX-like call to allow adding attributes afterwards
                m_handler.startElement(namespace, localName, elemName);
                boolean hasNSDecls = false;
                DTM dtm = m_dtm;
                for (int ns = dtm.getFirstNamespaceNode(node, true); DTM.NULL != ns; ns = dtm.getNextNamespaceNode(node, ns, true)) {
                    SerializerUtils.ensureNamespaceDeclDeclared(m_handler, dtm, ns);
                }
                for (int attr = dtm.getFirstAttribute(node); DTM.NULL != attr; attr = dtm.getNextAttribute(attr)) {
                    SerializerUtils.addAttribute(m_handler, attr);
                }
            }
        } else {
            xcntxt.pushCurrentNode(node);
            super.startNode(node);
            xcntxt.popCurrentNode();
        }
    } catch (javax.xml.transform.TransformerException te) {
        throw new org.xml.sax.SAXException(te);
    }
}
Also used : XPathContext(org.apache.xpath.XPathContext) DTM(org.apache.xml.dtm.DTM)

Example 37 with XPathContext

use of org.apache.xpath.XPathContext in project robovm by robovm.

the class KeyTable method getNodeSetDTMByKey.

/**
   * Given a valid element key, return the corresponding node list.
   * 
   * @param name The name of the key, which must match the 'name' attribute on xsl:key.
   * @param ref The value that must match the value found by the 'match' attribute on xsl:key.
   * @return a set of nodes referenced by the key named <CODE>name</CODE> and the reference <CODE>ref</CODE>. If no node is referenced by this key, an empty node set is returned.
   */
public XNodeSet getNodeSetDTMByKey(QName name, XMLString ref) {
    XNodeSet refNodes = (XNodeSet) getRefsTable().get(ref);
    // clone wiht reset the node set
    try {
        if (refNodes != null) {
            refNodes = (XNodeSet) refNodes.cloneWithReset();
        }
    } catch (CloneNotSupportedException e) {
        refNodes = null;
    }
    if (refNodes == null) {
        //  create an empty XNodeSet
        KeyIterator ki = (KeyIterator) (m_keyNodes).getContainedIter();
        XPathContext xctxt = ki.getXPathContext();
        refNodes = new XNodeSet(xctxt.getDTMManager()) {

            public void setRoot(int nodeHandle, Object environment) {
            // Root cannot be set on non-iterated node sets. Ignore it.
            }
        };
        refNodes.reset();
    }
    return refNodes;
}
Also used : XPathContext(org.apache.xpath.XPathContext) XObject(org.apache.xpath.objects.XObject) XNodeSet(org.apache.xpath.objects.XNodeSet)

Example 38 with XPathContext

use of org.apache.xpath.XPathContext in project robovm by robovm.

the class AxesWalker method setRoot.

/**
   * Set the root node of the TreeWalker.
   * (Not part of the DOM2 TreeWalker interface).
   *
   * @param root The context node of this step.
   */
public void setRoot(int root) {
    // %OPT% Get this directly from the lpi.
    XPathContext xctxt = wi().getXPathContext();
    m_dtm = xctxt.getDTM(root);
    m_traverser = m_dtm.getAxisTraverser(m_axis);
    m_isFresh = true;
    m_foundLast = false;
    m_root = root;
    m_currentNode = root;
    if (DTM.NULL == root) {
        throw new RuntimeException(//"\n !!!! Error! Setting the root of a walker to null!!!");
        XSLMessages.createXPATHMessage(XPATHErrorResources.ER_SETTING_WALKER_ROOT_TO_NULL, null));
    }
    resetProximityPositions();
}
Also used : XPathContext(org.apache.xpath.XPathContext)

Example 39 with XPathContext

use of org.apache.xpath.XPathContext in project robovm by robovm.

the class NodeSequence method setRoot.

/**
   * @see DTMIterator#setRoot(int, Object)
   */
public void setRoot(int nodeHandle, Object environment) {
    if (null != m_iter) {
        XPathContext xctxt = (XPathContext) environment;
        m_dtmMgr = xctxt.getDTMManager();
        m_iter.setRoot(nodeHandle, environment);
        if (!m_iter.isDocOrdered()) {
            if (!hasCache())
                setShouldCacheNodes(true);
            runTo(-1);
            m_next = 0;
        }
    } else
        assertion(false, "Can not setRoot on a non-iterated NodeSequence!");
}
Also used : XPathContext(org.apache.xpath.XPathContext)

Example 40 with XPathContext

use of org.apache.xpath.XPathContext in project robovm by robovm.

the class OneStepIterator method getProximityPosition.

/**
   * Get the current sub-context position.  In order to do the
   * reverse axes count, for the moment this re-searches the axes
   * up to the predicate.  An optimization on this is to cache
   * the nodes searched, but, for the moment, this case is probably
   * rare enough that the added complexity isn't worth it.
   *
   * @param predicateIndex The predicate index of the proximity position.
   *
   * @return The pridicate index, or -1.
   */
protected int getProximityPosition(int predicateIndex) {
    if (!isReverseAxes())
        return super.getProximityPosition(predicateIndex);
    // -sb
    if (predicateIndex < 0)
        return -1;
    if (m_proximityPositions[predicateIndex] <= 0) {
        XPathContext xctxt = getXPathContext();
        try {
            OneStepIterator clone = (OneStepIterator) this.clone();
            int root = getRoot();
            xctxt.pushCurrentNode(root);
            clone.setRoot(root, xctxt);
            // clone.setPredicateCount(predicateIndex);
            clone.m_predCount = predicateIndex;
            // Count 'em all
            int count = 1;
            int next;
            while (DTM.NULL != (next = clone.nextNode())) {
                count++;
            }
            m_proximityPositions[predicateIndex] += count;
        } catch (CloneNotSupportedException cnse) {
        // can't happen
        } finally {
            xctxt.popCurrentNode();
        }
    }
    return m_proximityPositions[predicateIndex];
}
Also used : XPathContext(org.apache.xpath.XPathContext)

Aggregations

XPathContext (org.apache.xpath.XPathContext)73 TransformerException (javax.xml.transform.TransformerException)30 XObject (org.apache.xpath.objects.XObject)29 DTM (org.apache.xml.dtm.DTM)16 SAXException (org.xml.sax.SAXException)16 SerializationHandler (org.apache.xml.serializer.SerializationHandler)14 DTMIterator (org.apache.xml.dtm.DTMIterator)12 Vector (java.util.Vector)10 VariableStack (org.apache.xpath.VariableStack)8 NodeVector (org.apache.xml.utils.NodeVector)6 QName (org.apache.xml.utils.QName)6 ElemTemplateElement (org.apache.xalan.templates.ElemTemplateElement)4 StylesheetRoot (org.apache.xalan.templates.StylesheetRoot)4 IntStack (org.apache.xml.utils.IntStack)4 Expression (org.apache.xpath.Expression)4 XNodeSet (org.apache.xpath.objects.XNodeSet)4 XRTreeFrag (org.apache.xpath.objects.XRTreeFrag)4 Node (org.w3c.dom.Node)3 IOException (java.io.IOException)2 Hashtable (java.util.Hashtable)2