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.response.search.entry;
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.i18n.I18n;
26 import org.apache.directory.api.ldap.codec.api.LdapMessageContainer;
27 import org.apache.directory.api.ldap.model.entry.Attribute;
28 import org.apache.directory.api.ldap.model.exception.LdapException;
29 import org.apache.directory.api.ldap.model.message.SearchResultEntry;
30 import org.apache.directory.api.util.Strings;
31 import org.slf4j.Logger;
32 import org.slf4j.LoggerFactory;
33
34
35
36
37
38
39
40
41
42
43
44
45
46 public class StoreSearchResultAttributeValue extends GrammarAction<LdapMessageContainer<SearchResultEntry>>
47 {
48
49 private static final Logger LOG = LoggerFactory.getLogger( StoreSearchResultAttributeValue.class );
50
51
52
53
54 public StoreSearchResultAttributeValue()
55 {
56 super( "Stores AttributeValue" );
57 }
58
59
60
61
62
63 public void action( LdapMessageContainer<SearchResultEntry> container )
64 {
65 Attribute currentAttribute = container.getCurrentAttribute();
66
67 TLV tlv = container.getCurrentTLV();
68
69
70 try
71 {
72 if ( tlv.getLength() == 0 )
73 {
74 currentAttribute.add( "" );
75
76 if ( LOG.isDebugEnabled() )
77 {
78 LOG.debug( I18n.msg( I18n.MSG_05180_NULL_ATTRIBUTE_VALUE ) );
79 }
80 }
81 else
82 {
83 if ( container.isBinary( container.getCurrentAttribute().getId() ) )
84 {
85 byte[] value = tlv.getValue().getData();
86 currentAttribute.add( value );
87
88 if ( LOG.isDebugEnabled() )
89 {
90 LOG.debug( I18n.msg( I18n.MSG_05181_ATTRIBUTE_VALUE, Strings.dumpBytes( ( byte[] ) value ) ) );
91 }
92 }
93 else
94 {
95 String value = Strings.utf8ToString( tlv.getValue().getData() );
96 currentAttribute.add( value );
97
98 if ( LOG.isDebugEnabled() )
99 {
100 LOG.debug( I18n.msg( I18n.MSG_05181_ATTRIBUTE_VALUE, value ) );
101 }
102 }
103
104 }
105 }
106 catch ( LdapException le )
107 {
108
109 }
110
111
112 container.setGrammarEndAllowed( true );
113 }
114 }