1 package eu
.etaxonomy
.cdm
.io
.taxonx2013
;
4 import java
.util
.ArrayList
;
7 import org
.apache
.log4j
.Logger
;
8 import org
.w3c
.dom
.Document
;
9 import org
.w3c
.dom
.Node
;
10 import org
.w3c
.dom
.NodeList
;
12 import eu
.etaxonomy
.cdm
.model
.name
.NomenclaturalCode
;
13 import eu
.etaxonomy
.cdm
.model
.reference
.Reference
;
14 import eu
.etaxonomy
.cdm
.model
.taxon
.Classification
;
16 public class TaxonXXMLFieldGetter
{
18 private static final Logger logger
= Logger
.getLogger(TaxonXXMLFieldGetter
.class);
19 private final Document doc
;
22 private final NomenclaturalCode nomenclaturalCode
;
23 private Classification classification
;
24 private final TaxonXImport importer
;
25 private final TaxonXImportState taxonXstate
;
26 TaxonXModsExtractor modsextractor
;
27 TaxonXTreatmentExtractor treatmentextractor
;
29 public TaxonXXMLFieldGetter(TaxonXDataHolder dataholder
, String prefix
,Document document
, TaxonXImport taxonXImport
, TaxonXImportState taxonXstate
, Classification classif
){
31 this.importer
= taxonXImport
;
32 this.nomenclaturalCode
= taxonXstate
.getConfig().getNomenclaturalCode();
33 this.classification
= classif
;
34 logger
.info("CLASSIFICATION "+classification
);
35 this.taxonXstate
=taxonXstate
;
36 modsextractor
= new TaxonXModsExtractor(importer
);
37 treatmentextractor
= new TaxonXTreatmentExtractor(nomenclaturalCode
,classification
,importer
, taxonXstate
);
42 * parse the Mods from the TaxonX file
44 *@return the created Reference object
46 public Reference
<?
> parseMods(){
47 // System.out.println("PARSEMODS");
49 Node root
= doc
.getFirstChild();
52 //taxonHeader, taxonBody
53 NodeList nodes
= root
.getChildNodes();
54 Reference
<?
> ref
= null;
55 for (int i
=0; i
< nodes
.getLength();i
++) {
56 // System.out.println(nodes.item(i).getNodeName());
57 if (nodes
.item(i
).getNodeName().equalsIgnoreCase("tax:taxonxheader")){
58 NodeList nodes2
= nodes
.item(i
).getChildNodes();
59 for (int j
=0; j
< nodes2
.getLength();j
++){
60 // System.out.println("nodes2 : "+nodes2.item(j).getNodeName());
61 if (nodes2
.item(j
).getNodeName().equalsIgnoreCase("mods:mods")){
62 ref
= modsextractor
.extractMods(nodes2
.item(j
));
63 // System.out.println("reference: "+ref.getTitleCache());
64 importer
.getReferenceService().saveOrUpdate(ref
);
70 taxonXstate
.getConfig().setClassificationName(ref
.getCitation());
72 taxonXstate
.getConfig().setClassificationName( "no reference title");
79 * Foreach treatment section, launches the treatment "extractor"
80 * @param ref : the current reference, extracted from the mods
81 * @param sourcename: the URI of the TaxonX document
83 public void parseTreatment(Reference
<?
> ref
, URI sourceName
){
84 System
.out
.println("PARSETREATMENT "+ref
);
86 Node root
= doc
.getFirstChild();
87 //taxonHeader, taxonBody
88 NodeList nodes
= root
.getChildNodes();
90 for (int i
=0; i
< nodes
.getLength();i
++) {
91 // System.out.println(nodes.item(i).getNodeName());
92 if (nodes
.item(i
).getNodeName().equalsIgnoreCase("tax:taxonxBody")){
93 NodeList nodes2
= nodes
.item(i
).getChildNodes();
94 for (int j
=0; j
< nodes2
.getLength();j
++){
95 if (nodes2
.item(j
).getNodeName().equalsIgnoreCase("tax:treatment")){
96 List
<Object
> tosave
= new ArrayList
<Object
>();
97 treatmentextractor
.extractTreatment(nodes2
.item(j
),tosave
,ref
,sourceName
);
107 * updates the classification in the treatment extractor
108 * @param classification2
110 public void updateClassification(Classification classification2
) {
111 System
.out
.println("UPDATECLASSIFICATIONS "+classification2
);
112 classification
=classification2
;
113 if (treatmentextractor
!= null) {
114 treatmentextractor
.updateClassification(classification
);