|
@@ -73,28 +73,6 @@ |
73 |
73 |
|
public void init( FilterConfig filterConfig ) |
74 |
74 |
|
throws ServletException |
75 |
75 |
|
{ |
76 |
|
- |
// if ( !Configuration.isInstantiated() ) |
77 |
|
- |
// { |
78 |
|
- |
// new ServerConfiguration( new MapConfigDataAccessorFactory( "No Config File - Testing?", IMAGES_BASE_PATH, "/TestImages" ) ); |
79 |
|
- |
// } |
80 |
|
- |
// String zImagesBasePath = Configuration.getStringRequired( IMAGES_BASE_PATH ); |
81 |
|
- |
// File zDir = new File( zImagesBasePath ); |
82 |
|
- |
// if ( !zDir.exists() ) |
83 |
|
- |
// { |
84 |
|
- |
// if ( !zDir.mkdir() ) |
85 |
|
- |
// { |
86 |
|
- |
// throw new ServletException( "Unable to create Image Base Path (" + zImagesBasePath + ") Directory!" ); |
87 |
|
- |
// } |
88 |
|
- |
// } |
89 |
|
- |
// if ( !zDir.isDirectory() ) |
90 |
|
- |
// { |
91 |
|
- |
// throw new ServletException( "Image Base Path (" + zImagesBasePath + "), not a Directory!" ); |
92 |
|
- |
// } |
93 |
|
- |
// if ( !zDir.canWrite() ) |
94 |
|
- |
// { |
95 |
|
- |
// throw new ServletException( "Image Base Path (" + zImagesBasePath + ") Directory NOT writable!" ); |
96 |
|
- |
// } |
97 |
|
- |
// mImagesBasePath = zDir; |
98 |
76 |
|
} |
99 |
77 |
|
|
100 |
78 |
|
@Override |
|
@@ -107,8 +85,6 @@ |
107 |
85 |
|
HttpServletRequest zRequest = (HttpServletRequest) request; |
108 |
86 |
|
String zURI = zRequest.getRequestURI(); |
109 |
87 |
|
|
110 |
|
- |
System.out.println( "VersionedStaticContentFilter.doFilter: " + zURI ); |
111 |
|
- |
|
112 |
88 |
|
if ( zURI.endsWith( ".nocache.js" ) ) |
113 |
89 |
|
{ |
114 |
90 |
|
zResponse.setHeader( "Cache-Control", "no-cache no-store must-revalidate" ); |
|
@@ -127,124 +103,40 @@ |
127 |
103 |
|
zResponse.setHeader( "Pragma", "temp" ); |
128 |
104 |
|
zResponse.setHeader( "Pragma", "" ); |
129 |
105 |
|
zResponse.setDateHeader( "Expires", System.currentTimeMillis() + 31536000000l ); |
130 |
|
- |
|
131 |
|
- |
// request.getRequestDispatcher( "/pages" + uri ).forward( request, response ); |
|
106 |
+ |
} |
|
107 |
+ |
// System.out.println( "VersionedStaticContentFilter.doFilter: " + zURI ); |
|
108 |
+ |
int at = zURI.indexOf( "/common/" ); |
|
109 |
+ |
if ( (at != -1) && zURI.startsWith( "/v" ) ) |
|
110 |
+ |
{ |
|
111 |
+ |
if ( isDigits( zURI.substring( 2, at ) ) ) |
|
112 |
+ |
{ |
|
113 |
+ |
request.getRequestDispatcher( zURI.substring( at ) ).forward( request, response ); |
|
114 |
+ |
return; |
|
115 |
+ |
} |
132 |
116 |
|
} |
133 |
117 |
|
} |
134 |
118 |
|
chain.doFilter( request, response ); // Goes to default servlet. |
135 |
119 |
|
} |
136 |
120 |
|
|
|
121 |
+ |
private boolean isDigits( String pString ) |
|
122 |
+ |
{ |
|
123 |
+ |
if ( pString.length() == 0 ) |
|
124 |
+ |
{ |
|
125 |
+ |
return false; |
|
126 |
+ |
} |
|
127 |
+ |
for ( int i = 0; i < pString.length(); i++ ) |
|
128 |
+ |
{ |
|
129 |
+ |
char c = pString.charAt( i ); |
|
130 |
+ |
if ( (c < '0') || ('9' < c) ) |
|
131 |
+ |
{ |
|
132 |
+ |
return false; |
|
133 |
+ |
} |
|
134 |
+ |
} |
|
135 |
+ |
return true; |
|
136 |
+ |
} |
|
137 |
+ |
|
137 |
138 |
|
@Override |
138 |
139 |
|
public void destroy() |
139 |
140 |
|
{ |
140 |
141 |
|
} |
141 |
|
- |
|
142 |
|
- |
// private String normalize( String pPathInfo ) |
143 |
|
- |
// throws FileNotFoundException |
144 |
|
- |
// { |
145 |
|
- |
// if ( pPathInfo != null ) |
146 |
|
- |
// { |
147 |
|
- |
// // switch any separators and insure that we start w/ a '/' |
148 |
|
- |
// pPathInfo = "/" + Utils.noSpaces( pPathInfo.replace( '\\', '/' ) ); |
149 |
|
- |
// // change all "//"s to '/' |
150 |
|
- |
// for ( int at; -1 != (at = pPathInfo.indexOf( "//" )); ) |
151 |
|
- |
// { |
152 |
|
- |
// pPathInfo = pPathInfo.substring( 0, at + 1 ) + pPathInfo.substring( at + 2 ); |
153 |
|
- |
// } |
154 |
|
- |
// // change all "/./"s to '/' |
155 |
|
- |
// for ( int at; -1 != (at = pPathInfo.indexOf( "/./" )); ) |
156 |
|
- |
// { |
157 |
|
- |
// pPathInfo = pPathInfo.substring( 0, at + 1 ) + pPathInfo.substring( at + 3 ); |
158 |
|
- |
// } |
159 |
|
- |
// if ( !pPathInfo.contains( "/../" ) ) // No Up Dirs! |
160 |
|
- |
// { |
161 |
|
- |
// while ( pPathInfo.startsWith( "/" ) ) |
162 |
|
- |
// { |
163 |
|
- |
// pPathInfo = pPathInfo.substring( 1 ); |
164 |
|
- |
// } |
165 |
|
- |
// File zFile = new File( mImagesBasePath, pPathInfo ); |
166 |
|
- |
// if ( zFile.isFile() ) |
167 |
|
- |
// { |
168 |
|
- |
// if ( zFile.canRead() ) |
169 |
|
- |
// { |
170 |
|
- |
// return zFile.getAbsolutePath(); |
171 |
|
- |
// } |
172 |
|
- |
// throw new FileNotFoundException( "Can't Read: " + pPathInfo + " -> " + zFile.getAbsolutePath() ); |
173 |
|
- |
// } |
174 |
|
- |
// } |
175 |
|
- |
// } |
176 |
|
- |
// throw new FileNotFoundException( "No Resource of: " + pPathInfo ); |
177 |
|
- |
// } |
178 |
|
- |
// |
179 |
|
- |
// // This method is called by the servlet container to process a GET request. |
180 |
|
- |
// public void doGet( HttpServletRequest pReq, HttpServletResponse pResp ) |
181 |
|
- |
// throws IOException |
182 |
|
- |
// { |
183 |
|
- |
// // http://localhost:8080/Images/Fred.jpg -> /Fred.jpg |
184 |
|
- |
// |
185 |
|
- |
// String filename = normalize( pReq.getPathInfo() ); |
186 |
|
- |
// |
187 |
|
- |
// ServletContext sc = getServletContext(); |
188 |
|
- |
// |
189 |
|
- |
// // Get the MIME type of the image |
190 |
|
- |
// String mimeType = sc.getMimeType( filename.toLowerCase() ); |
191 |
|
- |
// if ( mimeType == null ) |
192 |
|
- |
// { |
193 |
|
- |
// sc.log( "Could not get MIME type of " + filename ); |
194 |
|
- |
// pResp.setStatus( HttpServletResponse.SC_INTERNAL_SERVER_ERROR ); |
195 |
|
- |
// return; |
196 |
|
- |
// } |
197 |
|
- |
// |
198 |
|
- |
// // Set content type |
199 |
|
- |
// pResp.setContentType( mimeType ); |
200 |
|
- |
// |
201 |
|
- |
// // Set content size |
202 |
|
- |
// File file = new File( filename ); |
203 |
|
- |
// pResp.setContentLength( (int) file.length() ); |
204 |
|
- |
// |
205 |
|
- |
// // Open the file and output streams |
206 |
|
- |
// InputStream in = new FileInputStream( file ); |
207 |
|
- |
// try |
208 |
|
- |
// { |
209 |
|
- |
// OutputStream out = pResp.getOutputStream(); |
210 |
|
- |
// |
211 |
|
- |
// try |
212 |
|
- |
// { |
213 |
|
- |
// // Copy the contents of the file to the output stream |
214 |
|
- |
// byte[] buf = new byte[1024]; |
215 |
|
- |
// for ( int count; (count = in.read( buf )) > 0; ) |
216 |
|
- |
// { |
217 |
|
- |
// out.write( buf, 0, count ); |
218 |
|
- |
// } |
219 |
|
- |
// Closeable zCloseable = out; |
220 |
|
- |
// out = null; |
221 |
|
- |
// zCloseable.close(); |
222 |
|
- |
// } |
223 |
|
- |
// finally |
224 |
|
- |
// { |
225 |
|
- |
// if ( out != null ) |
226 |
|
- |
// { |
227 |
|
- |
// try |
228 |
|
- |
// { |
229 |
|
- |
// out.close(); |
230 |
|
- |
// } |
231 |
|
- |
// catch ( IOException e ) |
232 |
|
- |
// { |
233 |
|
- |
// // Whatever |
234 |
|
- |
// } |
235 |
|
- |
// } |
236 |
|
- |
// } |
237 |
|
- |
// } |
238 |
|
- |
// finally |
239 |
|
- |
// { |
240 |
|
- |
// try |
241 |
|
- |
// { |
242 |
|
- |
// in.close(); |
243 |
|
- |
// } |
244 |
|
- |
// catch ( IOException e ) |
245 |
|
- |
// { |
246 |
|
- |
// // Whatever |
247 |
|
- |
// } |
248 |
|
- |
// } |
249 |
|
- |
// } |
250 |
142 |
|
} |