@Override public void add(Object obj) { synchronized (SimpleSequence.this) { SimpleSequence.this.add(obj); } }
/** * Adds a boolean value to the end of this sequence. The newly added boolean will be immediately converted into * {@link TemplateBooleanModel#TRUE} or {@link TemplateBooleanModel#FALSE}, without using the {@link ObjectWrapper}. * * @param b * The boolean value to be added. * * @deprecated Use {@link #add(Object)} instead, as this bypasses the {@link ObjectWrapper}. */ @Deprecated public void add(boolean b) { add(b ? TemplateBooleanModel.TRUE : TemplateBooleanModel.FALSE); }
@Override TemplateModel calculateResult(String s, Environment env) { SimpleSequence result = new SimpleSequence(); StringTokenizer st = new StringTokenizer(s); while (st.hasMoreTokens()) { result.add(st.nextToken()); } return result; } }
MatchWithGroups(String input, Matcher matcher) { matchedInputPart = input.substring(matcher.start(), matcher.end()); final int grpCount = matcher.groupCount() + 1; groupsSeq = new SimpleSequence(grpCount); for (int i = 0; i < grpCount; i++) { groupsSeq.add(matcher.group(i)); } }
@Override TemplateModel _eval(Environment env) throws TemplateException { SimpleSequence list = new SimpleSequence(items.size()); for (Iterator it = items.iterator(); it.hasNext(); ) { Expression exp = (Expression) it.next(); TemplateModel tm = exp.eval(env); if (env == null || !env.isClassicCompatible()) { exp.assertNonNull(tm, env); } list.add(tm); } return list; }
public TemplateSequenceModel getChildNodes() { if (childBuffer != null) { final SimpleSequence seq = new SimpleSequence(childCount); for (int i = 0; i < childCount; i++) { seq.add(childBuffer[i]); } return seq; } else { return new SimpleSequence(0); } }
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); } } }
TemplateSequenceModel evaluateStringsToNamespaces(Environment env) throws TemplateException { TemplateSequenceModel val = (TemplateSequenceModel) eval(env); SimpleSequence result = new SimpleSequence(val.size()); for (int i = 0; i < items.size(); i++) { Object itemExpr = items.get(i); if (itemExpr instanceof StringLiteral) { String s = ((StringLiteral) itemExpr).getAsString(); try { Environment.Namespace ns = env.importLib(s, null); result.add(ns); } catch (IOException ioe) { throw new _MiscTemplateException(((StringLiteral) itemExpr), "Couldn't import library ", new _DelayedJQuote(s), ": ", new _DelayedGetMessage(ioe)); } } else { result.add(val.get(i)); } } return result; }
private void initValues() throws TemplateModelException { if (values == null) { SimpleSequence seq = new SimpleSequence(size()); // Note: size() invokes initKeys() if needed. int ln = keys.size(); for (int i = 0; i < ln; i++) { seq.add(get(((TemplateScalarModel) keys.get(i)).getAsString())); } values = new CollectionAndSequence(seq); } } }
if (nodeNamespaces == null) { SimpleSequence ss = new SimpleSequence(1); ss.add(currentNamespace); nodeNamespaces = ss;
@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; }
macroCtx.setLocalVar(argName, argValue); } else { catchAllParamValue.add(argValue);
if (nss instanceof TemplateHashModel) { SimpleSequence ss = new SimpleSequence(1); ss.add(nss); nss = ss; } else if (!(nss instanceof TemplateSequenceModel)) {
@Override TemplateElement[] accept(Environment env) throws IOException, TemplateException { TemplateModel node = targetNode.eval(env); if (!(node instanceof TemplateNodeModel)) { throw new NonNodeException(targetNode, node, env); } TemplateModel nss = namespaces == null ? null : namespaces.eval(env); if (namespaces instanceof StringLiteral) { nss = env.importLib(((TemplateScalarModel) nss).getAsString(), null); } else if (namespaces instanceof ListLiteral) { nss = ((ListLiteral) namespaces).evaluateStringsToNamespaces(env); } if (nss != null) { if (nss instanceof Environment.Namespace) { SimpleSequence ss = new SimpleSequence(1); ss.add(nss); nss = ss; } else if (!(nss instanceof TemplateSequenceModel)) { if (namespaces != null) { throw new NonSequenceException(namespaces, nss, env); } else { // Should not occur throw new _MiscTemplateException(env, "Expecting a sequence of namespaces after \"using\""); } } } env.invokeNodeHandlerFor((TemplateNodeModel) node, (TemplateSequenceModel) nss); return null; }
MatchWithGroups(String input, Matcher matcher) { matchedInputPart = input.substring(matcher.start(), matcher.end()); final int grpCount = matcher.groupCount() + 1; groupsSeq = new SimpleSequence(grpCount); for (int i = 0; i < grpCount; i++) { groupsSeq.add(matcher.group(i)); } }
@Override TemplateModel calculateResult(String s, Environment env) { SimpleSequence result = new SimpleSequence(); StringTokenizer st = new StringTokenizer(s); while (st.hasMoreTokens()) { result.add(st.nextToken()); } return result; } }
MatchWithGroups(String input, Matcher matcher) { matchedInputPart = input.substring(matcher.start(), matcher.end()); final int grpCount = matcher.groupCount() + 1; groupsSeq = new SimpleSequence(grpCount); for (int i = 0; i < grpCount; i++) { groupsSeq.add(matcher.group(i)); } }
public TemplateSequenceModel getChildNodes() { if (nestedElements != null) { return new SimpleSequence(nestedElements); } SimpleSequence result = new SimpleSequence(); if (nestedBlock != null) { result.add(nestedBlock); } return result; }
public TemplateSequenceModel getChildNodes() { if (childBuffer != null) { final SimpleSequence seq = new SimpleSequence(childCount); for (int i = 0; i < childCount; i++) { seq.add(childBuffer[i]); } return seq; } else { return new SimpleSequence(0); } }
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); } } }