Mercurial > dive4elements > river
comparison flys-client/src/main/java/de/intevation/flys/client/server/RiverInfoServiceImpl.java @ 4288:b6f2ecaa6704
Parse start and end time of an observation
Parse start and end time of an observation from the artifact server xml
response.
author | Björn Ricks <bjoern.ricks@intevation.de> |
---|---|
date | Mon, 29 Oct 2012 09:56:55 +0100 |
parents | 06d9098a609a |
children | 87362ba26c72 |
comparison
equal
deleted
inserted
replaced
4287:82c1e911dd71 | 4288:b6f2ecaa6704 |
---|---|
1 package de.intevation.flys.client.server; | 1 package de.intevation.flys.client.server; |
2 | 2 |
3 import java.text.DateFormat; | |
4 import java.text.ParseException; | |
3 import java.util.ArrayList; | 5 import java.util.ArrayList; |
6 import java.util.Date; | |
4 import java.util.List; | 7 import java.util.List; |
8 import java.util.Locale; | |
5 import javax.xml.xpath.XPathConstants; | 9 import javax.xml.xpath.XPathConstants; |
6 | 10 |
7 import org.apache.log4j.Logger; | 11 import org.apache.log4j.Logger; |
8 | 12 |
9 import org.w3c.dom.Document; | 13 import org.w3c.dom.Document; |
45 private static final String XPATH_STATIONS = | 49 private static final String XPATH_STATIONS = |
46 "/art:river-info/art:measurement-stations/art:measurement-station"; | 50 "/art:river-info/art:measurement-stations/art:measurement-station"; |
47 | 51 |
48 private static final String XPATH_GAUGES = "/art:river-info/art:gauges/art:gauge"; | 52 private static final String XPATH_GAUGES = "/art:river-info/art:gauges/art:gauge"; |
49 | 53 |
54 public static final DateFormat DATE_FORMAT = DateFormat.getDateInstance( | |
55 DateFormat.SHORT, Locale.GERMANY); | |
56 | |
50 public RiverInfo getGauges(String river) throws ServerException { | 57 public RiverInfo getGauges(String river) throws ServerException { |
51 logger.info("RiverInfoServiceImpl.getRiverInfo"); | 58 logger.info("RiverInfoServiceImpl.getRiverInfo"); |
52 | 59 |
53 String url = getServletContext().getInitParameter("server-url"); | 60 String url = getServletContext().getInitParameter("server-url"); |
54 | 61 |
163 } | 170 } |
164 try { | 171 try { |
165 return Integer.valueOf(value); | 172 return Integer.valueOf(value); |
166 } | 173 } |
167 catch(NumberFormatException e) { | 174 catch(NumberFormatException e) { |
175 logger.error(e, e); | |
176 return null; | |
177 } | |
178 } | |
179 | |
180 private Date parseDate(String value) { | |
181 if (value == null || value.isEmpty()) { | |
182 return null; | |
183 } | |
184 try { | |
185 return DATE_FORMAT.parse(value); | |
186 } | |
187 catch(ParseException e) { | |
168 logger.error(e, e); | 188 logger.error(e, e); |
169 return null; | 189 return null; |
170 } | 190 } |
171 } | 191 } |
172 | 192 |
206 ArtifactNamespaceContext.NAMESPACE_URI, "riverside"); | 226 ArtifactNamespaceContext.NAMESPACE_URI, "riverside"); |
207 String mid = stationele.getAttributeNS( | 227 String mid = stationele.getAttributeNS( |
208 ArtifactNamespaceContext.NAMESPACE_URI, "id"); | 228 ArtifactNamespaceContext.NAMESPACE_URI, "id"); |
209 String moperator = stationele.getAttributeNS( | 229 String moperator = stationele.getAttributeNS( |
210 ArtifactNamespaceContext.NAMESPACE_URI, "operator"); | 230 ArtifactNamespaceContext.NAMESPACE_URI, "operator"); |
231 String mstarttime = stationele.getAttributeNS( | |
232 ArtifactNamespaceContext.NAMESPACE_URI, "starttime"); | |
233 String mstoptime = stationele.getAttributeNS( | |
234 ArtifactNamespaceContext.NAMESPACE_URI, "stoptime"); | |
211 | 235 |
212 logger.debug("Found measurement station with name " + mname); | 236 logger.debug("Found measurement station with name " + mname); |
213 | 237 |
214 MeasurementStation station = new DefaultMeasurementStation( | 238 MeasurementStation station = new DefaultMeasurementStation( |
215 rivername, | 239 rivername, |
219 parseDouble(mstart), | 243 parseDouble(mstart), |
220 parseDouble(mend), | 244 parseDouble(mend), |
221 kmup, | 245 kmup, |
222 riverside, | 246 riverside, |
223 mtype, | 247 mtype, |
224 moperator | 248 moperator, |
249 parseDate(mstarttime), | |
250 parseDate(mstoptime) | |
225 ); | 251 ); |
226 | 252 |
227 mstations.add(station); | 253 mstations.add(station); |
228 } | 254 } |
229 } | 255 } |