public KeyValuePair next() throws TemplateModelException { final TemplateModel key = keyIter.next(); if (!(key instanceof TemplateScalarModel)) { throw _MessageUtil.newKeyValuePairListingNonStringKeyExceptionMessage(key, hash); } return new KeyValuePair() { public TemplateModel getKey() throws TemplateModelException { return key; } public TemplateModel getValue() throws TemplateModelException { return hash.get(((TemplateScalarModel) key).getAsString()); } }; }
private void initSequence() throws TemplateModelException { if (data == null) { data = new ArrayList<TemplateModel>(); TemplateModelIterator it = collection.iterator(); while (it.hasNext()) { data.add(it.next()); } } }
/** * Constructs a simple sequence from the passed collection model, which shouldn't be added to later. The internal * list will be build immediately (not lazily). The resulting sequence shouldn't be extended with * {@link #add(Object)}, because the appropriate {@link ObjectWrapper} won't be available; use * {@link #SimpleSequence(Collection, ObjectWrapper)} instead, if you need that. */ public SimpleSequence(TemplateCollectionModel tcm) throws TemplateModelException { ArrayList alist = new ArrayList(); for (TemplateModelIterator it = tcm.iterator(); it.hasNext(); ) { alist.add(it.next()); } alist.trimToSize(); list = alist; }
public DebugModel[] getCollection() throws TemplateModelException, RemoteException { List list = new ArrayList(); TemplateModelIterator i = ((TemplateCollectionModel) model).iterator(); while (i.hasNext()) { list.add(getDebugModel(i.next())); } return (DebugModel[]) list.toArray(new DebugModel[list.size()]); }
private TemplateModel calculateResultForColletion(TemplateCollectionModel coll) throws TemplateModelException { TemplateModelIterator iter = coll.iterator(); if (!iter.hasNext()) { return null; } return iter.next(); }
public String[] keys() throws TemplateModelException { TemplateHashModelEx h = (TemplateHashModelEx) model; List list = new ArrayList(); TemplateModelIterator i = h.keys().iterator(); while (i.hasNext()) { list.add(((TemplateScalarModel) i.next()).getAsString()); } return (String[]) list.toArray(new String[list.size()]); }
public Object nextElement() { try { return ((TemplateScalarModel) it.next()).getAsString(); } catch (TemplateModelException tme) { throw new UndeclaredThrowableException(tme); } } }
public Object next() { try { return wrapper.unwrap(i.next()); } catch (TemplateModelException e) { throw new UndeclaredThrowableException(e); } }
public Collection getLocalVariableNames() throws TemplateModelException { HashSet result = new HashSet(); for (TemplateModelIterator it = localVars.keys().iterator(); it.hasNext(); ) { result.add(((TemplateScalarModel) it.next()).getAsString()); } return result; } }
public Object exec(List args) throws TemplateModelException { checkMethodArgCount(args, 1); TemplateModel arg = (TemplateModel) args.get(0); TemplateModelIterator it = m_coll.iterator(); int idx = 0; while (it.hasNext()) { if (modelsEqual(idx, it.next(), arg, m_env)) return TemplateBooleanModel.TRUE; idx++; } return TemplateBooleanModel.FALSE; }
protected int findInCol(TemplateModel searched, final int allowedRangeStart, final int allowedRangeEnd) throws TemplateModelException { if (allowedRangeEnd < 0) return -1; TemplateModelIterator it = m_col.iterator(); int foundAtIdx = -1; // -1 is the return value for "not found" int idx = 0; searchItem: while (it.hasNext()) { if (idx > allowedRangeEnd) break searchItem; TemplateModel current = it.next(); if (idx >= allowedRangeStart) { if (modelsEqual(idx, current, searched, m_env)) { foundAtIdx = idx; // Don't stop if it's "find last". if (findFirst) { break searchItem; } } } idx++; } return foundAtIdx; }
private TemplateModel calculateResultForColletion(TemplateCollectionModel coll, Environment env) throws TemplateException { TemplateModel best = null; TemplateModelIterator iter = coll.iterator(); while (iter.hasNext()) { TemplateModel cur = iter.next(); if (cur != null && (best == null || EvalUtil.compare(cur, null, comparatorOperator, null, best, null, this, true, false, false, false, env))) { best = cur; } } return best; }
private static void addKeys(Set set, SimpleSequence keySeq, TemplateHashModelEx hash) throws TemplateModelException { TemplateModelIterator it = hash.keys().iterator(); while (it.hasNext()) { TemplateScalarModel tsm = (TemplateScalarModel) it.next(); if (set.add(tsm.getAsString())) { // The first occurence of the key decides the index; // this is consisten with stuff like java.util.LinkedHashSet. keySeq.add(tsm); } } }
public TemplateCollectionModel values() throws TemplateModelException { List<Object> values = new ArrayList<Object>(size()); TemplateModelIterator it = keys().iterator(); while (it.hasNext()) { String key = ((TemplateScalarModel) it.next()).getAsString(); values.add(get(key)); } return new CollectionAndSequence(new SimpleSequence(values, wrapper)); }
/** * Adds all object in the hash as shared variable to the configuration; it's like doing several * {@link #setSharedVariable(String, Object)} calls, one for each hash entry. It doesn't remove the already added * shared variable before doing this. * * <p>Never use <tt>TemplateModel</tt> implementation that is not thread-safe for shared shared variable values, * if the configuration is used by multiple threads! It is the typical situation for Servlet based Web sites. * * <p>This method is <b>not</b> thread safe; use it with the same restrictions as those that modify setting values. * * @param hash a hash model whose objects will be copied to the * configuration with same names as they are given in the hash. * If a shared variable with these names already exist, it will be replaced * with those from the map. * * @see #setSharedVaribles(Map) * @see #setSharedVariable(String,Object) * @see #setSharedVariable(String,TemplateModel) */ public void setAllSharedVariables(TemplateHashModelEx hash) throws TemplateModelException { TemplateModelIterator keys = hash.keys().iterator(); TemplateModelIterator values = hash.values().iterator(); while (keys.hasNext()) { setSharedVariable(((TemplateScalarModel) keys.next()).getAsString(), values.next()); } }
boolean hadItem = false; while (it.hasNext()) { TemplateModel item = it.next(); if (item != null) { if (hadItem) {
TemplateModelIterator rootNames = ((TemplateHashModelEx) rootDataModel).keys().iterator(); while (rootNames.hasNext()) { set.add(((TemplateScalarModel) rootNames.next()).getAsString()); set.add(((TemplateScalarModel) tmi.next()).getAsString()); set.add(((TemplateScalarModel) tmi.next()).getAsString());
TemplateModelIterator it = coll.iterator(); while (it.hasNext()) { list.add(unwrap(it.next(), nullModel, permissive)); TemplateModelIterator keys = hash.keys().iterator(); while (keys.hasNext()) { String key = (String) unwrap(keys.next(), nullModel, permissive); map.put(key, unwrap(hash.get(key), nullModel, permissive));
@Override TemplateModel _eval(Environment env) throws TemplateException { TemplateModel model = target.eval(env); if (model instanceof TemplateSequenceModel && !isBuggySeqButGoodCollection(model)) { return model; } if (!(model instanceof TemplateCollectionModel)) { throw new NonSequenceOrCollectionException(target, model, env); } TemplateCollectionModel coll = (TemplateCollectionModel) model; SimpleSequence seq = coll instanceof TemplateCollectionModelEx ? new SimpleSequence(((TemplateCollectionModelEx) coll).size()) : new SimpleSequence(); for (TemplateModelIterator iter = coll.iterator(); iter.hasNext(); ) { seq.add(iter.next()); } return seq; }
if (loopVarName != null) { listLoop: do { loopVar = iterModel.next(); hasNext = iterModel.hasNext(); try {