On 28/10/2019 17:41, Davi Baldin Tavares wrote:
Hi,

I’m wondering the implementation create a tree of the expression for example:

Filter = (&(name=davi*)(age>=30)(o=Some company))

Node representation:

Root operation AND
    -> leaf: operation = , key: name, value: davi*
   -> leaf: operation >= , key: age, value: 30
   -> leaf: operation = , key: o, value: Some company

Yes. It creates a AndNode which has 32 children :

o a SubstringNode

o a GreaterEqualNode

o a EqualityNode


Then I would like to iterate over ExprNode content and create a Mongo’s filter 
based on the LDAP Style search...
You will need to use instanceOf on each node to know which kind of filter you are dealing with.

I figured out that classes like EqualityNode has attribute name 
(getAttribute()) and value (getValue()). However I couldn’t figure out how to 
iterate over ExprNode content.

I appreciate any advice.

Cheers,

Davi

On 28 Oct 2019, at 11:20, Emmanuel Lécharny <[email protected]> wrote:

Hi,

On 28/10/2019 13:12, Davi Baldin Tavares wrote:
Hello,

I would like to use Apache’s FilterParser to parser RFC style queries.

However, digging into your APIs, I couldn’t figure out how to navigate under 
the parsed filter structure. My goal is to iterate over parser attributes and 
construct a MongoDB’s filter object.

import org.apache.directory.shared.ldap.filter.FilterParser;
final ExprNode filter = FilterParser.parse(“(name=Davi)”);

Would you have an example of iterating over the parsed filter?

Not sure what you mean by 'iterating over the parsed filter'.

In any case, the parse() method returns a ExprNode instance, which depends on 
the kind of filter you just parsed.  You have 2 big classes of Nodes :

- branch nodes (&, |, !), which contains sub-nodes

- leaf nodes ( =*, <=, >=, =, ~=, substring and extensible nodes), which are 
final nodes.

You can check the type of nodes you are dealing with using the 
ExprNode.isLeaf(), then the simlplest way to know which kind of node is to use 
instanceof.



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to