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.model.schema.normalizers;
21
22
23 import org.apache.directory.api.asn1.util.Oid;
24 import org.apache.directory.api.i18n.I18n;
25 import org.apache.directory.api.ldap.model.constants.SchemaConstants;
26 import org.apache.directory.api.ldap.model.exception.LdapException;
27 import org.apache.directory.api.ldap.model.exception.LdapInvalidAttributeValueException;
28 import org.apache.directory.api.ldap.model.message.ResultCodeEnum;
29 import org.apache.directory.api.ldap.model.schema.Normalizer;
30 import org.apache.directory.api.ldap.model.schema.PrepareString;
31 import org.apache.directory.api.ldap.model.schema.SchemaManager;
32 import org.apache.directory.api.util.Strings;
33
34
35
36
37
38
39
40 @SuppressWarnings("serial")
41 public class ObjectIdentifierNormalizer extends Normalizer
42 {
43
44 private transient SchemaManager schemaManager;
45
46
47
48
49 public ObjectIdentifierNormalizer()
50 {
51 super( SchemaConstants.OBJECT_IDENTIFIER_MATCH_MR_OID );
52 }
53
54
55
56
57
58 @Override
59 public void setSchemaManager( SchemaManager schemaManager )
60 {
61 this.schemaManager = schemaManager;
62 }
63
64
65
66
67
68 @Override
69 public String normalize( String value ) throws LdapException
70 {
71 if ( Strings.isEmpty( value ) )
72 {
73 return "";
74 }
75
76 String trimmedValue = value.trim();
77
78 if ( Strings.isEmpty( trimmedValue ) )
79 {
80 return "";
81 }
82
83 String oid = schemaManager.getRegistries().getOid( trimmedValue );
84
85 if ( oid == null )
86 {
87
88 if ( Oid.isOid( trimmedValue ) )
89 {
90
91 oid = trimmedValue;
92 }
93 else
94 {
95
96 for ( int i = 0; i < trimmedValue.length(); i++ )
97 {
98 char c = trimmedValue.charAt( i );
99
100 if ( i == 0 )
101 {
102 if ( !Character.isLetter( c ) )
103 {
104 throw new LdapInvalidAttributeValueException( ResultCodeEnum.INVALID_ATTRIBUTE_SYNTAX, I18n.err(
105 I18n.ERR_13724_INVALID_VALUE, value ) );
106 }
107 }
108 else
109 {
110 if ( !( Character.isDigit( c ) || Character.isLetter( c ) || ( c == '-' ) || ( c == '_' ) ) )
111 {
112 throw new LdapInvalidAttributeValueException( ResultCodeEnum.INVALID_ATTRIBUTE_SYNTAX, I18n.err(
113 I18n.ERR_13724_INVALID_VALUE, value ) );
114 }
115 }
116 }
117
118 oid = trimmedValue;
119 }
120 }
121
122 return oid;
123 }
124
125
126
127
128
129 @Override
130 public String normalize( String value, PrepareString.AssertionType assertionType ) throws LdapException
131 {
132 return normalize( value );
133 }
134 }