opendap.util
Class EscapeStrings

java.lang.Object
  extended by opendap.util.EscapeStrings

public class EscapeStrings
extends java.lang.Object

User: ndp Date: Jul 7, 2006 Time: 10:23:19 AM


Constructor Summary
EscapeStrings()
           
 
Method Summary
static java.lang.String escapeString(java.lang.String in, char[] allowable, char esc)
          Replace all characters in the String in not present in the String allowable with their hexidecimal values (encoded as ASCII) and preceeded by the String esc

The esc character may not appear on the allowable list, as if it did it would break the 1:1 and onto mapping between the unescaped character space and the escaped characater space.

static java.lang.String id2www_ce(java.lang.String in)
          Replace characters that are not allowed in WWW URLs using rules specific to Constraint Expressions.
static java.lang.String id2www(java.lang.String in)
          Replace characters that are not allowed in DAP2 identifiers.
static void main(java.lang.String[] args)
           
static java.lang.String normalizeToXML(java.lang.String s)
          This method is used to normalize strings prior to their inclusion in XML documents.
static java.lang.String unescapeString(java.lang.String in, char escape, java.lang.String except)
          Given a string that contains WWW escape sequences, translate those escape sequences back into ASCII characters.
static java.lang.String www2ce(java.lang.String in)
          Given a string that contains WWW escape sequences, translate those escape sequences back into ASCII characters, with the exception of the escaped space (0x20) character which appears as "%20".
static java.lang.String www2id(java.lang.String in)
          Given a string that contains WWW escape sequences, translate those escape sequences back into ASCII characters.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

EscapeStrings

public EscapeStrings()
Method Detail

normalizeToXML

public static java.lang.String normalizeToXML(java.lang.String s)
This method is used to normalize strings prior to their inclusion in XML documents. XML has certain parsing requirements around reserved characters. These reserved characters must be replaced with symbols recognized by the XML parser as place holder for the actual symbol.

The rule for this normalization is as follows:

Parameters:
s - The String to be normalized.
Returns:
The normalized String.

id2www_ce

public static java.lang.String id2www_ce(java.lang.String in)
Replace characters that are not allowed in WWW URLs using rules specific to Constraint Expressions. This has canged over time and now the only differences are:
  • '*' is escaped by this function while it is not escaped by id2www().
  • ',' is not escaped by this function and it is by id2www
  • The set of characters that are allowed in a CE are: "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-+_/.\"; All other characters will replaced with their hexidecimal value preceeded by the "%" character. Thus a space, " ", character will be represented in the returned string as "%20".

    Parameters:
    in - The string in which to replace characters.
    Returns:
    The modified identifier.

    escapeString

    public static java.lang.String escapeString(java.lang.String in,
                                                char[] allowable,
                                                char esc)
                                         throws java.lang.Exception
    Replace all characters in the String in not present in the String allowable with their hexidecimal values (encoded as ASCII) and preceeded by the String esc

    The esc character may not appear on the allowable list, as if it did it would break the 1:1 and onto mapping between the unescaped character space and the escaped characater space.

    Parameters:
    in - The string in which to replace characters.
    allowable - The set of allowable characters.
    esc - The escape String (typically "%" for a URI or "\" for a regular expression).
    Returns:
    The modified identifier.
    Throws:
    java.lang.Exception

    id2www

    public static java.lang.String id2www(java.lang.String in)
    Replace characters that are not allowed in DAP2 identifiers. The set of characters that are allowed in a URI are: "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-+_/.\*"; All other characters will replaced with their hexidecimal value preceeded by the "%" character. Thus a space, " ", character will be represented in the returned string as "%20".

    Parameters:
    in - The string in which to replace characters.
    Returns:
    The modified identifier.

    unescapeString

    public static java.lang.String unescapeString(java.lang.String in,
                                                  char escape,
                                                  java.lang.String except)
    Given a string that contains WWW escape sequences, translate those escape sequences back into ASCII characters. Return the modified string.

    Parameters:
    in - The string to modify.
    escape - The character used to signal the begining of an escape sequence.
    except - If there is some escape code that should not be removed by this call (e.g., you might not want to remove spaces, %20) use this parameter to specify that code. The function will then transform all escapes except that one.
    Returns:
    The modified string.

    www2id

    public static java.lang.String www2id(java.lang.String in)
    Given a string that contains WWW escape sequences, translate those escape sequences back into ASCII characters. Escape sequences are indicted by a leading "%" character followed by 2 characters indicating the hexidecimal value of the character that was escaped.

    Parameters:
    in - The string to modify.
    Returns:
    The modified string.

    www2ce

    public static java.lang.String www2ce(java.lang.String in)
    Given a string that contains WWW escape sequences, translate those escape sequences back into ASCII characters, with the exception of the escaped space (0x20) character which appears as "%20". THe Constraint Expression Parser will break if there are spaces in the CE. Escape sequences are indicted by a leading "%" character followed by 2 characters indicating the hexidecimal value of the character that was escaped.

    Parameters:
    in - The string to modify.
    Returns:
    The modified string.

    main

    public static void main(java.lang.String[] args)
                     throws java.lang.Exception
    Throws:
    java.lang.Exception