コード例 #1
0
ファイル: CurrentDateTime.java プロジェクト: gufengwyx8/Qizx
 public XQValue eval(Focus focus, EvalContext context) throws EvaluationException {
   context.at(this);
   try {
     return SingleMoment.dateTime(new DateTime(context.getCurrentDate()));
   } catch (DateTimeException e) {
     return XQValue.empty;
   }
 }
コード例 #2
0
 public BasicNode evalAsNode(Focus focus, EvalContext context) throws EvaluationException {
   BasicStaticContext staticContext = context.getStaticContext();
   // we arrive here if building nodes is really wanted
   CorePushBuilder builder =
       new CorePushBuilder(staticContext.getBaseURI(), staticContext.getInScopeNS());
   // for dynamic qname evaluation: make inscope ns visible
   context.setInScopeNS(builder.getNamespaceContext());
   evalAsEvents(builder, focus, context);
   return builder.harvest();
 }
コード例 #3
0
ファイル: TryCatchExpr.java プロジェクト: gufengwyx8/Qizx
  public XQValue eval(Focus focus, EvalContext context) throws EvaluationException {
    context.at(this);
    try {
      XQValue res = caught.eval(focus, context);
      // it is crucial to expand the sequence here, so that
      // eval errors are actually caught
      ArraySequence expanded = new ArraySequence(4, res);
      for (; res.next(); ) expanded.addItem(res.getItem());
      return expanded;
    } catch (EvaluationException e) {
      Catch catcher = null;
      for (int i = 0; i < catches.length; i++) {
        if (catches[i].catches(e.getErrorCode())) {
          catcher = catches[i];
          break;
        }
      }

      if (catcher == null) throw e;
      if (compatibility) {
        // feature: show error as a node whose name is the error code
        // and whose content the message
        CorePushBuilder builder = new CorePushBuilder("");
        QName errName = IQName.get(e.getErrorCode());
        try {
          builder.putElementStart(errName); // cant be attr value
          builder.putText(e.getMessage());
          builder.putElementEnd(errName);
        } catch (QizxException e1) {;
        }
        context.storeLocal(
            catcher.valueVar.address, new SingleNode(builder.harvest()), false /* current */, null);
      } else { // 1.1
        if (catcher.codeVar != null) {
          context.storeLocal(
              catcher.codeVar.address,
              new SingleQName(e.getErrorCode()),
              false /* current */,
              null);
        }
        if (catcher.descVar != null) {
          context.storeLocal(
              catcher.descVar.address, new SingleString(e.getMessage()), false /* current */, null);
        }
        if (catcher.valueVar != null) {
          XQValue v = e.getValue();
          if (v == null) v = XQValue.empty;
          context.storeLocal(catcher.valueVar.address, v, false /* current */, null);
        }
      }
      // execute the handler with bound variables (if any)
      return catcher.handler.eval(focus, context);
    }
  }
コード例 #4
0
ファイル: Compare.java プロジェクト: gufengwyx8/Qizx
    public long evalAsInteger(Focus focus, EvalContext context) throws EvaluationException {
      context.at(this);
      String s1 = args[0].evalAsOptString(focus, context);
      String s2 = args[1].evalAsOptString(focus, context);

      if (s1 == null || s2 == null) throw EmptyException.instance();

      Collator coll = getCollator(args.length <= 2 ? null : args[2], focus, context);
      context.at(this);
      // use Comparison.of to obtain EQ LT GT etc
      return Comparison.of(coll != null ? coll.compare(s1, s2) : s1.compareTo(s2), 0);
    }
コード例 #5
0
ファイル: WhileExpr.java プロジェクト: gufengwyx8/Qizx
 public XQValue eval(Focus focus, EvalContext context) throws EvaluationException {
   context.at(this);
   while (cond.evalEffectiveBooleanValue(focus, context)) {
     block.eval(focus, context);
   }
   return XQValue.empty;
 }
コード例 #6
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);
    }
  }
コード例 #7
0
 public double evalAsDouble(Focus focus, EvalContext context) throws EvaluationException {
   context.at(this);
   XQItem v = args[0].evalAsOptItem(focus, context);
   if (v == null) throw EmptyException.instance();
   if (v instanceof MomentValue) {
     MomentValue mv = (MomentValue) v;
     return mv.getValue().getSecond();
   }
   try {
     DateTime dt = DateTime.parseDateTime(v.getString());
     return dt.getSecond();
   } catch (DateTimeException e) {
     context.error(Conversion.ERR_CAST, this, "cannot cast to xs:dateTime : " + e.getMessage());
     return 0;
   }
 }
コード例 #8
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
      }
    }