public void evalAsEvents(XMLPushStreamBase output, Focus focus, EvalContext context)
      throws EvaluationException {
    context.at(this);
    QName qname = evalName(output, focus, context);

    try {
      output.putElementStart(qname);

      for (int a = 0; a < attributes.size(); a++) {
        try {
          getAttribute(a).evalAsEvents(output, focus, context);
        } catch (EvaluationException e) {
          if ((getFlags() & DIRECT) != 0) e.substituteCode("XQDY0025", "XQST0040");
          throw e;
        }
      }
      for (int c = 0; c < contents.length; c++) {
        contents[c].evalAsEvents(output, focus, context);
        output.noSpace();
      }
      output.putElementEnd(qname);
    } catch (DataModelException e) {
      dmError(context, e);
    }
  }
Beispiel #2
0
    public void evalAsEvents(XMLPushStreamBase output, Focus focus, EvalContext context)
        throws EvaluationException {
      context.at(this);
      String code = args[0].evalAsString(focus, context);
      code = code.replace('\r', ' ');
      Node options = (args.length < 2) ? null : args[1].evalAsOptNode(focus, context);
      LexicalTokenizer scolo = new LexicalTokenizer(code);

      QName wrapperElem = IQName.get("pre");
      QName spanElem = IQName.get("span");
      QName classAttr = IQName.get("class");

      try {
        if (options != null) {
          Node[] attrs = options.getAttributes();
          if (attrs != null)
            for (int a = 0; a < attrs.length; a++) {
              Node attr = attrs[a];
              String option = attr.getNodeName().getLocalPart();
              // TODO specify span element?
            }
        }
        output.putElementStart(wrapperElem);
        int prevToken = -1;
        for (int token = scolo.nextToken(); token > 0; token = scolo.nextToken()) {
          String space = scolo.getSpace();
          if (space != null) output.putText(space);
          if (token != prevToken) {
            if (prevToken >= 0) output.putElementEnd(spanElem);
            output.putElementStart(spanElem);
            output.putAttribute(classAttr, "xq_" + tokenTypes[token], null);
            prevToken = token;
          }
          String value = scolo.getTokenValue();
          output.putText(value);
        }
        output.putElementEnd(spanElem);
        output.putElementEnd(wrapperElem);
      } catch (DataModelException e) {
        // should not happen
      } catch (CompilationException e) {
        // ignore and stop
      }
    }