From: markt Date: Fri, 6 Jul 2007 02:36:32 +0000 (+0000) Subject: o.a.t.util.http X-Git-Url: https://git.internetallee.de/?a=commitdiff_plain;h=218a1dba19667d1c880ab8943f0c5e5f79e6c5cc;p=tomcat7.0 o.a.t.util.http Tabs -> 8 spaces Fix compiler warnings No functional change git-svn-id: https://svn.apache.org/repos/asf/tomcat/tc6.0.x/trunk@553700 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/java/org/apache/tomcat/util/http/AcceptLanguage.java b/java/org/apache/tomcat/util/http/AcceptLanguage.java index 061f24954..a3a103bc0 100644 --- a/java/org/apache/tomcat/util/http/AcceptLanguage.java +++ b/java/org/apache/tomcat/util/http/AcceptLanguage.java @@ -38,44 +38,46 @@ import java.util.Vector; public class AcceptLanguage { public static Locale getLocale(String acceptLanguage) { - if( acceptLanguage == null ) return Locale.getDefault(); + if( acceptLanguage == null ) return Locale.getDefault(); - Hashtable languages = new Hashtable(); - Vector quality=new Vector(); - processAcceptLanguage(acceptLanguage, languages,quality); + Hashtable> languages = + new Hashtable>(); + Vector quality = new Vector(); + processAcceptLanguage(acceptLanguage, languages, quality); if (languages.size() == 0) return Locale.getDefault(); - Vector l = new Vector(); + Vector l = new Vector(); extractLocales( languages,quality, l); return (Locale)l.elementAt(0); } public static Enumeration getLocales(String acceptLanguage) { - // Short circuit with an empty enumeration if null header + // Short circuit with an empty enumeration if null header if (acceptLanguage == null) { - Vector v = new Vector(); + Vector v = new Vector(); v.addElement(Locale.getDefault()); return v.elements(); } - - Hashtable languages = new Hashtable(); - Vector quality=new Vector(); - processAcceptLanguage(acceptLanguage, languages , quality); + + Hashtable> languages = + new Hashtable>(); + Vector quality=new Vector(); + processAcceptLanguage(acceptLanguage, languages , quality); if (languages.size() == 0) { - Vector v = new Vector(); + Vector v = new Vector(); v.addElement(Locale.getDefault()); return v.elements(); } - Vector l = new Vector(); - extractLocales( languages, quality , l); - return l.elements(); + Vector l = new Vector(); + extractLocales( languages, quality , l); + return l.elements(); } private static void processAcceptLanguage( String acceptLanguage, - Hashtable languages, Vector q) + Hashtable> languages, Vector q) { StringTokenizer languageTokenizer = new StringTokenizer(acceptLanguage, ","); @@ -90,7 +92,7 @@ public class AcceptLanguage { if (qValueIndex > -1 && qValueIndex < qIndex && qIndex < equalIndex) { - String qValueStr = language.substring(qValueIndex + 1); + String qValueStr = language.substring(qValueIndex + 1); language = language.substring(0, qValueIndex); qValueStr = qValueStr.trim().toLowerCase(); qValueIndex = qValueStr.indexOf('='); @@ -110,11 +112,11 @@ public class AcceptLanguage { if (! language.equals("*")) { String key = qValue.toString(); - Vector v; + Vector v; if (languages.containsKey(key)) { - v = (Vector)languages.get(key) ; + v = languages.get(key) ; } else { - v= new Vector(); + v= new Vector(); q.addElement(qValue); } v.addElement(language); @@ -123,7 +125,8 @@ public class AcceptLanguage { } } - private static void extractLocales(Hashtable languages, Vector q,Vector l) + private static void extractLocales(Hashtable languages, Vector q, + Vector l) { // XXX We will need to order by q value Vector in the Future ? Enumeration e = q.elements(); @@ -132,9 +135,9 @@ public class AcceptLanguage { (Vector)languages.get(((Double)e.nextElement()).toString()); Enumeration le = v.elements(); while (le.hasMoreElements()) { - String language = (String)le.nextElement(); - String country = ""; - int countryIndex = language.indexOf("-"); + String language = (String)le.nextElement(); + String country = ""; + int countryIndex = language.indexOf("-"); if (countryIndex > -1) { country = language.substring(countryIndex + 1).trim(); language = language.substring(0, countryIndex).trim(); diff --git a/java/org/apache/tomcat/util/http/BaseRequest.java b/java/org/apache/tomcat/util/http/BaseRequest.java index b00f5d322..92e04c928 100644 --- a/java/org/apache/tomcat/util/http/BaseRequest.java +++ b/java/org/apache/tomcat/util/http/BaseRequest.java @@ -59,7 +59,7 @@ public class BaseRequest { MessageBytes contentType = MessageBytes.newInstance(); MimeHeaders headers = new MimeHeaders(); Cookies cookies = new Cookies(); - HashMap attributes = new HashMap(); + HashMap attributes = new HashMap(); MessageBytes tomcatInstanceId = MessageBytes.newInstance(); diff --git a/java/org/apache/tomcat/util/http/Cookies.java b/java/org/apache/tomcat/util/http/Cookies.java index 3f0bc0ee9..fcc931d1d 100644 --- a/java/org/apache/tomcat/util/http/Cookies.java +++ b/java/org/apache/tomcat/util/http/Cookies.java @@ -343,7 +343,6 @@ public final class Cookies { // extends MultiMap { */ public static int findDelim3( byte bytes[], int off, int end, byte cc ) { - byte prev = bytes[off]; while( off < end ) { byte b=bytes[off]; if ( b== '\\' ) { diff --git a/java/org/apache/tomcat/util/http/MimeMap.java b/java/org/apache/tomcat/util/http/MimeMap.java index e377f388a..77cccce46 100644 --- a/java/org/apache/tomcat/util/http/MimeMap.java +++ b/java/org/apache/tomcat/util/http/MimeMap.java @@ -32,7 +32,8 @@ public class MimeMap implements FileNameMap { // Defaults - all of them are "well-known" types, // you can add using normal web.xml. - public static Hashtable defaultMap=new Hashtable(101); + public static Hashtable defaultMap = + new Hashtable(101); static { defaultMap.put("txt", "text/plain"); defaultMap.put("html","text/html"); @@ -42,7 +43,7 @@ public class MimeMap implements FileNameMap { defaultMap.put("jpe", "image/jpeg"); defaultMap.put("jpeg", "image/jpeg"); defaultMap.put("png", "image/png"); - defaultMap.put("java", "text/plain"); + defaultMap.put("java", "text/plain"); defaultMap.put("body", "text/html"); defaultMap.put("rtx", "text/richtext"); defaultMap.put("tsv", "text/tab-separated-values"); @@ -133,7 +134,7 @@ public class MimeMap implements FileNameMap { } - private Hashtable map = new Hashtable(); + private Hashtable map = new Hashtable(); public void addContentType(String extn, String type) { map.put(extn, type.toLowerCase()); @@ -145,8 +146,8 @@ public class MimeMap implements FileNameMap { public String getContentType(String extn) { String type = (String)map.get(extn.toLowerCase()); - if( type == null ) type=(String)defaultMap.get( extn ); - return type; + if( type == null ) type=(String)defaultMap.get( extn ); + return type; } public void removeContentType(String extn) { @@ -158,14 +159,14 @@ public class MimeMap implements FileNameMap { public static String getExtension( String fileName ) { // play it safe and get rid of any fragment id // that might be there - int length=fileName.length(); - + int length=fileName.length(); + int newEnd = fileName.lastIndexOf('#'); - if( newEnd== -1 ) newEnd=length; - // Instead of creating a new string. - // if (i != -1) { - // fileName = fileName.substring(0, i); - // } + if( newEnd== -1 ) newEnd=length; + // Instead of creating a new string. + // if (i != -1) { + // fileName = fileName.substring(0, i); + // } int i = fileName.lastIndexOf('.', newEnd ); if (i != -1) { return fileName.substring(i + 1, newEnd ); @@ -176,7 +177,7 @@ public class MimeMap implements FileNameMap { } public String getContentTypeFor(String fileName) { - String extn=getExtension( fileName ); + String extn=getExtension( fileName ); if (extn!=null) { return getContentType(extn); } else { diff --git a/java/org/apache/tomcat/util/http/Parameters.java b/java/org/apache/tomcat/util/http/Parameters.java index 03f59b800..1d7039449 100644 --- a/java/org/apache/tomcat/util/http/Parameters.java +++ b/java/org/apache/tomcat/util/http/Parameters.java @@ -40,7 +40,8 @@ public final class Parameters extends MultiMap { // Transition: we'll use the same Hashtable( String->String[] ) // for the beginning. When we are sure all accesses happen through // this class - we can switch to MultiMap - private Hashtable paramHashStringArray=new Hashtable(); + private Hashtable paramHashStringArray = + new Hashtable(); private boolean didQueryParameters=false; private boolean didMerge=false; @@ -225,7 +226,7 @@ public final class Parameters extends MultiMap { // Add the parent props to the child ( lower precedence ) parent.merge(); - Hashtable parentProps=parent.paramHashStringArray; + Hashtable parentProps=parent.paramHashStringArray; merge2( paramHashStringArray , parentProps); didMerge=true; if(debug > 0 ) @@ -273,13 +274,14 @@ public final class Parameters extends MultiMap { * Used to combine child parameters ( RequestDispatcher's query ) * with parent parameters ( original query or parent dispatcher ) */ - private static void merge2(Hashtable one, Hashtable two ) { + private static void merge2(Hashtable one, + Hashtable two ) { Enumeration e = two.keys(); while (e.hasMoreElements()) { String name = (String) e.nextElement(); - String[] oneValue = (String[]) one.get(name); - String[] twoValue = (String[]) two.get(name); + String[] oneValue = one.get(name); + String[] twoValue = two.get(name); String[] combinedValue; if (twoValue == null) { diff --git a/java/org/apache/tomcat/util/http/ServerCookie.java b/java/org/apache/tomcat/util/http/ServerCookie.java index 1c19a3a13..3698b1c86 100644 --- a/java/org/apache/tomcat/util/http/ServerCookie.java +++ b/java/org/apache/tomcat/util/http/ServerCookie.java @@ -43,15 +43,15 @@ public class ServerCookie implements Serializable { private MessageBytes name=MessageBytes.newInstance(); private MessageBytes value=MessageBytes.newInstance(); - private MessageBytes comment=MessageBytes.newInstance(); // ;Comment=VALUE - private MessageBytes domain=MessageBytes.newInstance(); // ;Domain=VALUE ... + private MessageBytes comment=MessageBytes.newInstance(); // ;Comment=VALUE + private MessageBytes domain=MessageBytes.newInstance(); // ;Domain=VALUE - private int maxAge = -1; // ;Max-Age=VALUE - // ;Discard ... implied by maxAge < 0 + private int maxAge = -1; // ;Max-Age=VALUE + // ;Discard ... implied by maxAge < 0 // RFC2109: maxAge=0 will end a session - private MessageBytes path=MessageBytes.newInstance(); // ;Path=VALUE . - private boolean secure; // ;Secure - private int version = 0; // ;Version=1 + private MessageBytes path=MessageBytes.newInstance(); // ;Path=VALUE + private boolean secure; // ;Secure + private int version = 0; // ;Version=1 //XXX CommentURL, Port -> use notes ? @@ -61,68 +61,68 @@ public class ServerCookie implements Serializable { public void recycle() { path.recycle(); - name.recycle(); - value.recycle(); - comment.recycle(); - maxAge=-1; - path.recycle(); + name.recycle(); + value.recycle(); + comment.recycle(); + maxAge=-1; + path.recycle(); domain.recycle(); - version=0; - secure=false; + version=0; + secure=false; } public MessageBytes getComment() { - return comment; + return comment; } public MessageBytes getDomain() { - return domain; + return domain; } public void setMaxAge(int expiry) { - maxAge = expiry; + maxAge = expiry; } public int getMaxAge() { - return maxAge; + return maxAge; } public MessageBytes getPath() { - return path; + return path; } public void setSecure(boolean flag) { - secure = flag; + secure = flag; } public boolean getSecure() { - return secure; + return secure; } public MessageBytes getName() { - return name; + return name; } public MessageBytes getValue() { - return value; + return value; } public int getVersion() { - return version; + return version; } public void setVersion(int v) { - version = v; + version = v; } // -------------------- utils -------------------- public String toString() { - return "Cookie " + getName() + "=" + getValue() + " ; " - + getVersion() + " " + getPath() + " " + getDomain(); + return "Cookie " + getName() + "=" + getValue() + " ; " + + getVersion() + " " + getPath() + " " + getDomain(); } // Note -- disabled for now to allow full Netscape compatibility @@ -136,52 +136,51 @@ public class ServerCookie implements Serializable { * Tests a string and returns true if the string counts as a * reserved token in the Java language. * - * @param value the String to be tested + * @param value the String to be tested * - * @return true if the String is - * a reserved token; false - * if it is not + * @return true if the String is a reserved + * token; false if it is not */ public static boolean isToken(String value) { - if( value==null) return true; - int len = value.length(); + if( value==null) return true; + int len = value.length(); - for (int i = 0; i < len; i++) { - char c = value.charAt(i); + for (int i = 0; i < len; i++) { + char c = value.charAt(i); - if (c < 0x20 || c >= 0x7f || tspecials.indexOf(c) != -1) - return false; - } - return true; + if (c < 0x20 || c >= 0x7f || tspecials.indexOf(c) != -1) + return false; + } + return true; } public static boolean isToken2(String value) { - if( value==null) return true; - int len = value.length(); + if( value==null) return true; + int len = value.length(); - for (int i = 0; i < len; i++) { - char c = value.charAt(i); + for (int i = 0; i < len; i++) { + char c = value.charAt(i); - if (c < 0x20 || c >= 0x7f || tspecials2.indexOf(c) != -1) - return false; - } - return true; + if (c < 0x20 || c >= 0x7f || tspecials2.indexOf(c) != -1) + return false; + } + return true; } public static boolean checkName( String name ) { - if (!isToken(name) - || name.equalsIgnoreCase("Comment") // rfc2019 - || name.equalsIgnoreCase("Discard") // 2019++ - || name.equalsIgnoreCase("Domain") - || name.equalsIgnoreCase("Expires") // (old cookies) - || name.equalsIgnoreCase("Max-Age") // rfc2019 - || name.equalsIgnoreCase("Path") - || name.equalsIgnoreCase("Secure") - || name.equalsIgnoreCase("Version") - ) { - return false; - } - return true; + if (!isToken(name) + || name.equalsIgnoreCase("Comment") // rfc2019 + || name.equalsIgnoreCase("Discard") // 2019++ + || name.equalsIgnoreCase("Domain") + || name.equalsIgnoreCase("Expires") // (old cookies) + || name.equalsIgnoreCase("Max-Age") // rfc2019 + || name.equalsIgnoreCase("Path") + || name.equalsIgnoreCase("Secure") + || name.equalsIgnoreCase("Version") + ) { + return false; + } + return true; } // -------------------- Cookie parsing tools @@ -191,99 +190,100 @@ public class ServerCookie implements Serializable { * version */ public String getCookieHeaderName() { - return getCookieHeaderName(version); + return getCookieHeaderName(version); } /** Return the header name to set the cookie, based on cookie * version */ public static String getCookieHeaderName(int version) { - if( dbg>0 ) log( (version==1) ? "Set-Cookie2" : "Set-Cookie"); + if( dbg>0 ) log( (version==1) ? "Set-Cookie2" : "Set-Cookie"); if (version == 1) { - // RFC2109 - return "Set-Cookie"; - // XXX RFC2965 is not standard yet, and Set-Cookie2 - // is not supported by Netscape 4, 6, IE 3, 5 . - // It is supported by Lynx, and there is hope - // return "Set-Cookie2"; + // RFC2109 + return "Set-Cookie"; + // XXX RFC2965 is not standard yet, and Set-Cookie2 + // is not supported by Netscape 4, 6, IE 3, 5 . + // It is supported by Lynx, and there is hope + // return "Set-Cookie2"; } else { - // Old Netscape - return "Set-Cookie"; + // Old Netscape + return "Set-Cookie"; } } - private static final String ancientDate=DateTool.formatOldCookie(new Date(10000)); + private static final String ancientDate = + DateTool.formatOldCookie(new Date(10000)); public static void appendCookieValue( StringBuffer buf, - int version, - String name, - String value, - String path, - String domain, - String comment, - int maxAge, - boolean isSecure ) + int version, + String name, + String value, + String path, + String domain, + String comment, + int maxAge, + boolean isSecure ) { // this part is the same for all cookies - buf.append( name ); + buf.append( name ); buf.append("="); maybeQuote2(version, buf, value); - // XXX Netscape cookie: "; " - // add version 1 specific information - if (version == 1) { - // Version=1 ... required - buf.append ("; Version=1"); - - // Comment=comment - if ( comment!=null ) { - buf.append ("; Comment="); - maybeQuote (version, buf, comment); - } - } - - // add domain information, if present - - if (domain!=null) { - buf.append("; Domain="); - maybeQuote (version, buf, domain); - } - - // Max-Age=secs/Discard ... or use old "Expires" format - if (maxAge >= 0) { - if (version == 0) { - // XXX XXX XXX We need to send both, for - // interoperatibility (long word ) - buf.append ("; Expires="); - // Wdy, DD-Mon-YY HH:MM:SS GMT ( Expires netscape format ) - // To expire we need to set the time back in future - // ( pfrieden@dChain.com ) + // XXX Netscape cookie: "; " + // add version 1 specific information + if (version == 1) { + // Version=1 ... required + buf.append ("; Version=1"); + + // Comment=comment + if ( comment!=null ) { + buf.append ("; Comment="); + maybeQuote (version, buf, comment); + } + } + + // add domain information, if present + + if (domain!=null) { + buf.append("; Domain="); + maybeQuote (version, buf, domain); + } + + // Max-Age=secs/Discard ... or use old "Expires" format + if (maxAge >= 0) { + if (version == 0) { + // XXX XXX XXX We need to send both, for + // interoperatibility (long word ) + buf.append ("; Expires="); + // Wdy, DD-Mon-YY HH:MM:SS GMT ( Expires netscape format ) + // To expire we need to set the time back in future + // ( pfrieden@dChain.com ) if (maxAge == 0) - buf.append( ancientDate ); - else + buf.append( ancientDate ); + else DateTool.formatOldCookie (new Date( System.currentTimeMillis() + maxAge *1000L), buf, new FieldPosition(0)); - } else { - buf.append ("; Max-Age="); - buf.append (maxAge); - } - } - - // Path=path - if (path!=null) { - buf.append ("; Path="); - maybeQuote (version, buf, path); - } - - // Secure - if (isSecure) { - buf.append ("; Secure"); - } - - + } else { + buf.append ("; Max-Age="); + buf.append (maxAge); + } + } + + // Path=path + if (path!=null) { + buf.append ("; Path="); + maybeQuote (version, buf, path); + } + + // Secure + if (isSecure) { + buf.append ("; Secure"); + } + + } public static void maybeQuote (int version, StringBuffer buf,