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 @SuppressWarnings("serial")
39 public final class Ia5StringSyntaxChecker extends SyntaxChecker
40 {
41
42
43
44 public static final Ia5StringSyntaxChecker INSTANCE = new Ia5StringSyntaxChecker( SchemaConstants.IA5_STRING_SYNTAX );
45
46
47
48
49 public static final class Builder extends SCBuilder<Ia5StringSyntaxChecker>
50 {
51
52
53
54 private Builder()
55 {
56 super( SchemaConstants.IA5_STRING_SYNTAX );
57 }
58
59
60
61
62
63
64 @Override
65 public Ia5StringSyntaxChecker build()
66 {
67 return new Ia5StringSyntaxChecker( oid );
68 }
69 }
70
71
72
73
74
75
76 private Ia5StringSyntaxChecker( String oid )
77 {
78 super( oid );
79 }
80
81
82
83
84
85 public static Builder builder()
86 {
87 return new Builder();
88 }
89
90
91
92
93
94 @Override
95 public boolean isValidSyntax( Object value )
96 {
97 String strValue;
98
99 if ( value == null )
100 {
101 if ( LOG.isDebugEnabled() )
102 {
103 LOG.debug( I18n.err( I18n.ERR_04488_SYNTAX_INVALID, "null" ) );
104 }
105
106 return true;
107 }
108
109 if ( value instanceof String )
110 {
111 strValue = ( String ) value;
112 }
113 else if ( value instanceof byte[] )
114 {
115 strValue = Strings.utf8ToString( ( byte[] ) value );
116 }
117 else
118 {
119 strValue = value.toString();
120 }
121
122 boolean result = Strings.isIA5String( strValue );
123
124 if ( result )
125 {
126 if ( LOG.isDebugEnabled() )
127 {
128 LOG.debug( I18n.msg( I18n.MSG_04489_SYNTAX_VALID, value ) );
129 }
130 }
131 else
132 {
133 if ( LOG.isDebugEnabled() )
134 {
135 LOG.debug( I18n.err( I18n.ERR_04488_SYNTAX_INVALID, value ) );
136 }
137 }
138
139 return result;
140 }
141 }