Mercurial > dive4elements > river
annotate flys-client/src/main/java/de/intevation/flys/client/server/features/XMLFileFeatures.java @ 3548:fed914a42a10
Merged revisions 5373,5377-5378 via svnmerge from
file:///home/clients/bsh/bsh-generischer-viewer/Material/SVN/flys-client/trunk
........
r5373 | ingo | 2012-09-07 11:21:25 +0200 (Fr, 07 Sep 2012) | 1 line
Tagged 'flys-client' as 2.9
........
r5377 | bricks | 2012-09-07 13:37:00 +0200 (Fr, 07 Sep 2012) | 2 lines
Move RemoteServiceServlet to server package
........
r5378 | bricks | 2012-09-07 13:58:11 +0200 (Fr, 07 Sep 2012) | 4 lines
Refactor UserServiceImpl getCurrentUser method
Return the logged in user in getCurrentUser method.
........
flys-client/tags/2.9@5381 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Ingo Weinzierl <ingo.weinzierl@intevation.de> |
---|---|
date | Fri, 07 Sep 2012 12:03:15 +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 } |