Search in sources :

Example 1 with PrefixResolver

use of org.apache.xml.utils.PrefixResolver in project robovm by robovm.

the class FilterExprIteratorSimple method executeFilterExpr.

/**
   * Execute the expression.  Meant for reuse by other FilterExpr iterators 
   * that are not derived from this object.
   */
public static XNodeSet executeFilterExpr(int context, XPathContext xctxt, PrefixResolver prefixResolver, boolean isTopLevel, int stackFrame, Expression expr) throws org.apache.xml.utils.WrappedRuntimeException {
    PrefixResolver savedResolver = xctxt.getNamespaceContext();
    XNodeSet result = null;
    try {
        xctxt.pushCurrentNode(context);
        xctxt.setNamespaceContext(prefixResolver);
        if (isTopLevel) {
            // System.out.println("calling m_expr.execute(getXPathContext())");
            VariableStack vars = xctxt.getVarStack();
            // These three statements need to be combined into one operation.
            int savedStart = vars.getStackFrame();
            vars.setStackFrame(stackFrame);
            result = (org.apache.xpath.objects.XNodeSet) expr.execute(xctxt);
            result.setShouldCacheNodes(true);
            // These two statements need to be combined into one operation.
            vars.setStackFrame(savedStart);
        } else
            result = (org.apache.xpath.objects.XNodeSet) expr.execute(xctxt);
    } catch (javax.xml.transform.TransformerException se) {
        // TODO: Fix...
        throw new org.apache.xml.utils.WrappedRuntimeException(se);
    } finally {
        xctxt.popCurrentNode();
        xctxt.setNamespaceContext(savedResolver);
    }
    return result;
}
Also used : VariableStack(org.apache.xpath.VariableStack) PrefixResolver(org.apache.xml.utils.PrefixResolver) XNodeSet(org.apache.xpath.objects.XNodeSet)

Example 2 with PrefixResolver

use of org.apache.xml.utils.PrefixResolver in project robovm by robovm.

the class PredicatedNodeTest method executePredicates.

/**
   * Process the predicates.
   *
   * @param context The current context node.
   * @param xctxt The XPath runtime context.
   *
   * @return the result of executing the predicate expressions.
   *
   * @throws javax.xml.transform.TransformerException
   */
boolean executePredicates(int context, XPathContext xctxt) throws javax.xml.transform.TransformerException {
    int nPredicates = getPredicateCount();
    // System.out.println("nPredicates: "+nPredicates);
    if (nPredicates == 0)
        return true;
    PrefixResolver savedResolver = xctxt.getNamespaceContext();
    try {
        m_predicateIndex = 0;
        xctxt.pushSubContextList(this);
        xctxt.pushNamespaceContext(m_lpi.getPrefixResolver());
        xctxt.pushCurrentNode(context);
        for (int i = 0; i < nPredicates; i++) {
            // System.out.println("Executing predicate expression - waiting count: "+m_lpi.getWaitingCount());
            XObject pred = m_predicates[i].execute(xctxt);
            // System.out.println("pred.getType(): "+pred.getType());
            if (XObject.CLASS_NUMBER == pred.getType()) {
                if (DEBUG_PREDICATECOUNTING) {
                    System.out.flush();
                    System.out.println("\n===== start predicate count ========");
                    System.out.println("m_predicateIndex: " + m_predicateIndex);
                    // System.out.println("getProximityPosition(m_predicateIndex): "
                    //                   + getProximityPosition(m_predicateIndex));
                    System.out.println("pred.num(): " + pred.num());
                }
                int proxPos = this.getProximityPosition(m_predicateIndex);
                int predIndex = (int) pred.num();
                if (proxPos != predIndex) {
                    if (DEBUG_PREDICATECOUNTING) {
                        System.out.println("\nnode context: " + nodeToString(context));
                        System.out.println("index predicate is false: " + proxPos);
                        System.out.println("\n===== end predicate count ========");
                    }
                    return false;
                } else if (DEBUG_PREDICATECOUNTING) {
                    System.out.println("\nnode context: " + nodeToString(context));
                    System.out.println("index predicate is true: " + proxPos);
                    System.out.println("\n===== end predicate count ========");
                }
                // only sets m_foundLast if on the last predicate
                if (m_predicates[i].isStableNumber() && i == nPredicates - 1) {
                    m_foundLast = true;
                }
            } else if (!pred.bool())
                return false;
            countProximityPosition(++m_predicateIndex);
        }
    } finally {
        xctxt.popCurrentNode();
        xctxt.popNamespaceContext();
        xctxt.popSubContextList();
        m_predicateIndex = -1;
    }
    return true;
}
Also used : PrefixResolver(org.apache.xml.utils.PrefixResolver) XObject(org.apache.xpath.objects.XObject)

