coliver     2004/04/24 14:35:35

  Modified:    src/java/org/apache/cocoon/generation
                        JXTemplateGenerator.java
  Log:
  Allow a nodeset to be returned as the result of xpath evaluation
  
  Revision  Changes    Path
  1.42      +26 -2     
cocoon-2.1/src/java/org/apache/cocoon/generation/JXTemplateGenerator.java
  
  Index: JXTemplateGenerator.java
  ===================================================================
  RCS file: 
/home/cvs/cocoon-2.1/src/java/org/apache/cocoon/generation/JXTemplateGenerator.java,v
  retrieving revision 1.41
  retrieving revision 1.42
  diff -u -r1.41 -r1.42
  --- JXTemplateGenerator.java  24 Apr 2004 15:59:52 -0000      1.41
  +++ JXTemplateGenerator.java  24 Apr 2004 21:35:35 -0000      1.42
  @@ -1136,7 +1136,31 @@
                   boolean oldLenient = jxpathContext.isLenient();
                   if (lenient != null) 
jxpathContext.setLenient(lenient.booleanValue());
                   try {
  -                    return e.getPointer(jxpathContext, expr.raw).getNode();
  +                    Iterator iter = 
  +                        e.iteratePointers(jxpathContext);
  +                    if (!iter.hasNext()) {
  +                        return null;
  +                    }
  +                    Pointer first = (Pointer)iter.next();
  +                    if (!iter.hasNext()) {
  +                        return first.getNode();
  +                    }
  +                    List result = new LinkedList();
  +                    result.add(first.getNode());
  +                    boolean dom = (first.getNode() instanceof Node);
  +                    while (iter.hasNext()) {
  +                        Object obj = ((Pointer)iter.next()).getNode();
  +                        dom = dom && (obj instanceof Node);
  +                        result.add(obj);
  +                    }
  +                    Object[] arr;
  +                    if (dom) {
  +                        arr = new Node[result.size()];
  +                    } else {
  +                        arr = new Object[result.size()];
  +                    }
  +                    result.toArray(arr);
  +                    return arr;
                   } finally {
                       jxpathContext.setLenient(oldLenient);
                   }
  
  
  

Reply via email to