comparison servlet/src/digilib/io/FileOps.java @ 271:d3abaf38fb5f

Servlet version 1.21b3 - searching in directories got faster (real binarySearch now!) - cached file lists get disposed - some code cleaning (Map types instead of HashMap)
author robcast
date Tue, 12 Oct 2004 16:06:43 +0200
parents beed92ee6022
children b3519a49ae51
comparison
equal deleted inserted replaced
270:b21915a3fc24 271:d3abaf38fb5f
73 static { 73 static {
74 fileTypes = new HashMap(); 74 fileTypes = new HashMap();
75 imageExtensions = new ArrayList(); 75 imageExtensions = new ArrayList();
76 textExtensions = new ArrayList(); 76 textExtensions = new ArrayList();
77 svgExtensions = new ArrayList(); 77 svgExtensions = new ArrayList();
78 // iterate through file types in ft and fill the Map and Lists
78 for (int i = 0; i < ft.length; i++) { 79 for (int i = 0; i < ft.length; i++) {
79 String ext = ft[i][0]; 80 String ext = ft[i][0];
80 String mt = ft[i][1]; 81 String mt = ft[i][1];
81 fileTypes.put(ext, mt); 82 fileTypes.put(ext, mt);
82 if (classForMimetype(mt) == CLASS_IMAGE) { 83 if (classForMimetype(mt) == CLASS_IMAGE) {
173 * 174 *
174 * @param fn 175 * @param fn
175 * @return 176 * @return
176 */ 177 */
177 public static String basename(String fn) { 178 public static String basename(String fn) {
179 if (fn == null) {
180 return null;
181 }
178 int i = fn.lastIndexOf('.'); 182 int i = fn.lastIndexOf('.');
179 if (i > 0) { 183 if (i > 0) {
180 return fn.substring(0, i); 184 return fn.substring(0, i);
181 } 185 }
182 return fn; 186 return fn;
191 * 195 *
192 * @param fn 196 * @param fn
193 * @return 197 * @return
194 */ 198 */
195 public static String extname(String fn) { 199 public static String extname(String fn) {
200 if (fn == null) {
201 return null;
202 }
196 int i = fn.lastIndexOf('.'); 203 int i = fn.lastIndexOf('.');
197 if (i > 0) { 204 if (i > 0) {
198 return fn.substring(i + 1); 205 return fn.substring(i + 1);
199 } 206 }
200 return ""; 207 return "";
209 * 216 *
210 * @param fn 217 * @param fn
211 * @return 218 * @return
212 */ 219 */
213 public static String parent(String fn) { 220 public static String parent(String fn) {
221 if (fn == null) {
222 return null;
223 }
214 int i = fn.lastIndexOf('/'); 224 int i = fn.lastIndexOf('/');
215 if (i > 0) { 225 if (i > 0) {
216 return fn.substring(0, i); 226 return fn.substring(0, i);
217 } 227 }
218 return ""; 228 return "";
226 * 236 *
227 * @param pathname 237 * @param pathname
228 * @return 238 * @return
229 */ 239 */
230 public static String normalName(String pathname) { 240 public static String normalName(String pathname) {
241 if (pathname == null) {
242 return null;
243 }
231 // upper-dir references are unwanted 244 // upper-dir references are unwanted
232 if (pathname.indexOf("../") >= 0) { 245 if (pathname.indexOf("../") >= 0) {
233 return null; 246 return null;
234 } 247 }
235 int a = 0; 248 int a = 0;
364 * @param type 377 * @param type
365 * @param value 378 * @param value
366 * @return 379 * @return
367 */ 380 */
368 public static Map newHints(Integer type, Object value) { 381 public static Map newHints(Integer type, Object value) {
369 HashMap m = new HashMap(); 382 Map m = new HashMap();
370 if (type != null) { 383 if (type != null) {
371 m.put(type, value); 384 m.put(type, value);
372 } 385 }
373 return m; 386 return m;
374 } 387 }