Example 3 with PrefixResolver

use of org.apache.xml.utils.PrefixResolver in project j2objc by google.

the class PredicatedNodeTest method executePredicates.

/**
   * Process the predicates.
   *
   * @param context The current context node.
   * @param xctxt The XPath runtime context.
   *
   * @return the result of executing the predicate expressions.
   *
   * @throws javax.xml.transform.TransformerException
   */
boolean executePredicates(int context, XPathContext xctxt) throws javax.xml.transform.TransformerException {
    int nPredicates = getPredicateCount();
    // System.out.println("nPredicates: "+nPredicates);
    if (nPredicates == 0)
        return true;
    PrefixResolver savedResolver = xctxt.getNamespaceContext();
    try {
        m_predicateIndex = 0;
        xctxt.pushSubContextList(this);
        xctxt.pushNamespaceContext(m_lpi.getPrefixResolver());
        xctxt.pushCurrentNode(context);
        for (int i = 0; i < nPredicates; i++) {
            // System.out.println("Executing predicate expression - waiting count: "+m_lpi.getWaitingCount());
            XObject pred = m_predicates[i].execute(xctxt);
            // System.out.println("pred.getType(): "+pred.getType());
            if (XObject.CLASS_NUMBER == pred.getType()) {
                if (DEBUG_PREDICATECOUNTING) {
                    System.out.flush();
                    System.out.println("\n===== start predicate count ========");
                    System.out.println("m_predicateIndex: " + m_predicateIndex);
                    // System.out.println("getProximityPosition(m_predicateIndex): "
                    //                   + getProximityPosition(m_predicateIndex));
                    System.out.println("pred.num(): " + pred.num());
                }
                int proxPos = this.getProximityPosition(m_predicateIndex);
                int predIndex = (int) pred.num();
                if (proxPos != predIndex) {
                    if (DEBUG_PREDICATECOUNTING) {
                        System.out.println("\nnode context: " + nodeToString(context));
                        System.out.println("index predicate is false: " + proxPos);
                        System.out.println("\n===== end predicate count ========");
                    }
                    return false;
                } else if (DEBUG_PREDICATECOUNTING) {
                    System.out.println("\nnode context: " + nodeToString(context));
                    System.out.println("index predicate is true: " + proxPos);
                    System.out.println("\n===== end predicate count ========");
                }
                // only sets m_foundLast if on the last predicate
                if (m_predicates[i].isStableNumber() && i == nPredicates - 1) {
                    m_foundLast = true;
                }
            } else if (!pred.bool())
                return false;
            countProximityPosition(++m_predicateIndex);
        }
    } finally {
        xctxt.popCurrentNode();
        xctxt.popNamespaceContext();
        xctxt.popSubContextList();
        m_predicateIndex = -1;
    }
    return true;
}
Also used : PrefixResolver(org.apache.xml.utils.PrefixResolver) XObject(org.apache.xpath.objects.XObject)

Example 4 with PrefixResolver

use of org.apache.xml.utils.PrefixResolver in project j2objc by google.

the class FilterExprIteratorSimple method executeFilterExpr.

/**
   * Execute the expression.  Meant for reuse by other FilterExpr iterators 
   * that are not derived from this object.
   */
