public void run() throws SaxonApiException {
    super.run();

    RuntimeValue wrapperNameValue = getOption(_wrapper);
    String wrapperNameStr = wrapperNameValue.getString();
    String wpfx = getOption(_wrapper_prefix, (String) null);
    String wns = getOption(_wrapper_namespace, (String) null);

    if (wpfx != null && wns == null) {
      throw XProcException.dynamicError(
          34, step.getNode(), "You can't specify a prefix without a namespace");
    }

    if (wns != null && wrapperNameStr.contains(":")) {
      throw XProcException.dynamicError(
          34, step.getNode(), "You can't specify a namespace if the wrapper name contains a colon");
    }

    if (wrapperNameStr.contains(":")) {
      wrapper = new QName(wrapperNameStr, wrapperNameValue.getNode());
    } else {
      wrapper = new QName(wpfx == null ? "" : wpfx, wns, wrapperNameStr);
    }

    groupAdjacent = getOption(_group_adjacent);

    if (groupAdjacent != null) {
      runAdjacent();
    } else {
      runSimple();
    }
  }
示例#2
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);
      }
    }
  }
示例#3
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;
  }