Mercurial > hg > digilib-old
comparison common/src/main/java/digilib/io/AliasingDocuDirCache.java @ 903:7779b37d1d05
refactored into maven modules per servlet type.
can build servlet-api 2.3 and 3.0 via profile now!
author | robcast |
---|---|
date | Tue, 26 Apr 2011 20:24:31 +0200 |
parents | servlet/src/main/java/digilib/io/AliasingDocuDirCache.java@ba1eb2d821a2 |
children |
comparison
equal
deleted
inserted
replaced
902:89ba3ffcf552 | 903:7779b37d1d05 |
---|---|
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.Map; | |
27 import java.util.Map.Entry; | |
28 | |
29 import digilib.io.FileOps.FileClass; | |
30 import digilib.servlet.DigilibConfiguration; | |
31 import digilib.util.XMLListLoader; | |
32 | |
33 /** | |
34 * @author casties | |
35 * | |
36 */ | |
37 public class AliasingDocuDirCache extends DocuDirCache { | |
38 | |
39 /** | |
40 * @param baseDirs | |
41 * @param fcs | |
42 * @param confFileName | |
43 * @throws FileOpException | |
44 */ | |
45 public AliasingDocuDirCache(String[] baseDirs, FileClass[] fcs, | |
46 File confFile, DigilibConfiguration dlConfig) | |
47 throws FileOpException { | |
48 // create standard DocuDirCache | |
49 super(baseDirs, fcs, dlConfig); | |
50 Map<String,String> pathMap = null; | |
51 // read alias config file | |
52 try { | |
53 // load into pathMap | |
54 XMLListLoader mapLoader = new XMLListLoader("digilib-aliases", | |
55 "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 (Entry<String, String> linkdir: pathMap.entrySet()) { | |
69 if (linkdir.getValue() == null) { | |
70 logger.error("Key mismatch in mapping file!"); | |
71 break; | |
72 } | |
73 DocuDirectory destDir = new DocuDirectory(linkdir.getValue(), this); | |
74 if (destDir.isValid()) { | |
75 logger.debug("Aliasing dir: " + linkdir.getKey()); | |
76 // add the alias name | |
77 putName(FileOps.normalName(linkdir.getKey()), destDir); | |
78 // add the real dir | |
79 putDir(destDir); | |
80 } | |
81 } | |
82 } | |
83 | |
84 /** | |
85 * Adds a DocuDirectory under another name to the cache. | |
86 * | |
87 * @param name | |
88 * @param newdir | |
89 */ | |
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 } | |
97 | |
98 } |