3 |
import java.io.IOException; |
import java.io.IOException; |
4 |
import java.io.PrintWriter; |
import java.io.PrintWriter; |
5 |
import java.net.URL; |
import java.net.URL; |
6 |
import java.util.ArrayList; |
import java.util.Map; |
7 |
import java.util.Set; |
import java.util.Set; |
8 |
|
import java.util.TreeMap; |
9 |
import java.util.TreeSet; |
import java.util.TreeSet; |
10 |
|
|
11 |
import javax.servlet.ServletException; |
import javax.servlet.ServletException; |
35 |
|
|
36 |
JsoupInvocation jsoup = new JsoupInvocation(new URL("http://trafikinfo.bane.dk/Trafikinformation/Stationsliste"), 5000); |
JsoupInvocation jsoup = new JsoupInvocation(new URL("http://trafikinfo.bane.dk/Trafikinformation/Stationsliste"), 5000); |
37 |
|
|
38 |
Set<String> banedkStations = new TreeSet<String>(); |
Map<String,String> banedkStations = new TreeMap<String,String>(); |
39 |
Set<String> dbStations = new TreeSet<String>(); |
Set<String> dbStations = new TreeSet<String>(); |
40 |
|
|
41 |
|
|
42 |
try { |
try { |
43 |
Document doc = (Document) cb.invoke(jsoup); |
Document doc = (Document) cb.invoke(jsoup); |
44 |
|
|
47 |
for(Element e : tables) { |
for(Element e : tables) { |
48 |
if (e.tagName().equals("table") ){ |
if (e.tagName().equals("table") ){ |
49 |
Elements links = e.getElementsByTag("a"); |
Elements links = e.getElementsByTag("a"); |
50 |
for (Element link : links) { |
for (Element link : links) { |
51 |
banedkStations.add( link.text() ); |
banedkStations.put( link.text(), link.attr("href") ); |
52 |
} |
} |
53 |
} |
} |
54 |
} |
} |
72 |
sb.append("<h2>stations on website not in db</h2>"); |
sb.append("<h2>stations on website not in db</h2>"); |
73 |
sb.append("<ul>"); |
sb.append("<ul>"); |
74 |
Set<String> tmpDbStations = new TreeSet<String>( dbStations ); |
Set<String> tmpDbStations = new TreeSet<String>( dbStations ); |
75 |
Set<String> tmpBanedkStations = new TreeSet<String>( banedkStations) ; |
Set<String> tmpBanedkStations = new TreeSet<String>( banedkStations.keySet()) ; |
76 |
tmpBanedkStations.removeAll(tmpDbStations); |
tmpBanedkStations.removeAll(tmpDbStations); |
77 |
for(String s : tmpBanedkStations) { |
for(String s : tmpBanedkStations) { |
78 |
sb.append( "<li>" + s + "</li>" ); |
String uri = banedkStations.get(s); |
79 |
|
sb.append( "<li><a href='http://trafikinfo.bane.dk" + uri + "'>"+ s + "</a></li>" ); |
80 |
} |
} |
81 |
sb.append("</ul>"); |
sb.append("</ul>"); |
82 |
|
|
84 |
sb.append("<h2>stations in db not on website </h2>"); |
sb.append("<h2>stations in db not on website </h2>"); |
85 |
sb.append("<ul>"); |
sb.append("<ul>"); |
86 |
tmpDbStations = new TreeSet<String>( dbStations ); |
tmpDbStations = new TreeSet<String>( dbStations ); |
87 |
tmpBanedkStations = new TreeSet<String>( banedkStations) ; |
tmpBanedkStations = new TreeSet<String>( banedkStations.keySet() ) ; |
88 |
tmpDbStations.removeAll(tmpBanedkStations); |
tmpDbStations.removeAll(tmpBanedkStations); |
89 |
for(String s : tmpDbStations) { |
for(String s : tmpDbStations) { |
90 |
sb.append( "<li>" + s + "</li>" ); |
sb.append( "<li>" + s + "</li>" ); |