@@ -560,33 +560,30 @@ private AbstractField parseLiElement(XMPMetadata xmp, QName descriptor, Element
560560 nsFinder .pop ();
561561 }
562562 }
563+ // no child
564+ String text = liElement .getTextContent ();
565+ TypeMapping tm = xmp .getTypeMapping ();
566+ if (type .isSimple ())
567+ {
568+ AbstractField af = tm .instanciateSimpleProperty (descriptor .getNamespaceURI (),
569+ descriptor .getPrefix (), descriptor .getLocalPart (), text , type );
570+ loadAttributes (af , liElement );
571+ return af ;
572+ }
563573 else
564574 {
565- // no child
566- String text = liElement .getTextContent ();
567- TypeMapping tm = xmp .getTypeMapping ();
568- if (type .isSimple ())
575+ // PDFBOX-4325: assume it is structured
576+ AbstractField af ;
577+ try
569578 {
570- AbstractField af = tm .instanciateSimpleProperty (descriptor .getNamespaceURI (),
571- descriptor .getPrefix (), descriptor .getLocalPart (), text , type );
572- loadAttributes (af , liElement );
573- return af ;
579+ af = tm .instanciateStructuredType (type , descriptor .getLocalPart ());
574580 }
575- else
581+ catch ( BadFieldValueException ex )
576582 {
577- // PDFBOX-4325: assume it is structured
578- AbstractField af ;
579- try
580- {
581- af = tm .instanciateStructuredType (type , descriptor .getLocalPart ());
582- }
583- catch (BadFieldValueException ex )
584- {
585- throw new XmpParsingException (ErrorType .InvalidType , "Parsing of structured type failed" , ex );
586- }
587- loadAttributes (af , liElement );
588- return af ;
583+ throw new XmpParsingException (ErrorType .InvalidType , "Parsing of structured type failed" , ex );
589584 }
585+ loadAttributes (af , liElement );
586+ return af ;
590587 }
591588 }
592589
@@ -617,30 +614,30 @@ else if (XmpConstants.DEFAULT_RDF_PREFIX.equals(attr.getPrefix())
617614 }
618615 }
619616
620- private AbstractStructuredType parseLiDescription (XMPMetadata xmp , QName descriptor , Element liElement )
617+ private AbstractStructuredType parseLiDescription (XMPMetadata xmp , QName descriptor , Element liDescriptionElement )
621618 throws XmpParsingException
622619 {
623620 TypeMapping tm = xmp .getTypeMapping ();
624- List <Element > elements = DomHelper .getElementChildren (liElement );
625- if (elements .isEmpty ())
621+ List <Element > liDescriptionElementChildren = DomHelper .getElementChildren (liDescriptionElement );
622+ if (liDescriptionElementChildren .isEmpty ())
626623 {
627624 // The list is empty
628625 return null ;
629626 }
630627 // Instantiate abstract structured type with hint from first element
631- Element first = elements .get (0 );
632- nsFinder .push (first );
633- PropertyType ctype = checkPropertyDefinition (xmp , DomHelper .getQName (first ));
628+ Element firstLiDescriptionElementChild = liDescriptionElementChildren .get (0 );
629+ nsFinder .push (firstLiDescriptionElementChild );
630+ PropertyType ctype = checkPropertyDefinition (xmp , DomHelper .getQName (firstLiDescriptionElementChild ));
634631 if (ctype == null )
635632 {
636- throw new XmpParsingException (ErrorType .NoType , "ctype is null, first: " + first +
637- ", DomHelper.getQName(first): " + DomHelper .getQName (first ));
633+ throw new XmpParsingException (ErrorType .NoType , "ctype is null, first: " + firstLiDescriptionElementChild +
634+ ", DomHelper.getQName(first): " + DomHelper .getQName (firstLiDescriptionElementChild ));
638635 }
639636 Types tt = ctype .type ();
640- AbstractStructuredType ast = instanciateStructured (tm , tt , descriptor .getLocalPart (), first .getNamespaceURI ());
637+ AbstractStructuredType ast = instanciateStructured (tm , tt , descriptor .getLocalPart (), firstLiDescriptionElementChild .getNamespaceURI ());
641638
642- ast .setNamespace (first .getNamespaceURI ());
643- ast .setPrefix (first .getPrefix ());
639+ ast .setNamespace (firstLiDescriptionElementChild .getNamespaceURI ());
640+ ast .setPrefix (firstLiDescriptionElementChild .getPrefix ());
644641
645642 PropertiesDescription pm ;
646643 if (tt .isStructured ())
@@ -649,25 +646,25 @@ private AbstractStructuredType parseLiDescription(XMPMetadata xmp, QName descrip
649646 }
650647 else
651648 {
652- pm = tm .getDefinedDescriptionByNamespace (first .getNamespaceURI ());
649+ pm = tm .getDefinedDescriptionByNamespace (firstLiDescriptionElementChild .getNamespaceURI ());
653650 }
654- for (Element element : elements )
651+ for (Element liDescriptionElementChild : liDescriptionElementChildren )
655652 {
656- String prefix = element .getPrefix ();
657- String name = element .getLocalName ();
658- String namespace = element .getNamespaceURI ();
653+ String prefix = liDescriptionElementChild .getPrefix ();
654+ String name = liDescriptionElementChild .getLocalName ();
655+ String namespace = liDescriptionElementChild .getNamespaceURI ();
659656 PropertyType type = pm .getPropertyType (name );
660657 if (type == null )
661658 {
662659 // not defined
663660 throw new XmpParsingException (ErrorType .NoType , "Type '" + name + "' not defined in "
664- + element .getNamespaceURI ());
661+ + liDescriptionElementChild .getNamespaceURI ());
665662 }
666663 else if (type .card ().isArray ())
667664 {
668665 ArrayProperty array = tm .createArrayProperty (namespace , prefix , name , type .card ());
669666 ast .getContainer ().addProperty (array );
670- Element bagOrSeq = DomHelper .getUniqueElementChild (element );
667+ Element bagOrSeq = DomHelper .getUniqueElementChild (liDescriptionElementChild );
671668 List <Element > lis = DomHelper .getElementChildren (bagOrSeq );
672669 for (Element element2 : lis )
673670 {
@@ -681,8 +678,8 @@ else if (type.card().isArray())
681678 else if (type .type ().isSimple ())
682679 {
683680 AbstractSimpleProperty sp = tm .instanciateSimpleProperty (namespace , prefix , name ,
684- element .getTextContent (), type .type ());
685- loadAttributes (sp , element );
681+ liDescriptionElementChild .getTextContent (), type .type ());
682+ loadAttributes (sp , liDescriptionElementChild );
686683 ast .getContainer ().addProperty (sp );
687684 }
688685 else if (type .type ().isStructured ())
@@ -693,13 +690,13 @@ else if (type.type().isStructured())
693690 inner .setPrefix (prefix );
694691 ast .getContainer ().addProperty (inner );
695692 ComplexPropertyContainer cpc = inner .getContainer ();
696- if (DomHelper .isParseTypeResource (element ))
693+ if (DomHelper .isParseTypeResource (liDescriptionElementChild ))
697694 {
698- parseDescriptionInner (xmp , element , cpc );
695+ parseDescriptionInner (xmp , liDescriptionElementChild , cpc );
699696 }
700697 else
701698 {
702- Element descElement = DomHelper .getFirstChildElement (element );
699+ Element descElement = DomHelper .getFirstChildElement (liDescriptionElementChild );
703700 if (descElement != null )
704701 {
705702 parseDescriptionInner (xmp , descElement , cpc );
@@ -708,7 +705,7 @@ else if (type.type().isStructured())
708705 }
709706 else
710707 {
711- throw new XmpParsingException (ErrorType .NoType , "Unidentified element to parse " + element + " (type="
708+ throw new XmpParsingException (ErrorType .NoType , "Unidentified element to parse " + liDescriptionElementChild + " (type="
712709 + type + ")" );
713710 }
714711
0 commit comments