/[projects]/android/TrainInfoService/src/dk/thoerup/traininfoservice/banedk/DepartureFetcher.java
ViewVC logotype

Diff of /android/TrainInfoService/src/dk/thoerup/traininfoservice/banedk/DepartureFetcher.java

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1035 by torben, Wed Sep 8 12:38:26 2010 UTC revision 1039 by torben, Sun Sep 12 19:03:32 2010 UTC
# Line 79  public class DepartureFetcher { Line 79  public class DepartureFetcher {
79                          departureBean.notifications.addAll(tempBean.notifications);                          departureBean.notifications.addAll(tempBean.notifications);
80                  }                                }              
81                                    
82                    if (departureBean.departureEntries.size() == 0) {
83                            logger.info("No departures found for station " + stationID);
84                    }
85                    
86                  Collections.sort( departureBean.departureEntries );                  Collections.sort( departureBean.departureEntries );
87    
88                                    
# Line 169  public class DepartureFetcher { Line 173  public class DepartureFetcher {
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();
# Line 214  public class DepartureFetcher { Line 218  public class DepartureFetcher {
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();
# Line 242  public class DepartureFetcher { Line 253  public class DepartureFetcher {
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);
# Line 250  public class DepartureFetcher { Line 261  public class DepartureFetcher {
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 + " " + extractTrainNumberWww(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);
# Line 312  public class DepartureFetcher { Line 323  public class DepartureFetcher {
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 extractTrainNumberAzure(Element trainTd) {
330                  Element anchorElement = trainTd.getElementsByTag("a").get(0);                  Element anchorElement = trainTd.getElementsByTag("a").get(0);
331                  String href = anchorElement.attr("href");                  String href = anchorElement.attr("href");
332                                    
# Line 325  public class DepartureFetcher { Line 336  public class DepartureFetcher {
336                  return number;                  return number;
337          }          }
338                    
339            private String extractTrainNumberWww(Element trainTd) {
340                    String number = "";
341                    Element anchorElement = trainTd.getElementsByTag("a").get(0);
342                    String href = anchorElement.attr("href");
343                    String argstring = href.substring( href.indexOf('?') + 1);
344                    
345                    String args[] = argstring.split("&");
346                    for (String arg : args) {
347                            String pair[] = arg.split("="); // Key=pair[0], Value=pair[1]
348                            
349                            if (pair[0].equalsIgnoreCase("TogNr"))
350                                    number = pair[1];
351                    }
352                    
353                    
354                    return number;
355            }
356    
357            
358          //test          //test
359          /*          /*
360          public static void main(String args[]) throws Exception {          public static void main(String args[]) throws Exception {

Legend:
Removed from v.1035  
changed lines
  Added in v.1039

  ViewVC Help
Powered by ViewVC 1.1.20