Mercurial > dive4elements > framework
annotate artifact-database/src/main/java/de/intevation/artifactdatabase/Config.java @ 114:19b86e27d0c3
New XPath constants and methods that retrieve important nodes of the DESCRIBE document.
artifacts/trunk@1328 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Ingo Weinzierl <ingo.weinzierl@intevation.de> |
---|---|
date | Fri, 18 Feb 2011 14:21:32 +0000 |
parents | 933bbc9fc11f |
children |
rev | line source |
---|---|
100
933bbc9fc11f
Added license file and license headers.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
93
diff
changeset
|
1 /* |
933bbc9fc11f
Added license file and license headers.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
93
diff
changeset
|
2 * Copyright (c) 2010 by Intevation GmbH |
933bbc9fc11f
Added license file and license headers.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
93
diff
changeset
|
3 * |
933bbc9fc11f
Added license file and license headers.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
93
diff
changeset
|
4 * This program is free software under the LGPL (>=v2.1) |
933bbc9fc11f
Added license file and license headers.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
93
diff
changeset
|
5 * Read the file LGPL.txt coming with the software for details |
933bbc9fc11f
Added license file and license headers.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
93
diff
changeset
|
6 * or visit http://www.gnu.org/licenses/ if it does not exist. |
933bbc9fc11f
Added license file and license headers.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
93
diff
changeset
|
7 */ |
933bbc9fc11f
Added license file and license headers.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
93
diff
changeset
|
8 |
5
8f2de197bce2
Added config to artifact database and modelled bootstap of artifact factories on top of this.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
9 package de.intevation.artifactdatabase; |
8f2de197bce2
Added config to artifact database and modelled bootstap of artifact factories on top of this.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
10 |
8f2de197bce2
Added config to artifact database and modelled bootstap of artifact factories on top of this.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
11 import java.io.File; |
8f2de197bce2
Added config to artifact database and modelled bootstap of artifact factories on top of this.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
12 import java.io.IOException; |
8f2de197bce2
Added config to artifact database and modelled bootstap of artifact factories on top of this.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
13 |
93
e27cf9c84eb8
Unified imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
91
diff
changeset
|
14 import javax.xml.namespace.QName; |
5
8f2de197bce2
Added config to artifact database and modelled bootstap of artifact factories on top of this.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
15 |
8f2de197bce2
Added config to artifact database and modelled bootstap of artifact factories on top of this.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
16 import javax.xml.parsers.DocumentBuilderFactory; |
8f2de197bce2
Added config to artifact database and modelled bootstap of artifact factories on top of this.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
17 import javax.xml.parsers.ParserConfigurationException; |
8f2de197bce2
Added config to artifact database and modelled bootstap of artifact factories on top of this.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
18 |
8f2de197bce2
Added config to artifact database and modelled bootstap of artifact factories on top of this.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
19 import javax.xml.xpath.XPathConstants; |
8f2de197bce2
Added config to artifact database and modelled bootstap of artifact factories on top of this.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
20 |
17
5a6b6a3debc7
Integrated logging into artifact database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
13
diff
changeset
|
21 import org.apache.log4j.Logger; |
5a6b6a3debc7
Integrated logging into artifact database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
13
diff
changeset
|
22 |
93
e27cf9c84eb8
Unified imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
91
diff
changeset
|
23 import org.w3c.dom.Document; |
e27cf9c84eb8
Unified imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
91
diff
changeset
|
24 import org.w3c.dom.Node; |
e27cf9c84eb8
Unified imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
91
diff
changeset
|
25 import org.w3c.dom.NodeList; |
e27cf9c84eb8
Unified imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
91
diff
changeset
|
26 |
e27cf9c84eb8
Unified imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
91
diff
changeset
|
27 import org.xml.sax.SAXException; |
e27cf9c84eb8
Unified imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
91
diff
changeset
|
28 |
10
e8626caac353
* Made Artifact life cycle symmetric: setup/endOfLife.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
9
diff
changeset
|
29 /** |
91
730ff077a58c
More javadoc, some code formatting.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
80
diff
changeset
|
30 * The central access to the configuration of the artifact database. |
730ff077a58c
More javadoc, some code formatting.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
80
diff
changeset
|
31 * This class provides some static methods to access the central |
730ff077a58c
More javadoc, some code formatting.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
80
diff
changeset
|
32 * configuration XML file via XPath. |
730ff077a58c
More javadoc, some code formatting.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
80
diff
changeset
|
33 * |
80
8447467cef86
Implementation to import artifacts from incoming xml documents (applied patch from issue208 by SLT).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
61
diff
changeset
|
34 * @author <a href="mailto:sascha.teichmann@intevation.de">Sascha L. Teichmann</a> |
10
e8626caac353
* Made Artifact life cycle symmetric: setup/endOfLife.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
9
diff
changeset
|
35 */ |
5
8f2de197bce2
Added config to artifact database and modelled bootstap of artifact factories on top of this.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
36 public final class Config |
8f2de197bce2
Added config to artifact database and modelled bootstap of artifact factories on top of this.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
37 { |
17
5a6b6a3debc7
Integrated logging into artifact database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
13
diff
changeset
|
38 private static Logger logger = Logger.getLogger(Config.class); |
5a6b6a3debc7
Integrated logging into artifact database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
13
diff
changeset
|
39 |
91
730ff077a58c
More javadoc, some code formatting.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
80
diff
changeset
|
40 /** |
730ff077a58c
More javadoc, some code formatting.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
80
diff
changeset
|
41 * System property name where to find the configuration directory. |
730ff077a58c
More javadoc, some code formatting.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
80
diff
changeset
|
42 */ |
19
1259d192e3c3
* New configuration based on config directory
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
17
diff
changeset
|
43 public static final String CONFIG_DIR = "artifact.database.dir"; |
5
8f2de197bce2
Added config to artifact database and modelled bootstap of artifact factories on top of this.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
44 |
91
730ff077a58c
More javadoc, some code formatting.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
80
diff
changeset
|
45 /** |
730ff077a58c
More javadoc, some code formatting.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
80
diff
changeset
|
46 * Default path to the configuration directory if none |
730ff077a58c
More javadoc, some code formatting.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
80
diff
changeset
|
47 * was specified by the CONFIG_DIR system property. |
730ff077a58c
More javadoc, some code formatting.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
80
diff
changeset
|
48 */ |
19
1259d192e3c3
* New configuration based on config directory
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
17
diff
changeset
|
49 public static final File CONFIG_DIR_DEFAULT = |
1259d192e3c3
* New configuration based on config directory
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
17
diff
changeset
|
50 new File(new File(System.getProperty("user.home", |
1259d192e3c3
* New configuration based on config directory
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
17
diff
changeset
|
51 System.getProperty("user.dir", "."))), ".artifactdb"); |
1259d192e3c3
* New configuration based on config directory
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
17
diff
changeset
|
52 |
91
730ff077a58c
More javadoc, some code formatting.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
80
diff
changeset
|
53 /** |
730ff077a58c
More javadoc, some code formatting.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
80
diff
changeset
|
54 * Name of the central configuration XML file. |
730ff077a58c
More javadoc, some code formatting.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
80
diff
changeset
|
55 */ |
19
1259d192e3c3
* New configuration based on config directory
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
17
diff
changeset
|
56 public static final String CONFIG_FILE = "conf.xml"; |
5
8f2de197bce2
Added config to artifact database and modelled bootstap of artifact factories on top of this.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
57 |
91
730ff077a58c
More javadoc, some code formatting.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
80
diff
changeset
|
58 /** |
730ff077a58c
More javadoc, some code formatting.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
80
diff
changeset
|
59 * Name of the configuration filename alias to be use |
730ff077a58c
More javadoc, some code formatting.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
80
diff
changeset
|
60 * within the configuration. This alias is replaced by |
730ff077a58c
More javadoc, some code formatting.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
80
diff
changeset
|
61 * the real path. |
730ff077a58c
More javadoc, some code formatting.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
80
diff
changeset
|
62 */ |
730ff077a58c
More javadoc, some code formatting.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
80
diff
changeset
|
63 public static final String CONFIG_DIR_PLACEHOLDER = |
730ff077a58c
More javadoc, some code formatting.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
80
diff
changeset
|
64 "${artifacts.config.dir}"; |
54
c2fc85e55f9f
Applied patch from slt to set the Configuration Folder into the AbsoluteFileName issue59
Tim Englich <tim.englich@intevation.de>
parents:
25
diff
changeset
|
65 |
5
8f2de197bce2
Added config to artifact database and modelled bootstap of artifact factories on top of this.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
66 private static Document config; |
8f2de197bce2
Added config to artifact database and modelled bootstap of artifact factories on top of this.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
67 |
8f2de197bce2
Added config to artifact database and modelled bootstap of artifact factories on top of this.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
68 private Config() { |
8f2de197bce2
Added config to artifact database and modelled bootstap of artifact factories on top of this.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
69 } |
8f2de197bce2
Added config to artifact database and modelled bootstap of artifact factories on top of this.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
70 |
91
730ff077a58c
More javadoc, some code formatting.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
80
diff
changeset
|
71 /** |
730ff077a58c
More javadoc, some code formatting.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
80
diff
changeset
|
72 * Singleton access to the central XML configuration document. |
730ff077a58c
More javadoc, some code formatting.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
80
diff
changeset
|
73 * @return The central XML configuration document. |
730ff077a58c
More javadoc, some code formatting.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
80
diff
changeset
|
74 */ |
5
8f2de197bce2
Added config to artifact database and modelled bootstap of artifact factories on top of this.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
75 public static synchronized final Document getConfig() { |
8f2de197bce2
Added config to artifact database and modelled bootstap of artifact factories on top of this.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
76 if (config == null) { |
61
911c684c8a1c
Removed config path of chart template which doesn't belong here from Config.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
59
diff
changeset
|
77 config = loadConfig(); |
5
8f2de197bce2
Added config to artifact database and modelled bootstap of artifact factories on top of this.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
78 } |
8f2de197bce2
Added config to artifact database and modelled bootstap of artifact factories on top of this.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
79 return config; |
8f2de197bce2
Added config to artifact database and modelled bootstap of artifact factories on top of this.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
80 } |
8f2de197bce2
Added config to artifact database and modelled bootstap of artifact factories on top of this.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
81 |
91
730ff077a58c
More javadoc, some code formatting.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
80
diff
changeset
|
82 /** |
730ff077a58c
More javadoc, some code formatting.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
80
diff
changeset
|
83 * Returns the path to the configuartion directory. If a path |
730ff077a58c
More javadoc, some code formatting.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
80
diff
changeset
|
84 * was specified via the CONFIG_DIR system property this one |
730ff077a58c
More javadoc, some code formatting.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
80
diff
changeset
|
85 * is used. Else it falls back to default configuration path. |
730ff077a58c
More javadoc, some code formatting.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
80
diff
changeset
|
86 * @return The path to the configuartion directory. |
730ff077a58c
More javadoc, some code formatting.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
80
diff
changeset
|
87 */ |
19
1259d192e3c3
* New configuration based on config directory
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
17
diff
changeset
|
88 public static File getConfigDirectory() { |
1259d192e3c3
* New configuration based on config directory
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
17
diff
changeset
|
89 String configDirString = System.getProperty(CONFIG_DIR); |
1259d192e3c3
* New configuration based on config directory
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
17
diff
changeset
|
90 |
1259d192e3c3
* New configuration based on config directory
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
17
diff
changeset
|
91 File configDir = configDirString != null |
1259d192e3c3
* New configuration based on config directory
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
17
diff
changeset
|
92 ? new File(configDirString) |
1259d192e3c3
* New configuration based on config directory
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
17
diff
changeset
|
93 : CONFIG_DIR_DEFAULT; |
1259d192e3c3
* New configuration based on config directory
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
17
diff
changeset
|
94 |
1259d192e3c3
* New configuration based on config directory
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
17
diff
changeset
|
95 if (!configDir.isDirectory()) { |
1259d192e3c3
* New configuration based on config directory
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
17
diff
changeset
|
96 logger.warn("'" + configDir + "' is not a directory."); |
1259d192e3c3
* New configuration based on config directory
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
17
diff
changeset
|
97 configDir = CONFIG_DIR_DEFAULT; |
1259d192e3c3
* New configuration based on config directory
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
17
diff
changeset
|
98 } |
1259d192e3c3
* New configuration based on config directory
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
17
diff
changeset
|
99 |
1259d192e3c3
* New configuration based on config directory
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
17
diff
changeset
|
100 return configDir; |
1259d192e3c3
* New configuration based on config directory
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
17
diff
changeset
|
101 } |
1259d192e3c3
* New configuration based on config directory
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
17
diff
changeset
|
102 |
91
730ff077a58c
More javadoc, some code formatting.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
80
diff
changeset
|
103 /** |
730ff077a58c
More javadoc, some code formatting.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
80
diff
changeset
|
104 * Replaces the CONFIG_DIR_PLACEHOLDER alias with the real path |
730ff077a58c
More javadoc, some code formatting.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
80
diff
changeset
|
105 * of the configuration directory. |
730ff077a58c
More javadoc, some code formatting.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
80
diff
changeset
|
106 * @param path The path containing the CONFIG_DIR_PLACEHOLDER placeholder. |
730ff077a58c
More javadoc, some code formatting.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
80
diff
changeset
|
107 * @return The path where the CONFIG_DIR_PLACEHOLDER placeholders are |
730ff077a58c
More javadoc, some code formatting.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
80
diff
changeset
|
108 * replaced by the real path name. |
730ff077a58c
More javadoc, some code formatting.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
80
diff
changeset
|
109 */ |
54
c2fc85e55f9f
Applied patch from slt to set the Configuration Folder into the AbsoluteFileName issue59
Tim Englich <tim.englich@intevation.de>
parents:
25
diff
changeset
|
110 public static String replaceConfigDir(String path) { |
c2fc85e55f9f
Applied patch from slt to set the Configuration Folder into the AbsoluteFileName issue59
Tim Englich <tim.englich@intevation.de>
parents:
25
diff
changeset
|
111 String configDir = getConfigDirectory().getAbsolutePath(); |
c2fc85e55f9f
Applied patch from slt to set the Configuration Folder into the AbsoluteFileName issue59
Tim Englich <tim.englich@intevation.de>
parents:
25
diff
changeset
|
112 return path.replace(CONFIG_DIR_PLACEHOLDER, configDir); |
c2fc85e55f9f
Applied patch from slt to set the Configuration Folder into the AbsoluteFileName issue59
Tim Englich <tim.englich@intevation.de>
parents:
25
diff
changeset
|
113 } |
c2fc85e55f9f
Applied patch from slt to set the Configuration Folder into the AbsoluteFileName issue59
Tim Englich <tim.englich@intevation.de>
parents:
25
diff
changeset
|
114 |
61
911c684c8a1c
Removed config path of chart template which doesn't belong here from Config.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
59
diff
changeset
|
115 private static Document loadConfig() { |
19
1259d192e3c3
* New configuration based on config directory
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
17
diff
changeset
|
116 |
1259d192e3c3
* New configuration based on config directory
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
17
diff
changeset
|
117 File configDir = getConfigDirectory(); |
1259d192e3c3
* New configuration based on config directory
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
17
diff
changeset
|
118 |
61
911c684c8a1c
Removed config path of chart template which doesn't belong here from Config.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
59
diff
changeset
|
119 File file = new File(configDir, CONFIG_FILE); |
5
8f2de197bce2
Added config to artifact database and modelled bootstap of artifact factories on top of this.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
120 |
8f2de197bce2
Added config to artifact database and modelled bootstap of artifact factories on top of this.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
121 if (!file.canRead() && !file.isFile()) { |
17
5a6b6a3debc7
Integrated logging into artifact database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
13
diff
changeset
|
122 logger.error("Cannot read config file '" |
5
8f2de197bce2
Added config to artifact database and modelled bootstap of artifact factories on top of this.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
123 + file + "'."); |
8f2de197bce2
Added config to artifact database and modelled bootstap of artifact factories on top of this.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
124 return null; |
8f2de197bce2
Added config to artifact database and modelled bootstap of artifact factories on top of this.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
125 } |
8f2de197bce2
Added config to artifact database and modelled bootstap of artifact factories on top of this.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
126 |
8f2de197bce2
Added config to artifact database and modelled bootstap of artifact factories on top of this.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
127 try { |
91
730ff077a58c
More javadoc, some code formatting.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
80
diff
changeset
|
128 DocumentBuilderFactory factory = |
730ff077a58c
More javadoc, some code formatting.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
80
diff
changeset
|
129 DocumentBuilderFactory.newInstance(); |
5
8f2de197bce2
Added config to artifact database and modelled bootstap of artifact factories on top of this.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
130 factory.setValidating(false); // XXX: This may change in future. |
8f2de197bce2
Added config to artifact database and modelled bootstap of artifact factories on top of this.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
131 return factory.newDocumentBuilder().parse(file); |
8f2de197bce2
Added config to artifact database and modelled bootstap of artifact factories on top of this.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
132 } |
8f2de197bce2
Added config to artifact database and modelled bootstap of artifact factories on top of this.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
133 catch (SAXException se) { |
17
5a6b6a3debc7
Integrated logging into artifact database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
13
diff
changeset
|
134 logger.error(se.getLocalizedMessage(), se); |
5
8f2de197bce2
Added config to artifact database and modelled bootstap of artifact factories on top of this.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
135 } |
8f2de197bce2
Added config to artifact database and modelled bootstap of artifact factories on top of this.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
136 catch (ParserConfigurationException pce) { |
17
5a6b6a3debc7
Integrated logging into artifact database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
13
diff
changeset
|
137 logger.error(pce.getLocalizedMessage(), pce); |
5
8f2de197bce2
Added config to artifact database and modelled bootstap of artifact factories on top of this.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
138 } |
8f2de197bce2
Added config to artifact database and modelled bootstap of artifact factories on top of this.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
139 catch (IOException ioe) { |
17
5a6b6a3debc7
Integrated logging into artifact database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
13
diff
changeset
|
140 logger.error(ioe.getLocalizedMessage()); |
5
8f2de197bce2
Added config to artifact database and modelled bootstap of artifact factories on top of this.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
141 } |
8f2de197bce2
Added config to artifact database and modelled bootstap of artifact factories on top of this.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
142 |
8f2de197bce2
Added config to artifact database and modelled bootstap of artifact factories on top of this.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
143 return null; |
8f2de197bce2
Added config to artifact database and modelled bootstap of artifact factories on top of this.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
144 } |
8f2de197bce2
Added config to artifact database and modelled bootstap of artifact factories on top of this.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
145 |
91
730ff077a58c
More javadoc, some code formatting.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
80
diff
changeset
|
146 /** |
730ff077a58c
More javadoc, some code formatting.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
80
diff
changeset
|
147 * Convenience method to search within a given document tree via XPath. |
730ff077a58c
More javadoc, some code formatting.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
80
diff
changeset
|
148 * See {@link XMLUtils#xpath(Object, String, QName) } for details. |
730ff077a58c
More javadoc, some code formatting.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
80
diff
changeset
|
149 * @param root The object which is used as the root of the tree to |
730ff077a58c
More javadoc, some code formatting.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
80
diff
changeset
|
150 * be searched in. |
730ff077a58c
More javadoc, some code formatting.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
80
diff
changeset
|
151 * @param query The XPath query. |
730ff077a58c
More javadoc, some code formatting.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
80
diff
changeset
|
152 * @param returnType The type of the result. |
730ff077a58c
More javadoc, some code formatting.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
80
diff
changeset
|
153 * @return The result of type 'returnTyp' or null if something went |
730ff077a58c
More javadoc, some code formatting.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
80
diff
changeset
|
154 * wrong during XPath evaluation. |
730ff077a58c
More javadoc, some code formatting.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
80
diff
changeset
|
155 */ |
10
e8626caac353
* Made Artifact life cycle symmetric: setup/endOfLife.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
9
diff
changeset
|
156 public static final Object getXPath( |
e8626caac353
* Made Artifact life cycle symmetric: setup/endOfLife.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
9
diff
changeset
|
157 Object root, String query, QName returnType |
e8626caac353
* Made Artifact life cycle symmetric: setup/endOfLife.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
9
diff
changeset
|
158 ) { |
25
ccc6aae25585
Moved some XPath stuff from Config into XMLUtils.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
23
diff
changeset
|
159 return XMLUtils.xpath(root, query, returnType); |
10
e8626caac353
* Made Artifact life cycle symmetric: setup/endOfLife.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
9
diff
changeset
|
160 } |
e8626caac353
* Made Artifact life cycle symmetric: setup/endOfLife.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
9
diff
changeset
|
161 |
91
730ff077a58c
More javadoc, some code formatting.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
80
diff
changeset
|
162 /** |
730ff077a58c
More javadoc, some code formatting.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
80
diff
changeset
|
163 * Convenience method to search within the central configuration via XPath. |
730ff077a58c
More javadoc, some code formatting.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
80
diff
changeset
|
164 * See {@link XMLUtils#xpath(Object, String, QName) } for details. |
730ff077a58c
More javadoc, some code formatting.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
80
diff
changeset
|
165 * @param query The XPath query. |
730ff077a58c
More javadoc, some code formatting.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
80
diff
changeset
|
166 * @param returnType The type of the result. |
730ff077a58c
More javadoc, some code formatting.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
80
diff
changeset
|
167 * @return The result of type 'returnTyp' or null if something went |
730ff077a58c
More javadoc, some code formatting.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
80
diff
changeset
|
168 * wrong during XPath evaluation. |
730ff077a58c
More javadoc, some code formatting.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
80
diff
changeset
|
169 */ |
10
e8626caac353
* Made Artifact life cycle symmetric: setup/endOfLife.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
9
diff
changeset
|
170 public static final Object getXPath(String query, QName returnType) { |
25
ccc6aae25585
Moved some XPath stuff from Config into XMLUtils.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
23
diff
changeset
|
171 return XMLUtils.xpath(getConfig(), query, returnType); |
10
e8626caac353
* Made Artifact life cycle symmetric: setup/endOfLife.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
9
diff
changeset
|
172 } |
e8626caac353
* Made Artifact life cycle symmetric: setup/endOfLife.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
9
diff
changeset
|
173 |
91
730ff077a58c
More javadoc, some code formatting.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
80
diff
changeset
|
174 /** |
730ff077a58c
More javadoc, some code formatting.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
80
diff
changeset
|
175 * Convenience method to search for a node list within the central |
730ff077a58c
More javadoc, some code formatting.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
80
diff
changeset
|
176 * configuation document via XPath. |
730ff077a58c
More javadoc, some code formatting.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
80
diff
changeset
|
177 * @param query The XPath query. |
730ff077a58c
More javadoc, some code formatting.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
80
diff
changeset
|
178 * @return The queried node list or null if something went |
730ff077a58c
More javadoc, some code formatting.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
80
diff
changeset
|
179 * wrong during XPath evaluation. |
730ff077a58c
More javadoc, some code formatting.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
80
diff
changeset
|
180 */ |
10
e8626caac353
* Made Artifact life cycle symmetric: setup/endOfLife.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
9
diff
changeset
|
181 public static final NodeList getNodeSetXPath(String query) { |
e8626caac353
* Made Artifact life cycle symmetric: setup/endOfLife.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
9
diff
changeset
|
182 return (NodeList)getXPath(query, XPathConstants.NODESET); |
e8626caac353
* Made Artifact life cycle symmetric: setup/endOfLife.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
9
diff
changeset
|
183 } |
e8626caac353
* Made Artifact life cycle symmetric: setup/endOfLife.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
9
diff
changeset
|
184 |
91
730ff077a58c
More javadoc, some code formatting.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
80
diff
changeset
|
185 /** |
730ff077a58c
More javadoc, some code formatting.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
80
diff
changeset
|
186 * Convenience method to search for a node within the central |
730ff077a58c
More javadoc, some code formatting.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
80
diff
changeset
|
187 * configuation document via XPath. |
730ff077a58c
More javadoc, some code formatting.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
80
diff
changeset
|
188 * @param query The XPath query. |
730ff077a58c
More javadoc, some code formatting.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
80
diff
changeset
|
189 * @return The queried node or null if something went |
730ff077a58c
More javadoc, some code formatting.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
80
diff
changeset
|
190 * wrong during XPath evaluation. |
730ff077a58c
More javadoc, some code formatting.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
80
diff
changeset
|
191 */ |
10
e8626caac353
* Made Artifact life cycle symmetric: setup/endOfLife.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
9
diff
changeset
|
192 public static final Node getNodeXPath(String query) { |
e8626caac353
* Made Artifact life cycle symmetric: setup/endOfLife.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
9
diff
changeset
|
193 return (Node)getXPath(query, XPathConstants.NODE); |
e8626caac353
* Made Artifact life cycle symmetric: setup/endOfLife.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
9
diff
changeset
|
194 } |
e8626caac353
* Made Artifact life cycle symmetric: setup/endOfLife.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
9
diff
changeset
|
195 |
91
730ff077a58c
More javadoc, some code formatting.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
80
diff
changeset
|
196 /** |
730ff077a58c
More javadoc, some code formatting.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
80
diff
changeset
|
197 * Convenience method to search for a string within the central |
730ff077a58c
More javadoc, some code formatting.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
80
diff
changeset
|
198 * configuation document via XPath. |
730ff077a58c
More javadoc, some code formatting.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
80
diff
changeset
|
199 * @param xpath The XPath query. |
730ff077a58c
More javadoc, some code formatting.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
80
diff
changeset
|
200 * @return The queried string or null if something went |
730ff077a58c
More javadoc, some code formatting.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
80
diff
changeset
|
201 * wrong during XPath evaluation. |
730ff077a58c
More javadoc, some code formatting.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
80
diff
changeset
|
202 */ |
5
8f2de197bce2
Added config to artifact database and modelled bootstap of artifact factories on top of this.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
203 public static final String getStringXPath(String xpath) { |
8f2de197bce2
Added config to artifact database and modelled bootstap of artifact factories on top of this.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
204 return getStringXPath(xpath, null); |
8f2de197bce2
Added config to artifact database and modelled bootstap of artifact factories on top of this.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
205 } |
8f2de197bce2
Added config to artifact database and modelled bootstap of artifact factories on top of this.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
206 |
91
730ff077a58c
More javadoc, some code formatting.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
80
diff
changeset
|
207 /** |
730ff077a58c
More javadoc, some code formatting.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
80
diff
changeset
|
208 * Convenience method to search for a string within the central |
730ff077a58c
More javadoc, some code formatting.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
80
diff
changeset
|
209 * configuation document via XPath. |
730ff077a58c
More javadoc, some code formatting.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
80
diff
changeset
|
210 * @param query The XPath query. |
730ff077a58c
More javadoc, some code formatting.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
80
diff
changeset
|
211 * @param def The string to be returned if the search has no results. |
730ff077a58c
More javadoc, some code formatting.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
80
diff
changeset
|
212 * @return The queried string or the default value if something went |
730ff077a58c
More javadoc, some code formatting.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
80
diff
changeset
|
213 * wrong during XPath evaluation. |
730ff077a58c
More javadoc, some code formatting.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
80
diff
changeset
|
214 */ |
5
8f2de197bce2
Added config to artifact database and modelled bootstap of artifact factories on top of this.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
215 public static final String getStringXPath(String query, String def) { |
8f2de197bce2
Added config to artifact database and modelled bootstap of artifact factories on top of this.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
216 String s = (String)getXPath(query, XPathConstants.STRING); |
8f2de197bce2
Added config to artifact database and modelled bootstap of artifact factories on top of this.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
217 return s == null || s.length() == 0 |
8f2de197bce2
Added config to artifact database and modelled bootstap of artifact factories on top of this.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
218 ? def |
8f2de197bce2
Added config to artifact database and modelled bootstap of artifact factories on top of this.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
219 : s; |
8f2de197bce2
Added config to artifact database and modelled bootstap of artifact factories on top of this.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
220 } |
8f2de197bce2
Added config to artifact database and modelled bootstap of artifact factories on top of this.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
221 |
91
730ff077a58c
More javadoc, some code formatting.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
80
diff
changeset
|
222 /** |
730ff077a58c
More javadoc, some code formatting.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
80
diff
changeset
|
223 * Convenience method to search for a node list within a given tree |
730ff077a58c
More javadoc, some code formatting.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
80
diff
changeset
|
224 * via XPath. |
730ff077a58c
More javadoc, some code formatting.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
80
diff
changeset
|
225 * @param root The root of the tree to be searched in. |
730ff077a58c
More javadoc, some code formatting.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
80
diff
changeset
|
226 * @param query The XPath query. |
730ff077a58c
More javadoc, some code formatting.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
80
diff
changeset
|
227 * @return The queried node list or null if something went |
730ff077a58c
More javadoc, some code formatting.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
80
diff
changeset
|
228 * wrong during XPath evaluation. |
730ff077a58c
More javadoc, some code formatting.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
80
diff
changeset
|
229 */ |
10
e8626caac353
* Made Artifact life cycle symmetric: setup/endOfLife.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
9
diff
changeset
|
230 public static final NodeList getNodeSetXPath(Object root, String query) { |
e8626caac353
* Made Artifact life cycle symmetric: setup/endOfLife.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
9
diff
changeset
|
231 return (NodeList)getXPath(root, query, XPathConstants.NODESET); |
5
8f2de197bce2
Added config to artifact database and modelled bootstap of artifact factories on top of this.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
232 } |
8f2de197bce2
Added config to artifact database and modelled bootstap of artifact factories on top of this.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
233 |
91
730ff077a58c
More javadoc, some code formatting.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
80
diff
changeset
|
234 /** |
730ff077a58c
More javadoc, some code formatting.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
80
diff
changeset
|
235 * Convenience method to search for a node within a given tree |
730ff077a58c
More javadoc, some code formatting.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
80
diff
changeset
|
236 * via XPath. |
730ff077a58c
More javadoc, some code formatting.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
80
diff
changeset
|
237 * @param root The root of the tree to be searched in. |
730ff077a58c
More javadoc, some code formatting.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
80
diff
changeset
|
238 * @param query The XPath query. |
730ff077a58c
More javadoc, some code formatting.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
80
diff
changeset
|
239 * @return The queried node or null if something went |
730ff077a58c
More javadoc, some code formatting.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
80
diff
changeset
|
240 * wrong during XPath evaluation. |
730ff077a58c
More javadoc, some code formatting.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
80
diff
changeset
|
241 */ |
10
e8626caac353
* Made Artifact life cycle symmetric: setup/endOfLife.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
9
diff
changeset
|
242 public static final Node getNodeXPath(Object root, String query) { |
e8626caac353
* Made Artifact life cycle symmetric: setup/endOfLife.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
9
diff
changeset
|
243 return (Node)getXPath(root, query, XPathConstants.NODE); |
5
8f2de197bce2
Added config to artifact database and modelled bootstap of artifact factories on top of this.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
244 } |
9
a5a279a0ee35
Laid tracks for artifacts being removed from artifact database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5
diff
changeset
|
245 |
91
730ff077a58c
More javadoc, some code formatting.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
80
diff
changeset
|
246 /** |
730ff077a58c
More javadoc, some code formatting.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
80
diff
changeset
|
247 * Convenience method to search for a string within a given tree |
730ff077a58c
More javadoc, some code formatting.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
80
diff
changeset
|
248 * via XPath. |
730ff077a58c
More javadoc, some code formatting.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
80
diff
changeset
|
249 * @param root The root of the tree to be searched in. |
730ff077a58c
More javadoc, some code formatting.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
80
diff
changeset
|
250 * @param xpath The XPath query. |
730ff077a58c
More javadoc, some code formatting.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
80
diff
changeset
|
251 * @return The queried string or null if something went |
730ff077a58c
More javadoc, some code formatting.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
80
diff
changeset
|
252 * wrong during XPath evaluation. |
730ff077a58c
More javadoc, some code formatting.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
80
diff
changeset
|
253 */ |
10
e8626caac353
* Made Artifact life cycle symmetric: setup/endOfLife.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
9
diff
changeset
|
254 public static final String getStringXPath(Object root, String xpath) { |
e8626caac353
* Made Artifact life cycle symmetric: setup/endOfLife.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
9
diff
changeset
|
255 return getStringXPath(root, xpath, null); |
e8626caac353
* Made Artifact life cycle symmetric: setup/endOfLife.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
9
diff
changeset
|
256 } |
e8626caac353
* Made Artifact life cycle symmetric: setup/endOfLife.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
9
diff
changeset
|
257 |
91
730ff077a58c
More javadoc, some code formatting.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
80
diff
changeset
|
258 /** |
730ff077a58c
More javadoc, some code formatting.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
80
diff
changeset
|
259 * Convenience method to search for a string within a given tree |
730ff077a58c
More javadoc, some code formatting.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
80
diff
changeset
|
260 * via XPath. |
730ff077a58c
More javadoc, some code formatting.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
80
diff
changeset
|
261 * @param root The root of the tree to be searched in. |
730ff077a58c
More javadoc, some code formatting.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
80
diff
changeset
|
262 * @param query xpath The XPath query. |
730ff077a58c
More javadoc, some code formatting.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
80
diff
changeset
|
263 * @param def The string to be returned if the search has no results. |
730ff077a58c
More javadoc, some code formatting.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
80
diff
changeset
|
264 * @return The queried string or the default value if something went |
730ff077a58c
More javadoc, some code formatting.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
80
diff
changeset
|
265 * wrong during XPath evaluation. |
730ff077a58c
More javadoc, some code formatting.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
80
diff
changeset
|
266 */ |
10
e8626caac353
* Made Artifact life cycle symmetric: setup/endOfLife.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
9
diff
changeset
|
267 public static final String getStringXPath( |
e8626caac353
* Made Artifact life cycle symmetric: setup/endOfLife.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
9
diff
changeset
|
268 Object root, String query, String def |
e8626caac353
* Made Artifact life cycle symmetric: setup/endOfLife.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
9
diff
changeset
|
269 ) { |
e8626caac353
* Made Artifact life cycle symmetric: setup/endOfLife.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
9
diff
changeset
|
270 String s = (String)getXPath(root, query, XPathConstants.STRING); |
e8626caac353
* Made Artifact life cycle symmetric: setup/endOfLife.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
9
diff
changeset
|
271 return s == null || s.length() == 0 |
e8626caac353
* Made Artifact life cycle symmetric: setup/endOfLife.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
9
diff
changeset
|
272 ? def |
e8626caac353
* Made Artifact life cycle symmetric: setup/endOfLife.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
9
diff
changeset
|
273 : s; |
9
a5a279a0ee35
Laid tracks for artifacts being removed from artifact database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5
diff
changeset
|
274 } |
5
8f2de197bce2
Added config to artifact database and modelled bootstap of artifact factories on top of this.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
275 } |
93
e27cf9c84eb8
Unified imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
91
diff
changeset
|
276 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |