Esempio n. 1
0
  /**
   * Run the query in pull mode.
   *
   * <p>
   *
   * <p>For maximum effect this method should be used when lazyConstructionMode has been set in the
   * Configuration.
   *
   * <p>
   *
   * <p><b>Note: this method usually has very similar performance to the {@link
   * #run(DynamicQueryContext,javax.xml.transform.Result,java.util.Properties)} method (which does
   * the same thing), but sometimes it is significantly slower. Therefore, the run() method is
   * preferred.</b>
   *
   * @param dynamicEnv the dynamic context for query evaluation
   * @param destination the destination of the query results
   * @param outputProperties the serialization parameters
   * @see Configuration#setLazyConstructionMode(boolean)
   */
  public void pull(DynamicQueryContext dynamicEnv, Result destination, Properties outputProperties)
      throws XPathException {
    if (isUpdating) {
      throw new XPathException("Cannot call pull() on an updating query");
    }
    Configuration config = dynamicEnv.getConfiguration();
    try {
      Controller controller = newController();
      // initializeController(dynamicEnv, controller);
      EventIterator iter = iterateEvents(controller, dynamicEnv);
      // iter = new Decomposer(iter, config);

      Properties actualProperties = validateOutputProperties(controller, outputProperties);
      SerializerFactory sf = config.getSerializerFactory();
      PipelineConfiguration pipe = config.makePipelineConfiguration();
      pipe.setSerializing(true);
      Receiver receiver = sf.getReceiver(destination, pipe, actualProperties);

      receiver = new NamespaceReducer(receiver);
      if ("yes".equals(actualProperties.getProperty(SaxonOutputKeys.WRAP))) {
        receiver = new SequenceWrapper(receiver);
        // receiver = new TracingFilter(receiver);
      } else {
        receiver = new TreeReceiver(receiver);
      }
      EventIteratorToReceiver.copy(iter, (SequenceReceiver) receiver);
    } catch (XPathException err) {
      config.reportFatalError(err);
      throw err;
    }
  }
Esempio n. 2
0
  /**
   * Run the query in pull mode.
   *
   * <p>
   *
   * <p>For maximum effect this method should be used when lazyConstructionMode has been set in the
   * Configuration.
   *
   * <p>
   *
   * <p><b>Note: this method usually has very similar performance to the {@link
   * #run(DynamicQueryContext,javax.xml.transform.Result,java.util.Properties)} method (which does
   * the same thing), but sometimes it is significantly slower. Therefore, the run() method is
   * preferred.</b>
   *
   * @param dynamicEnv the dynamic context for query evaluation
   * @param destination the destination of the query results
   * @param outputProperties the serialization parameters
   * @see Configuration#setLazyConstructionMode(boolean)
   */
  public void pullOLD(
      DynamicQueryContext dynamicEnv, Result destination, Properties outputProperties)
      throws XPathException {
    try {
      SequenceIterator iter = iterator(dynamicEnv);
      PullProvider pull = new PullFromIterator(iter);
      pull = new PullNamespaceReducer(pull);
      final Configuration config = executable.getConfiguration();
      pull.setPipelineConfiguration(config.makePipelineConfiguration());

      SerializerFactory sf = config.getSerializerFactory();
      Receiver receiver =
          sf.getReceiver(destination, pull.getPipelineConfiguration(), outputProperties);

      //            NamespaceReducer reducer = new NamespaceReducer();
      //            PipelineConfiguration pipe = pull.getPipelineConfiguration();
      //            reducer.setPipelineConfiguration(pipe);
      //            reducer.setUnderlyingReceiver(receiver);
      //            ComplexContentOutputter outputter = new ComplexContentOutputter();
      //            outputter.setReceiver(reducer);
      //            outputter.setPipelineConfiguration(pipe);
      Receiver outputter = receiver;
      if ("yes".equals(outputProperties.getProperty(SaxonOutputKeys.WRAP))) {
        receiver = new SequenceWrapper(outputter);
      } else {
        // receiver = new TreeReceiver(outputter);
      }
      new PullPushCopier(pull, receiver).copy();
    } catch (UncheckedXPathException e) {
      throw e.getXPathException();
    }
  }
Esempio n. 3
0
  private Properties validateOutputProperties(Controller controller, Properties outputProperties)
      throws XPathException {
    // Validate the serialization properties requested

    Properties baseProperties = controller.getOutputProperties();
    if (outputProperties != null) {
      Enumeration iter = outputProperties.propertyNames();
      while (iter.hasMoreElements()) {
        String key = (String) iter.nextElement();
        String value = outputProperties.getProperty(key);
        try {
          SaxonOutputKeys.checkOutputProperty(
              key, value, controller.getConfiguration().getNameChecker());
          baseProperties.setProperty(key, value);
        } catch (XPathException dynamicError) {
          try {
            outputProperties.remove(key);
            controller.getErrorListener().warning(dynamicError);
          } catch (TransformerException err2) {
            throw XPathException.makeXPathException(err2);
          }
        }
      }
    }
    if (baseProperties.getProperty("method") == null) {
      // XQuery forces the default method to XML, unlike XSLT where it depends on the contents of
      // the result tree
      baseProperties.setProperty("method", "xml");
    }
    return baseProperties;
  }