339
|
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;
|
|
27 import java.util.Map;
|
|
28
|
|
29 /**
|
|
30 * @author casties
|
|
31 *
|
|
32 */
|
|
33 public class AliasingDocuDirCache extends DocuDirCache {
|
|
34
|
|
35 /**
|
|
36 * @param baseDirs
|
|
37 * @param fileClasses
|
|
38 * @param confFileName
|
|
39 * @throws FileOpException
|
|
40 */
|
|
41 public AliasingDocuDirCache(File confFile) throws FileOpException {
|
|
42 // create standard DocuDirCache
|
|
43 super();
|
|
44 Map pathMap = null;
|
|
45 // read alias config file
|
|
46 try {
|
|
47 // load into pathMap
|
|
48 XMLListLoader mapLoader = new XMLListLoader("digilib-aliases",
|
|
49 "mapping", "link", "dir");
|
|
50 pathMap = mapLoader.loadURL(confFile.toURL().toString());
|
|
51 } catch (Exception e) {
|
|
52 throw new FileOpException("ERROR loading mapping file: " + e);
|
|
53 }
|
|
54 if (pathMap == null) {
|
|
55 throw new FileOpException("ERROR: unable to load mapping file!");
|
|
56 }
|
|
57
|
|
58 /*
|
|
59 * load map entries into cache
|
|
60 */
|
|
61
|
|
62 for (Iterator i = pathMap.keySet().iterator(); i.hasNext();) {
|
|
63 String link = FileOps.normalName((String) i.next());
|
|
64 String dn = (String) pathMap.get(link);
|
|
65 File dir = FileOps.getRealFile(dn);
|
|
66 if (dir.isDirectory()) {
|
|
67 logger.debug("Aliasing dir: " + link);
|
|
68 DigiDirectory destDir = new DigiDirectory(dir, dn, null);
|
|
69 // add the alias name
|
|
70 putName(link, destDir);
|
|
71 // add the real dir
|
|
72 putDir(destDir);
|
|
73 }
|
|
74 }
|
|
75 }
|
|
76
|
|
77 /**
|
|
78 * Adds a DocuDirectory under another name to the cache.
|
|
79 *
|
|
80 * @param name
|
|
81 * @param newdir
|
|
82 */
|
|
83 public void putName(String name, DigiDirectory newdir) {
|
|
84 Object oldkey = map.put(name, newdir);
|
|
85 if (oldkey != null) {
|
|
86 logger
|
|
87 .warn("Duplicate key in AliasingDocuDirCache.put -- replaced!");
|
|
88 }
|
|
89 }
|
|
90
|
|
91 }
|