Mercurial > dive4elements > framework
annotate artifacts-common/src/main/java/org/dive4elements/artifacts/common/utils/Config.java @ 560:2b631f788ce1
modules-Config-Dir introduced
author | gernotbelger |
---|---|
date | Tue, 04 Sep 2018 16:44:31 +0200 |
parents | 609ced80bcf0 |
children |
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 |
560 | 79 public static Properties loadProperties(final String CONFIG_FILE_LOCAL, final File configDir) throws IOException { |
556 | 80 final File configFile = new File(configDir, CONFIG_FILE_LOCAL); |
81 | |
558
609ced80bcf0
Fixed: used java 7 feature although java 6 comliance level is configured
gernotbelger
parents:
556
diff
changeset
|
82 InputStream reader = null; |
556 | 83 try { |
558
609ced80bcf0
Fixed: used java 7 feature although java 6 comliance level is configured
gernotbelger
parents:
556
diff
changeset
|
84 reader = new BufferedInputStream(new FileInputStream(configFile)); |
609ced80bcf0
Fixed: used java 7 feature although java 6 comliance level is configured
gernotbelger
parents:
556
diff
changeset
|
85 |
609ced80bcf0
Fixed: used java 7 feature although java 6 comliance level is configured
gernotbelger
parents:
556
diff
changeset
|
86 final Properties properties = new Properties(); |
556 | 87 properties.load(reader); |
558
609ced80bcf0
Fixed: used java 7 feature although java 6 comliance level is configured
gernotbelger
parents:
556
diff
changeset
|
88 return properties; |
609ced80bcf0
Fixed: used java 7 feature although java 6 comliance level is configured
gernotbelger
parents:
556
diff
changeset
|
89 } finally { |
609ced80bcf0
Fixed: used java 7 feature although java 6 comliance level is configured
gernotbelger
parents:
556
diff
changeset
|
90 try { |
609ced80bcf0
Fixed: used java 7 feature although java 6 comliance level is configured
gernotbelger
parents:
556
diff
changeset
|
91 if (reader != null) |
609ced80bcf0
Fixed: used java 7 feature although java 6 comliance level is configured
gernotbelger
parents:
556
diff
changeset
|
92 reader.close(); |
609ced80bcf0
Fixed: used java 7 feature although java 6 comliance level is configured
gernotbelger
parents:
556
diff
changeset
|
93 } |
609ced80bcf0
Fixed: used java 7 feature although java 6 comliance level is configured
gernotbelger
parents:
556
diff
changeset
|
94 catch (final IOException e1) { |
609ced80bcf0
Fixed: used java 7 feature although java 6 comliance level is configured
gernotbelger
parents:
556
diff
changeset
|
95 e1.printStackTrace(); |
609ced80bcf0
Fixed: used java 7 feature although java 6 comliance level is configured
gernotbelger
parents:
556
diff
changeset
|
96 } |
556 | 97 } |
98 } | |
99 | |
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
|
100 /** |
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 * 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
|
102 * 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
|
103 * is used. Else it falls back to default configuration path. |
556 | 104 * |
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
|
105 * @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
|
106 */ |
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 public static File getConfigDirectory() { |
556 | 108 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
|
109 |
556 | 110 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
|
111 |
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 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
|
113 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
|
114 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
|
115 } |
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 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
|
118 } |
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 /** |
560 | 121 * returns the path to modules-config, which is a subfolder of config |
122 */ | |
123 public static File getModulesConfigDirectory() { | |
124 | |
125 final File configDir = getConfigDirectory(); | |
126 final File modulesCfgFile = new File(configDir, "modules"); | |
127 | |
128 if (!modulesCfgFile.isDirectory()) { | |
129 logger.warn("'" + modulesCfgFile + "' is not a directory."); | |
130 return CONFIG_DIR_DEFAULT; // or null? | |
131 } | |
132 return modulesCfgFile; | |
133 } | |
134 | |
135 /** | |
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
|
136 * 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
|
137 * of the configuration directory. |
556 | 138 * |
139 * @param path | |
140 * 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
|
141 * @return The path where the CONFIG_DIR_PLACEHOLDER placeholders are |
556 | 142 * 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
|
143 */ |
556 | 144 public static String replaceConfigDir(final String path) { |
145 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
|
146 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
|
147 } |
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 |
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 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
|
150 |
556 | 151 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
|
152 |
556 | 153 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
|
154 |
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 if (!file.canRead() && !file.isFile()) { |
556 | 156 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
|
157 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
|
158 } |
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 try { |
556 | 161 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
|
162 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
|
163 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
|
164 } |
556 | 165 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
|
166 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
|
167 } |
556 | 168 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
|
169 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
|
170 } |
556 | 171 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
|
172 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
|
173 } |
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
|
174 |
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 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
|
176 } |
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 |
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
|
178 /** |
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 * 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
|
180 * See {@link XMLUtils#xpath(Object, String, QName) } for details. |
556 | 181 * |
182 * @param root | |
183 * The object which is used as the root of the tree to | |
184 * be searched in. | |
185 * @param query | |
186 * The XPath query. | |
187 * @param returnType | |
188 * 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
|
189 * @return The result of type 'returnTyp' or null if something went |
556 | 190 * 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
|
191 */ |
556 | 192 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
|
193 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
|
194 } |
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 * 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
|
198 * See {@link XMLUtils#xpath(Object, String, QName) } for details. |
556 | 199 * |
200 * @param query | |
201 * The XPath query. | |
202 * @param returnType | |
203 * 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
|
204 * @return The result of type 'returnTyp' or null if something went |
556 | 205 * 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
|
206 */ |
556 | 207 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
|
208 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
|
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 /** |
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 * 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
|
213 * configuation document via XPath. |
556 | 214 * |
215 * @param query | |
216 * 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
|
217 * @return The queried node list or null if something went |
556 | 218 * 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
|
219 */ |
556 | 220 public static final NodeList getNodeSetXPath(final String query) { |
221 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
|
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 /** |
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 * 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
|
226 * configuation document via XPath. |
556 | 227 * |
228 * @param query | |
229 * 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
|
230 * @return The queried node or null if something went |
556 | 231 * 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
|
232 */ |
556 | 233 public static final Node getNodeXPath(final String query) { |
234 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
|
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 /** |
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 * 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
|
239 * configuation document via XPath. |
556 | 240 * |
241 * @param xpath | |
242 * 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
|
243 * @return The queried string or null if something went |
556 | 244 * 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
|
245 */ |
556 | 246 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
|
247 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
|
248 } |
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
|
249 |
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 * 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
|
252 * configuation document via XPath. |
556 | 253 * |
254 * @param query | |
255 * The XPath query. | |
256 * @param def | |
257 * 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
|
258 * @return The queried string or the default value if something went |
556 | 259 * 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
|
260 */ |
556 | 261 public static final String getStringXPath(final String query, final String def) { |
262 final String s = (String) getXPath(query, XPathConstants.STRING); | |
263 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
|
264 } |
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 * 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
|
268 * via XPath. |
556 | 269 * |
270 * @param root | |
271 * The root of the tree to be searched in. | |
272 * @param query | |
273 * 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
|
274 * @return The queried node list or null if something went |
556 | 275 * 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
|
276 */ |
556 | 277 public static final NodeList getNodeSetXPath(final Object root, final String query) { |
278 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
|
279 } |
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 * 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
|
283 * via XPath. |
556 | 284 * |
285 * @param root | |
286 * The root of the tree to be searched in. | |
287 * @param query | |
288 * 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
|
289 * @return The queried node or null if something went |
556 | 290 * 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
|
291 */ |
556 | 292 public static final Node getNodeXPath(final Object root, final String query) { |
293 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
|
294 } |
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 * 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
|
298 * via XPath. |
556 | 299 * |
300 * @param root | |
301 * The root of the tree to be searched in. | |
302 * @param xpath | |
303 * 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
|
304 * @return The queried string or null if something went |
556 | 305 * 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
|
306 */ |
556 | 307 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
|
308 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
|
309 } |
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
|
310 |
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
|
311 /** |
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
|
312 * 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
|
313 * via XPath. |
556 | 314 * |
315 * @param root | |
316 * The root of the tree to be searched in. | |
317 * @param query | |
318 * xpath The XPath query. | |
319 * @param def | |
320 * 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
|
321 * @return The queried string or the default value if something went |
556 | 322 * 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
|
323 */ |
556 | 324 public static final String getStringXPath(final Object root, final String query, final String def) { |
325 final String s = (String) getXPath(root, query, XPathConstants.STRING); | |
326 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
|
327 } |
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
|
328 } |
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
|
329 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |