com.ideo.sweetdevria.util
Class URLUtils

java.lang.Object
  extended by com.ideo.sweetdevria.util.URLUtils

public class URLUtils
extends java.lang.Object


Constructor Summary
URLUtils()
           
 
Method Summary
static java.lang.String addParamToUrl(java.lang.String url, java.lang.String paramName, java.lang.Object paramValue)
          Add a GET parameter to the url.
static java.lang.String addParamToUrl(java.lang.String url, java.lang.String paramName, java.lang.String paramValue)
           
static java.lang.String concatUrlWithSlaches(java.lang.String firstPart, java.lang.String secondPart)
          Concat two part of an url into one.
static java.lang.String encodeParams(java.lang.String params)
          prepare params and transform them into URL GET params
static java.net.URL formatAjaxUrl(javax.servlet.http.HttpServletRequest request, java.lang.String url, java.lang.String pageId)
          Builds an URL object from the url sent
static java.net.URL formatAjaxUrlForServer(javax.servlet.http.HttpServletRequest request, java.lang.String url, java.lang.String pageId)
          FIX : Portlet compatibility.
static java.net.URL formatUrl(java.lang.String url, javax.servlet.http.HttpServletRequest request, java.lang.String pageId)
          Build an url corresponding to the string.
static java.net.URL formatUrlForServer(java.lang.String url, javax.servlet.http.HttpServletRequest request, java.lang.String pageId)
          FIX : Portlet compatibility.
static java.io.InputStream getFileContent(java.net.URL url, java.lang.String sessionId)
          Open an input stream to the specified URL.
static java.lang.String getFileFromUrl(java.lang.String url)
           
static java.lang.String getPathFromUrl(java.net.URL url, javax.servlet.http.HttpServletRequest request)
          SWTRIA-971 Extract from an url the path relative to the context of the reference request.
static java.lang.String getServerContext(javax.servlet.http.HttpServletRequest request)
          return Server port
static java.lang.String getServerName(javax.servlet.http.HttpServletRequest request)
          return Server Name
static java.lang.String getServerPort(javax.servlet.http.HttpServletRequest request)
          return Server port
static java.lang.String getServerScheme(javax.servlet.http.HttpServletRequest request)
          return Server Scheme
static java.lang.String getURLContent(java.net.URL url, javax.servlet.http.HttpServletRequest request, java.lang.String inputs)
          Return the content of an url
static boolean isAdressLocal(java.net.URL url, javax.servlet.http.HttpServletRequest request)
          SWTRIA-971 Test if the url is local in the conext of the referent request.
static void propagateCookies(javax.servlet.http.HttpServletRequest request, java.net.URLConnection connection)
          Propagate the whole informations transmitted into the request cookie
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

URLUtils

public URLUtils()
Method Detail

getFileContent

public static java.io.InputStream getFileContent(java.net.URL url,
                                                 java.lang.String sessionId)
                                          throws java.io.IOException
Open an input stream to the specified URL. Suffix the URL with the JSESSION ID if specified.

Parameters:
url - URL link to the file
sessionId - Session ID to specify in the URL (could be null).
Returns:
An opened Input stream (should be closed).
Throws:
java.io.IOException

getURLContent

public static java.lang.String getURLContent(java.net.URL url,
                                             javax.servlet.http.HttpServletRequest request,
                                             java.lang.String inputs)
                                      throws java.io.IOException
Return the content of an url

Parameters:
url - the url to call
request - the original request processing the url demand
Returns:
a String containing the call result
Throws:
java.io.IOException

formatAjaxUrl

public static java.net.URL formatAjaxUrl(javax.servlet.http.HttpServletRequest request,
                                         java.lang.String url,
                                         java.lang.String pageId)
                                  throws java.net.MalformedURLException
Builds an URL object from the url sent

Parameters:
request -
url - the url to format
pageId - used to propagate the current page configuration, and use the statefull zones
Returns:
an URL formatted from a request coming from a SweetDEV RIA Ajax call
Throws:
java.net.MalformedURLException

formatAjaxUrlForServer

public static java.net.URL formatAjaxUrlForServer(javax.servlet.http.HttpServletRequest request,
                                                  java.lang.String url,
                                                  java.lang.String pageId)
                                           throws java.net.MalformedURLException
FIX : Portlet compatibility. This function is used by RIA Component which load URL content from server. Builds an URL object from the url sent. IMPORTANT : this URL should be used by the server.

