Search in sources :

Example 16 with XNodeSet

use of org.apache.xpath.objects.XNodeSet in project robovm by robovm.

the class Variable method execute.

/**
   * Dereference the variable, and return the reference value.  Note that lazy 
   * evaluation will occur.  If a variable within scope is not found, a warning 
   * will be sent to the error listener, and an empty nodeset will be returned.
   *
   *
   * @param xctxt The runtime execution context.
   *
   * @return The evaluated variable, or an empty nodeset if not found.
   *
   * @throws javax.xml.transform.TransformerException
   */
public XObject execute(XPathContext xctxt, boolean destructiveOK) throws javax.xml.transform.TransformerException {
    org.apache.xml.utils.PrefixResolver xprefixResolver = xctxt.getNamespaceContext();
    XObject result;
    // XObject result = xctxt.getVariable(m_qname);
    if (m_fixUpWasCalled) {
        if (m_isGlobal)
            result = xctxt.getVarStack().getGlobalVariable(xctxt, m_index, destructiveOK);
        else
            result = xctxt.getVarStack().getLocalVariable(xctxt, m_index, destructiveOK);
    } else {
        result = xctxt.getVarStack().getVariableOrParam(xctxt, m_qname);
    }
    if (null == result) {
        // This should now never happen...
        warn(xctxt, XPATHErrorResources.WG_ILLEGAL_VARIABLE_REFERENCE, //"VariableReference given for variable out "+
        new Object[] { m_qname.getLocalPart() });
        //      (new RuntimeException()).printStackTrace();
        //      error(xctxt, XPATHErrorResources.ER_COULDNOT_GET_VAR_NAMED,
        //            new Object[]{ m_qname.getLocalPart() });  //"Could not get variable named "+varName);
        result = new XNodeSet(xctxt.getDTMManager());
    }
    return result;
//    }
//    else
//    {
//      // Hack city... big time.  This is needed to evaluate xpaths from extensions, 
//      // pending some bright light going off in my head.  Some sort of callback?
//      synchronized(this)
//      {
//      	org.apache.xalan.templates.ElemVariable vvar= getElemVariable();
//      	if(null != vvar)
//      	{
//          m_index = vvar.getIndex();
//          m_isGlobal = vvar.getIsTopLevel();
//          m_fixUpWasCalled = true;
//          return execute(xctxt);
//      	}
//      }
//      throw new javax.xml.transform.TransformerException(XSLMessages.createXPATHMessage(XPATHErrorResources.ER_VAR_NOT_RESOLVABLE, new Object[]{m_qname.toString()})); //"Variable not resolvable: "+m_qname);
//    }
}
Also used : XObject(org.apache.xpath.objects.XObject) XNodeSet(org.apache.xpath.objects.XNodeSet)

Example 17 with XNodeSet

use of org.apache.xpath.objects.XNodeSet in project j2objc by google.

the class FuncCurrent 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 {
    SubContextList subContextList = xctxt.getCurrentNodeList();
    int currentNode = DTM.NULL;
    if (null != subContextList) {
        if (subContextList instanceof PredicatedNodeTest) {
            LocPathIterator iter = ((PredicatedNodeTest) subContextList).getLocPathIterator();
            currentNode = iter.getCurrentContextNode();
        } else if (subContextList instanceof StepPattern) {
            throw new RuntimeException(XSLMessages.createMessage(XSLTErrorResources.ER_PROCESSOR_ERROR, null));
        }
    } else {
        // not predicate => ContextNode == CurrentNode
        currentNode = xctxt.getContextNode();
    }
    return new XNodeSet(currentNode, xctxt.getDTMManager());
}
Also used : PredicatedNodeTest(org.apache.xpath.axes.PredicatedNodeTest) StepPattern(org.apache.xpath.patterns.StepPattern) LocPathIterator(org.apache.xpath.axes.LocPathIterator) SubContextList(org.apache.xpath.axes.SubContextList) XNodeSet(org.apache.xpath.objects.XNodeSet)

Example 18 with XNodeSet

use of org.apache.xpath.objects.XNodeSet in project j2objc by google.

the class Variable method execute.

/**
   * Dereference the variable, and return the reference value.  Note that lazy 
   * evaluation will occur.  If a variable within scope is not found, a warning 
   * will be sent to the error listener, and an empty nodeset will be returned.
   *
   *
   * @param xctxt The runtime execution context.
   *
   * @return The evaluated variable, or an empty nodeset if not found.
   *
   * @throws javax.xml.transform.TransformerException
   */
