org.objectweb.telosys.util.web
Class WebUtil

java.lang.Object
  extended byorg.objectweb.telosys.util.web.WebUtil

public final class WebUtil
extends java.lang.Object

Utility class for Web operations ( set of static methods )


Method Summary
static boolean checkExistence(javax.servlet.ServletContext servletContext, java.lang.String sResourcePath)
          Check the existence of the given resource in the given servlet context
static void error(javax.servlet.http.HttpServletResponse response, java.lang.String sMsg)
          Generates a "text/html" response page with a "body" containing "ERROR" + the given message
static void error(javax.servlet.http.HttpServletResponse response, java.lang.String sMsg, java.util.ListIterator iter)
          Generates a "text/html" response page with a "body" containing the given message and one line for each item of the iterator
static boolean forward(java.lang.String sUrl, javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
          Uses the "request dispatcher" to forward a request
static java.lang.String getContextResourceURI(javax.servlet.http.HttpServletRequest request, java.lang.String sResourcePath)
          Returns the context URI for the given resource path
static java.lang.String getContextResourceURL(javax.servlet.http.HttpServletRequest request, java.lang.String sResourcePath)
          Returns the full "client side" http URL for the given resource path
static java.lang.String getContextRootURI(javax.servlet.http.HttpServletRequest request)
          Returns the context root URI for the given request
( e.g. : "/WebAppContext" )
static java.lang.String getContextRootURL(javax.servlet.http.HttpServletRequest request)
          Returns the full context root URL for the given request
( e.g. : "http://server:8080/WebAppContext" )
static java.lang.String getRootUrl(javax.servlet.http.HttpServletRequest request)
          Deprecated. : use getContextRootURL() instead
static void info(javax.servlet.http.HttpServletResponse response, java.lang.String sMsg)
          Generates a "text/html" response page with a "body" containing only the given message
static void msgPage(javax.servlet.http.HttpServletResponse response, java.lang.String sTitle, java.lang.String sMsg)
          Generates a "text/html" response page with a "body" containing the given title and message
static void noCache(javax.servlet.http.HttpServletResponse response)
          Set the HTTP headers to avoid caching
static boolean redirect(java.lang.String sUrl, javax.servlet.http.HttpServletResponse response)
          "HTTP redirection" to an other URL ( HTTP code "302" )
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

forward

public static boolean forward(java.lang.String sUrl,
                              javax.servlet.http.HttpServletRequest request,
                              javax.servlet.http.HttpServletResponse response)
                       throws javax.servlet.ServletException,
                              java.io.IOException
Uses the "request dispatcher" to forward a request

Parameters:
sUrl - the target URL
request - the request object
response - the response object
Returns:
boolean true if the forward is OK, false if cannot get the request dispatcher
Throws:
javax.servlet.ServletException - :
java.io.IOException - :

redirect

public static boolean redirect(java.lang.String sUrl,
                               javax.servlet.http.HttpServletResponse response)
"HTTP redirection" to an other URL ( HTTP code "302" )

Parameters:
sUrl - the target URL
response - the response object
Returns:
boolean true = OK, false = ERR

noCache

public static void noCache(javax.servlet.http.HttpServletResponse response)
Set the HTTP headers to avoid caching

Parameters:
response -

info

public static void info(javax.servlet.http.HttpServletResponse response,
                        java.lang.String sMsg)
                 throws javax.servlet.ServletException,
                        java.io.IOException
Generates a "text/html" response page with a "body" containing only the given message

Parameters:
response - the response object
sMsg - the message to print in the generated page
Throws:
javax.servlet.ServletException - :
java.io.IOException - :

error

public static void error(javax.servlet.http.HttpServletResponse response,
                         java.lang.String sMsg)
                  throws javax.servlet.ServletException,
                         java.io.IOException
Generates a "text/html" response page with a "body" containing "ERROR" + the given message

Parameters:
response - :
sMsg - :
Throws:
javax.servlet.ServletException - :
java.io.IOException - :

error

public static void error(javax.servlet.http.HttpServletResponse response,
                         java.lang.String sMsg,
                         java.util.ListIterator iter)
                  throws javax.servlet.ServletException,
                         java.io.IOException
Generates a "text/html" response page with a "body" containing the given message and one line for each item of the iterator

Parameters:
response - :
sMsg - :
iter - :
Throws:
javax.servlet.ServletException - :
java.io.IOException - :

msgPage

public static void msgPage(javax.servlet.http.HttpServletResponse response,
                           java.lang.String sTitle,
                           java.lang.String sMsg)
Generates a "text/html" response page with a "body" containing the given title and message

Parameters:
response -
sTitle - the title
sMsg - the message

getRootUrl

public static java.lang.String getRootUrl(javax.servlet.http.HttpServletRequest request)
Deprecated. : use getContextRootURL() instead

Returns the full context root URL for the given request with "/" at the end
( e.g. : "http://server:8080/WebAppContext/" )

Parameters:
request -
Returns:

getContextRootURL

public static java.lang.String getContextRootURL(javax.servlet.http.HttpServletRequest request)
Returns the full context root URL for the given request
( e.g. : "http://server:8080/WebAppContext" )

Parameters:
request -
Returns:
"http://server:8080/WebAppContext"

getContextRootURI

public static java.lang.String getContextRootURI(javax.servlet.http.HttpServletRequest request)
Returns the context root URI for the given request
( e.g. : "/WebAppContext" )

Parameters:
request -
Returns:
"/WebAppContext"

getContextResourceURL

public static java.lang.String getContextResourceURL(javax.servlet.http.HttpServletRequest request,
                                                     java.lang.String sResourcePath)
Returns the full "client side" http URL for the given resource path

Parameters:
request -
sResourcePath - : the server side context resource path
( ie : "/folder/file", "folder/file", "/file", "file" )
Returns:
: the full URL ( ie : "http://myhost:8080/contextname/folder/file")

getContextResourceURI

public static java.lang.String getContextResourceURI(javax.servlet.http.HttpServletRequest request,
                                                     java.lang.String sResourcePath)
Returns the context URI for the given resource path

Parameters:
request -
sResourcePath - : the server side context resource path
( ie : "/folder/file", "folder/file", "/file", "file" )
Returns:
: the URI ( ie : "/contextname/folder/file" )

checkExistence

public static boolean checkExistence(javax.servlet.ServletContext servletContext,
                                     java.lang.String sResourcePath)
Check the existence of the given resource in the given servlet context

Parameters:
servletContext -
sResourcePath - the path to the resource, it must begin with a "/"
and is interpreted as relative to the context root.
NB : The path is case sensitive
Returns:
true if the resource exists
Since:
1.0.5