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; |
47 |
} |
} |
48 |
|
|
49 |
class PositionContainer { |
class PositionContainer { |
50 |
|
List<RequestPosition> blue = new ArrayList<RequestPosition>(); |
51 |
List<RequestPosition> green = new ArrayList<RequestPosition>(); |
List<RequestPosition> green = new ArrayList<RequestPosition>(); |
52 |
List<RequestPosition> yellow = new ArrayList<RequestPosition>(); |
List<RequestPosition> yellow = new ArrayList<RequestPosition>(); |
53 |
List<RequestPosition> red = new ArrayList<RequestPosition>(); |
List<RequestPosition> red = new ArrayList<RequestPosition>(); |
128 |
positions.red.add(pos); //RED |
positions.red.add(pos); //RED |
129 |
} else if ( timediff < (24*60*60*1000)) { |
} else if ( timediff < (24*60*60*1000)) { |
130 |
positions.yellow.add(pos); //YELLOW |
positions.yellow.add(pos); //YELLOW |
131 |
} else { |
} else if ( timediff < (7*24*60*60*1000)) { |
132 |
positions.green.add(pos); //GREEN |
positions.green.add(pos); //GREEN |
133 |
|
} else { |
134 |
|
positions.blue.add(pos); //BLUE |
135 |
} |
} |
136 |
|
|
137 |
} |
} |
154 |
sb.append( "<Folder>\n"); |
sb.append( "<Folder>\n"); |
155 |
sb.append( " <name>" ).append(color).append("</name>\n"); |
sb.append( " <name>" ).append(color).append("</name>\n"); |
156 |
sb.append( " <open>0</open>\n" ); |
sb.append( " <open>0</open>\n" ); |
|
sb.append( " <description>Count=").append(list.size()).append("</description>\n"); |
|
157 |
|
|
158 |
for(RequestPosition current : list) { |
for(RequestPosition current : list) { |
159 |
sb.append( " <Placemark>\n" ); |
sb.append( " <Placemark>\n" ); |
160 |
|
sb.append( " <name>").append(current.ip).append("</name>\n"); |
161 |
sb.append( " <styleUrl>#").append(color).append("</styleUrl>\n" ); |
sb.append( " <styleUrl>#").append(color).append("</styleUrl>\n" ); |
162 |
sb.append( " <description>IP=").append(current.ip).append(" Time=").append(current.time).append("</description>\n" ); |
sb.append( " <description><![CDATA[IP=").append(current.ip).append("<br/>Time=").append(current.time).append("]]></description>\n" ); |
163 |
sb.append( " <Point><coordinates>").append(current.lng).append(",").append(current.lat).append(",0</coordinates></Point>\n" ); |
sb.append( " <Point><coordinates>").append(current.lng).append(",").append(current.lat).append(",0</coordinates></Point>\n" ); |
164 |
sb.append( " </Placemark>\n" ); |
sb.append( " </Placemark>\n" ); |
165 |
} |
} |
173 |
sb.append( "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" ); |
sb.append( "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" ); |
174 |
sb.append( "<kml xmlns=\"http://www.opengis.net/kml/2.2\">\n" ); |
sb.append( "<kml xmlns=\"http://www.opengis.net/kml/2.2\">\n" ); |
175 |
sb.append( "<Document>\n" ); |
sb.append( "<Document>\n" ); |
176 |
|
sb.append( " <description><![CDATA["); |
177 |
|
sb.append( " Red:").append(positions.red.size()).append(" (whithin 3 hours)<br/>\n"); |
178 |
|
sb.append( " Yellow:").append(positions.yellow.size()).append(" (within 24 hours)<br/>\n"); |
179 |
|
sb.append( " Green:").append(positions.green.size()).append(" (within one week)<br/>\n"); |
180 |
|
sb.append( " Blue:").append(positions.blue.size()).append(" (older)<br/>\n"); |
181 |
|
sb.append( " ]]></description>"); |
182 |
|
|
183 |
|
|
184 |
sb.append( " <Style id=\"red\">\n" ); |
sb.append( " <Style id=\"red\">\n" ); |
193 |
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" ); |
194 |
sb.append( " </Style>\n\n" ); |
sb.append( " </Style>\n\n" ); |
195 |
|
|
196 |
|
sb.append( " <Style id=\"blue\">\n" ); |
197 |
|
sb.append( " <IconStyle><Icon><href>http://maps.google.com/mapfiles/kml/paddle/blu-circle.png</href></Icon></IconStyle>\n" ); |
198 |
|
sb.append( " </Style>\n\n" ); |
199 |
/* |
/* |
200 |
String overlay = |
String overlay = |
201 |
" <ScreenOverlay>" + |
" <ScreenOverlay>" + |
215 |
*/ |
*/ |
216 |
|
|
217 |
|
|
218 |
|
formatPositions(sb, "blue", positions.blue); |
219 |
formatPositions(sb, "green", positions.green); |
formatPositions(sb, "green", positions.green); |
220 |
formatPositions(sb, "yellow", positions.yellow); |
formatPositions(sb, "yellow", positions.yellow); |
221 |
formatPositions(sb, "red", positions.red); |
formatPositions(sb, "red", positions.red); |