⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 sfajasperviewhandler.java

📁 国外的一套开源CRM
💻 JAVA
字号:
/*
 * 
 * Copyright (c) 2004 SourceTap - www.sourcetap.com
 *
 *  The contents of this file are subject to the SourceTap Public License 
 * ("License"); You may not use this file except in compliance with the 
 * License. You may obtain a copy of the License at http://www.sourcetap.com/license.htm
 * Software distributed under the License is distributed on an  "AS IS"  basis,
 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
 * the specific language governing rights and limitations under the License.
 *
 * The above copyright notice and this permission notice shall be included
 * in all copies or substantial portions of the Software.
 *
 */


/**
 * SFAJasperViewHandler - View Handler for Jasper PDF files.  same as JSPViewHandler, except it calls forward, not include
 *
 *@author     <a href="mailto:jaz@zsolv.com">Andy Zeneski</a>
 *@created    Feb 26, 2002
 *@version    1.0
 */
package com.sourcetap.sfa.view;

import java.io.IOException;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.jsp.JspException;

import org.ofbiz.base.util.Debug;
import org.ofbiz.content.webapp.view.ViewHandler;
import org.ofbiz.content.webapp.view.ViewHandlerException;


/**
 * DOCUMENT ME!
 *
 */
public class SFAJasperViewHandler implements ViewHandler {
    protected ServletContext context;

    /**
     * DOCUMENT ME!
     *
     * @param context 
     *
     * @throws ViewHandlerException 
     */
    public void init(ServletContext context) throws ViewHandlerException {
        this.context = context;
    }

    /**
     * DOCUMENT ME!
     *
     * @param name 
     * @param page 
     * @param info 
     * @param request 
     * @param response 
     *
     * @throws ViewHandlerException 
     */
    public void render(String name, String page, String info, String contentType, String encoding,
        HttpServletRequest request, HttpServletResponse response)
        throws ViewHandlerException {
        // some containers call filters on EVERY request, even forwarded ones,
        // so let it know that it came from the control servlet
        if (request == null) {
            throw new ViewHandlerException("Null HttpServletRequest object");
        }

        if ((page == null) || (page.length() == 0)) {
            throw new ViewHandlerException("Null or empty source");
        }

        request.setAttribute("_FORWARDED_FROM_CONTROL_SERVLET_",
            new Boolean(true));

        RequestDispatcher rd = request.getRequestDispatcher(page);

        if (rd == null) {
            throw new ViewHandlerException(
                "Source returned a null dispatcher (" + page + ")");
        }

        try {
            rd.forward(request, response);
        } catch (IOException ie) {
            throw new ViewHandlerException("IO Error in view", ie);
        } catch (ServletException e) {
            Throwable throwable = (e.getRootCause() != null) ? e.getRootCause()
                                                             : e;

            if (throwable instanceof JspException) {
                JspException jspe = (JspException) throwable;

                throwable = (jspe.getRootCause() != null) ? jspe.getRootCause()
                                                          : jspe;
            }

            Debug.logError(throwable, "ServletException rendering JSP view");
            throw new ViewHandlerException(e.getMessage(), throwable);
        }
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -