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.aci;
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.SchemaManager;
27 import org.apache.directory.api.ldap.model.schema.SyntaxChecker;
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 @SuppressWarnings("serial")
40 public class ACIItemSyntaxChecker extends SyntaxChecker
41 {
42
43 private static final Logger LOG = LoggerFactory.getLogger( ACIItemSyntaxChecker.class );
44
45
46 private ACIItemChecker aciItemChecker;
47
48
49
50
51
52 public ACIItemSyntaxChecker()
53 {
54 super( SchemaConstants.ACI_ITEM_SYNTAX );
55 }
56
57
58
59
60
61 public boolean isValidSyntax( Object value )
62 {
63 String strValue = null;
64
65 if ( value == null )
66 {
67 LOG.debug( "Syntax invalid for 'null'" );
68 return false;
69 }
70
71 if ( value instanceof String )
72 {
73 strValue = ( String ) value;
74 }
75 else if ( value instanceof byte[] )
76 {
77 strValue = Strings.utf8ToString( ( byte[] ) value );
78 }
79 else
80 {
81 strValue = value.toString();
82 }
83
84 if ( strValue.length() == 0 )
85 {
86 LOG.debug( "Syntax invalid for '{}'", value );
87 return false;
88 }
89
90 try
91 {
92 synchronized ( aciItemChecker )
93 {
94 aciItemChecker.parse( strValue );
95 }
96
97 LOG.debug( "Syntax valid for '{}'", value );
98 return true;
99 }
100 catch ( ParseException pe )
101 {
102 LOG.debug( "Syntax invalid for '{}'", value );
103 return false;
104 }
105 }
106
107
108
109
110
111 public void setSchemaManager( SchemaManager schemaManager )
112 {
113 aciItemChecker = new ACIItemChecker( schemaManager );
114 }
115 }