comparison servlet/src/digilib/io/DocuDirectory.java @ 259:beed92ee6022

Servlet version 1.21b1 - directory indexing got faster but less safe (configurable by "safe-dir-index") - mo=rawfile supplies filename - DigilibConfig takes File parameters - some SerialVersionUIDs (suggested by Eclipse)
author robcast
date Mon, 11 Oct 2004 21:23:00 +0200
parents aaf6eace011d
children b21915a3fc24
comparison
equal deleted inserted replaced
258:7a89d105f526 259:beed92ee6022
26 import java.util.ArrayList; 26 import java.util.ArrayList;
27 import java.util.Arrays; 27 import java.util.Arrays;
28 import java.util.HashMap; 28 import java.util.HashMap;
29 import java.util.Iterator; 29 import java.util.Iterator;
30 import java.util.List; 30 import java.util.List;
31 import java.util.Map;
31 32
32 import org.xml.sax.SAXException; 33 import org.xml.sax.SAXException;
33 34
34 /** 35 /**
35 * @author casties 36 * @author casties
177 // fill array with the remaining directories 178 // fill array with the remaining directories
178 for (int j = 1; j < nb; j++) { 179 for (int j = 1; j < nb; j++) {
179 File d = new File(baseDirNames[j], dirName); 180 File d = new File(baseDirNames[j], dirName);
180 if (d.isDirectory()) { 181 if (d.isDirectory()) {
181 dirs[j] = new Directory(d); 182 dirs[j] = new Directory(d);
182 } 183 dirs[j].readDir();
183 } 184 }
184 185 }
186
187 // read all filenames
188 logger.debug("reading directory "+dir.getPath());
189 /*
190 * using ReadableFileFilter is safer (we won't get directories
191 * with file extensions) but slower.
192 */
193 File[] allFiles = null;
194 if (cache.safeDirIndex) {
195 allFiles = dir.listFiles(new FileOps.ReadableFileFilter());
196 } else {
197 allFiles = dir.listFiles();
198 }
199 logger.debug(" done");
200 if (allFiles == null) {
201 // not a directory
202 return false;
203 }
185 // go through all file classes 204 // go through all file classes
186 for (int nc = 0; nc < FileOps.NUM_CLASSES; nc++) { 205 for (int nc = 0; nc < FileOps.NUM_CLASSES; nc++) {
187 int fc = cache.getFileClasses()[nc]; 206 int fc = cache.getFileClasses()[nc];
188 File[] fl = dir.listFiles(FileOps.filterForClass(fc)); 207 //logger.debug("filtering directory "+dir.getPath()+" for class "+fc);
189 if (fl == null) { 208 File[] fl = FileOps.listFiles(allFiles, FileOps.filterForClass(fc));
190 // not a directory 209 //logger.debug(" done");
191 return false;
192 }
193 // number of files in the directory 210 // number of files in the directory
194 int nf = fl.length; 211 int nf = fl.length;
195 if (nf > 0) { 212 if (nf > 0) {
196 // create new list 213 // create new list
197 list[fc] = new ArrayList(nf); 214 list[fc] = new ArrayList(nf);
198 // sort the file names alphabetically and iterate the list 215 // sort the file names alphabetically and iterate the list
199 Arrays.sort(fl); 216 Arrays.sort(fl);
217 Map hints = FileOps.newHints(FileOps.HINT_BASEDIRS, dirs);
218 hints.put(FileOps.HINT_FILEEXT, scalext);
200 for (int i = 0; i < nf; i++) { 219 for (int i = 0; i < nf; i++) {
201 DocuDirent f = FileOps.fileForClass(fc, fl[i], dirs, scalext); 220 DocuDirent f = FileOps.fileForClass(fc, fl[i], hints);
202 // add the file to our list 221 // add the file to our list
203 list[fc].add(f); 222 list[fc].add(f);
204 f.setParent(this); 223 f.setParent(this);
205 } 224 }
206 } 225 }
379 } 398 }
380 } 399 }
381 // try again without extension 400 // try again without extension
382 for (int i = 0; i < n; i++) { 401 for (int i = 0; i < n; i++) {
383 DocuDirent fs = (DocuDirent) list[fc].get(i); 402 DocuDirent fs = (DocuDirent) list[fc].get(i);
384 if (fs.getBasename().equals(FileOps.basename(fn))) { 403 if (FileOps.basename(fs.getName()).equals(FileOps.basename(fn))) {
385 // basename matches 404 // basename matches
386 return i; 405 return i;
387 } 406 }
388 } 407 }
389 return -1; 408 return -1;