views:

386

answers:

6

I'm looking for a standalone Java library which allows me to parse LDAP style filter expressions Is such thing available, or is it advisable to use ANTLR instead and build it by one self?

As background: the filter itself is submitted through a network, and I want to create say, the appropriate hibernate Criteria. I'm not doing anything with LDAP!

Any other ideas for a technology independent solution to transfer and transform user defined queries are also appreciated.

A: 

The only LDAP parsing library I know of are the .NET ones System.DirectoryServices.* In theory you should be able to use this library in Mono to get technology independence (other than from mono or .net itself).

Jacob Adams
A: 

Have you looked at jldap, as part of OpenLDAP?

The source is available, and there are classes for parsing both LDAP URLs and search expressions. It's more than you need, but you might be able to use just the objects without actually executing them against an LDAP server, if that's what you want to do.

lavinio
+1  A: 

You could also look at using Apache directory server either for using some of its classes like lavinio's suggestion for OpenLDAP or to embed it as part of your application.

Gaël Marziou
A: 

to clarify, are you set on them being LDAP syle queries, if you're not trying to query ldap.

have you looked at something like this?

http://josql.sourceforge.net/

phatmanace
interesting, but not what I'm looking for. In one case I query java objects directly, indeed, but I'm also using the same query to construct a SQL or Hibernate Query.
Mauli
+2  A: 

You can use the apache directory server's shared LDAP library.

It is available in maven at

<dependency>
  <groupId>org.apache.directory.shared</groupId>
  <artifactId>shared-ldap</artifactId>
  <version>0.9.15</version>
</dependency>

And you can use it like:

final ExprNode filter = FilterParser.parse(filterString);
flamingpenguin
I finally came around to try it, and it works quite fine.
Mauli
A: 

Most OSGi containers also contain this functionality, since these kinds of filters are part of the OSGi specification.

pmf