public static XNodeSet executeFilterExpr(int context, XPathContext xctxt, PrefixResolver prefixResolver, boolean isTopLevel, int stackFrame, Expression expr) throws org.apache.xml.utils.WrappedRuntimeException {
    PrefixResolver savedResolver = xctxt.getNamespaceContext();
    XNodeSet result = null;
    try {
        xctxt.pushCurrentNode(context);
        xctxt.setNamespaceContext(prefixResolver);
        if (isTopLevel) {
            // System.out.println("calling m_expr.execute(getXPathContext())");
            VariableStack vars = xctxt.getVarStack();
            // These three statements need to be combined into one operation.
            int savedStart = vars.getStackFrame();
            vars.setStackFrame(stackFrame);
            result = (org.apache.xpath.objects.XNodeSet) expr.execute(xctxt);
            result.setShouldCacheNodes(true);
            // These two statements need to be combined into one operation.
            vars.setStackFrame(savedStart);
        } else
            result = (org.apache.xpath.objects.XNodeSet) expr.execute(xctxt);
    } catch (javax.xml.transform.TransformerException se) {
        // TODO: Fix...
        throw new org.apache.xml.utils.WrappedRuntimeException(se);
    } finally {
        xctxt.popCurrentNode();
        xctxt.setNamespaceContext(savedResolver);
    }
    return result;
}
Also used : VariableStack(org.apache.xpath.VariableStack) PrefixResolver(org.apache.xml.utils.PrefixResolver) XNodeSet(org.apache.xpath.objects.XNodeSet)

Example 5 with PrefixResolver

use of org.apache.xml.utils.PrefixResolver in project intellij-community by JetBrains.

the class XalanStyleFrame method eval.

public Value eval(String expr) throws Debugger.EvaluationException {
    assert isValid();
    try {
        final DTMIterator context = myTransformer.getContextNodeList();
        final int ctx;
        final DTM dtm = context.getDTM(myCurrentNode);
        if (dtm.getDocumentRoot(myCurrentNode) == myCurrentNode) {
            ctx = dtm.getFirstChild(myCurrentNode);
        } else {
            ctx = myCurrentNode;
        }
        final DTMNodeProxy c = new DTMNodeProxy(dtm, ctx);
        final PrefixResolver prefixResolver = new PrefixResolverDefault(c) {

            public String getNamespaceForPrefix(String prefix, Node context) {
                if (context instanceof DTMNodeProxy) {
                    final DTMNodeProxy proxy = (DTMNodeProxy) context;
                    final DTM dtm = proxy.getDTM();
                    int p = proxy.getDTMNodeNumber();
                    while (p != DTM.NULL) {
                        int nsNode = dtm.getFirstNamespaceNode(p, true);
                        while (nsNode != DTM.NULL) {
                            final String s = dtm.getLocalName(nsNode);
                            if (s.equals(prefix)) {
                                return dtm.getNodeValue(nsNode);
                            }
                            nsNode = dtm.getNextNamespaceNode(p, nsNode, true);
                        }
                        p = dtm.getParent(p);
                    }
                }
                return super.getNamespaceForPrefix(prefix, context);
            }
        };
        final XPath xPath = new XPath(expr, myCurrentElement, prefixResolver, XPath.SELECT, myTransformer.getErrorListener());
        return new XObjectValue(xPath.execute(myContext, myCurrentNode, myCurrentElement));
    } catch (Exception e) {
        debug(e);
        final String message = e.getMessage();
        throw new Debugger.EvaluationException(message != null ? message : e.getClass().getSimpleName());
    }
}
Also used : XPath(org.apache.xpath.XPath) Debugger(org.intellij.plugins.xsltDebugger.rt.engine.Debugger) Node(org.w3c.dom.Node) PrefixResolver(org.apache.xml.utils.PrefixResolver) TransformerException(javax.xml.transform.TransformerException) DTMIterator(org.apache.xml.dtm.DTMIterator) DTM(org.apache.xml.dtm.DTM) DTMNodeProxy(org.apache.xml.dtm.ref.DTMNodeProxy) PrefixResolverDefault(org.apache.xml.utils.PrefixResolverDefault)

Aggregations

PrefixResolver (org.apache.xml.utils.PrefixResolver)5 VariableStack (org.apache.xpath.VariableStack)2 XNodeSet (org.apache.xpath.objects.XNodeSet)2 XObject (org.apache.xpath.objects.XObject)2 TransformerException (javax.xml.transform.TransformerException)1 DTM (org.apache.xml.dtm.DTM)1 DTMIterator (org.apache.xml.dtm.DTMIterator)1 DTMNodeProxy (org.apache.xml.dtm.ref.DTMNodeProxy)1 PrefixResolverDefault (org.apache.xml.utils.PrefixResolverDefault)1 XPath (org.apache.xpath.XPath)1 Debugger (org.intellij.plugins.xsltDebugger.rt.engine.Debugger)1 Node (org.w3c.dom.Node)1