com.google.api.client.http
Class GenericUrl

java.lang.Object
  extended by java.util.AbstractMap<String,Object>
      extended by com.google.api.client.util.GenericData
          extended by com.google.api.client.http.GenericUrl
All Implemented Interfaces:
Cloneable, Map<String,Object>
Direct Known Subclasses:
AbstractAuthorizationRequestUrl, AbstractOAuthGetToken, AuthSubSingleUseTokenRequestUrl, AuthSubSingleUseTokenRequestUrl.ResponseUrl, GoogleUrl, OAuthAuthorizeTemporaryTokenUrl, OAuthCallbackUrl

public class GenericUrl
extends GenericData

URL builder in which the query parameters are specified as generic data key/value pairs, based on the specification RFC 3986: Uniform Resource Identifier (URI).

The query parameters are specified with the data key name as the parameter name, and the data value as the parameter value. Subclasses can declare fields for known query parameters using the Key annotation. null parameter names are not allowed, but null query values are allowed.

Query parameter values are parsed using UrlEncodedParser.parse(String, Object).

Warning of an incompatibility for upgrading from version 2.2 of gdata-java-client library: repeated query parameters were not supported in that version, and therefore unknown query parameters (not from declared fields) were parsed as a single String. However, in version 1.0 of this library they are parsed as ArrayList<String>. Use getFirst(String) to get the first value.

Since:
1.0
Author:
Yaniv Inbar

Nested Class Summary
 
Nested classes/interfaces inherited from class java.util.AbstractMap
AbstractMap.SimpleEntry<K,V>, AbstractMap.SimpleImmutableEntry<K,V>
 
Nested classes/interfaces inherited from interface java.util.Map
Map.Entry<K,V>
 
Field Summary
 String fragment
          Fragment component or null for none.
 String host
          Host, for example "www.google.com".
 String path
          Deprecated. (scheduled to be removed in version 1.1) Use pathParts for encoded path support, or for unencoded paths use getRawPath(), setRawPath(String rawPath), or appendRawPath(String) which
 List<String> pathParts
          Decoded path component by parts with each part separated by a '/' or null for none, for example "/m8/feeds/contacts/default/full" is represented by "", "m8", "feeds", "contacts", "default", "full".
 int port
          Port number or -1 if undefined, for example 443.
 String scheme
          Scheme (lowercase), for example "https".
 
Fields inherited from class com.google.api.client.util.GenericData
unknownFields
 
Constructor Summary
GenericUrl()
           
GenericUrl(String encodedUrl)
          Constructs from an encoded URL.
 
Method Summary
 void appendRawPath(String encodedPath)
          Appends the given raw encoded path to the current pathParts, setting field only if it is null or empty.
 String build()
          Constructs the string representation of the URL, including the path specified by path and the query parameters specified by this generic URL.
 GenericUrl clone()
           
 boolean equals(Object obj)
           
 Collection<Object> getAll(String name)
          Returns all query parameter values for the given query parameter name.
 Object getFirst(String name)
          Returns the first query parameter value for the given query parameter name.
 String getRawPath()
          Returns the raw encoded path computed from the pathParts.
 int hashCode()
           
 void setRawPath(String encodedPath)
          Sets the pathParts from the given raw encoded path.
static List<String> toPathParts(String encodedPath)
          Returns the decoded path parts for the given encoded path.
 String toString()
           
 
Methods inherited from class com.google.api.client.util.GenericData
entrySet, get, put, putAll, remove, set, size
 
Methods inherited from class java.util.AbstractMap
clear, containsKey, containsValue, isEmpty, keySet, values
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

scheme

public String scheme
Scheme (lowercase), for example "https".


host

public String host
Host, for example "www.google.com".


port

public int port
Port number or -1 if undefined, for example 443.


path

@Deprecated
public String path
Deprecated. (scheduled to be removed in version 1.1) Use pathParts for encoded path support, or for unencoded paths use getRawPath(), setRawPath(String rawPath), or appendRawPath(String) which
Unencoded path component or null for none, for example "/m8/feeds/contacts/default/full".

This field is ignored if pathParts is not null.


pathParts

public List<String> pathParts
Decoded path component by parts with each part separated by a '/' or null for none, for example "/m8/feeds/contacts/default/full" is represented by "", "m8", "feeds", "contacts", "default", "full".

Use appendRawPath(String) to append to the path, which ensures that no extra slash is added.


fragment

public String fragment
Fragment component or null for none.

Constructor Detail

GenericUrl

public GenericUrl()

GenericUrl

public GenericUrl(String encodedUrl)
Constructs from an encoded URL.

Any known query parameters with pre-defined fields as data keys will be parsed based on their data type. Any unrecognized query parameter will always be parsed as a string.

Parameters:
encodedUrl - encoded URL, including any existing query parameters that should be parsed
Throws:
IllegalArgumentException - if URL has a syntax error
Method Detail

hashCode

public int hashCode()
Specified by:
hashCode in interface Map<String,Object>
Overrides:
hashCode in class AbstractMap<String,Object>

equals

public boolean equals(Object obj)
Specified by:
equals in interface Map<String,Object>
Overrides:
equals in class AbstractMap<String,Object>

toString

public String toString()
Overrides:
toString in class AbstractMap<String,Object>

clone

public GenericUrl clone()
Overrides:
clone in class GenericData

build

public final String build()
Constructs the string representation of the URL, including the path specified by path and the query parameters specified by this generic URL.


getFirst

public Object getFirst(String name)
Returns the first query parameter value for the given query parameter name.

Parameters:
name - query parameter name
Returns:
first query parameter value

getAll

public Collection<Object> getAll(String name)
Returns all query parameter values for the given query parameter name.

Parameters:
name - query parameter name
Returns:
unmodifiable collection of query parameter values (possibly empty)

getRawPath

public String getRawPath()
Returns the raw encoded path computed from the pathParts.

Returns:
raw encoded path computed from the pathParts or null if pathParts is null

setRawPath

public void setRawPath(String encodedPath)
Sets the pathParts from the given raw encoded path.

Parameters:
encodedPath - raw encoded path or null to set pathParts to null

appendRawPath

public void appendRawPath(String encodedPath)
Appends the given raw encoded path to the current pathParts, setting field only if it is null or empty.

The last part of the pathParts is merged with the first part of the path parts computed from the given encoded path. Thus, if the current raw encoded path is "a", and the given encoded path is "b", then the resulting raw encoded path is "ab".

Parameters:
encodedPath - raw encoded path or null to ignore

toPathParts

public static List<String> toPathParts(String encodedPath)
Returns the decoded path parts for the given encoded path.

Parameters:
encodedPath - slash-prefixed encoded path, for example "/m8/feeds/contacts/default/full"
Returns:
decoded path parts, with each part assumed to be preceded by a '/', for example "", "m8", "feeds", "contacts", "default", "full", or null for null or "" input


Copyright © 2010 Google. All Rights Reserved.