Search in sources :

Example 91 with TemplateModel

use of freemarker.template.TemplateModel in project ofbiz-framework by apache.

the class CatalogUrlDirective method execute.

@Override
public void execute(Environment env, Map args, TemplateModel[] loopVars, TemplateDirectiveBody body) throws TemplateException, IOException {
    Map<String, TemplateModel> params = UtilGenerics.checkMap(args);
    String productId = (String) DeepUnwrap.unwrap(params.get("productId"));
    String currentCategoryId = (String) DeepUnwrap.unwrap(params.get("currentCategoryId"));
    String previousCategoryId = (String) DeepUnwrap.unwrap(params.get("previousCategoryId"));
    BeanModel req = (BeanModel) env.getVariable("request");
    if (req != null) {
        HttpServletRequest request = (HttpServletRequest) req.getWrappedObject();
        env.getOut().write(CatalogUrlServlet.makeCatalogUrl(request, productId, currentCategoryId, previousCategoryId));
    }
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) BeanModel(freemarker.ext.beans.BeanModel) TemplateModel(freemarker.template.TemplateModel)

Example 92 with TemplateModel

use of freemarker.template.TemplateModel in project openj9 by eclipse.

the class UMA method get.

public TemplateModel get(String arg0) throws TemplateModelException {
    if (arg0.equals("spec")) {
        return new Spec();
    }
    if (arg0.equals("year")) {
        GregorianCalendar calendar = new GregorianCalendar();
        return new SimpleScalar(Integer.toString(calendar.get(Calendar.YEAR)));
    }
    try {
        TemplateModel platformExtension = com.ibm.uma.UMA.getUma().getPlatform().getDataModelExtension(com.ibm.uma.UMA.FREEMARKER_UMA, arg0);
        if (platformExtension != null)
            return platformExtension;
        TemplateModel configurationExtension = com.ibm.uma.UMA.getUma().getConfiguration().getDataModelExtension(com.ibm.uma.UMA.FREEMARKER_UMA, arg0);
        if (configurationExtension != null)
            return configurationExtension;
    } catch (UMAException e) {
        throw new TemplateModelException(e);
    }
    return null;
}
Also used : TemplateModelException(freemarker.template.TemplateModelException) GregorianCalendar(java.util.GregorianCalendar) TemplateModel(freemarker.template.TemplateModel) UMAException(com.ibm.uma.UMAException) SimpleScalar(freemarker.template.SimpleScalar)

Example 93 with TemplateModel

use of freemarker.template.TemplateModel in project entando-core by entando.

the class ControllerServlet method createModel.

@Override
protected TemplateModel createModel(ObjectWrapper wrapper, ServletContext servletContext, HttpServletRequest request, HttpServletResponse response) throws TemplateModelException {
    TemplateModel template = super.createModel(wrapper, servletContext, request, response);
    if (template instanceof AllHttpScopesHashModel) {
        AllHttpScopesHashModel hashModel = ((AllHttpScopesHashModel) template);
        ServletContextHashModel servletContextModel = (ServletContextHashModel) hashModel.get(KEY_APPLICATION);
        if (null == servletContextModel.getServlet()) {
            ServletContextHashModel newServletContextModel = new ServletContextHashModel(this, wrapper);
            servletContextModel = new ServletContextHashModel(this, wrapper);
            servletContext.setAttribute(ATTR_APPLICATION_MODEL, servletContextModel);
            TaglibFactory taglibs = new TaglibFactory(servletContext);
            servletContext.setAttribute(ATTR_JSP_TAGLIBS_MODEL, taglibs);
            hashModel.putUnlistedModel(KEY_APPLICATION, newServletContextModel);
            hashModel.putUnlistedModel(KEY_APPLICATION_PRIVATE, newServletContextModel);
        }
    }
    return template;
}
Also used : AllHttpScopesHashModel(freemarker.ext.servlet.AllHttpScopesHashModel) ServletContextHashModel(freemarker.ext.servlet.ServletContextHashModel) TaglibFactory(freemarker.ext.jsp.TaglibFactory) TemplateModel(freemarker.template.TemplateModel)

