/[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 829 by torben, Thu Jun 10 22:26:09 2010 UTC revision 1333 by torben, Wed Apr 20 06:26:19 2011 UTC
# Line 1  Line 1 
1  package dk.thoerup.traininfoservice.banedk;  package dk.thoerup.traininfoservice.banedk;
2    
3  import java.util.ArrayList;  
4    import java.net.URL;
5    import java.net.URLEncoder;
6  import java.util.Collections;  import java.util.Collections;
 import java.util.List;  
7  import java.util.Map;  import java.util.Map;
8  import java.util.logging.Logger;  import java.util.logging.Logger;
9    
10  import com.gargoylesoftware.htmlunit.BrowserVersion;  import org.jsoup.nodes.Document;
11  import com.gargoylesoftware.htmlunit.WebClient;  import org.jsoup.nodes.Element;
12  import com.gargoylesoftware.htmlunit.html.DomNodeList;  import org.jsoup.select.Elements;
13  import com.gargoylesoftware.htmlunit.html.HtmlElement;  
14  import com.gargoylesoftware.htmlunit.html.HtmlPage;  import dk.thoerup.android.traininfo.common.DepartureBean;
15    import dk.thoerup.android.traininfo.common.DepartureEntry;
16    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;
 import dk.thoerup.traininfoservice.StationBean;  
 import dk.thoerup.traininfoservice.StationDAO;  
19  import dk.thoerup.traininfoservice.Statistics;  import dk.thoerup.traininfoservice.Statistics;
20    import dk.thoerup.traininfoservice.TraininfoSettings;
21    import dk.thoerup.traininfoservice.db.StationDAO;
22    
23  public class DepartureFetcher {  public class DepartureFetcher {
24                    
25            enum TrainType{
26                    STOG,
27                    REGIONAL
28            }
29            
30            enum FetchTrainType {
31                    STOG,
32                    REGIONAL,
33                    BOTH
34            }
35            
36          Logger logger = Logger.getLogger(DepartureFetcher.class.getName());          Logger logger = Logger.getLogger(DepartureFetcher.class.getName());
37                    
38          Map<String, List<DepartureBean>> cache;          Map<String, DepartureBean> cache;
39                    
40          StationDAO stationDao = new StationDAO();          StationDAO stationDao = new StationDAO();
41                    
42          private boolean useTempSite;  
43            private TraininfoSettings settings;
44                    
45          public DepartureFetcher(boolean tempSite, int cacheTimeout) {          public DepartureFetcher(TraininfoSettings settings) {
46                  useTempSite = tempSite;                  this.settings = settings;
47                  cache = new TimeoutMap<String,List<DepartureBean>>(cacheTimeout);                  cache = new TimeoutMap<String,DepartureBean>( settings.getCacheTimeout() );
48          }          }
49                    
50                    
51                                    
52                    
53          public List<DepartureBean> cachedLookupDepartures(int stationID, boolean arrival) throws Exception {          public DepartureBean cachedLookupDepartures(int stationID, boolean arrival, FetchTrainType type) throws Exception {
54                  final String key = "" + stationID + ":" + arrival;                  
55                    final String key = "" + stationID + ":" + arrival + ":" + type.toString();
56                                    
57                  List<DepartureBean> list = cache.get(key);                  DepartureBean departureBean = cache.get(key);
58    
59                                    
60                  if (list == null) {                  if (departureBean == null) {
61                          list = lookupDepartures(stationID,arrival);                          departureBean = lookupDepartures(stationID, arrival, type);
62                          cache.put(key, list);                          cache.put(key, departureBean);
63                  } else {                  } else {
64                          Statistics.getInstance().incrementDepartureCacheHits();                          Statistics.getInstance().incrementDepartureCacheHits();
65                          logger.info("Departure: Cache hit " + key); //remove before production                          logger.info("Departure: Cache hit " + key); //remove before production
66                  }                  }
67                  return list;                  return departureBean;
68          }          }
69                                    
70    
71          public List<DepartureBean> lookupDepartures(int stationID, boolean arrival) throws Exception {          public DepartureBean lookupDepartures(int stationID, boolean arrival, FetchTrainType type) throws Exception {
                 List<DepartureBean> departureList = new ArrayList<DepartureBean>();  
72                                    
73                  StationBean station = stationDao.getById(stationID);                  DepartureBean departureBean = new DepartureBean();
74                                    
75                  if (station.getRegional() != null) {                  StationEntry station = stationDao.getById(stationID);
76                          List<DepartureBean> list = lookupDepartures(station.getRegional(), "FJRN", arrival);                  
77                          departureList.addAll(list);                                      departureBean.stationName = station.getName();
78    
79                    if (station.getRegional() != null && (type == FetchTrainType.REGIONAL||type == FetchTrainType.BOTH) ) {
80                            DepartureBean tempBean = lookupDepartures(station.getRegional(), TrainType.REGIONAL, arrival);
81                            departureBean.entries.addAll( tempBean.entries );
82                            departureBean.notifications.addAll(tempBean.notifications);
83                  }                  }
84                                    
85                  if (station.getStrain() != null) {                  if (station.getStrain() != null && (type == FetchTrainType.STOG||type == FetchTrainType.BOTH)) {
86                          List<DepartureBean> list = lookupDepartures(station.getStrain(), "S2", arrival);                          DepartureBean tempBean = lookupDepartures(station.getStrain(), TrainType.STOG, arrival);
87                          departureList.addAll(list);                              departureBean.entries.addAll( tempBean.entries );
88                            departureBean.notifications.addAll(tempBean.notifications);
89                  }                                }              
90                                    
91                  Collections.sort( departureList );                  if (departureBean.entries.size() == 0) {
92                            logger.info("No departures found for station " + stationID);
93                    }
94                    
95                    if (type == FetchTrainType.BOTH) { //if we have both S-tog and regional order by departure/arrival time
96                            Collections.sort( departureBean.entries );
97                    }
98    
99                                    
100                  return departureList;                  return departureBean;
101          }          }
102                    
103          public List<DepartureBean> lookupDepartures(String stationcode, String type, boolean arrival) throws Exception {          public DepartureBean lookupDepartures(String stationcode, TrainType type, boolean arrival) throws Exception {
104                  if (useTempSite == false) {                  if ( settings.getUseAzureSite() == true) {
105                          return lookupDeparturesNormalSite(stationcode, type, arrival);                          return lookupDeparturesAzureSite(stationcode, type, arrival);
106                  } else {                  } else {
107                          return lookupDeparturesFromTemporarySite(stationcode, type);                          return lookupDeparturesMobileSite(stationcode, type, arrival);
108                  }                  }
109          }          }
110                    
111          public List<DepartureBean> lookupDeparturesNormalSite(String stationcode, String type, boolean arrival) throws Exception {          private String getTypeStringAzure(TrainType type) {
112                                    switch (type) {
113                  List<DepartureBean> departureList = new ArrayList<DepartureBean>();                  case STOG:
114                            return "S-Tog";
115                    case REGIONAL:
116                            return "Fjerntog";
117                    default:
118                            return ""; //Can not happen
119                    }
120            }
121            
122            private String getTypeStringWww(TrainType type) {
123                    switch (type) {
124                    case STOG:
125                            return "S2";
126                    case REGIONAL:
127                            return "FJRN";
128                    default:
129                            return ""; //Can not happen
130                    }
131            }
132            
133            public DepartureBean lookupDeparturesAzureSite(String stationcode, TrainType type, boolean arrival) throws Exception {
134                                    
135              final WebClient webClient = new WebClient( BrowserVersion.FIREFOX_3 );                  DepartureBean departureBean = new DepartureBean();
136              webClient.setTimeout(2500);                  
             webClient.setJavaScriptEnabled(false);  
                               
             String uri = "http://www.bane.dk/visStation.asp?ArtikelID=4275&W=" + type + "&S=" + stationcode;  
             BanedkInvocation wrapper = new BanedkInvocation(webClient, uri);  
             CircuitBreaker breaker = CircuitBreakerManager.getManager().getCircuitBreaker("banedk");  
137                            
138              HtmlPage page = (HtmlPage) breaker.invoke(wrapper);              String typeString = getTypeStringAzure(type);
139                String arrivalDeparture = (arrival==false) ? "Afgang" : "Ankomst";
140                            
141              String tableName = arrival == false ? "afgangtabel" : "ankomsttabel";              stationcode = URLEncoder.encode(stationcode,"ISO-8859-1");
142    
143                String uri = "http://trafikinfo.bane.dk/Trafikinformation/AfgangAnkomst/" + arrivalDeparture + "/" + stationcode + "/" + typeString + "/UdvidetVisning";        
144                
145                logger.fine("URI: " + uri);    
146                JsoupInvocation wrapper = new JsoupInvocation( new URL(uri), settings.getReplyTimeout() );
147                CircuitBreaker breaker = CircuitBreakerManager.getManager().getCircuitBreaker("banedk");
148                            
149              System.out.println(uri);              Document page = (Document) breaker.invoke(wrapper);
             System.out.println(tableName);  
150                            
151              HtmlElement table = page.getElementById(tableName);              String tableName = arrival == false ? "afgangtabel" : "ankomsttabel";
152                Element table = page.getElementById(tableName);
153                            
154              if (table != null) {              if (table != null) {
155                      DomNodeList<HtmlElement> tableRows =  table.getElementsByTagName("tr");                      Elements tableRows =  table.getElementsByTag("tr");
156                                            
157                      for (HtmlElement currentRow : tableRows) {                      //boolean tidsstregExists = (table.getElementsByAttributeValue("class", "Tidsstreg").size() > 0);
158                          String rowClass = currentRow.getAttribute("class");                      //boolean passedTidsstreg = false;
159                        
160                        for (Element currentRow : tableRows) {
161                            String rowClass = currentRow.attr("class");
162                            /*
163                            if (tidsstregExists == true && passedTidsstreg == false) {
164                                    if (currentRow.getElementsByAttributeValue("class", "Tidsstreg").size() > 0) {
165                                            passedTidsstreg = true;
166                                    } else {
167                                            continue;
168                                    }
169                            }*/
170                            
171                          if (rowClass != null && rowClass.toLowerCase().contains("station") ) {                          if (rowClass != null && rowClass.toLowerCase().contains("station") ) {
172                                  DomNodeList<HtmlElement> fields = currentRow.getElementsByTagName("td");                                  
173                                    Elements fields = currentRow.getElementsByTag("td");
174                    
175                                  DepartureBean departure = new DepartureBean();                                  DepartureEntry departure = new DepartureEntry();
176                                                                    
177                                  String time = fields.get(0).asText();                                  String time = fields.get(0).text();
178                                  if (time.equals(""))                                  if (time.equals(""))
179                                          time = "0:00"; //Bane.dk bug work-around                                          time = "0:00"; //Bane.dk bug work-around
180                                  departure.setTime(time);                                  departure.setTime(time);
# Line 121  public class DepartureFetcher { Line 182  public class DepartureFetcher {
182                                  int updated = extractUpdated( fields.get(1) );                                  int updated = extractUpdated( fields.get(1) );
183                                  departure.setUpdated(updated);                                  departure.setUpdated(updated);
184                                                                    
185                                  String trainNumber = fields.get(2).asText();                                  String trainNumber = fields.get(2).text();
186                                  if (type.equalsIgnoreCase("S2")) //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
187                                          trainNumber = trainNumber + " " + extractTrainNumber(fields.get(2));                                          trainNumber = trainNumber + " " + extractTrainNumberAzure(fields.get(2));
188                                  departure.setTrainNumber(trainNumber);                                  departure.setTrainNumber(trainNumber);
189                                                                    
190                                  String destination = fields.get(3).asText();                                  String destination = fields.get(3).text();
191                                  departure.setDestination(destination);                                  departure.setDestination(destination);
192                                                                    
193                                  String origin = fields.get(4).asText();                                  String origin = fields.get(4).text();
194                                  departure.setOrigin(origin);                                  departure.setOrigin(origin);
195                                                                    
196                                  String location = fields.get(5).asText();                                  String location = fields.get(5).text();
197                                  departure.setLocation(location);                                  departure.setLocation(location);
198                                                                    
199                                  String status = fields.get(6).asText();                                  String status = fields.get(6).text().trim();
200                                  departure.setStatus(status);                                  departure.setStatus(status);
201                                                                    
202                                  String note = extractNote( fields.get(7) );                                  String note = extractNote( fields.get(7) );
203                                  departure.setNote(note);                                  departure.setNote(note);
204                                                                    
205                                  departure.setType(type);                                  departure.setType(typeString);
206                                                                    
207                                  departureList.add(departure);                                  departureBean.entries.add( departure );
208                          }                          }
209                      }                      }
210              } else {              } else {
211                  logger.warning("No departures found for station=" + stationcode + ", type=" + type);                  logger.warning("No departures found for station=" + stationcode + ", type=" + type);
212              }              }
             webClient.closeAllWindows();  
213                            
214              return departureList;              Element notifDiv = page.getElementById("station_planlagte_text");
215                if (notifDiv != null) {
216    
217                    Elements tables = notifDiv.getElementsByTag("table");
218                    for (Element tab : tables) {
219    
220                            Elements anchors = tab.getElementsByTag("a");          
221                            if (anchors.size() == 2) {
222                                    departureBean.notifications.add(  anchors.get(1).text() );
223                            }
224                    }
225                    
226                }
227                
228                
229                return departureBean;
230          }          }
231                    
232          public List<DepartureBean> lookupDeparturesFromTemporarySite(String stationcode, String type) throws Exception {          public DepartureBean lookupDeparturesMobileSite(String stationcode, TrainType traintype, boolean arrival) throws Exception {
                   
                 List<DepartureBean> departureList = new ArrayList<DepartureBean>();  
233                                    
234              final WebClient webClient = new WebClient(BrowserVersion.FIREFOX_3);                  DepartureBean departureBean = new DepartureBean();
235              webClient.setTimeout(2500);                  
             webClient.setJavaScriptEnabled(false);  
236                            
237                    String typeString = getTypeStringWww(traintype);
238              String uri = "http://bane.dk/lite/station.asp?w=" + type + "&s=" + stationcode;              String arrivalDeparture = (arrival==false) ? "afgang" : "ankomst";
239                            
240              BanedkInvocation wrapper = new BanedkInvocation(webClient, uri);              stationcode = URLEncoder.encode(stationcode,"ISO-8859-1");
241    
242                //String uri = "http://trafikinfo.bane.dk/Trafikinformation/AfgangAnkomst/" + arrivalDeparture + "/" + stationcode + "/" + typeString + "/UdvidetVisning";      
243                String uri = "http://mobil.bane.dk/mobilStation.asp?artikelID=5332&stat_kode=" + stationcode + "&webprofil=" + typeString  +"&beskrivelse=&mode=ankomstafgang&ankomstafgang=" + arrivalDeparture + "&gemstation=&fuldvisning=1";
244                logger.fine("URI: " + uri);    
245                JsoupInvocation wrapper = new JsoupInvocation( new URL(uri), settings.getReplyTimeout() );
246              CircuitBreaker breaker = CircuitBreakerManager.getManager().getCircuitBreaker("banedk");              CircuitBreaker breaker = CircuitBreakerManager.getManager().getCircuitBreaker("banedk");
247                            
248              HtmlPage page = (HtmlPage) breaker.invoke(wrapper);              Document page = (Document) breaker.invoke(wrapper);
249                
250                
251                Element content = page.getElementsByClass("contentDiv").get(0);
252                            
             HtmlElement table = page.getElementById("traf_afgang");  
253                            
254              if (table != null) {                                      if (content != null) {
255                      DomNodeList<HtmlElement> tableRows =  table.getElementsByTagName("tr");                      Elements tableRows =  content.child(0).children();
256                                            
257                      boolean isFirst = true;  
258                                            
259                      for (HtmlElement currentRow : tableRows) {                      for (Element currentRow : tableRows) {
260                          if (isFirst == true) { //skip table headers                          if (currentRow.tagName().equals("br") ) {
261                                  isFirst = false;                                  break;
                                 continue;  
262                          }                          }
263                                                    
264                          DomNodeList<HtmlElement> fields = currentRow.getElementsByTagName("td");                          
265                            Element link = currentRow.child(0);    
266                            System.out.println( currentRow.text() );;
267                            
268    
269                          DepartureBean departure = new DepartureBean();                          String parts[] = currentRow.text().split(",");
270                    
271    
272                          String time = fields.get(0).asText().trim();                          DepartureEntry departure = new DepartureEntry();
273    
274    /*
275    http://mobil.bane.dk/mobilStation.asp?artikelID=5332&tognummer=111&webprofil=FJRN&mode=rute&strBemaerkning=Afg%E5r+fra+%C5rhus+H+kl%2E07%3A21++&strRefURL=%2FmobilStation%2Easp%3FartikelID%3D5332%26stat%5Fkode%3DAR%26webprofil%3DFJRN%26beskrivelse%3D%25C5rhus%2BH%26mode%3Dankomstafgang%26ankomstafgang%3Dafgang%26gemstation%3D
276    */
277                            int offset = 0;
278                            
279                            String time = parts[offset++];
280                          if (time.equals(""))                          if (time.equals(""))
281                                  time = "0:00"; //Bane.dk bug work-around                                  time = "0:00"; //Bane.dk bug work-around
282                          departure.setTime(time);                          departure.setTime(time);
283    
284                            int updated = 4; //does not exist on mobile
285                            departure.setUpdated(updated);
286    
287                          String trainNumber = fields.get(1).asText();                          String trainNumber = "-"; //extractTrainNumberAzure(fields.get(2));
288                            /*if (traintype == TrainType.STOG) //If it is S-train we need to extract the trainNumber
289                                    trainNumber = trainNumber + " " + extractTrainNumberAzure(fields.get(2));*/
290                          departure.setTrainNumber(trainNumber);                          departure.setTrainNumber(trainNumber);
291    
292                          String destination = fields.get(2).asText();                                  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
293                                            offset++;
294                                    }
295    
296                            String destination = parts[offset++];
297                          departure.setDestination(destination);                          departure.setDestination(destination);
298    
299                          String origin = fields.get(3).asText();                          String origin = "-"; // fields.get(4).text(); does not exist on mobile
300                          departure.setOrigin(origin);                          departure.setOrigin(origin);
301    
302                          String status = fields.get(4).asText();                          String location = ""; // fields.get(5).text(); does not exist on mobile
303                            departure.setLocation(location);
304    
305                            String status = ""; //fields.get(6).text().trim(); - extract from url
306                          departure.setStatus(status);                          departure.setStatus(status);
307    
308                          String note = fields.get(5).asText();                          String note = ""; //extractNote( fields.get(7) ); - extract from url
309                          departure.setNote(note);                          departure.setNote(note);
310    
311                          departureList.add(departure);                          departure.setType(typeString);
312    
313                            departureBean.entries.add( departure );
314    
315                        }
316                } else {
317                    logger.warning("No departures found for station=" + stationcode + ", type=" + traintype);
318                }
319                
320                return departureBean;
321            }
322            
323            
324            
325            public static String cleanText(String input) {
326                    //apparently JSoup translates &nbsp; characters on www.bane.dk to 0xA0
327                    return input.replace((char) 0xA0, (char)0x20).trim();
328            }
329            
330            
331            // old www site is not available any more
332            @Deprecated
333            public DepartureBean lookupDeparturesWwwSite(String stationcode, TrainType trainType, boolean arrival) throws Exception {
334                    
335                    DepartureBean departureBean = new DepartureBean();
336                    
337                    String type = getTypeStringWww(trainType);
338                    
339                    stationcode = URLEncoder.encode(stationcode, "ISO-8859-1");
340                    
341                                                
342                String uri = "http://www.bane.dk/visStation.asp?ArtikelID=4275&W=" + type + "&S=" + stationcode;
343                logger.fine("URI:" + uri);
344                
345    
346                JsoupInvocation wrapper = new JsoupInvocation( new URL(uri), settings.getReplyTimeout() );
347                CircuitBreaker breaker = CircuitBreakerManager.getManager().getCircuitBreaker("banedk");
348                
349                Element page = (Element) breaker.invoke(wrapper);
350                
351                String tableName = arrival == false ? "afgangtabel" : "ankomsttabel";
352                Element table = page.getElementById(tableName);
353                
354    
355                
356                if (table != null) {
357                        Elements tableRows =  table.getElementsByTag("tr");
358                        
359                        //boolean passedTidsstreg = false;
360                        //boolean tidsstregExists = (table.getElementsByAttributeValue("class", "Tidsstreg").size() > 0);
361                        
362                        for (Element currentRow : tableRows) {
363                            String rowClass = currentRow.attr("class");
364                            /*
365                            if (tidsstregExists == true && passedTidsstreg == false) {
366                                    if (currentRow.getElementsByAttributeValue("class", "Tidsstreg").size() > 0) {
367                                            passedTidsstreg = true;
368                                    } else {
369                                            continue;
370                                    }
371                            }*/
372                            
373                            
374                            if (rowClass != null && rowClass.toLowerCase().contains("station") ) {
375                                    Elements fields = currentRow.getElementsByTag("td");
376            
377                                    DepartureEntry departure = new DepartureEntry();
378                                    
379    
380                                    
381                                    String time = cleanText( fields.get(0).getAllElements().get(2).text() );
382                                    if (time.equals(""))
383                                            time = "0:00"; //Bane.dk bug work-around
384                                    departure.setTime(time);
385                                    
386                                    int updated = extractUpdated( fields.get(1) );
387                                    departure.setUpdated(updated);
388                                    
389                                    String trainNumber = cleanText( fields.get(2).text() );
390                                    if (type.equalsIgnoreCase("S2")) //If it is S-train we need to extract the trainNumber
391                                            trainNumber = trainNumber + " " + extractTrainNumberWww(fields.get(2));
392                                    departure.setTrainNumber(trainNumber);
393                                    
394                                    String destination = cleanText( fields.get(3).text() );
395                                    departure.setDestination(destination);
396                                    
397                                    String origin = cleanText( fields.get(4).text() );
398                                    departure.setOrigin(origin);
399                                    
400                                    String location = cleanText( fields.get(5).text() );
401                                    departure.setLocation(location);
402                                    
403                                    String status = cleanText( fields.get(6).text() );
404                                    departure.setStatus(status);
405                                    
406                                    String note = cleanText( extractNote( fields.get(7) ) );
407                                    departure.setNote(note);
408                                    
409                                    departure.setType(type);
410                                    
411                                    departureBean.entries.add(departure);
412                                    
413                                    
414                            }
415                      }                      }
416              } else {              } else {
417                  logger.warning("No departures found for station=" + stationcode + ", type=" + type);                  logger.warning("No departures found for station=" + stationcode + ", type=" + type);
418              }              }
             webClient.closeAllWindows();  
419                            
420                            
421              return departureList;              return departureBean;
422          }          }
423                    
424                    
425          private int extractUpdated(HtmlElement updatedTd) { //extract the digit (in this case: 4) from "media/trafikinfo/opdater4.gif"          private int extractUpdated(Element updatedTd) { //extract the digit (in this case: 4) from "media/trafikinfo/opdater4.gif"
426                  int updated = -1;                  int updated = -1;
427                                    
428                  DomNodeList<HtmlElement> updatedImgs = updatedTd.getElementsByTagName("img");                  Elements updatedImgs = updatedTd.getElementsByTag("img");
429                  String updatedStr = updatedImgs.get(0).getAttribute("src");                  String updatedStr = updatedImgs.get(0).attr("src");
430                                    
431                  if (updatedStr != null) {                  if (updatedStr != null) {
432                          for (int i=0; i<updatedStr.length(); i++) {                          for (int i=0; i<updatedStr.length(); i++) {
# Line 239  public class DepartureFetcher { Line 440  public class DepartureFetcher {
440                  return updated;                  return updated;
441          }          }
442                    
443          private String extractNote(HtmlElement noteTd) {          private String extractNote(Element noteTd) {
444                  String note = noteTd.asText().trim();                  String note = noteTd.text().trim();
445                                    
446                  List<HtmlElement> elems = noteTd.getElementsByAttribute("span", "class", "bemtype");                  
447                    Elements elems = noteTd.getElementsByClass("bemtype");
448                  if (elems.size() > 0 && note.charAt(note.length()-1) == 'i')                  if (elems.size() > 0 && note.charAt(note.length()-1) == 'i')
449                          note = note.substring(0,note.length() -1 );                          note = note.substring(0,note.length() -1 );
450    
451                  return note;                  return note.trim();
452          }          }
453                    
454          private String extractTrainNumber(HtmlElement trainTd) {          private String extractTrainNumberAzure(Element trainTd) {
455                    Element anchorElement = trainTd.getElementsByTag("a").get(0);
456                    String href = anchorElement.attr("href");
457                    
458                    int pos = href.lastIndexOf('/');
459                    String number = href.substring(pos+1);
460                    
461                    return number;
462            }
463            
464            private String extractTrainNumberWww(Element trainTd) {
465                  String number = "";                  String number = "";
466                  HtmlElement anchorElement = trainTd.getElementsByTagName("a").get(0);                  Element anchorElement = trainTd.getElementsByTag("a").get(0);
467                  String href = anchorElement.getAttribute("href");                  String href = anchorElement.attr("href");
468                  String argstring = href.substring( href.indexOf('?') + 1);                  String argstring = href.substring( href.indexOf('?') + 1);
469                                    
470                  String args[] = argstring.split("&");                  String args[] = argstring.split("&");
# Line 266  public class DepartureFetcher { Line 478  public class DepartureFetcher {
478                                    
479                  return number;                  return number;
480          }          }
481    
482                    
483          //test          //test
484          /*          /*

Legend:
Removed from v.829  
changed lines
  Added in v.1333

  ViewVC Help
Powered by ViewVC 1.1.20