You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@turbine.apache.org by se...@apache.org on 2004/08/03 07:16:15 UTC

cvs commit: jakarta-turbine-2/src/java/org/apache/turbine/util HttpUtils.java BrowserDetector.java

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:magnus@handpoint.com">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:mospaw@polk-county.com">Chris Mospaw</a>
    * @author <a href="mailto:bgriffin@cddb.com">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: turbine-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: turbine-dev-help@jakarta.apache.org


Re: cvs commit: jakarta-turbine-2/src/java/org/apache/turbine/util

Posted by "Henning P. Schmiedehausen" <hp...@intermeta.de>.
Scott Eade <se...@backstagetech.com.au> writes:

>>> These classes are no longer deprecated - commons-http is clearly dead.
>>>
>>
>>Well, as it is neither visible in commons proper nor in sandbox, one
>>could say that. However, wouldn't it be better to resurrect these
>>classes in commons-http (make it un-dead... ;-) )
>>
>There was a vote back in November where the inconclusive conclusion 
>tended heavily towards rolling this code back into Turbine.  I didn't 
>want to go through the hassle of raising this again and I don't really 
>want to wade into the enormity of commons for a very static 3 class package.

I missed this vote (I wasn't reading much mail in Nov and Dec) . So,
this is fine with me. I wonder whether noone really needs this
functionality outside Turbine or if we are just missing some hugely
popular package that we could use, too.

	Regards
		Henning


-- 
Dipl.-Inf. (Univ.) Henning P. Schmiedehausen          INTERMETA GmbH
hps@intermeta.de        +49 9131 50 654 0   http://www.intermeta.de/

RedHat Certified Engineer -- Jakarta Turbine Development  -- hero for hire
   Linux, Java, perl, Solaris -- Consulting, Training, Development

"Fighting for one's political stand is an honorable action, but re-
 fusing to acknowledge that there might be weaknesses in one's
 position - in order to identify them so that they can be remedied -
 is a large enough problem with the Open Source movement that it
 deserves to be on this list of the top five problems."
                       -- Michelle Levesque, "Fundamental Issues with
                                    Open Source Software Development"

---------------------------------------------------------------------
To unsubscribe, e-mail: turbine-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: turbine-dev-help@jakarta.apache.org


Re: cvs commit: jakarta-turbine-2/src/java/org/apache/turbine/util HttpUtils.java BrowserDetector.java

Posted by Scott Eade <se...@backstagetech.com.au>.
Henning P. Schmiedehausen wrote:

>seade@apache.org writes:
>
>Hi Scott,
>
>
>> These classes are no longer deprecated - commons-http is clearly dead.
>>
>
>Well, as it is neither visible in commons proper nor in sandbox, one
>could say that. However, wouldn't it be better to resurrect these
>classes in commons-http (make it un-dead... ;-) )
>
There was a vote back in November where the inconclusive conclusion 
tended heavily towards rolling this code back into Turbine.  I didn't 
want to go through the hassle of raising this again and I don't really 
want to wade into the enormity of commons for a very static 3 class package.

>
>
>> -        if (expiry == 0)
>> +        if (0 == expiry)
>>
>[...]
>
>> -            data.getResponse().setHeader(
>> -                    "Expires", formatHttpDate(new Date()));
>> +            data.getResponse().setHeader("Expires",
>> +                    formatHttpDate(new Date()));
>>
>
>Well, caveat emptor. I learned to hate changes like this the hard
>way. If you use your tool, I might use another and a third developer
>yet another. The first change IMHO is completely unnecessary, folks
>like me might even be tempted to revert it back.
>
>Doing Formatting changes just for the sake of formatting changes makes
>the whole source code management thing moot. You can't simply diff
>between older revisions to see what really changed because the
>functional changes are drowned in a sea of "...I prefer each method
>call on a separate line...", "... throws belongs right after the
>method signature, no it should be on a new line...","... opening
>brackets on a new line or not..."  changes. If there are multiple
>developers, even things like "I prefer to indent Exceptions four
>spaces. No I prefer to indent them eight spaces" are cluttering the
>code.
>
>Yes, I'm guilty of my own share of checking in such changes. However,
>I would _really_ urge you to not do it. It simply makes no sense.
>
>
>> -            data.getResponse().setHeader(
>> -                    "Expires", formatHttpDate(expiryDate));
>> +            data.getResponse().setHeader("Expires",
>> +                    formatHttpDate(expiryDate));
>>
>
>Same thing. I would even prefer the first version.
>
>
>>          }
>>      }
>> +
>>  }
>>
>
>Someone else will remove this blank line for sure. 
>
>
>>  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";
>> -
>>
>
>Senseless reordering (I would have done this, too :-) ). Your IDE will
>display them in an outline anyway.
>
>Please read this as constructive critisism, not as flaming. As I said,
>I learned this the hard way in a project where I used my tool (emacs)
>and another developer used his tool (Eclipse). In the end, we decided
>to add a code formatter to the checkin scripts. ;-)
>
Guilty as charged of mixing formatting changes with functional changes, 
though the only functional change was the removal of the deprecation tag.

