net.rim.device.api.io
Class IDNA

java.lang.Object
  extended by net.rim.device.api.io.IDNA

public class IDNA
extends Object

This class provides methods to encode and decode host names as per the IDNA algorithm defined in RFC3490. This method provides implementations of the ToASCII and ToUnicode operations defined in RFC3490, as well as a few convenience methods to more simply use the class.

Since:
BlackBerry API 5.0.0

Field Summary
static String ACE_PREFIX
          The ASCII Compatible Encoding (ACE) prefix.
 
Method Summary
static boolean checkNonASCII(String input)
          Tests if the provided input string has non-ASCII code point.
static String toASCII(String host)
          This method performs the ToASCII operation on the provided hostname string.
static String toASCII(String input, boolean allowUnassigned, boolean useSTD3ASCIIRules)
          The ToASCII operation takes a sequence of Unicode code points that make up one label and transforms it into a sequence of code points in the ASCII range (0..7F).
static String toUnicode(String host)
          This method performs the ToUnicode operation on the provided IDNA-encoded hostname string.
static String toUnicode(String input, boolean allowUnassigned, boolean useSTD3ASCIIRules)
          The ToUnicode operation takes a sequence of Unicode code points that make up one label and returns a sequence of Unicode code points.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 



Field Detail

ACE_PREFIX

public static final String ACE_PREFIX
The ASCII Compatible Encoding (ACE) prefix. This is the literal string "xn--" as defined in RFC3490.

See Also:
Constant Field Values
Since:
BlackBerry API 5.0.0


Method Detail

toASCII

public static String toASCII(String host)
                      throws IDNAException
This method performs the ToASCII operation on the provided hostname string. Each label in the hostname string has the ToASCII operation applied to it separately, and the label is then replaced with the results of the operation.

Parameters:
host - The hostname to be IDNA-encoded. This must not be null.
Returns:
The IDNA-encoded hostname. This will not be null.
Throws:
IDNAException - If the ToASCII operation fails as described in RFC3490.
NullPointerException - If the host parameter is null.
Since:
BlackBerry API 5.0.0

toUnicode

public static String toUnicode(String host)
This method performs the ToUnicode operation on the provided IDNA-encoded hostname string. Each label has the ToUnicode operation applied to it separately, and the label is then replaced with the results of the operation.

Parameters:
host - The IDNA-encoded hostname. This must not be null.
Returns:
The unicode hostname. This will not be null.
Throws:
NullPointerException - If the host parameter is null.
Since:
BlackBerry API 5.0.0

checkNonASCII

public static boolean checkNonASCII(String input)
Tests if the provided input string has non-ASCII code point.

Parameters:
input - The string to check for non-ASCII code points. This must not be null.
Returns:
true if any of the code point in input are greater than or equal to U+0080, falseotherwise.
Throws:
NullPointerException - If input is null.
Since:
BlackBerry API 5.0.0

toASCII

public static String toASCII(String input,
                             boolean allowUnassigned,
                             boolean useSTD3ASCIIRules)
                      throws IDNAException
The ToASCII operation takes a sequence of Unicode code points that make up one label and transforms it into a sequence of code points in the ASCII range (0..7F). If ToASCII succeeds, the original sequence and the resulting sequence are equivalent labels. It is important to note that the ToASCII operation can fail. ToASCII fails if any step of it fails. If any step of the ToASCII operation fails on any label in a domain name, that domain name MUST NOT be used as an internationalized domain name. The method for dealing with this failure is application-specific. The inputs to ToASCII are a sequence of code points, the AllowUnassigned flag, and the UseSTD3ASCIIRules flag. The output of ToASCII is either a sequence of ASCII code points or a failure condition. ToASCII never alters a sequence of code points that are all in the ASCII range to begin with (although it could fail). Applying the ToASCII operation multiple times has exactly the same effect as applying it just once.

Parameters:
input - The label on which to perform the ToASCII operation. This must not be null.
allowUnassigned - The AllowUnassigned input flag to the ToASCII operation.
useSTD3ASCIIRules - The UseSTD3ASCIIRules input flag to the ToASCII operation.
Returns:
a String that has only ASCII code points. This will not be null.
Throws:
IDNAException - If the ToASCII operation fails.
NullPointerException - If the input parameter is null.
Since:
BlackBerry API 5.0.0

toUnicode

public static String toUnicode(String input,
                               boolean allowUnassigned,
                               boolean useSTD3ASCIIRules)
The ToUnicode operation takes a sequence of Unicode code points that make up one label and returns a sequence of Unicode code points. If the input sequence is a label in ACE form, then the result is an equivalent internationalized label that is not in ACE form, otherwise the original sequence is returned unaltered. ToUnicode never fails. If any step fails, then the original input sequence is returned immediately in that step. The ToUnicode output never contains more code points than its input. Note that the number of octets needed to represent a sequence of code points depends on the particular character encoding used. The inputs to ToUnicode are a sequence of code points, the AllowUnassigned flag, and the UseSTD3ASCIIRules flag. The output of ToUnicode is always a sequence of Unicode code points.

Parameters:
input - The label on which to perform the ToUnicode operation. This must not be null.
allowUnassigned - The AllowUnassigned input flag to the ToUnicode operation.
useSTD3ASCIIRules - The UseSTD3ASCIIRules input flag to the ToUnicode operation.
Returns:
the internationalized label. This will not be null.
Throws:
NullPointerException - If the input parameter is null.
Since:
BlackBerry API 5.0.0





Copyright 1999-2010 Research In Motion Limited. 295 Phillip Street, Waterloo, Ontario, Canada, N2L 3W8. All Rights Reserved.
Copyright 1993-2003 Sun Microsystems, Inc. 901 San Antonio Road, Palo Alto, California, 94303, U.S.A. All Rights Reserved.
Copyright 2002-2003 Nokia Corporation All Rights Reserved.
Java is a trademark of Sun Microsystems, Inc.