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));
}
}
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;
}
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;
}
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);
}
}
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;
}
Aggregations