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 @SuppressWarnings("serial")
40 public final class OtherMailboxSyntaxChecker extends SyntaxChecker
41 {
42
43
44
45 public static final OtherMailboxSyntaxChecker INSTANCE =
46 new OtherMailboxSyntaxChecker( SchemaConstants.OTHER_MAILBOX_SYNTAX );
47
48
49
50
51 public static final class Builder extends SCBuilder<OtherMailboxSyntaxChecker>
52 {
53
54
55
56 private Builder()
57 {
58 super( SchemaConstants.OTHER_MAILBOX_SYNTAX );
59 }
60
61
62
63
64
65
66 @Override
67 public OtherMailboxSyntaxChecker build()
68 {
69 return new OtherMailboxSyntaxChecker( oid );
70 }
71 }
72
73
74
75
76
77 private OtherMailboxSyntaxChecker( String oid )
78 {
79 super( oid );
80 }
81
82
83
84
85
86 public static Builder builder()
87 {
88 return new Builder();
89 }
90
91
92
93
94
95 @Override
96 public boolean isValidSyntax( Object value )
97 {
98 String strValue;
99
100 if ( value == null )
101 {
102 if ( LOG.isDebugEnabled() )
103 {
104 LOG.debug( I18n.err( I18n.ERR_04488_SYNTAX_INVALID, "null" ) );
105 }
106
107 return false;
108 }
109
110 if ( value instanceof String )
111 {
112 strValue = ( String ) value;
113 }
114 else if ( value instanceof byte[] )
115 {
116 strValue = Strings.utf8ToString( ( byte[] ) value );
117 }
118 else
119 {
120 strValue = value.toString();
121 }
122
123 if ( strValue.length() == 0 )
124 {
125 if ( LOG.isDebugEnabled() )
126 {
127 LOG.debug( I18n.err( I18n.ERR_04488_SYNTAX_INVALID, value ) );
128 }
129
130 return false;
131 }
132
133
134 int dollar = strValue.indexOf( '$' );
135
136 if ( dollar == -1 )
137 {
138
139 if ( LOG.isDebugEnabled() )
140 {
141 LOG.debug( I18n.err( I18n.ERR_04488_SYNTAX_INVALID, value ) );
142 }
143
144 return false;
145 }
146
147 String mailboxType = strValue.substring( 0, dollar );
148
149 String mailbox = ( dollar < strValue.length() - 1 )
150 ? strValue.substring( dollar + 1 ) : "";
151
152
153 if ( mailbox.indexOf( '$' ) != -1 )
154 {
155 if ( LOG.isDebugEnabled() )
156 {
157 LOG.debug( I18n.err( I18n.ERR_04488_SYNTAX_INVALID, value ) );
158 }
159
160 return false;
161 }
162
163
164 if ( !Strings.isPrintableString( mailboxType ) )
165 {
166 if ( LOG.isDebugEnabled() )
167 {
168 LOG.debug( I18n.err( I18n.ERR_04488_SYNTAX_INVALID, value ) );
169 }
170
171 return false;
172 }
173
174
175 boolean result = Strings.isIA5String( mailbox );
176
177 if ( LOG.isDebugEnabled() )
178 {
179 if ( result )
180 {
181 LOG.debug( I18n.msg( I18n.MSG_04489_SYNTAX_VALID, value ) );
182 }
183 else
184 {
185 LOG.debug( I18n.err( I18n.ERR_04488_SYNTAX_INVALID, value ) );
186 }
187 }
188
189 return result;
190 }
191 }