20 |
import java.util.zip.ZipOutputStream; |
import java.util.zip.ZipOutputStream; |
21 |
|
|
22 |
import javax.servlet.ServletException; |
import javax.servlet.ServletException; |
23 |
|
import javax.servlet.annotation.WebListener; |
24 |
|
import javax.servlet.annotation.WebServlet; |
25 |
import javax.servlet.http.HttpServlet; |
import javax.servlet.http.HttpServlet; |
26 |
import javax.servlet.http.HttpServletRequest; |
import javax.servlet.http.HttpServletRequest; |
27 |
import javax.servlet.http.HttpServletResponse; |
import javax.servlet.http.HttpServletResponse; |
28 |
|
|
29 |
import dk.thoerup.traininfoservice.banedk.TimeoutMap; |
import dk.thoerup.traininfoservice.banedk.TimeoutMap; |
30 |
|
|
31 |
|
@WebServlet(urlPatterns={"/RequestPlotter"}) |
32 |
public class RequestPlotter extends HttpServlet { |
public class RequestPlotter extends HttpServlet { |
33 |
private static final long serialVersionUID = 1L; |
private static final long serialVersionUID = 1L; |
34 |
|
|
37 |
static final String KML = "application/vnd.google-earth.kml"; |
static final String KML = "application/vnd.google-earth.kml"; |
38 |
static final String KMZ = "application/vnd.google-earth.kmz"; |
static final String KMZ = "application/vnd.google-earth.kmz"; |
39 |
|
|
40 |
Map<String,String> cache = new TimeoutMap<String,String>(2*60*1000); |
Map<String,String> cache = new TimeoutMap<String,String>(30*60*1000); |
41 |
|
|
42 |
class RequestPosition { |
class RequestPosition { |
43 |
public String ip; |
public String ip; |
151 |
sb.append( "<Folder>\n"); |
sb.append( "<Folder>\n"); |
152 |
sb.append( " <name>" ).append(color).append("</name>\n"); |
sb.append( " <name>" ).append(color).append("</name>\n"); |
153 |
sb.append( " <open>0</open>\n" ); |
sb.append( " <open>0</open>\n" ); |
|
sb.append( " <description>Count=").append(list.size()).append("</description>\n"); |
|
154 |
|
|
155 |
for(RequestPosition current : list) { |
for(RequestPosition current : list) { |
156 |
sb.append( " <Placemark>\n" ); |
sb.append( " <Placemark>\n" ); |
157 |
sb.append( " <styleUrl>#" + color + "</styleUrl>\n" ); |
sb.append( " <styleUrl>#").append(color).append("</styleUrl>\n" ); |
158 |
sb.append( " <description>IP=" + current.ip + " Time=" + current.time + "</description>\n" ); |
sb.append( " <description>IP=").append(current.ip).append(" Time=").append(current.time).append("</description>\n" ); |
159 |
sb.append( " <Point><coordinates>" + current.lng + "," + current.lat + ",0</coordinates></Point>\n" ); |
sb.append( " <Point><coordinates>").append(current.lng).append(",").append(current.lat).append(",0</coordinates></Point>\n" ); |
160 |
sb.append( " </Placemark>\n" ); |
sb.append( " </Placemark>\n" ); |
161 |
} |
} |
162 |
|
|
164 |
} |
} |
165 |
|
|
166 |
protected String formatXml(PositionContainer positions) { |
protected String formatXml(PositionContainer positions) { |
167 |
StringBuilder sb = new StringBuilder(); |
StringBuilder sb = new StringBuilder(1024*1024); |
168 |
|
|
169 |
sb.append( "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" ); |
sb.append( "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" ); |
170 |
sb.append( "<kml xmlns=\"http://www.opengis.net/kml/2.2\">\n" ); |
sb.append( "<kml xmlns=\"http://www.opengis.net/kml/2.2\">\n" ); |
171 |
sb.append( "<Document>\n" ); |
sb.append( "<Document>\n" ); |
172 |
|
sb.append( " <description><![CDATA["); |
173 |
|
sb.append( " Green:").append(positions.green.size()).append("<br/>\n"); |
174 |
|
sb.append( " Yellow:").append(positions.yellow.size()).append("<br/>\n"); |
175 |
|
sb.append( " Red:").append(positions.red.size()).append("\n"); |
176 |
|
sb.append( " ]]></description>"); |
177 |
|
|
178 |
|
|
179 |
sb.append( " <Style id=\"red\">\n" ); |
sb.append( " <Style id=\"red\">\n" ); |
208 |
|
|
209 |
|
|
210 |
formatPositions(sb, "green", positions.green); |
formatPositions(sb, "green", positions.green); |
211 |
formatPositions(sb, "yello", positions.yellow); |
formatPositions(sb, "yellow", positions.yellow); |
212 |
formatPositions(sb, "red", positions.red); |
formatPositions(sb, "red", positions.red); |
213 |
|
|
214 |
|
|