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 MailPreferenceSyntaxChecker extends SyntaxChecker
41 {
42
43
44
45 public static final MailPreferenceSyntaxChecker INSTANCE =
46 new MailPreferenceSyntaxChecker( SchemaConstants.MAIL_PREFERENCE_SYNTAX );
47
48
49
50
51 public static final class Builder extends SCBuilder<MailPreferenceSyntaxChecker>
52 {
53
54
55
56 private Builder()
57 {
58 super( SchemaConstants.MAIL_PREFERENCE_SYNTAX );
59 }
60
61
62
63
64
65
66 @Override
67 public MailPreferenceSyntaxChecker build()
68 {
69 return new MailPreferenceSyntaxChecker( oid );
70 }
71 }
72
73
74
75
76
77
78
79
80
81 private MailPreferenceSyntaxChecker( 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
97
98
99 @Override
100 public boolean isValidSyntax( Object value )
101 {
102 String strValue;
103
104 if ( value == null )
105 {
106 if ( LOG.isDebugEnabled() )
107 {
108 LOG.debug( I18n.err( I18n.ERR_04488_SYNTAX_INVALID, "null" ) );
109 }
110
111 return false;
112 }
113
114 if ( value instanceof String )
115 {
116 strValue = ( String ) value;
117 }
118 else if ( value instanceof byte[] )
119 {
120 strValue = Strings.utf8ToString( ( byte[] ) value );
121 }
122 else
123 {
124 strValue = value.toString();
125 }
126
127 if ( ( strValue.length() < 8 ) || ( strValue.length() > 18 ) )
128 {
129 if ( LOG.isDebugEnabled() )
130 {
131 LOG.debug( I18n.err( I18n.ERR_04488_SYNTAX_INVALID, value ) );
132 }
133
134 return false;
135 }
136
137 boolean result = ( "NO-LISTS".equals( strValue ) ) || ( "ANY-LIST".equals( strValue ) )
138 || ( "PROFESSIONAL-LISTS".equals( strValue ) );
139
140 if ( LOG.isDebugEnabled() )
141 {
142 if ( result )
143 {
144 LOG.debug( I18n.msg( I18n.MSG_04489_SYNTAX_VALID, value ) );
145 }
146 else
147 {
148 LOG.debug( I18n.err( I18n.ERR_04488_SYNTAX_INVALID, value ) );
149 }
150 }
151
152 return result;
153 }
154 }