Some of the changes were force of habit on my part (0 == expiry, blank 
line at end of class - slap on the wrist for these), some were dragged 
in from commons-http (moving the constants to the top of the class - as 
you said, you would have done this too :-).

The line wrapping changes close to the setHeader() invocations are more 
in line with the Turbine coding standard IMO and there were other 
formatting changes that corrected violations of the standard that do in 
fact make things clearer (adding missing braces to if...else, moving || 
to beginning of line on wrapped if statement) so a formatting commit was 
in order for one of these two classes anyway.

I promise to be more careful in the future :-)

Cheers,

Scott

-- 
Scott Eade
Backstage Technologies Pty. Ltd.
http://www.backstagetech.com.au


---------------------------------------------------------------------
To unsubscribe, e-mail: turbine-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: turbine-dev-help@jakarta.apache.org


Re: cvs commit: jakarta-turbine-2/src/java/org/apache/turbine/util HttpUtils.java BrowserDetector.java

Posted by "Henning P. Schmiedehausen" <hp...@intermeta.de>.
seade@apache.org writes:

Hi Scott,

>  These classes are no longer deprecated - commons-http is clearly dead.

Well, as it is neither visible in commons proper nor in sandbox, one
could say that. However, wouldn't it be better to resurrect these
classes in commons-http (make it un-dead... ;-) )


>  -        if (expiry == 0)
>  +        if (0 == expiry)
[...]
>  -            data.getResponse().setHeader(
>  -                    "Expires", formatHttpDate(new Date()));
>  +            data.getResponse().setHeader("Expires",
>  +                    formatHttpDate(new Date()));

Well, caveat emptor. I learned to hate changes like this the hard
way. If you use your tool, I might use another and a third developer
yet another. The first change IMHO is completely unnecessary, folks
like me might even be tempted to revert it back.

Doing Formatting changes just for the sake of formatting changes makes
the whole source code management thing moot. You can't simply diff
between older revisions to see what really changed because the
functional changes are drowned in a sea of "...I prefer each method
call on a separate line...", "... throws belongs right after the
method signature, no it should be on a new line...","... opening
brackets on a new line or not..."  changes. If there are multiple
developers, even things like "I prefer to indent Exceptions four
spaces. No I prefer to indent them eight spaces" are cluttering the
code.

Yes, I'm guilty of my own share of checking in such changes. However,
I would _really_ urge you to not do it. It simply makes no sense.

>  -            data.getResponse().setHeader(
>  -                    "Expires", formatHttpDate(expiryDate));
>  +            data.getResponse().setHeader("Expires",
>  +                    formatHttpDate(expiryDate));

Same thing. I would even prefer the first version.

>           }
>       }
>  +
>   }

Someone else will remove this blank line for sure. 

>   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";
>  -

Senseless reordering (I would have done this, too :-) ). Your IDE will
display them in an outline anyway.

Please read this as constructive critisism, not as flaming. As I said,
I learned this the hard way in a project where I used my tool (emacs)
and another developer used his tool (Eclipse). In the end, we decided
to add a code formatter to the checkin scripts. ;-)

	Regards
		Henning


-- 
Dipl.-Inf. (Univ.) Henning P. Schmiedehausen          INTERMETA GmbH
hps@intermeta.de        +49 9131 50 654 0   http://www.intermeta.de/

RedHat Certified Engineer -- Jakarta Turbine Development  -- hero for hire
   Linux, Java, perl, Solaris -- Consulting, Training, Development

"Fighting for one's political stand is an honorable action, but re-
 fusing to acknowledge that there might be weaknesses in one's
 position - in order to identify them so that they can be remedied -
 is a large enough problem with the Open Source movement that it
 deserves to be on this list of the top five problems."
                       -- Michelle Levesque, "Fundamental Issues with
                                    Open Source Software Development"

---------------------------------------------------------------------
To unsubscribe, e-mail: turbine-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: turbine-dev-help@jakarta.apache.org