16 |
import dk.thoerup.android.traininfo.common.StationBean.StationEntry; |
import dk.thoerup.android.traininfo.common.StationBean.StationEntry; |
17 |
import dk.thoerup.circuitbreaker.CircuitBreaker; |
import dk.thoerup.circuitbreaker.CircuitBreaker; |
18 |
import dk.thoerup.circuitbreaker.CircuitBreakerManager; |
import dk.thoerup.circuitbreaker.CircuitBreakerManager; |
19 |
|
import dk.thoerup.genericjavautils.HttpUtil; |
20 |
import dk.thoerup.genericjavautils.TimeoutMap; |
import dk.thoerup.genericjavautils.TimeoutMap; |
21 |
import dk.thoerup.traininfoservice.Statistics; |
import dk.thoerup.traininfoservice.Statistics; |
22 |
import dk.thoerup.traininfoservice.TraininfoSettings; |
import dk.thoerup.traininfoservice.TraininfoSettings; |
292 |
int updated = 4; //does not exist on mobile |
int updated = 4; //does not exist on mobile |
293 |
departure.setUpdated(updated); |
departure.setUpdated(updated); |
294 |
|
|
295 |
String trainNumber = "-"; //extractTrainNumberAzure(fields.get(2)); |
String trainNumber = extractTrainNumberMobile(link); |
296 |
/*if (traintype == TrainType.STOG) //If it is S-train we need to extract the trainNumber |
/*if (traintype == TrainType.STOG) //If it is S-train we need to extract the trainNumber |
297 |
trainNumber = trainNumber + " " + extractTrainNumberAzure(fields.get(2));*/ |
trainNumber = trainNumber + " " + extractTrainNumberAzure(fields.get(2));*/ |
298 |
departure.setTrainNumber(trainNumber); |
departure.setTrainNumber(trainNumber); |
299 |
|
|
300 |
if (traintype == TrainType.STOG) { //if it is stog the next vield is the "Line" code - this should be used somewhere, but skippint ahead for now |
if (traintype == TrainType.STOG) { //if it is stog the next vield is the "Line" code - this should be used somewhere, but skippint ahead for now |
301 |
offset++; |
String stogLine = parts[offset++].trim(); |
302 |
|
departure.setTrainNumber(stogLine + " " + trainNumber); |
303 |
} |
} |
304 |
|
|
305 |
String destination = parts[offset++]; |
String destination = parts[offset++].trim();; |
306 |
departure.setDestination(destination); |
departure.setDestination(destination); |
307 |
|
|
308 |
String origin = "-"; // fields.get(4).text(); does not exist on mobile |
String origin = "-"; // fields.get(4).text(); does not exist on mobile |
323 |
continue; |
continue; |
324 |
} |
} |
325 |
|
|
326 |
String status = parts[offset++]; //fields.get(6).text().trim(); - extract from url |
String status = parts[offset++].trim();; //fields.get(6).text().trim(); - extract from url |
327 |
departure.setStatus(status); |
departure.setStatus(status); |
328 |
|
|
329 |
String note = ""; //extractNote( fields.get(7) ); - extract from url |
String note = ""; //extractNote( fields.get(7) ); - extract from url |
478 |
return number; |
return number; |
479 |
} |
} |
480 |
|
|
481 |
|
private String extractTrainNumberMobile(String link) { |
482 |
|
Map<String,String> elements = HttpUtil.decodeParams(link); |
483 |
|
|
484 |
|
return elements.get("tognummer"); |
485 |
|
} |
486 |
|
|
487 |
private String extractTrainNumberWww(Element trainTd) { |
private String extractTrainNumberWww(Element trainTd) { |
488 |
String number = ""; |
String number = ""; |
489 |
Element anchorElement = trainTd.getElementsByTag("a").get(0); |
Element anchorElement = trainTd.getElementsByTag("a").get(0); |
490 |
String href = anchorElement.attr("href"); |
String href = anchorElement.attr("href"); |
491 |
String argstring = href.substring( href.indexOf('?') + 1); |
|
492 |
|
String argstring = href.split("?")[1]; |
493 |
|
Map<String,String> elements = HttpUtil.decodeParams(argstring); |
494 |
|
number = elements.get("TogNr"); |
495 |
|
|
496 |
|
|
497 |
|
/*String argstring = href.substring( href.indexOf('?') + 1); |
498 |
String args[] = argstring.split("&"); |
String args[] = argstring.split("&"); |
499 |
for (String arg : args) { |
for (String arg : args) { |
500 |
String pair[] = arg.split("="); // Key=pair[0], Value=pair[1] |
String pair[] = arg.split("="); // Key=pair[0], Value=pair[1] |
501 |
|
|
502 |
if (pair[0].equalsIgnoreCase("TogNr")) |
if (pair[0].equalsIgnoreCase("TogNr")) |
503 |
number = pair[1]; |
number = pair[1]; |
504 |
} |
}*/ |
505 |
|
|
506 |
|
|
507 |
return number; |
return number; |
508 |
} |
} |