# HG changeset patch # User robcast # Date 1133978791 -3600 # Node ID 422d42e3d4ec58a05ffe59d952bd8449d260ac18 # Parent 999c954c8ee729426b41522b5df56d4d042a9fbd digilib can now take its error-icons from the web app diff -r 999c954c8ee7 -r 422d42e3d4ec 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