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
|
563
|
29 import digilib.io.FileOps.FileClass;
|
259
|
30 import digilib.servlet.DigilibConfiguration;
|
590
|
31 import digilib.util.XMLListLoader;
|
259
|
32
|
176
|
33 /**
|
|
34 * @author casties
|
|
35 *
|
|
36 */
|
|
37 public class AliasingDocuDirCache extends DocuDirCache {
|
|
38
|
|
39 /**
|
|
40 * @param baseDirs
|
563
|
41 * @param fcs
|
176
|
42 * @param confFileName
|
|
43 * @throws FileOpException
|
|
44 */
|
563
|
45 public AliasingDocuDirCache(String[] baseDirs, FileClass[] fcs,
|
259
|
46 File confFile, DigilibConfiguration dlConfig)
|
|
47 throws FileOpException {
|
176
|
48 // create standard DocuDirCache
|
563
|
49 super(baseDirs, fcs, dlConfig);
|
531
|
50 Map<String,String> pathMap = null;
|
176
|
51 // read alias config file
|
|
52 try {
|
|
53 // load into pathMap
|
259
|
54 XMLListLoader mapLoader = new XMLListLoader("digilib-aliases",
|
|
55 "mapping", "link", "dir");
|
176
|
56 pathMap = mapLoader.loadURL(confFile.toURL().toString());
|
|
57 } catch (Exception e) {
|
|
58 throw new FileOpException("ERROR loading mapping file: " + e);
|
|
59 }
|
|
60 if (pathMap == null) {
|
197
|
61 throw new FileOpException("ERROR: unable to load mapping file!");
|
176
|
62 }
|
|
63
|
|
64 /*
|
|
65 * load map entries into cache
|
|
66 */
|
259
|
67
|
531
|
68 for (Entry<String, String> linkdir: pathMap.entrySet()) {
|
|
69 if (linkdir.getValue() == null) {
|
350
|
70 logger.error("Key mismatch in mapping file!");
|
|
71 break;
|
|
72 }
|
531
|
73 DocuDirectory destDir = new DocuDirectory(linkdir.getValue(), this);
|
176
|
74 if (destDir.isValid()) {
|
531
|
75 logger.debug("Aliasing dir: " + linkdir.getKey());
|
176
|
76 // add the alias name
|
531
|
77 putName(FileOps.normalName(linkdir.getKey()), destDir);
|
176
|
78 // add the real dir
|
|
79 putDir(destDir);
|
|
80 }
|
|
81 }
|
|
82 }
|
|
83
|
259
|
84 /**
|
|
85 * Adds a DocuDirectory under another name to the cache.
|
176
|
86 *
|
259
|
87 * @param name
|
176
|
88 * @param newdir
|
|
89 */
|
531
|
90 public void putName(String name, DocuDirectory newdir) {
|
|
91 if (map.containsKey(name)) {
|
|
92 logger.warn("Duplicate key in AliasingDocuDirCache.put -- ignored!");
|
|
93 } else {
|
|
94 map.put(name, newdir);
|
|
95 }
|
|
96 }
|
259
|
97
|
176
|
98 }
|