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

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

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

revision 353 by torben, Tue Sep 29 15:49:19 2009 UTC revision 389 by torben, Fri Oct 2 17:18:31 2009 UTC
# Line 7  import java.util.ArrayList; Line 7  import java.util.ArrayList;
7  import java.util.List;  import java.util.List;
8  import java.util.logging.Logger;  import java.util.logging.Logger;
9    
10  import com.gargoylesoftware.htmlunit.*;  import com.gargoylesoftware.htmlunit.Page;
11  import com.gargoylesoftware.htmlunit.html.*;  import com.gargoylesoftware.htmlunit.RefreshHandler;
12    import com.gargoylesoftware.htmlunit.WebClient;
13    import com.gargoylesoftware.htmlunit.html.DomNodeList;
14    import com.gargoylesoftware.htmlunit.html.HtmlElement;
15    import com.gargoylesoftware.htmlunit.html.HtmlPage;
16    
17  public class TimetableFetcher {  public class TimetableFetcher {
18                    
# Line 17  public class TimetableFetcher { Line 21  public class TimetableFetcher {
21                  }                  }
22                                    
23          }          }
24                    
25            TimeoutCache<String, List<TimetableBean>> cache = new TimeoutCache<String,List<TimetableBean>>(120 * 1000);
26            
27                    
28          Logger logger = Logger.getLogger(TimetableFetcher.class.getName());          Logger logger = Logger.getLogger(TimetableFetcher.class.getName());
29            
30            
31            List<TimetableBean> cachedLookupTimetable(String trainID, String type) throws Exception {
32                    String key = trainID+type;
33                    List<TimetableBean> list = cache.get(key);
34                    
35                    if (list == null) {
36                            list = lookupTimetable(trainID,type);
37                            cache.put(key, list);
38                    } else {
39                            logger.info("Timetable: Cache hit " + trainID);
40                    }
41                    return list;
42            }
43    
44          List<TimetableBean> lookupTimetable(String trainID, String type) throws Exception {          List<TimetableBean> lookupTimetable(String trainID, String type) throws Exception {            
45                  List<TimetableBean> timetableList = new ArrayList<TimetableBean>();                  List<TimetableBean> timetableList = new ArrayList<TimetableBean>();
46                                    
47                  String url = "http://www.bane.dk/visRute.asp?W=" + type + "&TogNr=" + trainID + "&artikelId=4276";                  String url = "http://www.bane.dk/visRute.asp?W=" + type + "&TogNr=" + trainID + "&artikelId=4276";
48                                                                    
49    
50              final WebClient webClient = new WebClient();              final WebClient webClient = new WebClient();
51              webClient.setTimeout(1000);              webClient.setTimeout(2500);
52              webClient.setJavaScriptEnabled(false);                      webClient.setJavaScriptEnabled(false);        
53              webClient.setRefreshHandler( new NullRefreshHandler() );              webClient.setRefreshHandler( new NullRefreshHandler() );
54              webClient.setCssEnabled(false);              webClient.setCssEnabled(false);

Legend:
Removed from v.353  
changed lines
  Added in v.389

  ViewVC Help
Powered by ViewVC 1.1.20