litesoft
@ 939
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 |
// This Source Code is in the Public Domain per: http://litesoft.org/License.txt package org.litesoft.GWT.server; import java.io.*; import javax.servlet.*; import javax.servlet.http.*; import org.litesoft.commonfoundation.typeutils.*; import org.litesoft.logger.*; import org.litesoft.reports.*; import org.litesoft.uispecification.*; public class ReportServlet extends HttpServlet { protected static Logger logger = LoggerFactory.getLogger( ReportServlet.class ); private static final long serialVersionUID = 1L; private PrintWriter responseInit( HttpServletResponse pResponse, String pTitle ) throws IOException { pResponse.setContentType( "text/html" ); PrintWriter out = pResponse.getWriter(); out.println( "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">" ); out.println( "<html>" ); out.println( " <head>" ); out.println( " <title>" + pTitle + "</title>" ); out.println( " <link rel=\"stylesheet\" type=\"text/css\" href=\"../../common/litesoft_reporting.css\" />" ); out.println( " </head>" ); out.println( " <body>" ); return out; } private void responseFini( PrintWriter pOut ) { pOut.println( " </body>" ); pOut.println( "</html>" ); pOut.flush(); pOut.close(); } /** * The doPost method of the servlet. */ @Override public void doPost( HttpServletRequest pRequest, HttpServletResponse pResponse ) throws ServletException, IOException { PrintWriter out = responseInit( pResponse, "Report" ); out.println( " Post Not Supported" ); responseFini( out ); } /** * The doGet method of the servlet. */ @Override public void doGet( HttpServletRequest pRequest, HttpServletResponse pResponse ) throws ServletException, IOException { String zPathInfo = Strings.deNull( pRequest.getPathInfo() ); ServletSessionHelper.chkInitialized(); ServletSessionHelper.callInit( pRequest.getSession( true ) ); try { PrintWriter out; ReportParamPair zPair = extractReportParamPair( zPathInfo ); String zReportID = (zPair != null) ? zPair.getReportID() : ""; String zTitle = "Report: " + zReportID; ServerReportFactory zReportFactory = ServerReportFactory.Registry.getFactory( zReportID ); if ( zReportFactory == null ) { out = responseInit( pResponse, zTitle ); out.println( " No Report for ReportID: " + zReportID ); } else { ServerReport zReport; try { zReport = zReportFactory.create( zPair.getParams() ); zTitle = zReport.pageTitle(); } catch ( RuntimeException e ) { out = responseInit( pResponse, zTitle ); e.printStackTrace( out ); responseFini( out ); return; } out = responseInit( pResponse, zTitle ); try { zReport.render( out ); } catch ( RuntimeException e ) { e.printStackTrace( out ); } } responseFini( out ); } finally { ServletSessionHelper.callFini(); } } private ReportParamPair extractReportParamPair( String pPathInfo ) { if ( pPathInfo.startsWith( "/" ) && pPathInfo.endsWith( ".html" ) ) { int zAt = pPathInfo.lastIndexOf( '/' ); if ( zAt != -1 ) { String zParams = pPathInfo.substring( 1, zAt ).trim(); String zReportID = dropWhen( pPathInfo.substring( zAt + 1, pPathInfo.length() - 5 ).trim() ); // x-1234-12-12-12-12 // 123456789012345678 if ( zReportID != null ) { return new ReportParamPair( zReportID, UriFragmentIdParams.fromParamsString( zParams ) ); } } } return null; } private String dropWhen( String pReportID ) { // x-1234-12-12-12-12 // 123456789012345678 int zWhenDashSepAt = pReportID.length() - 17; if ( (zWhenDashSepAt > 0) && validWhenTail( pReportID.substring( zWhenDashSepAt ) ) ) { return pReportID.substring( 0, zWhenDashSepAt ); } return null; } private boolean validWhenTail( String zTail ) { // ............... -1234-12-12-12-12 String zPattern = "-9999-99-99-99-99"; for ( int i = 0; i < zPattern.length(); i++ ) { char zPatternChar = zPattern.charAt( i ); char zTailChar = zTail.charAt( i ); if ( zPatternChar == '9' ) { if ( !Characters.isNumeric( zTailChar ) ) { return false; } } else if ( zPatternChar != zTailChar ) { return false; } } return true; } private static class ReportParamPair { private String mReportID; private UriFragmentIdParams mParams; private ReportParamPair( String pReportID, UriFragmentIdParams pParams ) { mReportID = pReportID; mParams = pParams; } public String getReportID() { return mReportID; } public UriFragmentIdParams getParams() { return mParams; } } } |
Commits for litesoft/trunk/Java/GWT/Server/src/org/litesoft/GWT/server/ReportServlet.java
Revision | Author | Commited | Message |
---|---|---|---|
939 Diff | GeorgeS | Mon 02 Jun, 2014 21:30:31 +0000 | Extracting commonfoundation |
811 Diff | GeorgeS | Sat 18 Aug, 2012 13:45:18 +0000 | |
802 Diff | GeorgeS | Wed 15 Aug, 2012 04:04:47 +0000 | |
49 Diff | GeorgeS | Mon 12 Apr, 2010 02:59:10 +0000 | License Text |
25 Diff | GeorgeS | Mon 01 Mar, 2010 14:09:51 +0000 | |
2 | GeorgeS | Sun 07 Feb, 2010 12:50:58 +0000 |