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