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