annotate servlet/src/digilib/io/AliasingDocuDirCache.java @ 339:6d2032b6121d gen2_1

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