org.jasig.cas.client.util
Class CommonUtils

java.lang.Object
  extended by org.jasig.cas.client.util.CommonUtils

public final class CommonUtils
extends java.lang.Object

Common utilities so that we don't need to include Commons Lang.

Since:
3.0
Version:
$Revision: 11729 $ $Date: 2007-09-26 14:22:30 -0400 (Tue, 26 Sep 2007) $
Author:
Scott Battaglia

Method Summary
static void assertNotEmpty(java.util.Collection c, java.lang.String message)
          Check whether the collection is null or empty.
static void assertNotNull(java.lang.Object object, java.lang.String message)
          Check whether the object is null or not.
static void assertTrue(boolean cond, java.lang.String message)
          Assert that the statement is true, otherwise throw an exception with the provided message.
static java.lang.String constructRedirectUrl(java.lang.String casServerLoginUrl, java.lang.String serviceParameterName, java.lang.String serviceUrl, boolean renew, boolean gateway)
          Constructs the URL to use to redirect to the CAS server.
static java.lang.String constructServiceUrl(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, java.lang.String service, java.lang.String serverName, java.lang.String artifactParameterName, boolean encode)
          Constructs a service url from the HttpServletRequest or from the given serviceUrl.
static java.lang.String getResponseFromServer(java.lang.String url)
          Contacts the remote URL and returns the response.
static java.lang.String getResponseFromServer(java.net.URL constructedUrl)
          Contacts the remote URL and returns the response.
static boolean isBlank(java.lang.String string)
          Determines if a String is blank or not.
static boolean isEmpty(java.lang.String string)
          Determines whether the String is null or of length 0.
static boolean isNotBlank(java.lang.String string)
          Determines if a string is not blank.
static boolean isNotEmpty(java.lang.String string)
          Determines if the String is not empty.
static void readAndRespondToProxyReceptorRequest(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, ProxyGrantingTicketStorage proxyGrantingTicketStorage)
           
static java.lang.String safeGetParameter(javax.servlet.http.HttpServletRequest request, java.lang.String parameter)
          Safe method for retrieving a parameter from the request without disrupting the reader UNLESS the parameter actually exists in the query string.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

assertNotNull

public static void assertNotNull(java.lang.Object object,
                                 java.lang.String message)
Check whether the object is null or not. If it is, throw an exception and display the message.

Parameters:
object - the object to check.
message - the message to display if the object is null.

assertNotEmpty

public static void assertNotEmpty(java.util.Collection c,
                                  java.lang.String message)
Check whether the collection is null or empty. If it is, throw an exception and display the message.

Parameters:
c - the collecion to check.
message - the message to display if the object is null.

assertTrue

public static void assertTrue(boolean cond,
                              java.lang.String message)
Assert that the statement is true, otherwise throw an exception with the provided message.

Parameters:
cond - the codition to assert is true.
message - the message to display if the condition is not true.

isEmpty

public static boolean isEmpty(java.lang.String string)
Determines whether the String is null or of length 0.

Parameters:
string - the string to check
Returns:
true if its null or length of 0, false otherwise.

isNotEmpty

public static boolean isNotEmpty(java.lang.String string)
Determines if the String is not empty. A string is not empty if it is not null and has a length > 0.

Parameters:
string - the string to check
Returns:
true if it is not empty, false otherwise.

isBlank

public static boolean isBlank(java.lang.String string)
Determines if a String is blank or not. A String is blank if its empty or if it only contains spaces.

Parameters:
string - the string to check
Returns:
true if its blank, false otherwise.

isNotBlank

public static boolean isNotBlank(java.lang.String string)
Determines if a string is not blank. A string is not blank if it contains at least one non-whitespace character.

Parameters:
string - the string to check.
Returns:
true if its not blank, false otherwise.

constructRedirectUrl

public static java.lang.String constructRedirectUrl(java.lang.String casServerLoginUrl,
                                                    java.lang.String serviceParameterName,
                                                    java.lang.String serviceUrl,
                                                    boolean renew,
                                                    boolean gateway)
Constructs the URL to use to redirect to the CAS server.

Parameters:
casServerLoginUrl - the CAS Server login url.
serviceParameterName - the name of the parameter that defines the service.
serviceUrl - the actual service's url.
renew - whether we should send renew or not.
gateway - where we should send gateway or not.
Returns:
the fully constructed redirect url.

readAndRespondToProxyReceptorRequest

public static void readAndRespondToProxyReceptorRequest(javax.servlet.http.HttpServletRequest request,
                                                        javax.servlet.http.HttpServletResponse response,
                                                        ProxyGrantingTicketStorage proxyGrantingTicketStorage)
                                                 throws java.io.IOException
Throws:
java.io.IOException

constructServiceUrl

public static java.lang.String constructServiceUrl(javax.servlet.http.HttpServletRequest request,
                                                   javax.servlet.http.HttpServletResponse response,
                                                   java.lang.String service,
                                                   java.lang.String serverName,
                                                   java.lang.String artifactParameterName,
                                                   boolean encode)
Constructs a service url from the HttpServletRequest or from the given serviceUrl. Prefers the serviceUrl provided if both a serviceUrl and a serviceName.

Parameters:
request - the HttpServletRequest
response - the HttpServletResponse
service - the configured service url (this will be used if not null)
serverName - the server name to use to constuct the service url if the service param is empty
artifactParameterName - the artifact parameter name to remove (i.e. ticket)
encode - whether to encode the url or not (i.e. Jsession).
Returns:
the service url to use.

safeGetParameter

public static java.lang.String safeGetParameter(javax.servlet.http.HttpServletRequest request,
                                                java.lang.String parameter)
Safe method for retrieving a parameter from the request without disrupting the reader UNLESS the parameter actually exists in the query string.

Note, this does not work for POST Requests for "logoutRequest". It works for all other CAS POST requests because the parameter is ALWAYS in the GET request.

If we see the "logoutRequest" parameter we MUST treat it as if calling the standard request.getParameter.

Parameters:
request - the request to check.
parameter - the parameter to look for.
Returns:
the value of the parameter.

getResponseFromServer

public static java.lang.String getResponseFromServer(java.net.URL constructedUrl)
Contacts the remote URL and returns the response.

Parameters:
constructedUrl - the url to contact.
Returns:
the response.

getResponseFromServer

public static java.lang.String getResponseFromServer(java.lang.String url)
Contacts the remote URL and returns the response.

Parameters:
url - the url to contact.
Returns:
the response.


Copyright © 2006-2009 JA-SIG. All Rights Reserved.