Beispiel #1
0
  @Override
  public Object callWithNamedValues(PageContext pageContext, Struct values, boolean doIncludePath)
      throws PageException {
    ArrayList<FunctionLibFunctionArg> flfas = flf.getArg();
    Iterator<FunctionLibFunctionArg> it = flfas.iterator();
    FunctionLibFunctionArg arg;
    Object val;

    List<Ref> refs = new ArrayList<Ref>();
    while (it.hasNext()) {
      arg = it.next();

      // match by name
      val = values.get(arg.getName(), null);

      // match by alias
      if (val == null) {
        String alias = arg.getAlias();
        if (!StringUtil.isEmpty(alias, true)) {
          String[] aliases =
              lucee.runtime.type.util.ListUtil.trimItems(
                  lucee.runtime.type.util.ListUtil.listToStringArray(alias, ','));
          for (int x = 0; x < aliases.length; x++) {
            val = values.get(aliases[x], null);
            if (val != null) break;
          }
        }
      }

      if (val == null) {
        if (arg.getRequired()) {
          String[] names = flf.getMemberNames();
          String n = ArrayUtil.isEmpty(names) ? "" : names[0];
          throw new ExpressionException(
              "missing required argument ["
                  + arg.getName()
                  + "] for build in function call ["
                  + n
                  + "]");
        }
      } else {
        refs.add(
            new Casting(
                arg.getTypeAsString(),
                arg.getType(),
                new LFunctionValue(new LString(arg.getName()), val)));
      }
    }

    BIFCall call = new BIFCall(flf, refs.toArray(new Ref[refs.size()]));
    return call.getValue(pageContext);
  }
Beispiel #2
0
 /**
  * @param category the category to set
  * @throws ApplicationException
  */
 public void setCategory(String listCategories) {
   if (StringUtil.isEmpty(listCategories)) return;
   this.category = ListUtil.trimItems(ListUtil.listToStringArray(listCategories, ','));
 }