1
|
/**
|
2
|
* Copyright (C) 2007 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.tcsrdf;
|
11
|
|
12
|
import java.io.InputStream;
|
13
|
import java.net.MalformedURLException;
|
14
|
import java.net.URI;
|
15
|
import java.net.URL;
|
16
|
import java.util.Map;
|
17
|
|
18
|
import org.apache.log4j.Logger;
|
19
|
import org.jdom.Element;
|
20
|
import org.jdom.Namespace;
|
21
|
|
22
|
import com.hp.hpl.jena.rdf.model.Model;
|
23
|
import com.hp.hpl.jena.rdf.model.ModelFactory;
|
24
|
|
25
|
import eu.etaxonomy.cdm.common.XmlHelp;
|
26
|
import eu.etaxonomy.cdm.database.ICdmDataSource;
|
27
|
import eu.etaxonomy.cdm.io.common.IImportConfigurator;
|
28
|
import eu.etaxonomy.cdm.io.common.ImportConfiguratorBase;
|
29
|
import eu.etaxonomy.cdm.io.common.mapping.IInputTransformer;
|
30
|
import eu.etaxonomy.cdm.model.reference.Reference;
|
31
|
import eu.etaxonomy.cdm.model.reference.ReferenceFactory;
|
32
|
|
33
|
/**
|
34
|
* @author a.mueller
|
35
|
* @since 29.05.2008
|
36
|
*/
|
37
|
public class TcsRdfImportConfigurator extends ImportConfiguratorBase<TcsRdfImportState, URI> implements IImportConfigurator {
|
38
|
|
39
|
private static final long serialVersionUID = -8987364078779275820L;
|
40
|
|
41
|
|
42
|
private static final Logger logger = Logger.getLogger(TcsRdfImportConfigurator.class);
|
43
|
|
44
|
|
45
|
//TODO
|
46
|
private static IInputTransformer defaultTransformer = null;
|
47
|
|
48
|
|
49
|
//if false references in this rdf file are not published in the bibliography list
|
50
|
private boolean isPublishReferences = true;
|
51
|
|
52
|
// //references
|
53
|
private DO_REFERENCES doReferences = DO_REFERENCES.ALL;
|
54
|
// //names
|
55
|
private boolean doTaxonNames = true;
|
56
|
private boolean doRelNames = true;
|
57
|
// //taxa
|
58
|
private boolean doTaxa = true;
|
59
|
private boolean doRelTaxa = true;
|
60
|
private boolean doFacts = true;
|
61
|
Map<String, String> nsPrefixMap;
|
62
|
/*//rdfNamespace
|
63
|
private Namespace rdfNamespace;
|
64
|
//Team namespace
|
65
|
private Namespace tmNamespace;
|
66
|
//Person namespace
|
67
|
private Namespace personNamespace;
|
68
|
//TaxonName namespace
|
69
|
private Namespace tnNamespace;
|
70
|
//TaxonConcept namespace
|
71
|
private Namespace tcNamespace;
|
72
|
//TDWG common namespace
|
73
|
private Namespace commonNamespace;
|
74
|
//TDWG geoNamespace
|
75
|
private Namespace geoNamespace;
|
76
|
//publicationNamespace
|
77
|
private Namespace publicationNamespace;
|
78
|
//owlNamespace
|
79
|
private Namespace owlNamespace;
|
80
|
//dcNamespace
|
81
|
private Namespace dcNamespace;
|
82
|
//dcTermsNamespace
|
83
|
private Namespace dcTermsNamespace;
|
84
|
//palmNamespace
|
85
|
private Namespace palmNamespace;
|
86
|
|
87
|
//TODO
|
88
|
protected static Namespace nsTcom = Namespace.getNamespace("http://rs.tdwg.org/ontology/voc/Common#");
|
89
|
protected static Namespace nsTn = Namespace.getNamespace("http://rs.tdwg.org/ontology/voc/TaxonName#");
|
90
|
protected static Namespace nsTgeo = Namespace.getNamespace("http://rs.tdwg.org/ontology/voc/GeographicRegion#");
|
91
|
protected static Namespace nsTc = Namespace.getNamespace("http://rs.tdwg.org/ontology/voc/TaxonConcept#");
|
92
|
protected static Namespace nsTpub = Namespace.getNamespace("http://rs.tdwg.org/ontology/voc/PublicationCitation#");
|
93
|
protected static Namespace nsTpalm = Namespace.getNamespace("http://wp5.e-taxonomy.eu/import/palmae/common");
|
94
|
|
95
|
String[] prefixArray = {"rdf", "tm", "p","tc","tcom", "tgeo","owl","dc","dcterms","tn"};
|
96
|
*/
|
97
|
@Override
|
98
|
protected void makeIoClassList(){
|
99
|
ioClassList = new Class[]{
|
100
|
TcsRdfReferenceImport.class
|
101
|
, TcsRdfTaxonNameImport.class
|
102
|
, TcsRdfTaxonNameRelationsImport.class
|
103
|
, TcsRdfTaxonImport.class
|
104
|
, TcsRdfTaxonRelationsImport.class
|
105
|
};
|
106
|
};
|
107
|
|
108
|
public static TcsRdfImportConfigurator NewInstance(URI uri, ICdmDataSource destination){
|
109
|
return new TcsRdfImportConfigurator(uri, destination);
|
110
|
}
|
111
|
|
112
|
//TODO for spring use only
|
113
|
private TcsRdfImportConfigurator(){
|
114
|
super(defaultTransformer);
|
115
|
|
116
|
}
|
117
|
|
118
|
|
119
|
/**
|
120
|
* @param berlinModelSource
|
121
|
* @param sourceReference
|
122
|
* @param destination
|
123
|
*/
|
124
|
private TcsRdfImportConfigurator(URI url, ICdmDataSource destination) {
|
125
|
super(defaultTransformer);
|
126
|
setSource(url);
|
127
|
setDestination(destination);
|
128
|
}
|
129
|
|
130
|
/**
|
131
|
* @return
|
132
|
*/
|
133
|
public Model getSourceRoot(){
|
134
|
URI source = getSource();
|
135
|
try {
|
136
|
URL url;
|
137
|
url = source.toURL();
|
138
|
Object o = url.getContent();
|
139
|
InputStream is = (InputStream)o;
|
140
|
Model model = ModelFactory.createDefaultModel();
|
141
|
model.read(is, null);
|
142
|
makeNamespaces(model);
|
143
|
return model;
|
144
|
} catch (MalformedURLException e) {
|
145
|
e.printStackTrace();
|
146
|
}catch (Exception e) {
|
147
|
// TODO Auto-generated catch block
|
148
|
e.printStackTrace();
|
149
|
}
|
150
|
return null;
|
151
|
}
|
152
|
public Element getSourceRoot(InputStream is){
|
153
|
|
154
|
try {
|
155
|
Element root = XmlHelp.getRoot(is);
|
156
|
makeNamespaces(root);
|
157
|
return root;
|
158
|
} catch (MalformedURLException e) {
|
159
|
e.printStackTrace();
|
160
|
}catch (Exception e) {
|
161
|
logger.warn("The InputStream does not contain an rdf file.");
|
162
|
logger.warn(e.getMessage());
|
163
|
}
|
164
|
return null;
|
165
|
}
|
166
|
|
167
|
|
168
|
private void makeNamespaces(Element root){
|
169
|
|
170
|
String prefix = "rdf";
|
171
|
nsPrefixMap.put(prefix, root.getNamespace().getURI().toString());
|
172
|
prefix = "tc";
|
173
|
nsPrefixMap.put(prefix, root.getNamespace().getURI().toString());
|
174
|
prefix = "tn";
|
175
|
nsPrefixMap.put(prefix, root.getNamespace().getURI().toString());
|
176
|
prefix = "tcom";
|
177
|
nsPrefixMap.put(prefix, root.getNamespace().getURI().toString());
|
178
|
prefix = "tgeo";
|
179
|
nsPrefixMap.put(prefix, root.getNamespace().getURI().toString());
|
180
|
prefix = "tpub";
|
181
|
nsPrefixMap.put(prefix, root.getNamespace().getURI().toString());
|
182
|
|
183
|
prefix = "tpalm";
|
184
|
nsPrefixMap.put(prefix, root.getNamespace().getURI().toString());
|
185
|
prefix = "tm";
|
186
|
nsPrefixMap.put(prefix, root.getNamespace().getURI().toString());
|
187
|
}
|
188
|
public void makeNamespaces(Model model){
|
189
|
nsPrefixMap = model.getNsPrefixMap();
|
190
|
|
191
|
}
|
192
|
|
193
|
|
194
|
/* (non-Javadoc)
|
195
|
* @see eu.etaxonomy.cdm.io.common.ImportConfiguratorBase#getSourceReference()
|
196
|
*/
|
197
|
@Override
|
198
|
public Reference getSourceReference() {
|
199
|
//TODO
|
200
|
if (this.sourceReference == null){
|
201
|
logger.warn("getSource Reference not yet fully implemented");
|
202
|
sourceReference = ReferenceFactory.newDatabase();
|
203
|
sourceReference.setTitleCache("XXX", true);
|
204
|
}
|
205
|
return sourceReference;
|
206
|
}
|
207
|
|
208
|
|
209
|
/* (non-Javadoc)
|
210
|
* @see eu.etaxonomy.cdm.io.common.IImportConfigurator#getSourceNameString()
|
211
|
*/
|
212
|
@Override
|
213
|
public String getSourceNameString() {
|
214
|
if (this.getSource() == null){
|
215
|
return null;
|
216
|
}else{
|
217
|
return this.getSource().toString();
|
218
|
}
|
219
|
}
|
220
|
|
221
|
public String getRdfNamespaceURIString() {
|
222
|
return nsPrefixMap.get("rdf");
|
223
|
}
|
224
|
|
225
|
public String getTeamNamespaceURIString() {
|
226
|
return nsPrefixMap.get("tm");
|
227
|
}
|
228
|
|
229
|
public void setNamespace(Namespace namespace) {
|
230
|
this.nsPrefixMap.put(namespace.getPrefix(), namespace.getURI());
|
231
|
}
|
232
|
|
233
|
public String getTcNamespaceURIString() {
|
234
|
return nsPrefixMap.get("tc");
|
235
|
}
|
236
|
|
237
|
|
238
|
|
239
|
public String getTnNamespaceURIString() {
|
240
|
return nsPrefixMap.get("tn");
|
241
|
}
|
242
|
|
243
|
|
244
|
|
245
|
public String getCommonNamespaceURIString() {
|
246
|
return nsPrefixMap.get("tcom");
|
247
|
}
|
248
|
|
249
|
|
250
|
|
251
|
public String getGeoNamespaceURIString() {
|
252
|
return nsPrefixMap.get("tgeo");
|
253
|
}
|
254
|
|
255
|
|
256
|
|
257
|
public String getPublicationNamespaceURI() {
|
258
|
return nsPrefixMap.get("tpub");
|
259
|
}
|
260
|
|
261
|
|
262
|
/**
|
263
|
* @return the palmNamespace
|
264
|
*/
|
265
|
public String getPalmNamespaceURIString() {
|
266
|
return nsPrefixMap.get("tpalm");
|
267
|
}
|
268
|
|
269
|
|
270
|
|
271
|
/**
|
272
|
* if false references in this rdf file are not published in the bibliography list
|
273
|
* @return the isPublishReferences
|
274
|
*/
|
275
|
public boolean isPublishReferences() {
|
276
|
return isPublishReferences;
|
277
|
}
|
278
|
|
279
|
/**
|
280
|
* @param isPublishReferences the isPublishReferences to set
|
281
|
*/
|
282
|
public void setPublishReferences(boolean isPublishReferences) {
|
283
|
this.isPublishReferences = isPublishReferences;
|
284
|
}
|
285
|
|
286
|
|
287
|
public boolean isDoFacts() {
|
288
|
return doFacts;
|
289
|
}
|
290
|
public void setDoFacts(boolean doFacts) {
|
291
|
this.doFacts = doFacts;
|
292
|
}
|
293
|
|
294
|
/**
|
295
|
* Import name relationships yes/no?.
|
296
|
* @return
|
297
|
*/
|
298
|
public boolean isDoRelNames() {
|
299
|
return doRelNames;
|
300
|
}
|
301
|
public void setDoRelNames(boolean doRelNames) {
|
302
|
this.doRelNames = doRelNames;
|
303
|
}
|
304
|
|
305
|
/* (non-Javadoc)
|
306
|
* @see eu.etaxonomy.cdm.io.common.IImportConfigurator#getNewState()
|
307
|
*/
|
308
|
@Override
|
309
|
public TcsRdfImportState getNewState() {
|
310
|
return new TcsRdfImportState(this);
|
311
|
}
|
312
|
|
313
|
|
314
|
|
315
|
public DO_REFERENCES getDoReferences() {
|
316
|
return doReferences;
|
317
|
}
|
318
|
public void setDoReferences(DO_REFERENCES doReferences) {
|
319
|
this.doReferences = doReferences;
|
320
|
}
|
321
|
|
322
|
public boolean isDoTaxonNames() {
|
323
|
return doTaxonNames;
|
324
|
}
|
325
|
public void setDoTaxonNames(boolean doTaxonNames) {
|
326
|
this.doTaxonNames = doTaxonNames;
|
327
|
}
|
328
|
|
329
|
public boolean isDoTaxa() {
|
330
|
return doTaxa;
|
331
|
}
|
332
|
public void setDoTaxa(boolean doTaxa) {
|
333
|
this.doTaxa = doTaxa;
|
334
|
}
|
335
|
|
336
|
public boolean isDoRelTaxa() {
|
337
|
return doRelTaxa;
|
338
|
}
|
339
|
public void setDoRelTaxa(boolean doRelTaxa) {
|
340
|
this.doRelTaxa = doRelTaxa;
|
341
|
}
|
342
|
|
343
|
|
344
|
|
345
|
|
346
|
|
347
|
}
|