X-Git-Url: http://jaekl.net/gitweb/?p=frank.git;a=blobdiff_plain;f=report%2Fnet%2Fjaekl%2Ffrank%2FViewSchedule.html;fp=report%2Fnet%2Fjaekl%2Ffrank%2FViewSchedule.html;h=0000000000000000000000000000000000000000;hp=66255f712229d09a936eeddc937e7be2c69b695c;hb=c35af9e511e8390a66ca76331c3af43d0f0f7464;hpb=24f097b0fe78fa44f99b9f6f2e51a8e689d86a4a diff --git a/report/net/jaekl/frank/ViewSchedule.html b/report/net/jaekl/frank/ViewSchedule.html deleted file mode 100644 index 66255f7..0000000 --- a/report/net/jaekl/frank/ViewSchedule.html +++ /dev/null @@ -1,755 +0,0 @@ - - -tests coverage - - - - - - - - - -
-Frames -No Frames -
-

- - - - - - - - - - - - - - - -
 %method%block%branch%line
net.jaekl.frank.ViewSchedule
67%(4/6)
38%(8/21)
30%(3/10)
43%(20/46)
-

-

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
hit countmethod namemethod modifiersmethod signature
3<init>[public]void <init>()
0doGet[public]void doGet(javax.servlet.http.HttpServletRequest,javax.servlet.http.HttpServletResponse)
0getLocale[]java.util.Locale getLocale(javax.servlet.http.HttpServletRequest)
4getParamInt[]int getParamInt(javax.servlet.http.HttpServletRequest,java.lang.String)
8getParamString[]java.lang.String getParamString(javax.servlet.http.HttpServletRequest,java.lang.String)
3writeErrorPage[]void writeErrorPage(java.io.PrintWriter,java.lang.Throwable,java.util.Locale)
-

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
 1 
 package net.jaekl.frank;
 2 
 
 3 
 import java.io.ByteArrayOutputStream;
 4 
 import java.io.FileInputStream;
 5 
 import java.io.IOException;
 6 
 import java.io.PrintStream;
 7 
 import java.io.PrintWriter;
 8 
 import java.util.Locale;
 9 
 
 10 
 import javax.servlet.ServletException;
 11 
 import javax.servlet.http.HttpServlet;
 12 
 import javax.servlet.http.HttpServletRequest;
 13 
 import javax.servlet.http.HttpServletResponse;
 14 
 
 15 
 import net.jaekl.frank.octranspo.Server;
 16 
 import net.jaekl.frank.octranspo.StopInfo;
 17 
 import net.jaekl.qd.util.ExceptionUtils;
 18 
 
 19 Block: 1/1 
 public class ViewSchedule extends HttpServlet {
 20 
 	private static final long serialVersionUID = 1L;
 21 
 	
 22 
 	static final String BUNDLE_NAME = "frank";
 23 
 	static final String STOP = "stop";
 24 
 	static final String ROUTE = "route";
 25 
 	static final String LANG = "lang";
 26 
 	
 27 
 	int getParamInt(HttpServletRequest req, String paramName) {
 28 Block: 1/1 
 		String valueStr = getParamString(req, paramName);
 29 
 		try {
 30 
 			return Integer.parseInt(valueStr);
 31 
 		}
 32 Block: 1/1 
 		catch (NumberFormatException exc) {
 33 
 			// TODO:  Error page
 34 
 			return 0;
 35 
 		}
 36 
 	}
 37 
 	
 38 
 	String getParamString(HttpServletRequest req, String paramName) {
 39 Block: 1/1 
 		String valueStr = req.getParameter(paramName);
 40 
 		if (null == valueStr|| valueStr.equals("")) {
 41 
 			// TODO:  Error page
 42 Block: 1/1 Branch: 1/2 
 			return null;
 43 
 		}
 44 Block: 1/1 Branch: 1/1 
 		return valueStr;
 45 
 	}
 46 
 	
 47 
 	Locale getLocale(HttpServletRequest req) {
 48 Block: 0/1 
 		Locale result = null;
 49 
 		String lang = getParamString(req, LANG);
 50 
 		if (null != lang) {
 51 Block: 0/1 Branch: 0/1 
 			result = new Locale(lang);
 52 
 		}
 53 Block: 0/1 Branch: 0/1 
 		if (null == result) {
 54 Block: 0/1 Branch: 0/1 
 			result = Locale.getDefault();
 55 
 		}
 56 Block: 0/1 Branch: 0/1 
 		return result;
 57 
 	}
 58 
 
 59 
 	@Override
 60 
 	public void doGet(HttpServletRequest req, HttpServletResponse res)
 61 
 	throws ServletException, IOException
 62 
 	{
 63 Block: 0/1 
 		res.setContentType("text/html");
 64 
 		PrintWriter pw = res.getWriter();
 65 
 		
 66 
 		Locale locale = getLocale(req);
 67 
 		int stop = getParamInt(req, STOP);
 68 
 		int route = getParamInt(req, ROUTE);
 69 
 		
 70 
 		try {
 71 
 			FileInputStream fis = new FileInputStream("apikey.txt");
 72 
 			try {
 73 
 				Server server = new Server("192f31d2", fis);
 74 
 				StopInfo stopInfo = null;
 75 
 				
 76 
 				if (0 == route) {
 77 Block: 0/1 Branch: 0/1 
 					stopInfo = server.getNextTripsForStopAllRoutes(stop);
 78 
 				}
 79 
 				else {
 80 Block: 0/1 Branch: 0/1 
 					stopInfo = server.getNextTripsForStop(stop, route);
 81 
 				}
 82 Block: 0/1 
 				Schedule schedule = new Schedule(locale);
 83 
 				
 84 
 				schedule.writePage(pw, stopInfo);
 85 
 			}
 86 
 			finally {
 87 Block: 0/1 
 				ExceptionUtils.tryClose(fis);
 88 
 			}
 89 
 		}
 90 Block: 0/1 
 		catch (Throwable t) {
 91 
 			writeErrorPage(pw, t, locale);
 92 Block: 0/1 
 		}
 93 Block: 0/1 
 	}
 94 
 	
 95 
 	void writeErrorPage(PrintWriter pw, Throwable t, Locale locale) {
 96 Block: 1/1 
 		ByteArrayOutputStream baos = new ByteArrayOutputStream();
 97 
 		PrintStream ps = new PrintStream(baos);
 98 
 		FrankBundle bundle = FrankBundle.getInst(locale);
 99 
 		
 100 
 		pw.println("<HTML><HEAD><TITLE>" + 
 101 
 				bundle.get(FrankBundle.FRANK) + ": " +
 102 
 				bundle.get(FrankBundle.ERROR_PAGE) + 
 103 
 				"</TITLE></HEAD>");
 104 
 		pw.println("<BODY><H1>" +
 105 
 				bundle.get(FrankBundle.FRANK) + ": " +
 106 
 				bundle.get(FrankBundle.UNEXPECTED_ERROR) + 
 107 
 				"</H1><P><PRE>");
 108 
 
 109 
 		// Note that, if we cared about security, we would log this stack trace to a
 110 
 		// server log, and only report a cross-reference to the log file back to the 
 111 
 		// end user's browser, to avoid potentially exposing internal info that we 
 112 
 		// don't want to share.
 113 
 		// At least at this point, we don't care (that much), and trade off a 
 114 
 		// potential information leak in favour of reducing our code complexity
 115 
 		// and the administrator's workload.
 116 
 		t.printStackTrace(ps);
 117 
 		String stackTrace = baos.toString(); 
 118 
 		pw.println(stackTrace);
 119 
 				
 120 
 		pw.println("</PRE></P></BODY>");
 121 
 		pw.println("</HTML>");
 122 
 	}
 123 
 	
 124 
 
 125 
 }
-

-

Report generated 11/12/14 11:31 PM
- -