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 java.text.ParseException;
24
25 import org.apache.directory.api.i18n.I18n;
26 import org.apache.directory.api.ldap.model.constants.SchemaConstants;
27 import org.apache.directory.api.ldap.model.schema.SyntaxChecker;
28 import org.apache.directory.api.ldap.model.schema.parsers.DitContentRuleDescriptionSchemaParser;
29 import org.apache.directory.api.util.Strings;
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51 @SuppressWarnings("serial")
52 public final class DitContentRuleDescriptionSyntaxChecker extends SyntaxChecker
53 {
54
55 private transient DitContentRuleDescriptionSchemaParser schemaParser = new DitContentRuleDescriptionSchemaParser();
56
57
58
59
60 public static final DitContentRuleDescriptionSyntaxChecker INSTANCE =
61 new DitContentRuleDescriptionSyntaxChecker( SchemaConstants.DIT_CONTENT_RULE_SYNTAX );
62
63
64
65
66 public static final class Builder extends SCBuilder<DitContentRuleDescriptionSyntaxChecker>
67 {
68
69
70
71 private Builder()
72 {
73 super( SchemaConstants.DIT_CONTENT_RULE_SYNTAX );
74 }
75
76
77
78
79
80
81 @Override
82 public DitContentRuleDescriptionSyntaxChecker build()
83 {
84 return new DitContentRuleDescriptionSyntaxChecker( oid );
85 }
86 }
87
88
89
90
91
92
93 private DitContentRuleDescriptionSyntaxChecker( String oid )
94 {
95 super( oid );
96 }
97
98
99
100
101
102 public static Builder builder()
103 {
104 return new Builder();
105 }
106
107
108
109
110
111 @Override
112 public boolean isValidSyntax( Object value )
113 {
114 String strValue;
115
116 if ( value == null )
117 {
118 if ( LOG.isDebugEnabled() )
119 {
120 LOG.debug( I18n.err( I18n.ERR_04488_SYNTAX_INVALID, "null" ) );
121 }
122
123 return false;
124 }
125
126 if ( value instanceof String )
127 {
128 strValue = ( String ) value;
129 }
130 else if ( value instanceof byte[] )
131 {
132 strValue = Strings.utf8ToString( ( byte[] ) value );
133 }
134 else
135 {
136 strValue = value.toString();
137 }
138
139 try
140 {
141 schemaParser.parseDITContentRuleDescription( strValue );
142
143 if ( LOG.isDebugEnabled() )
144 {
145 LOG.debug( I18n.msg( I18n.MSG_04489_SYNTAX_VALID, value ) );
146 }
147
148 return true;
149 }
150 catch ( ParseException pe )
151 {
152 if ( LOG.isDebugEnabled() )
153 {
154 LOG.debug( I18n.err( I18n.ERR_04488_SYNTAX_INVALID, value ) );
155 }
156
157 return false;
158 }
159 }
160 }