/[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 1037 by torben, Sat Sep 11 07:43:09 2010 UTC revision 1038 by torben, Sun Sep 12 18:41:17 2010 UTC
# Line 218  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 246  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 254  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 + " " + 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);
# Line 316  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 extractTrainNumber(Element trainTd) {

Legend:
Removed from v.1037  
changed lines
  Added in v.1038

  ViewVC Help
Powered by ViewVC 1.1.20