--- android/TrainInfoService/src/dk/thoerup/traininfoservice/RequestPlotter.java 2011/04/19 16:39:07 1312 +++ android/TrainInfoService/src/dk/thoerup/traininfoservice/RequestPlotter.java 2011/05/02 18:19:16 1426 @@ -26,7 +26,7 @@ import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; -import dk.thoerup.traininfoservice.banedk.TimeoutMap; +import dk.thoerup.genericjavautils.TimeoutMap; @WebServlet(urlPatterns={"/RequestPlotter"}) public class RequestPlotter extends HttpServlet { @@ -78,7 +78,7 @@ return empty; } - int from = logFiles.length - (count); + int from = (count>logFiles.length) ? 0 : logFiles.length - (count); int to = logFiles.length; return Arrays.copyOfRange(logFiles, from, to); @@ -267,8 +267,9 @@ for(RequestPosition current : list) { String id = color + count++; sb.append( " \n" ); + sb.append( " ").append(current.time).append("\n" ); sb.append( " #").append(color).append("\n" ); - sb.append( " Time=").append(current.time).append("]]>\n" ); + sb.append( " ]]>\n" ); sb.append( " ").append(current.lng).append(",").append(current.lat).append(",0\n" ); sb.append( " \n" ); } @@ -368,14 +369,25 @@ return (p != 0); } + int getCount(String param) { + if (param == null || param.equals("")) { + return 1; + } + + return Integer.parseInt(param); + } + + @Override protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { - int count = Integer.parseInt( req.getParameter("count") ); + int count = getCount( req.getParameter("count") ); if (count > 30) //limit to 30 days count = 30; + if (count < 0) //negative count is not allowed + count = 0; String kmlData = getRequestsFromFile(count);