com.atlassian.gadgets.util
Class Uri

java.lang.Object
  extended by com.atlassian.gadgets.util.Uri

public class Uri
extends Object

Utility class for dealing with URIs.


Method Summary
static URI create(String gadgetUri)
          Attempts to convert the gadgetUri to a URI object.
static String decodeUriComponent(String uriComponent)
          Returns the decoded part of the URI.
static String encodeUriComponent(String uriComponent)
          Returns the encoded part of the URI.
static String ensureTrailingSlash(String url)
          Returns a "/"-terminated String.
static boolean isValid(String gadgetUri)
          Returns true if the gadget URI is a valid URI and begins with http:// or https://, false otherwise.
static URI resolveUriAgainstBase(String baseUrl, String possiblyRelativeUri)
          Resolves a possibly relative URI (in String form) against a specified base.
static URI resolveUriAgainstBase(String baseUrl, URI possiblyRelativeUri)
          Resolves a possibly relative URI against a specified base.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

decodeUriComponent

public static String decodeUriComponent(String uriComponent)
Returns the decoded part of the URI. Always uses UTF-8 encoding which is required for all JVMs to support and so doesn't require you to catch an UnsupportedEncodingException.

Parameters:
uriComponent - part of the URI to decode
Returns:
the decoded part of the URI

encodeUriComponent

public static String encodeUriComponent(String uriComponent)
Returns the encoded part of the URI. Always uses UTF-8 encoding which is required for all JVMs to support and so doesn't require you to catch an UnsupportedEncodingException.

Parameters:
uriComponent - part of the URI to encode
Returns:
the encoded part of the URI

isValid

public static boolean isValid(String gadgetUri)
Returns true if the gadget URI is a valid URI and begins with http:// or https://, false otherwise.

Parameters:
gadgetUri - URI to validate
Returns:
true if the gadget URI is a valid URI and begins with http:// or https://, false otherwise.

create

public static URI create(String gadgetUri)
                  throws GadgetSpecUriNotAllowedException
Attempts to convert the gadgetUri to a URI object. If the URI is an invalid URI or does not begin with http:// or https://, throws an InvalidGadgetSpecUriException.

Parameters:
gadgetUri - value to be converted to a URI object
Returns:
gadgetUri converted to a URI object
Throws:
GadgetSpecUriNotAllowedException - thrown if the value is not a valid URI or does not start with http:// or https://

ensureTrailingSlash

public static String ensureTrailingSlash(String url)
Returns a "/"-terminated String.

Parameters:
url - the URL to be "/"-terminated.
Returns:
a "/"-terminated representing the URL

resolveUriAgainstBase

public static URI resolveUriAgainstBase(String baseUrl,
                                        URI possiblyRelativeUri)
Resolves a possibly relative URI against a specified base. Resolution occurs according to the rules defined in java.net.URI.resolve(java.net.URI).

Parameters:
baseUrl - the base URI to resolve against
possiblyRelativeUri - the relative URI to be resolved. If this is already absolute, it will not be resolved against the base
Returns:
the resolved URI

resolveUriAgainstBase

public static URI resolveUriAgainstBase(String baseUrl,
                                        String possiblyRelativeUri)
Resolves a possibly relative URI (in String form) against a specified base. Resolution occurs according to the rules defined in java.net.URI.resolve(java.net.URI).

Parameters:
baseUrl - the base URI to resolve against
possiblyRelativeUri - the relative URI to be resolved. If this is already absolute, it will not be resolved against the base
Returns:
the resolved URI


Copyright © 2010 Atlassian. All Rights Reserved.