Exemplo n.º 1
0
  public void run() throws SaxonApiException {
    fine(null, "Running p:viewport " + step.getName());

    XProcData data = runtime.getXProcData();
    data.openFrame(this);

    if (current == null) {
      current = new Pipe(runtime);
    }

    RuntimeValue match = ((Viewport) step).getMatch();

    String iport = "#viewport-source";
    ReadablePipe vsource = null;

    if (inputs.get(iport).size() != 1) {
      throw XProcException.dynamicError(3);
    } else {
      vsource = inputs.get(iport).get(0);
    }

    XdmNode doc = vsource.read();
    if (doc == null || vsource.moreDocuments()) {
      throw XProcException.dynamicError(3);
    }

    matcher = new ProcessMatch(runtime, this);

    // FIXME: Only do this if we really need to!
    sequenceLength = matcher.count(doc, match, false);

    runtime.getXProcData().setIterationSize(sequenceLength);

    matcher.match(doc, match);

    for (String port : inputs.keySet()) {
      if (port.startsWith("|")) {
        String wport = port.substring(1);
        WritablePipe pipe = outputs.get(wport);
        XdmNode result = matcher.getResult();
        pipe.write(result);
        finest(step.getNode(), "Viewport output copy from matcher to " + pipe);
      }
    }
  }
Exemplo n.º 2
0
  public boolean processStartElement(XdmNode node) {
    // Use a TreeWriter to make the matching node into a proper document
    TreeWriter treeWriter = new TreeWriter(runtime);
    treeWriter.startDocument(node.getBaseURI());
    treeWriter.addSubtree(node);
    treeWriter.endDocument();

    current.resetWriter();
    current.write(treeWriter.getResult());

    finest(step.getNode(), "Viewport copy matching node to " + current);

    sequencePosition++;
    runtime.getXProcData().setIterationPosition(sequencePosition);

    // Calculate all the variables
    inScopeOptions = parent.getInScopeOptions();
    for (Variable var : step.getVariables()) {
      RuntimeValue value = computeValue(var);

      if ("p3".equals(var.getName().getLocalName())) {
        System.err.println("DEBUG ME1: " + value.getString());
      }

      inScopeOptions.put(var.getName(), value);
    }

    try {
      for (XStep step : subpipeline) {
        step.reset();
        step.run();
      }
    } catch (SaxonApiException sae) {
      throw new XProcException(sae);
    }

    try {
      int count = 0;
      for (String port : inputs.keySet()) {
        if (port.startsWith("|")) {
          for (ReadablePipe reader : inputs.get(port)) {
            while (reader.moreDocuments()) {
              count++;

              if (count > 1) {
                XOutput output = getOutput(port.substring(1));
                if (!output.getSequence()) {
                  throw XProcException.dynamicError(7);
                }
              }

              XdmNode doc = reader.read();
              matcher.addSubtree(doc);
            }
            reader.resetReader();
          }
        }
      }
    } catch (SaxonApiException sae) {
      throw new XProcException(sae);
    }

    return false;
  }