Mercurial > hg > digilib-old
changeset 264:4ea05660f3e0
Servlet version 1.21b1
- directory indexing got faster but less safe
(configurable by "safe-dir-index")
- mo=rawfile supplies filename
- DigilibConfig takes File parameters
- some SerialVersionUIDs (suggested by Eclipse)
author | robcast |
---|---|
date | Mon, 11 Oct 2004 21:23:00 +0200 |
parents | e16d132aa6f6 |
children | eddf0bbe9adb |
files | servlet/src/digilib/servlet/ServletOps.java servlet/src/digilib/servlet/Texter.java |
diffstat | 2 files changed, 27 insertions(+), 2 deletions(-) [+] |
line wrap: on
line diff
--- a/servlet/src/digilib/servlet/ServletOps.java Mon Oct 11 21:23:00 2004 +0200 +++ b/servlet/src/digilib/servlet/ServletOps.java Mon Oct 11 21:23:00 2004 +0200 @@ -29,7 +29,6 @@ import java.util.StringTokenizer; import javax.servlet.ServletConfig; -import javax.servlet.ServletResponse; import javax.servlet.http.HttpServletResponse; import org.apache.log4j.Logger; @@ -62,6 +61,27 @@ } /** + * get a real File for a config File. + * + * If the File is not absolute the path is + * appended to the WEB-INF directory of the web-app. + * + * @param file + * @param sc + * @return + */ + public static File getConfigFile(File f, ServletConfig sc) { + // is the filename absolute? + if (!f.isAbsolute()) { + // relative path -> use getRealPath to resolve in WEB-INF + String fn = sc.getServletContext() + .getRealPath("WEB-INF/" + f.getPath()); + f = new File(fn); + } + return f; + } + + /** * get a real file name for a config file pathname. * * If filename starts with "/" its treated as absolute else the path is @@ -120,7 +140,7 @@ * @throws FileOpException * Exception is thrown for a IOException. */ - public static void sendFile(File f, String mt, ServletResponse response) + public static void sendFile(File f, String mt, HttpServletResponse response) throws FileOpException { logger.debug("sendRawFile(" + mt + ", " + f + ")"); if (mt == null) { @@ -133,6 +153,9 @@ response.setContentType(mt); // open file try { + if (mt.equals("application/octet-stream")) { + response.addHeader("Content-Disposition", "attachment; filename=\""+f.getName()+"\""); + } FileInputStream inFile = new FileInputStream(f); OutputStream outStream = response.getOutputStream(); byte dataBuffer[] = new byte[4096];
--- a/servlet/src/digilib/servlet/Texter.java Mon Oct 11 21:23:00 2004 +0200 +++ b/servlet/src/digilib/servlet/Texter.java Mon Oct 11 21:23:00 2004 +0200 @@ -42,6 +42,8 @@ */ public class Texter extends HttpServlet { + private static final long serialVersionUID = -8539178734033662322L; + /** Servlet version */ public static String tlVersion = "0.1b1";