176
|
1 /*
|
|
2 * AliasingDocuDirCache -- DocuDirCache using alias entries from config file
|
|
3 *
|
|
4 * Digital Image Library servlet components
|
|
5 *
|
|
6 * Copyright (C) 2003 Robert Casties (robcast@mail.berlios.de)
|
|
7 *
|
|
8 * This program is free software; you can redistribute it and/or modify it
|
|
9 * under the terms of the GNU General Public License as published by the Free
|
|
10 * Software Foundation; either version 2 of the License, or (at your option)
|
|
11 * any later version.
|
|
12 *
|
|
13 * Please read license.txt for the full details. A copy of the GPL may be found
|
|
14 * at http://www.gnu.org/copyleft/lgpl.html
|
|
15 *
|
|
16 * You should have received a copy of the GNU General Public License along with
|
|
17 * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
|
|
18 * Place, Suite 330, Boston, MA 02111-1307 USA
|
|
19 *
|
|
20 * Created on 04.11.2003
|
|
21 */
|
|
22
|
|
23 package digilib.io;
|
|
24
|
|
25 import java.io.File;
|
|
26 import java.util.Iterator;
|
268
|
27 import java.util.Map;
|
176
|
28
|
259
|
29 import digilib.servlet.DigilibConfiguration;
|
|
30
|
176
|
31 /**
|
|
32 * @author casties
|
|
33 *
|
|
34 */
|
|
35 public class AliasingDocuDirCache extends DocuDirCache {
|
|
36
|
|
37 /**
|
|
38 * @param baseDirs
|
|
39 * @param fileClasses
|
|
40 * @param confFileName
|
|
41 * @throws FileOpException
|
|
42 */
|
259
|
43 public AliasingDocuDirCache(String[] baseDirs, int[] fileClasses,
|
|
44 File confFile, DigilibConfiguration dlConfig)
|
|
45 throws FileOpException {
|
176
|
46 // create standard DocuDirCache
|
259
|
47 super(baseDirs, fileClasses, dlConfig);
|
268
|
48 Map pathMap = null;
|
176
|
49 // read alias config file
|
|
50 try {
|
|
51 // load into pathMap
|
259
|
52 XMLListLoader mapLoader = new XMLListLoader("digilib-aliases",
|
|
53 "mapping", "link", "dir");
|
176
|
54 pathMap = mapLoader.loadURL(confFile.toURL().toString());
|
|
55 } catch (Exception e) {
|
|
56 throw new FileOpException("ERROR loading mapping file: " + e);
|
|
57 }
|
|
58 if (pathMap == null) {
|
197
|
59 throw new FileOpException("ERROR: unable to load mapping file!");
|
176
|
60 }
|
|
61
|
|
62 /*
|
|
63 * load map entries into cache
|
|
64 */
|
259
|
65
|
176
|
66 for (Iterator i = pathMap.keySet().iterator(); i.hasNext();) {
|
259
|
67 String link = FileOps.normalName((String) i.next());
|
176
|
68 String dir = (String) pathMap.get(link);
|
|
69 DocuDirectory destDir = new DocuDirectory(dir, this);
|
|
70 if (destDir.isValid()) {
|
259
|
71 logger.debug("Aliasing dir: " + link);
|
176
|
72 // add the alias name
|
|
73 putName(link, destDir);
|
|
74 // add the real dir
|
|
75 putDir(destDir);
|
|
76 }
|
|
77 }
|
|
78 }
|
|
79
|
259
|
80 /**
|
|
81 * Adds a DocuDirectory under another name to the cache.
|
176
|
82 *
|
259
|
83 * @param name
|
176
|
84 * @param newdir
|
|
85 */
|
|
86 public void putName(String name, DocuDirectory newdir) {
|
|
87 if (map.containsKey(name)) {
|
259
|
88 logger
|
|
89 .warn("Duplicate key in AliasingDocuDirCache.put -- ignored!");
|
176
|
90 } else {
|
|
91 map.put(name, newdir);
|
|
92 }
|
|
93 }
|
259
|
94
|
176
|
95 }
|