--- android/TrainInfoService/src/dk/thoerup/traininfoservice/RequestPlotter.java 2010/06/07 11:46:25 802 +++ android/TrainInfoService/src/dk/thoerup/traininfoservice/RequestPlotter.java 2010/06/07 18:26:09 805 @@ -126,10 +126,11 @@ */ + final String STYLE_GREEN = "green"; + final String STYLE_YELLOW = "yellow"; + final String STYLE_RED = "red"; - - - + String oldstyle = null; Date now = new Date(); for(RequestPosition current : list) { @@ -137,21 +138,30 @@ long timediff = now.getTime() - current.time.getTime(); if ( timediff < (3*60*60*1000) ) { - style = "#red"; + style = STYLE_RED; } else if ( timediff < (24*60*60*1000)) { - style = "#yellow"; + style = STYLE_YELLOW; } else { - style = "#green"; + style = STYLE_GREEN; + } + + if ( !style.equals(oldstyle) ) { + if (oldstyle != null) + sb.append( "\n"); + sb.append( "\n"); + sb.append( " " ).append(style).append("\n"); + + oldstyle = style; } sb.append( " \n" ); - sb.append( " " + style + "\n" ); + sb.append( " #" + style + "\n" ); sb.append( " IP=" + current.ip + " Time=" + current.time + "\n" ); sb.append( " " + current.lng + "," + current.lat + ",0\n" ); sb.append( " \n" ); } - - sb.append( "\n" ); + sb.append( "\n" ); + sb.append( "\n" ); sb.append( "\n" ); return sb.toString(); @@ -159,15 +169,16 @@ @Override protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { + final String KEY = "kmldata"; - String data = cache.get("data"); + String kmlData = cache.get(KEY); - if (data == null) { - data = formatXml( getRequestsFromFile() ); - cache.put("data", data); - data += ""; + if (kmlData == null) { + kmlData = formatXml( getRequestsFromFile() ); + cache.put(KEY, kmlData); + kmlData += ""; } else { - data += ""; + kmlData += ""; } @@ -178,7 +189,7 @@ ZipOutputStream zip = new ZipOutputStream(baos); zip.putNextEntry( new ZipEntry("trains.kml") ); - zip.write( data.getBytes() ); + zip.write( kmlData.getBytes() ); zip.closeEntry(); zip.close(); @@ -190,7 +201,7 @@ } else { resp.setContentType(KML); - resp.getWriter().print( data ); + resp.getWriter().print( kmlData ); } } }