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