1 package com.icesoft.faces.webapp.http.core; 2 3 import com.icesoft.faces.webapp.http.common.Request; 4 import com.icesoft.faces.webapp.http.common.Response; 5 import com.icesoft.faces.webapp.http.common.ResponseHandler; 6 import com.icesoft.faces.webapp.http.common.Server; 7 import com.icesoft.faces.webapp.http.common.standard.NotFoundHandler; 8 9 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.length()); 22 final InputStream in = loader.getResourceAsStream(Package + file); 23 24 if (in == null) { 25 request.respondWith(NotFoundHandler.HANDLER); 26 } else { 27 request.respondWith(new ResponseHandler() { 28 public void respond(Response response) throws Exception { 29 response.setHeader("Content-Type", "text/javascript"); 30 response.writeBodyFrom(in); 31 } 32 }); 33 } 34 } 35 36 public void shutdown() { 37 } 38 } 39 | Popular Tags |