1 package eu
.etaxonomy
.cdm
.io
.taxonx2013
;
6 import org
.apache
.log4j
.Logger
;
7 import org
.w3c
.dom
.Document
;
8 import org
.w3c
.dom
.Node
;
9 import org
.w3c
.dom
.NodeList
;
11 import eu
.etaxonomy
.cdm
.model
.common
.CdmBase
;
12 import eu
.etaxonomy
.cdm
.model
.description
.Feature
;
13 import eu
.etaxonomy
.cdm
.model
.name
.NomenclaturalCode
;
14 import eu
.etaxonomy
.cdm
.model
.reference
.Reference
;
15 import eu
.etaxonomy
.cdm
.model
.taxon
.Classification
;
17 public class TaxonXXMLFieldGetter
{
19 private static final Logger logger
= Logger
.getLogger(TaxonXXMLFieldGetter
.class);
20 private final Document doc
;
23 private final NomenclaturalCode nomenclaturalCode
;
24 private Classification classification
;
25 private final TaxonXImport importer
;
26 private final TaxonXImportState taxonXstate
;
27 private TaxonXModsExtractor modsextractor
;
28 private TaxonXTreatmentExtractor treatmentextractor
;
30 public TaxonXXMLFieldGetter(TaxonXDataHolder dataholder
, String prefix
,Document document
, TaxonXImport taxonXImport
,
31 TaxonXImportState taxonXstate
, Classification classif
, Map
<String
,Feature
> featuresMap
){
33 this.importer
= taxonXImport
;
34 this.nomenclaturalCode
= taxonXstate
.getConfig().getNomenclaturalCode();
35 this.classification
= classif
;
36 logger
.info("CLASSIFICATION "+classification
);
37 this.taxonXstate
=taxonXstate
;
38 modsextractor
= new TaxonXModsExtractor(importer
);
39 Reference
<?
> originalSourceUrl
=taxonXstate
.getConfig().getOriginalSourceURL();
40 treatmentextractor
= new TaxonXTreatmentExtractor(nomenclaturalCode
,classification
,importer
, taxonXstate
,featuresMap
,originalSourceUrl
);
45 * parse the Mods from the TaxonX file
47 *@return the created Reference object
49 public Reference
<?
> parseMods(){
50 // System.out.println("PARSEMODS");
52 Node root
= doc
.getFirstChild();
55 //taxonHeader, taxonBody
56 NodeList nodes
= root
.getChildNodes();
57 Reference
<?
> ref
= null;
58 for (int i
=0; i
< nodes
.getLength();i
++) {
59 // System.out.println(nodes.item(i).getNodeName());
60 if (nodes
.item(i
).getNodeName().equalsIgnoreCase("tax:taxonxheader")){
61 NodeList nodes2
= nodes
.item(i
).getChildNodes();
62 for (int j
=0; j
< nodes2
.getLength();j
++){
63 if (nodes2
.item(j
).getNodeName().equalsIgnoreCase("mods:mods")){
64 ref
= modsextractor
.extractMods(nodes2
.item(j
));
65 importer
.getReferenceService().saveOrUpdate(ref
);
71 taxonXstate
.getConfig().setClassificationName(ref
.getCitation());
73 taxonXstate
.getConfig().setClassificationName("no reference title");
75 ref
=CdmBase
.deproxy(ref
, Reference
.class);
81 * Foreach treatment section, launches the treatment "extractor"
82 * @param ref : the current reference, extracted from the mods
83 * @param sourcename: the URI of the TaxonX document
85 public void parseTreatment(Reference
<?
> ref
, URI sourceName
){
86 System
.out
.println("PARSETREATMENT "+ref
);
88 Node root
= doc
.getFirstChild();
89 //taxonHeader, taxonBody
90 NodeList nodes
= root
.getChildNodes();
92 for ( int i
=0; i
< nodes
.getLength();i
++) {
93 // System.out.println(nodes.item(i).getNodeName());
94 if (nodes
.item(i
).getNodeName().equalsIgnoreCase("tax:taxonxBody")){
95 NodeList nodes2
= nodes
.item(i
).getChildNodes();
96 for (int j
=0; j
< nodes2
.getLength();j
++){
97 if (nodes2
.item(j
).getNodeName().equalsIgnoreCase("tax:treatment")){
99 treatmentextractor
.extractTreatment(nodes2
.item(j
), ref
,sourceName
);
100 } catch (Exception e
) {
101 logger
.error("Unhandled exception occurred in treatment. Treatment not fully imported.");
113 * updates the classification in the treatment extractor
114 * @param classification2
116 public void updateClassification(Classification classification2
) {
117 //System.out.println("UPDATECLASSIFICATIONS "+classification2);
118 classification
=classification2
;
119 if (treatmentextractor
!= null) {
120 treatmentextractor
.updateClassification(classification
);
129 public Map
<String
,Feature
> getFeaturesUsed() {
130 return treatmentextractor
.getFeaturesUsed();