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 stack
Full name Michael Stack
Date 2000-11-13 18:02:44 PST
Message User: stack
  Date: 00/11/13 18:02:44

  Modified: java/org/joist/util URL.java
  Log:
  Moved url building utility methods from org.tigris.helm.project.Project to here because i need to use the utility in more than one place
  
  Revision Changes Path
  1.12 +86 -1 joist/java/org/joist​/util/URL.java
  
  Index: URL.java
  ====================​====================​====================​=======
  RCS file: /cvs/joist/java/org/​joist/util/URL.java,​v
  retrieving revision 1.11
  retrieving revision 1.12
  diff -u -r1.11 -r1.12
  --- URL.java 2000/11/14 01:31:09 1.11
  +++ URL.java 2000/11/14 02:02:44 1.12
  @@ -62,7 +62,7 @@
    * Parses and builds URLs
    *
    * @author David C. Pellegrini <A HREF="mailto:davidp@​dataweb-systems.com"​>davidp@dataweb-s​ystems.com</A>​
  - * @version $Revision: 1.11 $
  + * @version $Revision: 1.12 $
    *
    * Copyright (c) 1999 dataweb systems, inc.
    * Copyright (c) 1999, 2000 Collab.Net, Inc.
  @@ -118,6 +118,91 @@
       if (p != 80) newURL.append(':').a​ppend(Integer.toStri​ng(p));
       if (debug) log.debug("httpAndServer: " + newURL.toString());
       return newURL;
  + }
  +
  +
  + /** Get Port.
  + *
  + * If port is default for the protocol, we return null else we pull port
  + * for the passed in protocol from inProperties.
  + *
  + * @param inProperties Instance of JoistProperties. Used to pull http
  + * ports from.
  + * @param inProtocol Either 'http' or 'https'.
  + *
  + * @return Port to use as string. Null if port is
  + *
  + * @exception NullPointerException If i can't get a JoistProperties
  + */
  + public String getPort( org.joist.util.JoistProperties inProperties,
  + String inProtocol )
  + throws NullPointerException
  + {
  + String port = null; // Port to return
  +
  + final String HTTP_PROTOCOL = "http";
  + final Integer DEFAULT_HTTP_PORT = new Integer( 80 );
  + final Integer DEFAULT_HTTPS_PORT = new Integer( 443 );
  + final String HTTP_PORT_KEY = "http_port"; // Key to pull http_port
  + final String HTTPS_PORT_KEY = "https_port"; // Key to pull https_port.
  +
  + boolean isHttp = inProtocol.equalsIgnoreCase( HTTP_PROTOCOL );
  + Integer defaultPort = ( isHttp )? DEFAULT_HTTP_PORT: DEFAULT_HTTPS_PORT;
  + String portKey = ( isHttp )? HTTP_PORT_KEY: HTTPS_PORT_KEY;
  + port = inProperties.getProperty( portKey );
  + if( port == null )
  + throw new NullPointerException( portKey + " is null" );
  + if( port.equals( defaultPort.toString( ) ) )
  + port = null; // Return null if port is default for the protocol.
  +
  + return port;
  + }
  +
  +
  + /** Get protocol -- http or https.
  + *
  + * @see #getProtocol( String )
  + */
  + public String getProtocol( )
  + throws NullPointerException, IllegalArgumentException
  + {
  + return getProtocol( ( String )null );
  + }
  +
  +
  + /** Get protocol -- http or https.
  + *
  + * Conveniance method.
  + * <p>
  + * Throws exception if neither. Returns 'http' as default if passed
  + * null.
  + *
  + * @param inProtocol Pass 'http' or 'https'. If null, we assume 'http'.
  + *
  + * @return Return 'http' or 'https'
  + *
  + * @exception IllegalArgumentException Thrown if you pass anything but
  + * 'http' or 'http' in the inProtocol param.
  + */
  + public String getProtocol( String inProtocol )
  + throws NullPointerException, IllegalArgumentException
  + {
  + final String HTTP_PROTOCOL = "http";
  + final String HTTPS_PROTOCOL = "https";
  + final String DEFAULT_PROTOCOL = HTTP_PROTOCOL; // Default protocol
  +
  + String protocol = DEFAULT_PROTOCOL; // Protocol to return.
  +
  + if( inProtocol != null )
  + protocol = inProtocol;
  + if( !protocol.equalsIgnoreCase( HTTP_PROTOCOL )
  + && !protocol.equalsIgnoreCase( HTTPS_PROTOCOL ) )
  + {
  + throw new IllegalArgumentException( "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 stack Michael Stack 2000-11-13 18:02:44 PST
Messages per page: