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;
|
268
|
26 import java.util.Map;
|
531
|
27 import java.util.Map.Entry;
|
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);
|
531
|
48 Map<String,String> 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
|
531
|
66 for (Entry<String, String> linkdir: pathMap.entrySet()) {
|
|
67 if (linkdir.getValue() == null) {
|
350
|
68 logger.error("Key mismatch in mapping file!");
|
|
69 break;
|
|
70 }
|
531
|
71 DocuDirectory destDir = new DocuDirectory(linkdir.getValue(), this);
|
176
|
72 if (destDir.isValid()) {
|
531
|
73 logger.debug("Aliasing dir: " + linkdir.getKey());
|
176
|
74 // add the alias name
|
531
|
75 putName(FileOps.normalName(linkdir.getKey()), destDir);
|
176
|
76 // add the real dir
|
|
77 putDir(destDir);
|
|
78 }
|
|
79 }
|
|
80 }
|
|
81
|
259
|
82 /**
|
|
83 * Adds a DocuDirectory under another name to the cache.
|
176
|
84 *
|
259
|
85 * @param name
|
176
|
86 * @param newdir
|
|
87 */
|
531
|
88 public void putName(String name, DocuDirectory newdir) {
|
|
89 if (map.containsKey(name)) {
|
|
90 logger.warn("Duplicate key in AliasingDocuDirCache.put -- ignored!");
|
|
91 } else {
|
|
92 map.put(name, newdir);
|
|
93 }
|
|
94 }
|
259
|
95
|
176
|
96 }
|