Example usage for com.liferay.portal.kernel.servlet PortletServlet PORTLET_SERVLET_CONFIG

List of usage examples for com.liferay.portal.kernel.servlet PortletServlet PORTLET_SERVLET_CONFIG

Introduction

In this page you can find the example usage for com.liferay.portal.kernel.servlet PortletServlet PORTLET_SERVLET_CONFIG.

Prototype

String PORTLET_SERVLET_CONFIG

To view the source code for com.liferay.portal.kernel.servlet PortletServlet PORTLET_SERVLET_CONFIG.

Click Source Link

Usage

From source file:com.liferay.mvc.freemarker.internal.FreeMarkerMVCContextHelper.java

License:Open Source License

public static void addPortletJSPTaglibSupport(FreeMarkerContext freeMarkerContext,
        PortletRequest portletRequest, PortletResponse portletResponse, Set<String> templateRegistry)
        throws Exception {

    HttpServletRequest request = PortalUtil.getHttpServletRequest(portletRequest);
    HttpServletResponse response = PortalUtil.getHttpServletResponse(portletResponse);

    FreeMarkerVariablesUtil.insertVariables(freeMarkerContext, request);

    Portlet portlet = (Portlet) request.getAttribute(WebKeys.RENDER_PORTLET);

    String servletContextName = portlet.getPortletApp().getServletContextName();

    final ServletContext servletContext = ServletContextPool.get(servletContextName);

    Object templateRegistryAttribute = servletContext.getAttribute(TEMPLATE_REGISTRY_ATTRIBUTE);

    if ((templateRegistry != null) && (templateRegistryAttribute == null)) {
        servletContext.setAttribute(TEMPLATE_REGISTRY_ATTRIBUTE, templateRegistry);
    }/*  w  ww.  ja v  a2s .  c  o m*/

    freeMarkerContext.put("fullTemplatesPath",
            StringPool.SLASH + servletContextName + FreeMarkerTemplateLoader.SERVLET_SEPARATOR);

    TemplateHashModel taglibsFactory = FreeMarkerTaglibFactoryUtil.createTaglibFactory(servletContext);

    freeMarkerContext.put("PortletJspTagLibs", taglibsFactory);

    ServletConfig servletConfig = (ServletConfig) portletRequest
            .getAttribute(PortletServlet.PORTLET_SERVLET_CONFIG);

    final PortletServlet portletServlet = new PortletServlet();

    portletServlet.init(servletConfig);

    ServletContextHashModel servletContextHashModel = new ServletContextHashModel(portletServlet,
            ObjectWrapper.DEFAULT_WRAPPER);

    freeMarkerContext.put("Application", servletContextHashModel);

    HttpRequestHashModel httpRequestHashModel = new HttpRequestHashModel(request, response,
            ObjectWrapper.DEFAULT_WRAPPER);

    freeMarkerContext.put("Request", httpRequestHashModel);
}