/[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 312 by torben, Thu Sep 10 18:13:52 2009 UTC revision 313 by torben, Fri Sep 11 07:13:46 2009 UTC
# Line 7  import java.util.ArrayList; Line 7  import java.util.ArrayList;
7  import java.util.Collections;  import java.util.Collections;
8  import java.util.List;  import java.util.List;
9    
10    import com.gargoylesoftware.htmlunit.ProxyConfig;
11  import com.gargoylesoftware.htmlunit.WebClient;  import com.gargoylesoftware.htmlunit.WebClient;
12  import com.gargoylesoftware.htmlunit.html.DomNodeList;  import com.gargoylesoftware.htmlunit.html.DomNodeList;
13  import com.gargoylesoftware.htmlunit.html.HtmlElement;  import com.gargoylesoftware.htmlunit.html.HtmlElement;
# Line 60  public class DepartureFetcher { Line 61  public class DepartureFetcher {
61                                    
62              final WebClient webClient = new WebClient();              final WebClient webClient = new WebClient();
63              webClient.setTimeout(1000);              webClient.setTimeout(1000);
64              webClient.setJavaScriptEnabled(false);              webClient.setJavaScriptEnabled(false);
65                                
66                            
67              final HtmlPage page = webClient.getPage("http://www.bane.dk/visStation.asp?ArtikelID=4275&W=" + type + "&S=" + stationcode);              final HtmlPage page = webClient.getPage("http://www.bane.dk/visStation.asp?ArtikelID=4275&W=" + type + "&S=" + stationcode);
68                            
# Line 95  public class DepartureFetcher { Line 97  public class DepartureFetcher {
97                          String status = fields.get(6).asText();                          String status = fields.get(6).asText();
98                          departure.setStatus(status);                          departure.setStatus(status);
99                                                    
100                          String note = fields.get(7).asText();                          String note = extractNote( fields.get(7) );
101                          departure.setNote(note);                          departure.setNote(note);
102                                                    
103                          departureList.add(departure);                          departureList.add(departure);
# Line 123  public class DepartureFetcher { Line 125  public class DepartureFetcher {
125                  return updated;                  return updated;
126          }          }
127                    
128            private String extractNote(HtmlElement noteTd) {
129                    String note = noteTd.asText().trim();
130                    
131                    List<HtmlElement> elems = noteTd.getElementsByAttribute("span", "class", "bemtype");
132                    if (elems.size() > 0 && note.charAt(note.length()-1) == 'i')
133                            note = note.substring(0,note.length() -1 );
134    
135                    return note;
136            }
137            
138          //test          //test
139          public static void main(String args[]) throws Exception{          public static void main(String args[]) throws Exception{
140                  DepartureFetcher f = new DepartureFetcher();                  DepartureFetcher f = new DepartureFetcher();

Legend:
Removed from v.312  
changed lines
  Added in v.313

  ViewVC Help
Powered by ViewVC 1.1.20