01: // Copyright 2006, 2007 The Apache Software Foundation
02: //
03: // Licensed under the Apache License, Version 2.0 (the "License");
04: // you may not use this file except in compliance with the License.
05: // You may obtain a copy of the License at
06: //
07: // http://www.apache.org/licenses/LICENSE-2.0
08: //
09: // Unless required by applicable law or agreed to in writing, software
10: // distributed under the License is distributed on an "AS IS" BASIS,
11: // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12: // See the License for the specific language governing permissions and
13: // limitations under the License.
14:
15: package org.apache.tapestry.internal.services;
16:
17: import java.io.IOException;
18: import java.net.URL;
19:
20: import org.apache.tapestry.services.Context;
21: import org.apache.tapestry.services.Request;
22: import org.apache.tapestry.services.RequestFilter;
23: import org.apache.tapestry.services.RequestHandler;
24: import org.apache.tapestry.services.Response;
25:
26: /**
27: * Identifies requests that are for actual resource files in the context. For those, Tapestry allows
28: * the servlet container to process the request.
29: */
30: public class StaticFilesFilter implements RequestFilter {
31: private final Context _context;
32:
33: public StaticFilesFilter(Context context) {
34: _context = context;
35: }
36:
37: public boolean service(Request request, Response response,
38: RequestHandler handler) throws IOException {
39: String path = request.getPath();
40:
41: // TAPESTRY-1322: Treat requests from the browser for a favorites icon via the normal
42: // servlet even if the file doesn't exist, to keep the request from looking like a
43: // component action request.
44:
45: if (path.equals("/favicon.ico"))
46: return false;
47:
48: // We are making the questionable assumption that all files to be vended out will contain
49: // an extension (with a dot seperator). Without this, the filter tends to match against
50: // folder names when we don't want it to (especially for the root context path).
51:
52: if (path.contains(".")) {
53: URL url = _context.getResource(path);
54:
55: if (url != null)
56: return false;
57: }
58:
59: return handler.service(request, response);
60: }
61: }
|