Project

General

Profile

Download (8.03 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

    
51

    
52
	public boolean isFillSecondList() {
53
		return fillSecondList;
54
	}
55

    
56
	public void setFillSecondList(boolean fillSecondList) {
57
		this.fillSecondList = fillSecondList;
58
	}
59

    
60
	//	//references
61
	private DO_REFERENCES doReferences = DO_REFERENCES.ALL;
62
//	//names
63
	private boolean doTaxonNames = true;
64
	private boolean doRelNames = true;
65
//	//taxa
66
	private boolean doTaxa = true;
67
	private boolean doRelTaxa = true;
68

    
69
	
70
	
71
	private Method functionMetaDataDetailed = null; 
72
	private ITcsXmlPlaceholderClass placeholderClass;
73
	
74
	//	rdfNamespace
75
	Namespace bfnXmlNamespace;
76

    
77
	protected static Namespace nsTcsXml = Namespace.getNamespace("http://www.tdwg.org/schemas/tcs/1.01");
78
	
79
//	@Autowired
80
//	TcsXmlMetaDataImport tcsXmlMetaDataImport;
81
//	@Autowired
82
//	TcsXmlSpecimensImport tcsXmlSpecimensIO;
83
//	@Autowired
84
//	TcsXmlPublicationsImport tcsXmlPublicationsIO;
85
//	@Autowired
86
//	BfnXmlTaxonNameImport tcsXmlTaxonNameIO;
87
//	@Autowired
88
//	TcsXmlTaxonNameRelationsImport tcsXmlTaxonNameRelationsIO;
89
//	@Autowired
90
//	BfnXmlTaxonImport tcsXmlTaxonIO;
91
//	@Autowired
92
//	TcsXmlTaxonRelationsImport tcsXmlTaxonRelationsIO;
93
	
94
	@SuppressWarnings("unchecked")
95
	protected void makeIoClassList(){
96
//		ioBeans = new String[]{
97
//				"tcsXmlMetaDataImport"
98
//				, "tcsXmlSpecimensIO"
99
//				, "tcsXmlPublicationsIO"
100
//				, "tcsXmlTaxonNameIO"
101
//				, "tcsXmlTaxonNameRelationsIO"
102
//				, "tcsXmlTaxonIO"
103
//				, "tcsXmlTaxonRelationsIO"	
104
//		};
105
		
106
		ioClassList = new Class[]{
107
				BfnXmlImportMetaData.class,
108
				BfnXmlImportFeature.class,
109
				BfnXmlImportTaxonName.class
110
		};
111
	};
112
	
113
	public static BfnXmlImportConfigurator NewInstance(URI uri,
114
			ICdmDataSource destination){
115
		return new BfnXmlImportConfigurator(uri, destination);
116
	}
117
	
118
	/**
119
	 * @param berlinModelSource
120
	 * @param sourceReference
121
	 * @param destination
122
	 */
123
	private BfnXmlImportConfigurator() {
124
		super(defaultTransformer);
125
//		setSource(url);
126
//		setDestination(destination);
127
	}
128
	
129
	/**
130
	 * @param berlinModelSource
131
	 * @param sourceReference
132
	 * @param destination
133
	 */
134
	private BfnXmlImportConfigurator(URI uri, ICdmDataSource destination) {
135
		super(defaultTransformer);
136
		setSource(uri);
137
		setDestination(destination);
138
	}
139
	
140
	
141

    
142
	/* (non-Javadoc)
143
	 * @see eu.etaxonomy.cdm.io.common.IImportConfigurator#getNewState()
144
	 */
145
	public BfnXmlImportState getNewState() {
146
		return new BfnXmlImportState(this);
147
	}
148

    
149
	/* (non-Javadoc)
150
	 * @see eu.etaxonomy.cdm.io.common.ImportConfiguratorBase#getSource()
151
	 */
152
	public URI getSource() {
153
		return (URI)super.getSource();
154
	}
155
	
156
	/**
157
	 * @param file
158
	 */
159
	public void setSource(URI uri) {
160
		super.setSource(uri);
161
	}
162
	
163
	/**
164
	 * @return
165
	 */
166
	public Element getSourceRoot(){
167
		URI source = getSource();
168
		try {
169
			URL url;
170
			url = source.toURL();
171
			Object o = url.getContent();
172
			InputStream is = (InputStream)o;
173
			Element root = XmlHelp.getRoot(is);
174
			makeNamespaces(root);
175
			return root;
176
		} catch (MalformedURLException e) {
177
			e.printStackTrace();
178
		}catch (Exception e) {
179
			// TODO Auto-generated catch block
180
			e.printStackTrace();
181
		}
182
		return null;
183
	}
184
	
185
	private boolean makeNamespaces(Element root){
186
		bfnXmlNamespace = root.getNamespace();
187
		if (bfnXmlNamespace == null 
188
				/**|| tcNamespace == null 
189
				 * || tnNamespace == null 
190
				 * || commonNamespace == null 
191
				 * ||	geoNamespace == null 
192
				 * || publicationNamespace == null*/){
193
			logger.warn("At least one Namespace is NULL");
194
		}
195
		return true;
196
	}
197

    
198

    
199
	/* (non-Javadoc)
200
	 * @see eu.etaxonomy.cdm.io.common.ImportConfiguratorBase#getSourceReference()
201
	 */
202
	@Override
203
	public Reference getSourceReference() {
204
		//TODO
205
		if (this.sourceReference == null){
206
			logger.warn("getSource Reference not yet fully implemented");
207
			sourceReference = ReferenceFactory.newDatabase();
208
			sourceReference.setTitleCache("", true);
209
		}
210
		return sourceReference;
211
	}
212

    
213

    
214
	/* (non-Javadoc)
215
	 * @see eu.etaxonomy.cdm.io.common.IImportConfigurator#getSourceNameString()
216
	 */
217
	public String getSourceNameString() {
218
		if (this.getSource() == null){
219
			return null;
220
		}else{
221
			return this.getSource().toString();
222
		}
223
	}
224
	
225
	public Namespace getBfnXmlNamespace() {
226
		return bfnXmlNamespace;
227
	}
228

    
229
	public void setBfnXmlNamespace(Namespace bfnXmlNamespace) {
230
		this.bfnXmlNamespace = bfnXmlNamespace;
231
	}
232

    
233
	/**
234
	 * @param funMetaDataDetailed the funMetaDataDetailed to set
235
	 */
236
	public void setFunctionMetaDataDetailed(Method functionMetaDataDetailed) {
237
		this.functionMetaDataDetailed = functionMetaDataDetailed;
238
	}
239
	
240
	public DO_REFERENCES getDoReferences() {
241
		return doReferences;
242
	}
243
	public void setDoReferences(DO_REFERENCES doReferences) {
244
		this.doReferences = doReferences;
245
	}
246
	
247
	public boolean isDoTaxonNames() {
248
		return doTaxonNames;
249
	}
250
	public void setDoTaxonNames(boolean doTaxonNames) {
251
		this.doTaxonNames = doTaxonNames;
252
	}
253

    
254
	public boolean isDoTaxa() {
255
		return doTaxa;
256
	}
257
	public void setDoTaxa(boolean doTaxa) {
258
		this.doTaxa = doTaxa;
259
	}
260

    
261
	public boolean isDoRelTaxa() {
262
		return doRelTaxa;
263
	}
264
	public void setDoRelTaxa(boolean doRelTaxa) {
265
		this.doRelTaxa = doRelTaxa;
266
	}
267

    
268
	/**
269
	 * Import name relationships yes/no?.
270
	 * @return
271
	 */
272
	public boolean isDoRelNames() {
273
		return doRelNames;
274
	}
275
	public void setDoRelNames(boolean doRelNames) {
276
		this.doRelNames = doRelNames;
277
	}
278
	
279
	/**
280
	 * @return the doMetaData
281
	 */
282
	public boolean isDoMetaData() {
283
		return doMetaData;
284
	}
285

    
286
	/**
287
	 * @param doMetaData the doMetaData to set
288
	 */
289
	public void setDoMetaData(boolean doMetaData) {
290
		this.doMetaData = doMetaData;
291
	}
292

    
293

    
294
	/**
295
	 * @return the doSpecimen
296
	 */
297
	public boolean isDoSpecimen() {
298
		return doSpecimen;
299
	}
300

    
301
	/**
302
	 * @param doSpecimen the doSpecimen to set
303
	 */
304
	public void setDoSpecimen(boolean doSpecimen) {
305
		this.doSpecimen = doSpecimen;
306
	}
307

    
308
	/**
309
	 * @return the placeholderClass
310
	 */
311
	public ITcsXmlPlaceholderClass getPlaceholderClass() {
312
		if (placeholderClass == null){
313
			placeholderClass = new DefaultTcsXmlPlaceholders();
314
		}
315
		return placeholderClass;
316
	}
317

    
318
	/**
319
	 * @param placeholderClass the placeholderClass to set
320
	 */
321
	public void setPlaceholderClass(ITcsXmlPlaceholderClass placeholderClass) {
322
		this.placeholderClass = placeholderClass;
323
	}
324
	
325
	public boolean isDoInformationImport() {
326
		return doInformationImport;
327
	}
328

    
329
	public void setDoInformationImport(boolean doInformationImport) {
330
		this.doInformationImport = doInformationImport;
331
	}
332
	
333
}
(2-2/7)