org.apache.clerezza.triaxrs.util
Class UriHelper

java.lang.Object
  extended by org.apache.clerezza.triaxrs.util.UriHelper

public class UriHelper
extends Object

Various methods for URI/URL manipulation.


Method Summary
static String appendAltToPath(String uri, javax.ws.rs.core.MediaType mediaType)
          Append an alt parameter to an uri.
static String appendPathToBaseUri(String baseUri, String path)
          Appends a path a baseUri.
static String appendQueryParamsToPath(String uri, Map<String,String[]> queryParams, boolean escapeKeyParam)
          The method appends query parameters to path
static String contructUri(String scheme, String userInfo, String host, int port, String path, String query, String fragment)
          Constructs a string with URI in unescaped form.
static String getNameFromPath(String uri)
          Get the last section of the path.
static String getQueryParamsStr(Map<String,String[]> queryParams, boolean escapeKeyParam)
          The method builds the query parameters String e.g.
static String getQueryString(String requestUri)
          Get query string.
static List<String> hidePassword(List<String> urls)
          Hides password from all the urls in the list.
static String hidePassword(String url)
          Hide password from the URL.
static String hidePassword(URI url)
          Hide password from the URL.
static String normalize(String uri)
          Normalize input uri according to href="http://www.ietf.org/rfc/rfc3986.txt">RFC 3986 section 6.2.2.
static List<javax.ws.rs.core.PathSegment> parsePath(String path)
          Parses a uri path into a list of PathSegements
static javax.ws.rs.core.MultivaluedMap<String,String> parseQuery(String queryStr)
          Parses a query string (without the leading '?') into a map of parameters and values
static String relativize(String basePath, String pathToRelativize)
          Relativize URI path.
static String removeStartSlash(String s)
           
static String removeTrailingSlash(String uri)
          Normalize URI: The last character in URI is NOT '/'
static String stripName(String requestUri)
          Strip name (last section in the path).
static String stripQueryString(String requestUri)
          Remove parameters for the url
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

removeTrailingSlash

public static String removeTrailingSlash(String uri)
Normalize URI:

Parameters:
uri - input URI
Returns:
normalized URI

stripQueryString

public static String stripQueryString(String requestUri)
Remove parameters for the url

Parameters:
requestUri - input URI
Returns:
input URI without query string

getQueryString

public static String getQueryString(String requestUri)
Get query string.

Parameters:
requestUri - input URI
Returns:
query string from input URI

stripName

public static String stripName(String requestUri)
Strip name (last section in the path).

Parameters:
requestUri - input URI
Returns:
part of URI after the last slash

getNameFromPath

public static String getNameFromPath(String uri)
Get the last section of the path.

Parameters:
uri - URI.
Returns:
name.

hidePassword

public static String hidePassword(URI url)
Hide password from the URL.

Parameters:
url - the URL to hide the password from
Returns:
URL with user information removed

hidePassword

public static String hidePassword(String url)
Hide password from the URL.

Parameters:
url - the URL to hide the password from
Returns:
URL with user information removed

hidePassword

public static List<String> hidePassword(List<String> urls)
Hides password from all the urls in the list.

Parameters:
urls - the list of urls to hide the password from
Returns:
URL with user information removed

relativize

public static String relativize(String basePath,
                                String pathToRelativize)
Relativize URI path. Can add ".." and "." segments.

Parameters:
basePath - relative against this path
pathToRelativize - path to change
Returns:
a relativized path

removeStartSlash

public static String removeStartSlash(String s)
Parameters:
s - a non-null string
Returns:
s value with optional first character '/' removed

appendPathToBaseUri

public static String appendPathToBaseUri(String baseUri,
                                         String path)
Appends a path a baseUri.

Parameters:
baseUri - the base uri, can but needn't to end with a '/', not null
path - path append, can but needn't to start with a '/'
Returns:
a string with path appended path-wise correctly to the path

appendAltToPath

public static String appendAltToPath(String uri,
                                     javax.ws.rs.core.MediaType mediaType)
Append an alt parameter to an uri.

Parameters:
uri - an uri without any parameters, not null
mediaType - the value of the alt parameter, not null
Returns:
string containing an uri, media type is uri-encoded

contructUri

public static String contructUri(String scheme,
                                 String userInfo,
                                 String host,
                                 int port,
                                 String path,
                                 String query,
                                 String fragment)
Constructs a string with URI in unescaped form. Use as woraround with unencoding/double encoding problems with URI constructor, new Uri(constructUri(...)).toASCIIString() should be the original URI.

Parameters:
scheme - URI.getScheme
userInfo - URI.getRawUserInfo
host - URI.getRawHost
port - URI.getPort; -1 = no port
path - URI.getRawPath
query - URI.getRawQuery
fragment - URI.getRawFragment
Returns:
URI with reserved characters escaped

getQueryParamsStr

public static String getQueryParamsStr(Map<String,String[]> queryParams,
                                       boolean escapeKeyParam)
The method builds the query parameters String e.g. param1=value1¶m2=value2

Parameters:
queryParams - Map of query parameters
escapeKeyParam - indicates if to escape the parameter's name and value
Returns:
String the query parameters String

appendQueryParamsToPath

public static String appendQueryParamsToPath(String uri,
                                             Map<String,String[]> queryParams,
                                             boolean escapeKeyParam)
The method appends query parameters to path

Parameters:
uri -
queryParams - Map of query parameters
escapeKeyParam - indicates if to escape the parameter's name and value
Returns:
String the path with query parameters

parsePath

public static List<javax.ws.rs.core.PathSegment> parsePath(String path)
Parses a uri path into a list of PathSegements

Parameters:
path - the path to parse
Returns:
list of PathSegement instances

parseQuery

public static javax.ws.rs.core.MultivaluedMap<String,String> parseQuery(String queryStr)
Parses a query string (without the leading '?') into a map of parameters and values

Parameters:
queryStr - the query strin to parse
Returns:
a map of query parameters and values

normalize

public static String normalize(String uri)
Normalize input uri according to href="http://www.ietf.org/rfc/rfc3986.txt">RFC 3986 section 6.2.2. - Syntax-Based Normalization

Parameters:
string -
Returns:
normalized instance of uri


Copyright © 2012 The Apache Software Foundation. All Rights Reserved.