org.opengts.util
Class URIArg

java.lang.Object
  extended by org.opengts.util.URIArg

public class URIArg
extends java.lang.Object

URI argument wrapper


Nested Class Summary
protected  class URIArg.KeyVal
          A URI argument key/value pair
 
Constructor Summary
URIArg(java.lang.String uri)
          Constructor
URIArg(java.lang.String uri, boolean unique)
          Constructor
URIArg(java.lang.StringBuffer reqURL, java.lang.String query)
          Constructor
URIArg(URIArg uriArg)
          Copy Constructor
 
Method Summary
protected  URIArg _addArg(java.lang.String key, java.lang.String value, boolean encode, boolean obfuscate)
          Adds an argument to the URI
static java.lang.String _des64(java.lang.String e)
          Descrambles String
static java.lang.String _ens64(java.lang.String d)
          Scrambles String
protected  void _setURI(java.lang.String uri)
           
 URIArg addArg(java.lang.String key, double value)
          Adds an argument to the URI
 URIArg addArg(java.lang.String key, int value)
          Adds an argument to the URI
 URIArg addArg(java.lang.String key, long value)
          Adds an argument to the URI
 URIArg addArg(java.lang.String key, RTProperties rtp)
          Adds an argument to the URI
 URIArg addArg(java.lang.String key, java.lang.String value)
          Adds an argument to the URI
 URIArg addArg(java.lang.String key, java.lang.String value, boolean obfuscate)
          Adds an argument to the URI
protected  URIArg addArg(URIArg.KeyVal keyVal)
          Adds an argument to the URI
 void addExtension(java.lang.String ext)
          Adds a file extension to the end of this URI, ".xml" etc.
static java.lang.StringBuffer decodeArg(java.lang.StringBuffer sb, java.lang.String s)
          Decodes the specified hex-encoded argument (not yet fully tested)
static java.lang.String encodeArg(java.lang.String s)
          Hex-encodes a URL argument (if required)
static java.lang.StringBuffer encodeArg(java.lang.StringBuffer sb, java.lang.String s)
          Hex-encodes a URL argument (if required)
static java.lang.StringBuffer encodeArg(java.lang.StringBuffer sb, java.lang.String s, boolean obfuscateAll)
          Hex-encodes a URL argument
static java.lang.String encodeRTP(RTProperties rtp)
          RTP encodes an argument
 java.util.List<java.lang.String> getArgNames()
          Gets a list of all the argument key names
 RTProperties getArgProperties()
          Gets args as RTProperties instance
 java.lang.String getArgString()
          Returns a String representation of all key/values
 java.lang.StringBuffer getArgString(java.lang.StringBuffer sbuff)
          Returns a String representation of all key/values
 java.lang.StringBuffer getArgString(java.lang.StringBuffer sbuff, boolean includeBlankValues)
          Returns a String representation of all key/values
 java.lang.String getArgValue(java.lang.String key)
          Gets the first occuring value of the specified key
 java.lang.String getArgValue(java.lang.String[] keys)
          Gets the first occuring value of the specified key
 java.lang.String getFile()
          Gets the 'file' specification in the URI
 java.lang.String getHost()
          Gets the 'host' specification in the URI
protected  URIArg.KeyVal getKeyVal(java.lang.String key)
          Gets the first occuring KeyVal of the specified key
protected  URIArg.KeyVal getKeyVal(java.lang.String[] keys)
          Gets the first occuring KeyVal of the specified key
protected  java.util.Collection<URIArg.KeyVal> getKeyValList()
          Gets all the argument key/value pairs as a list of KeyVal>s
protected  OrderedMap<java.lang.String,URIArg.KeyVal> getKeyValMap()
          Gets an OrderedMap of the argument key/value pairs indexed by their keys
 int getPort()
          Gets the 'port' specification in the URI
 java.lang.String getProtocol()
          Gets the 'protocol' specification in the URI
 java.lang.String getURI()
          Gets the URI (without arguments)
 boolean hasArg(java.lang.String key)
          Return true if this URI contains the specified key
 boolean hasArg(java.lang.String[] key)
          Return true if this URI contains one of the specified keys
 boolean hasUniqueKeys()
          Gets the 'Unique Arg' attribute
