changeset 393:8a9fd4d64ea7

digilib can now take its error-icons from the web app
author robcast
date Wed, 07 Dec 2005 19:06:31 +0100
parents 20f6c41a3f69
children 31643c12d939
files servlet/src/digilib/servlet/ServletOps.java
diffstat 1 files changed, 41 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- 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