org.mitre.midiki.workshop
Class UrlConverter

java.lang.Object
  |
  +--org.mitre.midiki.workshop.UrlConverter

public class UrlConverter
extends java.lang.Object

Translation class to encode/decode URLs. Allows queries to be sent via HTTP GET within the URL itself, and subsequently decoded by the query processor. Shamelessly ported from JavaScript at http://www.blooberry.com/indexdot/html/topics/urlencoding.htm.

Since:
1.0

Field Summary
protected static char[] hexVals
          Hexadecimal digits.
protected static java.lang.String unsafeAnywhereString
          Graphic characters which must always be converted inside a URL.
protected static java.lang.String unsafeLocationString
          Graphic characters which must be encoded if they are to appear in the URL without thier usual syntactic implications.
 
Constructor Summary
UrlConverter()
           
 
Method Summary
 java.lang.String convert(char val)
          Converts a character into a hexadecimal URL escape sequence.
 java.lang.String decode(java.lang.String val)
          Decodes an encoded URL string.
 java.lang.String decToHex(int num, int radix)
          Converts an integer into a hexadecimal (or smaller radix) string.
 java.lang.String encode(java.lang.String val)
          Encodes a string into a safe URL location.
 boolean isUnsafe(char compareChar)
          Returns true if the specified character is unsafe anywhere.
 boolean isUnsafeLocation(char compareChar)
          Returns true if the specified character is unsafe in the location, and you don't want it to have the standard meaning.
static void main(java.lang.String[] args)
           
 java.lang.String reversal(java.lang.String s)
          Reverses the string.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

hexVals

protected static char[] hexVals
Hexadecimal digits.

unsafeAnywhereString

protected static java.lang.String unsafeAnywhereString
Graphic characters which must always be converted inside a URL.

unsafeLocationString

protected static java.lang.String unsafeLocationString
Graphic characters which must be encoded if they are to appear in the URL without thier usual syntactic implications.
Constructor Detail

UrlConverter

public UrlConverter()
Method Detail

isUnsafe

public boolean isUnsafe(char compareChar)
Returns true if the specified character is unsafe anywhere.
Parameters:
compareChar - a char value
Returns:
a boolean value

isUnsafeLocation

public boolean isUnsafeLocation(char compareChar)
Returns true if the specified character is unsafe in the location, and you don't want it to have the standard meaning.
Parameters:
compareChar - a char value
Returns:
a boolean value

decToHex

public java.lang.String decToHex(int num,
                                 int radix)
Converts an integer into a hexadecimal (or smaller radix) string.
Parameters:
num - an int value
radix - an int value
Returns:
a String value

reversal

public java.lang.String reversal(java.lang.String s)
Reverses the string.
Parameters:
s - a String value
Returns:
a String value

convert

public java.lang.String convert(char val)
Converts a character into a hexadecimal URL escape sequence.
Parameters:
val - a char value
Returns:
a String value

encode

public java.lang.String encode(java.lang.String val)
Encodes a string into a safe URL location.
Parameters:
val - a String value
Returns:
a String value

decode

public java.lang.String decode(java.lang.String val)
Decodes an encoded URL string.
Parameters:
val - a String value
Returns:
a String value

main

public static void main(java.lang.String[] args)