当前位置: 首页>>代码示例>>Java>>正文


Java Context.getNodeSet方法代码示例

本文整理汇总了Java中org.jaxen.Context.getNodeSet方法的典型用法代码示例。如果您正苦于以下问题:Java Context.getNodeSet方法的具体用法?Java Context.getNodeSet怎么用?Java Context.getNodeSet使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.jaxen.Context的用法示例。


在下文中一共展示了Context.getNodeSet方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: evaluate

import org.jaxen.Context; //导入方法依赖的package包/类
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 );
}
 
开发者ID:jaxen-xpath,项目名称:jaxen,代码行数:27,代码来源:DefaultAbsoluteLocationPath.java

示例2: evaluate

import org.jaxen.Context; //导入方法依赖的package包/类
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);
        }
    }
    
    if (getSteps().size() > 1 || nodeSet.size() > 1) {
        Collections.sort(contextNodeSet, new NodeComparator(support.getNavigator()));
    }
    
    return contextNodeSet;
}
 
开发者ID:jaxen-xpath,项目名称:jaxen,代码行数:25,代码来源:DefaultLocationPath.java

示例3: evaluate

import org.jaxen.Context; //导入方法依赖的package包/类
public static List evaluate (Context context, Object arg)
    throws FunctionCallException
{
    List contextNodes = context.getNodeSet();
    
    if (contextNodes.size() == 0)
        return Collections.EMPTY_LIST;
  
    Navigator nav = context.getNavigator();

    String xpathString;
    if ( arg instanceof String )
        xpathString = (String)arg;
    else
        xpathString = StringFunction.evaluate(arg, nav);

    try {
        XPath xpath = nav.parseXPath(xpathString);
        ContextSupport support = context.getContextSupport();
        xpath.setVariableContext( support.getVariableContext() );
        xpath.setFunctionContext( support.getFunctionContext() );
        xpath.setNamespaceContext( support.getNamespaceContext() );
        return xpath.selectNodes( context.duplicate() );
    }
    catch ( org.jaxen.saxpath.SAXPathException e ) {
        throw new FunctionCallException(e.toString());
    }
}
 
开发者ID:jaxen-xpath,项目名称:jaxen,代码行数:29,代码来源:EvaluateFunction.java

示例4: asBoolean

import org.jaxen.Context; //导入方法依赖的package包/类
/** Returns true if the current filter matches at least one of the context nodes
 */
public boolean asBoolean(Context context) throws JaxenException 
{
    Object results = null;
    if ( expr != null ) 
    {
        results = expr.evaluate( context );
    }
    else
    {
        List nodeSet = context.getNodeSet();
        ArrayList list = new ArrayList(nodeSet.size());
        list.addAll( nodeSet );
        results = list;
    }
    
    if ( results instanceof Boolean ) 
    {
        Boolean b = (Boolean) results;
        return b.booleanValue();
    }
    if ( results instanceof List )
    {
        return getPredicateSet().evaluateAsBoolean( 
            (List) results, context.getContextSupport() 
        );
    }
    
    return false;
}
 
开发者ID:jaxen-xpath,项目名称:jaxen,代码行数:32,代码来源:DefaultFilterExpr.java

示例5: evaluate

import org.jaxen.Context; //导入方法依赖的package包/类
public List evaluate(final Context context) throws JaxenException
{
    final List contextNodeSet  = context.getNodeSet();
    final IdentitySet unique = new IdentitySet();
    final int contextSize = contextNodeSet.size();

    // ???? try linked lists instead?
    // ???? initial size for these?
    final ArrayList interimSet = new ArrayList();
    final ArrayList newNodeSet = new ArrayList();
    final ContextSupport support = context.getContextSupport();
        
    // ???? use iterator instead
    for ( int i = 0 ; i < contextSize ; ++i )
    {
        Object eachContextNode = contextNodeSet.get( i );


            /* See jaxen-106. Might be able to optimize this by doing
             * specific matching for individual axes. For instance on namespace axis
             * we should only get namespace nodes and on attribute axes we only get 
             * attribute nodes. Self and parent axes have single members.
             * Children, descendant, ancestor, and sibling axes never 
             * see any attributes or namespaces
             */
        Iterator axisNodeIter = axis.iterator(eachContextNode, support);
        while ( axisNodeIter.hasNext() )
        {
            Object eachAxisNode = axisNodeIter.next();
            if ( ! unique.contains( eachAxisNode ) )
            {
                if ( matches( eachAxisNode, support ) )
                {
                    unique.add( eachAxisNode );
                    interimSet.add( eachAxisNode );
                }
            }
        }
        newNodeSet.addAll(getPredicateSet().evaluatePredicates(
                          interimSet, support ));
        interimSet.clear();
    }
    return newNodeSet;
}
 
开发者ID:jaxen-xpath,项目名称:jaxen,代码行数:45,代码来源:DefaultStep.java

示例6: testDuplicate

import org.jaxen.Context; //导入方法依赖的package包/类
public void testDuplicate()
{
    Context original = new Context( this.support );

    original.setNodeSet( this.nodeSet );

    original.setSize( 4 );
    original.setPosition( 2 );

    Context dupe = original.duplicate();

    assertEquals(2, dupe.getPosition());
    assertEquals(4, dupe.getSize());
    
    assertTrue( original != dupe );

    List dupeNodeSet = dupe.getNodeSet();

    assertTrue( original.getNodeSet() != dupe.getNodeSet() );

    dupeNodeSet.clear();

    assertSame( dupeNodeSet,
                dupe.getNodeSet() );

    assertEquals( 0,
                  dupe.getNodeSet().size() );


    assertEquals( 4,
                  original.getNodeSet().size() );

    dupe.setSize( 0 );
    dupe.setPosition( 0 );

    assertEquals( 0,
                  dupe.getSize() );

    assertEquals( 0,
                  dupe.getPosition() );

    assertEquals( 4,
                  original.getSize() );

    assertEquals( 2,
                  original.getPosition() );
}
 
开发者ID:jaxen-xpath,项目名称:jaxen,代码行数:48,代码来源:ContextTest.java


注:本文中的org.jaxen.Context.getNodeSet方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。