Login | Register
My pages Projects Community openCollabNet

Discussions > cvs > CVS update: joist/java/org/joist/util URL.java

Project highlights: Architectural Overview

joist
Discussion topic

Back to topic list

CVS update: joist/java/org/joist/util URL.java

Author dlr
Full name Daniel Rall
Date 2001-04-24 13:49:44 PDT
Message User: dlr
  Date: 01/04/24 13:49:44

  Modified: java/org/joist/util Tag: TIGRIS_1_0 URL.java
  Log:
  Cleaned up and added appendCGISeparator method.
  
  Revision Changes Path
  No revision
  
  
  No revision
  
  
  1.32.6.1 +47 -34 joist/java/org/joist​/util/URL.java
  
  Index: URL.java
  ====================​====================​====================​=======
  RCS file: /cvs/joist/java/org/​joist/util/URL.java,​v
  retrieving revision 1.32
  retrieving revision 1.32.6.1
  diff -u -r1.32 -r1.32.6.1
  --- URL.java 2001/02/21 01:35:13 1.32
  +++ URL.java 2001/04/24 20:49:43 1.32.6.1
  @@ -65,10 +65,10 @@
    *
    * @author David C. Pellegrini <A HREF="mailto:davidp@​dataweb-systems.com"​>davidp@dataweb-s​ystems.com</A>​
    * @author <a href="mailto:dlr@col​lab.net">Daniel Rall</a>
  - * @version $Id: URL.java,v 1.32 2001/02/21 01:35:13 dlr Exp $
  + * @version $Id: URL.java,v 1.32.6.1 2001/04/24 20:49:43 dlr Exp $
    *
    * Copyright (c) 1999 dataweb systems, inc.
  - * Copyright (c) 1999, 2000 CollabNet, Inc.
  + * Copyright (c) 1999-2001 CollabNet, Inc.
    */
   
   public class URL
  @@ -137,7 +137,7 @@
        */
       public static boolean hasProtocol (String url)
       {
  - return (url != null ? url.indexOf("://") != -1 : false);
  + return (url != null ? url.indexOf("://") != -1 : false);
       }
   
       /**
  @@ -168,12 +168,15 @@
       protected static StringBuffer protoAndServer (WebContext context,
                                                     String protocol)
       {
  - StringBuffer newURL = new StringBuffer(protoco​l).append("://");
  - HttpServletRequest request = context.getRequest();
  - newURL.append(reques​t.getServerName());
  - int p = request.getServerPort();
  - if (p != HTTP_PORT) newURL.append(':').append(p);
  - return newURL;
  + StringBuffer newURL = new StringBuffer(protoco​l).append("://");
  + HttpServletRequest request = context.getRequest();
  + newURL.append(reques​t.getServerName());
  + int p = request.getServerPort();
  + if (p != HTTP_PORT && p != HTTPS_PORT)
  + {
  + newURL.append(':').append(p);
  + }
  + return newURL;
       }
   
       static final String DOMAIN_KEY = "domain";
  @@ -240,13 +243,25 @@
       private static String appendCGIParam (StringBuffer buf, String url,
                                             String name, String value)
       {
  - buf.append(url.indexOf('?') == -1 ? '?' : '&');
  + appendCGISeparator(buf, url);
           if (name != null) buf.append(URLEncode​r.encode(name)).appe​nd('=');
           buf.append(URLEncode​r.encode(value));
           return buf.toString();
       }
       
       /**
  + * Appends the CGI parameter separator character appropriate for
  + * the supplied URL to the specified buffer.
  + *
  + * @param buf The buffer to write to.
  + * @param url The URL to append to.
  + */
  + public static final void appendCGISeparator(StringBuffer buf, String url)
  + {
  + buf.append(url.indexOf('?') == -1 ? '?' : '&');
  + }
  +
  + /**
        * If port is default for the protocol, we return null else we pull port
        * for the passed in protocol from inProperties.
        *
  @@ -261,24 +276,18 @@
        public String getPort( String inProtocol )
           throws NullPointerException
        {
  - String port = null; // Port to return
  - String protocol = ( inProtocol == null )? getProtocol( ): inProtocol;
  -
  - // JoistProperties is a singleton of system properties.
  - org.joist.util.JoistProperties properties
  - = org.joist.util.Joist​Properties.getInstan​ce( );
  - if( properties == null )
  - throw new NullPointerException( "JoistProperties is null" );
  + String port = null;
   
  + String protocol = (inProtocol == null ? getProtocol() : inProtocol);
           boolean isHttp = protocol.equalsIgnoreCase( HTTP_PROTOCOL );
           Integer defaultPort = (isHttp ? DEFAULT_HTTP_PORT: DEFAULT_HTTPS_PORT);
           String portKey = (isHttp ? HTTP_PORT_KEY : HTTPS_PORT_KEY);
  - port = properties.getProperty( portKey );
  - if( port == null )
  + port = JoistProperties.getP​roperty(portKey);
  + if (port == null)
               throw new NullPointerException( portKey + " is null" );
  - if( port.equals( defaultPort.toString( ) ) )
  + if ( port.equals(defaultP​ort.toString()) )
               port = null; // Return null if port is default for the protocol.
  -
  +
           return port;
        }
       
  @@ -313,28 +322,32 @@
       public String getProtocol( String inProtocol )
           throws NullPointerException, IllegalArgumentException
       {
  - String protocol = DEFAULT_PROTOCOL; // Protocol to return.
  + String protocol = DEFAULT_PROTOCOL;
   
  - String forceProtocol = JoistProperties.getInstance().
  - getProperty(FORCE_SCHEME_KEY);
  - if( inProtocol != null ) {
  + String forceProtocol = JoistProperties.getP​roperty(FORCE_SCHEME​_KEY);
  + if (inProtocol != null)
  + {
               protocol = inProtocol;
  - } else if (forceProtocol != null) {
  + }
  + else if (forceProtocol != null)
  + {
               if (forceProtocol.equal​sIgnoreCase(HTTP_PRO​TOCOL))
                   protocol = HTTP_PROTOCOL;
               else if (forceProtocol.equal​sIgnoreCase(HTTPS_PR​OTOCOL))
                   protocol = HTTPS_PROTOCOL;
  - } else if ( inProtocol == null) {
  + }
  + else if (inProtocol == null)
  + {
               protocol = HTTP_PROTOCOL;
           }
  -
  - if( !protocol.equalsIgnoreCase( HTTP_PROTOCOL )
  - && !protocol.equalsIgnoreCase( HTTPS_PROTOCOL ) )
  +
  + if ( !protocol.equalsIgno​reCase(HTTP_PROTOCOL​)
  + && !protocol.equalsIgno​reCase(HTTPS_PROTOCO​L) )
           {
  - throw new IllegalArgumentException( "Unsupported protocol: "
  - + inProtocol );
  + throw new IllegalArgumentExcep​tion("Unsupported protocol: "
  + + inProtocol);
           }
  -
  +
           return protocol;
       }

« Previous message in topic | 1 of 1 | Next message in topic »

Messages

Show all messages in topic

CVS update: joist/java/org/joist/util URL.java dlr Daniel Rall 2001-04-24 13:49:44 PDT
Messages per page: