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.LdapSyntaxDescriptionSchemaParser;
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 @SuppressWarnings("serial")
47 public class LdapSyntaxDescriptionSyntaxChecker extends SyntaxChecker
48 {
49
50 private static final Logger LOG = LoggerFactory.getLogger( LdapSyntaxDescriptionSyntaxChecker.class );
51
52
53 private LdapSyntaxDescriptionSchemaParser schemaParser = new LdapSyntaxDescriptionSchemaParser();
54
55
56
57
58
59
60
61 public LdapSyntaxDescriptionSyntaxChecker()
62 {
63 super( SchemaConstants.LDAP_SYNTAX_DESCRIPTION_SYNTAX );
64 }
65
66
67
68
69
70 public boolean isValidSyntax( Object value )
71 {
72 String strValue = null;
73
74 if ( value == null )
75 {
76 LOG.debug( "Syntax invalid for 'null'" );
77 return false;
78 }
79
80 if ( value instanceof String )
81 {
82 strValue = ( String ) value;
83 }
84 else if ( value instanceof byte[] )
85 {
86 strValue = Strings.utf8ToString( ( byte[] ) value );
87 }
88 else
89 {
90 strValue = value.toString();
91 }
92
93 try
94 {
95 schemaParser.parseLdapSyntaxDescription( strValue );
96 LOG.debug( "Syntax valid for '{}'", value );
97
98 return true;
99 }
100 catch ( ParseException pe )
101 {
102 LOG.debug( "Syntax invalid for '{}'", value );
103 return false;
104 }
105 }
106 }