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
.taxonx2013
;
13 import org
.apache
.logging
.log4j
.LogManager
;
14 import org
.apache
.logging
.log4j
.Logger
;
15 import org
.w3c
.dom
.Document
;
16 import org
.w3c
.dom
.Node
;
17 import org
.w3c
.dom
.NodeList
;
19 import eu
.etaxonomy
.cdm
.common
.URI
;
20 import eu
.etaxonomy
.cdm
.model
.common
.CdmBase
;
21 import eu
.etaxonomy
.cdm
.model
.description
.Feature
;
22 import eu
.etaxonomy
.cdm
.model
.name
.NomenclaturalCode
;
23 import eu
.etaxonomy
.cdm
.model
.reference
.Reference
;
24 import eu
.etaxonomy
.cdm
.model
.taxon
.Classification
;
26 public class TaxonXXMLFieldGetter
{
28 private static final Logger logger
= LogManager
.getLogger();
30 private final Document doc
;
32 private final NomenclaturalCode nomenclaturalCode
;
33 private Classification classification
;
34 private final TaxonXImport importer
;
35 private final TaxonXImportState taxonXstate
;
36 private TaxonXModsExtractor modsextractor
;
37 private TaxonXTreatmentExtractor treatmentextractor
;
39 public TaxonXXMLFieldGetter(TaxonXDataHolder dataholder
, String prefix
,Document document
, TaxonXImport taxonXImport
,
40 TaxonXImportState taxonXstate
, Classification classif
, Map
<String
,Feature
> featuresMap
){
42 this.importer
= taxonXImport
;
43 this.nomenclaturalCode
= taxonXstate
.getConfig().getNomenclaturalCode();
44 this.classification
= classif
;
45 logger
.info("CLASSIFICATION "+classification
);
46 this.taxonXstate
=taxonXstate
;
47 modsextractor
= new TaxonXModsExtractor(importer
);
48 Reference originalSourceUrl
=taxonXstate
.getConfig().getOriginalSourceURL();
49 treatmentextractor
= new TaxonXTreatmentExtractor(nomenclaturalCode
,classification
,importer
, taxonXstate
,featuresMap
,originalSourceUrl
);
54 * parse the Mods from the TaxonX file
56 *@return the created Reference object
58 public Reference
parseMods(){
59 // System.out.println("PARSEMODS");
61 Node root
= doc
.getFirstChild();
64 //taxonHeader, taxonBody
65 NodeList nodes
= root
.getChildNodes();
67 for (int i
=0; i
< nodes
.getLength();i
++) {
68 // System.out.println(nodes.item(i).getNodeName());
69 if (nodes
.item(i
).getNodeName().equalsIgnoreCase("tax:taxonxheader")){
70 NodeList nodes2
= nodes
.item(i
).getChildNodes();
71 for (int j
=0; j
< nodes2
.getLength();j
++){
72 if (nodes2
.item(j
).getNodeName().equalsIgnoreCase("mods:mods")){
73 ref
= modsextractor
.extractMods(nodes2
.item(j
));
74 importer
.getReferenceService().saveOrUpdate(ref
);
80 taxonXstate
.getConfig().setClassificationName(ref
.getCitation());
82 taxonXstate
.getConfig().setClassificationName("no reference title");
84 ref
=CdmBase
.deproxy(ref
, Reference
.class);
90 * Foreach treatment section, launches the treatment "extractor"
91 * @param ref : the current reference, extracted from the mods
92 * @param sourcename: the URI of the TaxonX document
94 public void parseTreatment(Reference ref
, URI sourceName
){
95 System
.out
.println("PARSETREATMENT "+ref
);
97 Node root
= doc
.getFirstChild();
98 //taxonHeader, taxonBody
99 NodeList nodes
= root
.getChildNodes();
101 for ( int i
=0; i
< nodes
.getLength();i
++) {
102 // System.out.println(nodes.item(i).getNodeName());
103 if (nodes
.item(i
).getNodeName().equalsIgnoreCase("tax:taxonxBody")){
104 NodeList nodes2
= nodes
.item(i
).getChildNodes();
105 for (int j
=0; j
< nodes2
.getLength();j
++){
106 if (nodes2
.item(j
).getNodeName().equalsIgnoreCase("tax:treatment")){
108 treatmentextractor
.extractTreatment(nodes2
.item(j
), ref
,sourceName
);
109 } catch (Exception e
) {
110 logger
.error("Unhandled exception occurred in treatment. Treatment not fully imported.");
122 * updates the classification in the treatment extractor
123 * @param classification2
125 public void updateClassification(Classification classification2
) {
126 //System.out.println("UPDATECLASSIFICATIONS "+classification2);
127 classification
=classification2
;
128 if (treatmentextractor
!= null) {
129 treatmentextractor
.updateClassification(classification
);
138 public Map
<String
,Feature
> getFeaturesUsed() {
139 return treatmentextractor
.getFeaturesUsed();