Search in sources :

Example 1 with StandardCompress

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

the class MacroScreenViewHandler method render.

public void render(String name, String page, String info, String contentType, String encoding, HttpServletRequest request, HttpServletResponse response) throws ViewHandlerException {
    try {
        Writer writer = response.getWriter();
        VisualTheme visualTheme = UtilHttp.getVisualTheme(request);
        ModelTheme modelTheme = visualTheme.getModelTheme();
        Delegator delegator = (Delegator) request.getAttribute("delegator");
        // compress output if configured to do so
        if (UtilValidate.isEmpty(encoding)) {
            encoding = modelTheme.getEncoding(getName());
        }
        boolean compressOutput = "compressed".equals(encoding);
        if (!compressOutput) {
            compressOutput = "true".equals(modelTheme.getCompress(getName()));
        }
        if (!compressOutput && this.servletContext != null) {
            compressOutput = "true".equals(this.servletContext.getAttribute("compressHTML"));
        }
        if (compressOutput) {
            // StandardCompress defaults to a 2k buffer. That could be increased
            // to speed up output.
            writer = new StandardCompress().getWriter(writer, null);
        }
        MapStack<String> context = MapStack.create();
        ScreenRenderer.populateContextForRequest(context, null, request, response, servletContext);
        ScreenStringRenderer screenStringRenderer = loadRenderers(request, response, context, writer);
        ScreenRenderer screens = new ScreenRenderer(writer, context, screenStringRenderer);
        context.put("screens", screens);
        context.put("simpleEncoder", UtilCodec.getEncoder(visualTheme.getModelTheme().getEncoder(getName())));
        screenStringRenderer.renderScreenBegin(writer, context);
        screens.render(page);
        screenStringRenderer.renderScreenEnd(writer, context);
        writer.flush();
    } catch (TemplateException e) {
        Debug.logError(e, "Error initializing screen renderer", module);
        throw new ViewHandlerException(e.getMessage());
    } catch (IOException e) {
        throw new ViewHandlerException("Error in the response writer/output stream: " + e.toString(), e);
    } catch (SAXException | ParserConfigurationException e) {
        throw new ViewHandlerException("XML Error rendering page: " + e.toString(), e);
    } catch (GeneralException e) {
        throw new ViewHandlerException("Lower level error rendering page: " + e.toString(), e);
    }
}
Also used : ViewHandlerException(org.apache.ofbiz.webapp.view.ViewHandlerException) GeneralException(org.apache.ofbiz.base.util.GeneralException) TemplateException(freemarker.template.TemplateException) ScreenRenderer(org.apache.ofbiz.widget.renderer.ScreenRenderer) ModelTheme(org.apache.ofbiz.widget.model.ModelTheme) IOException(java.io.IOException) ScreenStringRenderer(org.apache.ofbiz.widget.renderer.ScreenStringRenderer) SAXException(org.xml.sax.SAXException) Delegator(org.apache.ofbiz.entity.Delegator) StandardCompress(freemarker.template.utility.StandardCompress) VisualTheme(org.apache.ofbiz.widget.renderer.VisualTheme) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) Writer(java.io.Writer)

Aggregations

TemplateException (freemarker.template.TemplateException)1 StandardCompress (freemarker.template.utility.StandardCompress)1 IOException (java.io.IOException)1 Writer (java.io.Writer)1 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)1 GeneralException (org.apache.ofbiz.base.util.GeneralException)1 Delegator (org.apache.ofbiz.entity.Delegator)1 ViewHandlerException (org.apache.ofbiz.webapp.view.ViewHandlerException)1 ModelTheme (org.apache.ofbiz.widget.model.ModelTheme)1 ScreenRenderer (org.apache.ofbiz.widget.renderer.ScreenRenderer)1 ScreenStringRenderer (org.apache.ofbiz.widget.renderer.ScreenStringRenderer)1 VisualTheme (org.apache.ofbiz.widget.renderer.VisualTheme)1 SAXException (org.xml.sax.SAXException)1