Debian Codegraph @

src/com/adobe/internal/xmp/options/SerializeOptions.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 com.adobe.internal.xmp.XMPException;
13 import com.adobe.internal.xmp.XMPMeta;
14 import com.adobe.internal.xmp.XMPMetaFactory;
15
16
17 /**
18 * Options for {@link XMPMetaFactory#serializeToBuffer(XMPMeta, SerializeOptions)}.
19 *
20 * @author Stefan Makswit
21 * @version $Revision$
22 * @since 24.01.2006
23 */
24 public final class SerializeOptions extends Options
25 {
26 /** Omit the XML packet wrapper. */
27 public static final int OMIT_PACKET_WRAPPER = 0x0010;
28 /** Mark packet as read-only. Default is a writeable packet. */
29 public static final int READONLY_PACKET = 0x0020;
30 /**
31 * Use a compact form of RDF.
32 * The compact form is the default serialization format (this flag is technically ignored).
33 * To serialize to the canonical form, set the flag USE_CANONICAL_FORMAT.
34 * If both flags "compact" and "canonical" are set, canonical is used.
35 */
36 public static final int USE_COMPACT_FORMAT = 0x0040;
37 /** Use the canonical form of RDF if set. By default the compact form is used */
38 public static final int USE_CANONICAL_FORMAT = 0x0080;
39 // <#AdobePrivate>
40 /** Serialize as &quot;Plain XMP&quot;, not RDF. */
41 public static final int USE_PLAIN_XMP = 0x0400;
42 // </#AdobePrivate>
43 /**
44 * Include a padding allowance for a thumbnail image. If no <tt>xmp:Thumbnails</tt> property
45 * is present, the typical space for a JPEG thumbnail is used.
46 */
47 public static final int INCLUDE_THUMBNAIL_PAD = 0x0100;
48 /**
49 * The padding parameter provides the overall packet length. The actual amount of padding is
50 * computed. An exception is thrown if the packet exceeds this length with no padding.
51 */
52 public static final int EXACT_PACKET_LENGTH = 0x0200;
53 /** Omit the &lt;x:xmpmeta&gt;-tag */
54 public static final int OMIT_XMPMETA_ELEMENT = 0x1000;
55 /** Sort the struct properties and qualifier before serializing */
56 public static final int SORT = 0x2000;
57
58 // ---------------------------------------------------------------------------------------------
59 // encoding bit constants
60
61 /** Bit indicating little endian encoding, unset is big endian */
62 private static final int LITTLEENDIAN_BIT = 0x0001;
63 /** Bit indication UTF16 encoding. */
64 private static final int UTF16_BIT = 0x0002;
65 /** UTF8 encoding; this is the default */
66 public static final int ENCODE_UTF8 = 0;
67 /** UTF16BE encoding */
68 public static final int ENCODE_UTF16BE = UTF16_BIT;
69 /** UTF16LE encoding */
70 public static final int ENCODE_UTF16LE = UTF16_BIT | LITTLEENDIAN_BIT;
71 /** */
72 private static final int ENCODING_MASK = UTF16_BIT | LITTLEENDIAN_BIT;
73
74 // <#AdobePrivate>
75 // /** Bit indicating UTF32 encoding */
76 // private static final int XMP_UTF32_BIT = 0x0004;
77 // /** UTF32BE */
78 // public static final int ENCODE_UTF32BE = XMP_UTF32_BIT;
79 // /** UTF32LE */
80 // public static final int ENCODE_UTF32LE = XMP_UTF32_BIT | XMP_LITTLEENDIAN_BIT;
81 // </#AdobePrivate>
82
83 /**
84 * The amount of padding to be added if a writeable XML packet is created. If zero is passed
85 * (the default) an appropriate amount of padding is computed.
86 */
87 private int padding = 2048;
88 /**
89 * The string to be used as a line terminator. If empty it defaults to; linefeed, U+000A, the
90 * standard XML newline.
91 */
92 private String newline = "\n";
93 /**
94 * The string to be used for each level of indentation in the serialized
95 * RDF. If empty it defaults to two ASCII spaces, U+0020.
96 */
97 private String indent = " ";
98 /**
99 * The number of levels of indentation to be used for the outermost XML element in the
100 * serialized RDF. This is convenient when embedding the RDF in other text, defaults to 0.
101 */
102 private int baseIndent = 0;
103 /** Omits the Toolkit version attribute, not published, only used for Unit tests. */
104 private boolean omitVersionAttribute = false;
105
106
107 /**
108 * Default constructor.
109 */
110 public SerializeOptions()
111 {
112 // reveal default constructor
113 }
114
115
116 /**
117 * Constructor using inital options
118 * @param options the inital options
119 * @throws XMPException Thrown if options are not consistant.
120 */
121 public SerializeOptions(int options) throws XMPException
122 {
123 super(options);
124 }
125
126
127 /**
128 * @return Returns the option.
129 */
130 public boolean getOmitPacketWrapper()
131 {
132 return getOption(OMIT_PACKET_WRAPPER);
133 }
134
135
136 /**
137 * @param value the value to set
138 * @return Returns the instance to call more set-methods.
139 */
140 public SerializeOptions setOmitPacketWrapper(boolean value)
141 {
142 setOption(OMIT_PACKET_WRAPPER, value);
143 return this;
144 }
145
146
147 /**
148 * @return Returns the option.
149 */
150 public boolean getOmitXmpMetaElement()
151 {
152 return getOption(OMIT_XMPMETA_ELEMENT);
153 }
154
155
156 /**
157 * @param value the value to set
158 * @return Returns the instance to call more set-methods.
159 */
160 public SerializeOptions setOmitXmpMetaElement(boolean value)
161 {
162 setOption(OMIT_XMPMETA_ELEMENT, value);
163 return this;
164 }
165
166
167 /**
168 * @return Returns the option.
169 */
170 public boolean getReadOnlyPacket()
171 {
172 return getOption(READONLY_PACKET);
173 }
174
175
176 /**
177 * @param value the value to set
178 * @return Returns the instance to call more set-methods.
179 */
180 public SerializeOptions setReadOnlyPacket(boolean value)
181 {
182 setOption(READONLY_PACKET, value);
183 return this;
184 }
185
186
187 /**
188 * @return Returns the option.
189 */
190 public boolean getUseCompactFormat()
191 {
192 return getOption(USE_COMPACT_FORMAT);
193 }
194
195
196 /**
197 * @param value the value to set
198 * @return Returns the instance to call more set-methods.
199 */
200 public SerializeOptions setUseCompactFormat(boolean value)
201 {
202 setOption(USE_COMPACT_FORMAT, value);
203 return this;
204 }
205
206
207 /**
208 * @return Returns the option.
209 */
210 public boolean getUseCanonicalFormat()
211 {
212 return getOption(USE_CANONICAL_FORMAT);
213 }
214
215
216 /**
217 * @param value the value to set
218 * @return Returns the instance to call more set-methods.
219 */
220 public SerializeOptions setUseCanonicalFormat(boolean value)
221 {
222 setOption(USE_CANONICAL_FORMAT, value);
223 return this;
224 }
225
226 // <#AdobePrivate>
227 /**
228 * @return Returns the option.
229 */
230 public boolean getUsePlainXMP()
231 {
232 return getOption(USE_PLAIN_XMP);
233 }
234
235
236 /**
237 * @param value the value to set
238 * @return Returns the instance to call more set-methods.
239 */
240 public SerializeOptions setUsePlainXMP(boolean value)
241 {
242 setOption(USE_PLAIN_XMP, value);
243 return this;
244 }
245 // </#AdobePrivate>
246
247 /**
248 * @return Returns the option.
249 */
250 public boolean getIncludeThumbnailPad()
251 {
252 return getOption(INCLUDE_THUMBNAIL_PAD);
253 }
254
255
256 /**
257 * @param value the value to set
258 * @return Returns the instance to call more set-methods.
259 */
260 public SerializeOptions setIncludeThumbnailPad(boolean value)
261 {
262 setOption(INCLUDE_THUMBNAIL_PAD, value);
263 return this;
264 }
265
266
267 /**
268 * @return Returns the option.
269 */
270 public boolean getExactPacketLength()
271 {
272 return getOption(EXACT_PACKET_LENGTH);
273 }
274
275
276 /**
277 * @param value the value to set
278 * @return Returns the instance to call more set-methods.
279 */
280 public SerializeOptions setExactPacketLength(boolean value)
281 {
282 setOption(EXACT_PACKET_LENGTH, value);
283 return this;
284 }
285
286
287 /**
288 * @return Returns the option.
289 */
290 public boolean getSort()
291 {
292 return getOption(SORT);
293 }
294
295
296 /**
297 * @param value the value to set
298 * @return Returns the instance to call more set-methods.
299 */
300 public SerializeOptions setSort(boolean value)
301 {
302 setOption(SORT, value);
303 return this;
304 }
305
306
307 /**
308 * @return Returns the option.
309 */
310 public boolean getEncodeUTF16BE()
311 {
312 return (getOptions() & ENCODING_MASK) == ENCODE_UTF16BE;
313 }
314
315
316 /**
317 * @param value the value to set
318 * @return Returns the instance to call more set-methods.
319 */
320 public SerializeOptions setEncodeUTF16BE(boolean value)
321 {
322 // clear unicode bits
323 setOption(UTF16_BIT | LITTLEENDIAN_BIT, false);
324 setOption(ENCODE_UTF16BE, value);
325 return this;
326 }
327
328
329 /**
330 * @return Returns the option.
331 */
332 public boolean getEncodeUTF16LE()
333 {
334 return (getOptions() & ENCODING_MASK) == ENCODE_UTF16LE;
335 }
336
337
338 /**
339 * @param value the value to set
340 * @return Returns the instance to call more set-methods.
341 */
342 public SerializeOptions setEncodeUTF16LE(boolean value)
343 {
344 // clear unicode bits
345 setOption(UTF16_BIT | LITTLEENDIAN_BIT, false);
346 setOption(ENCODE_UTF16LE, value);
347 return this;
348 }
349
350
351 /**
352 * @return Returns the baseIndent.
353 */
354 public int getBaseIndent()
355 {
356 return baseIndent;
357 }
358
359
360 /**
361 * @param baseIndent
362 * The baseIndent to set.
363 * @return Returns the instance to call more set-methods.
364 */
365 public SerializeOptions setBaseIndent(int baseIndent)
366 {
367 this.baseIndent = baseIndent;
368 return this;
369 }
370
371
372 /**
373 * @return Returns the indent.
374 */
375 public String getIndent()
376 {
377 return indent;
378 }
379
380
381 /**
382 * @param indent
383 * The indent to set.
384 * @return Returns the instance to call more set-methods.
385 */
386 public SerializeOptions setIndent(String indent)
387 {
388 this.indent = indent;
389 return this;
390 }
391
392
393 /**
394 * @return Returns the newline.
395 */
396 public String getNewline()
397 {
398 return newline;
399 }
400
401
402 /**
403 * @param newline
404 * The newline to set.
405 * @return Returns the instance to call more set-methods.
406 */
407 public SerializeOptions setNewline(String newline)
408 {
409 this.newline = newline;
410 return this;
411 }
412
413
414 /**
415 * @return Returns the padding.
416 */
417 public int getPadding()
418 {
419 return padding;
420 }
421
422
423 /**
424 * @param padding
425 * The padding to set.
426 * @return Returns the instance to call more set-methods.
427 */
428 public SerializeOptions setPadding(int padding)
429 {
430 this.padding = padding;
431 return this;
432 }
433
434
435 /**
436 * @return Returns whether the Toolkit version attribute shall be omitted.
437 * <em>Note:</em> This options can only be set by unit tests.
438 */
439 public boolean getOmitVersionAttribute()
440 {
441 return omitVersionAttribute;
442 }
443
444
445 /**
446 * @return Returns the encoding as Java encoding String.
447 */
448 public String getEncoding()
449 {
450 if (getEncodeUTF16BE())
451 {
452 return "UTF-16BE";
453 }
454 else if (getEncodeUTF16LE())
455 {
456 return "UTF-16LE";
457 }
458 else
459 {
460 return "UTF-8";
461 }
462 }
463
464
465 /**
466 *
467 * @return Returns clone of this SerializeOptions-object with the same options set.
468 * @throws CloneNotSupportedException Cannot happen in this place.
469 */
470 public Object clone() throws CloneNotSupportedException
471 {
472 SerializeOptions clone;
473 try
474 {
475 clone = new SerializeOptions(getOptions());
476 clone.setBaseIndent(baseIndent);
477 clone.setIndent(indent);
478 clone.setNewline(newline);
479 clone.setPadding(padding);
480 return clone;
481 }
482 catch (XMPException e)
483 {
484 // This cannot happen, the options are already checked in "this" object.
485 return null;
486 }
487 }
488
489
490 /**
491 * @see Options#defineOptionName(int)
492 */
493 protected String defineOptionName(int option)
494 {
495 switch (option)
496 {
497 case OMIT_PACKET_WRAPPER : return "OMIT_PACKET_WRAPPER";
498 case READONLY_PACKET : return "READONLY_PACKET";
499 case USE_COMPACT_FORMAT : return "USE_COMPACT_FORMAT";
500 // case USE_CANONICAL_FORMAT : return "USE_CANONICAL_FORMAT";
501 // <#AdobePrivate>
502 case USE_PLAIN_XMP : return "USE_PLAIN_XMP";
503 // </#AdobePrivate>
504 case INCLUDE_THUMBNAIL_PAD : return "INCLUDE_THUMBNAIL_PAD";
505 case EXACT_PACKET_LENGTH : return "EXACT_PACKET_LENGTH";
506 case OMIT_XMPMETA_ELEMENT: return "OMIT_XMPMETA_ELEMENT";
507 case SORT : return "NORMALIZED";
508 default: return null;
509 }
510 }
511
512
513 /**
514 * @see Options#getValidOptions()
515 */
516 protected int getValidOptions()
517 {
518 return
519 OMIT_PACKET_WRAPPER |
520 READONLY_PACKET |
521 USE_COMPACT_FORMAT |
522 // USE_CANONICAL_FORMAT |
523 // <#AdobePrivate>
524 USE_PLAIN_XMP |
525 // </#AdobePrivate>
526 INCLUDE_THUMBNAIL_PAD |
527 OMIT_XMPMETA_ELEMENT |
528 EXACT_PACKET_LENGTH |
529 SORT;
530 }
531 }