comparison servlet/src/digilib/io/AliasingDocuDirCache.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 f8c82fea551a
children 2c7747cc1838
comparison
equal deleted inserted replaced
258:7a89d105f526 259:beed92ee6022
24 24
25 import java.io.File; 25 import java.io.File;
26 import java.util.HashMap; 26 import java.util.HashMap;
27 import java.util.Iterator; 27 import java.util.Iterator;
28 28
29 import digilib.servlet.DigilibConfiguration;
30
29 /** 31 /**
30 * @author casties 32 * @author casties
31 * 33 *
32 */ 34 */
33 public class AliasingDocuDirCache extends DocuDirCache { 35 public class AliasingDocuDirCache extends DocuDirCache {
36 * @param baseDirs 38 * @param baseDirs
37 * @param fileClasses 39 * @param fileClasses
38 * @param confFileName 40 * @param confFileName
39 * @throws FileOpException 41 * @throws FileOpException
40 */ 42 */
41 public AliasingDocuDirCache( 43 public AliasingDocuDirCache(String[] baseDirs, int[] fileClasses,
42 String[] baseDirs, 44 File confFile, DigilibConfiguration dlConfig)
43 int[] fileClasses, 45 throws FileOpException {
44 String confFileName)
45 throws FileOpException {
46 // create standard DocuDirCache 46 // create standard DocuDirCache
47 super(baseDirs, fileClasses); 47 super(baseDirs, fileClasses, dlConfig);
48 HashMap pathMap = null; 48 HashMap pathMap = null;
49 // read alias config file 49 // read alias config file
50 try { 50 try {
51 // create data loader for mapping-file
52 File confFile = new File(confFileName);
53 // load into pathMap 51 // load into pathMap
54 XMLListLoader mapLoader = 52 XMLListLoader mapLoader = new XMLListLoader("digilib-aliases",
55 new XMLListLoader("digilib-aliases", "mapping", "link", "dir"); 53 "mapping", "link", "dir");
56 pathMap = mapLoader.loadURL(confFile.toURL().toString()); 54 pathMap = mapLoader.loadURL(confFile.toURL().toString());
57 } catch (Exception e) { 55 } catch (Exception e) {
58 throw new FileOpException("ERROR loading mapping file: " + e); 56 throw new FileOpException("ERROR loading mapping file: " + e);
59 } 57 }
60 if (pathMap == null) { 58 if (pathMap == null) {
62 } 60 }
63 61
64 /* 62 /*
65 * load map entries into cache 63 * load map entries into cache
66 */ 64 */
67 65
68 for (Iterator i = pathMap.keySet().iterator(); i.hasNext();) { 66 for (Iterator i = pathMap.keySet().iterator(); i.hasNext();) {
69 String link = FileOps.normalName((String)i.next()); 67 String link = FileOps.normalName((String) i.next());
70 String dir = (String) pathMap.get(link); 68 String dir = (String) pathMap.get(link);
71 DocuDirectory destDir = new DocuDirectory(dir, this); 69 DocuDirectory destDir = new DocuDirectory(dir, this);
72 if (destDir.isValid()) { 70 if (destDir.isValid()) {
73 logger.debug("Aliasing dir: "+link); 71 logger.debug("Aliasing dir: " + link);
74 // add the alias name 72 // add the alias name
75 putName(link, destDir); 73 putName(link, destDir);
76 // add the real dir 74 // add the real dir
77 putDir(destDir); 75 putDir(destDir);
78 } 76 }
79 } 77 }
80 } 78 }
81 79
82 /** Adds a DocuDirectory under another name to the cache. 80 /**
81 * Adds a DocuDirectory under another name to the cache.
83 * 82 *
84 * @param name 83 * @param name
85 * @param newdir 84 * @param newdir
86 */ 85 */
87 public void putName(String name, DocuDirectory newdir) { 86 public void putName(String name, DocuDirectory newdir) {
88 if (map.containsKey(name)) { 87 if (map.containsKey(name)) {
89 logger.warn("Duplicate key in AliasingDocuDirCache.put -- ignored!"); 88 logger
89 .warn("Duplicate key in AliasingDocuDirCache.put -- ignored!");
90 } else { 90 } else {
91 map.put(name, newdir); 91 map.put(name, newdir);
92 } 92 }
93 } 93 }
94 94
95 } 95 }