Example usage for com.liferay.portal.kernel.servlet JSPSupportServlet JSPSupportServlet

List of usage examples for com.liferay.portal.kernel.servlet JSPSupportServlet JSPSupportServlet

Introduction

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

Prototype

public JSPSupportServlet(ServletContext servletContext) 

Source Link

Usage

From source file:com.liferay.faces.bridge.ext.context.internal.HeadResponseWriterLiferayImpl.java

License:Open Source License

@Override
protected void addResourceToHeadSection(Element element, String nodeName) throws IOException {

    // Get the underlying HttpServletRequest and HttpServletResponse
    FacesContext facesContext = FacesContext.getCurrentInstance();
    ExternalContext externalContext = facesContext.getExternalContext();
    PortletRequest portletRequest = (PortletRequest) externalContext.getRequest();
    HttpServletRequest httpServletRequest = PortalUtil.getHttpServletRequest(portletRequest);
    PortletResponse portletResponse = (PortletResponse) externalContext.getResponse();
    HttpServletResponse httpServletResponse = PortalUtil.getHttpServletResponse(portletResponse);

    // Invoke the Liferay HtmlTopTag class directly (rather than using liferay-util:html-top from a JSP).
    HtmlTopTag htmlTopTag = new HtmlTopTag();
    JspFactory jspFactory = JspFactory.getDefaultFactory();
    ServletContext servletContext = getServletContext(httpServletRequest);
    JSPSupportServlet jspSupportServlet = new JSPSupportServlet(servletContext);
    PageContext pageContext = jspFactory.getPageContext(jspSupportServlet, httpServletRequest,
            httpServletResponse, null, false, 0, false);
    htmlTopTag.setPageContext(pageContext);
    htmlTopTag.doStartTag();//from w  w  w.j a v  a 2s  .  co  m

    String elementAsString = element.toString();
    BodyContent bodyContent = pageContext.pushBody();
    bodyContent.print(elementAsString);
    htmlTopTag.setBodyContent(bodyContent);

    try {
        htmlTopTag.doEndTag();
    } catch (Exception e) {
        throw new IOException(e.getMessage());
    }

    jspFactory.releasePageContext(pageContext);
    logger.debug(ADDED_RESOURCE_TO_HEAD, "Liferay", nodeName);
}