01: /*
02: * $Id: JPublishViewHandler.java,v 1.2 2003/08/19 20:54:08 jonesde Exp $
03: *
04: * Copyright (c) 2003 The Open For Business Project - www.ofbiz.org
05: *
06: * Permission is hereby granted, free of charge, to any person obtaining a
07: * copy of this software and associated documentation files (the "Software"),
08: * to deal in the Software without restriction, including without limitation
09: * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10: * and/or sell copies of the Software, and to permit persons to whom the
11: * Software is furnished to do so, subject to the following conditions:
12: *
13: * The above copyright notice and this permission notice shall be included
14: * in all copies or substantial portions of the Software.
15: *
16: * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
17: * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18: * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19: * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
20: * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT
21: * OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR
22: * THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23: *
24: */
25: package org.ofbiz.content.webapp.view;
26:
27: import java.io.IOException;
28: import java.io.Writer;
29:
30: import javax.servlet.ServletContext;
31: import javax.servlet.http.HttpServletRequest;
32: import javax.servlet.http.HttpServletResponse;
33:
34: import org.ofbiz.base.util.GeneralException;
35:
36: /**
37: * Handles JPublish type view rendering
38: *
39: * @author <a href="mailto:jaz@ofbiz.org">Andy Zeneski</a>
40: * @version $Revision: 1.2 $
41: * @since 2.1
42: */
43: public class JPublishViewHandler implements ViewHandler {
44:
45: public static final String module = JPublishViewHandler.class
46: .getName();
47:
48: protected ServletContext servletContext = null;
49: protected JPublishWrapper wrapper = null;
50:
51: /**
52: * @see org.ofbiz.content.webapp.view.ViewHandler#init(javax.servlet.ServletContext)
53: */
54: public void init(ServletContext context)
55: throws ViewHandlerException {
56: this .servletContext = context;
57: this .wrapper = (JPublishWrapper) context
58: .getAttribute("jpublishWrapper");
59: if (wrapper == null)
60: throw new ViewHandlerException(
61: "JPublishWrapper not found in ServletContext");
62: }
63:
64: /**
65: * @see org.ofbiz.content.webapp.view.ViewHandler#render(java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String, javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
66: */
67: public void render(String name, String page, String info,
68: String contentType, String encoding,
69: HttpServletRequest request, HttpServletResponse response)
70: throws ViewHandlerException {
71: try {
72: // Jetty throws IllegalStateException when doing response.getOutputStream()
73: // this is only used for static content, why would we use JP for static content?
74: Writer writer = response.getWriter();
75: wrapper.render(page, request, response, writer, null, true);
76: writer.close();
77: } catch (IOException e) {
78: throw new ViewHandlerException(
79: "Problems with the response writer/output stream",
80: e);
81: } catch (GeneralException e) {
82: throw new ViewHandlerException("Cannot render page", e);
83: }
84:
85: }
86: }
|