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 @SuppressWarnings("serial")
42 public final class BootParameterSyntaxChecker extends SyntaxChecker
43 {
44
45
46
47 public static final BootParameterSyntaxChecker INSTANCE =
48 new BootParameterSyntaxChecker( SchemaConstants.BOOT_PARAMETER_SYNTAX );
49
50
51
52
53 public static final class Builder extends SCBuilder<BootParameterSyntaxChecker>
54 {
55
56
57
58 private Builder()
59 {
60 super( SchemaConstants.BOOT_PARAMETER_SYNTAX );
61 }
62
63
64
65
66
67
68 @Override
69 public BootParameterSyntaxChecker build()
70 {
71 return new BootParameterSyntaxChecker( oid );
72 }
73 }
74
75
76
77
78
79
80
81 private BootParameterSyntaxChecker( String oid )
82 {
83 super( oid );
84 }
85
86
87
88
89
90 public static Builder builder()
91 {
92 return new Builder();
93 }
94
95
96 private int parseKeyString( String strValue, int pos, char limit )
97 {
98 try
99 {
100 char c = strValue.charAt( pos );
101
102
103 if ( c == limit )
104 {
105 return pos;
106 }
107
108
109 if ( Character.isUpperCase( c ) || Character.isLowerCase( c ) )
110 {
111 pos++;
112 }
113 else
114 {
115 return -1;
116 }
117
118 c = strValue.charAt( pos );
119
120 while ( c != limit )
121 {
122 if ( Character.isUpperCase( c ) || Character.isLowerCase( c ) || Character.isDigit( c )
123 || ( c == '-' ) || ( c == ';' ) || ( c == '_' ) )
124 {
125 pos++;
126 }
127 else
128 {
129 return -1;
130 }
131
132 c = strValue.charAt( pos );
133 }
134
135 return pos;
136 }
137 catch ( IndexOutOfBoundsException ioobe )
138 {
139 return -1;
140 }
141 }
142
143
144 private int parseKeyString( String strValue, int pos )
145 {
146 try
147 {
148 char c = strValue.charAt( pos );
149
150
151 if ( Character.isUpperCase( c ) || Character.isLowerCase( c ) )
152 {
153 pos++;
154 }
155 else
156 {
157 return -1;
158 }
159
160 while ( pos < strValue.length() )
161 {
162 c = strValue.charAt( pos );
163
164 if ( Character.isUpperCase( c ) || Character.isLowerCase( c ) || Character.isDigit( c )
165 || ( c == '-' ) || ( c == ';' ) || ( c == '_' ) )
166 {
167 pos++;
168 }
169 else
170 {
171 return -1;
172 }
173 }
174
175 return pos;
176 }
177 catch ( IndexOutOfBoundsException ioobe )
178 {
179 return -1;
180 }
181 }
182
183
184
185
186
187 @Override
188 public boolean isValidSyntax( Object value )
189 {
190 String strValue;
191
192 if ( value == null )
193 {
194 if ( LOG.isDebugEnabled() )
195 {
196 LOG.debug( I18n.err( I18n.ERR_13210_SYNTAX_INVALID, "null" ) );
197 }
198
199 return false;
200 }
201
202 if ( value instanceof String )
203 {
204 strValue = ( String ) value;
205 }
206 else if ( value instanceof byte[] )
207 {
208 strValue = Strings.utf8ToString( ( byte[] ) value );
209 }
210 else
211 {
212 strValue = value.toString();
213 }
214
215
216 if ( strValue.length() < 5 )
217 {
218 if ( LOG.isDebugEnabled() )
219 {
220 LOG.debug( I18n.err( I18n.ERR_13210_SYNTAX_INVALID, value ) );
221 }
222
223 return false;
224 }
225
226
227 int pos = parseKeyString( strValue, 0, '=' );
228
229 if ( pos == -1 )
230 {
231 if ( LOG.isDebugEnabled() )
232 {
233 LOG.debug( I18n.err( I18n.ERR_13210_SYNTAX_INVALID, value ) );
234 }
235
236 return false;
237 }
238
239 if ( strValue.charAt( pos ) != '=' )
240 {
241 if ( LOG.isDebugEnabled() )
242 {
243 LOG.debug( I18n.err( I18n.ERR_13210_SYNTAX_INVALID, value ) );
244 }
245
246 return false;
247 }
248 else
249 {
250 pos++;
251 }
252
253
254 pos = parseKeyString( strValue, pos, ':' );
255
256 if ( pos == -1 )
257 {
258 if ( LOG.isDebugEnabled() )
259 {
260 LOG.debug( I18n.err( I18n.ERR_13210_SYNTAX_INVALID, value ) );
261 }
262
263 return false;
264 }
265
266 if ( strValue.charAt( pos ) != ':' )
267 {
268 if ( LOG.isDebugEnabled() )
269 {
270 LOG.debug( I18n.err( I18n.ERR_13210_SYNTAX_INVALID, value ) );
271 }
272
273 return false;
274 }
275 else
276 {
277 pos++;
278 }
279
280
281 pos = parseKeyString( strValue, pos );
282
283 if ( pos == -1 )
284 {
285 if ( LOG.isDebugEnabled() )
286 {
287 LOG.debug( I18n.err( I18n.ERR_13210_SYNTAX_INVALID, value ) );
288 }
289
290 return false;
291 }
292
293 return true;
294 }
295 }