218 |
return departureBean; |
return departureBean; |
219 |
} |
} |
220 |
|
|
221 |
|
|
222 |
|
|
223 |
|
String cleanText(String input) { |
224 |
|
//apparently JSoup interprets some of space characters on www.bane.dk as 0xA0 |
225 |
|
return input.replace((char) 0xA0, (char)0x20).trim(); |
226 |
|
} |
227 |
|
|
228 |
public DepartureBean lookupDeparturesWwwSite(String stationcode, TrainType trainType, boolean arrival) throws Exception { |
public DepartureBean lookupDeparturesWwwSite(String stationcode, TrainType trainType, boolean arrival) throws Exception { |
229 |
|
|
230 |
DepartureBean departureBean = new DepartureBean(); |
DepartureBean departureBean = new DepartureBean(); |
253 |
|
|
254 |
|
|
255 |
|
|
256 |
String time = fields.get(0).getAllElements().get(2).text(); |
String time = cleanText( fields.get(0).getAllElements().get(2).text() ); |
257 |
if (time.equals("")) |
if (time.equals("")) |
258 |
time = "0:00"; //Bane.dk bug work-around |
time = "0:00"; //Bane.dk bug work-around |
259 |
departure.setTime(time); |
departure.setTime(time); |
261 |
int updated = extractUpdated( fields.get(1) ); |
int updated = extractUpdated( fields.get(1) ); |
262 |
departure.setUpdated(updated); |
departure.setUpdated(updated); |
263 |
|
|
264 |
String trainNumber = fields.get(2).text(); |
String trainNumber = cleanText( fields.get(2).text() ); |
265 |
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 |
266 |
trainNumber = trainNumber + " " + extractTrainNumber(fields.get(2)); |
trainNumber = trainNumber + " " + extractTrainNumber(fields.get(2)); |
267 |
departure.setTrainNumber(trainNumber); |
departure.setTrainNumber(trainNumber); |
268 |
|
|
269 |
String destination = fields.get(3).text(); |
String destination = cleanText( fields.get(3).text() ); |
270 |
departure.setDestination(destination); |
departure.setDestination(destination); |
271 |
|
|
272 |
String origin = fields.get(4).text(); |
String origin = cleanText( fields.get(4).text() ); |
273 |
departure.setOrigin(origin); |
departure.setOrigin(origin); |
274 |
|
|
275 |
String location = fields.get(5).text(); |
String location = cleanText( fields.get(5).text() ); |
276 |
departure.setLocation(location); |
departure.setLocation(location); |
277 |
|
|
278 |
String status = fields.get(6).text().trim(); |
String status = cleanText( fields.get(6).text() ); |
279 |
departure.setStatus(status); |
departure.setStatus(status); |
280 |
|
|
281 |
String note = extractNote( fields.get(7) ); |
String note = cleanText( extractNote( fields.get(7) ) ); |
282 |
departure.setNote(note); |
departure.setNote(note); |
283 |
|
|
284 |
departure.setType(type); |
departure.setType(type); |
323 |
if (elems.size() > 0 && note.charAt(note.length()-1) == 'i') |
if (elems.size() > 0 && note.charAt(note.length()-1) == 'i') |
324 |
note = note.substring(0,note.length() -1 ); |
note = note.substring(0,note.length() -1 ); |
325 |
|
|
326 |
return note; |
return note.trim(); |
327 |
} |
} |
328 |
|
|
329 |
private String extractTrainNumber(Element trainTd) { |
private String extractTrainNumber(Element trainTd) { |