01: package com.icesoft.faces.webapp.http.core;
02:
03: import com.icesoft.faces.webapp.http.common.MimeTypeMatcher;
04: import com.icesoft.faces.webapp.http.common.Request;
05: import com.icesoft.faces.webapp.http.common.Response;
06: import com.icesoft.faces.webapp.http.common.ResponseHandler;
07: import com.icesoft.faces.webapp.http.common.Server;
08: import com.icesoft.faces.webapp.http.common.standard.NotFoundHandler;
09:
10: import java.io.InputStream;
11:
12: public class ServeCSSResource implements Server {
13: private static final String Package = "com/icesoft/faces/resources/css/";
14: private ClassLoader loader;
15: private MimeTypeMatcher matcher;
16:
17: public ServeCSSResource(MimeTypeMatcher mimeTypeMatcher) {
18: loader = this .getClass().getClassLoader();
19: matcher = mimeTypeMatcher;
20: }
21:
22: public void service(Request request) throws Exception {
23: final String path = request.getURI().getPath();
24: String file = path.substring(path.lastIndexOf("css/") + 4, path
25: .length());
26: final InputStream in = loader.getResourceAsStream(Package
27: + file);
28:
29: if (in == null) {
30: request.respondWith(NotFoundHandler.HANDLER);
31: } else {
32: request.respondWith(new ResponseHandler() {
33: public void respond(Response response) throws Exception {
34: response.setHeader("Content-Type", matcher
35: .mimeTypeFor(path));
36: response.writeBodyFrom(in);
37: }
38: });
39: }
40: }
41:
42: public void shutdown() {
43: }
44: }
|