@Test public void testEncodeFilterValue() { assertEquals( "1234567890", FilterEncoder.encodeFilterValue( "1234567890" ) ); assertEquals( "\\28", FilterEncoder.encodeFilterValue( "(" ) ); assertEquals( "\\29", FilterEncoder.encodeFilterValue( ")" ) ); assertEquals( "\\2A", FilterEncoder.encodeFilterValue( "*" ) ); assertEquals( "\\5C", FilterEncoder.encodeFilterValue( "\\" ) ); assertEquals( "\\00", FilterEncoder.encodeFilterValue( "\0" ) ); assertEquals( "\\28\\2A\\29", FilterEncoder.encodeFilterValue( "(*)" ) ); assertEquals( "a test \\2A \\5Cend", FilterEncoder.encodeFilterValue( "a test \\2A \\end" ) ); }
public static String encodeFilterValue( String value ) { StringBuilder sb = new StringBuilder( value.length() ); boolean escaped = false; boolean hexPair = false; char hex = '\0'; for ( int i = 0; i < value.length(); i++ ) { char ch = value.charAt( i ); switch ( ch ) { case '*': if ( escaped ) { sb.append( "\\5C" ); if ( hexPair ) { sb.append( hex ); hexPair = false; } escaped = false; } sb.append( "\\2A" ); break; case '(': if ( escaped ) { sb.append( "\\5C" ); if ( hexPair ) { sb.append( hex ); hexPair = false; } escaped = false; } sb.append( "\\28" ); break; case ')': if ( escaped ) { sb.append( "\\5C" ); if ( hexPair ) { sb.append( hex ); hexPair = false; } escaped = false; } sb.append( "\\29" ); break; case '\0': if ( escaped ) { sb.append( "\\5C" ); if ( hexPair ) { sb.append( hex ); hexPair = false; } escaped = false; } sb.append( "\\00" ); break; case '\\': if ( escaped ) { sb.append( "\\5C" ); escaped = false; } else { escaped = true; hexPair = false; } break; case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': case 'a': case 'b': case 'c': case 'd': case 'e': case 'f': case 'A': case 'B': case 'C': case 'D': case 'E': case 'F': if ( escaped ) { if ( hexPair ) { sb.append( '\\' ).append( hex ).append( ch ); escaped = false; hexPair = false; } else { hexPair = true; hex = ch; } } else { sb.append( ch ); } break; default: if ( escaped ) { sb.append( "\\5C" ); if ( hexPair ) { sb.append( hex ); hexPair = false; } escaped = false; } sb.append( ch ); } } if ( escaped ) { sb.append( "\\5C" ); } return sb.toString(); }
FilterEncoder { public static String encodeFilterValue( String value ) { StringBuilder sb = new StringBuilder( value.length() ); boolean escaped = false; boolean hexPair = false; char hex = '\0'; for ( int i = 0; i < value.length(); i++ ) { char ch = value.charAt( i ); switch ( ch ) { case '*': if ( escaped ) { sb.append( "\\5C" ); if ( hexPair ) { sb.append( hex ); hexPair = false; } escaped = false; } sb.append( "\\2A" ); break; case '(': if ( escaped ) { sb.append( "\\5C" ); if ( hexPair ) { sb.append( hex ); hexPair = false; } escaped = false; } sb.append( "\\28" ); break; case ')': if ( escaped ) { sb.append( "\\5C" ); if ( hexPair ) { sb.append( hex ); hexPair = false; } escaped = false; } sb.append( "\\29" ); break; case '\0': if ( escaped ) { sb.append( "\\5C" ); if ( hexPair ) { sb.append( hex ); hexPair = false; } escaped = false; } sb.append( "\\00" ); break; case '\\': if ( escaped ) { sb.append( "\\5C" ); escaped = false; } else { escaped = true; hexPair = false; } break; case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': case 'a': case 'b': case 'c': case 'd': case 'e': case 'f': case 'A': case 'B': case 'C': case 'D': case 'E': case 'F': if ( escaped ) { if ( hexPair ) { sb.append( '\\' ).append( hex ).append( ch ); escaped = false; hexPair = false; } else { hexPair = true; hex = ch; } } else { sb.append( ch ); } break; default: if ( escaped ) { sb.append( "\\5C" ); if ( hexPair ) { sb.append( hex ); hexPair = false; } escaped = false; } sb.append( ch ); } } if ( escaped ) { sb.append( "\\5C" ); } return sb.toString(); } }
FilterEncoder { public static String encodeFilterValue( String value ) { StringBuilder sb = new StringBuilder( value.length() ); boolean escaped = false; boolean hexPair = false; char hex = '\0'; for ( int i = 0; i < value.length(); i++ ) { char ch = value.charAt( i ); switch ( ch ) { case '*': if ( escaped ) { sb.append( "\\5C" ); if ( hexPair ) { sb.append( hex ); hexPair = false; } escaped = false; } sb.append( "\\2A" ); break; case '(': if ( escaped ) { sb.append( "\\5C" ); if ( hexPair ) { sb.append( hex ); hexPair = false; } escaped = false; } sb.append( "\\28" ); break; case ')': if ( escaped ) { sb.append( "\\5C" ); if ( hexPair ) { sb.append( hex ); hexPair = false; } escaped = false; } sb.append( "\\29" ); break; case '\0': if ( escaped ) { sb.append( "\\5C" ); if ( hexPair ) { sb.append( hex ); hexPair = false; } escaped = false; } sb.append( "\\00" ); break; case '\\': if ( escaped ) { sb.append( "\\5C" ); escaped = false; } else { escaped = true; hexPair = false; } break; case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': case 'a': case 'b': case 'c': case 'd': case 'e': case 'f': case 'A': case 'B': case 'C': case 'D': case 'E': case 'F': if ( escaped ) { if ( hexPair ) { sb.append( '\\' ).append( hex ).append( ch ); escaped = false; hexPair = false; } else { hexPair = true; hex = ch; } } else { sb.append( ch ); } break; default: if ( escaped ) { sb.append( "\\5C" ); if ( hexPair ) { sb.append( hex ); hexPair = false; } escaped = false; } sb.append( ch ); } } if ( escaped ) { sb.append( "\\5C" ); } return sb.toString(); } private  FilterEncoder(); }
FilterEncoder { public static String encodeFilterValue( String value ) { StringBuilder sb = new StringBuilder( value.length() ); boolean escaped = false; boolean hexPair = false; char hex = '\0'; for ( int i = 0; i < value.length(); i++ ) { char ch = value.charAt( i ); switch ( ch ) { case '*': if ( escaped ) { sb.append( "\\5C" ); if ( hexPair ) { sb.append( hex ); hexPair = false; } escaped = false; } sb.append( "\\2A" ); break; case '(': if ( escaped ) { sb.append( "\\5C" ); if ( hexPair ) { sb.append( hex ); hexPair = false; } escaped = false; } sb.append( "\\28" ); break; case ')': if ( escaped ) { sb.append( "\\5C" ); if ( hexPair ) { sb.append( hex ); hexPair = false; } escaped = false; } sb.append( "\\29" ); break; case '\0': if ( escaped ) { sb.append( "\\5C" ); if ( hexPair ) { sb.append( hex ); hexPair = false; } escaped = false; } sb.append( "\\00" ); break; case '\\': if ( escaped ) { sb.append( "\\5C" ); escaped = false; } else { escaped = true; hexPair = false; } break; case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': case 'a': case 'b': case 'c': case 'd': case 'e': case 'f': case 'A': case 'B': case 'C': case 'D': case 'E': case 'F': if ( escaped ) { if ( hexPair ) { sb.append( '\\' ).append( hex ).append( ch ); escaped = false; hexPair = false; } else { hexPair = true; hex = ch; } } else { sb.append( ch ); } break; default: if ( escaped ) { sb.append( "\\5C" ); if ( hexPair ) { sb.append( hex ); hexPair = false; } escaped = false; } sb.append( ch ); } } if ( escaped ) { sb.append( "\\5C" ); } return sb.toString(); } private  FilterEncoder(); static String format( String filterTemplate, String... values ); static String encodeFilterValue( String value ); }
FilterEncoder { public static String encodeFilterValue( String value ) { StringBuilder sb = new StringBuilder( value.length() ); boolean escaped = false; boolean hexPair = false; char hex = '\0'; for ( int i = 0; i < value.length(); i++ ) { char ch = value.charAt( i ); switch ( ch ) { case '*': if ( escaped ) { sb.append( "\\5C" ); if ( hexPair ) { sb.append( hex ); hexPair = false; } escaped = false; } sb.append( "\\2A" ); break; case '(': if ( escaped ) { sb.append( "\\5C" ); if ( hexPair ) { sb.append( hex ); hexPair = false; } escaped = false; } sb.append( "\\28" ); break; case ')': if ( escaped ) { sb.append( "\\5C" ); if ( hexPair ) { sb.append( hex ); hexPair = false; } escaped = false; } sb.append( "\\29" ); break; case '\0': if ( escaped ) { sb.append( "\\5C" ); if ( hexPair ) { sb.append( hex ); hexPair = false; } escaped = false; } sb.append( "\\00" ); break; case '\\': if ( escaped ) { sb.append( "\\5C" ); escaped = false; } else { escaped = true; hexPair = false; } break; case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': case 'a': case 'b': case 'c': case 'd': case 'e': case 'f': case 'A': case 'B': case 'C': case 'D': case 'E': case 'F': if ( escaped ) { if ( hexPair ) { sb.append( '\\' ).append( hex ).append( ch ); escaped = false; hexPair = false; } else { hexPair = true; hex = ch; } } else { sb.append( ch ); } break; default: if ( escaped ) { sb.append( "\\5C" ); if ( hexPair ) { sb.append( hex ); hexPair = false; } escaped = false; } sb.append( ch ); } } if ( escaped ) { sb.append( "\\5C" ); } return sb.toString(); } private  FilterEncoder(); static String format( String filterTemplate, String... values ); static String encodeFilterValue( String value );  }