com.zeevbelkin.commons
Class UrlUtils

java.lang.Object
  extended by com.zeevbelkin.commons.UrlUtils

public class UrlUtils
extends java.lang.Object

Author:
Zeev (Vladimir) Belkin

Constructor Summary
UrlUtils()
           
 
Method Summary
static java.lang.String addParamtsToUrl(java.lang.String u, java.lang.String params)
          This method appends a given URL with name/value parameter pairs.
static java.lang.String getParamFromQuery(java.lang.String params, java.lang.String name)
          retrieves a value of parameter with a given name from an ampersand separated string
static java.lang.String getParamFromUrl(java.lang.String u, java.lang.String name)
          retrieves a parameter with a given name from an URL
static java.lang.String getRootUrl(java.lang.String u)
          returns, for any HTTP(s) URL, the URL that points to the site ROOT
static java.lang.String setParamInUrl(java.lang.String u, java.lang.String name, java.lang.String value)
          This method sets a parameter with a given name in an URL.
 
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

getRootUrl

public static java.lang.String getRootUrl(java.lang.String u)
returns, for any HTTP(s) URL, the URL that points to the site ROOT

Parameters:
u - any HTTP(s) URL
Returns:
the site root URL

addParamtsToUrl

public static java.lang.String addParamtsToUrl(java.lang.String u,
                                               java.lang.String params)
This method appends a given URL with name/value parameter pairs.

Parameters:
u - the initial URL
params - a string that contains the parameter value pairs in format name1=value1&name2=value ...
Returns:
an URL with the given additional parameters

setParamInUrl

public static java.lang.String setParamInUrl(java.lang.String u,
                                             java.lang.String name,
                                             java.lang.String value)
This method sets a parameter with a given name in an URL. If the initial URL already contains the parameter with the given name this parameter value will be updated. If there are several parameters with the given name, only one updated pair will be left.

Parameters:
name - the name of parameter to append or override
value - the value of parameter to set
u - an initial URL
Returns:
an updated URL

getParamFromUrl

public static java.lang.String getParamFromUrl(java.lang.String u,
                                               java.lang.String name)
retrieves a parameter with a given name from an URL

Parameters:
u - given URL
name - the parameter name

getParamFromQuery

public static java.lang.String getParamFromQuery(java.lang.String params,
                                                 java.lang.String name)
retrieves a value of parameter with a given name from an ampersand separated string

Parameters:
params - ampersand separated string
name - a parameter name to get the value
Returns:
the parameter value if any or null otherwise