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