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.request.modify;
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.ModifyRequest;
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 public class StoreModifyRequestAttributeValue extends GrammarAction<LdapMessageContainer<ModifyRequest>>
41 {
42
43 private static final Logger LOG = LoggerFactory.getLogger( StoreModifyRequestAttributeValue.class );
44
45
46
47
48 public StoreModifyRequestAttributeValue()
49 {
50 super( "Stores AttributeValue" );
51 }
52
53
54
55
56
57 @Override
58 public void action( LdapMessageContainer<ModifyRequest> container )
59 {
60 TLV tlv = container.getCurrentTLV();
61
62
63 byte[] value = Strings.EMPTY_BYTES;
64 Attribute currentAttribute = container.getCurrentAttribute();
65
66 try
67 {
68 if ( tlv.getLength() == 0 )
69 {
70 currentAttribute.add( "" );
71 }
72 else
73 {
74 value = tlv.getValue().getData();
75
76 if ( container.isBinary( currentAttribute.getId() ) )
77 {
78 container.getCurrentAttribute().add( value );
79 }
80 else
81 {
82 currentAttribute.add( Strings.utf8ToString( ( byte[] ) value ) );
83 }
84 }
85 }
86 catch ( LdapException le )
87 {
88
89 }
90
91
92 container.setGrammarEndAllowed( true );
93
94 if ( LOG.isDebugEnabled() )
95 {
96 LOG.debug( I18n.msg( I18n.MSG_05131_VALUE_MODIFIED, value ) );
97 }
98 }
99 }