org.semwebcentral.sweetrules.util
Class URIEncode

java.lang.Object
  extended byorg.semwebcentral.sweetrules.util.URIEncode

public class URIEncode
extends java.lang.Object

Provides static methods to encode URIs into simple tokens that can be used as predicates in CommonRules.

Example

http://xmlcontracting.org/pr.daml#hasException(co123,e12);
would be encoded as:
_uri_http://xmlcontracting.org/pr.daml_8hasException(co123,e12);
Caveats:

See Also:
RFC 2396

Field Summary
private static char[] buf
           
private static int BUF_LENGTH
           
private static java.lang.String ENCODE_PREFIX
           
private static char ESCAPE_CHAR
           
private static char[] ESCAPED_CHARS
           
private static char[] NEED_ESCAPE_CHARS
           
private static java.lang.String URI_PROTOCOL_PREFIX
           
private static java.lang.String USAGE
           
 
Constructor Summary
URIEncode()
           
 
Method Summary
private static boolean charInArray(char c, char[] arr)
           
static java.lang.String decodeRules(java.lang.String clpRules)
          Decodes all the encoded URIs found in the input rules.
static java.lang.String decodeURI(java.lang.String encodedURI)
          Decodes the given encoded URI
static java.lang.String encodeRules(java.lang.String clpRules)
          Encodes all the URIs found in the input rules.
static java.lang.String encodeURI(java.lang.String uri)
          Encodes the given URI
private static char escapedChar(char c)
           
static boolean isEncodedURI(java.lang.String token)
          Returns true if the given token is an encoded URI, false otherwise.
static boolean isURI(java.lang.String token)
          Returns true if the given token is an unencoded URI, false otherwise.
private static boolean isURIChar(char c)
           
static void main(java.lang.String[] args)
          A command line interface for running URIEncode.
private static boolean needEscape(char c)
           
static void test()
           
private static void testEncodeRules(java.lang.String text)
           
private static void testEncodeURI(java.lang.String uri)
           
private static char unescapedChar(char c)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

URI_PROTOCOL_PREFIX

private static final java.lang.String URI_PROTOCOL_PREFIX
See Also:
Constant Field Values

ENCODE_PREFIX

private static final java.lang.String ENCODE_PREFIX
See Also:
Constant Field Values

ESCAPE_CHAR

private static final char ESCAPE_CHAR
See Also:
Constant Field Values

NEED_ESCAPE_CHARS

private static final char[] NEED_ESCAPE_CHARS

ESCAPED_CHARS

private static final char[] ESCAPED_CHARS

USAGE

private static final java.lang.String USAGE
See Also:
Constant Field Values

BUF_LENGTH

private static final int BUF_LENGTH
See Also:
Constant Field Values

buf

private static char[] buf
Constructor Detail

URIEncode

public URIEncode()
Method Detail

encodeRules

public static java.lang.String encodeRules(java.lang.String clpRules)
Encodes all the URIs found in the input rules.

Returns:
a string where all the URIs have been encoded

decodeRules

public static java.lang.String decodeRules(java.lang.String clpRules)
Decodes all the encoded URIs found in the input rules.

Returns:
a string where all the URIs have been decoded

encodeURI

public static java.lang.String encodeURI(java.lang.String uri)
Encodes the given URI


decodeURI

public static java.lang.String decodeURI(java.lang.String encodedURI)
Decodes the given encoded URI


isURI

public static boolean isURI(java.lang.String token)
Returns true if the given token is an unencoded URI, false otherwise. This tries to create a java.net.URI object and if there is no URISyntaxException then it returns true.

Parameters:
token - The token which should be checked to see if it is a URI
Returns:
true if a java.net.URI can be constructed from the token

isEncodedURI

public static boolean isEncodedURI(java.lang.String token)
Returns true if the given token is an encoded URI, false otherwise.


isURIChar

private static boolean isURIChar(char c)

needEscape

private static boolean needEscape(char c)

escapedChar

private static char escapedChar(char c)

unescapedChar

private static char unescapedChar(char c)

charInArray

private static boolean charInArray(char c,
                                   char[] arr)

testEncodeRules

private static void testEncodeRules(java.lang.String text)

testEncodeURI

private static void testEncodeURI(java.lang.String uri)

test

public static void test()

main

public static void main(java.lang.String[] args)
                 throws java.io.IOException
A command line interface for running URIEncode.

 Encoding/decoding: java sweet.deal.URIEncode [-e|-d] <input_file> <output_file>
 Diagnostic tests: java sweet.deal.URIEncode -test
 

Throws:
java.io.IOException