Esempio n. 1
0
 /**
  * @param value
  * @param runtime
  * @param appender
  * @param ctx
  * @param factory
  */
 public void processOrder(
     Object value,
     TemplateRuntime runtime,
     TemplateOutputStream appender,
     QueryContext ctx,
     VariableResolverFactory factory) {
   if (value instanceof Iterable) {
     Iterable<?> ordItems = (Iterable<?>) value;
     new Joiner(appender).join(ordItems);
   } else if (value instanceof CharSequence) {
     CharSequence seq = (CharSequence) value;
     if (seq.length() > 0) {
       appender.append(ORDER_BY_PREFIX);
       appender.append((CharSequence) value);
     }
   } else {
     Object[] ordItems = asObjectArray(value);
     if (ordItems != null) {
       new Joiner(appender).join(ordItems);
     } else if (value != null) {
       appender.append(ORDER_BY_PREFIX);
       appender.append(value.toString());
     }
   }
 }
Esempio n. 2
0
  public Object eval(
      TemplateRuntime runtime,
      TemplateOutputStream appender,
      Object ctx,
      VariableResolverFactory factory) {
    Iterator[] iters = new Iterator[item.length];

    Object o;
    for (int i = 0; i < iters.length; i++) {
      if ((o = MVEL.eval(expression[i], ctx, factory)) instanceof Iterable) {
        iters[i] = ((Iterable) o).iterator();
      } else if (o instanceof Object[]) {
        iters[i] = new ArrayIterator((Object[]) o);
      } else {
        throw new TemplateRuntimeError("cannot iterate object type: " + o.getClass().getName());
      }
    }

    Map<String, Object> locals = new HashMap<String, Object>();
    MapVariableResolverFactory localFactory = new MapVariableResolverFactory(locals, factory);

    int iterate = iters.length;

    while (true) {
      for (int i = 0; i < iters.length; i++) {
        if (!iters[i].hasNext()) {
          iterate--;
          locals.put(item[i], "");
        } else {
          locals.put(item[i], iters[i].next());
        }
      }
      if (iterate != 0) {
        nestedNode.eval(runtime, appender, ctx, localFactory);

        if (sepExpr != null) {
          for (Iterator it : iters) {
            if (it.hasNext()) {
              appender.append(String.valueOf(MVEL.eval(sepExpr, ctx, factory)));
              break;
            }
          }
        }
      } else break;
    }

    return next != null ? next.eval(runtime, appender, ctx, factory) : null;
  }
Esempio n. 3
0
 /**
  * @param appender
  * @param ord
  */
 protected void appendOrder(TemplateOutputStream appender, OrderBy ord) {
   appender.append(ord.getOrderItem()).append(" ").append(ord.getOrder().name());
 }
Esempio n. 4
0
 @Override
 protected TemplateOutputStream appendFirst(TemplateOutputStream output, Object value) {
   output.append(ORDER_BY_PREFIX);
   return output.append(value.toString());
 }
Esempio n. 5
0
 @Override
 protected TemplateOutputStream append(TemplateOutputStream output, Object value) {
   return output.append(value.toString());
 }