45 |
TimetableBean cachedLookupTimetable(String trainID, String type) throws Exception { |
TimetableBean cachedLookupTimetable(String trainID, String type) throws Exception { |
46 |
String key = trainID+type; |
String key = trainID+type; |
47 |
TimetableBean list = cache.get(key); |
TimetableBean list = cache.get(key); |
48 |
|
list = null; //TODO: DEBUG |
49 |
|
|
50 |
if (list == null) { |
if (list == null) { |
51 |
list = lookupTimetable(trainID,type); |
list = lookupTimetable(trainID,type); |
173 |
} |
} |
174 |
|
|
175 |
TimetableBean lookupTimetableMobileSite(String trainID, String type) throws Exception { |
TimetableBean lookupTimetableMobileSite(String trainID, String type) throws Exception { |
176 |
return new TimetableBean(); //dummy skeleton method |
TimetableBean timetableBean = new TimetableBean(); |
177 |
|
|
178 |
|
String url = "http://mobil.bane.dk/mobilStation.asp?artikelID=5332&tognummer=" + trainID + "&webprofil=" + type + "&mode=rute"; |
179 |
|
logger.fine("URL:" + url); |
180 |
|
|
181 |
|
|
182 |
|
JsoupInvocation wrapper = new JsoupInvocation( new URL(url) , settings.getReplyTimeout() ); |
183 |
|
CircuitBreaker breaker = CircuitBreakerManager.getManager().getCircuitBreaker("banedk"); |
184 |
|
|
185 |
|
Document doc = (Document) breaker.invoke(wrapper); |
186 |
|
|
187 |
|
Element content = doc.getElementsByClass("contentDiv").get(1); |
188 |
|
Element dlist = content.child(0); |
189 |
|
|
190 |
|
|
191 |
|
Elements rows = dlist.getElementsByTag("dt"); |
192 |
|
|
193 |
|
for (int i=0; i<rows.size(); i++) { |
194 |
|
|
195 |
|
Element row = rows.get(i); |
196 |
|
|
197 |
|
logger.info( row.text() ); |
198 |
|
|
199 |
|
String parts[] = row.text().split(","); |
200 |
|
|
201 |
|
TimetableEntry entry = new TimetableEntry(); |
202 |
|
|
203 |
|
String station = DepartureFetcher.cleanText( parts[0] ) ; |
204 |
|
if (station.equals("København")) |
205 |
|
station = "København H"; //correct inconsistency in naming |
206 |
|
|
207 |
|
String arrival = DepartureFetcher.cleanText( parts[1] ); |
208 |
|
String departure = DepartureFetcher.cleanText( "" ); |
209 |
|
|
210 |
|
entry.setStation( station ); |
211 |
|
entry.setArrival( arrival ); |
212 |
|
entry.setDeparture( departure ); |
213 |
|
|
214 |
|
|
215 |
|
entry.setStationId( getStationId( station )); |
216 |
|
|
217 |
|
timetableBean.entries.add(entry); |
218 |
|
} |
219 |
|
|
220 |
|
|
221 |
|
return timetableBean; |
222 |
|
|
223 |
} |
} |
224 |
|
|
225 |
@Deprecated |
@Deprecated |