--- android/TrainInfoService/src/dk/thoerup/traininfoservice/banedk/TimetableFetcher.java 2009/10/22 06:04:45 468 +++ android/TrainInfoService/src/dk/thoerup/traininfoservice/banedk/TimetableFetcher.java 2010/02/10 14:07:04 591 @@ -8,6 +8,7 @@ import java.util.Map; import java.util.logging.Logger; +import com.gargoylesoftware.htmlunit.BrowserVersion; import com.gargoylesoftware.htmlunit.Page; import com.gargoylesoftware.htmlunit.RefreshHandler; import com.gargoylesoftware.htmlunit.WebClient; @@ -26,11 +27,19 @@ } - Map> cache = new TimeoutMap>(120 * 1000); + Map> cache; Logger logger = Logger.getLogger(TimetableFetcher.class.getName()); + private boolean useTempSite; + + public TimetableFetcher(boolean tmpSite, int cacheTimeout) { + useTempSite = tmpSite; + + cache = new TimeoutMap>(cacheTimeout); + } + List cachedLookupTimetable(String trainID, String type) throws Exception { String key = trainID+type; @@ -44,14 +53,22 @@ } return list; } + + List lookupTimetable(String trainID, String type) throws Exception { + if (useTempSite == false ){ + return lookupTimetableRealSite(trainID, type); + } else { + return new ArrayList(); // no timetable data on temp site + } + } - List lookupTimetable(String trainID, String type) throws Exception { + List lookupTimetableRealSite(String trainID, String type) throws Exception { List timetableList = new ArrayList(); String url = "http://www.bane.dk/visRute.asp?W=" + type + "&TogNr=" + trainID + "&artikelId=4276"; - final WebClient webClient = new WebClient(); + final WebClient webClient = new WebClient(BrowserVersion.FIREFOX_3); webClient.setTimeout(2500); webClient.setJavaScriptEnabled(false); webClient.setRefreshHandler( new NullRefreshHandler() ); @@ -102,6 +119,7 @@ } else { logger.warning("No time table found, trainID=" + trainID + " type=" + type); } + webClient.closeAllWindows(); return timetableList; }