10 |
import java.util.ArrayList; |
import java.util.ArrayList; |
11 |
import java.util.Date; |
import java.util.Date; |
12 |
import java.util.List; |
import java.util.List; |
13 |
|
import java.util.Map; |
14 |
import java.util.logging.Level; |
import java.util.logging.Level; |
15 |
import java.util.logging.Logger; |
import java.util.logging.Logger; |
16 |
import java.util.zip.ZipEntry; |
import java.util.zip.ZipEntry; |
21 |
import javax.servlet.http.HttpServletRequest; |
import javax.servlet.http.HttpServletRequest; |
22 |
import javax.servlet.http.HttpServletResponse; |
import javax.servlet.http.HttpServletResponse; |
23 |
|
|
24 |
|
import dk.thoerup.traininfoservice.banedk.TimeoutMap; |
25 |
|
|
26 |
public class RequestPlotter extends HttpServlet { |
public class RequestPlotter extends HttpServlet { |
27 |
private static final long serialVersionUID = 1L; |
private static final long serialVersionUID = 1L; |
28 |
|
|
30 |
|
|
31 |
static final String KML = "application/vnd.google-earth.kml"; |
static final String KML = "application/vnd.google-earth.kml"; |
32 |
static final String KMZ = "application/vnd.google-earth.kmz"; |
static final String KMZ = "application/vnd.google-earth.kmz"; |
33 |
|
|
34 |
|
Map<String,String> cache = new TimeoutMap<String,String>(2*60*1000); |
35 |
|
|
36 |
class RequestPosition { |
class RequestPosition { |
37 |
public String ip; |
public String ip; |
105 |
|
|
106 |
sb.append( " <Style id=\"green\">\n" ); |
sb.append( " <Style id=\"green\">\n" ); |
107 |
sb.append( " <IconStyle><Icon><href>http://maps.google.com/mapfiles/kml/paddle/grn-circle.png</href></Icon></IconStyle>\n" ); |
sb.append( " <IconStyle><Icon><href>http://maps.google.com/mapfiles/kml/paddle/grn-circle.png</href></Icon></IconStyle>\n" ); |
108 |
sb.append( " </Style>\n\n" ); |
sb.append( " </Style>\n\n" ); |
109 |
|
|
110 |
|
/* |
111 |
|
String overlay = |
112 |
|
" <ScreenOverlay>" + |
113 |
|
" <name>Absolute Positioning: Top left</name>" + |
114 |
|
" <description>Absolute Positioning: Top left</description>" + |
115 |
|
" <visibility>1</visibility>" + |
116 |
|
" <Icon>" + |
117 |
|
" <href>http://code.google.com/apis/kml/documentation/top_left.jpg</href>" + |
118 |
|
" </Icon>" + |
119 |
|
" <overlayXY x=\"0\" y=\"1\" xunits=\"fraction\" yunits=\"fraction\"/>" + |
120 |
|
" <screenXY x=\"0\" y=\"1\" xunits=\"fraction\" yunits=\"fraction\"/>" + |
121 |
|
" <rotationXY x=\"0\" y=\"0\" xunits=\"fraction\" yunits=\"fraction\"/>" + |
122 |
|
" <size x=\"0\" y=\"0\" xunits=\"fraction\" yunits=\"fraction\"/>" + |
123 |
|
" </ScreenOverlay>" ; |
124 |
|
|
125 |
|
sb.append(overlay); |
126 |
|
*/ |
127 |
|
|
128 |
|
|
129 |
|
|
130 |
|
|
131 |
|
|
159 |
|
|
160 |
@Override |
@Override |
161 |
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { |
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { |
162 |
|
final String KEY = "kmldata"; |
163 |
|
|
164 |
|
String kmlData = cache.get(KEY); |
165 |
|
|
166 |
|
if (kmlData == null) { |
167 |
|
kmlData = formatXml( getRequestsFromFile() ); |
168 |
|
cache.put(KEY, kmlData); |
169 |
|
kmlData += "<!-- from source -->"; |
170 |
|
} else { |
171 |
|
kmlData += "<!-- cached -->"; |
172 |
|
} |
173 |
|
|
174 |
String data = formatXml( getRequestsFromFile() ); |
|
175 |
|
|
176 |
if (req.getParameter("zip") != null) { |
if (req.getParameter("zip") != null) { |
177 |
|
|
179 |
|
|
180 |
ZipOutputStream zip = new ZipOutputStream(baos); |
ZipOutputStream zip = new ZipOutputStream(baos); |
181 |
zip.putNextEntry( new ZipEntry("trains.kml") ); |
zip.putNextEntry( new ZipEntry("trains.kml") ); |
182 |
zip.write( data.getBytes() ); |
zip.write( kmlData.getBytes() ); |
183 |
zip.closeEntry(); |
zip.closeEntry(); |
184 |
zip.close(); |
zip.close(); |
185 |
|
|
191 |
|
|
192 |
} else { |
} else { |
193 |
resp.setContentType(KML); |
resp.setContentType(KML); |
194 |
resp.getWriter().print( data ); |
resp.getWriter().print( kmlData ); |
195 |
} |
} |
196 |
} |
} |
197 |
} |
} |