Project

General

Profile

Download (7.81 KB) Statistics
| Branch: | Revision:
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
	private String nomenclaturalCode = null;
80

    
81
	protected static Namespace nsTcsXml = Namespace.getNamespace("http://www.tdwg.org/schemas/tcs/1.01");
82
	
83
	@SuppressWarnings("unchecked")
84
	protected void makeIoClassList(){
85
		ioClassList = new Class[]{
86
				BfnXmlImportAddtionalTerms.class,
87
				BfnXmlImportMetaData.class,
88
				BfnXmlImportFeature.class,
89
				BfnXmlImportTaxonName.class
90
		};
91
	};
92
	
93
	public static BfnXmlImportConfigurator NewInstance(URI uri,
94
			ICdmDataSource destination){
95
		return new BfnXmlImportConfigurator(uri, destination);
96
	}
97
	
98
	/**
99
	 * @param berlinModelSource
100
	 * @param sourceReference
101
	 * @param destination
102
	 */
103
	private BfnXmlImportConfigurator() {
104
		super(defaultTransformer);
105
//		setSource(url);
106
//		setDestination(destination);
107
	}
108
	
109
	/**
110
	 * @param berlinModelSource
111
	 * @param sourceReference
112
	 * @param destination
113
	 */
114
	private BfnXmlImportConfigurator(URI uri, ICdmDataSource destination) {
115
		super(defaultTransformer);
116
		setSource(uri);
117
		setDestination(destination);
118
	}
119
	
120
	
121

    
122
	/* (non-Javadoc)
123
	 * @see eu.etaxonomy.cdm.io.common.IImportConfigurator#getNewState()
124
	 */
125
	public BfnXmlImportState getNewState() {
126
		return new BfnXmlImportState(this);
127
	}
128

    
129
	/* (non-Javadoc)
130
	 * @see eu.etaxonomy.cdm.io.common.ImportConfiguratorBase#getSource()
131
	 */
132
	public URI getSource() {
133
		return (URI)super.getSource();
134
	}
135
	
136
	/**
137
	 * @param file
138
	 */
139
	public void setSource(URI uri) {
140
		super.setSource(uri);
141
	}
142
	
143
	/**
144
	 * @return
145
	 */
146
	public Element getSourceRoot(){
147
		URI source = getSource();
148
		try {
149
			URL url;
150
			url = source.toURL();
151
			Object o = url.getContent();
152
			InputStream is = (InputStream)o;
153
			Element root = XmlHelp.getRoot(is);
154
			makeNamespaces(root);
155
			return root;
156
		} catch (MalformedURLException e) {
157
			e.printStackTrace();
158
		}catch (Exception e) {
159
			// TODO Auto-generated catch block
160
			e.printStackTrace();
161
		}
162
		return null;
163
	}
164
	
165
	private boolean makeNamespaces(Element root){
166
		bfnXmlNamespace = root.getNamespace();
167
		if (bfnXmlNamespace == null 
168
				/**|| tcNamespace == null 
169
				 * || tnNamespace == null 
170
				 * || commonNamespace == null 
171
				 * ||	geoNamespace == null 
172
				 * || publicationNamespace == null*/){
173
			logger.warn("At least one Namespace is NULL");
174
		}
175
		return true;
176
	}
177

    
178

    
179
	/* (non-Javadoc)
180
	 * @see eu.etaxonomy.cdm.io.common.ImportConfiguratorBase#getSourceReference()
181
	 */
182
	@Override
183
	public Reference getSourceReference() {
184
		//TODO
185
		if (this.sourceReference == null){
186
			logger.warn("getSource Reference not yet fully implemented");
187
			sourceReference = ReferenceFactory.newDatabase();
188
			sourceReference.setTitleCache("", true);
189
		}
190
		return sourceReference;
191
	}
192

    
193

    
194
	/* (non-Javadoc)
195
	 * @see eu.etaxonomy.cdm.io.common.IImportConfigurator#getSourceNameString()
196
	 */
