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.
9 package eu
.etaxonomy
.cdm
.io
.redlist
.bfnXml
.out
;
11 import java
.io
.FileWriter
;
12 import java
.io
.IOException
;
13 import java
.util
.List
;
16 import org
.apache
.log4j
.Logger
;
17 import org
.jdom2
.Attribute
;
18 import org
.jdom2
.Document
;
19 import org
.jdom2
.Element
;
20 import org
.jdom2
.output
.Format
;
21 import org
.jdom2
.output
.XMLOutputter
;
22 import org
.springframework
.stereotype
.Component
;
24 import eu
.etaxonomy
.cdm
.hibernate
.HibernateProxyHelper
;
25 import eu
.etaxonomy
.cdm
.io
.redlist
.bfnXml
.BfnXmlConstants
;
26 import eu
.etaxonomy
.cdm
.io
.redlist
.bfnXml
.in
.BfnXmlTransformer
;
27 import eu
.etaxonomy
.cdm
.model
.common
.IdentifiableSource
;
28 import eu
.etaxonomy
.cdm
.model
.common
.OriginalSourceType
;
29 import eu
.etaxonomy
.cdm
.model
.name
.NonViralName
;
30 import eu
.etaxonomy
.cdm
.model
.name
.Rank
;
31 import eu
.etaxonomy
.cdm
.model
.name
.TaxonNameBase
;
32 import eu
.etaxonomy
.cdm
.model
.taxon
.Classification
;
33 import eu
.etaxonomy
.cdm
.model
.taxon
.Taxon
;
34 import eu
.etaxonomy
.cdm
.model
.taxon
.TaxonNode
;
45 public class BfnXmlTaxonNameExport
extends BfnXmlExportBase
<TaxonNameBase
> {
47 private static final long serialVersionUID
= -931703660108981011L;
49 private static final Logger logger
= Logger
.getLogger(BfnXmlTaxonNameExport
.class);
51 public BfnXmlTaxonNameExport(){
56 protected void doInvoke(BfnXmlExportState state
){
57 Document document
= state
.getConfig().getDocument();
59 startTransaction(true);
61 //get all classifications
62 List
<Classification
> classifications
= getClassificationService().list(Classification
.class, null, null, null, null);
63 for (Classification classification
: classifications
) {
64 Element roteListeDaten
= new Element(BfnXmlConstants
.EL_ROTELISTEDATEN
);
65 roteListeDaten
.setAttribute(new Attribute(BfnXmlConstants
.ATT_INHALT
, classification
.getTitleCache()));
66 document
.getRootElement().addContent(roteListeDaten
);
69 Element taxonyme
= new Element(BfnXmlConstants
.EL_TAXONYME
);
70 roteListeDaten
.addContent(taxonyme
);
71 List
<TaxonNode
> childNodes
= classification
.getChildNodes();
72 for (TaxonNode taxonNode
: childNodes
) {
73 exportTaxon(taxonNode
, taxonyme
);
77 XMLOutputter outputter
= new XMLOutputter();
78 outputter
.setFormat(Format
.getPrettyFormat());
80 outputter
.output(document
, new FileWriter(state
.getConfig().getDestination()));
81 } catch (IOException e
) {
82 logger
.error("Error writing file", e
);
87 private void exportTaxon(TaxonNode taxonNode
, Element parent
) {
88 Element taxonym
= new Element(BfnXmlConstants
.EL_TAXONYM
);
89 parent
.addContent(taxonym
);
91 Taxon taxon
= taxonNode
.getTaxon();
92 NonViralName name
= HibernateProxyHelper
.deproxy(taxon
.getName(), NonViralName
.class);
93 Rank rank
= name
.getRank();
95 addNanteil(taxonym
, BfnXmlConstants
.BEREICH_WISSNAME
, taxon
.getTitleCache());
97 addNanteil(taxonym
, BfnXmlConstants
.BEREICH_EPITHETON1
, name
.getGenusOrUninomial());
98 if(rank
.isLower(Rank
.GENUS())){
99 String epitheton2
= name
.getInfraGenericEpithet();
100 if(epitheton2
==null){
101 epitheton2
= name
.getSpecificEpithet();
103 addNanteil(taxonym
, BfnXmlConstants
.BEREICH_EPITHETON2
, epitheton2
);
105 if(rank
.isLower(Rank
.SPECIES())){
106 String epitheton3
= name
.getInfraSpecificEpithet();
107 if(epitheton3
==null){
108 epitheton3
= name
.getSpecificEpithet();
110 addNanteil(taxonym
, BfnXmlConstants
.BEREICH_EPITHETON3
, epitheton3
);
112 Set
<IdentifiableSource
> sources
= taxon
.getSources();
113 for (IdentifiableSource identifiableSource
: sources
) {
114 if(identifiableSource
.getType().equals(OriginalSourceType
.Import
)
115 && identifiableSource
.getIdNamespace().equals(BfnXmlConstants
.EL_TAXONYM
+":"
116 +BfnXmlConstants
.EL_WISSNAME
+":"+BfnXmlConstants
.EL_NANTEIL
+":"+BfnXmlConstants
.BEREICH_EINDEUTIGER_CODE
)){
117 addNanteil(taxonym
, BfnXmlConstants
.BEREICH_EINDEUTIGER_CODE
, identifiableSource
.getIdInSource());
121 addNanteil(taxonym
, BfnXmlConstants
.BEREICH_RANG
, BfnXmlTransformer
.getRankmap().get(rank
));
125 private void addNanteil(Element element
, String bereich
, String textContent
) {
126 Element nanteil
= new Element(BfnXmlConstants
.EL_NANTEIL
);
127 nanteil
.setAttribute(new Attribute(BfnXmlConstants
.ATT_BEREICH
, bereich
));
128 nanteil
.addContent(textContent
);
129 element
.addContent(nanteil
);
133 protected boolean doCheck(BfnXmlExportState state
) {
138 protected boolean isIgnore(BfnXmlExportState state
) {