Debian Codegraph @

src/com/adobe/internal/xmp/impl/ParsePlainXMP.java

raw symbols SCIP
1 // The Plain XMP format is disabled
2 //
3 // =================================================================================================
4 // ADOBE SYSTEMS INCORPORATED
5 // Copyright 2006 Adobe Systems Incorporated
6 // All Rights Reserved
7 //
8 // NOTICE: Adobe permits you to use, modify, and distribute this file in accordance with the terms
9 // of the Adobe license agreement accompanying it.
10 // =================================================================================================
11 //
12 //package com.adobe.internal.xmp.impl;
13 //
14 //import org.w3c.dom.Node;
15 //
16 //import com.adobe.internal.xmp.XMPConst;
17 //import com.adobe.internal.xmp.XMPError;
18 //import com.adobe.internal.xmp.XMPException;
19 //import com.adobe.internal.xmp.XMPMetaFactory;
20 //import com.adobe.internal.xmp.XMPSchemaRegistry;
21 //import com.adobe.internal.xmp.options.PropertyOptions;
22 //
23 //
24 ///**
25 // * Parser for Plain XML serialisation of RDF.
26 // *
27 // * @author Stefan Makswit
28 // * @version $Revision$
29 // * @since 14.11.2006
30 // */
31 //public class ParsePlainXMP implements XMPConst
32 //{
33 // /** The node might or might not be a qualifier. */
34 // private static final int ALLOW_QUALIFIER = 0;
35 // /** The node must be a qualifier. */
36 // private static final int REQUIRE_QUALIFIER = 1;
37 // /** The node must not be a qualifier. */
38 // private static final int REQUIRE_NON_QUALIFIER = 2;
39 //
40 //
41 // /**
42 // * The main parsing method. The XML tree is walked through from the root
43 // * node and and XMP tree is created.
44 // *
45 // * @param xmlRoot
46 // * the XML root node
47 // * @return Returns an XMP metadata object (not normalized)
48 // * @throws XMPException
49 // * Occurs if the parsing fails for any reason.
50 // */
51 // static XMPMetaImpl parse(Node xmlRoot) throws XMPException
52 // {
53 // XMPMetaImpl xmp = new XMPMetaImpl();
54 //
55 // // handle about-attribute
56 // Node about = xmlRoot.getAttributes().getNamedItemNS(NS_PXMP, "about");
57 // if (about != null)
58 // {
59 // xmp.setObjectName(about.getNodeValue());
60 // }
61 //
62 // // Process the SchemaGroup elements and top level properties.
63 // for (int i = 0; i < xmlRoot.getChildNodes().getLength(); i++)
64 // {
65 // Node pxmpSchema = xmlRoot.getChildNodes().item(i);
66 // if (pxmpSchema.getNodeType() == Node.ELEMENT_NODE)
67 // {
68 // if ("XMP_SchemaGroup".equals(pxmpSchema.getLocalName()))
69 // {
70 // String namespace = pxmpSchema.getNamespaceURI();
71 // if (NS_DC_DEPRECATED.equals(namespace))
72 // {
73 // // Fix a legacy DC namespace
74 // // FfF: remove it after CS3
75 // namespace = NS_DC;
76 // }
77 //
78 // XMPNode xmpSchema = XMPNodeUtils.findSchemaNode(xmp.getRoot(), namespace,
79 // pxmpSchema.getPrefix(), true);
80 // xmpSchema.setImplicit(false);
81 //
82 // parseSchema(pxmpSchema, xmpSchema);
83 // }
84 // else
85 // {
86 // throw new XMPException(
87 // "Children of pxmp:XMP_Packet must be groupNS:XMP_SchemaGroup elements",
88 // XMPError.BADXMP);
89 // }
90 // }
91 // }
92 //
93 // return xmp;
94 // }
95 //
96 //
97 //
98 // /**
99 // * Parse one schema.
100 // *
101 // * @param pxmpSchema the XML schema node
102 // * @param xmpSchema the xmp schema node
103 // * @throws XMPException Quites the parsing with a fatal error.
104 // */
105 // private static void parseSchema(Node pxmpSchema, XMPNode xmpSchema)
106 // throws XMPException
107 // {
108 // // iterate recursively through the properties
109 // for (int j = 0; j < pxmpSchema.getChildNodes().getLength(); j++)
110 // {
111 // Node pxmpProp = pxmpSchema.getChildNodes().item(j);
112 // if (pxmpProp.getNodeType() == Node.ELEMENT_NODE)
113 // {
114 // if (pxmpSchema.getNamespaceURI().equals(pxmpProp.getNamespaceURI()))
115 // {
116 // addXMPNode(xmpSchema, pxmpProp, REQUIRE_NON_QUALIFIER);
117 // }
118 // else
119 // {
120 // throw new XMPException("Top level property in wrong XMP_SchemaGroup",
121 // XMPError.BADXMP);
122 // }
123 // }
124 // }
125 // }
126 //
127 //
128 //
129 // /**
130 // * Add a node to the XMP tree from an XML element. Called recursively for
131 // * lower level children. The kind of node is determined from the value of
132 // * the "kind" XML attribute:
133 // * <ul>
134 // * <li>No kind attribute - A simple child, must have a "value" attribute.
135 // * <li>struct - A regular struct, the fields are contained elements
136 // * <li>c-struct - A compact struct, the fields are attributes.
137 // * <li>bag, seq, alt - A regular array, the items are contained elements.
138 // * <li>c-bag, c-seq, c-alt - A compact array, the items are catenated in a
139 // * "value" attribute.
140 // * <li>qual - A simple qualifier, must have a "value" attribute.
141 // * <li>*-qual - A qualifier with a struct or array value, the * part is
142 // * struct, c-struct, bag, ...
143 // * </ul>
144 // *
145 // * @param xmpParent the parent <code>XMPNode</code>
146 // * @param xmlNode the curernt XML node to parse
147 // * @param qualMode a modus that teels if a qualifier is expected, see constants
148 // * @throws XMPException Thrown if the node mal-formed.
149 // */
150 // private static void addXMPNode(XMPNode xmpParent, Node xmlNode, int qualMode)
151 // throws XMPException
152 // {
153 // // The three special attributes that might be present.
154 // Node valueAttr = null;
155 // Node kindAttr = null;
156 // Node sepAttr = null;
157 //
158 // // Scan for the special attributes. They might be anywhere among the XML
159 // // node's attributes.
160 // // Make sure all other attributes are in a namespace.
161 // for (int i = 0; i < xmlNode.getAttributes().getLength(); i++)
162 // {
163 // Node attribute = xmlNode.getAttributes().item(i);
164 // String attrName = attribute.getNodeName();
165 // if ("value".equals(attrName))
166 // {
167 // valueAttr = attribute;
168 // }
169 // else if ("kind".equals(attrName))
170 // {
171 // kindAttr = attribute;
172 // }
173 // else if ("sep".equals(attrName))
174 // {
175 // sepAttr = attribute;
176 // }
177 // else if (attribute.getNamespaceURI() == null)
178 // {
179 // throw new XMPException("Non-special XML attribute must be in a namespace",
180 // XMPError.BADXMP);
181 // }
182 // }
183 //
184 // // Do semantic checks on the special attributes, determine the kind of
185 // // child.
186 // PropertyOptions childOpts = evaluateNodeType(qualMode, valueAttr, kindAttr, sepAttr);
187 // boolean isQual = childOpts.isQualifier();
188 // assert childOpts.isSimple() || childOpts.isStruct() || childOpts.isArray();
189 // assert !(childOpts.isSimple() && childOpts.isCompact());
190 //
191 //
192 // // Perform some checks and add the child to the XMP parent.
193 // String nodeLocalName = xmlNode.getLocalName();
194 // String nodeNS = xmlNode.getNamespaceURI();
195 // boolean isAlias = false;
196 // if (NS_XML.equals(nodeNS) ||
197 // NS_PXMP.equals(nodeNS) ||
198 // NS_RDF.equals(nodeNS))
199 // {
200 // throw new XMPException("Improper use of xml:, pxmp:, or rdf: namespace",
201 // XMPError.BADXMP);
202 // }
203 // else if (isQual)
204 // {
205 // if (nodeNS == null)
206 // {
207 // throw new XMPException("Qualifiers must be in a namespace", XMPError.BADXMP);
208 // }
209 // else if (!childOpts.isSimple()
210 // && ((XML_LANG.equals(xmlNode.getNodeName())) ||
211 // ("type".equals(nodeLocalName) && NS_RDF.equals(nodeNS)) ||
212 // ("resource".equals(nodeLocalName) && NS_RDF.equals(nodeNS))))
213 // {
214 // throw new XMPException(
215 // "xml:lang, rdf:type, and rdf:resource qualifiers must be simple",
216 // XMPError.BADXMP);
217 // }
218 // }
219 // else
220 // {
221 // if (xmpParent.getOptions().isArray())
222 // {
223 // if (!"item".equals(nodeLocalName))
224 // {
225 // throw new XMPException("Array item elements must be named 'item'",
226 // XMPError.BADXMP);
227 // }
228 // }
229 // else if (nodeNS == null)
230 // {
231 // throw new XMPException(
232 // "Properties and fields, must be in a namespace", XMPError.BADXMP);
233 // }
234 //
235 //
236 // if (xmpParent.getOptions().isSchemaNode())
237 // {
238 // if (XMPMetaFactory.getSchemaRegistry().resolveAlias(nodeNS, nodeLocalName) != null)
239 // {
240 // isAlias = true;
241 // xmpParent.setHasAliases(true);
242 // xmpParent.getParent().setHasAliases(true);
243 // }
244 // }
245 // }
246 //
247 // XMPNode newNode;
248 // if (childOpts.isSimple())
249 // {
250 // newNode = addSimpleNode(xmpParent, xmlNode, isQual, valueAttr, kindAttr);
251 // }
252 // else if (childOpts.isStruct())
253 // {
254 // newNode = addStructNode(xmpParent, xmlNode, childOpts, isQual, kindAttr);
255 // }
256 // else
257 // {
258 // // isArray
259 // newNode = addArrayNode(xmpParent, xmlNode, childOpts, isQual, valueAttr, kindAttr,
260 // sepAttr);
261 // }
262 // newNode.setAlias(isAlias);
263 // }
264 //
265 //
266 // /**
267 // * Parses a simle node.
268 // *
269 // * @param xmpParent the parent node
270 // * @param xmlNode the xml node describing the struct
271 // * @param isQual flag if node will be a qualifier
272 // * @param valueAttr the value attribute
273 // * @param kindAttr the kind attribute node
274 // * @return Returns the generated node.
275 // * @throws XMPException Thrown if node is mal-formed
276 // */
277 // private static XMPNode addSimpleNode(XMPNode xmpParent, Node xmlNode,
278 // boolean isQual, Node valueAttr, Node kindAttr) throws XMPException
279 // {
280 // assert valueAttr == null || "value".equals(valueAttr.getNodeName());
281 // assert kindAttr == null || "kind".equals(kindAttr.getNodeName());
282 //
283 // String nodeName = xmlNode.getNodeName();
284 // String localName = xmlNode.getLocalName();
285 // String namespace = xmlNode.getNamespaceURI();
286 //
287 // XMPNode newNode = new XMPNode(getNodeName(xmlNode), null);
288 //
289 // if (xmlNode.getNodeType() == Node.ATTRIBUTE_NODE)
290 // {
291 // // A simple child from an attribute has nothing more but the value.
292 // assert valueAttr == null && kindAttr == null;
293 // newNode.setValue(xmlNode.getNodeValue());
294 // }
295 // else
296 // {
297 // // A simple child from an element needs a value attribute and might
298 // // have qualifiers.
299 // assert xmlNode.getNodeType() == Node.ELEMENT_NODE;
300 // assert valueAttr != null;
301 // assert isQual == (kindAttr != null);
302 //
303 // newNode.setValue(valueAttr.getNodeValue());
304 //
305 // // Process the qualifiers. Simple ones are general attributes,
306 // // compound ones are nested elements.
307 // // Do the attributes first so that simple qualifiers from them are
308 // // before compound qualifiers.
309 // for (int i = 0; i < xmlNode.getAttributes().getLength(); i++)
310 // {
311 // Node xmlQualifier = xmlNode.getAttributes().item(i);
312 // if (xmlQualifier != valueAttr && xmlQualifier != kindAttr)
313 // {
314 // addSimpleNode(newNode, xmlQualifier, true, null, null);
315 // }
316 //
317 // }
318 //
319 // for (int i = 0; i < xmlNode.getChildNodes().getLength(); i++)
320 // {
321 // Node xmlQualifier = xmlNode.getChildNodes().item(i);
322 // if (xmlQualifier.getNodeType() == Node.ELEMENT_NODE)
323 // {
324 // addXMPNode(newNode, xmlQualifier, REQUIRE_QUALIFIER);
325 // }
326 // }
327 // }
328 //
329 // // Done, transfer the child to the parent and return.
330 // if (!isQual)
331 // {
332 // xmpParent.addChild(newNode);
333 //
334 // }
335 // else
336 // {
337 // boolean isLang = XML_LANG.equals(nodeName);
338 // boolean isType = "type".equals(localName) && NS_RDF.equals(namespace);
339 // boolean isURI = "resource".equals(localName) && NS_RDF.equals(namespace);
340 //
341 // if ((isLang | isType | isURI) && newNode.hasQualifier())
342 // {
343 // throw new XMPException(
344 // "xml:lang, rdf:type, and rdf:resource qualifiers must be simple",
345 // XMPError.BADXMP);
346 // }
347 // else if (isURI)
348 // {
349 // // The rdf:resource qualifier is stored as an option bit, not a
350 // // regular qualifier.
351 // if (xmpParent.getOptions().isCompositeProperty())
352 // {
353 // throw new XMPException("rdf:resource can only be applied to simple nodes",
354 // XMPError.BADXMP);
355 // }
356 //
357 // xmpParent.getOptions().setURI(true);
358 // }
359 // else
360 // {
361 // xmpParent.addQualifier(newNode);
362 // }
363 // }
364 //
365 // return newNode;
366 // }
367 //
368 //
369 // /**
370 // * Parses a struct node.
371 // *
372 // * @param xmpParent the parent node
373 // * @param xmlNode the xml node describing the struct
374 // * @param options the options for the new node
375 // * @param isQual flag if node will be a qualifier
376 // * @param kindAttr the kind attribute node
377 // * @return Returns the generated node.
378 // * @throws XMPException Thrown if node is mal-formed
379 // */
380 // private static XMPNode addStructNode(XMPNode xmpParent, Node xmlNode, PropertyOptions options,
381 // boolean isQual, Node kindAttr) throws XMPException
382 // {
383 // assert options.isStruct();
384 // assert isQual == options.isQualifier();
385 // assert kindAttr != null && "kind".equals(kindAttr.getNodeName());
386 //
387 // XMPNode newNode = new XMPNode(getNodeName(xmlNode), options);
388 //
389 // // Process the fields of the struct.
390 // if (options.isCompact())
391 // {
392 // // The fields of a compact struct are attributes of the parent. Any
393 // // contained elements are qualifiers.
394 // for (int i = 0; i < xmlNode.getAttributes().getLength(); i++)
395 // {
396 // Node xmlField = xmlNode.getAttributes().item(i);
397 // if (xmlField != kindAttr)
398 // {
399 // addSimpleNode(newNode, xmlField, false, null, null);
400 // }
401 // }
402 //
403 // for (int i = 0; i < xmlNode.getChildNodes().getLength(); i++)
404 // {
405 // Node xmlQualifier = xmlNode.getAttributes().item(i);
406 // if (xmlQualifier.getNodeType() == Node.ELEMENT_NODE)
407 // {
408 // addXMPNode(newNode, xmlQualifier, REQUIRE_QUALIFIER);
409 // }
410 // }
411 // }
412 // else
413 // {
414 // // The fields of a regular struct are contained elements, possibly mixed with
415 // // qualifiers. General attributes of the parent node are simple qualifiers. Do the
416 // // attributes first so that simple qualifiers from them are before compound qualifiers.
417 // for (int i = 0; i < xmlNode.getAttributes().getLength(); i++)
418 // {
419 // Node xmlQualifier = xmlNode.getAttributes().item(i);
420 // if (xmlQualifier != kindAttr)
421 // {
422 // addSimpleNode(newNode, xmlQualifier, true, null, null);
423 // }
424 // }
425 //
426 // for (int i = 0; i < xmlNode.getChildNodes().getLength(); i++)
427 // {
428 // Node xmlField = xmlNode.getChildNodes().item(i);
429 // if (xmlField.getNodeType() == Node.ELEMENT_NODE)
430 // {
431 // addXMPNode(newNode, xmlField, ALLOW_QUALIFIER);
432 // }
433 // }
434 // }
435 //
436 // // Done, transfer the child to the parent.
437 // if (!isQual)
438 // {
439 // xmpParent.addChild(newNode);
440 // }
441 // else
442 // {
443 // xmpParent.addQualifier(newNode);
444 // }
445 //
446 // return newNode;
447 // }
448 //
449 //
450 // /**
451 // * Parses an array node.
452 // *
453 // * @param xmpParent the parent node
454 // * @param xmlNode the xml node describing the struct
455 // * @param options the options for the new node
456 // * @param isQual flag if node will be a qualifier
457 // * @param valueAttr the value attribute node
458 // * @param kindAttr the kind attribute node
459 // * @param sepAttr the separator attribute node
460 // * @return Returns the generated node.
461 // * @throws XMPException Thrown if node is mal-formed
462 // */
463 // private static XMPNode addArrayNode(XMPNode xmpParent, Node xmlNode, PropertyOptions options,
464 // boolean isQual, Node valueAttr, Node kindAttr, Node sepAttr)
465 // throws XMPException
466 // {
467 // assert xmlNode.getNodeType() == Node.ELEMENT_NODE;
468 // assert options.isArray();
469 // assert isQual == options.isQualifier();
470 // assert (valueAttr == null) || ("value".equals(valueAttr.getNodeName()));
471 // assert (kindAttr != null) && "kind".equals(kindAttr.getNodeName());
472 // assert (sepAttr == null) || "sep".equals(sepAttr.getNodeName());
473 // assert (sepAttr == null) || " ".equals(sepAttr.getNodeValue())
474 // || "; ".equals(sepAttr.getNodeValue());
475 //
476 // XMPNode newNode = new XMPNode(getNodeName(xmlNode), options);
477 //
478 // // The items of a regular array are contained "item" elements. Other contained elements of a
479 // // regular array are compound qualifiers. The items of a compact array are catenated
480 // // in the "value" attribute. All contained elements of a compact array are compound
481 // // qualifiers. In either case, general attributes of the XML parent are simple qualifiers.
482 // // Do the attributes first so that simple qualifiers from them are
483 // // before compound qualifiers.
484 //
485 // for (int i = 0; i < xmlNode.getAttributes().getLength(); i++)
486 // {
487 // Node xmlQualifier = xmlNode.getAttributes().item(i);
488 // if (xmlQualifier != valueAttr &&
489 // xmlQualifier != kindAttr &&
490 // xmlQualifier != sepAttr)
491 // {
492 // addSimpleNode(newNode, xmlQualifier, true, null, null);
493 // }
494 // }
495 //
496 // int qualMode = ALLOW_QUALIFIER;
497 //
498 // if (options.isCompact())
499 // {
500 // qualMode = REQUIRE_QUALIFIER;
501 // addCompactArrayItems(newNode, valueAttr, sepAttr);
502 // }
503 //
504 // for (int i = 0; i < xmlNode.getChildNodes().getLength(); i++)
505 // {
506 // Node xmlElement = xmlNode.getChildNodes().item(i);
507 // if (xmlElement.getNodeType() == Node.ELEMENT_NODE)
508 // {
509 // addXMPNode(newNode, xmlElement, qualMode);
510 // }
511 // }
512 //
513 //
514 // if (!options.isCompact() && options.isArrayAlternate())
515 // {
516 // XMPNodeUtils.detectAltText(newNode);
517 // }
518 //
519 // // Done, transfer the child to the parent.
520 // if (!isQual)
521 // {
522 // xmpParent.addChild(newNode);
523 // }
524 // else
525 // {
526 // xmpParent.addQualifier(newNode);
527 // }
528 //
529 // return newNode;
530 // }
531 //
532 //
533 //
534 // /**
535 // * Parses a compact array node.
536 // * @param xmpArray the XMP array node to fill
537 // * @param valueAttr the value attribute node
538 // * @param sepAttr the value attribute node
539 // * @throws XMPException Thrown if node is mal-formed
540 // */
541 // private static void addCompactArrayItems(XMPNode xmpArray, Node valueAttr, Node sepAttr)
542 // throws XMPException
543 // {
544 // assert xmpArray.getOptions().isArray();
545 //
546 // String fullValue = valueAttr.getNodeValue();
547 // if (sepAttr == null || " ".equals(sepAttr.getNodeValue()))
548 // {
549 // int start = 0, end = 0;
550 // while (end < fullValue.length())
551 // {
552 // boolean isWhitespace = Character.isWhitespace(fullValue.charAt(end));
553 // if (isWhitespace || end == fullValue.length() - 1)
554 // {
555 // if (end != start)
556 // {
557 // if (!isWhitespace)
558 // {
559 // end++;
560 // }
561 // XMPNode newItem = new XMPNode(ARRAY_ITEM_NAME, fullValue
562 // .substring(start, end), null);
563 // xmpArray.addChild(newItem);
564 // }
565 // end++;
566 // start = end;
567 // }
568 // else
569 // {
570 // end++;
571 // }
572 // }
573 // }
574 // else
575 // {
576 // int itemEnd;
577 // for (int itemStart = 0; itemStart < fullValue.length(); itemStart = itemEnd + 2)
578 // {
579 // for (itemEnd = itemStart; itemEnd < fullValue.length(); itemEnd++)
580 // {
581 // if (fullValue.charAt(itemEnd) == ';' && (itemEnd + 1) < fullValue.length())
582 // {
583 // char next = fullValue.charAt(itemEnd + 1);
584 // if (next == ' ')
585 // {
586 // break;
587 // }
588 // else if (next == ';')
589 // {
590 // itemEnd++;
591 // }
592 // }
593 // }
594 // String value = fullValue.substring(itemStart, itemEnd);
595 // if (value.indexOf(";;") >= 0)
596 // {
597 // value = value.replaceAll(";;", ";");
598 // }
599 // XMPNode newItem = new XMPNode(ARRAY_ITEM_NAME, value, null);
600 // xmpArray.addChild(newItem);
601 // }
602 // }
603 // }
604 //
605 //
606 // /**
607 // * Evaluates the the node type performs some checks.
608 // *
609 // * @param qualMode the "need-qualifier"-mode
610 // * @param valueAttr the value attribute
611 // * @param kindAttr the kind attribute
612 // * @param sepAttr the separator attribute
613 // * @return Returns the new child options which are set appropriate
614 // * @throws XMPException Thrown if the node is mal-formed.
615 // */
616 // private static PropertyOptions evaluateNodeType(int qualMode, Node valueAttr, Node kindAttr,
617 // Node sepAttr) throws XMPException
618 // {
619 // PropertyOptions childOpts;
620 // assert !"".equals(kindAttr); // make sure that it can't be empty
621 // if (kindAttr == null)
622 // {
623 // // This must be a simple property or struct field.
624 // if (qualMode == REQUIRE_QUALIFIER)
625 // {
626 // throw new XMPException("Simple qualifier element must have a \"kind\" attribute",
627 // XMPError.BADXMP);
628 // }
629 // if (valueAttr == null)
630 // {
631 // throw new XMPException("Simple child element must have a \"value\" attribute",
632 // XMPError.BADXMP);
633 // }
634 // if (sepAttr != null)
635 // {
636 // throw new XMPException("Simple child element has a \"sep\" attribute",
637 // XMPError.BADXMP);
638 // }
639 //
640 // childOpts = new PropertyOptions();
641 // }
642 // else if ("qual".equals(kindAttr.getNodeValue()))
643 // {
644 // // This must be a simple qualifier.
645 // if (qualMode == REQUIRE_NON_QUALIFIER)
646 // {
647 // throw new XMPException("Unexpected simple qualifier element", XMPError.BADXMP);
648 // }
649 // if (valueAttr == null)
650 // {
651 // throw new XMPException("Simple qualifier element must have a \"value\" attribute",
652 // XMPError.BADXMP);
653 // }
654 // if (sepAttr != null)
655 // {
656 // throw new XMPException("Simple qualifier element has a \"sep\" attribute",
657 // XMPError.BADXMP);
658 // }
659 // childOpts = new PropertyOptions(PropertyOptions.QUALIFIER);
660 // }
661 // else
662 // {
663 // // can be anything
664 // childOpts = evaluateKindAttribute(qualMode, valueAttr, kindAttr, sepAttr);
665 // }
666 //
667 // return childOpts;
668 // }
669 //
670 //
671 // /**
672 // * Evaluates the kind-attribute and perform some checks.
673 // *
674 // * @param qualMode the "need-qualifier"-mode
675 // * @param valueAttr the value attribute
676 // * @param kindAttr the kind attribute
677 // * @param sepAttr the separator attribute
678 // * @return Returns the new child options which are set appropriate.
679 // * @throws XMPException Thrown if the kind attribute is not recognized
680 // */
681 // private static PropertyOptions evaluateKindAttribute(int qualMode, Node valueAttr,
682 // Node kindAttr, Node sepAttr) throws XMPException
683 // {
684 // PropertyOptions childOpts;
685 // // This must be a struct or an array. It might also be compact, it
686 // // might also be a qualifier.
687 // // "c-...", "c-...-qual", "..." or "...-qual"
688 // childOpts = new PropertyOptions();
689 // String kindStr = kindAttr.getNodeValue();
690 // if (kindStr.startsWith("c-"))
691 // {
692 // // This is a compact struct or array.
693 // childOpts.setCompact(true);
694 // kindStr = kindStr.substring(2);
695 // }
696 //
697 // boolean compoundQual = false;
698 // if (kindStr.endsWith("-qual"))
699 // {
700 // compoundQual = true;
701 // kindStr = kindStr.substring(0, kindStr.length() - 5);
702 // }
703 // else if (kindStr.indexOf('-') >= 0)
704 // {
705 // throw new XMPException("Bad suffix for \"kind\" attribute value", XMPError.BADXMP);
706 // }
707 //
708 //
709 // switch (qualMode)
710 // {
711 // case REQUIRE_QUALIFIER:
712 // if (compoundQual)
713 // {
714 // childOpts.setQualifier(true);
715 // }
716 // else
717 // {
718 // throw new XMPException(
719 // "Compound qualifier element missing \"-qual\" kind suffix",
720 // XMPError.BADXMP);
721 // }
722 // break;
723 //
724 // case REQUIRE_NON_QUALIFIER:
725 // if (compoundQual)
726 // {
727 // throw new XMPException(
728 // "Unexpected compound qualifier element", XMPError.BADXMP);
729 // }
730 // else if ("qual".equals(kindStr))
731 // {
732 // throw new XMPException("Unexpected simple qualifier element", XMPError.BADXMP);
733 // }
734 //
735 // break;
736 //
737 // case ALLOW_QUALIFIER:
738 // default:
739 // // do nothing
740 // }
741 //
742 //
743 // // Determine if this is a struct, or determine the array form.
744 // if ("struct".equals(kindStr))
745 // {
746 // childOpts.setStruct(true);
747 // }
748 // else if ("bag".equals(kindStr))
749 // {
750 // childOpts.setArray(true);
751 // }
752 // else if ("seq".equals(kindStr))
753 // {
754 // childOpts.setArray(true).setArrayOrdered(true);
755 // }
756 // else if ("alt".equals(kindStr))
757 // {
758 // childOpts.setArray(true).setArrayOrdered(true).setArrayAlternate(true);
759 // }
760 // else
761 // {
762 // throw new XMPException("Bad value for 'kind' attribute", XMPError.BADXMP);
763 // }
764 //
765 // if (childOpts.isArray() && childOpts.isCompact())
766 // {
767 // if (valueAttr == null)
768 // {
769 // throw new XMPException("Compact array must have a 'value' attribute",
770 // XMPError.BADXMP);
771 // }
772 // }
773 // else
774 // {
775 // if (valueAttr != null)
776 // {
777 // throw new XMPException(
778 // "Struct or regular array can't have a 'value' attribute",
779 // XMPError.BADXMP);
780 // }
781 // else if (sepAttr != null)
782 // {
783 // throw new XMPException("Only compact arrays may have a 'sep' attribute",
784 // XMPError.BADXMP);
785 // }
786 // }
787 // return childOpts;
788 // }
789 //
790 //
791 // /**
792 // * Registers the prefix if not exising and fixes the node name.
793 // *
794 // * @param xmlNode an XML Property Node
795 // * @return Returns the normalized name.
796 // * @throws XMPException Forwards XMP exceptions.
797 // */
798 // private static String getNodeName(Node xmlNode) throws XMPException
799 // {
800 // if (!"item".equals(xmlNode.getNodeName()))
801 // {
802 // XMPSchemaRegistry registry = XMPMetaFactory.getSchemaRegistry();
803 // String namespace = xmlNode.getNamespaceURI();
804 // if (NS_DC_DEPRECATED.equals(namespace))
805 // {
806 // // Fix a legacy DC namespace
807 // // FfF: remove it after CS3
808 // namespace = NS_DC;
809 // }
810 // String prefix = registry.getNamespacePrefix(namespace);
811 // if (prefix == null)
812 // {
813 // prefix = registry.registerNamespace(namespace, xmlNode.getPrefix());
814 // }
815 // return prefix + xmlNode.getLocalName();
816 // }
817 // else
818 // {
819 // return ARRAY_ITEM_NAME;
820 // }
821 // }
822 //}