Esempio n. 1
0
 /**
  * Execute the compiled Query, returning the first item in the result. This is useful where it is
  * known that the expression will only return a singleton value (for example, a single node, or a
  * boolean).
  *
  * @param env Provides the dynamic query evaluation context
  * @return The first item in the sequence returned by the expression. If the expression returns an
  *     empty sequence, this method returns null. Otherwise, it returns the first item in the
  *     result sequence, represented as a Java object using the same mapping as for the {@link
  *     XQueryExpression#evaluate evaluate} method
  */
 public Object evaluateSingle(DynamicQueryContext env) throws XPathException {
   if (isUpdating) {
     throw new XPathException("Cannot call evaluateSingle() on an updating query");
   }
   SequenceIterator iterator = iterator(env);
   Item item = iterator.next();
   if (item == null) {
     return null;
   }
   return Value.convertToJava(item);
 }
Esempio n. 2
0
 /**
  * Execute a the compiled Query, returning the results as a List.
  *
  * @param env Provides the dynamic query evaluation context
  * @return The results of the expression, as a List. The List represents the sequence of items
  *     returned by the expression. Each item in the list will either be an object representing a
  *     node, or an object representing an atomic value. For the types of Java object that may be
  *     returned, see the description of the {@link org.orbeon.saxon.xpath.XPathEvaluator#evaluate
  *     evaluate} method of class XPathProcessor
  */
 public List evaluate(DynamicQueryContext env) throws XPathException {
   if (isUpdating) {
     throw new XPathException("Cannot call evaluate() on an updating query");
   }
   SequenceIterator iterator = iterator(env);
   ArrayList list = new ArrayList(100);
   while (true) {
     Item item = iterator.next();
     if (item == null) {
       return list;
     }
     list.add(Value.convertToJava(item));
   }
 }
Esempio n. 3
0
 public Item next() throws XPathException {
   try {
     return base.next();
   } catch (XPathException e1) {
     e1.maybeSetLocation(expression);
     try {
       listener.fatalError(e1);
     } catch (TransformerException e2) {
       //
     }
     e1.setHasBeenReported();
     throw e1;
   }
 }
Esempio n. 4
0
  /** Evaluate as an expression. */
  public Item evaluateItem(XPathContext context) throws XPathException {
    if (isLazyConstruction()
        && (context.getConfiguration().areAllNodesUntyped()
            || (validation == Validation.PRESERVE && getSchemaType() == null))) {
      return new UnconstructedDocument(this, context);
    } else {
      Controller controller = context.getController();
      DocumentInfo root;
      if (textOnly) {
        CharSequence textValue;
        if (constantText != null) {
          textValue = constantText;
        } else {
          FastStringBuffer sb = new FastStringBuffer(100);
          SequenceIterator iter = content.iterate(context);
          while (true) {
            Item item = iter.next();
            if (item == null) break;
            sb.append(item.getStringValueCS());
          }
          textValue = sb.condense();
        }
        root = new TextFragmentValue(textValue, getBaseURI());
        ((TextFragmentValue) root).setConfiguration(controller.getConfiguration());
      } else {
        try {
          XPathContext c2 = context.newMinorContext();
          c2.setOrigin(this);

          Builder builder = controller.makeBuilder();
          // builder.setSizeParameters(treeSizeParameters);
          builder.setLineNumbering(controller.getConfiguration().isLineNumbering());

          // receiver.setSystemId(getBaseURI());
          builder.setBaseURI(getBaseURI());
          builder.setTiming(false);

          PipelineConfiguration pipe = controller.makePipelineConfiguration();
          pipe.setHostLanguage(getHostLanguage());
          // pipe.setBaseURI(baseURI);
          builder.setPipelineConfiguration(pipe);

          c2.changeOutputDestination(
              null, builder, false, getHostLanguage(), validation, getSchemaType());
          Receiver out = c2.getReceiver();
          out.open();
          out.startDocument(0);

          content.process(c2);

          out.endDocument();
          out.close();

          root = (DocumentInfo) builder.getCurrentRoot();
        } catch (XPathException e) {
          e.maybeSetLocation(this);
          e.maybeSetContext(context);
          throw e;
        }
      }
      return root;
    }
  }
Esempio n. 5
0
 public SequenceIterator getAnother() throws XPathException {
   return new ErrorReportingIterator(base.getAnother(), listener);
 }
Esempio n. 6
0
 public void close() {
   base.close();
 }
Esempio n. 7
0
 public int position() {
   return base.position();
 }
Esempio n. 8
0
 public Item current() {
   return base.current();
 }