Java Code Examples for freemarker.template.SimpleHash#putAll()

The following examples show how to use freemarker.template.SimpleHash#putAll() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: WrapTag.java    From javalite with Apache License 2.0 6 votes vote down vote up
public void execute(Environment env, Map params, TemplateModel[] loopVars, TemplateDirectiveBody body) throws TemplateException, IOException {
    if(!params.containsKey("with")) {
        throw new RuntimeException("\"with\" param was not provided");
    }

    String withArgument = params.get("with").toString();

    StringWriter innerContent = new StringWriter();
    body.render(innerContent);        

    SimpleHash envValues = getHash(env);
    envValues.putAll(params);
    envValues.put("page_content", innerContent.toString());
    for(Object key : params.keySet()) {
        if(key.toString().equals("with")) {
            continue;
        } else {
            envValues.put(key.toString(), params.get(key));
        }
    }

    String path = getTemplatePath(env.getTemplate().getName(), withArgument);
    Template template = env.getConfiguration().getTemplate(path + ".ftl");
    template.process(envValues, env.getOut());
}
 
Example 2
Source File: RenderComponentDirective.java    From engine with GNU General Public License v3.0 5 votes vote down vote up
protected SimpleHash getFullModel(SiteItem component, Map<String, Object> templateModel,
                                  Map<String, Object> additionalModel) throws TemplateException {
    SimpleHash model = modelFactory.getObject();
    model.put(KEY_MODEL, component);
    model.put(KEY_CONTENT_MODEL, component);

    if (MapUtils.isNotEmpty(templateModel)) {
        model.putAll(templateModel);
    }
    if (MapUtils.isNotEmpty(additionalModel)) {
        model.putAll(additionalModel);
    }

    return model;
}
 
Example 3
Source File: FreeMarkerView.java    From spring-analysis-note with MIT License 2 votes vote down vote up
/**
 * Build a FreeMarker template model for the given model Map.
 * <p>The default implementation builds a {@link SimpleHash}.
 * @param model the model to use for rendering
 * @param exchange current exchange
 * @return the FreeMarker template model, as a {@link SimpleHash} or subclass thereof
 */
protected SimpleHash getTemplateModel(Map<String, Object> model, ServerWebExchange exchange) {
	SimpleHash fmModel = new SimpleHash(getObjectWrapper());
	fmModel.putAll(model);
	return fmModel;
}
 
Example 4
Source File: FreeMarkerView.java    From java-technology-stack with MIT License 2 votes vote down vote up
/**
 * Build a FreeMarker template model for the given model Map.
 * <p>The default implementation builds a {@link SimpleHash}.
 * @param model the model to use for rendering
 * @param exchange current exchange
 * @return the FreeMarker template model, as a {@link SimpleHash} or subclass thereof
 */
protected SimpleHash getTemplateModel(Map<String, Object> model, ServerWebExchange exchange) {
	SimpleHash fmModel = new SimpleHash(getObjectWrapper());
	fmModel.putAll(model);
	return fmModel;
}