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.syntaxCheckers;
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.name.Dn;
26 import org.apache.directory.api.ldap.model.name.Rdn;
27 import org.apache.directory.api.ldap.model.schema.SyntaxChecker;
28 import org.apache.directory.api.util.Strings;
29
30
31
32
33
34
35
36
37 @SuppressWarnings("serial")
38 public final class DnSyntaxChecker extends SyntaxChecker
39 {
40
41
42
43 public static final DnSyntaxChecker INSTANCE = new DnSyntaxChecker( SchemaConstants.DN_SYNTAX );
44
45
46
47
48 public static final class Builder extends SCBuilder<DnSyntaxChecker>
49 {
50
51
52
53 private Builder()
54 {
55 super( SchemaConstants.DN_SYNTAX );
56 }
57
58
59
60
61
62
63 @Override
64 public DnSyntaxChecker build()
65 {
66 return new DnSyntaxChecker( oid );
67 }
68 }
69
70
71
72
73
74
75
76 private DnSyntaxChecker( String oid )
77 {
78 super( oid );
79 }
80
81
82
83
84
85 public static Builder builder()
86 {
87 return new Builder();
88 }
89
90
91
92
93
94 @Override
95 public boolean isValidSyntax( Object value )
96 {
97 String strValue;
98
99 if ( value == null )
100 {
101 if ( LOG.isDebugEnabled() )
102 {
103 LOG.debug( I18n.err( I18n.ERR_13210_SYNTAX_INVALID, "null" ) );
104 }
105
106 return false;
107 }
108
109 if ( value instanceof String )
110 {
111 strValue = ( String ) value;
112 }
113 else if ( value instanceof byte[] )
114 {
115 strValue = Strings.utf8ToString( ( byte[] ) value );
116 }
117 else
118 {
119 strValue = value.toString();
120 }
121
122 if ( strValue.length() == 0 )
123 {
124
125
126
127 if ( LOG.isDebugEnabled() )
128 {
129 LOG.debug( I18n.msg( I18n.MSG_13701_SYNTAX_VALID, value ) );
130 }
131
132 return true;
133 }
134
135
136 boolean result = Dn.isValid( strValue );
137
138 if ( LOG.isDebugEnabled() )
139 {
140 if ( result )
141 {
142 LOG.debug( I18n.msg( I18n.MSG_13701_SYNTAX_VALID, value ) );
143 }
144 else
145 {
146 LOG.debug( I18n.err( I18n.ERR_13210_SYNTAX_INVALID, value ) );
147 }
148 }
149
150 return result;
151 }
152 }