Mercurial > dive4elements > river
comparison gwt-client/src/main/java/org/dive4elements/river/client/server/FixingsOverviewServiceImpl.java @ 6867:0f3dad5d74a2
Client: Removed an XPath eval and simplified a loop.
author | Sascha L. Teichmann <teichmann@intevation.de> |
---|---|
date | Mon, 19 Aug 2013 16:02:48 +0200 |
parents | ea9eef426962 |
children | 0a5239a1e46e |
comparison
equal
deleted
inserted
replaced
6866:93c0a1692aa5 | 6867:0f3dad5d74a2 |
---|---|
31 import java.io.InputStream; | 31 import java.io.InputStream; |
32 | 32 |
33 import java.util.ArrayList; | 33 import java.util.ArrayList; |
34 import java.util.List; | 34 import java.util.List; |
35 | 35 |
36 import javax.xml.xpath.XPathConstants; | |
37 | |
38 import org.apache.log4j.Logger; | 36 import org.apache.log4j.Logger; |
39 | 37 |
40 import org.w3c.dom.Document; | 38 import org.w3c.dom.Document; |
41 import org.w3c.dom.Element; | 39 import org.w3c.dom.Element; |
42 import org.w3c.dom.NodeList; | 40 import org.w3c.dom.NodeList; |
55 | 53 |
56 protected static final String XPATH_RID = "/fixings/river/@rid"; | 54 protected static final String XPATH_RID = "/fixings/river/@rid"; |
57 protected static final String XPATH_RIVER = "/fixings/river/@name"; | 55 protected static final String XPATH_RIVER = "/fixings/river/@name"; |
58 protected static final String XPATH_RFROM = "/fixings/river/@from"; | 56 protected static final String XPATH_RFROM = "/fixings/river/@from"; |
59 protected static final String XPATH_RTO = "/fixings/river/@to"; | 57 protected static final String XPATH_RTO = "/fixings/river/@to"; |
60 | |
61 protected static final String XPATH_EVENT = "/fixings/events/event"; | |
62 | |
63 | 58 |
64 @Override | 59 @Override |
65 public FixingsOverviewInfo generateOverview( | 60 public FixingsOverviewInfo generateOverview( |
66 String locale, | 61 String locale, |
67 String uuid, | 62 String uuid, |
191 | 186 |
192 | 187 |
193 protected List<FixEvent> getFixEvents(Document doc) { | 188 protected List<FixEvent> getFixEvents(Document doc) { |
194 List<FixEvent> list = new ArrayList<FixEvent>(); | 189 List<FixEvent> list = new ArrayList<FixEvent>(); |
195 | 190 |
196 NodeList events = (NodeList) XMLUtils.xpath( | 191 NodeList events = doc.getElementsByTagName("event"); |
197 doc, | 192 |
198 XPATH_EVENT, | 193 int E = events.getLength(); |
199 XPathConstants.NODESET, | 194 |
200 null); | 195 if (E == 0) { |
201 | |
202 if (events == null || events.getLength() == 0) { | |
203 log.warn("No events in Overview!"); | 196 log.warn("No events in Overview!"); |
204 return list; | 197 return list; |
205 } | 198 } |
206 | 199 |
207 for (int i = 0, E = events.getLength(); i < E; i++) { | 200 for (int i = 0; i < E; i++) { |
208 Element n = (Element)events.item(i); | 201 Element n = (Element)events.item(i); |
209 List<Sector> sectors = getSectors(n); | 202 List<Sector> sectors = getSectors(n); |
210 String cid = n.getAttribute("cid"); | 203 String cid = n.getAttribute("cid"); |
211 String date = n.getAttribute("date");; | 204 String date = n.getAttribute("date");; |
212 String name = n.getAttribute("description"); | 205 String name = n.getAttribute("description"); |
216 } | 209 } |
217 | 210 |
218 protected List<Sector> getSectors(Element event) { | 211 protected List<Sector> getSectors(Element event) { |
219 NodeList sectors = event.getElementsByTagName("sector"); | 212 NodeList sectors = event.getElementsByTagName("sector"); |
220 | 213 |
221 if (sectors.getLength() == 0) { | 214 int S = sectors.getLength(); |
215 | |
216 if (S == 0) { | |
222 log.warn("No Sectors in Event!"); | 217 log.warn("No Sectors in Event!"); |
223 return null; | 218 return null; |
224 } | 219 } |
225 | 220 |
226 List<Sector> list = new ArrayList<Sector>(); | 221 List<Sector> list = new ArrayList<Sector>(S); |
227 for (int i = 0, S = sectors.getLength(); i < S; i++) { | 222 for (int i = 0; i < S; i++) { |
228 Element n = (Element)sectors.item(i); | 223 Element n = (Element)sectors.item(i); |
229 int cls = -1; | 224 int cls = -1; |
230 double from = -1; | 225 double from = -1; |
231 double to = -1; | 226 double to = -1; |
232 String cls_str = n.getAttribute("class"); | 227 String cls_str = n.getAttribute("class"); |