197
	public String getSourceNameString() {
198
		if (this.getSource() == null){
199
			return null;
200
		}else{
201
			return this.getSource().toString();
202
		}
203
	}
204
	
205
	public Namespace getBfnXmlNamespace() {
206
		return bfnXmlNamespace;
207
	}
208

    
209
	public void setBfnXmlNamespace(Namespace bfnXmlNamespace) {
210
		this.bfnXmlNamespace = bfnXmlNamespace;
211
	}
212

    
213
	/**
214
	 * @param funMetaDataDetailed the funMetaDataDetailed to set
215
	 */
216
	public void setFunctionMetaDataDetailed(Method functionMetaDataDetailed) {
217
		this.functionMetaDataDetailed = functionMetaDataDetailed;
218
	}
219
	
220
	public DO_REFERENCES getDoReferences() {
221
		return doReferences;
222
	}
223
	public void setDoReferences(DO_REFERENCES doReferences) {
224
		this.doReferences = doReferences;
225
	}
226
	
227
	public boolean isDoTaxonNames() {
228
		return doTaxonNames;
229
	}
230
	public void setDoTaxonNames(boolean doTaxonNames) {
231
		this.doTaxonNames = doTaxonNames;
232
	}
233

    
234
	public boolean isDoTaxa() {
235
		return doTaxa;
236
	}
237
	public void setDoTaxa(boolean doTaxa) {
238
		this.doTaxa = doTaxa;
239
	}
240

    
241
	public boolean isDoRelTaxa() {
242
		return doRelTaxa;
243
	}
244
	public void setDoRelTaxa(boolean doRelTaxa) {
245
		this.doRelTaxa = doRelTaxa;
246
	}
247

    
248
	/**
249
	 * Import name relationships yes/no?.
250
	 * @return
251
	 */
252
	public boolean isDoRelNames() {
253
		return doRelNames;
254
	}
255
	public void setDoRelNames(boolean doRelNames) {
256
		this.doRelNames = doRelNames;
257
	}
258
	
259
	/**
260
	 * @return the doMetaData
261
	 */
262
	public boolean isDoMetaData() {
263
		return doMetaData;
264
	}
265

    
266
	/**
267
	 * @param doMetaData the doMetaData to set
268
	 */
269
	public void setDoMetaData(boolean doMetaData) {
270
		this.doMetaData = doMetaData;
271
	}
272

    
273

    
274
	/**
275
	 * @return the doSpecimen
276
	 */
277
	public boolean isDoSpecimen() {
278
		return doSpecimen;
279
	}
280

    
281
	/**
282
	 * @param doSpecimen the doSpecimen to set
283
	 */
284
	public void setDoSpecimen(boolean doSpecimen) {
285
		this.doSpecimen = doSpecimen;
286
	}
287

    
288
	/**
289
	 * @return the placeholderClass
290
	 */
291
	public ITcsXmlPlaceholderClass getPlaceholderClass() {
292
		if (placeholderClass == null){
293
			placeholderClass = new DefaultTcsXmlPlaceholders();
294
		}
295
		return placeholderClass;
296
	}
297

    
298
	/**
299
	 * @param placeholderClass the placeholderClass to set
300
	 */
301
	public void setPlaceholderClass(ITcsXmlPlaceholderClass placeholderClass) {
302
		this.placeholderClass = placeholderClass;
303
	}
304
	
305
	public boolean isDoInformationImport() {
306
		return doInformationImport;
307
	}
308

    
309
	public void setDoInformationImport(boolean doInformationImport) {
310
		this.doInformationImport = doInformationImport;
311
	}
312

    
313
	public boolean isHasSecondList() {
314
		return hasSecondList;
315
	}
316

    
317
	public void setHasSecondList(boolean hasSecondList) {
318
		this.hasSecondList = hasSecondList;
319
	}
320

    
321
	public void setNomenclaturalSig(String nomenclaturalCode) {
322
		this.nomenclaturalCode = nomenclaturalCode;
323
	}
324

    
325
	public String getNomenclaturalSig(){
326
		return nomenclaturalCode;
327
	}
328
}
(3-3/8)