Author: markt Date: Tue Sep 30 10:10:48 2008 New Revision: 700526 URL: http://svn.apache.org/viewvc?rev=700526&view=rev Log: Code clean up. Use generics. Remove used code and a couple of other Find Bugs issues.
Modified: tomcat/trunk/java/org/apache/catalina/servlets/CGIServlet.java Modified: tomcat/trunk/java/org/apache/catalina/servlets/CGIServlet.java URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/servlets/CGIServlet.java?rev=700526&r1=700525&r2=700526&view=diff ============================================================================== --- tomcat/trunk/java/org/apache/catalina/servlets/CGIServlet.java (original) +++ tomcat/trunk/java/org/apache/catalina/servlets/CGIServlet.java Tue Sep 30 10:10:48 2008 @@ -340,9 +340,9 @@ // Document the properties from ServletRequest out.println("<h1>ServletRequest Properties</h1>"); out.println("<ul>"); - Enumeration attrs = req.getAttributeNames(); + Enumeration<String> attrs = req.getAttributeNames(); while (attrs.hasMoreElements()) { - String attr = (String) attrs.nextElement(); + String attr = attrs.nextElement(); out.println("<li><b>attribute</b> " + attr + " = " + req.getAttribute(attr)); } @@ -352,14 +352,14 @@ req.getContentLength()); out.println("<li><b>contentType</b> = " + req.getContentType()); - Enumeration locales = req.getLocales(); + Enumeration<Locale> locales = req.getLocales(); while (locales.hasMoreElements()) { - Locale locale = (Locale) locales.nextElement(); + Locale locale = locales.nextElement(); out.println("<li><b>locale</b> = " + locale); } - Enumeration params = req.getParameterNames(); + Enumeration<String> params = req.getParameterNames(); while (params.hasMoreElements()) { - String param = (String) params.nextElement(); + String param = params.nextElement(); String values[] = req.getParameterValues(param); for (int i = 0; i < values.length; i++) out.println("<li><b>parameter</b> " + param + " = " + @@ -386,9 +386,9 @@ for (int i = 0; i < cookies.length; i++) out.println("<li><b>cookie</b> " + cookies[i].getName() +" = " +cookies[i].getValue()); } - Enumeration headers = req.getHeaderNames(); + Enumeration<String> headers = req.getHeaderNames(); while (headers.hasMoreElements()) { - String header = (String) headers.nextElement(); + String header = headers.nextElement(); out.println("<li><b>header</b> " + header + " = " + req.getHeader(header)); } @@ -423,7 +423,7 @@ out.println("<ul>"); attrs = req.getAttributeNames(); while (attrs.hasMoreElements()) { - String attr = (String) attrs.nextElement(); + String attr = attrs.nextElement(); out.println("<li><b>" + attr + "</b> = " + req.getAttribute(attr)); } @@ -453,7 +453,7 @@ out.println("<ul>"); attrs = session.getAttributeNames(); while (attrs.hasMoreElements()) { - String attr = (String) attrs.nextElement(); + String attr = attrs.nextElement(); out.println("<li><b>" + attr + "</b> = " + session.getAttribute(attr)); } @@ -475,7 +475,7 @@ out.println("<ul>"); params = getServletConfig().getInitParameterNames(); while (params.hasMoreElements()) { - String param = (String) params.nextElement(); + String param = params.nextElement(); String value = getServletConfig().getInitParameter(param); out.println("<li><b>" + param + "</b> = " + value); } @@ -501,7 +501,7 @@ out.println("<ul>"); params = getServletContext().getInitParameterNames(); while (params.hasMoreElements()) { - String param = (String) params.nextElement(); + String param = params.nextElement(); String value = getServletContext().getInitParameter(param); out.println("<li><b>" + param + "</b> = " + value); } @@ -513,7 +513,7 @@ out.println("<ul>"); attrs = getServletContext().getAttributeNames(); while (attrs.hasMoreElements()) { - String attr = (String) attrs.nextElement(); + String attr = attrs.nextElement(); out.println("<li><b>" + attr + "</b> = " + getServletContext().getAttribute(attr)); } @@ -665,7 +665,7 @@ private File tmpDir = null; /** derived cgi environment */ - private Hashtable env = null; + private Hashtable<String, String> env = null; /** cgi command to be invoked */ private String command = null; @@ -934,7 +934,6 @@ // Add the CGI environment variables String sPathInfoOrig = null; - String sPathTranslatedOrig = null; String sPathInfoCGI = null; String sPathTranslatedCGI = null; String sCGIFullPath = null; @@ -947,10 +946,6 @@ sPathInfoOrig = this.pathInfo; sPathInfoOrig = sPathInfoOrig == null ? "" : sPathInfoOrig; - sPathTranslatedOrig = req.getPathTranslated(); - sPathTranslatedOrig = - sPathTranslatedOrig == null ? "" : sPathTranslatedOrig; - if (webAppRootDir == null ) { // The app has not been deployed in exploded form webAppRootDir = tmpDir.toString(); @@ -984,7 +979,8 @@ envp.put("SERVER_PROTOCOL", nullsToBlanks(req.getProtocol())); int port = req.getServerPort(); - Integer iPort = (port == 0 ? new Integer(-1) : new Integer(port)); + Integer iPort = + (port == 0 ? Integer.valueOf(-1) : Integer.valueOf(port)); envp.put("SERVER_PORT", iPort.toString()); envp.put("REQUEST_METHOD", nullsToBlanks(req.getMethod())); @@ -1033,8 +1029,6 @@ */ if (sPathInfoCGI != null && !("".equals(sPathInfoCGI))) { sPathTranslatedCGI = context.getRealPath(sPathInfoCGI); - } else { - sPathTranslatedCGI = null; } if (sPathTranslatedCGI == null || "".equals(sPathTranslatedCGI)) { //NOOP @@ -1066,15 +1060,15 @@ */ int contentLength = req.getContentLength(); String sContentLength = (contentLength <= 0 ? "" : - (new Integer(contentLength)).toString()); + (Integer.valueOf(contentLength)).toString()); envp.put("CONTENT_LENGTH", sContentLength); - Enumeration headers = req.getHeaderNames(); + Enumeration<String> headers = req.getHeaderNames(); String header = null; while (headers.hasMoreElements()) { header = null; - header = ((String) headers.nextElement()).toUpperCase(); + header = headers.nextElement().toUpperCase(); //REMIND: rewrite multiple headers as if received as single //REMIND: change character set //REMIND: I forgot what the previous REMIND means @@ -1146,8 +1140,8 @@ } // create directories - String dirPath = new String (destPath.toString().substring( - 0,destPath.toString().lastIndexOf("/"))); + String dirPath = destPath.toString().substring( + 0,destPath.toString().lastIndexOf("/")); File dir = new File(dirPath); dir.mkdirs(); @@ -1206,13 +1200,13 @@ sb.append("</td></tr>"); if (isValid()) { - Enumeration envk = env.keys(); + Enumeration<String> envk = env.keys(); while (envk.hasMoreElements()) { - String s = (String) envk.nextElement(); + String s = envk.nextElement(); sb.append("<tr><td>"); sb.append(s); sb.append("</td><td>"); - sb.append(blanksToString((String) env.get(s), + sb.append(blanksToString(env.get(s), "[will be set to blank]")); sb.append("</td></tr>"); } @@ -1232,7 +1226,7 @@ sb.append("<tr><td>Command Line Params</td><td>"); for (int i=0; i < cmdLineParameters.size(); i++) { - String param = (String) cmdLineParameters.get(i); + String param = cmdLineParameters.get(i); sb.append("<p>"); sb.append(param); sb.append("</p>"); @@ -1276,7 +1270,7 @@ * @return CGI environment * */ - protected Hashtable getEnvironment() { + protected Hashtable<String,String> getEnvironment() { return env; } @@ -1288,7 +1282,7 @@ * @return CGI query parameters * */ - protected ArrayList getParameters() { + protected ArrayList<String> getParameters() { return cmdLineParameters; } @@ -1390,13 +1384,13 @@ private String command = null; /** environment used when invoking the cgi script */ - private Hashtable env = null; + private Hashtable<String,String> env = null; /** working directory used when invoking the cgi script */ private File wd = null; /** command line parameters to be passed to the invoked script */ - private ArrayList params = null; + private ArrayList<String> params = null; /** stdin to be passed to cgi script */ private InputStream stdin = null; @@ -1424,8 +1418,8 @@ * @param params ArrayList with the script's query command line * paramters as strings */ - protected CGIRunner(String command, Hashtable env, File wd, - ArrayList params) { + protected CGIRunner(String command, Hashtable<String,String> env, + File wd, ArrayList<String> params) { this.command = command; this.env = env; this.wd = wd; @@ -1503,13 +1497,13 @@ * @exception NullPointerException if a hash key has a null value * */ - protected String[] hashToStringArray(Hashtable h) + protected String[] hashToStringArray(Hashtable<String,?> h) throws NullPointerException { Vector<String> v = new Vector<String>(); - Enumeration e = h.keys(); + Enumeration<String> e = h.keys(); while (e.hasMoreElements()) { - String k = e.nextElement().toString(); - v.add(k + "=" + h.get(k)); + String k = e.nextElement(); + v.add(k + "=" + h.get(k).toString()); } String[] strArr = new String[v.size()]; v.copyInto(strArr); @@ -1616,7 +1610,7 @@ for (int i=0; i < params.size(); i++) { cmdAndArgs.append(" "); - String param = (String) params.get(i); + String param = params.get(i); if (param.indexOf(" ") < 0) { cmdAndArgs.append(param); } else { @@ -1636,7 +1630,7 @@ rt = Runtime.getRuntime(); proc = rt.exec(cmdAndArgs.toString(), hashToStringArray(env), wd); - String sContentLength = (String) env.get("CONTENT_LENGTH"); + String sContentLength = env.get("CONTENT_LENGTH"); if(!"".equals(sContentLength)) { commandsStdIn = new BufferedOutputStream(proc.getOutputStream()); @@ -1659,7 +1653,7 @@ new Thread() { public void run () { sendToLog(stdErrRdr) ; - } ; + } }.start() ; InputStream cgiHeaderStream = @@ -1826,11 +1820,11 @@ rdr.close() ; } catch (IOException ce) { log("sendToLog error", ce) ; - } ; - } ; + } + } if ( lineCount > 0 && debug > 2) { log("runCGI: " + lineCount + " lines received on stderr") ; - } ; + } } } //class CGIRunner --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]