Parameters:
request -
url - the url to format
pageId - used to propagate the current page configuration, and use the statefull zones
Returns:
an URL formatted from a request coming from a SweetDEV RIA Ajax call
Throws:
java.net.MalformedURLException

formatUrl

public static java.net.URL formatUrl(java.lang.String url,
                                     javax.servlet.http.HttpServletRequest request,
                                     java.lang.String pageId)
                              throws java.net.MalformedURLException
Build an url corresponding to the string. Convert either absolutes urls (http://...) , absolutes ones (/mypage...) or relatives ones (url).

Parameters:
url - the url to build
pageId - used to propagate the current page configuration, and use the statefull zones
Returns:
a full URL corresponding to the string given in parameter
Throws:
java.net.MalformedURLException

formatUrlForServer

public static java.net.URL formatUrlForServer(java.lang.String url,
                                              javax.servlet.http.HttpServletRequest request,
                                              java.lang.String pageId)
                                       throws java.net.MalformedURLException
FIX : Portlet compatibility. This function is used by RIA Component which load URL content from server. Build an url corresponding to the string. Convert either absolutes urls (http://...) , absolutes ones (/mypage...) or relatives ones (url). IMPORTANT : this URL should be used by the server.

Parameters:
url - the url to build
pageId - used to propagate the current page configuration, and use the statefull zones
Returns:
a full URL corresponding to the string given in parameter
Throws:
java.net.MalformedURLException

getServerScheme

public static java.lang.String getServerScheme(javax.servlet.http.HttpServletRequest request)
return Server Scheme

Parameters:
request -
Returns:

getServerName

public static java.lang.String getServerName(javax.servlet.http.HttpServletRequest request)
return Server Name

Parameters:
request -
Returns:

getServerPort

public static java.lang.String getServerPort(javax.servlet.http.HttpServletRequest request)
return Server port

Parameters:
request -
Returns:

getServerContext

public static java.lang.String getServerContext(javax.servlet.http.HttpServletRequest request)
return Server port

Parameters:
request -
Returns:

propagateCookies

public static void propagateCookies(javax.servlet.http.HttpServletRequest request,
                                    java.net.URLConnection connection)
Propagate the whole informations transmitted into the request cookie

Parameters:
request - the request given in parameter.
connection - the connection that will propagate the cookies
Throws:
{@link - IllegalStateException}

isAdressLocal

public static boolean isAdressLocal(java.net.URL url,
                                    javax.servlet.http.HttpServletRequest request)
                             throws java.net.MalformedURLException
SWTRIA-971 Test if the url is local in the conext of the referent request.

Parameters:
url - the Url from which the path will be extracted
request - Reference request
Returns:
'true' is the url is local, else 'false'.
Throws:
java.net.MalformedURLException

getPathFromUrl

public static java.lang.String getPathFromUrl(java.net.URL url,
                                              javax.servlet.http.HttpServletRequest request)
                                       throws java.net.MalformedURLException
SWTRIA-971 Extract from an url the path relative to the context of the reference request. If the url is no local (@see isAdressLocal(URL url, HttpServletRequest request)) then returns null.

Parameters:
url - the Url from which the path will be extracted
request - Reference request
Returns:
the relative path
Throws:
java.net.MalformedURLException

getFileFromUrl

public static java.lang.String getFileFromUrl(java.lang.String url)
Parameters:
url -
Returns:

encodeParams

public static java.lang.String encodeParams(java.lang.String params)
prepare params and transform them into URL GET params

Parameters:
params -
Returns:

concatUrlWithSlaches

public static java.lang.String concatUrlWithSlaches(java.lang.String firstPart,
                                                    java.lang.String secondPart)
Concat two part of an url into one. Check that this two part are separated with "/". Check that there no double "/" separating the two part

Parameters:
firstPart -
secondPart -
Returns:

addParamToUrl

public static java.lang.String addParamToUrl(java.lang.String url,
                                             java.lang.String paramName,
                                             java.lang.Object paramValue)
Add a GET parameter to the url. Check if parameters already exists. This function do not encode paramName or paramValue. This has to been done before if necessary.

addParamToUrl

public static java.lang.String addParamToUrl(java.lang.String url,
                                             java.lang.String paramName,
                                             java.lang.String paramValue)
Parameters:
propertyName -
Returns:


Copyright © 2010 Ideo Technologies. All Rights Reserved.