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.i18n.I18n;
24 import org.apache.directory.api.ldap.model.constants.SchemaConstants;
25 import org.apache.directory.api.ldap.model.exception.LdapException;
26 import org.apache.directory.api.ldap.model.exception.LdapOtherException;
27 import org.apache.directory.api.ldap.model.schema.Normalizer;
28 import org.apache.directory.api.ldap.model.schema.PrepareString;
29 import org.apache.directory.api.ldap.model.schema.SchemaManager;
30 import org.apache.directory.api.ldap.model.schema.syntaxCheckers.NumericOidSyntaxChecker;
31 import org.apache.directory.api.util.Strings;
32
33
34
35
36
37
38
39
40
41
42 @SuppressWarnings("serial")
43 public class NameOrNumericIdNormalizer extends Normalizer
44 {
45 private NumericOidSyntaxChecker checker = NumericOidSyntaxChecker.INSTANCE;
46
47
48 private transient SchemaManager schemaManager;
49
50
51 public static final NameOrNumericIdNormalizer INSTANCE = new NameOrNumericIdNormalizer();
52
53
54
55
56
57 public NameOrNumericIdNormalizer()
58 {
59 super( SchemaConstants.NAME_OR_NUMERIC_ID_MATCH_OID );
60 }
61
62
63
64
65
66 @Override
67 public String normalize( String value ) throws LdapException
68 {
69 return normalize( value, PrepareString.AssertionType.ATTRIBUTE_VALUE );
70 }
71
72
73
74
75
76 @Override
77 public String normalize( String value, PrepareString.AssertionType assertionType ) throws LdapException
78 {
79 if ( Strings.isEmpty( value ) )
80 {
81 return value;
82 }
83
84
85 if ( checker.isValidSyntax( value ) )
86 {
87 return value;
88 }
89
90
91 String oid = schemaManager.getRegistries().getOid( value );
92
93 if ( oid != null )
94 {
95 return oid;
96 }
97
98
99 if ( schemaManager.isStrict() )
100 {
101 throw new LdapOtherException( I18n.err( I18n.ERR_13725_CANNOT_HANDLE_NAME_AND_OPTIONAL_UID_NORM, value ) );
102 }
103 else
104 {
105 return value;
106 }
107 }
108
109
110
111
112
113 @Override
114 public void setSchemaManager( SchemaManager schemaManager )
115 {
116 this.schemaManager = schemaManager;
117 }
118 }