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.searchResultEntry;
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.SearchResultEntryDecorator;
27 import org.apache.directory.api.ldap.model.exception.LdapException;
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 public class StoreSearchResultAttributeValue extends GrammarAction<LdapMessageContainer<SearchResultEntryDecorator>>
45 {
46
47 private static final Logger LOG = LoggerFactory.getLogger( StoreSearchResultAttributeValue.class );
48
49
50 private static final boolean IS_DEBUG = LOG.isDebugEnabled();
51
52
53
54
55
56 public StoreSearchResultAttributeValue()
57 {
58 super( "Stores AttributeValue" );
59 }
60
61
62
63
64
65 public void action( LdapMessageContainer<SearchResultEntryDecorator> container )
66 {
67 SearchResultEntryDecorator searchResultEntry = container.getMessage();
68
69 TLV tlv = container.getCurrentTLV();
70
71
72 Object value = null;
73
74 try
75 {
76 if ( tlv.getLength() == 0 )
77 {
78 searchResultEntry.addAttributeValue( "" );
79
80 LOG.debug( "The attribute value is null" );
81 }
82 else
83 {
84 if ( container.isBinary( searchResultEntry.getCurrentAttribute().getId() ) )
85 {
86 value = tlv.getValue().getData();
87
88 if ( IS_DEBUG )
89 {
90 LOG.debug( "Attribute value {}", Strings.dumpBytes( ( byte[] ) value ) );
91 }
92 }
93 else
94 {
95 value = Strings.utf8ToString( tlv.getValue().getData() );
96
97 LOG.debug( "Attribute value {}", value );
98 }
99
100 searchResultEntry.addAttributeValue( value );
101 }
102 }
103 catch ( LdapException le )
104 {
105
106 }
107
108
109 container.setGrammarEndAllowed( true );
110 }
111 }