public XObject execute(XPathContext xctxt, boolean destructiveOK) throws javax.xml.transform.TransformerException {
    org.apache.xml.utils.PrefixResolver xprefixResolver = xctxt.getNamespaceContext();
    XObject result;
    // XObject result = xctxt.getVariable(m_qname);
    if (m_fixUpWasCalled) {
        if (m_isGlobal)
            result = xctxt.getVarStack().getGlobalVariable(xctxt, m_index, destructiveOK);
        else
            result = xctxt.getVarStack().getLocalVariable(xctxt, m_index, destructiveOK);
    } else {
        result = xctxt.getVarStack().getVariableOrParam(xctxt, m_qname);
    }
    if (null == result) {
        // This should now never happen...
        warn(xctxt, XPATHErrorResources.WG_ILLEGAL_VARIABLE_REFERENCE, //"VariableReference given for variable out "+
        new Object[] { m_qname.getLocalPart() });
        //      (new RuntimeException()).printStackTrace();
        //      error(xctxt, XPATHErrorResources.ER_COULDNOT_GET_VAR_NAMED,
        //            new Object[]{ m_qname.getLocalPart() });  //"Could not get variable named "+varName);
        result = new XNodeSet(xctxt.getDTMManager());
    }
    return result;
//    }
//    else
//    {
//      // Hack city... big time.  This is needed to evaluate xpaths from extensions, 
//      // pending some bright light going off in my head.  Some sort of callback?
//      synchronized(this)
//      {
//      	org.apache.xalan.templates.ElemVariable vvar= getElemVariable();
//      	if(null != vvar)
//      	{
//          m_index = vvar.getIndex();
//          m_isGlobal = vvar.getIsTopLevel();
//          m_fixUpWasCalled = true;
//          return execute(xctxt);
//      	}
//      }
//      throw new javax.xml.transform.TransformerException(XSLMessages.createXPATHMessage(XPATHErrorResources.ER_VAR_NOT_RESOLVABLE, new Object[]{m_qname.toString()})); //"Variable not resolvable: "+m_qname);
//    }
}
Also used : XObject(org.apache.xpath.objects.XObject) XNodeSet(org.apache.xpath.objects.XNodeSet)

Example 19 with XNodeSet

use of org.apache.xpath.objects.XNodeSet in project j2objc by google.

the class FuncId 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 = xctxt.getCurrentNode();
    DTM dtm = xctxt.getDTM(context);
    int docContext = dtm.getDocument();
    if (DTM.NULL == docContext)
        error(xctxt, XPATHErrorResources.ER_CONTEXT_HAS_NO_OWNERDOC, null);
    XObject arg = m_arg0.execute(xctxt);
    int argType = arg.getType();
    XNodeSet nodes = new XNodeSet(xctxt.getDTMManager());
    NodeSetDTM nodeSet = nodes.mutableNodeset();
    if (XObject.CLASS_NODESET == argType) {
        DTMIterator ni = arg.iter();
        StringVector usedrefs = null;
        int pos = ni.nextNode();
        while (DTM.NULL != pos) {
            DTM ndtm = ni.getDTM(pos);
            String refval = ndtm.getStringValue(pos).toString();
            pos = ni.nextNode();
            usedrefs = getNodesByID(xctxt, docContext, refval, usedrefs, nodeSet, DTM.NULL != pos);
        }
    // ni.detach();
    } else if (XObject.CLASS_NULL == argType) {
        return nodes;
    } else {
        String refval = arg.str();
        getNodesByID(xctxt, docContext, refval, null, nodeSet, false);
    }
    return nodes;
}
Also used : NodeSetDTM(org.apache.xpath.NodeSetDTM) StringVector(org.apache.xml.utils.StringVector) NodeSetDTM(org.apache.xpath.NodeSetDTM) DTM(org.apache.xml.dtm.DTM) XObject(org.apache.xpath.objects.XObject) XNodeSet(org.apache.xpath.objects.XNodeSet) DTMIterator(org.apache.xml.dtm.DTMIterator)

Example 20 with XNodeSet

use of org.apache.xpath.objects.XNodeSet in project j2objc by google.

the class LocPathIterator method execute.

/**
   * Execute this iterator, meaning create a clone that can
   * store state, and initialize it for fast execution from
   * the current runtime state.  When this is called, no actual
   * query from the current context node is performed.
   *
   * @param xctxt The XPath execution context.
   *
   * @return An XNodeSet reference that holds this iterator.
   *
   * @throws javax.xml.transform.TransformerException
   */
public XObject execute(XPathContext xctxt) throws javax.xml.transform.TransformerException {
    XNodeSet iter = new XNodeSet((LocPathIterator) m_clones.getInstance());
    iter.setRoot(xctxt.getCurrentNode(), xctxt);
    return iter;
}
Also used : XNodeSet(org.apache.xpath.objects.XNodeSet)

Aggregations

XNodeSet (org.apache.xpath.objects.XNodeSet)32 XObject (org.apache.xpath.objects.XObject)16 DTM (org.apache.xml.dtm.DTM)8 DTMIterator (org.apache.xml.dtm.DTMIterator)8 TransformerException (javax.xml.transform.TransformerException)6 XMLString (org.apache.xml.utils.XMLString)6 ArrayList (java.util.ArrayList)4 Hashtable (java.util.Hashtable)4 Vector (java.util.Vector)4 QName (javax.xml.namespace.QName)4 XPathFunction (javax.xml.xpath.XPathFunction)4 XPathFunctionException (javax.xml.xpath.XPathFunctionException)4 Expression (org.apache.xpath.Expression)4 NodeSetDTM (org.apache.xpath.NodeSetDTM)4 XPathContext (org.apache.xpath.XPathContext)4 ElemTemplateElement (org.apache.xalan.templates.ElemTemplateElement)2 KeyDeclaration (org.apache.xalan.templates.KeyDeclaration)2 KeyManager (org.apache.xalan.transformer.KeyManager)2 TransformerImpl (org.apache.xalan.transformer.TransformerImpl)2 DTMManager (org.apache.xml.dtm.DTMManager)2