Java Code Examples for com.ibm.icu.text.StringPrepParseException#DOMAIN_NAME_TOO_LONG_ERROR

The following examples show how to use com.ibm.icu.text.StringPrepParseException#DOMAIN_NAME_TOO_LONG_ERROR . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: fitnotifications   File: IDNA2003.java    License: Apache License 2.0 5 votes vote down vote up
public static StringBuffer convertIDNToASCII(String src,int options)
        throws StringPrepParseException{

    char[] srcArr = src.toCharArray();
    StringBuffer result = new StringBuffer();
    int sepIndex=0;
    int oldSepIndex=0;
    for(;;){
        sepIndex = getSeparatorIndex(srcArr,sepIndex,srcArr.length);
        String label = new String(srcArr,oldSepIndex,sepIndex-oldSepIndex);
        //make sure this is not a root label separator.
        if(!(label.length()==0 && sepIndex==srcArr.length)){
            UCharacterIterator iter = UCharacterIterator.getInstance(label);
            result.append(convertToASCII(iter,options));
        }
        if(sepIndex==srcArr.length){
            break;
        }
        
        // increment the sepIndex to skip past the separator
        sepIndex++;
        oldSepIndex = sepIndex;
        result.append((char)FULL_STOP);
    }
    if(result.length() > MAX_DOMAIN_NAME_LENGTH){
        throw new StringPrepParseException("The output exceed the max allowed length.", StringPrepParseException.DOMAIN_NAME_TOO_LONG_ERROR);
    }
    return result;
}
 
Example 2
Source Project: fitnotifications   File: IDNA2003.java    License: Apache License 2.0 5 votes vote down vote up
public static StringBuffer convertIDNToUnicode(String src, int options)
        throws StringPrepParseException{
    
    char[] srcArr = src.toCharArray();
    StringBuffer result = new StringBuffer();
    int sepIndex=0;
    int oldSepIndex=0;
    for(;;){
        sepIndex = getSeparatorIndex(srcArr,sepIndex,srcArr.length);
        String label = new String(srcArr,oldSepIndex,sepIndex-oldSepIndex);
        if(label.length()==0 && sepIndex!=srcArr.length ){
            throw new StringPrepParseException("Found zero length lable after NamePrep.",StringPrepParseException.ZERO_LENGTH_LABEL);
        }
        UCharacterIterator iter = UCharacterIterator.getInstance(label);
        result.append(convertToUnicode(iter,options));
        if(sepIndex==srcArr.length){
            break;
        }
        // Unlike the ToASCII operation we don't normalize the label separators
        result.append(srcArr[sepIndex]);
        // increment the sepIndex to skip past the separator
        sepIndex++;
        oldSepIndex =sepIndex;
    }
    if(result.length() > MAX_DOMAIN_NAME_LENGTH){
        throw new StringPrepParseException("The output exceed the max allowed length.", StringPrepParseException.DOMAIN_NAME_TOO_LONG_ERROR);
    }
    return result;
}
 
Example 3
Source Project: trekarta   File: IDNA2003.java    License: GNU General Public License v3.0 5 votes vote down vote up
public static StringBuffer convertIDNToASCII(String src,int options)
        throws StringPrepParseException{

    char[] srcArr = src.toCharArray();
    StringBuffer result = new StringBuffer();
    int sepIndex=0;
    int oldSepIndex=0;
    for(;;){
        sepIndex = getSeparatorIndex(srcArr,sepIndex,srcArr.length);
        String label = new String(srcArr,oldSepIndex,sepIndex-oldSepIndex);
        //make sure this is not a root label separator.
        if(!(label.length()==0 && sepIndex==srcArr.length)){
            UCharacterIterator iter = UCharacterIterator.getInstance(label);
            result.append(convertToASCII(iter,options));
        }
        if(sepIndex==srcArr.length){
            break;
        }
        
        // increment the sepIndex to skip past the separator
        sepIndex++;
        oldSepIndex = sepIndex;
        result.append((char)FULL_STOP);
    }
    if(result.length() > MAX_DOMAIN_NAME_LENGTH){
        throw new StringPrepParseException("The output exceed the max allowed length.", StringPrepParseException.DOMAIN_NAME_TOO_LONG_ERROR);
    }
    return result;
}
 
Example 4
Source Project: trekarta   File: IDNA2003.java    License: GNU General Public License v3.0 5 votes vote down vote up
public static StringBuffer convertIDNToUnicode(String src, int options)
        throws StringPrepParseException{
    
    char[] srcArr = src.toCharArray();
    StringBuffer result = new StringBuffer();
    int sepIndex=0;
    int oldSepIndex=0;
    for(;;){
        sepIndex = getSeparatorIndex(srcArr,sepIndex,srcArr.length);
        String label = new String(srcArr,oldSepIndex,sepIndex-oldSepIndex);
        if(label.length()==0 && sepIndex!=srcArr.length ){
            throw new StringPrepParseException("Found zero length lable after NamePrep.",StringPrepParseException.ZERO_LENGTH_LABEL);
        }
        UCharacterIterator iter = UCharacterIterator.getInstance(label);
        result.append(convertToUnicode(iter,options));
        if(sepIndex==srcArr.length){
            break;
        }
        // Unlike the ToASCII operation we don't normalize the label separators
        result.append(srcArr[sepIndex]);
        // increment the sepIndex to skip past the separator
        sepIndex++;
        oldSepIndex =sepIndex;
    }
    if(result.length() > MAX_DOMAIN_NAME_LENGTH){
        throw new StringPrepParseException("The output exceed the max allowed length.", StringPrepParseException.DOMAIN_NAME_TOO_LONG_ERROR);
    }
    return result;
}