Example 94 with TemplateModel

use of freemarker.template.TemplateModel in project entando-core by entando.

the class AbstractTestExecutorService method setUp.

@Override
protected void setUp() throws Exception {
    super.setUp();
    try {
        Configuration config = new Configuration();
        DefaultObjectWrapper wrapper = new DefaultObjectWrapper();
        config.setTemplateExceptionHandler(TemplateExceptionHandler.HTML_DEBUG_HANDLER);
        config.setObjectWrapper(wrapper);
        config.setTemplateExceptionHandler(TemplateExceptionHandler.DEBUG_HANDLER);
        TemplateModel templateModel = this.createModel(wrapper);
        ExecutorBeanContainer ebc = new ExecutorBeanContainer(config, templateModel);
        super.getRequestContext().addExtraParam(SystemConstants.EXTRAPAR_EXECUTOR_BEAN_CONTAINER, ebc);
    } catch (Throwable t) {
        throw new Exception(t);
    }
}
Also used : Configuration(freemarker.template.Configuration) DefaultObjectWrapper(freemarker.template.DefaultObjectWrapper) TemplateModel(freemarker.template.TemplateModel) ExecutorBeanContainer(org.entando.entando.aps.system.services.controller.executor.ExecutorBeanContainer)

Example 95 with TemplateModel

use of freemarker.template.TemplateModel in project be5 by DevelopmentOnTheEdge.

the class Environment method getNodeProcessor.

private TemplateModel getNodeProcessor(Namespace ns, String localName, String nsURI) throws TemplateException {
    TemplateModel result = null;
    if (nsURI == null) {
        result = ns.get(localName);
        if (!(result instanceof Macro) && !(result instanceof TemplateTransformModel)) {
            result = null;
        }
    } else {
        Template template = ns.getTemplate();
        String prefix = template.getPrefixForNamespace(nsURI);
        if (prefix == null) {
            // since it has no prefix registered for the namespace
            return null;
        }
        if (prefix.length() > 0) {
            result = ns.get(prefix + ":" + localName);
            if (!(result instanceof Macro) && !(result instanceof TemplateTransformModel)) {
                result = null;
            }
        } else {
            if (nsURI.length() == 0) {
                result = ns.get(Template.NO_NS_PREFIX + ":" + localName);
                if (!(result instanceof Macro) && !(result instanceof TemplateTransformModel)) {
                    result = null;
                }
            }
            if (nsURI.equals(template.getDefaultNS())) {
                result = ns.get(Template.DEFAULT_NAMESPACE_PREFIX + ":" + localName);
                if (!(result instanceof Macro) && !(result instanceof TemplateTransformModel)) {
                    result = null;
                }
            }
            if (result == null) {
                result = ns.get(localName);
                if (!(result instanceof Macro) && !(result instanceof TemplateTransformModel)) {
                    result = null;
                }
            }
        }
    }
    return result;
}
Also used : TemplateTransformModel(freemarker.template.TemplateTransformModel) TemplateModel(freemarker.template.TemplateModel) Template(freemarker.template.Template)

Aggregations

TemplateModel (freemarker.template.TemplateModel)108 TemplateModelException (freemarker.template.TemplateModelException)26 Map (java.util.Map)23 TemplateScalarModel (freemarker.template.TemplateScalarModel)18 Test (org.junit.Test)17 ArrayList (java.util.ArrayList)15 TemplateException (freemarker.template.TemplateException)13 HashMap (java.util.HashMap)13 SimpleScalar (freemarker.template.SimpleScalar)11 IOException (java.io.IOException)11 List (java.util.List)11 Template (freemarker.template.Template)9 TemplateSequenceModel (freemarker.template.TemplateSequenceModel)8 TemplateTransformModel (freemarker.template.TemplateTransformModel)8 SimpleHash (freemarker.template.SimpleHash)7 SimpleSequence (freemarker.template.SimpleSequence)7 Writer (java.io.Writer)7 Iterator (java.util.Iterator)7 Environment (freemarker.core.Environment)6 TemplateHashModel (freemarker.template.TemplateHashModel)6