1 package eu
.etaxonomy
.cdm
.io
.taxonx2013
;
4 import java
.util
.ArrayList
;
8 import org
.apache
.log4j
.Logger
;
9 import org
.w3c
.dom
.Document
;
10 import org
.w3c
.dom
.Node
;
11 import org
.w3c
.dom
.NodeList
;
13 import eu
.etaxonomy
.cdm
.model
.common
.CdmBase
;
14 import eu
.etaxonomy
.cdm
.model
.description
.Feature
;
15 import eu
.etaxonomy
.cdm
.model
.name
.NomenclaturalCode
;
16 import eu
.etaxonomy
.cdm
.model
.reference
.Reference
;
17 import eu
.etaxonomy
.cdm
.model
.taxon
.Classification
;
19 public class TaxonXXMLFieldGetter
{
21 private static final Logger logger
= Logger
.getLogger(TaxonXXMLFieldGetter
.class);
22 private final Document doc
;
25 private final NomenclaturalCode nomenclaturalCode
;
26 private Classification classification
;
27 private final TaxonXImport importer
;
28 private final TaxonXImportState taxonXstate
;
29 TaxonXModsExtractor modsextractor
;
30 TaxonXTreatmentExtractor treatmentextractor
;
32 public TaxonXXMLFieldGetter(TaxonXDataHolder dataholder
, String prefix
,Document document
, TaxonXImport taxonXImport
,
33 TaxonXImportState taxonXstate
, Classification classif
, Map
<String
,Feature
> featuresMap
){
35 this.importer
= taxonXImport
;
36 this.nomenclaturalCode
= taxonXstate
.getConfig().getNomenclaturalCode();
37 this.classification
= classif
;
38 logger
.info("CLASSIFICATION "+classification
);
39 this.taxonXstate
=taxonXstate
;
40 modsextractor
= new TaxonXModsExtractor(importer
);
41 Reference
<?
> originalSourceUrl
=taxonXstate
.getConfig().getOriginalSourceURL();
42 treatmentextractor
= new TaxonXTreatmentExtractor(nomenclaturalCode
,classification
,importer
, taxonXstate
,featuresMap
,originalSourceUrl
);
47 * parse the Mods from the TaxonX file
49 *@return the created Reference object
51 public Reference
<?
> parseMods(){
52 // System.out.println("PARSEMODS");
54 Node root
= doc
.getFirstChild();
57 //taxonHeader, taxonBody
58 NodeList nodes
= root
.getChildNodes();
59 Reference
<?
> ref
= null;
60 for (int i
=0; i
< nodes
.getLength();i
++) {
61 // System.out.println(nodes.item(i).getNodeName());
62 if (nodes
.item(i
).getNodeName().equalsIgnoreCase("tax:taxonxheader")){
63 NodeList nodes2
= nodes
.item(i
).getChildNodes();
64 for (int j
=0; j
< nodes2
.getLength();j
++){
65 // System.out.println("nodes2 : "+nodes2.item(j).getNodeName());
66 if (nodes2
.item(j
).getNodeName().equalsIgnoreCase("mods:mods")){
67 ref
= modsextractor
.extractMods(nodes2
.item(j
));
68 // System.out.println("reference: "+ref.getTitleCache());
69 importer
.getReferenceService().saveOrUpdate(ref
);
70 ref
=CdmBase
.deproxy(ref
, Reference
.class);
76 taxonXstate
.getConfig().setClassificationName(ref
.getCitation());
78 taxonXstate
.getConfig().setClassificationName( "no reference title");
80 ref
=CdmBase
.deproxy(ref
, Reference
.class);
86 * Foreach treatment section, launches the treatment "extractor"
87 * @param ref : the current reference, extracted from the mods
88 * @param sourcename: the URI of the TaxonX document
90 public void parseTreatment(Reference
<?
> ref
, URI sourceName
){
91 System
.out
.println("PARSETREATMENT "+ref
);
93 Node root
= doc
.getFirstChild();
94 //taxonHeader, taxonBody
95 NodeList nodes
= root
.getChildNodes();
97 for ( int i
=0; i
< nodes
.getLength();i
++) {
98 // System.out.println(nodes.item(i).getNodeName());
99 if (nodes
.item(i
).getNodeName().equalsIgnoreCase("tax:taxonxBody")){
100 NodeList nodes2
= nodes
.item(i
).getChildNodes();
101 for (int j
=0; j
< nodes2
.getLength();j
++){
102 if (nodes2
.item(j
).getNodeName().equalsIgnoreCase("tax:treatment")){
103 List
<Object
> tosave
= new ArrayList
<Object
>();
104 treatmentextractor
.extractTreatment(nodes2
.item(j
),tosave
,ref
,sourceName
);
114 * updates the classification in the treatment extractor
115 * @param classification2
117 public void updateClassification(Classification classification2
) {
118 //System.out.println("UPDATECLASSIFICATIONS "+classification2);
119 classification
=classification2
;
120 if (treatmentextractor
!= null) {
121 treatmentextractor
.updateClassification(classification
);
130 public Map
<String
,Feature
> getFeaturesUsed() {
131 return treatmentextractor
.getFeaturesUsed();