@Test public void testUnescapeValueHexaWrong() { try { Rdn.unescapeValue( "#fF1" ); fail(); } catch ( IllegalArgumentException iae ) { assertTrue( true ); } }
public static Object unescapeValue( String value ) { if ( Strings.isEmpty( value ) ) { return ""; } char[] chars = value.toCharArray(); if ( ( chars[0] == '\"' ) && ( chars[chars.length - 1] == '\"' ) ) { return new String( chars, 1, chars.length - 2 ); } if ( chars[0] == '#' ) { if ( chars.length == 1 ) { return Strings.EMPTY_BYTES; } if ( ( chars.length % 2 ) != 1 ) { throw new IllegalArgumentException( I18n.err( I18n.ERR_13613_VALUE_NOT_IN_HEX_FORM_ODD_NUMBER ) ); } byte[] hexValue = new byte[( chars.length - 1 ) / 2]; int pos = 0; for ( int i = 1; i < chars.length; i += 2 ) { if ( Chars.isHex( chars, i ) && Chars.isHex( chars, i + 1 ) ) { hexValue[pos++] = Hex.getHexValue( chars[i], chars[i + 1] ); } else { throw new IllegalArgumentException( I18n.err( I18n.ERR_13614_VALUE_NOT_IN_HEX_FORM ) ); } } return hexValue; } else { boolean escaped = false; boolean isHex = false; byte pair = -1; int pos = 0; byte[] bytes = new byte[chars.length * 6]; for ( int i = 0; i < chars.length; i++ ) { if ( escaped ) { escaped = false; switch ( chars[i] ) { case '\\': case '"': case '+': case ',': case ';': case '<': case '>': case '#': case '=': case ' ': bytes[pos++] = ( byte ) chars[i]; break; default: if ( Chars.isHex( chars, i ) ) { isHex = true; pair = ( byte ) ( Hex.getHexValue( chars[i] ) << 4 ); } break; } } else { if ( isHex ) { if ( Chars.isHex( chars, i ) ) { pair += Hex.getHexValue( chars[i] ); bytes[pos++] = pair; isHex = false; pair = 0; } } else { switch ( chars[i] ) { case '\\': escaped = true; break; case '"': case '+': case ',': case ';': case '<': case '>': case '#': if ( i != 0 ) { bytes[pos++] = '#'; } break; case ' ': if ( ( i == 0 ) || ( i == chars.length - 1 ) ) { throw new IllegalArgumentException( I18n.err( I18n.ERR_13615_UNESCAPED_CHARS_NOT_ALLOWED ) ); } else { bytes[pos++] = ' '; break; } default: if ( chars[i] < 128 ) { bytes[pos++] = ( byte ) chars[i]; } else { byte[] result = Unicode.charToBytes( chars[i] ); System.arraycopy( result, 0, bytes, pos, result.length ); pos += result.length; } break; } } } } return Strings.utf8ToString( bytes, pos ); } }
Rdn implements Cloneable, Externalizable, Iterable<Ava>, Comparable<Rdn> { public static Object unescapeValue( String value ) { if ( Strings.isEmpty( value ) ) { return ""; } char[] chars = value.toCharArray(); if ( ( chars[0] == '\"' ) && ( chars[chars.length - 1] == '\"' ) ) { return new String( chars, 1, chars.length - 2 ); } if ( chars[0] == '#' ) { if ( chars.length == 1 ) { return Strings.EMPTY_BYTES; } if ( ( chars.length % 2 ) != 1 ) { throw new IllegalArgumentException( I18n.err( I18n.ERR_13613_VALUE_NOT_IN_HEX_FORM_ODD_NUMBER ) ); } byte[] hexValue = new byte[( chars.length - 1 ) / 2]; int pos = 0; for ( int i = 1; i < chars.length; i += 2 ) { if ( Chars.isHex( chars, i ) && Chars.isHex( chars, i + 1 ) ) { hexValue[pos++] = Hex.getHexValue( chars[i], chars[i + 1] ); } else { throw new IllegalArgumentException( I18n.err( I18n.ERR_13614_VALUE_NOT_IN_HEX_FORM ) ); } } return hexValue; } else { boolean escaped = false; boolean isHex = false; byte pair = -1; int pos = 0; byte[] bytes = new byte[chars.length * 6]; for ( int i = 0; i < chars.length; i++ ) { if ( escaped ) { escaped = false; switch ( chars[i] ) { case '\\': case '"': case '+': case ',': case ';': case '<': case '>': case '#': case '=': case ' ': bytes[pos++] = ( byte ) chars[i]; break; default: if ( Chars.isHex( chars, i ) ) { isHex = true; pair = ( byte ) ( Hex.getHexValue( chars[i] ) << 4 ); } break; } } else { if ( isHex ) { if ( Chars.isHex( chars, i ) ) { pair += Hex.getHexValue( chars[i] ); bytes[pos++] = pair; isHex = false; pair = 0; } } else { switch ( chars[i] ) { case '\\': escaped = true; break; case '"': case '+': case ',': case ';': case '<': case '>': case '#': if ( i != 0 ) { bytes[pos++] = '#'; } break; case ' ': if ( ( i == 0 ) || ( i == chars.length - 1 ) ) { throw new IllegalArgumentException( I18n.err( I18n.ERR_13615_UNESCAPED_CHARS_NOT_ALLOWED ) ); } else { bytes[pos++] = ' '; break; } default: if ( chars[i] < 128 ) { bytes[pos++] = ( byte ) chars[i]; } else { byte[] result = Unicode.charToBytes( chars[i] ); System.arraycopy( result, 0, bytes, pos, result.length ); pos += result.length; } break; } } } } return Strings.utf8ToString( bytes, pos ); } } }
Rdn implements Cloneable, Externalizable, Iterable<Ava>, Comparable<Rdn> { public static Object unescapeValue( String value ) { if ( Strings.isEmpty( value ) ) { return ""; } char[] chars = value.toCharArray(); if ( ( chars[0] == '\"' ) && ( chars[chars.length - 1] == '\"' ) ) { return new String( chars, 1, chars.length - 2 ); } if ( chars[0] == '#' ) { if ( chars.length == 1 ) { return Strings.EMPTY_BYTES; } if ( ( chars.length % 2 ) != 1 ) { throw new IllegalArgumentException( I18n.err( I18n.ERR_13613_VALUE_NOT_IN_HEX_FORM_ODD_NUMBER ) ); } byte[] hexValue = new byte[( chars.length - 1 ) / 2]; int pos = 0; for ( int i = 1; i < chars.length; i += 2 ) { if ( Chars.isHex( chars, i ) && Chars.isHex( chars, i + 1 ) ) { hexValue[pos++] = Hex.getHexValue( chars[i], chars[i + 1] ); } else { throw new IllegalArgumentException( I18n.err( I18n.ERR_13614_VALUE_NOT_IN_HEX_FORM ) ); } } return hexValue; } else { boolean escaped = false; boolean isHex = false; byte pair = -1; int pos = 0; byte[] bytes = new byte[chars.length * 6]; for ( int i = 0; i < chars.length; i++ ) { if ( escaped ) { escaped = false; switch ( chars[i] ) { case '\\': case '"': case '+': case ',': case ';': case '<': case '>': case '#': case '=': case ' ': bytes[pos++] = ( byte ) chars[i]; break; default: if ( Chars.isHex( chars, i ) ) { isHex = true; pair = ( byte ) ( Hex.getHexValue( chars[i] ) << 4 ); } break; } } else { if ( isHex ) { if ( Chars.isHex( chars, i ) ) { pair += Hex.getHexValue( chars[i] ); bytes[pos++] = pair; isHex = false; pair = 0; } } else { switch ( chars[i] ) { case '\\': escaped = true; break; case '"': case '+': case ',': case ';': case '<': case '>': case '#': if ( i != 0 ) { bytes[pos++] = '#'; } break; case ' ': if ( ( i == 0 ) || ( i == chars.length - 1 ) ) { throw new IllegalArgumentException( I18n.err( I18n.ERR_13615_UNESCAPED_CHARS_NOT_ALLOWED ) ); } else { bytes[pos++] = ' '; break; } default: if ( chars[i] < 128 ) { bytes[pos++] = ( byte ) chars[i]; } else { byte[] result = Unicode.charToBytes( chars[i] ); System.arraycopy( result, 0, bytes, pos, result.length ); pos += result.length; } break; } } } } return Strings.utf8ToString( bytes, pos ); } } Rdn();  Rdn( SchemaManager schemaManager );  Rdn( SchemaManager schemaManager, String rdn );  Rdn( String rdn );  Rdn( SchemaManager schemaManager, String upType, String upValue );  Rdn( String upType, String upValue );  Rdn( SchemaManager schemaManager, Ava... avas );  Rdn( Ava... avas );  Rdn( Rdn rdn );  Rdn( SchemaManager schemaManager, Rdn rdn ); }
Rdn implements Cloneable, Externalizable, Iterable<Ava>, Comparable<Rdn> { public static Object unescapeValue( String value ) { if ( Strings.isEmpty( value ) ) { return ""; } char[] chars = value.toCharArray(); if ( ( chars[0] == '\"' ) && ( chars[chars.length - 1] == '\"' ) ) { return new String( chars, 1, chars.length - 2 ); } if ( chars[0] == '#' ) { if ( chars.length == 1 ) { return Strings.EMPTY_BYTES; } if ( ( chars.length % 2 ) != 1 ) { throw new IllegalArgumentException( I18n.err( I18n.ERR_13613_VALUE_NOT_IN_HEX_FORM_ODD_NUMBER ) ); } byte[] hexValue = new byte[( chars.length - 1 ) / 2]; int pos = 0; for ( int i = 1; i < chars.length; i += 2 ) { if ( Chars.isHex( chars, i ) && Chars.isHex( chars, i + 1 ) ) { hexValue[pos++] = Hex.getHexValue( chars[i], chars[i + 1] ); } else { throw new IllegalArgumentException( I18n.err( I18n.ERR_13614_VALUE_NOT_IN_HEX_FORM ) ); } } return hexValue; } else { boolean escaped = false; boolean isHex = false; byte pair = -1; int pos = 0; byte[] bytes = new byte[chars.length * 6]; for ( int i = 0; i < chars.length; i++ ) { if ( escaped ) { escaped = false; switch ( chars[i] ) { case '\\': case '"': case '+': case ',': case ';': case '<': case '>': case '#': case '=': case ' ': bytes[pos++] = ( byte ) chars[i]; break; default: if ( Chars.isHex( chars, i ) ) { isHex = true; pair = ( byte ) ( Hex.getHexValue( chars[i] ) << 4 ); } break; } } else { if ( isHex ) { if ( Chars.isHex( chars, i ) ) { pair += Hex.getHexValue( chars[i] ); bytes[pos++] = pair; isHex = false; pair = 0; } } else { switch ( chars[i] ) { case '\\': escaped = true; break; case '"': case '+': case ',': case ';': case '<': case '>': case '#': if ( i != 0 ) { bytes[pos++] = '#'; } break; case ' ': if ( ( i == 0 ) || ( i == chars.length - 1 ) ) { throw new IllegalArgumentException( I18n.err( I18n.ERR_13615_UNESCAPED_CHARS_NOT_ALLOWED ) ); } else { bytes[pos++] = ' '; break; } default: if ( chars[i] < 128 ) { bytes[pos++] = ( byte ) chars[i]; } else { byte[] result = Unicode.charToBytes( chars[i] ); System.arraycopy( result, 0, bytes, pos, result.length ); pos += result.length; } break; } } } } return Strings.utf8ToString( bytes, pos ); } } Rdn();  Rdn( SchemaManager schemaManager );  Rdn( SchemaManager schemaManager, String rdn );  Rdn( String rdn );  Rdn( SchemaManager schemaManager, String upType, String upValue );  Rdn( String upType, String upValue );  Rdn( SchemaManager schemaManager, Ava... avas );  Rdn( Ava... avas );  Rdn( Rdn rdn );  Rdn( SchemaManager schemaManager, Rdn rdn ); Object getValue( String type ); Ava getAva( String type ); @Override Iterator<Ava> iterator(); @Override Rdn clone(); String getName(); String getNormName(); Ava getAva(); Ava getAva( int pos ); String getType(); String getNormType(); String getValue(); @Override boolean equals( Object that ); int size(); static Object unescapeValue( String value ); static String escapeValue( String value ); String getEscaped(); static String escapeValue( byte[] attrValue ); boolean isSchemaAware(); static boolean isValid( String dn ); static boolean isValid( SchemaManager schemaManager, String dn ); @Override int hashCode(); int serialize( byte[] buffer, int pos ); int deserialize( byte[] buffer, int pos ); @Override void writeExternal( ObjectOutput out ); @Override void readExternal( ObjectInput in ); @Override int compareTo( Rdn otherRdn ); @Override String toString(); }
Rdn implements Cloneable, Externalizable, Iterable<Ava>, Comparable<Rdn> { public static Object unescapeValue( String value ) { if ( Strings.isEmpty( value ) ) { return ""; } char[] chars = value.toCharArray(); if ( ( chars[0] == '\"' ) && ( chars[chars.length - 1] == '\"' ) ) { return new String( chars, 1, chars.length - 2 ); } if ( chars[0] == '#' ) { if ( chars.length == 1 ) { return Strings.EMPTY_BYTES; } if ( ( chars.length % 2 ) != 1 ) { throw new IllegalArgumentException( I18n.err( I18n.ERR_13613_VALUE_NOT_IN_HEX_FORM_ODD_NUMBER ) ); } byte[] hexValue = new byte[( chars.length - 1 ) / 2]; int pos = 0; for ( int i = 1; i < chars.length; i += 2 ) { if ( Chars.isHex( chars, i ) && Chars.isHex( chars, i + 1 ) ) { hexValue[pos++] = Hex.getHexValue( chars[i], chars[i + 1] ); } else { throw new IllegalArgumentException( I18n.err( I18n.ERR_13614_VALUE_NOT_IN_HEX_FORM ) ); } } return hexValue; } else { boolean escaped = false; boolean isHex = false; byte pair = -1; int pos = 0; byte[] bytes = new byte[chars.length * 6]; for ( int i = 0; i < chars.length; i++ ) { if ( escaped ) { escaped = false; switch ( chars[i] ) { case '\\': case '"': case '+': case ',': case ';': case '<': case '>': case '#': case '=': case ' ': bytes[pos++] = ( byte ) chars[i]; break; default: if ( Chars.isHex( chars, i ) ) { isHex = true; pair = ( byte ) ( Hex.getHexValue( chars[i] ) << 4 ); } break; } } else { if ( isHex ) { if ( Chars.isHex( chars, i ) ) { pair += Hex.getHexValue( chars[i] ); bytes[pos++] = pair; isHex = false; pair = 0; } } else { switch ( chars[i] ) { case '\\': escaped = true; break; case '"': case '+': case ',': case ';': case '<': case '>': case '#': if ( i != 0 ) { bytes[pos++] = '#'; } break; case ' ': if ( ( i == 0 ) || ( i == chars.length - 1 ) ) { throw new IllegalArgumentException( I18n.err( I18n.ERR_13615_UNESCAPED_CHARS_NOT_ALLOWED ) ); } else { bytes[pos++] = ' '; break; } default: if ( chars[i] < 128 ) { bytes[pos++] = ( byte ) chars[i]; } else { byte[] result = Unicode.charToBytes( chars[i] ); System.arraycopy( result, 0, bytes, pos, result.length ); pos += result.length; } break; } } } } return Strings.utf8ToString( bytes, pos ); } } Rdn();  Rdn( SchemaManager schemaManager );  Rdn( SchemaManager schemaManager, String rdn );  Rdn( String rdn );  Rdn( SchemaManager schemaManager, String upType, String upValue );  Rdn( String upType, String upValue );  Rdn( SchemaManager schemaManager, Ava... avas );  Rdn( Ava... avas );  Rdn( Rdn rdn );  Rdn( SchemaManager schemaManager, Rdn rdn ); Object getValue( String type ); Ava getAva( String type ); @Override Iterator<Ava> iterator(); @Override Rdn clone(); String getName(); String getNormName(); Ava getAva(); Ava getAva( int pos ); String getType(); String getNormType(); String getValue(); @Override boolean equals( Object that ); int size(); static Object unescapeValue( String value ); static String escapeValue( String value ); String getEscaped(); static String escapeValue( byte[] attrValue ); boolean isSchemaAware(); static boolean isValid( String dn ); static boolean isValid( SchemaManager schemaManager, String dn ); @Override int hashCode(); int serialize( byte[] buffer, int pos ); int deserialize( byte[] buffer, int pos ); @Override void writeExternal( ObjectOutput out ); @Override void readExternal( ObjectInput in ); @Override int compareTo( Rdn otherRdn ); @Override String toString(); static final Rdn EMPTY_RDN; static final int UNDEFINED; static final int SUPERIOR; static final int INFERIOR; static final int EQUAL; }