diff servlet/src/digilib/io/FileOps.java @ 176:67ff8c7fecb9

Servlet version 1.17b2 - new mapping file for "virtual directories" - direct file URLs now work without extension (even with wrong ones)
author robcast
date Mon, 10 Nov 2003 20:59:00 +0100
parents e743b853efca
children afe7ff98bb71
line wrap: on
line diff
--- a/servlet/src/digilib/io/FileOps.java	Mon Nov 10 20:50:32 2003 +0100
+++ b/servlet/src/digilib/io/FileOps.java	Mon Nov 10 20:59:00 2003 +0100
@@ -148,6 +148,40 @@
 		}
 		return pathArray;
 	}
+	
+	/** Extract the base of a file name (sans extension).
+	 * 
+	 * Returns the filename without the extension. The extension is the part behind
+	 * the last dot in the filename. If the filename has no dot the full file name 
+	 * is returned.
+	 *  
+	 * @param fn
+	 * @return
+	 */
+	public static String basename(String fn) {
+		int i = fn.lastIndexOf('.');
+		if (i > 0) {
+			return fn.substring(0, i);
+		}
+		return fn;
+	}
+
+	/** Extract the extension of a file name.
+	 * 
+	 * Returns the extension of a file name. The extension is the part behind
+	 * the last dot in the filename. If the filename has no dot the empty string 
+	 * is returned.
+	 *  
+	 * @param fn
+	 * @return
+	 */
+	public static String extname(String fn) {
+		int i = fn.lastIndexOf('.');
+		if (i > 0) {
+			return fn.substring(i+1);
+		}
+		return "";
+	}
 
 	/**
 	 *  FileFilter for image types (helper class for getFile)