seade 2004/08/02 22:16:15
Modified: src/java/org/apache/turbine/util Tag: TURBINE_2_3_BRANCH
HttpUtils.java BrowserDetector.java
Log:
These classes are no longer deprecated - commons-http is clearly dead.
Also fixed typos in JavaDoc and did some minor reformatting.
Revision Changes Path
No revision
No revision
1.4.2.4 +16 -16
jakarta-turbine-2/src/java/org/apache/turbine/util/HttpUtils.java
Index: HttpUtils.java
===================================================================
RCS file:
/home/cvs/jakarta-turbine-2/src/java/org/apache/turbine/util/HttpUtils.java,v
retrieving revision 1.4.2.3
retrieving revision 1.4.2.4
diff -u -r1.4.2.3 -r1.4.2.4
--- HttpUtils.java 20 May 2004 03:16:38 -0000 1.4.2.3
+++ HttpUtils.java 3 Aug 2004 05:16:14 -0000 1.4.2.4
@@ -3,7 +3,7 @@
/*
* Copyright 2001-2004 The Apache Software Foundation.
*
- * Licensed under the Apache License, Version 2.0 (the "License")
+ * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
@@ -17,18 +17,17 @@
*/
import java.text.SimpleDateFormat;
+
import java.util.Date;
import java.util.Locale;
import java.util.TimeZone;
/**
- * This class provides utilities for handling some semi-trivial
- * HTTP stuff that would othterwize be handled elsewhere.
+ * This class provides utilities for handling some semi-trivial HTTP stuff that
+ * would othterwise be handled elsewhere.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Magn�s ��r Torfason</a>
* @version $Id$
- * @deprecated This class will be removed after the 2.3 release. Please
- * use HttpUtils from <a
href="http://jakarta.apache.org/commons/">commons-http</a>.
*/
public class HttpUtils
{
@@ -45,8 +44,8 @@
}
/**
- * Formats a java Date according to rfc 1123, the rfc
- * standard for dates in http.
+ * Formats a java Date according to rfc 1123, the rfc standard for dates in
+ * http.
*
* @param date The Date to format
* @return A String represeentation of the date
@@ -60,9 +59,9 @@
}
/**
- * This method sets the required expiration headers in the response
- * for a given RunData object. This method attempts to set all
- * relevant headers, both for HTTP 1.0 and HTTP 1.1.
+ * This method sets the required expiration headers in the response for a
+ * given RunData object. This method attempts to set all relevant headers,
+ * both for HTTP 1.0 and HTTP 1.1.
*
* @param data The RunData object we are setting cache information for.
* @param expiry The number of seconds untill the document should expire,
@@ -70,18 +69,19 @@
*/
public static void setCacheHeaders(RunData data, int expiry)
{
- if (expiry == 0)
+ if (0 == expiry)
{
data.getResponse().setHeader("Pragma", "no-cache");
data.getResponse().setHeader("Cache-Control", "no-cache");
- data.getResponse().setHeader(
- "Expires", formatHttpDate(new Date()));
+ data.getResponse().setHeader("Expires",
+ formatHttpDate(new Date()));
}
else
{
Date expiryDate = new Date(System.currentTimeMillis() + expiry);
- data.getResponse().setHeader(
- "Expires", formatHttpDate(expiryDate));
+ data.getResponse().setHeader("Expires",
+ formatHttpDate(expiryDate));
}
}
+
}
1.4.2.3 +36 -32
jakarta-turbine-2/src/java/org/apache/turbine/util/BrowserDetector.java
Index: BrowserDetector.java
===================================================================
RCS file:
/home/cvs/jakarta-turbine-2/src/java/org/apache/turbine/util/BrowserDetector.java,v
retrieving revision 1.4.2.2
retrieving revision 1.4.2.3
diff -u -r1.4.2.2 -r1.4.2.3
--- BrowserDetector.java 20 May 2004 03:16:38 -0000 1.4.2.2
+++ BrowserDetector.java 3 Aug 2004 05:16:15 -0000 1.4.2.3
@@ -3,7 +3,7 @@
/*
* Copyright 2001-2004 The Apache Software Foundation.
*
- * Licensed under the Apache License, Version 2.0 (the "License")
+ * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
@@ -41,11 +41,17 @@
* @author <a href="mailto:[EMAIL PROTECTED]">Chris Mospaw</a>
* @author <a href="mailto:[EMAIL PROTECTED]">Benjamin Elijah Griffin</a>
* @version $Id$
- * @deprecated This class will be removed after the 2.3 release. Please
- * use BrowserDetector from <a
href="http://jakarta.apache.org/commons/">commons-http</a>.
*/
public class BrowserDetector
{
+ public static final String MSIE = "MSIE";
+ public static final String OPERA = "Opera";
+ public static final String MOZILLA = "Mozilla";
+
+ public static final String WINDOWS = "Windows";
+ public static final String UNIX = "Unix";
+ public static final String MACINTOSH = "Macintosh";
+
/** The user agent string. */
private String userAgentString = "";
@@ -72,14 +78,6 @@
/** Whether or not file upload works in this browser. */
private boolean fileUploadOK = false;
- /** Constants used by this class. */
- public static final String MSIE = "MSIE";
- public static final String OPERA = "Opera";
- public static final String MOZILLA = "Mozilla";
- public static final String WINDOWS = "Windows";
- public static final String UNIX = "Unix";
- public static final String MACINTOSH = "Macintosh";
-
/**
* Constructor used to initialize this class.
*
@@ -98,8 +96,7 @@
*/
public BrowserDetector(RunData data)
{
- this.userAgentString =
- data.getRequest().getHeader("User-Agent");
+ this.userAgentString = data.getUserAgent();
parse();
}
@@ -189,9 +186,15 @@
// string.
String agentSubstring = null;
if (versionEndIndex < 0)
- agentSubstring = userAgentString.substring(versionStartIndex + 1);
+ {
+ agentSubstring
+ = userAgentString.substring(versionStartIndex + 1);
+ }
else
- agentSubstring = userAgentString.substring(versionStartIndex + 1,
versionEndIndex);
+ {
+ agentSubstring = userAgentString
+ .substring(versionStartIndex + 1, versionEndIndex);
+ }
browserVersion = toFloat(agentSubstring);
}
catch (NumberFormatException e)
@@ -203,15 +206,15 @@
if (userAgentString.indexOf(MSIE) != -1)
{
// Ex: Mozilla/4.0 (compatible; MSIE 5.0; Windows NT; DigExt)
- versionStartIndex = (userAgentString.indexOf(MSIE) +
- MSIE.length() + 1);
- versionEndIndex = userAgentString.indexOf(";",
- versionStartIndex);
+ versionStartIndex = (userAgentString.indexOf(MSIE)
+ + MSIE.length() + 1);
+ versionEndIndex = userAgentString.indexOf(";", versionStartIndex);
browserName = MSIE;
try
{
- browserVersion =
toFloat(userAgentString.substring(versionStartIndex, versionEndIndex));
+ browserVersion = toFloat(userAgentString
+ .substring(versionStartIndex, versionEndIndex));
}
catch (NumberFormatException e)
{
@@ -230,15 +233,15 @@
if (userAgentString.indexOf(OPERA) != -1)
{
//Ex: Mozilla/4.0 (Windows NT 4.0;US) Opera 3.61 [en]
- versionStartIndex = (userAgentString.indexOf(OPERA) +
- OPERA.length() + 1);
- versionEndIndex = userAgentString.indexOf(" ",
- versionStartIndex);
+ versionStartIndex = (userAgentString.indexOf(OPERA)
+ + OPERA.length() + 1);
+ versionEndIndex = userAgentString.indexOf(" ", versionStartIndex);
browserName = OPERA;
try
{
- browserVersion =
toFloat(userAgentString.substring(versionStartIndex, versionEndIndex));
+ browserVersion = toFloat(userAgentString
+ .substring(versionStartIndex, versionEndIndex));
}
catch (NumberFormatException e)
{
@@ -254,10 +257,10 @@
// Try to figure out what platform.
- if ((userAgentString.indexOf("Windows") != -1) ||
- (userAgentString.indexOf("WinNT") != -1) ||
- (userAgentString.indexOf("Win98") != -1) ||
- (userAgentString.indexOf("Win95") != -1))
+ if ((userAgentString.indexOf("Windows") != -1)
+ || (userAgentString.indexOf("WinNT") != -1)
+ || (userAgentString.indexOf("Win98") != -1)
+ || (userAgentString.indexOf("Win95") != -1))
{
browserPlatform = WINDOWS;
}
@@ -350,13 +353,14 @@
}
/**
- * Helper method to conver String to a float.
+ * Helper method to convert String to a float.
*
* @param s A String.
* @return The String converted to float.
*/
- private float toFloat(String s)
+ private static final float toFloat(String s)
{
return Float.valueOf(s).floatValue();
}
+
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]