2 * Copyright (C) 2007 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
6 * The contents of this file are subject to the Mozilla Public License Version 1.1
7 * See LICENSE.TXT at the top of this package for the full license terms.
10 package eu
.etaxonomy
.cdm
.io
.eflora
;
12 import java
.util
.List
;
14 import org
.apache
.log4j
.Logger
;
15 import org
.jdom
.Element
;
16 import org
.jdom
.Namespace
;
18 import eu
.etaxonomy
.cdm
.common
.CdmUtils
;
19 import eu
.etaxonomy
.cdm
.common
.ResultWrapper
;
20 import eu
.etaxonomy
.cdm
.common
.XmlHelp
;
21 import eu
.etaxonomy
.cdm
.io
.common
.CdmImportBase
;
22 import eu
.etaxonomy
.cdm
.io
.common
.MapWrapper
;
23 import eu
.etaxonomy
.cdm
.model
.agent
.Team
;
24 import eu
.etaxonomy
.cdm
.model
.common
.IdentifiableEntity
;
25 import eu
.etaxonomy
.cdm
.model
.reference
.ReferenceBase
;
26 import eu
.etaxonomy
.cdm
.model
.reference
.ReferenceFactory
;
33 public abstract class EfloraImportBase
extends CdmImportBase
<EfloraImportConfigurator
, EfloraImportState
> {
34 private static final Logger logger
= Logger
.getLogger(EfloraImportBase
.class);
37 protected abstract boolean doInvoke(EfloraImportState state
);
41 protected Element
getBodyElement(EfloraImportConfigurator config
){
42 Element root
= config
.getSourceRoot();
44 if (! "body".equalsIgnoreCase(root
.getName())){
45 logger
.error("Root element is not 'body'");
48 //TODO prevent multiple elements
54 protected boolean testAdditionalElements(Element parentElement
, List
<String
> excludeList
){
55 boolean result
= true;
56 List
<Element
> list
= parentElement
.getChildren();
57 for (Element element
: list
){
58 if (! excludeList
.contains(element
.getName())){
59 logger
.warn("Unknown element (" + element
.getName() + ") in parent element (" + parentElement
.getName() + ")");
67 protected <T
extends IdentifiableEntity
> T
makeReferenceType(Element element
, Class
<?
extends T
> clazz
, MapWrapper
<?
extends T
> objectMap
, ResultWrapper
<Boolean
> success
){
69 String linkType
= element
.getAttributeValue("linkType");
70 String ref
= element
.getAttributeValue("ref");
71 if(ref
== null && linkType
== null){
72 result
= getInstance(clazz
);
74 String title
= element
.getTextNormalize();
75 result
.setTitleCache(title
, true);
77 }else if (linkType
== null || linkType
.equals("local")){
79 result
= objectMap
.get(ref
);
81 logger
.warn("Object (ref = " + ref
+ ")could not be found in WrapperMap");
83 }else if(linkType
.equals("external")){
84 logger
.warn("External link types not yet implemented");
85 }else if(linkType
.equals("other")){
86 logger
.warn("Other link types not yet implemented");
88 logger
.warn("Unknown link type or missing ref");
91 success
.setValue(false);
97 protected ReferenceBase
makeAccordingTo(Element elAccordingTo
, MapWrapper
<ReferenceBase
> referenceMap
, ResultWrapper
<Boolean
> success
){
98 ReferenceBase result
= null;
99 if (elAccordingTo
!= null){
100 String childName
= "AccordingToDetailed";
101 boolean obligatory
= false;
102 Element elAccordingToDetailed
= XmlHelp
.getSingleChildElement(success
, elAccordingTo
, childName
, elAccordingTo
.getNamespace(), obligatory
);
104 childName
= "Simple";
106 Element elSimple
= XmlHelp
.getSingleChildElement(success
, elAccordingTo
, childName
, elAccordingTo
.getNamespace(), obligatory
);
108 if (elAccordingToDetailed
!= null){
109 result
= makeAccordingToDetailed(elAccordingToDetailed
, referenceMap
, success
);
111 result
= ReferenceFactory
.newGeneric();
112 String title
= elSimple
.getTextNormalize();
113 result
.setTitleCache(title
, true);
120 private ReferenceBase
makeAccordingToDetailed(Element elAccordingToDetailed
, MapWrapper
<ReferenceBase
> referenceMap
, ResultWrapper
<Boolean
> success
){
121 ReferenceBase result
= null;
122 Namespace tcsNamespace
= elAccordingToDetailed
.getNamespace();
123 if (elAccordingToDetailed
!= null){
125 String childName
= "AuthorTeam";
126 boolean obligatory
= false;
127 Element elAuthorTeam
= XmlHelp
.getSingleChildElement(success
, elAccordingToDetailed
, childName
, tcsNamespace
, obligatory
);
128 makeAccordingToAuthorTeam(elAuthorTeam
, success
);
131 childName
= "PublishedIn";
133 Element elPublishedIn
= XmlHelp
.getSingleChildElement(success
, elAccordingToDetailed
, childName
, tcsNamespace
, obligatory
);
134 result
= makeReferenceType(elPublishedIn
, ReferenceBase
.class, referenceMap
, success
);
137 childName
= "MicroReference";
139 Element elMicroReference
= XmlHelp
.getSingleChildElement(success
, elAccordingToDetailed
, childName
, tcsNamespace
, obligatory
);
140 String microReference
= elMicroReference
.getTextNormalize();
141 if (CdmUtils
.Nz(microReference
).equals("")){
143 logger
.warn("MicroReference not yet implemented for AccordingToDetailed");
149 private Team
makeAccordingToAuthorTeam(Element elAuthorTeam
, ResultWrapper
<Boolean
> succes
){
151 if (elAuthorTeam
!= null){
153 logger
.warn("AuthorTeam not yet implemented for AccordingToDetailed");