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 import com.icesoft.util.ContentUtilities; 9 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 16 public ServeCSSResource() { 17 loader = this.getClass().getClassLoader(); 18 } 19 20 public void service(Request request) throws Exception { 21 String path = request.getURI().getPath(); 22 final String contentType = ContentUtilities.guessTypeFromName(path); 23 String file = path.substring(path.lastIndexOf("css/") + 4, path.length()); 24 final InputStream in = loader.getResourceAsStream(Package + 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", contentType); 32 response.writeBodyFrom(in); 33 } 34 }); 35 } 36 } 37 38 public void shutdown() { 39 } 40 } 41 | Popular Tags |