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.schema.SyntaxChecker;
26 import org.apache.directory.api.util.Strings;
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43 @SuppressWarnings("serial")
44 public final class DsaQualitySyntaxSyntaxChecker extends SyntaxChecker
45 {
46
47
48
49 public static final DsaQualitySyntaxSyntaxChecker INSTANCE =
50 new DsaQualitySyntaxSyntaxChecker( SchemaConstants.DSA_QUALITY_SYNTAX );
51
52
53
54
55 public static final class Builder extends SCBuilder<DsaQualitySyntaxSyntaxChecker>
56 {
57
58
59
60 private Builder()
61 {
62 super( SchemaConstants.DSA_QUALITY_SYNTAX );
63 }
64
65
66
67
68
69
70 @Override
71 public DsaQualitySyntaxSyntaxChecker build()
72 {
73 return new DsaQualitySyntaxSyntaxChecker( oid );
74 }
75 }
76
77
78
79
80
81
82
83 private DsaQualitySyntaxSyntaxChecker( String oid )
84 {
85 super( oid );
86 }
87
88
89
90
91
92 public static Builder builder()
93 {
94 return new Builder();
95 }
96
97
98
99
100
101 @Override
102 public boolean isValidSyntax( Object value )
103 {
104 String strValue;
105
106 if ( value == null )
107 {
108 if ( LOG.isDebugEnabled() )
109 {
110 LOG.debug( I18n.err( I18n.ERR_04488_SYNTAX_INVALID, "null" ) );
111 }
112
113 return false;
114 }
115
116 if ( value instanceof String )
117 {
118 strValue = ( String ) value;
119 }
120 else if ( value instanceof byte[] )
121 {
122 strValue = Strings.utf8ToString( ( byte[] ) value );
123 }
124 else
125 {
126 strValue = value.toString();
127 }
128
129 if ( strValue.length() < 7 )
130 {
131 if ( LOG.isDebugEnabled() )
132 {
133 LOG.debug( I18n.err( I18n.ERR_04488_SYNTAX_INVALID, value ) );
134 }
135
136 return false;
137 }
138
139 String remaining;
140
141 switch ( strValue.charAt( 0 ) )
142 {
143 case 'B':
144 if ( !strValue.startsWith( "BEST-EFFORT" ) )
145 {
146 if ( LOG.isDebugEnabled() )
147 {
148 LOG.debug( I18n.err( I18n.ERR_04488_SYNTAX_INVALID, value ) );
149 }
150
151 return false;
152 }
153
154 remaining = strValue.substring( "BEST-EFFORT".length() );
155 break;
156
157 case 'D':
158 if ( !strValue.startsWith( "DEFUNCT" ) )
159 {
160 if ( LOG.isDebugEnabled() )
161 {
162 LOG.debug( I18n.err( I18n.ERR_04488_SYNTAX_INVALID, value ) );
163 }
164
165 return false;
166 }
167
168 remaining = strValue.substring( "DEFUNCT".length() );
169 break;
170
171 case 'E':
172 if ( !strValue.startsWith( "EXPERIMENTAL" ) )
173 {
174 if ( LOG.isDebugEnabled() )
175 {
176 LOG.debug( I18n.err( I18n.ERR_04488_SYNTAX_INVALID, value ) );
177 }
178
179 return false;
180 }
181
182 remaining = strValue.substring( "EXPERIMENTAL".length() );
183 break;
184
185 case 'F':
186 if ( !strValue.startsWith( "FULL-SERVICE" ) )
187 {
188 if ( LOG.isDebugEnabled() )
189 {
190 LOG.debug( I18n.err( I18n.ERR_04488_SYNTAX_INVALID, value ) );
191 }
192
193 return false;
194 }
195
196 remaining = strValue.substring( "FULL-SERVICE".length() );
197 break;
198
199 case 'P':
200 if ( !strValue.startsWith( "PILOT-SERVICE" ) )
201 {
202 if ( LOG.isDebugEnabled() )
203 {
204 LOG.debug( I18n.err( I18n.ERR_04488_SYNTAX_INVALID, value ) );
205 }
206
207 return false;
208 }
209
210 remaining = strValue.substring( "PILOT-SERVICE".length() );
211 break;
212
213 default:
214 if ( LOG.isDebugEnabled() )
215 {
216 LOG.debug( I18n.err( I18n.ERR_04488_SYNTAX_INVALID, value ) );
217 }
218
219 return false;
220 }
221
222
223
224 if ( remaining.length() == 0 )
225 {
226 if ( LOG.isDebugEnabled() )
227 {
228 LOG.debug( I18n.msg( I18n.MSG_04489_SYNTAX_VALID, value ) );
229 }
230
231 return true;
232 }
233
234 if ( remaining.charAt( 0 ) != '#' )
235 {
236
237 if ( LOG.isDebugEnabled() )
238 {
239 LOG.debug( I18n.err( I18n.ERR_04488_SYNTAX_INVALID, value ) );
240 }
241
242 return false;
243 }
244
245
246 boolean result = Strings.isPrintableString( remaining.substring( 1 ) );
247
248 if ( LOG.isDebugEnabled() )
249 {
250 if ( result )
251 {
252 LOG.debug( I18n.msg( I18n.MSG_04489_SYNTAX_VALID, value ) );
253 }
254 else
255 {
256 LOG.debug( I18n.err( I18n.ERR_04488_SYNTAX_INVALID, value ) );
257 }
258 }
259
260 return result;
261 }
262 }