comparison servlet/src/digilib/io/DocuDirCache.java @ 472:f8ca069517a2

Bugfix for images not found in dir: added sorting for ArrayLists of ImageFilesets
author hertzhaft
date Fri, 07 Apr 2006 20:39:07 +0200
parents dd1e681924bf
children fca40a188a22
comparison
equal deleted inserted replaced
471:d623c6fee3c9 472:f8ca069517a2
186 DocuDirectory dd; 186 DocuDirectory dd;
187 // file number is 1-based, vector index is 0-based 187 // file number is 1-based, vector index is 0-based
188 int n = in - 1; 188 int n = in - 1;
189 // first, assume fn is a directory and look in the cache 189 // first, assume fn is a directory and look in the cache
190 dd = (DocuDirectory) map.get(fn); 190 dd = (DocuDirectory) map.get(fn);
191 // logger.debug("fn: " + fn);
192 // logger.debug("dd: " + dd);
191 if (dd == null) { 193 if (dd == null) {
192 // cache miss 194 // cache miss
193 misses++; 195 misses++;
194 /* 196 /*
195 * see if fn is a directory 197 * see if fn is a directory
196 */ 198 */
197 File f = new File(baseDirNames[0], fn); 199 File f = new File(baseDirNames[0], fn);
198 if (f.isDirectory()) { 200 if (f.isDirectory()) {
201 // logger.debug(fn + " is a dir");
199 dd = new DocuDirectory(fn, this); 202 dd = new DocuDirectory(fn, this);
200 if (dd.isValid()) { 203 if (dd.isValid()) {
201 // add to the cache 204 // add to the cache
202 putDir(dd); 205 putDir(dd);
203 } 206 }
207 */ 210 */
208 // get the parent directory string (like we store it in the 211 // get the parent directory string (like we store it in the
209 // cache) 212 // cache)
210 String d = FileOps.parent(fn); 213 String d = FileOps.parent(fn);
211 // try it in the cache 214 // try it in the cache
215 // logger.debug(fn + " is a file in dir " + d);
212 dd = (DocuDirectory) map.get(d); 216 dd = (DocuDirectory) map.get(d);
213 if (dd == null) { 217 if (dd == null) {
214 // try to read from disk 218 // try to read from disk
215 dd = new DocuDirectory(d, this); 219 dd = new DocuDirectory(d, this);
216 if (dd.isValid()) { 220 if (dd.isValid()) {
217 // add to the cache 221 // add to the cache
222 // logger.debug(dd + " is valid");
218 putDir(dd); 223 putDir(dd);
219 } else { 224 } else {
220 // invalid path 225 // invalid path
221 return null; 226 return null;
222 } 227 }
224 // it was not a real cache miss 229 // it was not a real cache miss
225 misses--; 230 misses--;
226 } 231 }
227 // get the file's index 232 // get the file's index
228 n = dd.indexOf(f.getName(), fc); 233 n = dd.indexOf(f.getName(), fc);
234 // logger.debug(f.getName() + ", index is " + n + ", fc = " + fc);
229 } 235 }
230 } else { 236 } else {
231 // cache hit 237 // cache hit
232 hits++; 238 hits++;
233 } 239 }
234 dd.refresh(); 240 dd.refresh();
241 // logger.debug(dd + " refreshed");
235 if (dd.isValid()) { 242 if (dd.isValid()) {
236 try { 243 try {
244 // logger.debug(dd + " is valid");
237 return dd.get(n, fc); 245 return dd.get(n, fc);
238 } catch (IndexOutOfBoundsException e) { 246 } catch (IndexOutOfBoundsException e) {
247 logger.debug(fn + ": index out of bounds");
239 } 248 }
240 } 249 }
241 return null; 250 return null;
242 } 251 }
243 252