1
|
/**
|
2
|
* Copyright (C) 2007 EDIT
|
3
|
* European Distributed Institute of Taxonomy
|
4
|
* http://www.e-taxonomy.eu
|
5
|
*
|
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.
|
8
|
*/
|
9
|
package eu.etaxonomy.cdm.io.redlist.bfnXml.out;
|
10
|
|
11
|
import java.io.FileWriter;
|
12
|
import java.io.IOException;
|
13
|
import java.util.List;
|
14
|
|
15
|
import org.apache.log4j.Logger;
|
16
|
import org.jdom2.Attribute;
|
17
|
import org.jdom2.Document;
|
18
|
import org.jdom2.Element;
|
19
|
import org.jdom2.output.Format;
|
20
|
import org.jdom2.output.XMLOutputter;
|
21
|
import org.springframework.stereotype.Component;
|
22
|
|
23
|
import eu.etaxonomy.cdm.io.redlist.bfnXml.BfnXmlConstants;
|
24
|
import eu.etaxonomy.cdm.model.name.TaxonNameBase;
|
25
|
import eu.etaxonomy.cdm.model.taxon.Classification;
|
26
|
import eu.etaxonomy.cdm.model.taxon.Taxon;
|
27
|
import eu.etaxonomy.cdm.model.taxon.TaxonNode;
|
28
|
|
29
|
|
30
|
|
31
|
/**
|
32
|
*
|
33
|
* @author pplitzner
|
34
|
* @date May 3, 2016
|
35
|
*
|
36
|
*/
|
37
|
@Component
|
38
|
public class BfnXmlTaxonNameExport extends BfnXmlExportBase<TaxonNameBase> {
|
39
|
|
40
|
private static final long serialVersionUID = -931703660108981011L;
|
41
|
|
42
|
private static final Logger logger = Logger.getLogger(BfnXmlTaxonNameExport.class);
|
43
|
|
44
|
public BfnXmlTaxonNameExport(){
|
45
|
super();
|
46
|
}
|
47
|
|
48
|
@Override
|
49
|
protected void doInvoke(BfnXmlExportState state){
|
50
|
Document document = state.getConfig().getDocument();
|
51
|
|
52
|
startTransaction(true);
|
53
|
|
54
|
//get all classifications
|
55
|
List<Classification> classifications = getClassificationService().list(Classification.class, null, null, null, null);
|
56
|
for (Classification classification : classifications) {
|
57
|
Element roteListeDaten = new Element(BfnXmlConstants.EL_ROTELISTEDATEN);
|
58
|
roteListeDaten.setAttribute(new Attribute(BfnXmlConstants.ATT_INHALT, classification.getTitleCache()));
|
59
|
document.getRootElement().addContent(roteListeDaten);
|
60
|
|
61
|
//export taxonomy
|
62
|
Element taxonyme = new Element(BfnXmlConstants.EL_TAXONYME);
|
63
|
roteListeDaten.addContent(taxonyme);
|
64
|
List<TaxonNode> childNodes = classification.getChildNodes();
|
65
|
for (TaxonNode taxonNode : childNodes) {
|
66
|
exportTaxon(taxonNode, taxonyme);
|
67
|
}
|
68
|
}
|
69
|
|
70
|
XMLOutputter outputter = new XMLOutputter();
|
71
|
outputter.setFormat(Format.getPrettyFormat());
|
72
|
try {
|
73
|
outputter.output(document, new FileWriter(state.getConfig().getDestination()));
|
74
|
} catch (IOException e) {
|
75
|
logger.error("Error writing file", e);
|
76
|
}
|
77
|
|
78
|
}
|
79
|
|
80
|
private void exportTaxon(TaxonNode taxonNode, Element parent) {
|
81
|
Element taxonym = new Element(BfnXmlConstants.EL_TAXONYM);
|
82
|
parent.addContent(taxonym);
|
83
|
|
84
|
Taxon taxon = taxonNode.getTaxon();
|
85
|
Element nanteil = addNanteil(BfnXmlConstants.BEREICH_WISSNAME, taxon.getTitleCache());
|
86
|
taxonym.addContent(nanteil);
|
87
|
|
88
|
}
|
89
|
|
90
|
private Element addNanteil(String bereich, String textContent) {
|
91
|
Element nanteil = new Element(BfnXmlConstants.EL_NANTEIL);
|
92
|
nanteil.setAttribute(new Attribute(BfnXmlConstants.ATT_BEREICH, bereich));
|
93
|
nanteil.addContent(textContent);
|
94
|
return nanteil;
|
95
|
}
|
96
|
|
97
|
@Override
|
98
|
protected boolean doCheck(BfnXmlExportState state) {
|
99
|
return false;
|
100
|
}
|
101
|
|
102
|
@Override
|
103
|
protected boolean isIgnore(BfnXmlExportState state) {
|
104
|
return false;
|
105
|
}
|
106
|
|
107
|
}
|