diff servlet/src/digilib/io/FileOps.java @ 197:bb4ed821d06e

Servlet version 1.18b6 - small fixes to the mapping code (really works now)
author robcast
date Tue, 23 Dec 2003 17:26:45 +0100
parents b3f9a7f646c5
children f8c82fea551a
line wrap: on
line diff
--- a/servlet/src/digilib/io/FileOps.java	Mon Dec 08 16:50:59 2003 +0100
+++ b/servlet/src/digilib/io/FileOps.java	Tue Dec 23 17:26:45 2003 +0100
@@ -178,6 +178,32 @@
 		return "";
 	}
 
+	/** Normalize a path name.
+	 * 
+	 * Removes leading and trailing slashes. Returns null if there is other
+	 * unwanted stuff in the path name. 
+	 * 
+	 * @param pathname
+	 * @return
+	 */
+	public static String normalName(String pathname) {
+		// upper-dir references are unwanted
+		if (pathname.indexOf("../") >= 0) {
+			return null;
+		}
+		int a = 0;
+		int e = pathname.length();
+		// leading and trailing "/" are removed
+		if (pathname.startsWith("/")) {
+			a++;
+		}
+		if (pathname.endsWith("/")) {
+			e--; 
+		}
+		return pathname.substring(a, e);
+	}
+	
+	
 	/**
 	 * FileFilter for image types (helper class for getFile)
 	 */