1
|
/**
|
2
|
* Copyright (C) 2009 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
|
|
10
|
package eu.etaxonomy.cdm.io.redlist.bfnXml;
|
11
|
|
12
|
/**
|
13
|
* @author a.oppermann
|
14
|
* @date 03.07.2013
|
15
|
*
|
16
|
*/
|
17
|
import java.io.InputStream;
|
18
|
import java.net.MalformedURLException;
|
19
|
import java.net.URI;
|
20
|
import java.net.URL;
|
21
|
|
22
|
import org.apache.log4j.Logger;
|
23
|
import org.jdom.Element;
|
24
|
import org.jdom.Namespace;
|
25
|
import org.springframework.stereotype.Component;
|
26
|
|
27
|
import eu.etaxonomy.cdm.common.XmlHelp;
|
28
|
import eu.etaxonomy.cdm.database.ICdmDataSource;
|
29
|
import eu.etaxonomy.cdm.io.common.ImportConfiguratorBase;
|
30
|
import eu.etaxonomy.cdm.io.common.mapping.IInputTransformer;
|
31
|
import eu.etaxonomy.cdm.model.name.NomenclaturalCode;
|
32
|
import eu.etaxonomy.cdm.model.reference.Reference;
|
33
|
import eu.etaxonomy.cdm.model.reference.ReferenceFactory;
|
34
|
|
35
|
@Component
|
36
|
public class BfnXmlImportConfigurator extends ImportConfiguratorBase<BfnXmlImportState, URI> {
|
37
|
private static final Logger logger = Logger.getLogger(BfnXmlImportConfigurator.class);
|
38
|
|
39
|
//TODO
|
40
|
private static IInputTransformer defaultTransformer = null;
|
41
|
|
42
|
|
43
|
private boolean doMetaData = true;
|
44
|
private boolean doTaxonNames = true;
|
45
|
private boolean doFeature = true;
|
46
|
private boolean doAdditionalTerms = true;
|
47
|
|
48
|
private boolean doInformationImport = true;
|
49
|
private boolean fillSecondList = false;
|
50
|
private boolean hasSecondList = false;
|
51
|
|
52
|
|
53
|
|
54
|
public boolean isFillSecondList() {
|
55
|
return fillSecondList;
|
56
|
}
|
57
|
|
58
|
public void setFillSecondList(boolean fillSecondList) {
|
59
|
this.fillSecondList = fillSecondList;
|
60
|
}
|
61
|
|
62
|
|
63
|
// rdfNamespace
|
64
|
Namespace bfnXmlNamespace;
|
65
|
|
66
|
private NomenclaturalCode nomenclaturalCode = null;
|
67
|
|
68
|
@SuppressWarnings("unchecked")
|
69
|
@Override
|
70
|
protected void makeIoClassList(){
|
71
|
ioClassList = new Class[]{
|
72
|
BfnXmlImportAddtionalTerms.class,
|
73
|
BfnXmlImportMetaData.class,
|
74
|
BfnXmlImportFeature.class,
|
75
|
BfnXmlImportTaxonName.class
|
76
|
};
|
77
|
};
|
78
|
|
79
|
public static BfnXmlImportConfigurator NewInstance(URI uri,
|
80
|
ICdmDataSource destination){
|
81
|
return new BfnXmlImportConfigurator(uri, destination);
|
82
|
}
|
83
|
|
84
|
/**
|
85
|
* @param berlinModelSource
|
86
|
* @param sourceReference
|
87
|
* @param destination
|
88
|
*/
|
89
|
private BfnXmlImportConfigurator() {
|
90
|
super(defaultTransformer);
|
91
|
}
|
92
|
|
93
|
/**
|
94
|
* @param berlinModelSource
|
95
|
* @param sourceReference
|
96
|
* @param destination
|
97
|
*/
|
98
|
private BfnXmlImportConfigurator(URI uri, ICdmDataSource destination) {
|
99
|
super(defaultTransformer);
|
100
|
setSource(uri);
|
101
|
setDestination(destination);
|
102
|
}
|
103
|
|
104
|
|
105
|
@Override
|
106
|
public BfnXmlImportState getNewState() {
|
107
|
return new BfnXmlImportState(this);
|
108
|
}
|
109
|
|
110
|
/**
|
111
|
* @return
|
112
|
*/
|
113
|
public Element getSourceRoot(){
|
114
|
URI source = getSource();
|
115
|
try {
|
116
|
URL url;
|
117
|
url = source.toURL();
|
118
|
Object o = url.getContent();
|
119
|
InputStream is = (InputStream)o;
|
120
|
Element root = XmlHelp.getRoot(is);
|
121
|
makeNamespaces(root);
|
122
|
return root;
|
123
|
} catch (MalformedURLException e) {
|
124
|
e.printStackTrace();
|
125
|
}catch (Exception e) {
|
126
|
// TODO Auto-generated catch block
|
127
|
e.printStackTrace();
|
128
|
}
|
129
|
return null;
|
130
|
}
|
131
|
|
132
|
private boolean makeNamespaces(Element root){
|
133
|
bfnXmlNamespace = root.getNamespace();
|
134
|
if (bfnXmlNamespace == null
|
135
|
/**|| tcNamespace == null
|
136
|
* || tnNamespace == null
|
137
|
* || commonNamespace == null
|
138
|
* || geoNamespace == null
|
139
|
* || publicationNamespace == null*/){
|
140
|
logger.warn("At least one Namespace is NULL");
|
141
|
}
|
142
|
return true;
|
143
|
}
|
144
|
|
145
|
@Override
|
146
|
public Reference getSourceReference() {
|
147
|
//TODO
|
148
|
if (this.sourceReference == null){
|
149
|
logger.warn("getSource Reference not yet fully implemented");
|
150
|
sourceReference = ReferenceFactory.newDatabase();
|
151
|
sourceReference.setTitleCache("", true);
|
152
|
}
|
153
|
return sourceReference;
|
154
|
}
|
155
|
|
156
|
@Override
|
157
|
public String getSourceNameString() {
|
158
|
if (this.getSource() == null){
|
159
|
return null;
|
160
|
}else{
|
161
|
return this.getSource().toString();
|
162
|
}
|
163
|
}
|
164
|
|
165
|
public Namespace getBfnXmlNamespace() {
|
166
|
return bfnXmlNamespace;
|
167
|
}
|
168
|
|
169
|
public void setBfnXmlNamespace(Namespace bfnXmlNamespace) {
|
170
|
this.bfnXmlNamespace = bfnXmlNamespace;
|
171
|
}
|
172
|
|
173
|
public boolean isDoTaxonNames() {
|
174
|
return doTaxonNames;
|
175
|
}
|
176
|
public void setDoTaxonNames(boolean doTaxonNames) {
|
177
|
this.doTaxonNames = doTaxonNames;
|
178
|
}
|
179
|
|
180
|
/**
|
181
|
* @return the doMetaData
|
182
|
*/
|
183
|
public boolean isDoMetaData() {
|
184
|
return doMetaData;
|
185
|
}
|
186
|
|
187
|
/**
|
188
|
* @param doMetaData the doMetaData to set
|
189
|
*/
|
190
|
public void setDoMetaData(boolean doMetaData) {
|
191
|
this.doMetaData = doMetaData;
|
192
|
}
|
193
|
|
194
|
|
195
|
public boolean isDoInformationImport() {
|
196
|
return doInformationImport;
|
197
|
}
|
198
|
|
199
|
public void setDoInformationImport(boolean doInformationImport) {
|
200
|
this.doInformationImport = doInformationImport;
|
201
|
}
|
202
|
|
203
|
public boolean isHasSecondList() {
|
204
|
return hasSecondList;
|
205
|
}
|
206
|
|
207
|
public void setHasSecondList(boolean hasSecondList) {
|
208
|
this.hasSecondList = hasSecondList;
|
209
|
}
|
210
|
|
211
|
public void setNomenclaturalCode(NomenclaturalCode nomenclaturalCode) {
|
212
|
this.nomenclaturalCode = nomenclaturalCode;
|
213
|
}
|
214
|
|
215
|
@Override
|
216
|
public NomenclaturalCode getNomenclaturalCode(){
|
217
|
return nomenclaturalCode;
|
218
|
}
|
219
|
|
220
|
/**
|
221
|
* @return the doFeature
|
222
|
*/
|
223
|
public boolean isDoFeature() {
|
224
|
return doFeature;
|
225
|
}
|
226
|
|
227
|
|
228
|
/**
|
229
|
* @param doFeature the doFeature to set
|
230
|
*/
|
231
|
public void setDoFeature(boolean doFeature) {
|
232
|
this.doFeature = doFeature;
|
233
|
}
|
234
|
|
235
|
/**
|
236
|
* @return the doAdditionalTerms
|
237
|
*/
|
238
|
public boolean isDoAdditionalTerms() {
|
239
|
return doAdditionalTerms;
|
240
|
}
|
241
|
|
242
|
/**
|
243
|
* @param doAdditionalTerms the doAdditionalTerms to set
|
244
|
*/
|
245
|
public void setDoAdditionalTerms(boolean doAdditionalTerms) {
|
246
|
this.doAdditionalTerms = doAdditionalTerms;
|
247
|
}
|
248
|
}
|