List of usage examples for javax.servlet.jsp PageContext getResponse
abstract public ServletResponse getResponse();
From source file:org.apache.struts2.components.template.JspTemplateEngine.java
public void renderTemplate(TemplateRenderingContext templateContext) throws Exception { Template template = templateContext.getTemplate(); if (LOG.isDebugEnabled()) { LOG.debug("Trying to render template " + template + ", repeating through parents until we succeed"); }// w w w . j ava 2 s .co m UIBean tag = templateContext.getTag(); ValueStack stack = templateContext.getStack(); stack.push(tag); PageContext pageContext = (PageContext) stack.getContext().get(ServletActionContext.PAGE_CONTEXT); List templates = template.getPossibleTemplates(this); Exception exception = null; boolean success = false; for (Iterator iterator = templates.iterator(); iterator.hasNext();) { Template t = (Template) iterator.next(); try { Include.include(getFinalTemplateName(t), pageContext.getOut(), pageContext.getRequest(), (HttpServletResponse) pageContext.getResponse()); success = true; break; } catch (Exception e) { if (exception == null) { exception = e; } } } if (!success) { LOG.error("Could not render JSP template " + templateContext.getTemplate()); if (exception != null) { throw exception; } else { return; } } stack.pop(); }
From source file:org.apache.tiles.jsp.context.JspTilesRequestContext.java
/** * Constructor.//from w w w . j a v a 2 s.c o m * * @param context The servlet context to use. * @param pageContext The page context to use. */ public JspTilesRequestContext(ServletContext context, PageContext pageContext) { super(context, (HttpServletRequest) pageContext.getRequest(), (HttpServletResponse) pageContext.getResponse()); this.pageContext = pageContext; }
From source file:org.jahia.taglibs.template.include.OptionTag.java
public static void renderNodeWithViewAndTypes(JCRNodeWrapper node, String view, String commaConcatenatedNodeTypes, PageContext pageContext, Map<String, String> parameters) throws RepositoryException, IOException, RenderException { String charset = pageContext.getResponse().getCharacterEncoding(); // Todo test if module is active RenderContext renderContext = (RenderContext) pageContext.getAttribute("renderContext", PageContext.REQUEST_SCOPE);/* w w w.j av a 2s.co m*/ Resource currentResource = (Resource) pageContext.getAttribute("currentResource", PageContext.REQUEST_SCOPE); String[] nodeTypes = StringUtils.split(commaConcatenatedNodeTypes, ","); if (nodeTypes.length > 0) { final String primaryNodeType = nodeTypes[0]; if (node.isNodeType(primaryNodeType)) { ExtendedNodeType mixinNodeType = NodeTypeRegistry.getInstance().getNodeType(primaryNodeType); // create a resource to render the current node with the specified view Resource wrappedResource = new Resource(node, currentResource.getTemplateType(), view, Resource.CONFIGURATION_INCLUDE); wrappedResource.setResourceNodeType(mixinNodeType); // set parameters for (Map.Entry<String, String> param : parameters.entrySet()) { wrappedResource.getModuleParams().put(URLDecoder.decode(param.getKey(), charset), URLDecoder.decode(param.getValue(), charset)); } // attempt to resolve script for the newly created resource Script script = null; try { script = RenderService.getInstance().resolveScript(wrappedResource, renderContext); } catch (RepositoryException e) { logger.error(e.getMessage(), e); } catch (TemplateNotFoundException e) { // if we didn't find a script, attempt to locate one based on secondary node type if one was specified if (nodeTypes.length > 1) { mixinNodeType = NodeTypeRegistry.getInstance().getNodeType(nodeTypes[1]); wrappedResource.setResourceNodeType(mixinNodeType); script = RenderService.getInstance().resolveScript(wrappedResource, renderContext); } } // if we have found a script, render it if (script != null) { final ServletRequest request = pageContext.getRequest(); //save environment Object currentNode = request.getAttribute("currentNode"); Resource currentOption = (Resource) request.getAttribute("optionResource"); // set attributes to render the newly created resource request.setAttribute("optionResource", currentResource); request.setAttribute("currentNode", node); request.setAttribute("currentResource", wrappedResource); try { pageContext.getOut().write(script.execute(wrappedResource, renderContext)); } finally { // restore environment as it previously was request.setAttribute("optionResource", currentOption); request.setAttribute("currentNode", currentNode); request.setAttribute("currentResource", currentResource); } } } } }