annotate flys-client/src/main/java/org/dive4elements/river/client/server/features/XMLFileFeatures.java @ 5834:f507086aa94b

Repaired internal references.
author Sascha L. Teichmann <teichmann@intevation.de>
date Thu, 25 Apr 2013 12:31:32 +0200
parents flys-client/src/main/java/de/intevation/flys/client/server/features/XMLFileFeatures.java@02cf2b1dff84
children 821a02bbfb4e
rev   line source
3476
4a6321dd5186 Implement a class representation of features corresponding to roles
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
1 package de.intevation.flys.client.server.features;
4a6321dd5186 Implement a class representation of features corresponding to roles
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
2
4a6321dd5186 Implement a class representation of features corresponding to roles
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
3 import java.io.FileInputStream;
4a6321dd5186 Implement a class representation of features corresponding to roles
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
4 import java.io.IOException;
4a6321dd5186 Implement a class representation of features corresponding to roles
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
5
3482
c64cad8dc772 Add missing import of ArrayList
Bjoern Ricks <bjoern.ricks@intevation.de>
parents: 3481
diff changeset
6 import java.util.ArrayList;
3484
83845aa322ea XMLFileFeatures: Cosmetics.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3482
diff changeset
7 import java.util.HashMap;
3476
4a6321dd5186 Implement a class representation of features corresponding to roles
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
8 import java.util.List;
3484
83845aa322ea XMLFileFeatures: Cosmetics.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3482
diff changeset
9 import java.util.Map;
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 javax.xml.xpath.XPathConstants;
4a6321dd5186 Implement a class representation of features corresponding to roles
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
12
4a6321dd5186 Implement a class representation of features corresponding to roles
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
13 import org.apache.log4j.Logger;
4a6321dd5186 Implement a class representation of features corresponding to roles
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
14
4a6321dd5186 Implement a class representation of features corresponding to roles
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
15 import org.w3c.dom.Document;
4a6321dd5186 Implement a class representation of features corresponding to roles
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
16 import org.w3c.dom.Element;
4a6321dd5186 Implement a class representation of features corresponding to roles
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
17 import org.w3c.dom.Node;
4a6321dd5186 Implement a class representation of features corresponding to roles
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
18 import org.w3c.dom.NodeList;
4a6321dd5186 Implement a class representation of features corresponding to roles
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
19
4a6321dd5186 Implement a class representation of features corresponding to roles
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
20 import de.intevation.artifacts.common.utils.XMLUtils;
4a6321dd5186 Implement a class representation of features corresponding to roles
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
21
4a6321dd5186 Implement a class representation of features corresponding to roles
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
22 public class XMLFileFeatures implements Features {
4a6321dd5186 Implement a class representation of features corresponding to roles
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
23
3484
83845aa322ea XMLFileFeatures: Cosmetics.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3482
diff changeset
24 private static final Logger logger =
83845aa322ea XMLFileFeatures: Cosmetics.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3482
diff changeset
25 Logger.getLogger(XMLFileFeatures.class);
3476
4a6321dd5186 Implement a class representation of features corresponding to roles
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
26
3484
83845aa322ea XMLFileFeatures: Cosmetics.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3482
diff changeset
27 private Map<String, List<String>> featuremap =
83845aa322ea XMLFileFeatures: Cosmetics.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3482
diff changeset
28 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
29
3481
e59588ea27bd Some optimization of the code mentioned by Sascha T.
Bjoern Ricks <bjoern.ricks@intevation.de>
parents: 3476
diff changeset
30 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
31 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
32
3476
4a6321dd5186 Implement a class representation of features corresponding to roles
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
33 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
34 FileInputStream finput = new FileInputStream(filename);
4632
02cf2b1dff84 Make floodmap riveraxis layer name configurable.
Christian Lins <christian.lins@intevation.de>
parents: 3490
diff changeset
35 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
36 try {
e59588ea27bd Some optimization of the code mentioned by Sascha T.
Bjoern Ricks <bjoern.ricks@intevation.de>
parents: 3476
diff changeset
37 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
38
3481
e59588ea27bd Some optimization of the code mentioned by Sascha T.
Bjoern Ricks <bjoern.ricks@intevation.de>
parents: 3476
diff changeset
39 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
40 doc,
e59588ea27bd Some optimization of the code mentioned by Sascha T.
Bjoern Ricks <bjoern.ricks@intevation.de>
parents: 3476
diff changeset
41 XPATH_ROLES,
3476
4a6321dd5186 Implement a class representation of features corresponding to roles
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
42 XPathConstants.NODESET,
4a6321dd5186 Implement a class representation of features corresponding to roles
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
43 FeaturesNamespaceContext.INSTANCE);
4a6321dd5186 Implement a class representation of features corresponding to roles
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
44
3484
83845aa322ea XMLFileFeatures: Cosmetics.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3482
diff changeset
45 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
46 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
47
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
48 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
49
e59588ea27bd Some optimization of the code mentioned by Sascha T.
Bjoern Ricks <bjoern.ricks@intevation.de>
parents: 3476
diff changeset
50 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
51
e59588ea27bd Some optimization of the code mentioned by Sascha T.
Bjoern Ricks <bjoern.ricks@intevation.de>
parents: 3476
diff changeset
52 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
53 rolenode,
e59588ea27bd Some optimization of the code mentioned by Sascha T.
Bjoern Ricks <bjoern.ricks@intevation.de>
parents: 3476
diff changeset
54 XPATH_FEATURES,
e59588ea27bd Some optimization of the code mentioned by Sascha T.
Bjoern Ricks <bjoern.ricks@intevation.de>
parents: 3476
diff changeset
55 XPathConstants.NODESET,
e59588ea27bd Some optimization of the code mentioned by Sascha T.
Bjoern Ricks <bjoern.ricks@intevation.de>
parents: 3476
diff changeset
56 FeaturesNamespaceContext.INSTANCE);
e59588ea27bd Some optimization of the code mentioned by Sascha T.
Bjoern Ricks <bjoern.ricks@intevation.de>
parents: 3476
diff changeset
57
3484
83845aa322ea XMLFileFeatures: Cosmetics.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3482
diff changeset
58 if (features == null) {
83845aa322ea XMLFileFeatures: Cosmetics.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3482
diff changeset
59 continue;
83845aa322ea XMLFileFeatures: Cosmetics.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3482
diff changeset
60 }
83845aa322ea XMLFileFeatures: Cosmetics.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3482
diff changeset
61
83845aa322ea XMLFileFeatures: Cosmetics.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3482
diff changeset
62 int N = features.getLength();
83845aa322ea XMLFileFeatures: Cosmetics.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3482
diff changeset
63
83845aa322ea XMLFileFeatures: Cosmetics.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3482
diff changeset
64 if (N > 0) {
83845aa322ea XMLFileFeatures: Cosmetics.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3482
diff changeset
65 List<String> allowed = new ArrayList<String>(N);
83845aa322ea XMLFileFeatures: Cosmetics.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3482
diff changeset
66 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
67 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
68 String featurename = featurenode.getNodeValue();
e59588ea27bd Some optimization of the code mentioned by Sascha T.
Bjoern Ricks <bjoern.ricks@intevation.de>
parents: 3476
diff changeset
69
e59588ea27bd Some optimization of the code mentioned by Sascha T.
Bjoern Ricks <bjoern.ricks@intevation.de>
parents: 3476
diff changeset
70 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
71
e59588ea27bd Some optimization of the code mentioned by Sascha T.
Bjoern Ricks <bjoern.ricks@intevation.de>
parents: 3476
diff changeset
72 allowed.add(featurename);
e59588ea27bd Some optimization of the code mentioned by Sascha T.
Bjoern Ricks <bjoern.ricks@intevation.de>
parents: 3476
diff changeset
73 }
e59588ea27bd Some optimization of the code mentioned by Sascha T.
Bjoern Ricks <bjoern.ricks@intevation.de>
parents: 3476
diff changeset
74 featuremap.put(name, allowed);
3476
4a6321dd5186 Implement a class representation of features corresponding to roles
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
75 }
4a6321dd5186 Implement a class representation of features corresponding to roles
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
76 }
3481
e59588ea27bd Some optimization of the code mentioned by Sascha T.
Bjoern Ricks <bjoern.ricks@intevation.de>
parents: 3476
diff changeset
77 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
78 }
3481
e59588ea27bd Some optimization of the code mentioned by Sascha T.
Bjoern Ricks <bjoern.ricks@intevation.de>
parents: 3476
diff changeset
79 finally {
e59588ea27bd Some optimization of the code mentioned by Sascha T.
Bjoern Ricks <bjoern.ricks@intevation.de>
parents: 3476
diff changeset
80 finput.close();
e59588ea27bd Some optimization of the code mentioned by Sascha T.
Bjoern Ricks <bjoern.ricks@intevation.de>
parents: 3476
diff changeset
81 }
3476
4a6321dd5186 Implement a class representation of features corresponding to roles
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
82 }
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 @Override
4a6321dd5186 Implement a class representation of features corresponding to roles
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
85 public List<String> getFeatures(List<String> roles) {
3484
83845aa322ea XMLFileFeatures: Cosmetics.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3482
diff changeset
86 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
87
4a6321dd5186 Implement a class representation of features corresponding to roles
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
88 for (String role: roles) {
4a6321dd5186 Implement a class representation of features corresponding to roles
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
89 List<String> allowed = this.featuremap.get(role);
3484
83845aa322ea XMLFileFeatures: Cosmetics.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3482
diff changeset
90 if (allowed != null) {
3476
4a6321dd5186 Implement a class representation of features corresponding to roles
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
91 features.addAll(allowed);
4a6321dd5186 Implement a class representation of features corresponding to roles
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
92 }
4a6321dd5186 Implement a class representation of features corresponding to roles
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
93 }
4a6321dd5186 Implement a class representation of features corresponding to roles
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff changeset
94 return features;
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 }

http://dive4elements.wald.intevation.org