173 |
|
|
174 |
String trainNumber = fields.get(2).text(); |
String trainNumber = fields.get(2).text(); |
175 |
if (type == TrainType.STOG) //If it is S-train we need to extract the trainNumber |
if (type == TrainType.STOG) //If it is S-train we need to extract the trainNumber |
176 |
trainNumber = trainNumber + " " + extractTrainNumber(fields.get(2)); |
trainNumber = trainNumber + " " + extractTrainNumberAzure(fields.get(2)); |
177 |
departure.setTrainNumber(trainNumber); |
departure.setTrainNumber(trainNumber); |
178 |
|
|
179 |
String destination = fields.get(3).text(); |
String destination = fields.get(3).text(); |
220 |
|
|
221 |
|
|
222 |
|
|
223 |
String cleanText(String input) { |
public static String cleanText(String input) { |
224 |
//apparently JSoup interprets some of space characters on www.bane.dk as 0xA0 |
//apparently JSoup translates characters on www.bane.dk to 0xA0 |
225 |
return input.replace((char) 0xA0, (char)0x20).trim(); |
return input.replace((char) 0xA0, (char)0x20).trim(); |
226 |
} |
} |
227 |
|
|
231 |
|
|
232 |
String type = getTypeStringWww(trainType); |
String type = getTypeStringWww(trainType); |
233 |
|
|
234 |
|
stationcode = URLEncoder.encode(stationcode, "ISO-8859-1"); |
235 |
|
|
236 |
|
|
237 |
String uri = "http://www.bane.dk/visStation.asp?ArtikelID=4275&W=" + type + "&S=" + stationcode; |
String uri = "http://www.bane.dk/visStation.asp?ArtikelID=4275&W=" + type + "&S=" + stationcode; |
238 |
|
logger.info("URI:" + uri); |
239 |
JsoupInvocation wrapper = new JsoupInvocation( new URL(uri), replyTimeout); |
JsoupInvocation wrapper = new JsoupInvocation( new URL(uri), replyTimeout); |
240 |
CircuitBreaker breaker = CircuitBreakerManager.getManager().getCircuitBreaker("banedk"); |
CircuitBreaker breaker = CircuitBreakerManager.getManager().getCircuitBreaker("banedk"); |
241 |
|
|
266 |
|
|
267 |
String trainNumber = cleanText( fields.get(2).text() ); |
String trainNumber = cleanText( fields.get(2).text() ); |
268 |
if (type.equalsIgnoreCase("S2")) //If it is S-train we need to extract the trainNumber |
if (type.equalsIgnoreCase("S2")) //If it is S-train we need to extract the trainNumber |
269 |
trainNumber = trainNumber + " " + extractTrainNumber(fields.get(2)); |
trainNumber = trainNumber + " " + extractTrainNumberWww(fields.get(2)); |
270 |
departure.setTrainNumber(trainNumber); |
departure.setTrainNumber(trainNumber); |
271 |
|
|
272 |
String destination = cleanText( fields.get(3).text() ); |
String destination = cleanText( fields.get(3).text() ); |
329 |
return note.trim(); |
return note.trim(); |
330 |
} |
} |
331 |
|
|
332 |
private String extractTrainNumber(Element trainTd) { |
private String extractTrainNumberAzure(Element trainTd) { |
333 |
Element anchorElement = trainTd.getElementsByTag("a").get(0); |
Element anchorElement = trainTd.getElementsByTag("a").get(0); |
334 |
String href = anchorElement.attr("href"); |
String href = anchorElement.attr("href"); |
335 |
|
|
339 |
return number; |
return number; |
340 |
} |
} |
341 |
|
|
342 |
|
private String extractTrainNumberWww(Element trainTd) { |
343 |
|
String number = ""; |
344 |
|
Element anchorElement = trainTd.getElementsByTag("a").get(0); |
345 |
|
String href = anchorElement.attr("href"); |
346 |
|
String argstring = href.substring( href.indexOf('?') + 1); |
347 |
|
|
348 |
|
String args[] = argstring.split("&"); |
349 |
|
for (String arg : args) { |
350 |
|
String pair[] = arg.split("="); // Key=pair[0], Value=pair[1] |
351 |
|
|
352 |
|
if (pair[0].equalsIgnoreCase("TogNr")) |
353 |
|
number = pair[1]; |
354 |
|
} |
355 |
|
|
356 |
|
|
357 |
|
return number; |
358 |
|
} |
359 |
|
|
360 |
|
|
361 |
//test |
//test |
362 |
/* |
/* |
363 |
public static void main(String args[]) throws Exception { |
public static void main(String args[]) throws Exception { |