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.lang.reflect.Method;
|
19
|
import java.net.MalformedURLException;
|
20
|
import java.net.URI;
|
21
|
import java.net.URL;
|
22
|
|
23
|
import org.apache.log4j.Logger;
|
24
|
import org.jdom.Element;
|
25
|
import org.jdom.Namespace;
|
26
|
import org.springframework.stereotype.Component;
|
27
|
|
28
|
import eu.etaxonomy.cdm.common.XmlHelp;
|
29
|
import eu.etaxonomy.cdm.database.ICdmDataSource;
|
30
|
import eu.etaxonomy.cdm.io.common.IImportConfigurator;
|
31
|
import eu.etaxonomy.cdm.io.common.ImportConfiguratorBase;
|
32
|
import eu.etaxonomy.cdm.io.common.mapping.IInputTransformer;
|
33
|
import eu.etaxonomy.cdm.io.tcsxml.DefaultTcsXmlPlaceholders;
|
34
|
import eu.etaxonomy.cdm.io.tcsxml.ITcsXmlPlaceholderClass;
|
35
|
import eu.etaxonomy.cdm.model.reference.Reference;
|
36
|
import eu.etaxonomy.cdm.model.reference.ReferenceFactory;
|
37
|
|
38
|
@Component
|
39
|
public class BfnXmlImportConfigurator extends ImportConfiguratorBase<BfnXmlImportState, URI> implements IImportConfigurator {
|
40
|
private static final Logger logger = Logger.getLogger(BfnXmlImportConfigurator.class);
|
41
|
|
42
|
//TODO
|
43
|
private static IInputTransformer defaultTransformer = null;
|
44
|
|
45
|
|
46
|
private boolean doMetaData = true;
|
47
|
private boolean doSpecimen = true;
|
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
|
// //references
|
63
|
private DO_REFERENCES doReferences = DO_REFERENCES.ALL;
|
64
|
// //names
|
65
|
private boolean doTaxonNames = true;
|
66
|
private boolean doRelNames = true;
|
67
|
// //taxa
|
68
|
private boolean doTaxa = true;
|
69
|
private boolean doRelTaxa = true;
|
70
|
|
71
|
|
72
|
|
73
|
private Method functionMetaDataDetailed = null;
|
74
|
private ITcsXmlPlaceholderClass placeholderClass;
|
75
|
|
76
|
// rdfNamespace
|
77
|
Namespace bfnXmlNamespace;
|
78
|
|
79
|
protected static Namespace nsTcsXml = Namespace.getNamespace("http://www.tdwg.org/schemas/tcs/1.01");
|
80
|
|
81
|
@SuppressWarnings("unchecked")
|
82
|
protected void makeIoClassList(){
|
83
|
ioClassList = new Class[]{
|
84
|
BfnXmlImportMetaData.class,
|
85
|
BfnXmlImportFeature.class,
|
86
|
BfnXmlImportTaxonName.class
|
87
|
};
|
88
|
};
|
89
|
|
90
|
public static BfnXmlImportConfigurator NewInstance(URI uri,
|
91
|
ICdmDataSource destination){
|
92
|
return new BfnXmlImportConfigurator(uri, destination);
|
93
|
}
|
94
|
|
95
|
/**
|
96
|
* @param berlinModelSource
|
97
|
* @param sourceReference
|
98
|
* @param destination
|
99
|
*/
|
100
|
private BfnXmlImportConfigurator() {
|
101
|
super(defaultTransformer);
|
102
|
// setSource(url);
|
103
|
// setDestination(destination);
|
104
|
}
|
105
|
|
106
|
/**
|
107
|
* @param berlinModelSource
|
108
|
* @param sourceReference
|
109
|
* @param destination
|
110
|
*/
|
111
|
private BfnXmlImportConfigurator(URI uri, ICdmDataSource destination) {
|
112
|
super(defaultTransformer);
|
113
|
setSource(uri);
|
114
|
setDestination(destination);
|
115
|
}
|
116
|
|
117
|
|
118
|
|
119
|
/* (non-Javadoc)
|
120
|
* @see eu.etaxonomy.cdm.io.common.IImportConfigurator#getNewState()
|
121
|
*/
|
122
|
public BfnXmlImportState getNewState() {
|
123
|
return new BfnXmlImportState(this);
|
124
|
}
|
125
|
|
126
|
/* (non-Javadoc)
|
127
|
* @see eu.etaxonomy.cdm.io.common.ImportConfiguratorBase#getSource()
|
128
|
*/
|
129
|
public URI getSource() {
|
130
|
return (URI)super.getSource();
|
131
|
}
|
132
|
|
133
|
/**
|
134
|
* @param file
|
135
|
*/
|
136
|
public void setSource(URI uri) {
|
137
|
super.setSource(uri);
|
138
|
}
|
139
|
|
140
|
/**
|
141
|
* @return
|
142
|
*/
|
143
|
public Element getSourceRoot(){
|
144
|
URI source = getSource();
|
145
|
try {
|
146
|
URL url;
|
147
|
url = source.toURL();
|
148
|
Object o = url.getContent();
|
149
|
InputStream is = (InputStream)o;
|
150
|
Element root = XmlHelp.getRoot(is);
|
151
|
makeNamespaces(root);
|
152
|
return root;
|
153
|
} catch (MalformedURLException e) {
|
154
|
e.printStackTrace();
|
155
|
}catch (Exception e) {
|
156
|
// TODO Auto-generated catch block
|
157
|
e.printStackTrace();
|
158
|
}
|
159
|
return null;
|
160
|
}
|
161
|
|
162
|
private boolean makeNamespaces(Element root){
|
163
|
bfnXmlNamespace = root.getNamespace();
|
164
|
if (bfnXmlNamespace == null
|
165
|
/**|| tcNamespace == null
|
166
|
* || tnNamespace == null
|
167
|
* || commonNamespace == null
|
168
|
* || geoNamespace == null
|
169
|
* || publicationNamespace == null*/){
|
170
|
logger.warn("At least one Namespace is NULL");
|
171
|
}
|
172
|
return true;
|
173
|
}
|
174
|
|
175
|
|
176
|
/* (non-Javadoc)
|
177
|
* @see eu.etaxonomy.cdm.io.common.ImportConfiguratorBase#getSourceReference()
|
178
|
*/
|
179
|
@Override
|
180
|
public Reference getSourceReference() {
|
181
|
//TODO
|
182
|
if (this.sourceReference == null){
|
183
|
logger.warn("getSource Reference not yet fully implemented");
|
184
|
sourceReference = ReferenceFactory.newDatabase();
|
185
|
sourceReference.setTitleCache("", true);
|
186
|
}
|
187
|
return sourceReference;
|
188
|
}
|
189
|
|
190
|
|
191
|
/* (non-Javadoc)
|
192
|
* @see eu.etaxonomy.cdm.io.common.IImportConfigurator#getSourceNameString()
|
193
|
*/
|
194
|
public String getSourceNameString() {
|
195
|
if (this.getSource() == null){
|
196
|
return null;
|
197
|
}else{
|
198
|
return this.getSource().toString();
|
199
|
}
|
200
|
}
|
201
|
|
202
|
public Namespace getBfnXmlNamespace() {
|
203
|
return bfnXmlNamespace;
|
204
|
}
|
205
|
|
206
|
public void setBfnXmlNamespace(Namespace bfnXmlNamespace) {
|
207
|
this.bfnXmlNamespace = bfnXmlNamespace;
|
208
|
}
|
209
|
|
210
|
/**
|
211
|
* @param funMetaDataDetailed the funMetaDataDetailed to set
|
212
|
*/
|
213
|
public void setFunctionMetaDataDetailed(Method functionMetaDataDetailed) {
|
214
|
this.functionMetaDataDetailed = functionMetaDataDetailed;
|
215
|
}
|
216
|
|
217
|
public DO_REFERENCES getDoReferences() {
|
218
|
return doReferences;
|
219
|
}
|
220
|
public void setDoReferences(DO_REFERENCES doReferences) {
|
221
|
this.doReferences = doReferences;
|
222
|
}
|
223
|
|
224
|
public boolean isDoTaxonNames() {
|
225
|
return doTaxonNames;
|
226
|
}
|
227
|
public void setDoTaxonNames(boolean doTaxonNames) {
|
228
|
this.doTaxonNames = doTaxonNames;
|
229
|
}
|
230
|
|
231
|
public boolean isDoTaxa() {
|
232
|
return doTaxa;
|
233
|
}
|
234
|
public void setDoTaxa(boolean doTaxa) {
|
235
|
this.doTaxa = doTaxa;
|
236
|
}
|
237
|
|
238
|
public boolean isDoRelTaxa() {
|
239
|
return doRelTaxa;
|
240
|
}
|
241
|
public void setDoRelTaxa(boolean doRelTaxa) {
|
242
|
this.doRelTaxa = doRelTaxa;
|
243
|
}
|
244
|
|
245
|
/**
|
246
|
* Import name relationships yes/no?.
|
247
|
* @return
|
248
|
*/
|
249
|
public boolean isDoRelNames() {
|
250
|
return doRelNames;
|
251
|
}
|
252
|
public void setDoRelNames(boolean doRelNames) {
|
253
|
this.doRelNames = doRelNames;
|
254
|
}
|
255
|
|
256
|
/**
|
257
|
* @return the doMetaData
|
258
|
*/
|
259
|
public boolean isDoMetaData() {
|
260
|
return doMetaData;
|
261
|
}
|
262
|
|
263
|
/**
|
264
|
* @param doMetaData the doMetaData to set
|
265
|
*/
|
266
|
public void setDoMetaData(boolean doMetaData) {
|
267
|
this.doMetaData = doMetaData;
|
268
|
}
|
269
|
|
270
|
|
271
|
/**
|
272
|
* @return the doSpecimen
|
273
|
*/
|
274
|
public boolean isDoSpecimen() {
|
275
|
return doSpecimen;
|
276
|
}
|
277
|
|
278
|
/**
|
279
|
* @param doSpecimen the doSpecimen to set
|
280
|
*/
|
281
|
public void setDoSpecimen(boolean doSpecimen) {
|
282
|
this.doSpecimen = doSpecimen;
|
283
|
}
|
284
|
|
285
|
/**
|
286
|
* @return the placeholderClass
|
287
|
*/
|
288
|
public ITcsXmlPlaceholderClass getPlaceholderClass() {
|
289
|
if (placeholderClass == null){
|
290
|
placeholderClass = new DefaultTcsXmlPlaceholders();
|
291
|
}
|
292
|
return placeholderClass;
|
293
|
}
|
294
|
|
295
|
/**
|
296
|
* @param placeholderClass the placeholderClass to set
|
297
|
*/
|
298
|
public void setPlaceholderClass(ITcsXmlPlaceholderClass placeholderClass) {
|
299
|
this.placeholderClass = placeholderClass;
|
300
|
}
|
301
|
|
302
|
public boolean isDoInformationImport() {
|
303
|
return doInformationImport;
|
304
|
}
|
305
|
|
306
|
public void setDoInformationImport(boolean doInformationImport) {
|
307
|
this.doInformationImport = doInformationImport;
|
308
|
}
|
309
|
|
310
|
public boolean isHasSecondList() {
|
311
|
return hasSecondList;
|
312
|
}
|
313
|
|
314
|
public void setHasSecondList(boolean hasSecondList) {
|
315
|
this.hasSecondList = hasSecondList;
|
316
|
}
|
317
|
|
318
|
|
319
|
}
|