239 final class NotFilter implements StringFilter {
240 private StringFilter filter;
241
242 public void parse() throws InvalidSearchFilterException {
243 SearchFilter.this.consumeChar(); // consume the "!"
244 filter = SearchFilter.this.createNextFilter();
245 }
246
247 public boolean check(Attributes targetAttrs) throws NamingException {
248 return !filter.check(targetAttrs);
249 }
250 } /* notFilter */
251
252 // note: declared here since member classes can't have static variables
253 static final int EQUAL_MATCH = 1;
254 static final int APPROX_MATCH = 2;
255 static final int GREATER_MATCH = 3;
256 static final int LESS_MATCH = 4;
257
258 /**
259 * A class for dealing wtih atomic filters
260 */
261 final class AtomicFilter implements StringFilter {
262 private String attrID;
263 private String value;
264 private int matchType;
265
266 public void parse() throws InvalidSearchFilterException {
267
268 skipWhiteSpace();
269
270 try {
271 // find the end
272 int endPos = SearchFilter.this.relIndexOf(END_FILTER_TOKEN);
273
274 //determine the match type
275 int i = SearchFilter.this.relIndexOf(EQUAL_TOKEN);
276 if(debug) {System.out.println("AtomicFilter: = at " + i);}
277 int qualifier = SearchFilter.this.relCharAt(i-1);
278 switch(qualifier) {
279 case APPROX_TOKEN:
352 case APPROX_MATCH:
353 case EQUAL_MATCH:
354 if(substringMatch(this.value, val)) {
355 if (debug) {System.out.println("Atomic: EQUAL match");}
356 return true;
357 }
358 break;
359 case GREATER_MATCH:
360 if (debug) {System.out.println("Atomic: GREATER match");}
361 if(val.compareTo(this.value) >= 0) {
362 return true;
363 }
364 break;
365 case LESS_MATCH:
366 if (debug) {System.out.println("Atomic: LESS match");}
367 if(val.compareTo(this.value) <= 0) {
368 return true;
369 }
370 break;
371 default:
372 if (debug) {System.out.println("AtomicFilter: unkown " +
373 "matchType");}
374 }
375 }
376 return false;
377 }
378
379 // used for substring comparisons (where proto has "*" wildcards
380 private boolean substringMatch(String proto, String value) {
381 // simple case 1: "*" means attribute presence is being tested
382 if(proto.equals(Character.toString(WILDCARD_TOKEN))) {
383 if(debug) {System.out.println("simple presence assertion");}
384 return true;
385 }
386
387 // simple case 2: if there are no wildcards, call String.equals()
388 if(proto.indexOf(WILDCARD_TOKEN) == -1) {
389 return proto.equalsIgnoreCase(value);
390 }
391
392 if(debug) {System.out.println("doing substring comparison");}
417 currentPos += currentStr.length();
418 }
419
420 // do we need to end with the last token?
421 if(proto.charAt(proto.length() - 1) != WILDCARD_TOKEN &&
422 currentPos != value.length() ) {
423 if(debug) {System.out.println("faild final test");}
424 return false;
425 }
426
427 return true;
428 }
429
430 } /* AtomicFilter */
431
432 // ----- static methods for producing string filters given attribute set
433 // ----- or object array
434
435
436 /**
437 * Creates an LDAP filter as a conjuction of the attributes supplied.
438 */
439 public static String format(Attributes attrs) throws NamingException {
440 if (attrs == null || attrs.size() == 0) {
441 return "objectClass=*";
442 }
443
444 String answer;
445 answer = "(& ";
446 Attribute attr;
447 for (NamingEnumeration<? extends Attribute> e = attrs.getAll();
448 e.hasMore(); ) {
449 attr = e.next();
450 if (attr.size() == 0 || (attr.size() == 1 && attr.get() == null)) {
451 // only checking presence of attribute
452 answer += "(" + attr.getID() + "=" + "*)";
453 } else {
454 for (NamingEnumeration<?> ve = attr.getAll();
455 ve.hasMore(); ) {
456 String val = getEncodedStringRep(ve.next());
457 if (val != null) {
|
239 final class NotFilter implements StringFilter {
240 private StringFilter filter;
241
242 public void parse() throws InvalidSearchFilterException {
243 SearchFilter.this.consumeChar(); // consume the "!"
244 filter = SearchFilter.this.createNextFilter();
245 }
246
247 public boolean check(Attributes targetAttrs) throws NamingException {
248 return !filter.check(targetAttrs);
249 }
250 } /* notFilter */
251
252 // note: declared here since member classes can't have static variables
253 static final int EQUAL_MATCH = 1;
254 static final int APPROX_MATCH = 2;
255 static final int GREATER_MATCH = 3;
256 static final int LESS_MATCH = 4;
257
258 /**
259 * A class for dealing with atomic filters
260 */
261 final class AtomicFilter implements StringFilter {
262 private String attrID;
263 private String value;
264 private int matchType;
265
266 public void parse() throws InvalidSearchFilterException {
267
268 skipWhiteSpace();
269
270 try {
271 // find the end
272 int endPos = SearchFilter.this.relIndexOf(END_FILTER_TOKEN);
273
274 //determine the match type
275 int i = SearchFilter.this.relIndexOf(EQUAL_TOKEN);
276 if(debug) {System.out.println("AtomicFilter: = at " + i);}
277 int qualifier = SearchFilter.this.relCharAt(i-1);
278 switch(qualifier) {
279 case APPROX_TOKEN:
352 case APPROX_MATCH:
353 case EQUAL_MATCH:
354 if(substringMatch(this.value, val)) {
355 if (debug) {System.out.println("Atomic: EQUAL match");}
356 return true;
357 }
358 break;
359 case GREATER_MATCH:
360 if (debug) {System.out.println("Atomic: GREATER match");}
361 if(val.compareTo(this.value) >= 0) {
362 return true;
363 }
364 break;
365 case LESS_MATCH:
366 if (debug) {System.out.println("Atomic: LESS match");}
367 if(val.compareTo(this.value) <= 0) {
368 return true;
369 }
370 break;
371 default:
372 if (debug) {System.out.println("AtomicFilter: unknown " +
373 "matchType");}
374 }
375 }
376 return false;
377 }
378
379 // used for substring comparisons (where proto has "*" wildcards
380 private boolean substringMatch(String proto, String value) {
381 // simple case 1: "*" means attribute presence is being tested
382 if(proto.equals(Character.toString(WILDCARD_TOKEN))) {
383 if(debug) {System.out.println("simple presence assertion");}
384 return true;
385 }
386
387 // simple case 2: if there are no wildcards, call String.equals()
388 if(proto.indexOf(WILDCARD_TOKEN) == -1) {
389 return proto.equalsIgnoreCase(value);
390 }
391
392 if(debug) {System.out.println("doing substring comparison");}
417 currentPos += currentStr.length();
418 }
419
420 // do we need to end with the last token?
421 if(proto.charAt(proto.length() - 1) != WILDCARD_TOKEN &&
422 currentPos != value.length() ) {
423 if(debug) {System.out.println("faild final test");}
424 return false;
425 }
426
427 return true;
428 }
429
430 } /* AtomicFilter */
431
432 // ----- static methods for producing string filters given attribute set
433 // ----- or object array
434
435
436 /**
437 * Creates an LDAP filter as a conjunction of the attributes supplied.
438 */
439 public static String format(Attributes attrs) throws NamingException {
440 if (attrs == null || attrs.size() == 0) {
441 return "objectClass=*";
442 }
443
444 String answer;
445 answer = "(& ";
446 Attribute attr;
447 for (NamingEnumeration<? extends Attribute> e = attrs.getAll();
448 e.hasMore(); ) {
449 attr = e.next();
450 if (attr.size() == 0 || (attr.size() == 1 && attr.get() == null)) {
451 // only checking presence of attribute
452 answer += "(" + attr.getID() + "=" + "*)";
453 } else {
454 for (NamingEnumeration<?> ve = attr.getAll();
455 ve.hasMore(); ) {
456 String val = getEncodedStringRep(ve.next());
457 if (val != null) {
|