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.schema.SyntaxChecker;
25 import org.slf4j.Logger;
26 import org.slf4j.LoggerFactory;
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44 @SuppressWarnings("serial")
45 public class JpegSyntaxChecker extends SyntaxChecker
46 {
47
48 private static final Logger LOG = LoggerFactory.getLogger( JpegSyntaxChecker.class );
49
50
51
52
53 public JpegSyntaxChecker()
54 {
55 super( SchemaConstants.JPEG_SYNTAX );
56 }
57
58
59
60
61
62 public boolean isValidSyntax( Object value )
63 {
64 if ( value == null )
65 {
66 LOG.debug( "Syntax invalid for 'null'" );
67 return false;
68 }
69
70
71 if ( !( value instanceof byte[] ) )
72 {
73 LOG.debug( "Syntax invalid for '{}'", value );
74 return false;
75 }
76
77 byte[] bytes = ( byte[] ) value;
78
79
80 if ( bytes.length < 11 )
81 {
82 LOG.debug( "Syntax invalid for '{}'", value );
83 return false;
84 }
85
86 if ( ( bytes[0] == ( byte ) 0x00FF )
87 && ( bytes[1] == ( byte ) 0x00D8 )
88 && ( bytes[2] == ( byte ) 0x00FF ) )
89 {
90 if ( bytes[3] == (byte)0x00E0 )
91 {
92
93 if ( ( bytes[6] == 'J' )
94 && ( bytes[7] == 'F' )
95 && ( bytes[8] == 'I' )
96 && ( bytes[9] == 'F' )
97 && ( bytes[10] == 0x00 ) )
98 {
99 LOG.debug( "Syntax valid for '{}'", value );
100 return true;
101 }
102 }
103 else if ( bytes[3] == (byte)0x00E1 )
104 {
105
106 if ( ( bytes[6] == 'E' )
107 && ( bytes[7] == 'x' )
108 && ( bytes[8] == 'i' )
109 && ( bytes[9] == 'f' )
110 && ( bytes[10] == 0x00 ) )
111 {
112 LOG.debug( "Syntax valid for '{}'", value );
113 return true;
114 }
115 }
116 }
117
118 LOG.debug( "Syntax invalid for '{}'", value );
119 return false;
120 }
121 }