Mercurial > dive4elements > river
annotate flys-client/src/main/java/de/intevation/flys/client/server/features/XMLFileFeatures.java @ 3497:88feb3347aa5
Implement a ProxyServlet
Implement a ProxyServlet to be able to restrict the access to the
mapserver too. All queries to the provided map services should go throught
this new ProxyServlet. Currently the ProxyServlet can only handle HTTP GET
requests.
flys-client/trunk@5221 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Bjoern Ricks <bjoern.ricks@intevation.de> |
---|---|
date | Thu, 16 Aug 2012 14:42:36 +0000 |
parents | 5f628a13ca9f |
children | 02cf2b1dff84 |
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); |
4a6321dd5186
Implement a class representation of features corresponding to roles
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
35 |
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 } |