01: package com.icesoft.faces.webapp.http.core;
02:
03: import com.icesoft.faces.webapp.http.common.Configuration;
04: import com.icesoft.faces.webapp.http.common.FileLocator;
05: import com.icesoft.faces.webapp.http.common.MimeTypeMatcher;
06: import com.icesoft.faces.webapp.http.common.Request;
07: import com.icesoft.faces.webapp.http.common.Server;
08: import com.icesoft.faces.webapp.http.common.standard.CacheControlledServer;
09: import com.icesoft.faces.webapp.http.common.standard.CompressingServer;
10: import com.icesoft.faces.webapp.http.common.standard.PathDispatcherServer;
11:
12: public class ResourceServer implements Server {
13: private Server dispatcher;
14:
15: public ResourceServer(Configuration configuration,
16: MimeTypeMatcher mimeTypeMatcher, FileLocator fileLocator) {
17: PathDispatcherServer pathDispatcher = new PathDispatcherServer();
18: pathDispatcher.dispatchOn(".*xmlhttp\\/javascript-blocked$",
19: new RedirectOnJSBlocked(configuration));
20: pathDispatcher.dispatchOn(".*xmlhttp\\/.*\\/.*\\.js$",
21: new CacheControlledServer(new ServeJSCode()));
22: pathDispatcher.dispatchOn(".*xmlhttp\\/css\\/.*",
23: new CacheControlledServer(new ServeCSSResource(
24: mimeTypeMatcher)));
25: pathDispatcher.dispatchOn(".*xmlhttp\\/blank$",
26: new ServeBlankPage());
27: pathDispatcher.dispatchOn(".*", new FileServer(fileLocator,
28: mimeTypeMatcher));
29: if (configuration.getAttributeAsBoolean("compressResources",
30: true)) {
31: dispatcher = new CompressingServer(pathDispatcher);
32: } else {
33: dispatcher = pathDispatcher;
34: }
35: }
36:
37: public void service(Request request) throws Exception {
38: dispatcher.service(request);
39: }
40:
41: public void shutdown() {
42: dispatcher.shutdown();
43: }
44: }
|