annotate artifacts-common/src/main/java/org/dive4elements/artifacts/common/utils/Config.java @ 556:ba31ca213c88

loadConfig static method
author gernotbelger
date Tue, 26 Jun 2018 20:25:46 +0200
parents 415df0fc4fa1
children 609ced80bcf0
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;
556
ba31ca213c88 loadConfig static method
gernotbelger
parents: 475
diff changeset
13 import java.io.InputStreamReader;
ba31ca213c88 loadConfig static method
gernotbelger
parents: 475
diff changeset
14 import java.nio.charset.StandardCharsets;
ba31ca213c88 loadConfig static method
gernotbelger
parents: 475
diff changeset
15 import java.nio.file.Files;
ba31ca213c88 loadConfig static method
gernotbelger
parents: 475
diff changeset
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
ba31ca213c88 loadConfig static method
gernotbelger
parents: 475
diff changeset
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
ba31ca213c88 loadConfig static method
gernotbelger
parents: 475
diff changeset
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
ba31ca213c88 loadConfig static method
gernotbelger
parents: 475
diff changeset
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
ba31ca213c88 loadConfig static method
gernotbelger
parents: 475
diff changeset
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
ba31ca213c88 loadConfig static method
gernotbelger
parents: 475
diff changeset
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
556
ba31ca213c88 loadConfig static method
gernotbelger
parents: 475
diff changeset
79 public static Properties loadProperties(final String CONFIG_FILE_LOCAL) {
ba31ca213c88 loadConfig static method
gernotbelger
parents: 475
diff changeset
80 final File configDir = getConfigDirectory();
ba31ca213c88 loadConfig static method
gernotbelger
parents: 475
diff changeset
81 final File configFile = new File(configDir, CONFIG_FILE_LOCAL);
ba31ca213c88 loadConfig static method
gernotbelger
parents: 475
diff changeset
82
ba31ca213c88 loadConfig static method
gernotbelger
parents: 475
diff changeset
83 final Properties properties = new Properties();
ba31ca213c88 loadConfig static method
gernotbelger
parents: 475
diff changeset
84 InputStreamReader reader;
ba31ca213c88 loadConfig static method
gernotbelger
parents: 475
diff changeset
85 try {
ba31ca213c88 loadConfig static method
gernotbelger
parents: 475
diff changeset
86 reader = new InputStreamReader(Files.newInputStream(configFile.toPath()), StandardCharsets.ISO_8859_1);
ba31ca213c88 loadConfig static method
gernotbelger
parents: 475
diff changeset
87 properties.load(reader);
ba31ca213c88 loadConfig static method
gernotbelger
parents: 475
diff changeset
88 }
ba31ca213c88 loadConfig static method
gernotbelger
parents: 475
diff changeset
89 catch (final IOException e) {
ba31ca213c88 loadConfig static method
gernotbelger
parents: 475
diff changeset
90 e.printStackTrace();
ba31ca213c88 loadConfig static method
gernotbelger
parents: 475
diff changeset
91 }
ba31ca213c88 loadConfig static method
gernotbelger
parents: 475
diff changeset
92
ba31ca213c88 loadConfig static method
gernotbelger
parents: 475
diff changeset
93 return properties;
ba31ca213c88 loadConfig static method
gernotbelger
parents: 475
diff changeset
94 }
ba31ca213c88 loadConfig static method
gernotbelger
parents: 475
diff changeset
95
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
96 /**
33f58a847fc4 Added 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 * 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
98 * 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
99 * is used. Else it falls back to default configuration path.
556
ba31ca213c88 loadConfig static method
gernotbelger
parents: 475
diff changeset
100 *
206
33f58a847fc4 Added a copy of Config in the commons package. TODO: Remove it from artifacts-database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
101 * @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
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 public static File getConfigDirectory() {
556
ba31ca213c88 loadConfig static method
gernotbelger
parents: 475
diff changeset
104 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
105
556
ba31ca213c88 loadConfig static method
gernotbelger
parents: 475
diff changeset
106 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
107
33f58a847fc4 Added a copy of Config in the commons package. TODO: Remove it from artifacts-database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
108 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
109 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
110 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
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
33f58a847fc4 Added 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 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 /**
33f58a847fc4 Added 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 * 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
118 * of the configuration directory.
556
ba31ca213c88 loadConfig static method
gernotbelger
parents: 475
diff changeset
119 *
ba31ca213c88 loadConfig static method
gernotbelger
parents: 475
diff changeset
120 * @param path
ba31ca213c88 loadConfig static method
gernotbelger
parents: 475
diff changeset
121 * 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
122 * @return The path where the CONFIG_DIR_PLACEHOLDER placeholders are
556
ba31ca213c88 loadConfig static method
gernotbelger
parents: 475
diff changeset
123 * 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
124 */
556
ba31ca213c88 loadConfig static method
gernotbelger
parents: 475
diff changeset
125 public static String replaceConfigDir(final String path) {
ba31ca213c88 loadConfig static method
gernotbelger
parents: 475
diff changeset
126 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
127 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
128 }
33f58a847fc4 Added 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
33f58a847fc4 Added 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 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
131
556
ba31ca213c88 loadConfig static method
gernotbelger
parents: 475
diff changeset
132 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
133
556
ba31ca213c88 loadConfig static method
gernotbelger
parents: 475
diff changeset
134 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
135
33f58a847fc4 Added 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 if (!file.canRead() && !file.isFile()) {
556
ba31ca213c88 loadConfig static method
gernotbelger
parents: 475
diff changeset
137 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
138 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
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
33f58a847fc4 Added 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 try {
556
ba31ca213c88 loadConfig static method
gernotbelger
parents: 475
diff changeset
142 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
143 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
144 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
145 }
556
ba31ca213c88 loadConfig static method
gernotbelger
parents: 475
diff changeset
146 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
147 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
148 }
556
ba31ca213c88 loadConfig static method
gernotbelger
parents: 475
diff changeset
149 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
150 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
151 }
556
ba31ca213c88 loadConfig static method
gernotbelger
parents: 475
diff changeset
152 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
153 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
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
33f58a847fc4 Added 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 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
157 }
33f58a847fc4 Added 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 * 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
161 * See {@link XMLUtils#xpath(Object, String, QName) } for details.
556
ba31ca213c88 loadConfig static method
gernotbelger
parents: 475
diff changeset
162 *
ba31ca213c88 loadConfig static method
gernotbelger
parents: 475
diff changeset
163 * @param root
ba31ca213c88 loadConfig static method
gernotbelger
parents: 475
diff changeset
164 * The object which is used as the root of the tree to
ba31ca213c88 loadConfig static method
gernotbelger
parents: 475
diff changeset
165 * be searched in.
ba31ca213c88 loadConfig static method
gernotbelger
parents: 475
diff changeset
166 * @param query
ba31ca213c88 loadConfig static method
gernotbelger
parents: 475
diff changeset
167 * The XPath query.
ba31ca213c88 loadConfig static method
gernotbelger
parents: 475
diff changeset
168 * @param returnType
ba31ca213c88 loadConfig static method
gernotbelger
parents: 475
diff changeset
169 * 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
170 * @return The result of type 'returnTyp' or null if something went
556
ba31ca213c88 loadConfig static method
gernotbelger
parents: 475
diff changeset
171 * 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
172 */
556
ba31ca213c88 loadConfig static method
gernotbelger
parents: 475
diff changeset
173 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
174 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
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
33f58a847fc4 Added 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 * 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
179 * See {@link XMLUtils#xpath(Object, String, QName) } for details.
556
ba31ca213c88 loadConfig static method
gernotbelger
parents: 475
diff changeset
180 *
ba31ca213c88 loadConfig static method
gernotbelger
parents: 475
diff changeset
181 * @param query
ba31ca213c88 loadConfig static method
gernotbelger
parents: 475
diff changeset
182 * The XPath query.
ba31ca213c88 loadConfig static method
gernotbelger
parents: 475
diff changeset
183 * @param returnType
ba31ca213c88 loadConfig static method
gernotbelger
parents: 475
diff changeset
184 * 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
185 * @return The result of type 'returnTyp' or null if something went
556
ba31ca213c88 loadConfig static method
gernotbelger
parents: 475
diff changeset
186 * 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
187 */
556
ba31ca213c88 loadConfig static method
gernotbelger
parents: 475
diff changeset
188 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
189 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
190 }
33f58a847fc4 Added 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
33f58a847fc4 Added 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 * 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
194 * configuation document via XPath.
556
ba31ca213c88 loadConfig static method
gernotbelger
parents: 475
diff changeset
195 *
ba31ca213c88 loadConfig static method
gernotbelger
parents: 475
diff changeset
196 * @param query
ba31ca213c88 loadConfig static method
gernotbelger
parents: 475
diff changeset
197 * 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
198 * @return The queried node list or null if something went
556
ba31ca213c88 loadConfig static method
gernotbelger
parents: 475
diff changeset
199 * 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
200 */
556
ba31ca213c88 loadConfig static method
gernotbelger
parents: 475
diff changeset
201 public static final NodeList getNodeSetXPath(final String query) {
ba31ca213c88 loadConfig static method
gernotbelger
parents: 475
diff changeset
202 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
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
33f58a847fc4 Added 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 /**
33f58a847fc4 Added 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 * 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
207 * configuation document via XPath.
556
ba31ca213c88 loadConfig static method
gernotbelger
parents: 475
diff changeset
208 *
ba31ca213c88 loadConfig static method
gernotbelger
parents: 475
diff changeset
209 * @param query
ba31ca213c88 loadConfig static method
gernotbelger
parents: 475
diff changeset
210 * 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
211 * @return The queried node or null if something went
556
ba31ca213c88 loadConfig static method
gernotbelger
parents: 475
diff changeset
212 * 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
213 */
556
ba31ca213c88 loadConfig static method
gernotbelger
parents: 475
diff changeset
214 public static final Node getNodeXPath(final String query) {
ba31ca213c88 loadConfig static method
gernotbelger
parents: 475
diff changeset
215 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
216 }
33f58a847fc4 Added 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
33f58a847fc4 Added 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 /**
33f58a847fc4 Added 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 * 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
220 * configuation document via XPath.
556
ba31ca213c88 loadConfig static method
gernotbelger
parents: 475
diff changeset
221 *
ba31ca213c88 loadConfig static method
gernotbelger
parents: 475
diff changeset
222 * @param xpath
ba31ca213c88 loadConfig static method
gernotbelger
parents: 475
diff changeset
223 * 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
224 * @return The queried string or null if something went
556
ba31ca213c88 loadConfig static method
gernotbelger
parents: 475
diff changeset
225 * 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
226 */
556
ba31ca213c88 loadConfig static method
gernotbelger
parents: 475
diff changeset
227 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
228 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
229 }
33f58a847fc4 Added 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 /**
33f58a847fc4 Added 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 * 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
233 * configuation document via XPath.
556
ba31ca213c88 loadConfig static method
gernotbelger
parents: 475
diff changeset
234 *
ba31ca213c88 loadConfig static method
gernotbelger
parents: 475
diff changeset
235 * @param query
ba31ca213c88 loadConfig static method
gernotbelger
parents: 475
diff changeset
236 * The XPath query.
ba31ca213c88 loadConfig static method
gernotbelger
parents: 475
diff changeset
237 * @param def
ba31ca213c88 loadConfig static method
gernotbelger
parents: 475
diff changeset
238 * 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
239 * @return The queried string or the default value if something went
556
ba31ca213c88 loadConfig static method
gernotbelger
parents: 475
diff changeset
240 * 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
241 */
556
ba31ca213c88 loadConfig static method
gernotbelger
parents: 475
diff changeset
242 public static final String getStringXPath(final String query, final String def) {
ba31ca213c88 loadConfig static method
gernotbelger
parents: 475
diff changeset
243 final String s = (String) getXPath(query, XPathConstants.STRING);
ba31ca213c88 loadConfig static method
gernotbelger
parents: 475
diff changeset
244 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
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 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
249 * via XPath.
556
ba31ca213c88 loadConfig static method
gernotbelger
parents: 475
diff changeset
250 *
ba31ca213c88 loadConfig static method
gernotbelger
parents: 475
diff changeset
251 * @param root
ba31ca213c88 loadConfig static method
gernotbelger
parents: 475
diff changeset
252 * The root of the tree to be searched in.
ba31ca213c88 loadConfig static method
gernotbelger
parents: 475
diff changeset
253 * @param query
ba31ca213c88 loadConfig static method
gernotbelger
parents: 475
diff changeset
254 * 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
255 * @return The queried node list or null if something went
556
ba31ca213c88 loadConfig static method
gernotbelger
parents: 475
diff changeset
256 * 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
257 */
556
ba31ca213c88 loadConfig static method
gernotbelger
parents: 475
diff changeset
258 public static final NodeList getNodeSetXPath(final Object root, final String query) {
ba31ca213c88 loadConfig static method
gernotbelger
parents: 475
diff changeset
259 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
260 }
33f58a847fc4 Added 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
33f58a847fc4 Added 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 /**
33f58a847fc4 Added 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 * 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
264 * via XPath.
556
ba31ca213c88 loadConfig static method
gernotbelger
parents: 475
diff changeset
265 *
ba31ca213c88 loadConfig static method
gernotbelger
parents: 475
diff changeset
266 * @param root
ba31ca213c88 loadConfig static method
gernotbelger
parents: 475
diff changeset
267 * The root of the tree to be searched in.
ba31ca213c88 loadConfig static method
gernotbelger
parents: 475
diff changeset
268 * @param query
ba31ca213c88 loadConfig static method
gernotbelger
parents: 475
diff changeset
269 * 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
270 * @return The queried node or null if something went
556
ba31ca213c88 loadConfig static method
gernotbelger
parents: 475
diff changeset
271 * 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
272 */
556
ba31ca213c88 loadConfig static method
gernotbelger
parents: 475
diff changeset
273 public static final Node getNodeXPath(final Object root, final String query) {
ba31ca213c88 loadConfig static method
gernotbelger
parents: 475
diff changeset
274 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
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 /**
33f58a847fc4 Added a copy of Config in the commons package. TODO: Remove it from artifacts-database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
278 * 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
279 * via XPath.
556
ba31ca213c88 loadConfig static method
gernotbelger
parents: 475
diff changeset
280 *
ba31ca213c88 loadConfig static method
gernotbelger
parents: 475
diff changeset
281 * @param root
ba31ca213c88 loadConfig static method
gernotbelger
parents: 475
diff changeset
282 * The root of the tree to be searched in.
ba31ca213c88 loadConfig static method
gernotbelger
parents: 475
diff changeset
283 * @param xpath
ba31ca213c88 loadConfig static method
gernotbelger
parents: 475
diff changeset
284 * 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
285 * @return The queried string or null if something went
556
ba31ca213c88 loadConfig static method
gernotbelger
parents: 475
diff changeset
286 * 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
287 */
556
ba31ca213c88 loadConfig static method
gernotbelger
parents: 475
diff changeset
288 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
289 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
290 }
33f58a847fc4 Added 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
33f58a847fc4 Added a copy of Config in the commons package. TODO: Remove it from artifacts-database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
292 /**
33f58a847fc4 Added a copy of Config in the commons package. TODO: Remove it from artifacts-database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
293 * 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
294 * via XPath.
556
ba31ca213c88 loadConfig static method
gernotbelger
parents: 475
diff changeset
295 *
ba31ca213c88 loadConfig static method
gernotbelger
parents: 475
diff changeset
296 * @param root
ba31ca213c88 loadConfig static method
gernotbelger
parents: 475
diff changeset
297 * The root of the tree to be searched in.
ba31ca213c88 loadConfig static method
gernotbelger
parents: 475
diff changeset
298 * @param query
ba31ca213c88 loadConfig static method
gernotbelger
parents: 475
diff changeset
299 * xpath The XPath query.
ba31ca213c88 loadConfig static method
gernotbelger
parents: 475
diff changeset
300 * @param def
ba31ca213c88 loadConfig static method
gernotbelger
parents: 475
diff changeset
301 * 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
302 * @return The queried string or the default value if something went
556
ba31ca213c88 loadConfig static method
gernotbelger
parents: 475
diff changeset
303 * 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
304 */
556
ba31ca213c88 loadConfig static method
gernotbelger
parents: 475
diff changeset
305 public static final String getStringXPath(final Object root, final String query, final String def) {
ba31ca213c88 loadConfig static method
gernotbelger
parents: 475
diff changeset
306 final String s = (String) getXPath(root, query, XPathConstants.STRING);
ba31ca213c88 loadConfig static method
gernotbelger
parents: 475
diff changeset
307 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
308 }
33f58a847fc4 Added 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 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org