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.i18n.I18n;
24 import org.apache.directory.api.ldap.model.constants.SchemaConstants;
25 import org.apache.directory.api.ldap.model.schema.SyntaxChecker;
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45 @SuppressWarnings("serial")
46 public final class JpegSyntaxChecker extends SyntaxChecker
47 {
48
49
50
51 public static final JpegSyntaxChecker INSTANCE = new JpegSyntaxChecker( SchemaConstants.JPEG_SYNTAX );
52
53
54
55
56 public static final class Builder extends SCBuilder<JpegSyntaxChecker>
57 {
58
59
60
61 private Builder()
62 {
63 super( SchemaConstants.JPEG_SYNTAX );
64 }
65
66
67
68
69
70
71 @Override
72 public JpegSyntaxChecker build()
73 {
74 return new JpegSyntaxChecker( oid );
75 }
76 }
77
78
79
80
81
82
83
84 private JpegSyntaxChecker( String oid )
85 {
86 super( oid );
87 }
88
89
90
91
92
93 public static Builder builder()
94 {
95 return new Builder();
96 }
97
98
99
100
101
102 @Override
103 public boolean isValidSyntax( Object value )
104 {
105 if ( value == null )
106 {
107 if ( LOG.isDebugEnabled() )
108 {
109 LOG.debug( I18n.err( I18n.ERR_04488_SYNTAX_INVALID, "null" ) );
110 }
111
112 return false;
113 }
114
115
116 if ( !( value instanceof byte[] ) )
117 {
118 if ( LOG.isDebugEnabled() )
119 {
120 LOG.debug( I18n.err( I18n.ERR_04488_SYNTAX_INVALID, value ) );
121 }
122
123 return false;
124 }
125
126 byte[] bytes = ( byte[] ) value;
127
128
129 if ( bytes.length < 11 )
130 {
131 if ( LOG.isDebugEnabled() )
132 {
133 LOG.debug( I18n.err( I18n.ERR_04488_SYNTAX_INVALID, value ) );
134 }
135
136 return false;
137 }
138
139
140 if ( ( bytes[0] == ( byte ) 0x00FF )
141 && ( bytes[1] == ( byte ) 0x00D8 )
142 && ( bytes[2] == ( byte ) 0x00FF ) )
143 {
144
145 if ( ( bytes[3] == ( byte ) 0x00E0 )
146 && ( bytes[6] == 'J' )
147 && ( bytes[7] == 'F' )
148 && ( bytes[8] == 'I' )
149 && ( bytes[9] == 'F' )
150 && ( bytes[10] == 0x00 ) )
151 {
152 if ( LOG.isDebugEnabled() )
153 {
154 LOG.debug( I18n.msg( I18n.MSG_04489_SYNTAX_VALID, value ) );
155 }
156
157 return true;
158 }
159
160 else if ( ( bytes[3] == ( byte ) 0x00E1 )
161 && ( bytes[6] == 'E' )
162 && ( bytes[7] == 'x' )
163 && ( bytes[8] == 'i' )
164 && ( bytes[9] == 'f' )
165 && ( bytes[10] == 0x00 ) )
166 {
167 if ( LOG.isDebugEnabled() )
168 {
169 LOG.debug( I18n.msg( I18n.MSG_04489_SYNTAX_VALID, value ) );
170 }
171
172 return true;
173 }
174 }
175
176 if ( LOG.isDebugEnabled() )
177 {
178 LOG.debug( I18n.err( I18n.ERR_04488_SYNTAX_INVALID, value ) );
179 }
180
181 return false;
182 }
183 }