/** * Puts a boolean in the map * * @param key the name by which the resulting <tt>TemplateModel</tt> * is identified in the template. * @param b the boolean to store. */ public void put(String key, boolean b) { put(key, b ? TemplateBooleanModel.TRUE : TemplateBooleanModel.FALSE); }
@Override public void put(String key, Object obj) { synchronized (SimpleHash.this) { SimpleHash.this.put(key, obj); } }
/** * Adds all the key/value entries in the map * @param m the map with the entries to add, the keys are assumed to be strings. */ public void putAll(Map m) { for (Iterator it = m.entrySet().iterator(); it.hasNext(); ) { Map.Entry entry = (Map.Entry) it.next(); this.put((String) entry.getKey(), entry.getValue()); } }
private static TemplateModel wrapMap(Map table) { SimpleHash model = new SimpleHash(); for (Iterator it = table.entrySet().iterator(); it.hasNext(); ) { Map.Entry entry = (Map.Entry) it.next(); model.put(String.valueOf(entry.getKey()), new SimpleScalar(String.valueOf(entry.getValue()))); } return model; }
/** * Loads a template from a file passed as the first argument, loads an XML * document from the standard input, passes it to the template as variable * <tt>document</tt> and writes the result of template processing to * standard output. * * @deprecated Will be removed (main method in a library, often classified as CWE-489 "Leftover Debug Code"). */ @Deprecated public static void main(String[] args) throws Exception { org.jdom.input.SAXBuilder builder = new org.jdom.input.SAXBuilder(); Document document = builder.build(System.in); SimpleHash model = new SimpleHash(); model.put("document", new NodeListModel(document)); FileReader fr = new FileReader(args[0]); Template template = new Template(args[0], fr); Writer w = new java.io.OutputStreamWriter(System.out); template.process(model, w); w.flush(); w.close(); }
root.put("page", new JspContextModel(pageContext, JspContextModel.PAGE_SCOPE)); root.put("request", new JspContextModel(pageContext, JspContextModel.REQUEST_SCOPE)); root.put("session", new JspContextModel(pageContext, JspContextModel.SESSION_SCOPE)); root.put("application", new JspContextModel(pageContext, JspContextModel.APPLICATION_SCOPE)); root.put("any", new JspContextModel(pageContext, JspContextModel.ANY_SCOPE));
private SimpleHash buildType(ComplexType ft) { // create a variable "attributes" which his a list of all the // attributes, but at the same time, is a map keyed by name Map<String, Object> attributeMap = new LinkedHashMap<String, Object>(); Collection<PropertyDescriptor> descriptors = ft.getDescriptors(); for (Iterator<PropertyDescriptor> it = descriptors.iterator(); it.hasNext(); ) { PropertyDescriptor descr = it.next(); Map<String, Object> attribute = new HashMap<String, Object>(); attribute.put("name", descr.getName().getLocalPart()); attribute.put("namespace", getNamespace(descr.getName())); attribute.put("prefix", getPrefix(descr.getName())); attribute.put("type", descr.getType().getBinding().getName()); attribute.put( "isGeometry", Boolean.valueOf(Geometry.class.isAssignableFrom(descr.getType().getBinding()))); attributeMap.put(descr.getName().toString(), attribute); } // build up the result, feature type is represented by its name an // attributes SimpleHash map = new SimpleHash(); map.put("attributes", new SequenceMapModel(attributeMap, this)); map.put("name", ft.getName().getLocalPart()); map.put("namespace", getNamespace(ft.getName())); map.put("prefix", getPrefix(ft.getName())); return map; }
public TemplateModel wrap(Object object) throws TemplateModelException { // check for feature collection if (object instanceof FeatureCollection) { // create a model with just one variable called 'features' SimpleHash map = new SimpleHash(); map.put( "features", templateFeatureCollectionFactory.createTemplateFeatureCollection( (FeatureCollection) object, this)); map.put("type", wrap(((FeatureCollection) object).getSchema())); return map; } else if (object instanceof ComplexType) { return buildType((ComplexType) object); } else if (object instanceof Feature) { return buildComplex((Feature) object); } return super.wrap(object); }
for (int i = 0; i < attributes.getLength(); i++) { Attr att = (Attr) attributes.item(i); hash.put(att.getName(), att.getValue());
result.put(RESULT_EXISTS, template != null); result.put(RESULT_INCLUDE, new TemplateDirectiveModel() { public void execute(Environment env, Map params, TemplateModel[] loopVars, TemplateDirectiveBody body) throws TemplateException, IOException { result.put(RESULT_IMPORT, new TemplateMethodModelEx() { public Object exec(List args) throws TemplateModelException { if (!args.isEmpty()) {
macroCtx.setLocalVar(argName, argValue); } else { catchAllParamValue.put(argName, argValue);
SimpleHash globalModel = new SimpleHash(); TemplateHashModel enumModels = BeansWrapper.getDefaultInstance().getEnumModels(); TemplateHashModel myEnumModel = (TemplateHashModel) enumModels.get("your.fully.qualified.enum.MyEnum"); globalModel.put("MyEnum", myEnumModel); freemarkerConfiguration.setAllSharedVariables(globalModel);
public TemplateContextAdapter(TemplateContext context, ObjectWrapper wrapper) { super(wrapper); for (String key : context.keySet()) { super.put(key, context.get(key)); } } }
public TemplateContextAdapter(TemplateContext context, ObjectWrapper wrapper) { super(wrapper); for (String key : context.keySet()) { super.put(key, context.get(key)); } } }
/** * Puts a boolean in the map * * @param key the name by which the resulting <tt>TemplateModel</tt> * is identified in the template. * @param b the boolean to store. */ public void put(String key, boolean b) { put(key, b ? TemplateBooleanModel.TRUE : TemplateBooleanModel.FALSE); }
/** * Adds all the key/value entries in the map * @param m the map with the entries to add, the keys are assumed to be strings. */ public void putAll(Map m) { for (Iterator it = m.entrySet().iterator(); it.hasNext(); ) { Map.Entry entry = (Map.Entry) it.next(); this.put((String) entry.getKey(), entry.getValue()); } }
protected SimpleHash buildModelMap() { final SimpleHash model = new SimpleHash(); // No popups are currently used in InterProScan 5 standalone mode, only used by the InterPro web application // (through AJAX calls) model.put("standalone", false); return model; }
private SimpleHash getHash(Environment env) throws TemplateModelException { Set names = env.getKnownVariableNames(); SimpleHash simpleHash = new SimpleHash(); for(Object name: names){ simpleHash.put(name.toString(),env.getVariable(name.toString())); } return simpleHash; } }
protected Object internalPutInContext(String key, Object value) { TemplateModel model = null; try { model = getContext().get(key); } catch (TemplateModelException e) { throw new RuntimeException("Could not get key " + key, e); } getContext().put(key, value); return model; }