001: /*
002: *
003: * Copyright (c) 2004 SourceTap - www.sourcetap.com
004: *
005: * The contents of this file are subject to the SourceTap Public License
006: * ("License"); You may not use this file except in compliance with the
007: * License. You may obtain a copy of the License at http://www.sourcetap.com/license.htm
008: * Software distributed under the License is distributed on an "AS IS" basis,
009: * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
010: * the specific language governing rights and limitations under the License.
011: *
012: * The above copyright notice and this permission notice shall be included
013: * in all copies or substantial portions of the Software.
014: *
015: */
016:
017: /**
018: * SFAJasperViewHandler - View Handler for Jasper PDF files. same as JSPViewHandler, except it calls forward, not include
019: *
020: *@author <a href="mailto:jaz@zsolv.com">Andy Zeneski</a>
021: *@created Feb 26, 2002
022: *@version 1.0
023: */package com.sourcetap.sfa.view;
024:
025: import java.io.IOException;
026:
027: import javax.servlet.RequestDispatcher;
028: import javax.servlet.ServletContext;
029: import javax.servlet.ServletException;
030: import javax.servlet.http.HttpServletRequest;
031: import javax.servlet.http.HttpServletResponse;
032: import javax.servlet.jsp.JspException;
033:
034: import org.ofbiz.base.util.Debug;
035: import org.ofbiz.content.webapp.view.ViewHandler;
036: import org.ofbiz.content.webapp.view.ViewHandlerException;
037:
038: /**
039: * DOCUMENT ME!
040: *
041: */
042: public class SFAJasperViewHandler implements ViewHandler {
043: protected ServletContext context;
044:
045: /**
046: * DOCUMENT ME!
047: *
048: * @param context
049: *
050: * @throws ViewHandlerException
051: */
052: public void init(ServletContext context)
053: throws ViewHandlerException {
054: this .context = context;
055: }
056:
057: /**
058: * DOCUMENT ME!
059: *
060: * @param name
061: * @param page
062: * @param info
063: * @param request
064: * @param response
065: *
066: * @throws ViewHandlerException
067: */
068: public void render(String name, String page, String info,
069: String contentType, String encoding,
070: HttpServletRequest request, HttpServletResponse response)
071: throws ViewHandlerException {
072: // some containers call filters on EVERY request, even forwarded ones,
073: // so let it know that it came from the control servlet
074: if (request == null) {
075: throw new ViewHandlerException(
076: "Null HttpServletRequest object");
077: }
078:
079: if ((page == null) || (page.length() == 0)) {
080: throw new ViewHandlerException("Null or empty source");
081: }
082:
083: request.setAttribute("_FORWARDED_FROM_CONTROL_SERVLET_",
084: new Boolean(true));
085:
086: RequestDispatcher rd = request.getRequestDispatcher(page);
087:
088: if (rd == null) {
089: throw new ViewHandlerException(
090: "Source returned a null dispatcher (" + page + ")");
091: }
092:
093: try {
094: rd.forward(request, response);
095: } catch (IOException ie) {
096: throw new ViewHandlerException("IO Error in view", ie);
097: } catch (ServletException e) {
098: Throwable throwable = (e.getRootCause() != null) ? e
099: .getRootCause() : e;
100:
101: if (throwable instanceof JspException) {
102: JspException jspe = (JspException) throwable;
103:
104: throwable = (jspe.getRootCause() != null) ? jspe
105: .getRootCause() : jspe;
106: }
107:
108: Debug.logError(throwable,
109: "ServletException rendering JSP view");
110: throw new ViewHandlerException(e.getMessage(), throwable);
111: }
112: }
113: }
|