1 4 5 9 10 package org.openlaszlo.servlets.responders; 11 12 import java.io.*; 13 import java.util.Properties ; 14 import javax.servlet.ServletConfig ; 15 import javax.servlet.ServletException ; 16 import javax.servlet.http.HttpServletRequest ; 17 import javax.servlet.http.HttpServletResponse ; 18 import org.openlaszlo.utils.LZHttpUtils; 19 import javax.servlet.ServletOutputStream ; 20 import org.openlaszlo.cache.MediaCache; 21 import org.openlaszlo.cache.RequestCache; 22 import org.openlaszlo.server.LPS; 23 import org.openlaszlo.utils.FileUtils; 24 import org.openlaszlo.media.MimeType; 25 26 import org.apache.log4j.Logger; 27 28 33 34 public final class ResponderLIB extends Responder 35 { 36 private static Logger mLogger = Logger.getLogger(ResponderLIB.class); 37 38 public int getMimeType() 39 { 40 return MIME_TYPE_SWF; 41 } 42 43 public void init(String reqName, ServletConfig config, Properties prop) 44 throws ServletException , IOException 45 { 46 super.init(reqName, config, prop); 47 } 48 49 59 protected void respondImpl(HttpServletRequest req, HttpServletResponse res) 60 throws IOException 61 { 62 63 try { 64 String patharg = req.getParameter("libpath"); 65 if (patharg == null) { 66 throw new IOException("could not find 'libpath' query arg in lzt=lib request"); 67 } 68 69 75 76 77 ServletOutputStream out = res.getOutputStream(); 78 PrintWriter p = new PrintWriter(out); 79 80 String path = (new File(patharg)).getPath(); 82 String appbasedir = (new File(req.getServletPath())).getParent(); 83 String libpath; 84 if (path.charAt(0) == File.separatorChar) { 87 libpath = path; 88 } else { 89 libpath = (new File(appbasedir, path)).getPath(); 90 } 91 String filename = LZHttpUtils.getRealPath(mContext, libpath); 92 mLogger.info("Responding with LIB for " + filename); 93 res.setContentType(MimeType.SWF); 94 InputStream ins = null; 95 try { 96 ins = new BufferedInputStream(new FileInputStream(filename)); 98 FileUtils.send(ins, out); 99 } finally { 100 FileUtils.close(out); 101 FileUtils.close(ins); 102 } 103 } catch (java.io.FileNotFoundException e) { 104 throw new IOException(e.getMessage()); 105 } 106 } 107 } 108 109 | Popular Tags |