comparison artifact-database/src/main/java/de/intevation/artifactdatabase/Config.java @ 17:5a6b6a3debc7

Integrated logging into artifact database. artifacts/trunk@33 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Tue, 08 Sep 2009 06:29:52 +0000
parents 0d6badf6af42
children 1259d192e3c3
comparison
equal deleted inserted replaced
16:635310c6a20e 17:5a6b6a3debc7
18 import javax.xml.xpath.XPathFactory; 18 import javax.xml.xpath.XPathFactory;
19 import javax.xml.xpath.XPath; 19 import javax.xml.xpath.XPath;
20 import javax.xml.xpath.XPathExpressionException; 20 import javax.xml.xpath.XPathExpressionException;
21 import javax.xml.xpath.XPathConstants; 21 import javax.xml.xpath.XPathConstants;
22 22
23 import org.apache.log4j.Logger;
24
23 /** 25 /**
24 * @author Sascha L. Teichmann 26 * @author Sascha L. Teichmann
25 */ 27 */
26 public final class Config 28 public final class Config
27 { 29 {
30 private static Logger logger = Logger.getLogger(Config.class);
31
28 public static final String CONFIG_PROPERTY = "artifact.database.config"; 32 public static final String CONFIG_PROPERTY = "artifact.database.config";
29 33
30 public static final String CONFIG_DEFAULT = "artifactdb-conf.xml"; 34 public static final String CONFIG_DEFAULT = "artifactdb-conf.xml";
31 35
32 private static Document config; 36 private static Document config;
44 private static Document loadConfig() { 48 private static Document loadConfig() {
45 File file = new File( 49 File file = new File(
46 System.getProperty(CONFIG_PROPERTY, CONFIG_DEFAULT)); 50 System.getProperty(CONFIG_PROPERTY, CONFIG_DEFAULT));
47 51
48 if (!file.canRead() && !file.isFile()) { 52 if (!file.canRead() && !file.isFile()) {
49 System.err.println("ERROR: cannot read config file '" 53 logger.error("Cannot read config file '"
50 + file + "'."); 54 + file + "'.");
51 return null; 55 return null;
52 } 56 }
53 57
54 try { 58 try {
55 DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); 59 DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
56 factory.setValidating(false); // XXX: This may change in future. 60 factory.setValidating(false); // XXX: This may change in future.
57 return factory.newDocumentBuilder().parse(file); 61 return factory.newDocumentBuilder().parse(file);
58 } 62 }
59 catch (SAXException se) { 63 catch (SAXException se) {
60 System.err.println("ERROR: while processing XML file '" 64 logger.error(se.getLocalizedMessage(), se);
61 + file + "'");
62 se.printStackTrace(System.err);
63 } 65 }
64 catch (ParserConfigurationException pce) { 66 catch (ParserConfigurationException pce) {
65 System.err.println("ERROR: with XML configuration"); 67 logger.error(pce.getLocalizedMessage(), pce);
66 pce.printStackTrace(System.err);
67 } 68 }
68 catch (IOException ioe) { 69 catch (IOException ioe) {
69 System.err.println("ERROR: I/O while processing file '" 70 logger.error(ioe.getLocalizedMessage());
70 + file + "'");
71 ioe.printStackTrace(System.err);
72 } 71 }
73 72
74 return null; 73 return null;
75 } 74 }
76 75
86 85
87 try { 86 try {
88 return xpath.evaluate(query, root, returnType); 87 return xpath.evaluate(query, root, returnType);
89 } 88 }
90 catch (XPathExpressionException xpee) { 89 catch (XPathExpressionException xpee) {
91 xpee.printStackTrace(System.err); 90 logger.error(xpee.getLocalizedMessage(), xpee);
92 } 91 }
93 92
94 return null; 93 return null;
95 } 94 }
96 95

http://dive4elements.wald.intevation.org