1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package org.apache.directory.api.ldap.codec.actions.compareRequest;
21
22
23 import org.apache.directory.api.asn1.ber.grammar.GrammarAction;
24 import org.apache.directory.api.asn1.ber.tlv.TLV;
25 import org.apache.directory.api.ldap.codec.api.LdapMessageContainer;
26 import org.apache.directory.api.ldap.codec.decorators.CompareRequestDecorator;
27 import org.apache.directory.api.ldap.model.message.CompareRequest;
28 import org.apache.directory.api.util.Strings;
29 import org.slf4j.Logger;
30 import org.slf4j.LoggerFactory;
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48 public class StoreCompareRequestAssertionValue extends GrammarAction<LdapMessageContainer<CompareRequestDecorator>>
49 {
50
51 private static final Logger LOG = LoggerFactory.getLogger( StoreCompareRequestAssertionValue.class );
52
53
54 private static final boolean IS_DEBUG = LOG.isDebugEnabled();
55
56
57
58
59
60 public StoreCompareRequestAssertionValue()
61 {
62 super( "Store CompareRequest assertion value" );
63 }
64
65
66
67
68
69 public void action( LdapMessageContainer<CompareRequestDecorator> container )
70 {
71
72 CompareRequest compareRequest = container.getMessage();
73
74
75 TLV tlv = container.getCurrentTLV();
76
77
78 if ( tlv.getLength() == 0 )
79 {
80 compareRequest.setAssertionValue( "" );
81 }
82 else
83 {
84 if ( container.isBinary( compareRequest.getAttributeId() ) )
85 {
86 compareRequest.setAssertionValue( tlv.getValue().getData() );
87
88 if ( IS_DEBUG )
89 {
90 LOG.debug( "Comparing attribute value {}", Strings.dumpBytes( compareRequest
91 .getAssertionValue().getBytes() ) );
92 }
93 }
94 else
95 {
96 compareRequest.setAssertionValue( Strings.utf8ToString( tlv.getValue().getData() ) );
97
98 if ( LOG.isDebugEnabled() )
99 {
100 LOG.debug( "Comparing attribute value {}", compareRequest.getAssertionValue() );
101 }
102 }
103 }
104
105
106 container.setGrammarEndAllowed( true );
107 }
108 }