Project

General

Profile

Download (8.4 KB) Statistics
| Branch: | Tag: | Revision:
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

    
17
import org.apache.log4j.Logger;
18
import org.jdom.Element;
19
import org.jdom.Namespace;
20

    
21
import eu.etaxonomy.cdm.common.XmlHelp;
22
import eu.etaxonomy.cdm.database.ICdmDataSource;
23
import eu.etaxonomy.cdm.io.common.IImportConfigurator;
24
import eu.etaxonomy.cdm.io.common.ImportConfiguratorBase;
25
import eu.etaxonomy.cdm.io.common.mapping.IInputTransformer;
26
import eu.etaxonomy.cdm.model.reference.Reference;
27
import eu.etaxonomy.cdm.model.reference.ReferenceFactory;
28

    
29
/**
30
 * @author a.mueller
31
 * @created 29.05.2008
32
 * @version 1.0
33
 */
34
public class TcsRdfImportConfigurator extends ImportConfiguratorBase<TcsRdfImportState, URI> implements IImportConfigurator {
35
	private static final Logger logger = Logger.getLogger(TcsRdfImportConfigurator.class);
36
	
37
	
38
	//TODO
39
	private static IInputTransformer defaultTransformer = null;
40

    
41
	
42
	//if false references in this rdf file are not published in the bibliography list
43
	private boolean isPublishReferences = true;
44
	
45
//	//references
46
	private DO_REFERENCES doReferences = DO_REFERENCES.ALL;
47
//	//names
48
	private boolean doTaxonNames = true;
49
	private boolean doRelNames = true;
50
//	//taxa
51
	private boolean doTaxa = true;
52
	private boolean doRelTaxa = true;
53
	private boolean doFacts = true;
54
	
55
	//rdfNamespace
56
	private Namespace rdfNamespace;
57
	//TaxonConcept namespace
58
	private Namespace tcNamespace;
59
	//TaxonName namespace
60
	private Namespace tnNamespace;
61
	//TDWG common namespace
62
	private Namespace commonNamespace;
63
	//TDWG geoNamespace
64
	private Namespace geoNamespace;
65
	//publicationNamespace
66
	private Namespace publicationNamespace;
67
	//palmNamespace
68
	private Namespace palmNamespace;
69
	
70
//TODO	
71
	protected static Namespace nsTcom = Namespace.getNamespace("http://rs.tdwg.org/ontology/voc/Common#");
72
	protected static Namespace nsTn = Namespace.getNamespace("http://rs.tdwg.org/ontology/voc/TaxonName#");
73
	protected static Namespace nsTgeo = Namespace.getNamespace("http://rs.tdwg.org/ontology/voc/GeographicRegion#");
74
	protected static Namespace nsTc = Namespace.getNamespace("http://rs.tdwg.org/ontology/voc/TaxonConcept#");
75
	protected static Namespace nsTpub = Namespace.getNamespace("http://rs.tdwg.org/ontology/voc/PublicationCitation#");
76
	protected static Namespace nsTpalm = Namespace.getNamespace("http://wp5.e-taxonomy.eu/import/palmae/common");
77

    
78
	protected void makeIoClassList(){
79
		ioClassList = new Class[]{
80
			TcsRdfReferenceImport.class
81
			, TcsRdfTaxonNameImport.class
82
			, TcsRdfTaxonNameRelationsImport.class
83
			, TcsRdfTaxonImport.class
84
			, TcsRdfTaxonRelationsImport.class
85
		};
86
	};
87
	
88
	public static TcsRdfImportConfigurator NewInstance(URI uri, ICdmDataSource destination){
89
		return new TcsRdfImportConfigurator(uri, destination);
90
	}
91
	
92
	//TODO for spring use only 
93
	private TcsRdfImportConfigurator(){
94
		super(defaultTransformer);
95
		
96
	}
97
	
98
	
99
	/**
100
	 * @param berlinModelSource
101
	 * @param sourceReference
102
	 * @param destination
103
	 */
104
	private TcsRdfImportConfigurator(URI url, ICdmDataSource destination) {
105
		super(defaultTransformer);
106
		setSource(url);
107
		setDestination(destination);
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
		//String strTnNamespace = "http://rs.tdwg.org/ontology/voc/TaxonName#";
134
		//Namespace taxonNameNamespace = Namespace.getNamespace("tn", strTnNamespace);
135

    
136
		String prefix;
137
		rdfNamespace = root.getNamespace();
138
		prefix = "tc";
139
		tcNamespace = root.getNamespace(prefix);
140
		prefix = "tn";
141
		tnNamespace = root.getNamespace(prefix);
142
		prefix = "tcom";
143
		commonNamespace = root.getNamespace(prefix);
144
		prefix = "tgeo";
145
		geoNamespace = root.getNamespace(prefix);
146
		prefix = "tpub";
147
		publicationNamespace = root.getNamespace(prefix);
148
		
149
		prefix = "tpalm";
150
		palmNamespace = root.getNamespace(prefix);
151
		
152
		if (rdfNamespace == null || tcNamespace == null || tnNamespace == null ||
153
				commonNamespace == null ||	geoNamespace == null || publicationNamespace == null 
154
				|| palmNamespace == null){
155
			logger.warn("At least one Namespace is NULL");
156
		}
157
		return true;
158
	}
159

    
160

    
161
	/* (non-Javadoc)
162
	 * @see eu.etaxonomy.cdm.io.common.ImportConfiguratorBase#getSourceReference()
163
	 */
164
	@Override
165
	public Reference getSourceReference() {
166
		//TODO
167
		if (this.sourceReference == null){
168
			logger.warn("getSource Reference not yet fully implemented");
169
			ReferenceFactory refFactory = ReferenceFactory.newInstance();
170
			sourceReference = refFactory.newDatabase();
171
			sourceReference.setTitleCache("XXX", true);
172
		}
173
		return sourceReference;
174
	}
175

    
176

    
177
	/* (non-Javadoc)
178
	 * @see eu.etaxonomy.cdm.io.common.IImportConfigurator#getSourceNameString()
179
	 */
180
	public String getSourceNameString() {
181
		if (this.getSource() == null){
182
			return null;
183
		}else{
184
			return this.getSource().toString();
185
		}
186
	}
187
	
188
	public Namespace getRdfNamespace() {
189
		return rdfNamespace;
190
	}
191

    
192
	public void setRdfNamespace(Namespace rdfNamespace) {
193
		this.rdfNamespace = rdfNamespace;
194
	}
195

    
196
	public Namespace getTcNamespace() {
197
		return tcNamespace;
198
	}
199

    
200
	public void setTcNamespace(Namespace tcNamespace) {
201
		this.tcNamespace = tcNamespace;
202
	}
203

    
204
	public Namespace getTnNamespace() {
205
		return tnNamespace;
206
	}
207

    
208
	public void setTnNamespace(Namespace tnNamespace) {
209
		this.tnNamespace = tnNamespace;
210
	}
211

    
212
	public Namespace getCommonNamespace() {
213
		return commonNamespace;
214
	}
215

    
216
	public void setCommonNamespace(Namespace commonNamespace) {
217
		this.commonNamespace = commonNamespace;
218
	}
219

    
220
	public Namespace getGeoNamespace() {
221
		return geoNamespace;
222
	}
223

    
224
	public void setGeoNamespace(Namespace geoNamespace) {
225
		this.geoNamespace = geoNamespace;
226
	}
227

    
228
	public Namespace getPublicationNamespace() {
229
		return publicationNamespace;
230
	}
231

    
232
	public void setPublicationNamespace(Namespace publicationNamespace) {
233
		this.publicationNamespace = publicationNamespace;
234
	}
235
	/**
236
	 * @return the palmNamespace
237
	 */
238
	public Namespace getPalmNamespace() {
239
		return palmNamespace;
240
	}
241

    
242
	/**
243
	 * @param palmNamespace the palmNamespace to set
244
	 */
245
	public void setPalmNamespace(Namespace palmNamespace) {
246
		this.palmNamespace = palmNamespace;
247
	}
248

    
249
	/**
250
	 * if false references in this rdf file are not published in the bibliography list
251
	 * @return the isPublishReferences
252
	 */
253
	public boolean isPublishReferences() {
254
		return isPublishReferences;
255
	}
256

    
257
	/**
258
	 * @param isPublishReferences the isPublishReferences to set
259
	 */
260
	public void setPublishReferences(boolean isPublishReferences) {
261
		this.isPublishReferences = isPublishReferences;
262
	}
263
	
264
	
265
	public boolean isDoFacts() {
266
		return doFacts;
267
	}
268
	public void setDoFacts(boolean doFacts) {
269
		this.doFacts = doFacts;
270
	}
271
	
272
	/**
273
	 * Import name relationships yes/no?.
274
	 * @return
275
	 */
276
	public boolean isDoRelNames() {
277
		return doRelNames;
278
	}
279
	public void setDoRelNames(boolean doRelNames) {
280
		this.doRelNames = doRelNames;
281
	}
282

    
283
	/* (non-Javadoc)
284
	 * @see eu.etaxonomy.cdm.io.common.IImportConfigurator#getNewState()
285
	 */
286
	public TcsRdfImportState getNewState() {
287
		return new TcsRdfImportState(this);
288
	}
289
	
290
	
291
	
292
	public DO_REFERENCES getDoReferences() {
293
		return doReferences;
294
	}
295
	public void setDoReferences(DO_REFERENCES doReferences) {
296
		this.doReferences = doReferences;
297
	}
298
	
299
	public boolean isDoTaxonNames() {
300
		return doTaxonNames;
301
	}
302
	public void setDoTaxonNames(boolean doTaxonNames) {
303
		this.doTaxonNames = doTaxonNames;
304
	}
305

    
306
	public boolean isDoTaxa() {
307
		return doTaxa;
308
	}
309
	public void setDoTaxa(boolean doTaxa) {
310
		this.doTaxa = doTaxa;
311
	}
312

    
313
	public boolean isDoRelTaxa() {
314
		return doRelTaxa;
315
	}
316
	public void setDoRelTaxa(boolean doRelTaxa) {
317
		this.doRelTaxa = doRelTaxa;
318
	}
319

    
320
	
321

    
322
	
323
	
324
}
(6-6/13)