Package org.jaxen

Examples of org.jaxen.Context


    private Context context;

    public XPathPattern(Pattern pattern) {
        this.pattern = pattern;
        this.text = pattern.getText();
        this.context = new Context(getContextSupport());
    }
View Full Code Here


        this.context = new Context(getContextSupport());
    }

    public XPathPattern(String text) {
        this.text = text;
        this.context = new Context(getContextSupport());

        try {
            this.pattern = PatternParser.parse(text);
        } catch (SAXPathException e) {
            throw new InvalidXPathException(text, e.getMessage());
View Full Code Here

        return this;
    }

    public Object evaluate(Context context) throws JaxenException {
        Object results = null;
        Context pathContext = null;
        if (getFilterExpr() != null) {
            results = getFilterExpr().evaluate(context);
            pathContext = new Context(context.getContextSupport());
            pathContext.setNodeSet(convertToList(results));
        }
        if (getLocationPath() != null) {
            return getLocationPath().evaluate(pathContext);
        }
        return results;
View Full Code Here

        List nodes2Filter = contextNodeSet;
        // apply all predicates
        while(predIter.hasNext()) {
            final int nodes2FilterSize = nodes2Filter.size();
            // Set up a dummy context with a list to hold each node
            Context predContext = new Context(support);
            List tempList = new ArrayList(1);
            predContext.setNodeSet(tempList);
            // loop through the current nodes to filter and add to the
            // filtered nodes list if the predicate succeeds
            for (int i = 0; i < nodes2FilterSize; ++i) {
                Object contextNode = nodes2Filter.get(i);
                tempList.clear();
                tempList.add(contextNode);
                predContext.setNodeSet(tempList);
                // ????
                predContext.setPosition(i + 1);
                predContext.setSize(nodes2FilterSize);
                Object predResult = ((Predicate)predIter.next()).evaluate(predContext);
                if (predResult instanceof Number) {
                    // Here we assume nodes are in forward or reverse order
                    // as appropriate for axis
                    int proximity = ((Number) predResult).intValue();
                    if (proximity == (i + 1)) {
                        return true;
                    }
                }
                else {
                    Boolean includes =
                        BooleanFunction.evaluate(predResult,
                                                predContext.getNavigator());
                    if (includes.booleanValue()) {
                        return true;
                    }
                }
            }
View Full Code Here

    public List applyPredicate(Predicate predicate, List nodes2Filter, ContextSupport support)
            throws JaxenException {
        final int nodes2FilterSize = nodes2Filter.size();
        List filteredNodes = new ArrayList(nodes2FilterSize);
        // Set up a dummy context with a list to hold each node
        Context predContext = new Context(support);
        List tempList = new ArrayList(1);
        predContext.setNodeSet(tempList);
        // loop through the current nodes to filter and add to the
        // filtered nodes list if the predicate succeeds
        for (int i = 0; i < nodes2FilterSize; ++i) {
            Object contextNode = nodes2Filter.get(i);
            tempList.clear();
            tempList.add(contextNode);
            predContext.setNodeSet(tempList);
            // ????
            predContext.setPosition(i + 1);
            predContext.setSize(nodes2FilterSize);
            Object predResult = predicate.evaluate(predContext);
            if (predResult instanceof Number) {
                // Here we assume nodes are in forward or reverse order
                // as appropriate for axis
                int proximity = ((Number) predResult).intValue();
                if (proximity == (i + 1)) {
                    filteredNodes.add(contextNode);
                }
            }
            else {
                Boolean includes =
                    BooleanFunction.evaluate(predResult,
                                            predContext.getNavigator());
                if (includes.booleanValue()) {
                    filteredNodes.add(contextNode);
                }
            }
        }
View Full Code Here

    public Object evaluate(Context context) throws JaxenException
    {
        ContextSupport support = context.getContextSupport();
        Navigator      nav     = support.getNavigator();
        Context absContext = new Context( support );
        List contextNodes = context.getNodeSet();

        if ( contextNodes.isEmpty() )
        {
            return Collections.EMPTY_LIST;
        }

        Object firstNode = contextNodes.get( 0 );
        Object docNode   = nav.getDocumentNode( firstNode );

        if ( docNode == null )
        {
            return Collections.EMPTY_LIST;
        }

        List list = new SingletonList(docNode);

        absContext.setNodeSet( list );

        return super.evaluate( absContext );
    }
View Full Code Here

    public Object evaluate(Context context) throws JaxenException
    {
        List nodeSet = context.getNodeSet();
        List contextNodeSet = new ArrayList(nodeSet);
        ContextSupport support = context.getContextSupport();
        Context stepContext = new Context(support);
        Iterator stepIter = getSteps().iterator();
        while ( stepIter.hasNext() )
        {
            Step eachStep = (Step) stepIter.next();
            stepContext.setNodeSet(contextNodeSet);
            contextNodeSet = eachStep.evaluate(stepContext);
            // now we need to reverse the list if this is a reverse axis
            if (isReverseAxis(eachStep)) {
                Collections.reverse(contextNodeSet);
            }
View Full Code Here

        Navigator      nav     = support.getNavigator();



        Context absContext = new Context( support );



       

        List contextNodes = context.getNodeSet();



        if ( contextNodes.isEmpty() )

        {

            return Collections.EMPTY_LIST;

        }



        Object firstNode = contextNodes.get( 0 );



        Object docNode   = nav.getDocumentNode( firstNode );



        if ( docNode == null )

        {

            return Collections.EMPTY_LIST;

        }



        List list = new SingletonList(docNode);



        absContext.setNodeSet( list );



        return super.evaluate( absContext );
View Full Code Here

        Iterator stepIter = getSteps().iterator();
        Step eachStep = null;
        while ( stepIter.hasNext() )
        {
            eachStep = (Step) stepIter.next();
            Context stepContext = new Context(context.getContextSupport());
            stepContext.setNodeSet(contextNodeSet);
            contextNodeSet = eachStep.evaluate(stepContext);
        }
        return contextNodeSet;
    }
View Full Code Here

    public List applyPredicate(Predicate predicate, List nodes2Filter, ContextSupport support)
            throws JaxenException {
        List filteredNodes = new ArrayList();
        final int nodes2FilerSize = nodes2Filter.size();
        // Set up a dummy context with a list to hold each node
        Context predContext = new Context(support);
        List tempList = new ArrayList(1);
        predContext.setNodeSet(tempList);

        // loop through the current nodes to filter and add to the
        // filtered nodes list if the predicate succeeds
        for (int i = 0; i < nodes2FilerSize; ++i) {
            Object contextNode = nodes2Filter.get(i);
            tempList.clear();
            tempList.add(contextNode);
            predContext.setNodeSet(tempList);
            predContext.setPosition(i + 1);
            predContext.setSize(nodes2FilerSize);

            Object predResult = predicate.evaluate(predContext);

            if (predResult instanceof Number) {
                int proximity = ((Number) predResult).intValue();

                if (proximity == (i + 1)) {
                    filteredNodes.add(contextNode);
                }
            }
            else {
                Boolean includes =
                    BooleanFunction.evaluate(predResult,
                                            predContext.getNavigator());

                if (includes.booleanValue()) {
                    filteredNodes.add(contextNode);
                }
            }
View Full Code Here

TOP

Related Classes of org.jaxen.Context

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.