01: /******************************************************************************
02: * JBoss, a division of Red Hat *
03: * Copyright 2006, Red Hat Middleware, LLC, and individual *
04: * contributors as indicated by the @authors tag. See the *
05: * copyright.txt in the distribution for a full listing of *
06: * individual contributors. *
07: * *
08: * This is free software; you can redistribute it and/or modify it *
09: * under the terms of the GNU Lesser General Public License as *
10: * published by the Free Software Foundation; either version 2.1 of *
11: * the License, or (at your option) any later version. *
12: * *
13: * This software is distributed in the hope that it will be useful, *
14: * but WITHOUT ANY WARRANTY; without even the implied warranty of *
15: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
16: * Lesser General Public License for more details. *
17: * *
18: * You should have received a copy of the GNU Lesser General Public *
19: * License along with this software; if not, write to the Free *
20: * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
21: * 02110-1301 USA, or see the FSF site: http://www.fsf.org. *
22: ******************************************************************************/package org.jboss.portal.core.theme;
23:
24: import org.jboss.portal.common.util.MarkupInfo;
25: import org.jboss.portal.core.controller.ControllerResponse;
26: import org.jboss.portal.theme.PageService;
27: import org.jboss.portal.theme.PortalLayout;
28: import org.jboss.portal.theme.PortalTheme;
29: import org.jboss.portal.theme.page.PageResult;
30: import org.jboss.portal.theme.render.RenderException;
31: import org.jboss.portal.theme.render.RendererContext;
32: import org.jboss.portal.theme.render.ThemeContext;
33: import org.jboss.portal.web.ServletContextDispatcher;
34:
35: import javax.servlet.ServletException;
36: import java.io.IOException;
37:
38: /**
39: * Should not be a controller response, but it comes from legacy design.
40: *
41: * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
42: * @version $Revision: 8786 $
43: */
44: public class PageRendition extends ControllerResponse {
45:
46: /** . */
47: private PortalLayout layout;
48:
49: /** . */
50: private PageResult pageResult;
51:
52: /** . */
53: private PortalTheme theme;
54:
55: /** . */
56: private PageService pageService;
57:
58: public PageRendition(PortalLayout layout, PortalTheme theme,
59: PageResult markupResult, PageService pageService) {
60: this .layout = layout;
61: this .theme = theme;
62: this .pageResult = markupResult;
63: this .pageService = pageService;
64: }
65:
66: /** Performs the page rendition. */
67: public void render(MarkupInfo markupInfo,
68: ServletContextDispatcher dispatcher) throws IOException,
69: ServletException {
70: // Compute correct content type response header
71: // String contentType = rendererContext.getContentType() + "; charset=" + rendererContext.getCharset();
72: String contentType = markupInfo.getContentType() + "; charset="
73: + markupInfo.getCharset();
74:
75: // Set charset and content type on the response
76: dispatcher.getResponse().setContentType(contentType);
77: dispatcher.getResponse().setCharacterEncoding(
78: markupInfo.getCharset());
79:
80: //
81: ThemeContext themeContext = new ThemeContext(theme, pageService
82: .getThemeService());
83:
84: //
85: RendererContext rendererContext = layout.getRenderContext(
86: themeContext, markupInfo, dispatcher);
87:
88: //
89: try {
90: rendererContext.render(pageResult);
91: } catch (RenderException e) {
92: e.printStackTrace();
93: }
94: }
95:
96: public PageResult getPageResult() {
97: return pageResult;
98: }
99: }
|