comparison servlet/src/digilib/io/AliasingDocuDirCache.java @ 176:67ff8c7fecb9

Servlet version 1.17b2 - new mapping file for "virtual directories" - direct file URLs now work without extension (even with wrong ones)
author robcast
date Mon, 10 Nov 2003 20:59:00 +0100
parents
children afe7ff98bb71
comparison
equal deleted inserted replaced
175:633947100c86 176:67ff8c7fecb9
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.HashMap;
27 import java.util.Iterator;
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(
42 String[] baseDirs,
43 int[] fileClasses,
44 String confFileName)
45 throws FileOpException {
46 // create standard DocuDirCache
47 super(baseDirs, fileClasses);
48 HashMap pathMap = null;
49 // read alias config file
50 try {
51 // create data loader for mapping-file
52 File confFile = new File(confFileName);
53 // load into pathMap
54 XMLListLoader mapLoader =
55 new XMLListLoader("digilib-aliases", "mapping", "link", "dir");
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) {
61 throw new FileOpException("ERROR unable to load mapping file!");
62 }
63
64 /*
65 * load map entries into cache
66 */
67
68 for (Iterator i = pathMap.keySet().iterator(); i.hasNext();) {
69 String link = (String)i.next();
70 String dir = (String) pathMap.get(link);
71 DocuDirectory destDir = new DocuDirectory(dir, this);
72 if (destDir.isValid()) {
73 // add the alias name
74 putName(link, destDir);
75 // add the real dir
76 putDir(destDir);
77 }
78 }
79 }
80
81 /** Adds a DocuDirectory under another name to the cache.
82 *
83 * @param name
84 * @param newdir
85 */
86 public void putName(String name, DocuDirectory newdir) {
87 if (map.containsKey(name)) {
88 System.out.println("Baah, duplicate key in AliasingDocuDirCache.put!");
89 } else {
90 map.put(name, newdir);
91 }
92 }
93
94 }