Debian Codegraph @

src/com/adobe/internal/xmp/options/ParseOptions.java

raw symbols SCIP
1 // =================================================================================================
2 // ADOBE SYSTEMS INCORPORATED
3 // Copyright 2006 Adobe Systems Incorporated
4 // All Rights Reserved
5 //
6 // NOTICE: Adobe permits you to use, modify, and distribute this file in accordance with the terms
7 // of the Adobe license agreement accompanying it.
8 // =================================================================================================
9
10 package com.adobe.internal.xmp.options;
11
12 import java.io.InputStream;
13 import java.util.Collections;
14 import java.util.HashMap;
15 import java.util.Map;
16
17 import com.adobe.internal.xmp.XMPMetaFactory;
18
19
20 /**
21 * Options for {@link XMPMetaFactory#parse(InputStream, ParseOptions)}.
22 *
23 * @author Stefan Makswit
24 * @version $Revision$
25 * @since 24.01.2006
26 */
27 public final class ParseOptions extends Options
28 {
29 /** Require a surrounding "x:xmpmeta" element in the xml-document. */
30 public static final int REQUIRE_XMP_META = 0x0001;
31 /** Do not reconcile alias differences, throw an exception instead. */
32 public static final int STRICT_ALIASING = 0x0004;
33 /** Convert ASCII control characters 0x01 - 0x1F (except tab, cr, and lf) to spaces. */
34 public static final int FIX_CONTROL_CHARS = 0x0008;
35 /** If the input is not unicode, try to parse it as ISO-8859-1. */
36 public static final int ACCEPT_LATIN_1 = 0x0010;
37
38 /** Do not carry run the XMPNormalizer on a packet, leave it as it is. */
39 public static final int OMIT_NORMALIZATION = 0x0020;
40 /** Disallow DOCTYPE declarations to prevent entity expansion attacks.
41 * <em>Note:</em> Slight performance loss when set */
42 public static final int DISALLOW_DOCTYPE = 0x0040;
43
44 /** Map of nodes whose children are to be limited */
45 private Map<String, Integer> mXMPNodesToLimit = new HashMap<String, Integer>();
46
47 /**
48 * Sets the options to the default values.
49 */
50 public ParseOptions()
51 {
52 setOption(FIX_CONTROL_CHARS | ACCEPT_LATIN_1 | DISALLOW_DOCTYPE, true);
53 }
54
55
56 /**
57 * @return Returns the requireXMPMeta.
58 */
59 public boolean getRequireXMPMeta()
60 {
61 return getOption(REQUIRE_XMP_META);
62 }
63
64
65 /**
66 * @param value the value to set
67 * @return Returns the instance to call more set-methods.
68 */
69 public ParseOptions setRequireXMPMeta(boolean value)
70 {
71 setOption(REQUIRE_XMP_META, value);
72 return this;
73 }
74
75
76 /**
77 * @return Returns the strictAliasing.
78 */
79 public boolean getStrictAliasing()
80 {
81 return getOption(STRICT_ALIASING);
82 }
83
84
85 /**
86 * @param value the value to set
87 * @return Returns the instance to call more set-methods.
88 */
89 public ParseOptions setStrictAliasing(boolean value)
90 {
91 setOption(STRICT_ALIASING, value);
92 return this;
93 }
94
95
96 /**
97 * @return Returns the strictAliasing.
98 */
99 public boolean getFixControlChars()
100 {
101 return getOption(FIX_CONTROL_CHARS);
102 }
103
104
105 /**
106 * @param value the value to set
107 * @return Returns the instance to call more set-methods.
108 */
109 public ParseOptions setFixControlChars(boolean value)
110 {
111 setOption(FIX_CONTROL_CHARS, value);
112 return this;
113 }
114
115
116 /**
117 * @return Returns the strictAliasing.
118 */
119 public boolean getAcceptLatin1()
120 {
121 return getOption(ACCEPT_LATIN_1);
122 }
123
124
125 /**
126 * @param value the value to set
127 * @return Returns the instance to call more set-methods.
128 */
129 public ParseOptions setOmitNormalization(boolean value)
130 {
131 setOption(OMIT_NORMALIZATION, value);
132 return this;
133 }
134
135
136 /**
137 * @return Returns the option "omit normalization".
138 */
139 public boolean getOmitNormalization()
140 {
141 return getOption(OMIT_NORMALIZATION);
142 }
143
144
145 /**
146 * @param value the value to set
147 * @return Returns the instance to call more set-methods.
148 */
149 public ParseOptions setDisallowDoctype(boolean value)
150 {
151 setOption(DISALLOW_DOCTYPE, value);
152 return this;
153 }
154
155
156 /**
157 * @return Returns the option "disallow DOCTYPE".
158 */
159 public boolean getDisallowDoctype()
160 {
161 return getOption(DISALLOW_DOCTYPE);
162 }
163
164
165 /**
166 * @param value the value to set
167 * @return Returns the instance to call more set-methods.
168 */
169 public ParseOptions setAcceptLatin1(boolean value)
170 {
171 setOption(ACCEPT_LATIN_1, value);
172 return this;
173 }
174
175
176 /**
177 * @return Returns true if some XMP nodes have been limited.
178 */
179 public boolean areXMPNodesLimited()
180 {
181 return ((mXMPNodesToLimit.size() > 0));
182 }
183
184
185 /**
186 * @param nodeMap the Map with name of nodes and number-of-items to limit them to
187 * @return Returns the instance to call more set-methods.
188 */
189 public ParseOptions setXMPNodesToLimit(Map<String, Integer> nodeMap)
190 {
191 mXMPNodesToLimit.putAll(nodeMap);
192 return this;
193 }
194
195
196 /**
197 * @return Returns Unmodifiable Map containing names oF XMP nodes to limit and number-of-items limit corresponding to the XMP nodes.
198 */
199 public Map<String, Integer> getXMPNodesToLimit()
200 {
201 return Collections.unmodifiableMap(mXMPNodesToLimit);
202 }
203
204
205 /**
206 * @see Options#defineOptionName(int)
207 */
208 protected String defineOptionName(int option)
209 {
210 switch (option)
211 {
212 case REQUIRE_XMP_META : return "REQUIRE_XMP_META";
213 case STRICT_ALIASING : return "STRICT_ALIASING";
214 case FIX_CONTROL_CHARS: return "FIX_CONTROL_CHARS";
215 case ACCEPT_LATIN_1: return "ACCEPT_LATIN_1";
216 case OMIT_NORMALIZATION: return "OMIT_NORMALIZATION";
217 case DISALLOW_DOCTYPE: return "DISALLOW_DOCTYPE";
218 default: return null;
219 }
220 }
221
222
223 /**
224 * @see Options#getValidOptions()
225 */
226 protected int getValidOptions()
227 {
228 return
229 REQUIRE_XMP_META |
230 STRICT_ALIASING |
231 FIX_CONTROL_CHARS |
232 ACCEPT_LATIN_1 |
233 OMIT_NORMALIZATION |
234 DISALLOW_DOCTYPE;
235 }
236 }