/[projects]/android/TrainInfoService/src/dk/thoerup/traininfoservice/RequestPlotter.java
ViewVC logotype

Diff of /android/TrainInfoService/src/dk/thoerup/traininfoservice/RequestPlotter.java

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 802 by torben, Mon Jun 7 11:46:25 2010 UTC revision 805 by torben, Mon Jun 7 18:26:09 2010 UTC
# Line 126  public class RequestPlotter extends Http Line 126  public class RequestPlotter extends Http
126          */                */      
127                                    
128    
129                    final String STYLE_GREEN = "green";
130                    final String STYLE_YELLOW = "yellow";
131                    final String STYLE_RED = "red";
132    
133                    String oldstyle = null;
   
   
134                  Date now = new Date();                  Date now = new Date();
135                  for(RequestPosition current : list) {                  for(RequestPosition current : list) {
136                                                    
# Line 137  public class RequestPlotter extends Http Line 138  public class RequestPlotter extends Http
138                          long timediff = now.getTime() - current.time.getTime();                          long timediff = now.getTime() - current.time.getTime();
139                                                    
140                          if ( timediff < (3*60*60*1000) ) {                          if ( timediff < (3*60*60*1000) ) {
141                                  style = "#red";                                  style = STYLE_RED;
142                          } else if ( timediff < (24*60*60*1000)) {                          } else if ( timediff < (24*60*60*1000)) {
143                                  style = "#yellow";                                  style = STYLE_YELLOW;
144                          } else {                          } else {
145                                  style = "#green";                                  style = STYLE_GREEN;
146                            }
147                            
148                            if (  !style.equals(oldstyle) ) {
149                                    if (oldstyle != null)                          
150                                            sb.append( "</Folder>\n");
151                                    sb.append( "<Folder>\n");
152                                    sb.append( " <name>" ).append(style).append("</name>\n");
153                                    
154                                    oldstyle = style;
155                          }                          }
156                                                    
157                          sb.append( " <Placemark>\n" );                          sb.append( " <Placemark>\n" );
158                          sb.append( "  <styleUrl>" + style + "</styleUrl>\n" );                          sb.append( "  <styleUrl>#" + style + "</styleUrl>\n" );
159                          sb.append( "  <description>IP=" + current.ip + "  Time=" + current.time + "</description>\n" );                          sb.append( "  <description>IP=" + current.ip + "  Time=" + current.time + "</description>\n" );
160                          sb.append( "  <Point><coordinates>" + current.lng + "," + current.lat + ",0</coordinates></Point>\n" );                          sb.append( "  <Point><coordinates>" + current.lng + "," + current.lat + ",0</coordinates></Point>\n" );
161                          sb.append( " </Placemark>\n" );                                          sb.append( " </Placemark>\n" );                
162                  }                  }
163                    sb.append( "</Folder>\n" );
164                  sb.append(  "</Document>\n" );                  sb.append( "</Document>\n" );
165                  sb.append( "</kml>\n" );                  sb.append( "</kml>\n" );
166    
167                  return sb.toString();                  return sb.toString();
# Line 159  public class RequestPlotter extends Http Line 169  public class RequestPlotter extends Http
169    
170          @Override          @Override
171          protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {          protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
172                    final String KEY = "kmldata";
173                                    
174                  String data = cache.get("data");                  String kmlData = cache.get(KEY);
175                                    
176                  if (data == null) {                  if (kmlData == null) {
177                          data = formatXml( getRequestsFromFile() );                          kmlData = formatXml( getRequestsFromFile() );
178                          cache.put("data", data);                          cache.put(KEY, kmlData);
179                          data += "<!-- from source -->";                                          kmlData += "<!-- from source -->";                      
180                  } else {                  } else {
181                          data += "<!-- cached -->";                          kmlData += "<!-- cached -->";
182                  }                  }
183    
184                                    
# Line 178  public class RequestPlotter extends Http Line 189  public class RequestPlotter extends Http
189    
190                          ZipOutputStream zip = new ZipOutputStream(baos);                          ZipOutputStream zip = new ZipOutputStream(baos);
191                          zip.putNextEntry( new ZipEntry("trains.kml") );                          zip.putNextEntry( new ZipEntry("trains.kml") );
192                          zip.write( data.getBytes() );                          zip.write( kmlData.getBytes() );
193                          zip.closeEntry();                          zip.closeEntry();
194                          zip.close();                          zip.close();
195    
# Line 190  public class RequestPlotter extends Http Line 201  public class RequestPlotter extends Http
201    
202                  } else {                  } else {
203                          resp.setContentType(KML);                          resp.setContentType(KML);
204                          resp.getWriter().print( data );                          resp.getWriter().print( kmlData );
205                  }                  }
206          }          }
207  }  }

Legend:
Removed from v.802  
changed lines
  Added in v.805

  ViewVC Help
Powered by ViewVC 1.1.20