コード例 #1
0
ファイル: IteratorBlock.java プロジェクト: gufanyi/wdp
 void runLoop(Environment env) throws TemplateException, IOException {
   if (list instanceof TemplateCollectionModel) {
     TemplateCollectionModel baseListModel = (TemplateCollectionModel) list;
     TemplateModelIterator it = baseListModel.iterator();
     hasNext = it.hasNext();
     while (hasNext) {
       loopVar = it.next();
       hasNext = it.hasNext();
       if (nestedBlock != null) {
         env.visit(nestedBlock);
       }
       index++;
     }
   } else if (list instanceof TemplateSequenceModel) {
     TemplateSequenceModel tsm = (TemplateSequenceModel) list;
     int size = tsm.size();
     for (index = 0; index < size; index++) {
       loopVar = tsm.get(index);
       hasNext = (size > index + 1);
       if (nestedBlock != null) {
         env.visit(nestedBlock);
       }
     }
   } else if (env.isClassicCompatible()) {
     loopVar = list;
     if (nestedBlock != null) {
       env.visit(nestedBlock);
     }
   } else {
     throw invalidTypeException(list, listExpression, env, "collection or sequence");
   }
 }
コード例 #2
0
 public Collection<Entity<?>> convert(TemplateHashModelEx hash, String... ignore) {
   List<Entity<?>> entities = new LinkedList<Entity<?>>();
   List<String> ignoreList = Arrays.asList(ignore);
   TemplateCollectionModel keys;
   try {
     keys = hash.keys();
     for (TemplateModelIterator iterator = keys.iterator(); iterator.hasNext(); ) {
       TemplateModel model = iterator.next();
       String key = model.toString();
       if (!ignoreList.contains(key)) {
         entities.add(new SimpleEntityModel(key, hash.get(key).toString()));
       }
     }
     Collections.sort(entities, new EntityComparator());
     return entities;
   } catch (TemplateModelException e) {
     throw new RuntimeException(e);
   }
 }
コード例 #3
0
ファイル: SQLTemplate.java プロジェクト: wutongservice/wutong
 private static List<TemplateModel> readList(TemplateModel o) {
   try {
     ArrayList<TemplateModel> l = new ArrayList<TemplateModel>();
     if (o instanceof TemplateSequenceModel) {
       TemplateSequenceModel seq = (TemplateSequenceModel) o;
       for (int i = 0; i < seq.size(); i++) l.add(seq.get(i));
     } else if (o instanceof TemplateCollectionModel) {
       TemplateCollectionModel coll = (TemplateCollectionModel) o;
       TemplateModelIterator iter = coll.iterator();
       while (iter.hasNext()) l.add(iter.next());
     } else if (o instanceof TemplateBooleanModel) {
       l.add(o);
     } else if (o instanceof TemplateNumberModel) {
       l.add(o);
     } else if (o instanceof TemplateScalarModel) {
       l.add(o);
     }
     return l;
   } catch (TemplateModelException e) {
     throw new ServerException(BaseErrors.PLATFORM_SQL_TEMPLATE_ERROR, e);
   }
 }