seade 2004/08/02 23:11:09
Modified: src/java/org/apache/turbine/util 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
1.6 +28 -65
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.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- HttpUtils.java 21 Nov 2003 19:33:26 -0000 1.5
+++ HttpUtils.java 3 Aug 2004 06:11:09 -0000 1.6
@@ -1,71 +1,33 @@
package org.apache.turbine.util;
-/* ====================================================================
- * The Apache Software License, Version 1.1
+/*
+ * Copyright 2001-2004 The Apache Software Foundation.
*
- * Copyright (c) 2001-2003 The Apache Software Foundation. All rights
- * reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- *
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in
- * the documentation and/or other materials provided with the
- * distribution.
- *
- * 3. The end-user documentation included with the redistribution,
- * if any, must include the following acknowledgment:
- * "This product includes software developed by the
- * Apache Software Foundation (http://www.apache.org/)."
- * Alternately, this acknowledgment may appear in the software itself,
- * if and wherever such third-party acknowledgments normally appear.
- *
- * 4. The names "Apache" and "Apache Software Foundation" and
- * "Apache Turbine" must not be used to endorse or promote products
- * derived from this software without prior written permission. For
- * written permission, please contact [EMAIL PROTECTED]
- *
- * 5. Products derived from this software may not be called "Apache",
- * "Apache Turbine", nor may "Apache" appear in their name, without
- * prior written permission of the Apache Software Foundation.
- *
- * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
- * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
- * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
- * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
- * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
- * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
- * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- * ====================================================================
- *
- * This software consists of voluntary contributions made by many
- * individuals on behalf of the Apache Software Foundation. For more
- * information on the Apache Software Foundation, please see
- * <http://www.apache.org/>.
+ * 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
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
*/
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>
- * @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>.
+ * @version $Id$
*/
public class HttpUtils
{
@@ -82,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
@@ -97,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,
@@ -107,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.5 +48 -82
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
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- BrowserDetector.java 11 Apr 2003 13:17:04 -0000 1.4
+++ BrowserDetector.java 3 Aug 2004 06:11:09 -0000 1.5
@@ -1,57 +1,19 @@
package org.apache.turbine.util;
-/* ====================================================================
- * The Apache Software License, Version 1.1
+/*
+ * Copyright 2001-2004 The Apache Software Foundation.
*
- * Copyright (c) 2001-2003 The Apache Software Foundation. All rights
- * reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- *
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in
- * the documentation and/or other materials provided with the
- * distribution.
- *
- * 3. The end-user documentation included with the redistribution,
- * if any, must include the following acknowledgment:
- * "This product includes software developed by the
- * Apache Software Foundation (http://www.apache.org/)."
- * Alternately, this acknowledgment may appear in the software itself,
- * if and wherever such third-party acknowledgments normally appear.
- *
- * 4. The names "Apache" and "Apache Software Foundation" and
- * "Apache Turbine" must not be used to endorse or promote products
- * derived from this software without prior written permission. For
- * written permission, please contact [EMAIL PROTECTED]
- *
- * 5. Products derived from this software may not be called "Apache",
- * "Apache Turbine", nor may "Apache" appear in their name, without
- * prior written permission of the Apache Software Foundation.
- *
- * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
- * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
- * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
- * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
- * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
- * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
- * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- * ====================================================================
- *
- * This software consists of voluntary contributions made by many
- * individuals on behalf of the Apache Software Foundation. For more
- * information on the Apache Software Foundation, please see
- * <http://www.apache.org/>.
+ * 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
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
*/
/**
@@ -79,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 = "";
@@ -110,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.
*
@@ -136,8 +96,7 @@
*/
public BrowserDetector(RunData data)
{
- this.userAgentString =
- data.getRequest().getHeader("User-Agent");
+ this.userAgentString = data.getUserAgent();
parse();
}
@@ -227,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)
@@ -241,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)
{
@@ -268,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)
{
@@ -292,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;
}
@@ -388,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]