annotate gwt-client/src/main/java/org/dive4elements/river/client/server/features/XMLFileFeatures.java @ 5861:172338b1407f

GWT client: Added copyright header.
author Sascha L. Teichmann <teichmann@intevation.de>
date Sun, 28 Apr 2013 14:30:15 +0200
parents 5aa05a7a34b7
children ea9eef426962
rev   line source
5861
172338b1407f GWT client: Added copyright header.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5838
diff changeset
1 /* Copyright (C) 2011, 2012, 2013 by Bundesanstalt für Gewässerkunde
172338b1407f GWT client: Added copyright header.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5838
diff changeset
2 * Software engineering by Intevation GmbH
172338b1407f GWT client: Added copyright header.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5838
diff changeset
3 *
172338b1407f GWT client: Added copyright header.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5838
diff changeset
4 * This file is Free Software under the GNU AGPL (>=v3)
172338b1407f GWT client: Added copyright header.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5838
diff changeset
5 * and comes with ABSOLUTELY NO WARRANTY! Check out the
172338b1407f GWT client: Added copyright header.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5838
diff changeset
6 * documentation coming with Dive4Elements River for details.
172338b1407f GWT client: Added copyright header.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5838
diff changeset
7 */
172338b1407f GWT client: Added copyright header.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5838
diff changeset
8
5835
821a02bbfb4e Fixed internal java dependencies
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5834
diff changeset
9 package org.dive4elements.river.client.server.features;
3476
4a6321dd5186 Implement a class representation of features corresponding to roles
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
10
4a6321dd5186 Implement a class representation of features corresponding to roles
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
11 import java.io.FileInputStream;
4a6321dd5186 Implement a class representation of features corresponding to roles
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
12 import java.io.IOException;
4a6321dd5186 Implement a class representation of features corresponding to roles
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
13
3482
c64cad8dc772 Add missing import of ArrayList
Bjoern Ricks <bjoern.ricks@intevation.de>
parents: 3481
diff changeset
14 import java.util.ArrayList;
3484
83845aa322ea XMLFileFeatures: Cosmetics.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3482
diff changeset
15 import java.util.HashMap;
3476
4a6321dd5186 Implement a class representation of features corresponding to roles
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
16 import java.util.List;
3484
83845aa322ea XMLFileFeatures: Cosmetics.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3482
diff changeset
17 import java.util.Map;
3476
4a6321dd5186 Implement a class representation of features corresponding to roles
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
18
4a6321dd5186 Implement a class representation of features corresponding to roles
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
19 import javax.xml.xpath.XPathConstants;
4a6321dd5186 Implement a class representation of features corresponding to roles
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
20
4a6321dd5186 Implement a class representation of features corresponding to roles
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
21 import org.apache.log4j.Logger;
4a6321dd5186 Implement a class representation of features corresponding to roles
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
22
4a6321dd5186 Implement a class representation of features corresponding to roles
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
23 import org.w3c.dom.Document;
4a6321dd5186 Implement a class representation of features corresponding to roles
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
24 import org.w3c.dom.Element;
4a6321dd5186 Implement a class representation of features corresponding to roles
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
25 import org.w3c.dom.Node;
4a6321dd5186 Implement a class representation of features corresponding to roles
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
26 import org.w3c.dom.NodeList;
4a6321dd5186 Implement a class representation of features corresponding to roles
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
27
5835
821a02bbfb4e Fixed internal java dependencies
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5834
diff changeset
28 import org.dive4elements.artifacts.common.utils.XMLUtils;
3476
4a6321dd5186 Implement a class representation of features corresponding to roles
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
29
4a6321dd5186 Implement a class representation of features corresponding to roles
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
30 public class XMLFileFeatures implements Features {
4a6321dd5186 Implement a class representation of features corresponding to roles
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
31
3484
83845aa322ea XMLFileFeatures: Cosmetics.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3482
diff changeset
32 private static final Logger logger =
83845aa322ea XMLFileFeatures: Cosmetics.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3482
diff changeset
33 Logger.getLogger(XMLFileFeatures.class);
3476
4a6321dd5186 Implement a class representation of features corresponding to roles
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
34
3484
83845aa322ea XMLFileFeatures: Cosmetics.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3482
diff changeset
35 private Map<String, List<String>> featuremap =
83845aa322ea XMLFileFeatures: Cosmetics.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3482
diff changeset
36 new HashMap<String, List<String>>();
3476
4a6321dd5186 Implement a class representation of features corresponding to roles
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
37
3481
e59588ea27bd Some optimization of the code mentioned by Sascha T.
Bjoern Ricks <bjoern.ricks@intevation.de>
parents: 3476
diff changeset
38 private final static String XPATH_FEATURES = "ftr:feature/child::text()";
e59588ea27bd Some optimization of the code mentioned by Sascha T.
Bjoern Ricks <bjoern.ricks@intevation.de>
parents: 3476
diff changeset
39 private final static String XPATH_ROLES = "/ftr:features/ftr:role";
e59588ea27bd Some optimization of the code mentioned by Sascha T.
Bjoern Ricks <bjoern.ricks@intevation.de>
parents: 3476
diff changeset
40
3476
4a6321dd5186 Implement a class representation of features corresponding to roles
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
41 public XMLFileFeatures(String filename) throws IOException {
4a6321dd5186 Implement a class representation of features corresponding to roles
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
42 FileInputStream finput = new FileInputStream(filename);
4632
02cf2b1dff84 Make floodmap riveraxis layer name configurable.
Christian Lins <christian.lins@intevation.de>
parents: 3490
diff changeset
43 logger.debug("XMLFileFeatures: " + filename);
3481
e59588ea27bd Some optimization of the code mentioned by Sascha T.
Bjoern Ricks <bjoern.ricks@intevation.de>
parents: 3476
diff changeset
44 try {
e59588ea27bd Some optimization of the code mentioned by Sascha T.
Bjoern Ricks <bjoern.ricks@intevation.de>
parents: 3476
diff changeset
45 Document doc = XMLUtils.parseDocument(finput);
3476
4a6321dd5186 Implement a class representation of features corresponding to roles
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
46
3481
e59588ea27bd Some optimization of the code mentioned by Sascha T.
Bjoern Ricks <bjoern.ricks@intevation.de>
parents: 3476
diff changeset
47 NodeList roles = (NodeList) XMLUtils.xpath(
e59588ea27bd Some optimization of the code mentioned by Sascha T.
Bjoern Ricks <bjoern.ricks@intevation.de>
parents: 3476
diff changeset
48 doc,
e59588ea27bd Some optimization of the code mentioned by Sascha T.
Bjoern Ricks <bjoern.ricks@intevation.de>
parents: 3476
diff changeset
49 XPATH_ROLES,
3476
4a6321dd5186 Implement a class representation of features corresponding to roles
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
50 XPathConstants.NODESET,
4a6321dd5186 Implement a class representation of features corresponding to roles
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
51 FeaturesNamespaceContext.INSTANCE);
4a6321dd5186 Implement a class representation of features corresponding to roles
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
52
3484
83845aa322ea XMLFileFeatures: Cosmetics.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3482
diff changeset
53 for(int i = 0, m = roles.getLength(); i < m; i++) {
3481
e59588ea27bd Some optimization of the code mentioned by Sascha T.
Bjoern Ricks <bjoern.ricks@intevation.de>
parents: 3476
diff changeset
54 Element rolenode = (Element)roles.item(i);
3476
4a6321dd5186 Implement a class representation of features corresponding to roles
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
55
3487
3dfe7bbab70f Don't use xml namespace to get the "name" attribute of a role
Bjoern Ricks <bjoern.ricks@intevation.de>
parents: 3484
diff changeset
56 String name = rolenode.getAttribute("name");
3481
e59588ea27bd Some optimization of the code mentioned by Sascha T.
Bjoern Ricks <bjoern.ricks@intevation.de>
parents: 3476
diff changeset
57
e59588ea27bd Some optimization of the code mentioned by Sascha T.
Bjoern Ricks <bjoern.ricks@intevation.de>
parents: 3476
diff changeset
58 logger.debug("Found role: " + name);
e59588ea27bd Some optimization of the code mentioned by Sascha T.
Bjoern Ricks <bjoern.ricks@intevation.de>
parents: 3476
diff changeset
59
e59588ea27bd Some optimization of the code mentioned by Sascha T.
Bjoern Ricks <bjoern.ricks@intevation.de>
parents: 3476
diff changeset
60 NodeList features = (NodeList) XMLUtils.xpath(
e59588ea27bd Some optimization of the code mentioned by Sascha T.
Bjoern Ricks <bjoern.ricks@intevation.de>
parents: 3476
diff changeset
61 rolenode,
e59588ea27bd Some optimization of the code mentioned by Sascha T.
Bjoern Ricks <bjoern.ricks@intevation.de>
parents: 3476
diff changeset
62 XPATH_FEATURES,
e59588ea27bd Some optimization of the code mentioned by Sascha T.
Bjoern Ricks <bjoern.ricks@intevation.de>
parents: 3476
diff changeset
63 XPathConstants.NODESET,
e59588ea27bd Some optimization of the code mentioned by Sascha T.
Bjoern Ricks <bjoern.ricks@intevation.de>
parents: 3476
diff changeset
64 FeaturesNamespaceContext.INSTANCE);
e59588ea27bd Some optimization of the code mentioned by Sascha T.
Bjoern Ricks <bjoern.ricks@intevation.de>
parents: 3476
diff changeset
65
3484
83845aa322ea XMLFileFeatures: Cosmetics.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3482
diff changeset
66 if (features == null) {
83845aa322ea XMLFileFeatures: Cosmetics.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3482
diff changeset
67 continue;
83845aa322ea XMLFileFeatures: Cosmetics.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3482
diff changeset
68 }
83845aa322ea XMLFileFeatures: Cosmetics.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3482
diff changeset
69
83845aa322ea XMLFileFeatures: Cosmetics.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3482
diff changeset
70 int N = features.getLength();
83845aa322ea XMLFileFeatures: Cosmetics.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3482
diff changeset
71
83845aa322ea XMLFileFeatures: Cosmetics.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3482
diff changeset
72 if (N > 0) {
83845aa322ea XMLFileFeatures: Cosmetics.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3482
diff changeset
73 List<String> allowed = new ArrayList<String>(N);
83845aa322ea XMLFileFeatures: Cosmetics.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3482
diff changeset
74 for (int j = 0; j < N; j++) {
3481
e59588ea27bd Some optimization of the code mentioned by Sascha T.
Bjoern Ricks <bjoern.ricks@intevation.de>
parents: 3476
diff changeset
75 Node featurenode = features.item(j);
e59588ea27bd Some optimization of the code mentioned by Sascha T.
Bjoern Ricks <bjoern.ricks@intevation.de>
parents: 3476
diff changeset
76 String featurename = featurenode.getNodeValue();
e59588ea27bd Some optimization of the code mentioned by Sascha T.
Bjoern Ricks <bjoern.ricks@intevation.de>
parents: 3476
diff changeset
77
e59588ea27bd Some optimization of the code mentioned by Sascha T.
Bjoern Ricks <bjoern.ricks@intevation.de>
parents: 3476
diff changeset
78 logger.debug("Found feature: " + featurename);
e59588ea27bd Some optimization of the code mentioned by Sascha T.
Bjoern Ricks <bjoern.ricks@intevation.de>
parents: 3476
diff changeset
79
e59588ea27bd Some optimization of the code mentioned by Sascha T.
Bjoern Ricks <bjoern.ricks@intevation.de>
parents: 3476
diff changeset
80 allowed.add(featurename);
e59588ea27bd Some optimization of the code mentioned by Sascha T.
Bjoern Ricks <bjoern.ricks@intevation.de>
parents: 3476
diff changeset
81 }
e59588ea27bd Some optimization of the code mentioned by Sascha T.
Bjoern Ricks <bjoern.ricks@intevation.de>
parents: 3476
diff changeset
82 featuremap.put(name, allowed);
3476
4a6321dd5186 Implement a class representation of features corresponding to roles
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
83 }
4a6321dd5186 Implement a class representation of features corresponding to roles
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
84 }
3481
e59588ea27bd Some optimization of the code mentioned by Sascha T.
Bjoern Ricks <bjoern.ricks@intevation.de>
parents: 3476
diff changeset
85 logger.debug("Loaded all features");
3476
4a6321dd5186 Implement a class representation of features corresponding to roles
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
86 }
3481
e59588ea27bd Some optimization of the code mentioned by Sascha T.
Bjoern Ricks <bjoern.ricks@intevation.de>
parents: 3476
diff changeset
87 finally {
e59588ea27bd Some optimization of the code mentioned by Sascha T.
Bjoern Ricks <bjoern.ricks@intevation.de>
parents: 3476
diff changeset
88 finput.close();
e59588ea27bd Some optimization of the code mentioned by Sascha T.
Bjoern Ricks <bjoern.ricks@intevation.de>
parents: 3476
diff changeset
89 }
3476
4a6321dd5186 Implement a class representation of features corresponding to roles
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
90 }
4a6321dd5186 Implement a class representation of features corresponding to roles
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
91
4a6321dd5186 Implement a class representation of features corresponding to roles
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
92 @Override
4a6321dd5186 Implement a class representation of features corresponding to roles
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
93 public List<String> getFeatures(List<String> roles) {
3484
83845aa322ea XMLFileFeatures: Cosmetics.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3482
diff changeset
94 List<String> features = new ArrayList<String>();
3476
4a6321dd5186 Implement a class representation of features corresponding to roles
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
95
4a6321dd5186 Implement a class representation of features corresponding to roles
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
96 for (String role: roles) {
4a6321dd5186 Implement a class representation of features corresponding to roles
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
97 List<String> allowed = this.featuremap.get(role);
3484
83845aa322ea XMLFileFeatures: Cosmetics.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3482
diff changeset
98 if (allowed != null) {
3476
4a6321dd5186 Implement a class representation of features corresponding to roles
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
99 features.addAll(allowed);
4a6321dd5186 Implement a class representation of features corresponding to roles
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
100 }
4a6321dd5186 Implement a class representation of features corresponding to roles
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
101 }
4a6321dd5186 Implement a class representation of features corresponding to roles
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
102 return features;
4a6321dd5186 Implement a class representation of features corresponding to roles
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
103 }
4a6321dd5186 Implement a class representation of features corresponding to roles
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
104 }

http://dive4elements.wald.intevation.org