示例#1
0
  public static Literal cachedWithinValue(Expression val) throws EvaluatorException {
    if (val instanceof Literal) {
      Literal l = (Literal) val;

      // double == days
      Double d = l.getDouble(null);
      if (d != null) {
        return new LitLong(TimeSpanImpl.fromDays(d.doubleValue()).getMillis(), null, null);
      }

      // request
      String str = l.getString();
      if (str != null && "request".equalsIgnoreCase(str.trim()))
        return new LitString("request", null, null);

      throw cacheWithinException();
    }
    // createTimespan
    else if (val instanceof Variable) {
      Variable var = (Variable) val;
      if (var.getMembers().size() == 1) {
        Member first = var.getFirstMember();
        if (first instanceof BIF) {
          BIF bif = (BIF) first;
          if ("createTimeSpan".equalsIgnoreCase(bif.getFlf().getName())) {
            Argument[] args = bif.getArguments();
            int len = ArrayUtil.size(args);
            if (len >= 4 && len <= 5) {
              double days = toDouble(args[0].getValue());
              double hours = toDouble(args[1].getValue());
              double minutes = toDouble(args[2].getValue());
              double seconds = toDouble(args[3].getValue());
              double millis = len == 5 ? toDouble(args[4].getValue()) : 0;
              return new LitLong(
                  new TimeSpanImpl(
                          (int) days, (int) hours, (int) minutes, (int) seconds, (int) millis)
                      .getMillis(),
                  null,
                  null);
            }
          }
        }
      }
    }
    throw cacheWithinException();
  }
示例#2
0
 /**
  * extract the content of a attribut
  *
  * @param cfxdTag
  * @param attrName
  * @return attribute value
  * @throws EvaluatorException
  */
 public static String getAttributeString(Tag tag, String attrName, String defaultValue) {
   Literal lit = getAttributeLiteral(tag, attrName, null);
   if (lit == null) return defaultValue;
   return lit.getString();
 }