Mercurial > dive4elements > river
comparison flys-client/src/main/java/de/intevation/flys/client/server/features/XMLFileFeatures.java @ 3481:e59588ea27bd
Some optimization of the code mentioned by Sascha T.
flys-client/trunk@5176 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Bjoern Ricks <bjoern.ricks@intevation.de> |
---|---|
date | Wed, 08 Aug 2012 13:39:35 +0000 |
parents | 4a6321dd5186 |
children | c64cad8dc772 |
comparison
equal
deleted
inserted
replaced
3480:14d37be8541e | 3481:e59588ea27bd |
---|---|
22 | 22 |
23 private static final Logger logger = Logger.getLogger(XMLFileFeatures.class); | 23 private static final Logger logger = Logger.getLogger(XMLFileFeatures.class); |
24 | 24 |
25 private Hashtable<String, List<String>> featuremap = new Hashtable<String, List<String>>(); | 25 private Hashtable<String, List<String>> featuremap = new Hashtable<String, List<String>>(); |
26 | 26 |
27 private final static String XPATH_FEATURES = "ftr:feature/child::text()"; | |
28 private final static String XPATH_ROLES = "/ftr:features/ftr:role"; | |
29 | |
27 public XMLFileFeatures(String filename) throws IOException { | 30 public XMLFileFeatures(String filename) throws IOException { |
28 FileInputStream finput = new FileInputStream(filename); | 31 FileInputStream finput = new FileInputStream(filename); |
29 Document doc = XMLUtils.parseDocument(finput); | |
30 | 32 |
31 String XPATH_FEATURES = "ftr:feature/child::text()"; | 33 try { |
32 String XPATH_ROLES = "/ftr:features/ftr:role"; | 34 Document doc = XMLUtils.parseDocument(finput); |
33 | 35 |
34 NodeList roles = (NodeList) XMLUtils.xpath( | 36 NodeList roles = (NodeList) XMLUtils.xpath( |
35 doc, | 37 doc, |
36 XPATH_ROLES, | 38 XPATH_ROLES, |
37 XPathConstants.NODESET, | |
38 FeaturesNamespaceContext.INSTANCE); | |
39 | |
40 for(int i=0; i < roles.getLength(); i++) { | |
41 Node rolenode = roles.item(i); | |
42 | |
43 String name = XMLUtils.xpathString( | |
44 rolenode, "@name", FeaturesNamespaceContext.INSTANCE); | |
45 | |
46 logger.debug("Found role: " + name); | |
47 | |
48 NodeList features = (NodeList) XMLUtils.xpath( | |
49 rolenode, | |
50 XPATH_FEATURES, | |
51 XPathConstants.NODESET, | 39 XPathConstants.NODESET, |
52 FeaturesNamespaceContext.INSTANCE); | 40 FeaturesNamespaceContext.INSTANCE); |
53 | 41 |
54 if (features.getLength() > 0) { | 42 for(int i=0, m = roles.getLength(); i < m; i++) { |
55 List<String> allowed = new LinkedList<String>(); | 43 Element rolenode = (Element)roles.item(i); |
56 for (int j=0; j < features.getLength(); j++) { | |
57 Node featurenode = features.item(j); | |
58 String featurename = featurenode.getNodeValue(); | |
59 | 44 |
60 logger.debug("found feature: " + featurename); | 45 String name = rolenode.getAttributeNS( |
46 FeaturesNamespaceContext.NAMESPACE_URI, "name"); | |
61 | 47 |
62 allowed.add(featurename); | 48 logger.debug("Found role: " + name); |
49 | |
50 NodeList features = (NodeList) XMLUtils.xpath( | |
51 rolenode, | |
52 XPATH_FEATURES, | |
53 XPathConstants.NODESET, | |
54 FeaturesNamespaceContext.INSTANCE); | |
55 | |
56 if (features.getLength() > 0) { | |
57 List<String> allowed = new ArrayList<String>(features.getLength()); | |
58 for (int j=0, l = features.getLength(); j < l; j++) { | |
59 Node featurenode = features.item(j); | |
60 String featurename = featurenode.getNodeValue(); | |
61 | |
62 logger.debug("Found feature: " + featurename); | |
63 | |
64 allowed.add(featurename); | |
65 } | |
66 featuremap.put(name, allowed); | |
63 } | 67 } |
64 featuremap.put(name, allowed); | |
65 } | 68 } |
69 logger.debug("Loaded all features"); | |
66 } | 70 } |
67 logger.debug("Loaded all features"); | 71 finally { |
68 | 72 finput.close(); |
69 finput.close(); | 73 } |
70 } | 74 } |
71 | 75 |
72 @Override | 76 @Override |
73 public List<String> getFeatures(List<String> roles) { | 77 public List<String> getFeatures(List<String> roles) { |
74 List<String> features = new LinkedList<String>(); | 78 List<String> features = new LinkedList<String>(); |