1 26 27 package com.opensugar.cube.ldap; 28 29 import java.util.Dictionary ; 30 31 public class ApproxClause extends SimpleClause { 33 34 public ApproxClause( String key, String value, boolean keysCaseSensitive ) { 35 super( key, value, keysCaseSensitive ); 36 } 37 38 public boolean filter( Dictionary props ) { 39 Object obj = getProperty( getKey(), props ); 40 if ( obj == null ) { 41 return false; 42 } 43 44 if ( obj instanceof String ) { 45 return removeWhiteSpace( (String )obj ).toLowerCase().equals( removeWhiteSpace( getValue() ).toLowerCase() ); 46 } 47 else if ( obj instanceof String [] ) { 48 String [] s = (String [])obj; 49 for ( int i = 0; i < s.length; i++ ) { 50 if ( s[ i ] != null && removeWhiteSpace( s[ i ] ).toLowerCase().equals( removeWhiteSpace( getValue() ).toLowerCase() ) ) { 51 return true; 52 } 53 } 54 } 55 return false; 56 } 57 58 private static String removeWhiteSpace( String s ) { 59 StringBuffer sb = new StringBuffer (); 60 char c; 61 for ( int i = 0; i < s.length(); i++ ) { 62 c = s.charAt( i ); 63 if ( !Character.isWhitespace( c ) ) { 64 sb.append( c ); 65 } 66 } 67 return sb.toString(); 68 } 69 70 public String getCanonicalForm() { 71 return "(" + getKey() + Filter.APPROX + getValue() + ")"; 72 } 73 74 } 75 | Popular Tags |