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.asn1.util.Oid;
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.Chars;
27 import org.apache.directory.api.util.Strings;
28 import org.slf4j.Logger;
29 import org.slf4j.LoggerFactory;
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53 @SuppressWarnings("serial")
54 public class OidSyntaxChecker extends SyntaxChecker
55 {
56
57 private static final Logger LOG = LoggerFactory.getLogger( OidSyntaxChecker.class );
58
59
60
61
62
63 public OidSyntaxChecker()
64 {
65 super( SchemaConstants.OID_SYNTAX );
66 }
67
68
69
70
71
72 public boolean isValidSyntax( Object value )
73 {
74 String strValue = null;
75
76 if ( value == null )
77 {
78 LOG.debug( "Syntax invalid for 'null'" );
79 return false;
80 }
81
82 if ( value instanceof String )
83 {
84 strValue = ( String ) value;
85 }
86 else if ( value instanceof byte[] )
87 {
88 strValue = Strings.utf8ToString( ( byte[] ) value );
89 }
90 else
91 {
92 strValue = value.toString();
93 }
94
95 if ( strValue.length() == 0 )
96 {
97 LOG.debug( "Syntax invalid for '{}'", value );
98 return false;
99 }
100
101
102
103 if ( Chars.isDigit( strValue.charAt( 0 ) ) )
104 {
105 if ( !Oid.isOid( strValue ) )
106 {
107 LOG.debug( "Syntax invalid for '{}'", value );
108 return false;
109 }
110 else
111 {
112 LOG.debug( "Syntax valid for '{}'", value );
113 return true;
114 }
115 }
116
117
118
119 if ( Chars.isAlphaASCII( strValue, 0 ) )
120 {
121 for ( int index = 0; index < strValue.length(); index++ )
122 {
123 char c = strValue.charAt( index );
124
125 if ( !Chars.isAlphaDigitMinus( c ) )
126 {
127 LOG.debug( "Syntax invalid for '{}'", value );
128 return false;
129 }
130 }
131
132 LOG.debug( "Syntax valid for '{}'", value );
133 return true;
134 }
135 else
136 {
137 LOG.debug( "Syntax invalid for '{}'", value );
138 return false;
139 }
140 }
141 }