/[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 349 by torben, Mon Sep 28 19:14:18 2009 UTC revision 410 by torben, Wed Oct 7 13:37:37 2009 UTC
# Line 8  import java.util.Collections; Line 8  import java.util.Collections;
8  import java.util.List;  import java.util.List;
9  import java.util.logging.Logger;  import java.util.logging.Logger;
10    
11  import com.gargoylesoftware.htmlunit.ProxyConfig;  
12  import com.gargoylesoftware.htmlunit.WebClient;  import com.gargoylesoftware.htmlunit.WebClient;
13  import com.gargoylesoftware.htmlunit.html.DomNodeList;  import com.gargoylesoftware.htmlunit.html.DomNodeList;
14  import com.gargoylesoftware.htmlunit.html.HtmlElement;  import com.gargoylesoftware.htmlunit.html.HtmlElement;
# Line 19  import dk.thoerup.traininfoservice.DBCon Line 19  import dk.thoerup.traininfoservice.DBCon
19  public class DepartureFetcher {  public class DepartureFetcher {
20                    
21          Logger logger = Logger.getLogger(DepartureFetcher.class.getName());          Logger logger = Logger.getLogger(DepartureFetcher.class.getName());
22            
23            TimeoutCache<Integer, List<DepartureBean>> cache = new TimeoutCache<Integer,List<DepartureBean>>(120 * 1000);
24            
25                    
26            
27            public List<DepartureBean> cachedLookupDepartures(int stationID) throws Exception {
28    
29                    List<DepartureBean> list = cache.get(stationID);
30                    
31                    if (list == null) {
32                            list = lookupDepartures(stationID);
33                            cache.put(stationID, list);
34                    } else {
35                            logger.info("Departure: Cache hit " + stationID); //remove before production
36                    }
37                    return list;
38            }
39                                    
40    
41          public List<DepartureBean> lookupDepartures(int stationID) throws Exception {          public List<DepartureBean> lookupDepartures(int stationID) throws Exception {
# Line 63  public class DepartureFetcher { Line 80  public class DepartureFetcher {
80                  List<DepartureBean> departureList = new ArrayList<DepartureBean>();                  List<DepartureBean> departureList = new ArrayList<DepartureBean>();
81                                    
82              final WebClient webClient = new WebClient();              final WebClient webClient = new WebClient();
83              webClient.setTimeout(1000);              webClient.setTimeout(2500);
84              webClient.setJavaScriptEnabled(false);              webClient.setJavaScriptEnabled(false);
85                                                            
86                            
# Line 82  public class DepartureFetcher { Line 99  public class DepartureFetcher {
99                                  DepartureBean departure = new DepartureBean();                                  DepartureBean departure = new DepartureBean();
100                                                                    
101                                  String time = fields.get(0).asText();                                  String time = fields.get(0).asText();
102                                    if (time.equals(""))
103                                            time = "0:00"; //Bane.dk bug work-around
104                                  departure.setTime(time);                                  departure.setTime(time);
105                                                                    
106                                  int updated = extractUpdated( fields.get(1) );                                  int updated = extractUpdated( fields.get(1) );
107                                  departure.setUpdated(updated);                                  departure.setUpdated(updated);
108                                                                    
109                                  String trainNumber = fields.get(2).asText();                                  String trainNumber = fields.get(2).asText();
110                                  if (trainNumber.trim().length() == 1)                                  if (type.equalsIgnoreCase("S2")) //If it is S-train we need to extract the trainNumber
111                                          trainNumber = trainNumber + " " + extractTrainNumber(fields.get(2));                                          trainNumber = trainNumber + " " + extractTrainNumber(fields.get(2));
112                                  departure.setTrainNumber(trainNumber);                                  departure.setTrainNumber(trainNumber);
113                                                                    

Legend:
Removed from v.349  
changed lines
  Added in v.410

  ViewVC Help
Powered by ViewVC 1.1.20