/[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 806 by torben, Mon Jun 7 18:35:40 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                                    sb.append( " <open>0</open>\n" );
154                                    
155                                    oldstyle = style;
156                          }                          }
157                                                    
158                          sb.append( " <Placemark>\n" );                          sb.append( " <Placemark>\n" );
159                          sb.append( "  <styleUrl>" + style + "</styleUrl>\n" );                          sb.append( "  <styleUrl>#" + style + "</styleUrl>\n" );
160                          sb.append( "  <description>IP=" + current.ip + "  Time=" + current.time + "</description>\n" );                          sb.append( "  <description>IP=" + current.ip + "  Time=" + current.time + "</description>\n" );
161                          sb.append( "  <Point><coordinates>" + current.lng + "," + current.lat + ",0</coordinates></Point>\n" );                          sb.append( "  <Point><coordinates>" + current.lng + "," + current.lat + ",0</coordinates></Point>\n" );
162                          sb.append( " </Placemark>\n" );                                          sb.append( " </Placemark>\n" );                
163                  }                  }
164                    sb.append( "</Folder>\n" );
165                  sb.append(  "</Document>\n" );                  sb.append( "</Document>\n" );
166                  sb.append( "</kml>\n" );                  sb.append( "</kml>\n" );
167    
168                  return sb.toString();                  return sb.toString();
# Line 159  public class RequestPlotter extends Http Line 170  public class RequestPlotter extends Http
170    
171          @Override          @Override
172          protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {          protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
173                    final String KEY = "kmldata";
174                                    
175                  String data = cache.get("data");                  String kmlData = cache.get(KEY);
176                                    
177                  if (data == null) {                  if (kmlData == null) {
178                          data = formatXml( getRequestsFromFile() );                          kmlData = formatXml( getRequestsFromFile() );
179                          cache.put("data", data);                          cache.put(KEY, kmlData);
180                          data += "<!-- from source -->";                                          kmlData += "<!-- from source -->";                      
181                  } else {                  } else {
182                          data += "<!-- cached -->";                          kmlData += "<!-- cached -->";
183                  }                  }
184    
185                                    
# Line 178  public class RequestPlotter extends Http Line 190  public class RequestPlotter extends Http
190    
191                          ZipOutputStream zip = new ZipOutputStream(baos);                          ZipOutputStream zip = new ZipOutputStream(baos);
192                          zip.putNextEntry( new ZipEntry("trains.kml") );                          zip.putNextEntry( new ZipEntry("trains.kml") );
193                          zip.write( data.getBytes() );                          zip.write( kmlData.getBytes() );
194                          zip.closeEntry();                          zip.closeEntry();
195                          zip.close();                          zip.close();
196    
# Line 190  public class RequestPlotter extends Http Line 202  public class RequestPlotter extends Http
202    
203                  } else {                  } else {
204                          resp.setContentType(KML);                          resp.setContentType(KML);
205                          resp.getWriter().print( data );                          resp.getWriter().print( kmlData );
206                  }                  }
207          }          }
208  }  }

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

  ViewVC Help
Powered by ViewVC 1.1.20