Mercurial > dive4elements > framework
annotate artifacts-common/src/main/java/org/dive4elements/artifacts/common/utils/Config.java @ 570:584591f8203c 3.2.x
Upgrade to Log4j 2
author | Tom Gottfried <tom@intevation.de> |
---|---|
date | Mon, 28 Feb 2022 17:41:14 +0100 |
parents | 415df0fc4fa1 |
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 |
33f58a847fc4
Added a copy of Config in the commons package. TODO: Remove it from artifacts-database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
11 import java.io.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
|
12 import java.io.IOException; |
33f58a847fc4
Added a copy of Config in the commons package. TODO: Remove it from artifacts-database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
13 |
33f58a847fc4
Added 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 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
|
15 |
33f58a847fc4
Added a copy of Config in the commons package. TODO: Remove it from artifacts-database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
16 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
|
17 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
|
18 |
33f58a847fc4
Added 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.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
|
20 |
570 | 21 import org.apache.logging.log4j.Logger; |
22 import org.apache.logging.log4j.LogManager; | |
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
|
23 |
33f58a847fc4
Added 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 |
33f58a847fc4
Added 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 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
|
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 /** |
33f58a847fc4
Added 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 * 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
|
32 * 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
|
33 * 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
|
34 * |
33f58a847fc4
Added 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 * @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
|
36 */ |
33f58a847fc4
Added 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 public final class 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
|
38 { |
570 | 39 private static Logger logger = LogManager.getLogger(Config.class); |
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
|
40 |
33f58a847fc4
Added 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 * 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
|
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 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
|
45 |
33f58a847fc4
Added 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 /** |
33f58a847fc4
Added 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 * 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
|
48 * 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
|
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 public static final File 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
|
51 new File(new File(System.getProperty("user.home", |
33f58a847fc4
Added 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 System.getProperty("user.dir", "."))), ".artifactdb"); |
33f58a847fc4
Added a copy of Config in the commons package. TODO: Remove it from artifacts-database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
53 |
33f58a847fc4
Added 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 * 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
|
56 */ |
33f58a847fc4
Added 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 public static final String CONFIG_FILE = "conf.xml"; |
33f58a847fc4
Added 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 |
33f58a847fc4
Added 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 /** |
33f58a847fc4
Added a copy of Config in the commons package. TODO: Remove it from artifacts-database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
60 * 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
|
61 * 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
|
62 * 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
|
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 public static final String CONFIG_DIR_PLACEHOLDER = |
33f58a847fc4
Added 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 "${artifacts.config.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
|
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 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
|
68 |
33f58a847fc4
Added a copy of Config in the commons package. TODO: Remove it from artifacts-database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
69 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
|
70 } |
33f58a847fc4
Added 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 /** |
33f58a847fc4
Added 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 * Singleton access to 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
|
74 * @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
|
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 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
|
77 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
|
78 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
|
79 } |
33f58a847fc4
Added a copy of Config in the commons package. TODO: Remove it from artifacts-database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
80 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
|
81 } |
33f58a847fc4
Added a copy of Config in the commons package. TODO: Remove it from artifacts-database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
82 |
33f58a847fc4
Added a copy of Config in the commons package. TODO: Remove it from artifacts-database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
83 /** |
33f58a847fc4
Added a copy of Config in the commons package. TODO: Remove it from artifacts-database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
84 * 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
|
85 * 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
|
86 * is used. Else it falls back to default configuration 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
|
87 * @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
|
88 */ |
33f58a847fc4
Added a copy of Config in the commons package. TODO: Remove it from artifacts-database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
89 public static File getConfigDirectory() { |
33f58a847fc4
Added a copy of Config in the commons package. TODO: Remove it from artifacts-database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
90 String configDirString = System.getProperty(CONFIG_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
|
91 |
33f58a847fc4
Added a copy of Config in the commons package. TODO: Remove it from artifacts-database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
92 File configDir = configDirString != 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
|
93 ? new File(configDirString) |
33f58a847fc4
Added a copy of Config in the commons package. TODO: Remove it from artifacts-database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
94 : 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
|
95 |
33f58a847fc4
Added a copy of Config in the commons package. TODO: Remove it from artifacts-database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
96 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
|
97 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
|
98 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
|
99 } |
33f58a847fc4
Added 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 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
|
102 } |
33f58a847fc4
Added 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 |
33f58a847fc4
Added 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 /** |
33f58a847fc4
Added 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 * 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
|
106 * of 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
|
107 * @param path The path containing the CONFIG_DIR_PLACEHOLDER placeholder. |
33f58a847fc4
Added 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 * @return The path where the CONFIG_DIR_PLACEHOLDER placeholders are |
33f58a847fc4
Added 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 * replaced by the real path name. |
33f58a847fc4
Added 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 */ |
33f58a847fc4
Added 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 public static String replaceConfigDir(String 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
|
112 String configDir = getConfigDirectory().getAbsolutePath(); |
33f58a847fc4
Added 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 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
|
114 } |
33f58a847fc4
Added 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 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
|
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 File configDir = getConfigDirectory(); |
33f58a847fc4
Added 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 File file = new File(configDir, CONFIG_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
|
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 if (!file.canRead() && !file.isFile()) { |
33f58a847fc4
Added 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 logger.error("Cannot read config 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
|
124 + 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
|
125 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
|
126 } |
33f58a847fc4
Added 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 |
33f58a847fc4
Added a copy of Config in the commons package. TODO: Remove it from artifacts-database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
128 try { |
33f58a847fc4
Added 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 DocumentBuilderFactory factory = |
33f58a847fc4
Added a copy of Config in the commons package. TODO: Remove it from artifacts-database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
130 DocumentBuilderFactory.newInstance(); |
33f58a847fc4
Added a copy of Config in the commons package. TODO: Remove it from artifacts-database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
131 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
|
132 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
|
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 catch (SAXException 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
|
135 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
|
136 } |
33f58a847fc4
Added 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 catch (ParserConfigurationException 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
|
138 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
|
139 } |
33f58a847fc4
Added 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 catch (IOException ioe) { |
33f58a847fc4
Added 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 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
|
142 } |
33f58a847fc4
Added 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 |
33f58a847fc4
Added 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 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
|
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 |
33f58a847fc4
Added 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 * 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
|
149 * See {@link XMLUtils#xpath(Object, String, QName) } 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
|
150 * @param root The object which is used as the root of the tree to |
33f58a847fc4
Added a copy of Config in the commons package. TODO: Remove it from artifacts-database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
151 * be searched in. |
33f58a847fc4
Added 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 * @param query The XPath query. |
33f58a847fc4
Added 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 * @param returnType The type of the result. |
33f58a847fc4
Added 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 * @return The result of type 'returnTyp' or null if something went |
33f58a847fc4
Added 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 * wrong during XPath evaluation. |
33f58a847fc4
Added 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 */ |
33f58a847fc4
Added 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 public static final Object getXPath( |
33f58a847fc4
Added 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 Object root, String query, QName 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
|
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 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
|
161 } |
33f58a847fc4
Added 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 * 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
|
165 * See {@link XMLUtils#xpath(Object, String, QName) } 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
|
166 * @param query The XPath query. |
33f58a847fc4
Added 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 * @param returnType The type of the result. |
33f58a847fc4
Added a copy of Config in the commons package. TODO: Remove it from artifacts-database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
168 * @return The result of type 'returnTyp' or null if something went |
33f58a847fc4
Added 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 * wrong during XPath evaluation. |
33f58a847fc4
Added 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 */ |
33f58a847fc4
Added a copy of Config in the commons package. TODO: Remove it from artifacts-database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
171 public static final Object getXPath(String query, QName 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
|
172 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
|
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 /** |
33f58a847fc4
Added 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 * 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
|
177 * configuation document 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
|
178 * @param query The XPath query. |
33f58a847fc4
Added 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 The queried node list or null if something went |
33f58a847fc4
Added 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 * wrong during XPath evaluation. |
33f58a847fc4
Added 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 public static final NodeList getNodeSetXPath(String query) { |
33f58a847fc4
Added 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 return (NodeList)getXPath(query, XPathConstants.NODESET); |
33f58a847fc4
Added 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 } |
33f58a847fc4
Added a copy of Config in the commons package. TODO: Remove it from artifacts-database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
185 |
33f58a847fc4
Added a copy of Config in the commons package. TODO: Remove it from artifacts-database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
186 /** |
33f58a847fc4
Added a copy of Config in the commons package. TODO: Remove it from artifacts-database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
187 * 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
|
188 * configuation document 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
|
189 * @param query The XPath query. |
33f58a847fc4
Added 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 queried node or null if something went |
33f58a847fc4
Added 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 * wrong during XPath evaluation. |
33f58a847fc4
Added 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 */ |
33f58a847fc4
Added 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 public static final Node getNodeXPath(String query) { |
33f58a847fc4
Added 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 (Node)getXPath(query, XPathConstants.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
|
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 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
|
199 * configuation document 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
|
200 * @param xpath The XPath query. |
33f58a847fc4
Added a copy of Config in the commons package. TODO: Remove it from artifacts-database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
201 * @return The queried string or null if something went |
33f58a847fc4
Added a copy of Config in the commons package. TODO: Remove it from artifacts-database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
202 * wrong during XPath evaluation. |
33f58a847fc4
Added 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 */ |
33f58a847fc4
Added 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 public static final String getStringXPath(String 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
|
205 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
|
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
|
207 |
33f58a847fc4
Added 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 * 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
|
210 * configuation document 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
|
211 * @param query The XPath query. |
33f58a847fc4
Added 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 * @param def The string to be returned if the search has no results. |
33f58a847fc4
Added 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 * @return The queried string or the default value if something went |
33f58a847fc4
Added a copy of Config in the commons package. TODO: Remove it from artifacts-database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
214 * wrong during XPath evaluation. |
33f58a847fc4
Added a copy of Config in the commons package. TODO: Remove it from artifacts-database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
215 */ |
33f58a847fc4
Added 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 public static final String getStringXPath(String query, String def) { |
33f58a847fc4
Added 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 String s = (String)getXPath(query, XPathConstants.STRING); |
33f58a847fc4
Added 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 return s == null || s.length() == 0 |
33f58a847fc4
Added 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 ? def |
33f58a847fc4
Added a copy of Config in the commons package. TODO: Remove it from artifacts-database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
220 : s; |
33f58a847fc4
Added 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 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
|
225 * 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
|
226 * @param root The root of the tree to be searched in. |
33f58a847fc4
Added a copy of Config in the commons package. TODO: Remove it from artifacts-database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
227 * @param query The XPath query. |
33f58a847fc4
Added a copy of Config in the commons package. TODO: Remove it from artifacts-database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
228 * @return The queried node list or null if something went |
33f58a847fc4
Added 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 * wrong during XPath evaluation. |
33f58a847fc4
Added 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 */ |
33f58a847fc4
Added 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 public static final NodeList getNodeSetXPath(Object root, String query) { |
33f58a847fc4
Added 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 return (NodeList)getXPath(root, query, XPathConstants.NODESET); |
33f58a847fc4
Added 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 } |
33f58a847fc4
Added 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 * 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
|
237 * 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
|
238 * @param root The root of the tree to be searched in. |
33f58a847fc4
Added 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 * @param query The XPath query. |
33f58a847fc4
Added a copy of Config in the commons package. TODO: Remove it from artifacts-database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
240 * @return The queried node or null if something went |
33f58a847fc4
Added a copy of Config in the commons package. TODO: Remove it from artifacts-database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
241 * wrong during XPath evaluation. |
33f58a847fc4
Added a copy of Config in the commons package. TODO: Remove it from artifacts-database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
242 */ |
33f58a847fc4
Added 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 public static final Node getNodeXPath(Object root, String query) { |
33f58a847fc4
Added 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 (Node)getXPath(root, query, XPathConstants.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
|
245 } |
33f58a847fc4
Added 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 |
33f58a847fc4
Added 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 /** |
33f58a847fc4
Added 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 * 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
|
249 * 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
|
250 * @param root The root of the tree to be searched in. |
33f58a847fc4
Added 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 * @param xpath The XPath query. |
33f58a847fc4
Added 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 * @return The queried string or null if something went |
33f58a847fc4
Added 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 * wrong during XPath evaluation. |
33f58a847fc4
Added 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 */ |
33f58a847fc4
Added a copy of Config in the commons package. TODO: Remove it from artifacts-database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
255 public static final String getStringXPath(Object root, String 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
|
256 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
|
257 } |
33f58a847fc4
Added 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 |
33f58a847fc4
Added a copy of Config in the commons package. TODO: Remove it from artifacts-database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
259 /** |
33f58a847fc4
Added 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 * 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
|
261 * 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
|
262 * @param root The root of the tree to be searched in. |
33f58a847fc4
Added a copy of Config in the commons package. TODO: Remove it from artifacts-database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
263 * @param query xpath The XPath query. |
33f58a847fc4
Added 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 * @param def The string to be returned if the search has no results. |
33f58a847fc4
Added 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 * @return The queried string or the default value if something went |
33f58a847fc4
Added 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 * wrong during XPath evaluation. |
33f58a847fc4
Added 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 public static final String getStringXPath( |
33f58a847fc4
Added 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 Object root, String query, String def |
33f58a847fc4
Added a copy of Config in the commons package. TODO: Remove it from artifacts-database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
270 ) { |
33f58a847fc4
Added a copy of Config in the commons package. TODO: Remove it from artifacts-database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
271 String s = (String)getXPath(root, query, XPathConstants.STRING); |
33f58a847fc4
Added a copy of Config in the commons package. TODO: Remove it from artifacts-database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
272 return s == null || s.length() == 0 |
33f58a847fc4
Added a copy of Config in the commons package. TODO: Remove it from artifacts-database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
273 ? def |
33f58a847fc4
Added 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 : s; |
33f58a847fc4
Added 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 } |
33f58a847fc4
Added 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 } |
33f58a847fc4
Added 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 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |