Mercurial > dive4elements > framework
annotate artifacts-common/src/main/java/org/dive4elements/artifacts/common/utils/Config.java @ 558:609ced80bcf0
Fixed: used java 7 feature although java 6 comliance level is configured
author | gernotbelger |
---|---|
date | Thu, 28 Jun 2018 19:16:06 +0200 |
parents | ba31ca213c88 |
children | 2b631f788ce1 |
rev | line source |
---|---|
206
33f58a847fc4
Added a copy of Config in the commons package. TODO: Remove it from artifacts-database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
1 /* |
33f58a847fc4
Added a copy of Config in the commons package. TODO: Remove it from artifacts-database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
2 * Copyright (c) 2010 by Intevation GmbH |
33f58a847fc4
Added a copy of Config in the commons package. TODO: Remove it from artifacts-database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
3 * |
33f58a847fc4
Added a copy of Config in the commons package. TODO: Remove it from artifacts-database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
4 * This program is free software under the LGPL (>=v2.1) |
33f58a847fc4
Added a copy of Config in the commons package. TODO: Remove it from artifacts-database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
5 * Read the file LGPL.txt coming with the software for details |
33f58a847fc4
Added a copy of Config in the commons package. TODO: Remove it from artifacts-database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
6 * or visit http://www.gnu.org/licenses/ if it does not exist. |
33f58a847fc4
Added a copy of Config in the commons package. TODO: Remove it from artifacts-database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
7 */ |
33f58a847fc4
Added a copy of Config in the commons package. TODO: Remove it from artifacts-database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
8 |
475
415df0fc4fa1
Fixed maven group ids
Sascha L. Teichmann <teichmann@intevation.de>
parents:
472
diff
changeset
|
9 package org.dive4elements.artifacts.common.utils; |
206
33f58a847fc4
Added a copy of Config in the commons package. TODO: Remove it from artifacts-database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
10 |
558
609ced80bcf0
Fixed: used java 7 feature although java 6 comliance level is configured
gernotbelger
parents:
556
diff
changeset
|
11 import java.io.BufferedInputStream; |
206
33f58a847fc4
Added a copy of Config in the commons package. TODO: Remove it from artifacts-database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
12 import java.io.File; |
558
609ced80bcf0
Fixed: used java 7 feature although java 6 comliance level is configured
gernotbelger
parents:
556
diff
changeset
|
13 import java.io.FileInputStream; |
206
33f58a847fc4
Added a copy of Config in the commons package. TODO: Remove it from artifacts-database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
14 import java.io.IOException; |
558
609ced80bcf0
Fixed: used java 7 feature although java 6 comliance level is configured
gernotbelger
parents:
556
diff
changeset
|
15 import java.io.InputStream; |
556 | 16 import java.util.Properties; |
206
33f58a847fc4
Added a copy of Config in the commons package. TODO: Remove it from artifacts-database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
17 |
33f58a847fc4
Added a copy of Config in the commons package. TODO: Remove it from artifacts-database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
18 import javax.xml.namespace.QName; |
33f58a847fc4
Added a copy of Config in the commons package. TODO: Remove it from artifacts-database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
19 import javax.xml.parsers.DocumentBuilderFactory; |
33f58a847fc4
Added a copy of Config in the commons package. TODO: Remove it from artifacts-database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
20 import javax.xml.parsers.ParserConfigurationException; |
33f58a847fc4
Added a copy of Config in the commons package. TODO: Remove it from artifacts-database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
21 import javax.xml.xpath.XPathConstants; |
33f58a847fc4
Added a copy of Config in the commons package. TODO: Remove it from artifacts-database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
22 |
33f58a847fc4
Added a copy of Config in the commons package. TODO: Remove it from artifacts-database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
23 import org.apache.log4j.Logger; |
33f58a847fc4
Added a copy of Config in the commons package. TODO: Remove it from artifacts-database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
24 import org.w3c.dom.Document; |
33f58a847fc4
Added a copy of Config in the commons package. TODO: Remove it from artifacts-database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
25 import org.w3c.dom.Node; |
33f58a847fc4
Added a copy of Config in the commons package. TODO: Remove it from artifacts-database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
26 import org.w3c.dom.NodeList; |
33f58a847fc4
Added a copy of Config in the commons package. TODO: Remove it from artifacts-database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
27 import org.xml.sax.SAXException; |
33f58a847fc4
Added a copy of Config in the commons package. TODO: Remove it from artifacts-database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
28 |
33f58a847fc4
Added a copy of Config in the commons package. TODO: Remove it from artifacts-database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
29 /** |
33f58a847fc4
Added a copy of Config in the commons package. TODO: Remove it from artifacts-database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
30 * The central access to the configuration of the artifact database. |
33f58a847fc4
Added a copy of Config in the commons package. TODO: Remove it from artifacts-database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
31 * This class provides some static methods to access the central |
33f58a847fc4
Added a copy of Config in the commons package. TODO: Remove it from artifacts-database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
32 * configuration XML file via XPath. |
33f58a847fc4
Added a copy of Config in the commons package. TODO: Remove it from artifacts-database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
33 * |
33f58a847fc4
Added a copy of Config in the commons package. TODO: Remove it from artifacts-database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
34 * @author <a href="mailto:sascha.teichmann@intevation.de">Sascha L. Teichmann</a> |
33f58a847fc4
Added a copy of Config in the commons package. TODO: Remove it from artifacts-database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
35 */ |
556 | 36 public final class Config { |
206
33f58a847fc4
Added a copy of Config in the commons package. TODO: Remove it from artifacts-database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
37 private static Logger logger = Logger.getLogger(Config.class); |
33f58a847fc4
Added a copy of Config in the commons package. TODO: Remove it from artifacts-database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
38 |
33f58a847fc4
Added a copy of Config in the commons package. TODO: Remove it from artifacts-database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
39 /** |
33f58a847fc4
Added a copy of Config in the commons package. TODO: Remove it from artifacts-database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
40 * System property name where to find the configuration directory. |
33f58a847fc4
Added a copy of Config in the commons package. TODO: Remove it from artifacts-database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
41 */ |
33f58a847fc4
Added a copy of Config in the commons package. TODO: Remove it from artifacts-database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
42 public static final String CONFIG_DIR = "artifact.database.dir"; |
33f58a847fc4
Added a copy of Config in the commons package. TODO: Remove it from artifacts-database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
43 |
33f58a847fc4
Added a copy of Config in the commons package. TODO: Remove it from artifacts-database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
44 /** |
33f58a847fc4
Added a copy of Config in the commons package. TODO: Remove it from artifacts-database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
45 * Default path to the configuration directory if none |
33f58a847fc4
Added a copy of Config in the commons package. TODO: Remove it from artifacts-database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
46 * was specified by the CONFIG_DIR system property. |
33f58a847fc4
Added a copy of Config in the commons package. TODO: Remove it from artifacts-database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
47 */ |
556 | 48 public static final File CONFIG_DIR_DEFAULT = new File(new File(System.getProperty("user.home", System.getProperty("user.dir", "."))), ".artifactdb"); |
206
33f58a847fc4
Added a copy of Config in the commons package. TODO: Remove it from artifacts-database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
49 |
33f58a847fc4
Added a copy of Config in the commons package. TODO: Remove it from artifacts-database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
50 /** |
33f58a847fc4
Added a copy of Config in the commons package. TODO: Remove it from artifacts-database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
51 * Name of the central configuration XML file. |
33f58a847fc4
Added a copy of Config in the commons package. TODO: Remove it from artifacts-database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
52 */ |
556 | 53 public static final String CONFIG_FILE = "conf.xml"; |
206
33f58a847fc4
Added a copy of Config in the commons package. TODO: Remove it from artifacts-database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
54 |
33f58a847fc4
Added a copy of Config in the commons package. TODO: Remove it from artifacts-database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
55 /** |
33f58a847fc4
Added a copy of Config in the commons package. TODO: Remove it from artifacts-database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
56 * Name of the configuration filename alias to be use |
33f58a847fc4
Added a copy of Config in the commons package. TODO: Remove it from artifacts-database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
57 * within the configuration. This alias is replaced by |
33f58a847fc4
Added a copy of Config in the commons package. TODO: Remove it from artifacts-database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
58 * the real path. |
33f58a847fc4
Added a copy of Config in the commons package. TODO: Remove it from artifacts-database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
59 */ |
556 | 60 public static final String CONFIG_DIR_PLACEHOLDER = "${artifacts.config.dir}"; |
206
33f58a847fc4
Added a copy of Config in the commons package. TODO: Remove it from artifacts-database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
61 |
33f58a847fc4
Added a copy of Config in the commons package. TODO: Remove it from artifacts-database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
62 private static Document config; |
33f58a847fc4
Added a copy of Config in the commons package. TODO: Remove it from artifacts-database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
63 |
33f58a847fc4
Added a copy of Config in the commons package. TODO: Remove it from artifacts-database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
64 private Config() { |
33f58a847fc4
Added a copy of Config in the commons package. TODO: Remove it from artifacts-database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
65 } |
33f58a847fc4
Added a copy of Config in the commons package. TODO: Remove it from artifacts-database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
66 |
33f58a847fc4
Added a copy of Config in the commons package. TODO: Remove it from artifacts-database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
67 /** |
33f58a847fc4
Added a copy of Config in the commons package. TODO: Remove it from artifacts-database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
68 * Singleton access to the central XML configuration document. |
556 | 69 * |
206
33f58a847fc4
Added a copy of Config in the commons package. TODO: Remove it from artifacts-database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
70 * @return The central XML configuration document. |
33f58a847fc4
Added a copy of Config in the commons package. TODO: Remove it from artifacts-database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
71 */ |
33f58a847fc4
Added a copy of Config in the commons package. TODO: Remove it from artifacts-database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
72 public static synchronized final Document getConfig() { |
33f58a847fc4
Added a copy of Config in the commons package. TODO: Remove it from artifacts-database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
73 if (config == null) { |
33f58a847fc4
Added a copy of Config in the commons package. TODO: Remove it from artifacts-database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
74 config = loadConfig(); |
33f58a847fc4
Added a copy of Config in the commons package. TODO: Remove it from artifacts-database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
75 } |
33f58a847fc4
Added a copy of Config in the commons package. TODO: Remove it from artifacts-database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
76 return config; |
33f58a847fc4
Added a copy of Config in the commons package. TODO: Remove it from artifacts-database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
77 } |
33f58a847fc4
Added a copy of Config in the commons package. TODO: Remove it from artifacts-database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
78 |
558
609ced80bcf0
Fixed: used java 7 feature although java 6 comliance level is configured
gernotbelger
parents:
556
diff
changeset
|
79 public static Properties loadProperties(final String CONFIG_FILE_LOCAL) throws IOException { |
556 | 80 final File configDir = getConfigDirectory(); |
81 final File configFile = new File(configDir, CONFIG_FILE_LOCAL); | |
82 | |
558
609ced80bcf0
Fixed: used java 7 feature although java 6 comliance level is configured
gernotbelger
parents:
556
diff
changeset
|
83 InputStream reader = null; |
556 | 84 try { |
558
609ced80bcf0
Fixed: used java 7 feature although java 6 comliance level is configured
gernotbelger
parents:
556
diff
changeset
|
85 reader = new BufferedInputStream(new FileInputStream(configFile)); |
609ced80bcf0
Fixed: used java 7 feature although java 6 comliance level is configured
gernotbelger
parents:
556
diff
changeset
|
86 |
609ced80bcf0
Fixed: used java 7 feature although java 6 comliance level is configured
gernotbelger
parents:
556
diff
changeset
|
87 final Properties properties = new Properties(); |
556 | 88 properties.load(reader); |
558
609ced80bcf0
Fixed: used java 7 feature although java 6 comliance level is configured
gernotbelger
parents:
556
diff
changeset
|
89 return properties; |
609ced80bcf0
Fixed: used java 7 feature although java 6 comliance level is configured
gernotbelger
parents:
556
diff
changeset
|
90 } finally { |
609ced80bcf0
Fixed: used java 7 feature although java 6 comliance level is configured
gernotbelger
parents:
556
diff
changeset
|
91 try { |
609ced80bcf0
Fixed: used java 7 feature although java 6 comliance level is configured
gernotbelger
parents:
556
diff
changeset
|
92 if (reader != null) |
609ced80bcf0
Fixed: used java 7 feature although java 6 comliance level is configured
gernotbelger
parents:
556
diff
changeset
|
93 reader.close(); |
609ced80bcf0
Fixed: used java 7 feature although java 6 comliance level is configured
gernotbelger
parents:
556
diff
changeset
|
94 } |
609ced80bcf0
Fixed: used java 7 feature although java 6 comliance level is configured
gernotbelger
parents:
556
diff
changeset
|
95 catch (final IOException e1) { |
609ced80bcf0
Fixed: used java 7 feature although java 6 comliance level is configured
gernotbelger
parents:
556
diff
changeset
|
96 e1.printStackTrace(); |
609ced80bcf0
Fixed: used java 7 feature although java 6 comliance level is configured
gernotbelger
parents:
556
diff
changeset
|
97 } |
556 | 98 } |
99 } | |
100 | |
206
33f58a847fc4
Added a copy of Config in the commons package. TODO: Remove it from artifacts-database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
101 /** |
33f58a847fc4
Added a copy of Config in the commons package. TODO: Remove it from artifacts-database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
102 * Returns the path to the configuartion directory. If a path |
33f58a847fc4
Added a copy of Config in the commons package. TODO: Remove it from artifacts-database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
103 * was specified via the CONFIG_DIR system property this one |
33f58a847fc4
Added a copy of Config in the commons package. TODO: Remove it from artifacts-database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
104 * is used. Else it falls back to default configuration path. |
556 | 105 * |
206
33f58a847fc4
Added a copy of Config in the commons package. TODO: Remove it from artifacts-database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
106 * @return The path to the configuartion directory. |
33f58a847fc4
Added a copy of Config in the commons package. TODO: Remove it from artifacts-database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
107 */ |
33f58a847fc4
Added a copy of Config in the commons package. TODO: Remove it from artifacts-database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
108 public static File getConfigDirectory() { |
556 | 109 final String configDirString = System.getProperty(CONFIG_DIR); |
206
33f58a847fc4
Added a copy of Config in the commons package. TODO: Remove it from artifacts-database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
110 |
556 | 111 File configDir = configDirString != null ? new File(configDirString) : CONFIG_DIR_DEFAULT; |
206
33f58a847fc4
Added a copy of Config in the commons package. TODO: Remove it from artifacts-database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
112 |
33f58a847fc4
Added a copy of Config in the commons package. TODO: Remove it from artifacts-database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
113 if (!configDir.isDirectory()) { |
33f58a847fc4
Added a copy of Config in the commons package. TODO: Remove it from artifacts-database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
114 logger.warn("'" + configDir + "' is not a directory."); |
33f58a847fc4
Added a copy of Config in the commons package. TODO: Remove it from artifacts-database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
115 configDir = CONFIG_DIR_DEFAULT; |
33f58a847fc4
Added a copy of Config in the commons package. TODO: Remove it from artifacts-database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
116 } |
33f58a847fc4
Added a copy of Config in the commons package. TODO: Remove it from artifacts-database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
117 |
33f58a847fc4
Added a copy of Config in the commons package. TODO: Remove it from artifacts-database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
118 return configDir; |
33f58a847fc4
Added a copy of Config in the commons package. TODO: Remove it from artifacts-database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
119 } |
33f58a847fc4
Added a copy of Config in the commons package. TODO: Remove it from artifacts-database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
120 |
33f58a847fc4
Added a copy of Config in the commons package. TODO: Remove it from artifacts-database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
121 /** |
33f58a847fc4
Added a copy of Config in the commons package. TODO: Remove it from artifacts-database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
122 * Replaces the CONFIG_DIR_PLACEHOLDER alias with the real path |
33f58a847fc4
Added a copy of Config in the commons package. TODO: Remove it from artifacts-database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
123 * of the configuration directory. |
556 | 124 * |
125 * @param path | |
126 * The path containing the CONFIG_DIR_PLACEHOLDER placeholder. | |
206
33f58a847fc4
Added a copy of Config in the commons package. TODO: Remove it from artifacts-database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
127 * @return The path where the CONFIG_DIR_PLACEHOLDER placeholders are |
556 | 128 * replaced by the real path name. |
206
33f58a847fc4
Added a copy of Config in the commons package. TODO: Remove it from artifacts-database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
129 */ |
556 | 130 public static String replaceConfigDir(final String path) { |
131 final String configDir = getConfigDirectory().getAbsolutePath(); | |
206
33f58a847fc4
Added a copy of Config in the commons package. TODO: Remove it from artifacts-database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
132 return path.replace(CONFIG_DIR_PLACEHOLDER, configDir); |
33f58a847fc4
Added a copy of Config in the commons package. TODO: Remove it from artifacts-database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
133 } |
33f58a847fc4
Added a copy of Config in the commons package. TODO: Remove it from artifacts-database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
134 |
33f58a847fc4
Added a copy of Config in the commons package. TODO: Remove it from artifacts-database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
135 private static Document loadConfig() { |
33f58a847fc4
Added a copy of Config in the commons package. TODO: Remove it from artifacts-database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
136 |
556 | 137 final File configDir = getConfigDirectory(); |
206
33f58a847fc4
Added a copy of Config in the commons package. TODO: Remove it from artifacts-database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
138 |
556 | 139 final File file = new File(configDir, CONFIG_FILE); |
206
33f58a847fc4
Added a copy of Config in the commons package. TODO: Remove it from artifacts-database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
140 |
33f58a847fc4
Added a copy of Config in the commons package. TODO: Remove it from artifacts-database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
141 if (!file.canRead() && !file.isFile()) { |
556 | 142 logger.error("Cannot read config file '" + file + "'."); |
206
33f58a847fc4
Added a copy of Config in the commons package. TODO: Remove it from artifacts-database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
143 return null; |
33f58a847fc4
Added a copy of Config in the commons package. TODO: Remove it from artifacts-database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
144 } |
33f58a847fc4
Added a copy of Config in the commons package. TODO: Remove it from artifacts-database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
145 |
33f58a847fc4
Added a copy of Config in the commons package. TODO: Remove it from artifacts-database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
146 try { |
556 | 147 final DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); |
206
33f58a847fc4
Added a copy of Config in the commons package. TODO: Remove it from artifacts-database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
148 factory.setValidating(false); // XXX: This may change in future. |
33f58a847fc4
Added a copy of Config in the commons package. TODO: Remove it from artifacts-database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
149 return factory.newDocumentBuilder().parse(file); |
33f58a847fc4
Added a copy of Config in the commons package. TODO: Remove it from artifacts-database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
150 } |
556 | 151 catch (final SAXException se) { |
206
33f58a847fc4
Added a copy of Config in the commons package. TODO: Remove it from artifacts-database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
152 logger.error(se.getLocalizedMessage(), se); |
33f58a847fc4
Added a copy of Config in the commons package. TODO: Remove it from artifacts-database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
153 } |
556 | 154 catch (final ParserConfigurationException pce) { |
206
33f58a847fc4
Added a copy of Config in the commons package. TODO: Remove it from artifacts-database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
155 logger.error(pce.getLocalizedMessage(), pce); |
33f58a847fc4
Added a copy of Config in the commons package. TODO: Remove it from artifacts-database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
156 } |
556 | 157 catch (final IOException ioe) { |
206
33f58a847fc4
Added a copy of Config in the commons package. TODO: Remove it from artifacts-database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
158 logger.error(ioe.getLocalizedMessage()); |
33f58a847fc4
Added a copy of Config in the commons package. TODO: Remove it from artifacts-database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
159 } |
33f58a847fc4
Added a copy of Config in the commons package. TODO: Remove it from artifacts-database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
160 |
33f58a847fc4
Added a copy of Config in the commons package. TODO: Remove it from artifacts-database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
161 return null; |
33f58a847fc4
Added a copy of Config in the commons package. TODO: Remove it from artifacts-database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
162 } |
33f58a847fc4
Added a copy of Config in the commons package. TODO: Remove it from artifacts-database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
163 |
33f58a847fc4
Added a copy of Config in the commons package. TODO: Remove it from artifacts-database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
164 /** |
33f58a847fc4
Added a copy of Config in the commons package. TODO: Remove it from artifacts-database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
165 * Convenience method to search within a given document tree via XPath. |
33f58a847fc4
Added a copy of Config in the commons package. TODO: Remove it from artifacts-database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
166 * See {@link XMLUtils#xpath(Object, String, QName) } for details. |
556 | 167 * |
168 * @param root | |
169 * The object which is used as the root of the tree to | |
170 * be searched in. | |
171 * @param query | |
172 * The XPath query. | |
173 * @param returnType | |
174 * The type of the result. | |
206
33f58a847fc4
Added a copy of Config in the commons package. TODO: Remove it from artifacts-database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
175 * @return The result of type 'returnTyp' or null if something went |
556 | 176 * wrong during XPath evaluation. |
206
33f58a847fc4
Added a copy of Config in the commons package. TODO: Remove it from artifacts-database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
177 */ |
556 | 178 public static final Object getXPath(final Object root, final String query, final QName returnType) { |
206
33f58a847fc4
Added a copy of Config in the commons package. TODO: Remove it from artifacts-database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
179 return XMLUtils.xpath(root, query, returnType); |
33f58a847fc4
Added a copy of Config in the commons package. TODO: Remove it from artifacts-database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
180 } |
33f58a847fc4
Added a copy of Config in the commons package. TODO: Remove it from artifacts-database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
181 |
33f58a847fc4
Added a copy of Config in the commons package. TODO: Remove it from artifacts-database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
182 /** |
33f58a847fc4
Added a copy of Config in the commons package. TODO: Remove it from artifacts-database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
183 * Convenience method to search within the central configuration via XPath. |
33f58a847fc4
Added a copy of Config in the commons package. TODO: Remove it from artifacts-database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
184 * See {@link XMLUtils#xpath(Object, String, QName) } for details. |
556 | 185 * |
186 * @param query | |
187 * The XPath query. | |
188 * @param returnType | |
189 * The type of the result. | |
206
33f58a847fc4
Added a copy of Config in the commons package. TODO: Remove it from artifacts-database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
190 * @return The result of type 'returnTyp' or null if something went |
556 | 191 * wrong during XPath evaluation. |
206
33f58a847fc4
Added a copy of Config in the commons package. TODO: Remove it from artifacts-database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
192 */ |
556 | 193 public static final Object getXPath(final String query, final QName returnType) { |
206
33f58a847fc4
Added a copy of Config in the commons package. TODO: Remove it from artifacts-database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
194 return XMLUtils.xpath(getConfig(), query, returnType); |
33f58a847fc4
Added a copy of Config in the commons package. TODO: Remove it from artifacts-database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
195 } |
33f58a847fc4
Added a copy of Config in the commons package. TODO: Remove it from artifacts-database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
196 |
33f58a847fc4
Added a copy of Config in the commons package. TODO: Remove it from artifacts-database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
197 /** |
33f58a847fc4
Added a copy of Config in the commons package. TODO: Remove it from artifacts-database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
198 * Convenience method to search for a node list within the central |
33f58a847fc4
Added a copy of Config in the commons package. TODO: Remove it from artifacts-database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
199 * configuation document via XPath. |
556 | 200 * |
201 * @param query | |
202 * The XPath query. | |
206
33f58a847fc4
Added a copy of Config in the commons package. TODO: Remove it from artifacts-database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
203 * @return The queried node list or null if something went |
556 | 204 * wrong during XPath evaluation. |
206
33f58a847fc4
Added a copy of Config in the commons package. TODO: Remove it from artifacts-database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
205 */ |
556 | 206 public static final NodeList getNodeSetXPath(final String query) { |
207 return (NodeList) getXPath(query, XPathConstants.NODESET); | |
206
33f58a847fc4
Added a copy of Config in the commons package. TODO: Remove it from artifacts-database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
208 } |
33f58a847fc4
Added a copy of Config in the commons package. TODO: Remove it from artifacts-database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
209 |
33f58a847fc4
Added a copy of Config in the commons package. TODO: Remove it from artifacts-database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
210 /** |
33f58a847fc4
Added a copy of Config in the commons package. TODO: Remove it from artifacts-database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
211 * Convenience method to search for a node within the central |
33f58a847fc4
Added a copy of Config in the commons package. TODO: Remove it from artifacts-database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
212 * configuation document via XPath. |
556 | 213 * |
214 * @param query | |
215 * The XPath query. | |
206
33f58a847fc4
Added a copy of Config in the commons package. TODO: Remove it from artifacts-database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
216 * @return The queried node or null if something went |
556 | 217 * wrong during XPath evaluation. |
206
33f58a847fc4
Added a copy of Config in the commons package. TODO: Remove it from artifacts-database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
218 */ |
556 | 219 public static final Node getNodeXPath(final String query) { |
220 return (Node) getXPath(query, XPathConstants.NODE); | |
206
33f58a847fc4
Added a copy of Config in the commons package. TODO: Remove it from artifacts-database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
221 } |
33f58a847fc4
Added a copy of Config in the commons package. TODO: Remove it from artifacts-database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
222 |
33f58a847fc4
Added a copy of Config in the commons package. TODO: Remove it from artifacts-database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
223 /** |
33f58a847fc4
Added a copy of Config in the commons package. TODO: Remove it from artifacts-database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
224 * Convenience method to search for a string within the central |
33f58a847fc4
Added a copy of Config in the commons package. TODO: Remove it from artifacts-database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
225 * configuation document via XPath. |
556 | 226 * |
227 * @param xpath | |
228 * The XPath query. | |
206
33f58a847fc4
Added a copy of Config in the commons package. TODO: Remove it from artifacts-database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
229 * @return The queried string or null if something went |
556 | 230 * wrong during XPath evaluation. |
206
33f58a847fc4
Added a copy of Config in the commons package. TODO: Remove it from artifacts-database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
231 */ |
556 | 232 public static final String getStringXPath(final String xpath) { |
206
33f58a847fc4
Added a copy of Config in the commons package. TODO: Remove it from artifacts-database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
233 return getStringXPath(xpath, null); |
33f58a847fc4
Added a copy of Config in the commons package. TODO: Remove it from artifacts-database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
234 } |
33f58a847fc4
Added a copy of Config in the commons package. TODO: Remove it from artifacts-database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
235 |
33f58a847fc4
Added a copy of Config in the commons package. TODO: Remove it from artifacts-database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
236 /** |
33f58a847fc4
Added a copy of Config in the commons package. TODO: Remove it from artifacts-database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
237 * Convenience method to search for a string within the central |
33f58a847fc4
Added a copy of Config in the commons package. TODO: Remove it from artifacts-database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
238 * configuation document via XPath. |
556 | 239 * |
240 * @param query | |
241 * The XPath query. | |
242 * @param def | |
243 * The string to be returned if the search has no results. | |
206
33f58a847fc4
Added a copy of Config in the commons package. TODO: Remove it from artifacts-database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
244 * @return The queried string or the default value if something went |
556 | 245 * wrong during XPath evaluation. |
206
33f58a847fc4
Added a copy of Config in the commons package. TODO: Remove it from artifacts-database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
246 */ |
556 | 247 public static final String getStringXPath(final String query, final String def) { |
248 final String s = (String) getXPath(query, XPathConstants.STRING); | |
249 return s == null || s.length() == 0 ? def : s; | |
206
33f58a847fc4
Added a copy of Config in the commons package. TODO: Remove it from artifacts-database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
250 } |
33f58a847fc4
Added a copy of Config in the commons package. TODO: Remove it from artifacts-database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
251 |
33f58a847fc4
Added a copy of Config in the commons package. TODO: Remove it from artifacts-database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
252 /** |
33f58a847fc4
Added a copy of Config in the commons package. TODO: Remove it from artifacts-database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
253 * Convenience method to search for a node list within a given tree |
33f58a847fc4
Added a copy of Config in the commons package. TODO: Remove it from artifacts-database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
254 * via XPath. |
556 | 255 * |
256 * @param root | |
257 * The root of the tree to be searched in. | |
258 * @param query | |
259 * The XPath query. | |
206
33f58a847fc4
Added a copy of Config in the commons package. TODO: Remove it from artifacts-database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
260 * @return The queried node list or null if something went |
556 | 261 * wrong during XPath evaluation. |
206
33f58a847fc4
Added a copy of Config in the commons package. TODO: Remove it from artifacts-database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
262 */ |
556 | 263 public static final NodeList getNodeSetXPath(final Object root, final String query) { |
264 return (NodeList) getXPath(root, query, XPathConstants.NODESET); | |
206
33f58a847fc4
Added a copy of Config in the commons package. TODO: Remove it from artifacts-database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
265 } |
33f58a847fc4
Added a copy of Config in the commons package. TODO: Remove it from artifacts-database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
266 |
33f58a847fc4
Added a copy of Config in the commons package. TODO: Remove it from artifacts-database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
267 /** |
33f58a847fc4
Added a copy of Config in the commons package. TODO: Remove it from artifacts-database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
268 * Convenience method to search for a node within a given tree |
33f58a847fc4
Added a copy of Config in the commons package. TODO: Remove it from artifacts-database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
269 * via XPath. |
556 | 270 * |
271 * @param root | |
272 * The root of the tree to be searched in. | |
273 * @param query | |
274 * The XPath query. | |
206
33f58a847fc4
Added a copy of Config in the commons package. TODO: Remove it from artifacts-database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
275 * @return The queried node or null if something went |
556 | 276 * wrong during XPath evaluation. |
206
33f58a847fc4
Added a copy of Config in the commons package. TODO: Remove it from artifacts-database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
277 */ |
556 | 278 public static final Node getNodeXPath(final Object root, final String query) { |
279 return (Node) getXPath(root, query, XPathConstants.NODE); | |
206
33f58a847fc4
Added a copy of Config in the commons package. TODO: Remove it from artifacts-database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
280 } |
33f58a847fc4
Added a copy of Config in the commons package. TODO: Remove it from artifacts-database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
281 |
33f58a847fc4
Added a copy of Config in the commons package. TODO: Remove it from artifacts-database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
282 /** |
33f58a847fc4
Added a copy of Config in the commons package. TODO: Remove it from artifacts-database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
283 * Convenience method to search for a string within a given tree |
33f58a847fc4
Added a copy of Config in the commons package. TODO: Remove it from artifacts-database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
284 * via XPath. |
556 | 285 * |
286 * @param root | |
287 * The root of the tree to be searched in. | |
288 * @param xpath | |
289 * The XPath query. | |
206
33f58a847fc4
Added a copy of Config in the commons package. TODO: Remove it from artifacts-database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
290 * @return The queried string or null if something went |
556 | 291 * wrong during XPath evaluation. |
206
33f58a847fc4
Added a copy of Config in the commons package. TODO: Remove it from artifacts-database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
292 */ |
556 | 293 public static final String getStringXPath(final Object root, final String xpath) { |
206
33f58a847fc4
Added a copy of Config in the commons package. TODO: Remove it from artifacts-database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
294 return getStringXPath(root, xpath, null); |
33f58a847fc4
Added a copy of Config in the commons package. TODO: Remove it from artifacts-database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
295 } |
33f58a847fc4
Added a copy of Config in the commons package. TODO: Remove it from artifacts-database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
296 |
33f58a847fc4
Added a copy of Config in the commons package. TODO: Remove it from artifacts-database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
297 /** |
33f58a847fc4
Added a copy of Config in the commons package. TODO: Remove it from artifacts-database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
298 * Convenience method to search for a string within a given tree |
33f58a847fc4
Added a copy of Config in the commons package. TODO: Remove it from artifacts-database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
299 * via XPath. |
556 | 300 * |
301 * @param root | |
302 * The root of the tree to be searched in. | |
303 * @param query | |
304 * xpath The XPath query. | |
305 * @param def | |
306 * The string to be returned if the search has no results. | |
206
33f58a847fc4
Added a copy of Config in the commons package. TODO: Remove it from artifacts-database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
307 * @return The queried string or the default value if something went |
556 | 308 * wrong during XPath evaluation. |
206
33f58a847fc4
Added a copy of Config in the commons package. TODO: Remove it from artifacts-database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
309 */ |
556 | 310 public static final String getStringXPath(final Object root, final String query, final String def) { |
311 final String s = (String) getXPath(root, query, XPathConstants.STRING); | |
312 return s == null || s.length() == 0 ? def : s; | |
206
33f58a847fc4
Added a copy of Config in the commons package. TODO: Remove it from artifacts-database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
313 } |
33f58a847fc4
Added a copy of Config in the commons package. TODO: Remove it from artifacts-database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
314 } |
33f58a847fc4
Added a copy of Config in the commons package. TODO: Remove it from artifacts-database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
315 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |