# HG changeset patch # User robcast # Date 1133978791 -3600 # Node ID 8a9fd4d64ea7e3e79297d3b0b0e1c363ce48b0f9 # Parent 20f6c41a3f696b3f4d3fc449b8cfd9a4a6c755fc digilib can now take its error-icons from the web app diff -r 20f6c41a3f69 -r 8a9fd4d64ea7 servlet/src/digilib/servlet/ServletOps.java --- a/servlet/src/digilib/servlet/ServletOps.java Wed Dec 07 18:51:11 2005 +0100 +++ b/servlet/src/digilib/servlet/ServletOps.java Wed Dec 07 19:06:31 2005 +0100 @@ -61,6 +61,47 @@ } /** + * get a real File for a web app File. + * + * If the File is not absolute the path is appended to the base directory + * of the web-app. + * + * @param file + * @param sc + * @return + */ + public static File getFile(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(f.getPath()); + f = new File(fn); + } + return f; + } + + /** + * get a real file name for a web app file pathname. + * + * If filename starts with "/" its treated as absolute else the path is + * appended to the base directory of the web-app. + * + * @param filename + * @param sc + * @return + */ + public static String getFile(String filename, ServletConfig sc) { + File f = new File(filename); + // is the filename absolute? + if (!f.isAbsolute()) { + // relative path -> use getRealPath to resolve in WEB-INF + filename = sc.getServletContext() + .getRealPath(filename); + } + return filename; + } + + /** * get a real File for a config File. * * If the File is not absolute the path is appended to the WEB-INF directory