static boolean isAbsoluteURL(java.lang.String url)
          Returns true if the URL starts with a protocol definition (ie.
static void main(java.lang.String[] argv)
          Main entry point for testing/debugging
static java.lang.String obfuscateArg(java.lang.String s)
          Obfuscates (hex-encodes) all characters in the String
static RTProperties parseRTP(java.lang.String rtpArg)
          Decodes an RTP encoded argument
 URIArg removeArg(java.lang.String key)
          Removes all occurances of the specified key from the URI
 URIArg removeArg(java.lang.String[] keys)
          Removes all occurances of the specified keys from the URI
 URIArg removeBlankValues()
          Removes all arguments which have blank values
 URIArg rtpDecode(java.lang.String rtpKey)
          Returns a new URIArg with this URIArg's arguments decoded from a single RTProperties added a specified key [CHECK]
 URIArg rtpEncode(java.lang.String rtpKey, java.lang.String... exclKeys)
          Returns a new URIArg with this URIArg's arguments encoded into a single RTProperties added with a specified key [CHECK]
 boolean setArgValue(java.lang.String[] key, int value)
          Sets the specified argument key to the specified int value.
 boolean setArgValue(java.lang.String[] key, java.lang.String value)
          Sets the specified argument key to the specified String value.
 boolean setArgValue(java.lang.String[] key, java.lang.String value, boolean obfuscate)
          Sets the specified argument key to the specified String value.
 boolean setArgValue(java.lang.String key, int value)
          Sets the specified argument key to the specified int value.
 boolean setArgValue(java.lang.String key, java.lang.String value)
          Sets the specified argument key to the specified String value.
 boolean setArgValue(java.lang.String key, java.lang.String value, boolean obfuscate)
          Sets the specified argument key to the specified String value.
 boolean setHost(java.lang.String _host)
          Sets the 'host'
protected  void setKeys(java.util.Collection<URIArg.KeyVal> k)
          Sets the argument keys in this URI
 boolean setPort(int _port)
          Sets the 'port'
 boolean setProtocol(java.lang.String _proto)
          Sets the 'protocol'
 void setUniqueKeys(boolean unique)
          Sets the 'Unique Arg' attribute
 void setURI(java.lang.String uri)
          Sets the URI from a string
 java.lang.String toString()
          A String reperesentation of this URI (with arguments)
 java.lang.String toString(boolean includeBlankValues)
          A String reperesentation of this URI (with arguments)
 java.net.URL toURL()
          Returns this URI as a new URL
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

URIArg

public URIArg(URIArg uriArg)
Copy Constructor


URIArg

public URIArg(java.lang.String uri,
              boolean unique)
Constructor

Parameters:
uri - The URI

URIArg

public URIArg(java.lang.String uri)
Constructor

Parameters:
uri - The URI

URIArg

public URIArg(java.lang.StringBuffer reqURL,
              java.lang.String query)
Constructor

Parameters:
reqURL - The URL (typically from "request.getRequestURL()")
query - The request query string (typically from "request.getQueryString()")
Method Detail

_des64

public static java.lang.String _des64(java.lang.String e)
Descrambles String


_ens64

public static java.lang.String _ens64(java.lang.String d)
Scrambles String


parseRTP

public static RTProperties parseRTP(java.lang.String rtpArg)
Decodes an RTP encoded argument


encodeRTP

public static java.lang.String encodeRTP(RTProperties rtp)
RTP encodes an argument


encodeArg

public static java.lang.String encodeArg(java.lang.String s)
Hex-encodes a URL argument (if required)

Parameters:
s - The URL argument to encode (if required)
Returns:
The hex encoded argument

encodeArg

public static java.lang.StringBuffer encodeArg(java.lang.StringBuffer sb,
                                               java.lang.String s)
Hex-encodes a URL argument (if required)

Parameters:
sb - The StringBuffer where the hex encoded String argument will be placed
s - The URL argument to encode (if required)
Returns:
The StringBuffer where the hex-encoded String will be placed

encodeArg

public static java.lang.StringBuffer encodeArg(java.lang.StringBuffer sb,
                                               java.lang.String s,
                                               boolean obfuscateAll)
Hex-encodes a URL argument

Parameters:
sb - The StringBuffer where the hex encoded String argument will be placed
s - The URL argument to encode
obfuscateAll - True to force hex-encoding on all argument characters
Returns:
The StringBuffer where the hex-encoded String will be placed

obfuscateArg

public static java.lang.String obfuscateArg(java.lang.String s)
Obfuscates (hex-encodes) all characters in the String

Parameters:
s - The String to hex-encode
Returns:
The hex-encoded String

decodeArg

public static java.lang.StringBuffer decodeArg(java.lang.StringBuffer sb,
                                               java.lang.String s)
Decodes the specified hex-encoded argument (not yet fully tested)

Parameters:
sb - The StringBuffer where the decoded String argument will be placed
s - The String to decode
Returns:
The StringBuffer where the decoded String will be placed

isAbsoluteURL

public static boolean isAbsoluteURL(java.lang.String url)
Returns true if the URL starts with a protocol definition (ie. "http://...")

Parameters:
url - The URL to test
Returns:
True if the URL starts with a protocol definition

setUniqueKeys

public void setUniqueKeys(boolean unique)
Sets the 'Unique Arg' attribute

Parameters:
unique - True to set unique args

hasUniqueKeys

public boolean hasUniqueKeys()
Gets the 'Unique Arg' attribute

Returns:
True if this instance retains only unique arguments

setURI

public void setURI(java.lang.String uri)
Sets the URI from a string


_setURI

protected void _setURI(java.lang.String uri)

getURI

public java.lang.String getURI()
Gets the URI (without arguments)

Returns:
The URI

addExtension

public void addExtension(java.lang.String ext)
Adds a file extension to the end of this URI, ".xml" etc. The extension will be added to the URI if doesn't already end with it

Parameters:
ext - The extension to add

setKeys

protected void setKeys(java.util.Collection<URIArg.KeyVal> k)
Sets the argument keys in this URI

Parameters:
k - The argument keys

getKeyValList

protected java.util.Collection<URIArg.KeyVal> getKeyValList()
Gets all the argument key/value pairs as a list of KeyVal>s

Returns:
The list of argument key/value pairs

getKeyValMap

protected OrderedMap<java.lang.String,URIArg.KeyVal> getKeyValMap()
Gets an OrderedMap of the argument key/value pairs indexed by their keys

Returns:
An OrderedMap of the argument key/value pairs

getArgNames

public java.util.List<java.lang.String> getArgNames()
Gets a list of all the argument key names

Returns:
a list of all the argument key names

addArg

public URIArg addArg(java.lang.String key,
                     double value)
Adds an argument to the URI

Parameters:
key - The key name of the argument to add
value - The value of the new key
Returns:
This URIArg, with the argument added

addArg

public URIArg addArg(java.lang.String key,
                     int value)
Adds an argument to the URI

Parameters:
key - The key name of the argument to add
value - The value of the new key
Returns:
This URIArg, with the argument added

addArg

public URIArg addArg(java.lang.String key,
                     long value)
Adds an argument to the URI

Parameters:
key - The key name of the argument to add
value - The value of the new key
Returns:
This URIArg, with the argument added

addArg

public URIArg addArg(java.lang.String key,
                     RTProperties rtp)
Adds an argument to the URI

Parameters:
key - The key name of the argument to add
rtp - The RTP encoded values of the new key
Returns:
This URIArg, with the argument added

addArg

public URIArg addArg(java.lang.String key,
                     java.lang.String value)
Adds an argument to the URI

Parameters:
key - The key name of the argument to add
value - The value of the new key
Returns:
This URIArg, with the argument added

addArg

public URIArg addArg(java.lang.String key,
                     java.lang.String value,
                     boolean obfuscate)
Adds an argument to the URI

Parameters:
key - The key name of the argument to add
value - The value of the new key
obfuscate - True if value should be obfuscated
Returns:
This URIArg, with the argument added

_addArg

protected URIArg _addArg(java.lang.String key,
                         java.lang.String value,
                         boolean encode,
                         boolean obfuscate)
Adds an argument to the URI

Parameters:
key - The key name of the argument to add
value - The value of the new key
encode - True if value shoudl be hex encoded
obfuscate - True if value should be obfuscated
Returns:
This URIArg, with the argument added

addArg

protected URIArg addArg(URIArg.KeyVal keyVal)
Adds an argument to the URI

Parameters:
keyVal - The key/value pair to add
Returns:
This URIArg, with the argument added

removeArg

public URIArg removeArg(java.lang.String key)
Removes all occurances of the specified key from the URI

Parameters:
key - The key to remove
Returns:
This URIArg, with the argument added

removeArg

public URIArg removeArg(java.lang.String[] keys)
Removes all occurances of the specified keys from the URI

Parameters:
keys - The key list to remove
Returns:
This URIArg, with the argument added

removeBlankValues

public URIArg removeBlankValues()
Removes all arguments which have blank values

Returns:
This URIArg

hasArg

public boolean hasArg(java.lang.String key)
Return true if this URI contains the specified key

Returns:
True if this URI contains the specified key

hasArg

public boolean hasArg(java.lang.String[] key)
Return true if this URI contains one of the specified keys

Returns:
True if this URI contains one of the specified keys

setArgValue

public boolean setArgValue(java.lang.String key,
                           int value)
Sets the specified argument key to the specified int value.

Parameters:
key - The agrument key
value - The value to set
Returns:
True if the argument exists, else false

setArgValue

public boolean setArgValue(java.lang.String key,
                           java.lang.String value)
Sets the specified argument key to the specified String value.

Parameters:
key - The key of the agrument
value - The value to set
Returns:
True if the argument existed, else false

setArgValue

public boolean setArgValue(java.lang.String key,
                           java.lang.String value,
                           boolean obfuscate)
Sets the specified argument key to the specified String value.

Parameters:
key - The key of the agrument
value - The value to set
obfuscate - True if the value should be obfuscated
Returns:
True if the argument existed, else false

setArgValue

public boolean setArgValue(java.lang.String[] key,
                           int value)
Sets the specified argument key to the specified int value.

Parameters:
key - The agrument key
value - The value to set
Returns:
True if the argument exists, else false

setArgValue

public boolean setArgValue(java.lang.String[] key,
                           java.lang.String value)
Sets the specified argument key to the specified String value.

Parameters:
key - The key of the agrument
value - The value to set
Returns:
True if the argument existed, else false

setArgValue

public boolean setArgValue(java.lang.String[] key,
                           java.lang.String value,
                           boolean obfuscate)
Sets the specified argument key to the specified String value.

Parameters:
key - The key of the agrument
value - The value to set
obfuscate - True if the value should be obfuscated
Returns:
True if the argument existed, else false

getKeyVal

protected URIArg.KeyVal getKeyVal(java.lang.String key)
Gets the first occuring KeyVal of the specified key

Parameters:
key - The key to get
Returns:
The KeyVal associated with key, if any

getKeyVal

protected URIArg.KeyVal getKeyVal(java.lang.String[] keys)
Gets the first occuring KeyVal of the specified key

Parameters:
keys - The key to get
Returns:
The KeyVal associated with key, if any

getArgValue

public java.lang.String getArgValue(java.lang.String key)
Gets the first occuring value of the specified key

Parameters:
key - The key to get
Returns:
The value associated with key, if any

getArgValue

public java.lang.String getArgValue(java.lang.String[] keys)
Gets the first occuring value of the specified key

Parameters:
keys - The key list used to check for the returned value
Returns:
The value associated with key, if any

getArgString

public java.lang.String getArgString()
Returns a String representation of all key/values

Returns:
A String representation of all key/values

getArgString

public java.lang.StringBuffer getArgString(java.lang.StringBuffer sbuff)
Returns a String representation of all key/values

Parameters:
sbuff - The StringBuffer to write the key/values to, or null for a new one
Returns:
A String representation of all key/values

getArgString

public java.lang.StringBuffer getArgString(java.lang.StringBuffer sbuff,
                                           boolean includeBlankValues)
Returns a String representation of all key/values

Parameters:
sbuff - The StringBuffer to write the key/values to, or null for a new one
includeBlankValues - True to include keys for blank values.
Returns:
A String representation of all key/values

getArgProperties

public RTProperties getArgProperties()
Gets args as RTProperties instance

Returns:
A new RTProperties instance with this URIArg's key value pairs

toString

public java.lang.String toString()
A String reperesentation of this URI (with arguments)

Overrides:
toString in class java.lang.Object
Returns:
A String representation of this URI

toString

public java.lang.String toString(boolean includeBlankValues)
A String reperesentation of this URI (with arguments)

Parameters:
includeBlankValues - True to include keys for blank values.
Returns:
A String representation of this URI

rtpEncode

public URIArg rtpEncode(java.lang.String rtpKey,
                        java.lang.String... exclKeys)
Returns a new URIArg with this URIArg's arguments encoded into a single RTProperties added with a specified key [CHECK]

Parameters:
rtpKey - The key to add the encoded args at
exclKeys - keys to exclude from encoding
Returns:
A new URIArg with non excluded arguments encoded

rtpDecode

public URIArg rtpDecode(java.lang.String rtpKey)
Returns a new URIArg with this URIArg's arguments decoded from a single RTProperties added a specified key [CHECK]

Parameters:
rtpKey - The key of the RTProperties to decode the encoded args from
Returns:
A new URIArg with non excluded arguments encoded

toURL

public java.net.URL toURL()
                   throws java.net.MalformedURLException
Returns this URI as a new URL

Returns:
A URL representing this URI
Throws:
java.net.MalformedURLException

getProtocol

public java.lang.String getProtocol()
Gets the 'protocol' specification in the URI

Returns:
The 'protocol' specification in the URL, or null if unable to determine protocol

setProtocol

public boolean setProtocol(java.lang.String _proto)
Sets the 'protocol'


getHost

public java.lang.String getHost()
Gets the 'host' specification in the URI

Returns:
The 'host' specification in the URL, or null if unable to determine host

setHost

public boolean setHost(java.lang.String _host)
Sets the 'host'


getPort

public int getPort()
Gets the 'port' specification in the URI

Returns:
The 'port' specification in the URL, or -1 if not port is specified

setPort

public boolean setPort(int _port)
Sets the 'port'


getFile

public java.lang.String getFile()
Gets the 'file' specification in the URI

Returns:
The 'file' specification in the URL, or null if unable to determine file

main

public static void main(java.lang.String[] argv)
Main entry point for testing/debugging

Parameters:
argv - Comand-line arguments