protected Configuration createConfiguration() throws TemplateException { return FreemarkerManager.getInstance().getConfiguration(getServletContext()); }
protected BeansWrapper getObjectWrapper() { return new WebWorkBeanWrapper(); }
public TemplateModel create(Object object, ObjectWrapper wrapper) { return new FriendlyMapModel((Map) object, (BeansWrapper) wrapper); } };
public SimpleHash buildTemplateModel(OgnlValueStack stack, Object action, ServletContext servletContext, HttpServletRequest request, HttpServletResponse response, ObjectWrapper wrapper) { ScopesHashModel model = buildScopesHashModel(servletContext, request, response, wrapper, stack); populateContext(model, stack, action, request, response); model.put("ww", new WebWorkModels(stack, request, response)); if (Configuration.isSet(WebWorkConstants.WEBWORK_FREEMARKER_SITEMESH_APPLY_DECORATOR_TRANSFORM)) { if ("true".equals(Configuration.get(WebWorkConstants.WEBWORK_FREEMARKER_SITEMESH_APPLY_DECORATOR_TRANSFORM))) { model.put("sitemesh", new SitemeshModel(stack, request, response)); } } return model; } }
/** * This method is called from {@link #doExecute(String, ActionInvocation)} to obtain the * FreeMarker configuration object that this result will use for template loading. This is a * hook that allows you to custom-configure the configuration object in a subclass, or to fetch * it from an IoC container. * <p/> * <b> * The default implementation obtains the configuration from the ConfigurationManager instance. * </b> */ protected Configuration getConfiguration() throws TemplateException { return FreemarkerManager.getInstance().getConfiguration(ServletActionContext.getServletContext()); }
protected TemplateModel createModel(ObjectWrapper wrapper, ServletContext servletContext, HttpServletRequest request, HttpServletResponse response) throws TemplateModelException { OgnlValueStack stack = ServletActionContext.getContext().getValueStack(); Object action = null; if (ServletActionContext.getContext().getActionInvocation() != null) { action = ServletActionContext.getContext().getActionInvocation().getAction(); } TemplateModel model = FreemarkerManager.getInstance().buildTemplateModel(stack, action, servletContext, request, response, wrapper); return model; }
/** * Create the instance of the freemarker Configuration object. * <p/> * this implementation * <ul> * <li>obtains the default configuration from Configuration.getDefaultConfiguration() * <li>sets up template loading from a ClassTemplateLoader and a WebappTemplateLoader * <li>sets up the object wrapper to be the BeansWrapper * <li>loads settings from the classpath file /freemarker.properties * </ul> * * @param servletContext */ protected freemarker.template.Configuration createConfiguration(ServletContext servletContext) throws TemplateException { freemarker.template.Configuration configuration = new freemarker.template.Configuration(); configuration.setTemplateLoader(getTemplateLoader(servletContext)); configuration.setTemplateExceptionHandler(TemplateExceptionHandler.HTML_DEBUG_HANDLER); configuration.setObjectWrapper(getObjectWrapper()); if (Configuration.isSet(WebWorkConstants.WEBWORK_I18N_ENCODING)) { configuration.setDefaultEncoding(Configuration.getString(WebWorkConstants.WEBWORK_I18N_ENCODING)); } loadSettings(servletContext, configuration); return configuration; }
/** * Create a Freemarker's Model through {@link FreemarkerManager#buildTemplateModel(OgnlValueStack, Object, ServletContext, HttpServletRequest, HttpServletResponse, ObjectWrapper)}. * * @return * @throws TemplateException */ protected SimpleHash createModel() throws TemplateException { FreemarkerManager freemarkerManager = FreemarkerManager.getInstance(); ActionInvocation invocation = ActionContext.getContext().getActionInvocation(); ServletContext servletContext = JspSupportServlet.jspSupportServlet.getServletContext(); OgnlValueStack stack = ActionContext.getContext().getValueStack(); ObjectWrapper wrapper = freemarkerManager.getConfiguration(servletContext).getObjectWrapper(); Object action = null; if(invocation!= null ) action = invocation.getAction(); //Added for NullPointException return freemarkerManager.buildTemplateModel(stack, action, servletContext, request, response, wrapper); } }
public void populateContext(ScopesHashModel model, OgnlValueStack stack, Object action, HttpServletRequest request, HttpServletResponse response) { // put the same objects into the context that the velocity result uses Map standard = ContextUtil.getStandardContext(stack, request, response); model.putAll(standard); // support for JSP exception pages, exposing the servlet or JSP exception Throwable exception = (Throwable) request.getAttribute("javax.servlet.error.exception"); if (exception == null) { exception = (Throwable) request.getAttribute("javax.servlet.error.JspException"); } if (exception != null) { model.put(KEY_EXCEPTION, exception); } }
/** * Execute this result, using the specified template location. <p/>The * template location has already been interoplated for any variable * substitutions <p/>this method obtains the freemarker configuration and * the object wrapper from the provided hooks. It them implements the * template processing workflow by calling the hooks for preTemplateProcess * and postTemplateProcess */ public void doExecute(String location, ActionInvocation invocation) throws IOException, TemplateException, PortletException { if (PortletActionContext.isEvent()) { executeActionResult(location, invocation); } else if (PortletActionContext.isRender()) { executeRenderResult(location, invocation); } }
final public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { request.setAttribute("webwork.freemarker.servlet", this); process(request, response); }
public void init() throws ServletException { try { configuration = createConfiguration(); } catch (TemplateException e) { throw new ServletException("could not configure Freemarker", e); } }
public final synchronized freemarker.template.Configuration getConfiguration(ServletContext servletContext) throws TemplateException { freemarker.template.Configuration config = (freemarker.template.Configuration) servletContext.getAttribute(CONFIG_SERVLET_CONTEXT_KEY); if (config == null) { config = createConfiguration(servletContext); // store this configuration in the servlet context servletContext.setAttribute(CONFIG_SERVLET_CONTEXT_KEY, config); } config.setWhitespaceStripping(true); return config; }
public TemplateModel wrap(Object object) throws TemplateModelException { if (object instanceof TemplateBooleanModel) { return super.wrap(object); } // attempt to get the best of both the SimpleMapModel and the MapModel of FM. if (altMapWrapper && object instanceof Map) { return getInstance(object, FriendlyMapModel.FACTORY); } return super.wrap(object); }
attrContentType.toString()); } else { String contentType = getContentType();
/** * This method is called from {@link #doExecute(String, ActionInvocation)} * to obtain the FreeMarker configuration object that this result will use * for template loading. This is a hook that allows you to custom-configure * the configuration object in a subclass, or to fetch it from an IoC * container. <p/><b>The default implementation obtains the configuration * from the ConfigurationManager instance. </b> */ protected Configuration getConfiguration() throws TemplateException { return FreemarkerManager.getInstance().getConfiguration( ServletActionContext.getServletContext()); }
/** * Build the instance of the ScopesHashModel, including JspTagLib support * <p/>Objects added to the model are <p/> * <ul> * <li>Application - servlet context attributes hash model * <li>JspTaglibs - jsp tag lib factory model * <li>Request - request attributes hash model * <li>Session - session attributes hash model * <li>req - the HttpServletRequst object for direct access * <li>res - the HttpServletResponse object for direct access * <li>stack - the OgnLValueStack instance for direct access * <li>ognl - the instance of the OgnlTool * <li>action - the action itself * <li>exception - optional : the JSP or Servlet exception as per the * servlet spec (for JSP Exception pages) * <li>webwork - instance of the WebWorkUtil class * </ul> */ protected TemplateModel createModel() throws TemplateModelException { ServletContext servletContext = ServletActionContext .getServletContext(); HttpServletRequest request = ServletActionContext.getRequest(); HttpServletResponse response = ServletActionContext.getResponse(); OgnlValueStack stack = ServletActionContext.getContext() .getValueStack(); return FreemarkerManager.getInstance().buildTemplateModel(stack, invocation.getAction(), servletContext, request, response, wrapper); }
final public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { request.setAttribute("webwork.freemarker.servlet", this); process(request, response); }
/** * Method Hook: <p/> * Returns a Freemarker's Template bsaed on the <code>templatePath</code> * supplied. * * @param templatePath * @return * @throws IOException * @throws TemplateException */ protected Template getFreemarkerTemplate(String templatePath) throws IOException, TemplateException { FreemarkerManager freemarkerManager = FreemarkerManager.getInstance(); Configuration configuration = freemarkerManager.getConfiguration(JspSupportServlet.jspSupportServlet.getServletContext()); return configuration.getTemplate(templatePath); }
/** * Build the instance of the ScopesHashModel, including JspTagLib support * <p/> * Objects added to the model are * <p/> * <ul> * <li>Application - servlet context attributes hash model * <li>JspTaglibs - jsp tag lib factory model * <li>Request - request attributes hash model * <li>Session - session attributes hash model * <li>req - the HttpServletRequst object for direct access * <li>res - the HttpServletResponse object for direct access * <li>stack - the OgnLValueStack instance for direct access * <li>ognl - the instance of the OgnlTool * <li>action - the action itself * <li>exception - optional : the JSP or Servlet exception as per the servlet spec (for JSP Exception pages) * <li>webwork - instance of the WebWorkUtil class * </ul> */ protected TemplateModel createModel() throws TemplateModelException { ServletContext servletContext = ServletActionContext.getServletContext(); HttpServletRequest request = ServletActionContext.getRequest(); HttpServletResponse response = ServletActionContext.getResponse(); OgnlValueStack stack = ServletActionContext.getContext().getValueStack(); Object action = null; if(invocation!= null ) action = invocation.getAction(); //Added for NullPointException return FreemarkerManager.getInstance().buildTemplateModel(stack, action, servletContext, request, response, wrapper); }