package portal.struts.action.CCAP; import java.io.IOException; import java.io.UnsupportedEncodingException; import javax.servlet.ServletConfig; import javax.servlet.ServletException; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.eclipse.birt.core.exception.BirtException; import org.eclipse.birt.report.IBirtConstants; import org.eclipse.birt.report.service.BirtReportServiceFactory; import org.eclipse.birt.report.service.BirtViewerReportService; import org.eclipse.birt.report.servlet.BirtSoapMessageDispatcherServlet; import org.eclipse.birt.report.utility.BirtUtility; import org.eclipse.birt.report.utility.ParameterAccessor; import org.eclipse.birt.report.context.BirtContext; import org.eclipse.birt.report.context.IContext; import org.eclipse.birt.report.presentation.aggregation.IFragment; import org.eclipse.birt.report.presentation.aggregation.layout.FramesetFragment; import org.eclipse.birt.report.presentation.aggregation.layout.RunFragment; /** * Servlet implementation of BIRT Web Viewer. *
* There are four servlet mappings defined for ViewerServlet in the web.xml. *
* Each public mapping expects some URL parameters, *
* Each URL parameter is described below.
Parameter | *Description | *Values | *Default | *
__report | *The path to the report document | ** | required | *
__format | *The output format | *html or pdf | *optional, default to html | *
__locale | *Report locale | *Java locale value such as en or ch-zh. | *optional, default to JVM locale | *
__page | *Report page number | *Report page to be viewed. | *optional, default to 0 | *
reportParam | *User defined report parameter. | *As specified in the report design. | *As specified in the report design. | *
*/ public class ViewerServlet extends BirtSoapMessageDispatcherServlet { /** * TODO: what's this? */ private static final long serialVersionUID = 1L; /** * Local initialization. * * @return */ protected void __init( ServletConfig config ) { System.out.println("inside of ViewerServlet init"); BirtReportServiceFactory.init( new BirtViewerReportService( config.getServletContext( ) ) ); // handle 'frameset' pattern viewer = new FramesetFragment( ); viewer.buildComposite( ); viewer.setJSPRootPath( "/birt" ); //$NON-NLS-1$ // handle 'run' pattern run = new RunFragment( ); run.buildComposite( ); run.setJSPRootPath( "/birt" ); //$NON-NLS-1$ System.out.println("leaving init"); } /** * Init context. * * @param request * incoming http request * @param response * http response * @exception BirtException * @return IContext */ protected IContext __getContext( HttpServletRequest request, HttpServletResponse response ) throws BirtException { System.out.println("inside of ViewerServlet getContext"); BirtReportServiceFactory.getReportService( ).setContext(getServletContext( ), null ); System.out.println("about to return/leave getContext"); return new BirtContext( request, response ); } /** * Local process http request with GET method. * * @param request * incoming http request * @param response * http response * @exception ServletException * @exception IOException * @return */ protected void __doGet( IContext context ) throws ServletException, IOException, BirtException { System.out.println("inside of ViewerServlet doGet"); IFragment activeFragment = null; String servletPath = context.getRequest( ).getServletPath( ); System.out.println("before if #1 doGet"); if ( IBirtConstants.SERVLET_PATH_FRAMESET.equalsIgnoreCase( servletPath ) ) { System.out.println("in first if clause of if#1 doGet"); activeFragment = viewer; }else if ( IBirtConstants.SERVLET_PATH_RUN.equalsIgnoreCase( servletPath ) ) { System.out.println("2nd if clause of if#1 doGet"); activeFragment = run; } System.out.println("right before if#2 doGet"); if ( activeFragment != null ) { System.out.println("inside if#2 doGet"); activeFragment.service( context.getRequest( ), context.getResponse( ) ); } System.out.println("about to leave doGet"); } /** * Locale process http request with POST method. Four different servlet * paths are expected: "/frameset", "/navigation", "/toolbar", and "/run". * * @param request * incoming http request * @param response * http response * @exception ServletException * @exception IOException * @return */ protected void __doPost( IContext context ) throws ServletException, IOException, BirtException { System.out.println("inside of ViewerServlet doPost. nothing else here"); } /** * Local authentication. Always returns true. * * @param request * incoming http request * @param response * http response * @return */ protected boolean __authenticate( HttpServletRequest request, HttpServletResponse response ) { System.out.println("inside of ViewerServlet authenticate. only a return true below"); return true; } /** * Process exception for non soap request. * * @param request * incoming http request * @param response * http response * @param exception * @throws ServletException * @throws IOException */ protected void __handleNonSoapException( HttpServletRequest request, HttpServletResponse response, Exception exception ) throws ServletException, IOException { exception.printStackTrace( ); BirtUtility.appendErrorMessage( response.getOutputStream( ), exception ); } }