Mercurial > hg > digilib-old
comparison servlet2/src/main/java/digilib/servlet/DigilibServletConfiguration.java @ 911:0cea7e608080
add relative-basedir back in. fix digicat.
author | robcast |
---|---|
date | Tue, 24 May 2011 13:48:37 -0400 |
parents | 7779b37d1d05 |
children | b2d97b842612 |
comparison
equal
deleted
inserted
replaced
910:91e5f20a7c56 | 911:0cea7e608080 |
---|---|
162 */ | 162 */ |
163 public DigilibServletConfiguration(ServletContext c) throws Exception { | 163 public DigilibServletConfiguration(ServletContext c) throws Exception { |
164 readConfig(c); | 164 readConfig(c); |
165 } | 165 } |
166 | 166 |
167 /** | 167 /** |
168 * read parameter list from the XML file in init parameter "config-file" | 168 * read parameter list from the XML file in init parameter "config-file" or |
169 * or file digilib-config.xml | 169 * file digilib-config.xml |
170 */ | 170 */ |
171 @SuppressWarnings("unchecked") | 171 @SuppressWarnings("unchecked") |
172 public void readConfig(ServletContext c) throws Exception { | 172 public void readConfig(ServletContext c) throws Exception { |
173 | 173 |
174 /* | 174 /* |
175 * Get config file name. The file name is first looked for as an init | 175 * Get config file name. The file name is first looked for as an init |
176 * parameter, then in a fixed location in the webapp. | 176 * parameter, then in a fixed location in the webapp. |
177 */ | 177 */ |
178 if (c == null) { | 178 if (c == null) { |
179 // no config no file... | 179 // no config no file... |
180 return; | 180 return; |
181 } | 181 } |
182 String fn = c.getInitParameter("config-file"); | 182 String fn = c.getInitParameter("config-file"); |
183 if (fn == null) { | 183 if (fn == null) { |
184 fn = ServletOps.getConfigFile("digilib-config.xml", c); | 184 fn = ServletOps.getConfigFile("digilib-config.xml", c); |
185 if (fn == null) { | 185 if (fn == null) { |
186 logger.fatal("readConfig: no param config-file"); | 186 logger.fatal("readConfig: no param config-file"); |
187 throw new ServletException("ERROR: no digilib config file!"); | 187 throw new ServletException("ERROR: no digilib config file!"); |
188 } | 188 } |
189 } | 189 } |
190 File f = new File(fn); | 190 File f = new File(fn); |
191 // setup config file list reader | 191 // setup config file list reader |
192 XMLListLoader lilo = | 192 XMLListLoader lilo = new XMLListLoader("digilib-config", "parameter", |
193 new XMLListLoader("digilib-config", "parameter", "name", "value"); | 193 "name", "value"); |
194 // read config file into HashMap | 194 // read config file into HashMap |
195 Map<String,String> confTable = lilo.loadURL(f.toURL().toString()); | 195 Map<String, String> confTable = lilo.loadURL(f.toURL().toString()); |
196 | 196 |
197 // set config file path parameter | 197 // set config file path parameter |
198 setValue("servlet.config.file", f.getCanonicalPath()); | 198 setValue("servlet.config.file", f.getCanonicalPath()); |
199 | 199 |
200 /* | 200 /* |
201 * read parameters | 201 * read parameters |
202 */ | 202 */ |
203 | 203 |
204 for (Entry<String, String> confEntry: confTable.entrySet()) { | 204 for (Entry<String, String> confEntry : confTable.entrySet()) { |
205 Parameter p = get(confEntry.getKey()); | 205 Parameter p = get(confEntry.getKey()); |
206 if (p != null) { | 206 if (p != null) { |
207 if (p.getType() == 's') { | 207 if (p.getType() == 's') { |
208 // type 's' Parameters are not overwritten. | 208 // type 's' Parameters are not overwritten. |
209 continue; | 209 continue; |
210 } | 210 } |
211 if (!p.setValueFromString(confEntry.getValue())) { | 211 if (!p.setValueFromString(confEntry.getValue())) { |
212 /* | 212 /* |
213 * automatic conversion failed -- try special cases | 213 * automatic conversion failed -- try special cases |
214 */ | 214 */ |
215 | 215 |
216 // basedir-list | 216 // basedir-list |
217 if (confEntry.getKey().equals("basedir-list")) { | 217 if (confEntry.getKey().equals("basedir-list")) { |
218 // split list into directories | 218 // split list into directories |
219 String[] sa = FileOps.pathToArray(confEntry.getValue()); | 219 String[] dirs = FileOps.pathToArray(confEntry.getValue()); |
220 if (sa != null) { | 220 for (int j = 0; j < dirs.length; j++) { |
221 p.setValue(sa); | 221 // make relative directory paths be inside the webapp |
222 } | 222 dirs[j] = ServletOps.getFile(dirs[j], c); |
223 } | 223 } |
224 } | 224 if (dirs != null) { |
225 } else { | 225 p.setValue(dirs); |
226 // parameter unknown -- just add | 226 } |
227 newParameter(confEntry.getKey(), null, confEntry.getValue(), 'f'); | 227 } |
228 } | 228 } |
229 } | 229 } else { |
230 // initialise static DocuImage class instance | 230 // parameter unknown -- just add |
231 DigilibServletConfiguration.docuImageClass = (Class<DocuImageImpl>) Class.forName(getAsString("docuimage-class")); | 231 newParameter(confEntry.getKey(), null, confEntry.getValue(), |
232 } | 232 'f'); |
233 } | |
234 } | |
235 // initialise static DocuImage class instance | |
236 DigilibServletConfiguration.docuImageClass = (Class<DocuImageImpl>) Class | |
237 .forName(getAsString("docuimage-class")); | |
238 } | |
233 | 239 |
234 } | 240 } |