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.ldap.model.constants.SchemaConstants;
26 import org.apache.directory.api.ldap.model.schema.SyntaxChecker;
27 import org.apache.directory.api.ldap.model.schema.parsers.DitContentRuleDescriptionSchemaParser;
28 import org.apache.directory.api.util.Strings;
29 import org.slf4j.Logger;
30 import org.slf4j.LoggerFactory;
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52 @SuppressWarnings("serial")
53 public class DitContentRuleDescriptionSyntaxChecker extends SyntaxChecker
54 {
55
56 private static final Logger LOG = LoggerFactory.getLogger( DitContentRuleDescriptionSyntaxChecker.class );
57
58
59 private DitContentRuleDescriptionSchemaParser schemaParser = new DitContentRuleDescriptionSchemaParser();
60
61
62
63
64
65 public DitContentRuleDescriptionSyntaxChecker()
66 {
67 super( SchemaConstants.DIT_CONTENT_RULE_SYNTAX );
68 }
69
70
71
72
73
74 public boolean isValidSyntax( Object value )
75 {
76 String strValue = null;
77
78 if ( value == null )
79 {
80 LOG.debug( "Syntax invalid for 'null'" );
81 return false;
82 }
83
84 if ( value instanceof String )
85 {
86 strValue = ( String ) value;
87 }
88 else if ( value instanceof byte[] )
89 {
90 strValue = Strings.utf8ToString( ( byte[] ) value );
91 }
92 else
93 {
94 strValue = value.toString();
95 }
96
97 try
98 {
99 schemaParser.parseDITContentRuleDescription( strValue );
100 LOG.debug( "Syntax valid for '{}'", value );
101 return true;
102 }
103 catch ( ParseException pe )
104 {
105 LOG.debug( "Syntax invalid for '{}'", value );
106 return false;
107 }
108 }
109 }