1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package org.apache.directory.server.core.event;
21
22
23 import java.util.regex.Pattern;
24 import java.util.regex.PatternSyntaxException;
25
26 import javax.naming.NamingException;
27
28 import org.apache.directory.server.core.entry.ServerEntry;
29 import org.apache.directory.server.schema.registries.AttributeTypeRegistry;
30 import org.apache.directory.server.schema.registries.OidRegistry;
31 import org.apache.directory.shared.ldap.entry.EntryAttribute;
32 import org.apache.directory.shared.ldap.entry.Value;
33 import org.apache.directory.shared.ldap.filter.ExprNode;
34 import org.apache.directory.shared.ldap.filter.SubstringNode;
35 import org.apache.directory.shared.ldap.schema.AttributeType;
36 import org.apache.directory.shared.ldap.schema.MatchingRule;
37 import org.apache.directory.shared.ldap.schema.Normalizer;
38
39
40
41
42
43
44
45
46 public class SubstringEvaluator implements Evaluator
47 {
48
49 private OidRegistry oidRegistry;
50
51 private AttributeTypeRegistry attributeTypeRegistry;
52
53
54
55
56
57
58
59
60 public SubstringEvaluator(OidRegistry oidRegistry, AttributeTypeRegistry attributeTypeRegistry)
61 {
62 this.oidRegistry = oidRegistry;
63 this.attributeTypeRegistry = attributeTypeRegistry;
64 }
65
66
67
68
69
70 public boolean evaluate( ExprNode node, String dn, ServerEntry entry ) throws NamingException
71 {
72 Pattern regex = null;
73 SubstringNode snode = (SubstringNode)node;
74 String oid = oidRegistry.getOid( snode.getAttribute() );
75 AttributeType type = attributeTypeRegistry.lookup( oid );
76 MatchingRule matchingRule = type.getSubstr();
77
78 if ( matchingRule == null )
79 {
80 matchingRule = type.getEquality();
81 }
82
83 Normalizer normalizer = matchingRule.getNormalizer();
84
85
86
87 EntryAttribute attr = entry.get( snode.getAttribute() );
88
89
90 if ( null == attr )
91 {
92 return false;
93 }
94
95
96 try
97 {
98 regex = snode.getRegex( normalizer );
99 }
100 catch ( PatternSyntaxException pse )
101 {
102 NamingException ne = new NamingException( "SubstringNode '" + node + "' had " + "incorrect syntax" );
103 ne.setRootCause( pse );
104 throw ne;
105 }
106
107
108
109
110
111
112
113
114 for ( Value<?> value: attr )
115 {
116 String normValue = ( String ) normalizer.normalize( value );
117
118
119
120 if ( regex.matcher( normValue ).matches() )
121 {
122 return true;
123 }
124 }
125
126
127 return false;
128 }
129 }