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