示例#1
0
  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);
    }
  }
示例#2
0
 public void putDocumentEnd() throws DataModelException {
   try {
     if (contentHandler != null) contentHandler.endDocument();
   } catch (SAXException e) {
     convertSaxException(e);
   }
   super.putDocumentEnd();
 }
示例#3
0
 public void putElementEnd(QName name) throws DataModelException {
   if (elementStarted) flushElementStart(true);
   if (contentHandler != null)
     try {
       String qname = // TODO avoid double creation by managing a stack
           getNsPrefixes() ? nsContext.prefixedName(name) : "";
       contentHandler.endElement(name.getNamespaceURI(), name.getLocalPart(), qname);
       // remove mappings
       for (int m = 0, cnt = nsContext.getLocalSize(); m < cnt; m++)
         contentHandler.endPrefixMapping(nsContext.getLocalPrefix(m));
     } catch (SAXException e) {
       convertSaxException(e);
     }
   super.putElementEnd(name);
 }
示例#4
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
      }
    }