01: /*
02: * This file is part of PFIXCORE.
03: *
04: * PFIXCORE is free software; you can redistribute it and/or modify
05: * it under the terms of the GNU Lesser General Public License as published by
06: * the Free Software Foundation; either version 2 of the License, or
07: * (at your option) any later version.
08: *
09: * PFIXCORE is distributed in the hope that it will be useful,
10: * but WITHOUT ANY WARRANTY; without even the implied warranty of
11: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12: * GNU Lesser General Public License for more details.
13: *
14: * You should have received a copy of the GNU Lesser General Public License
15: * along with PFIXCORE; if not, write to the Free Software
16: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17: */
18:
19: package de.schlund.pfixxml.config;
20:
21: import java.io.IOException;
22: import java.util.Properties;
23:
24: import org.xml.sax.SAXException;
25:
26: import de.schlund.pfixcore.exception.PustefixCoreException;
27: import de.schlund.pfixxml.config.impl.ContextXMLServletConfigImpl;
28: import de.schlund.pfixxml.config.impl.DirectOutputServletConfigImpl;
29: import de.schlund.pfixxml.resources.FileResource;
30:
31: /**
32: * Generates configuration objects by reading corresponding configuration
33: * files.
34: *
35: * @author Sebastian Marsching <sebastian.marsching@1und1.de>
36: */
37: public class ConfigReader {
38:
39: /**
40: * Used to read a configuration for the
41: * {@link de.schlund.pfixxml.ContextXMLServlet}.
42: *
43: * @param file configuration file to read
44: * @param globalProperties globally defined properties the configuration
45: * should inherit from
46: * @return configuration initialized from file
47: * @throws PustefixCoreException if a parsing error occurs
48: */
49: public static ContextXMLServletConfig readContextXMLServletConfig(
50: FileResource file, Properties globalProperties)
51: throws PustefixCoreException {
52: try {
53: return ContextXMLServletConfigImpl.readFromFile(file,
54: globalProperties);
55: } catch (SAXException e) {
56: throw new PustefixCoreException(
57: "Error while reading configuration file " + file
58: + ": " + e.getMessage(), e);
59: } catch (IOException e) {
60: throw new PustefixCoreException(
61: "Error while reading configuration file " + file
62: + ": " + e.getMessage(), e);
63: }
64: }
65:
66: /**
67: * Used to read a configuration for the
68: * {@link de.schlund.pfixxml.DirectOutputServlet}.
69: *
70: * @param file configuration file to read
71: * @param globalProperties globally defined properties the configuration
72: * should inherit from
73: * @return configuration initialized from file
74: * @throws PustefixCoreException if a parsing error occurs
75: */
76: public static DirectOutputServletConfig readDirectOutputServletConfig(
77: FileResource file, Properties globalProperties)
78: throws PustefixCoreException {
79: try {
80: return DirectOutputServletConfigImpl.readFromFile(file,
81: globalProperties);
82: } catch (SAXException e) {
83: throw new PustefixCoreException(
84: "Error while reading configuration file " + file
85: + ": " + e.getMessage(), e);
86: } catch (IOException e) {
87: throw new PustefixCoreException(
88: "Error while reading configuration file " + file
89: + ": " + e.getMessage(), e);
90: }
91: }
92: }
|