Project

General

Profile

Download (7.03 KB) Statistics
| Branch: | Tag: | 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.tcsxml.in;
11

    
12
import java.io.InputStream;
13
import java.lang.reflect.Method;
14
import java.net.MalformedURLException;
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.ImportStateBase;
27
import eu.etaxonomy.cdm.io.common.mapping.IInputTransformer;
28
import eu.etaxonomy.cdm.io.tcsxml.DefaultTcsXmlPlaceholders;
29
import eu.etaxonomy.cdm.io.tcsxml.ITcsXmlPlaceholderClass;
30
import eu.etaxonomy.cdm.model.reference.IDatabase;
31
import eu.etaxonomy.cdm.model.reference.ReferenceBase;
32
import eu.etaxonomy.cdm.model.reference.ReferenceFactory;
33

    
34
@Component
35
public class TcsXmlImportConfigurator extends ImportConfiguratorBase<TcsXmlImportState> implements IImportConfigurator {
36
	private static final Logger logger = Logger.getLogger(TcsXmlImportConfigurator.class);
37
	
38
	//TODO
39
	private static IInputTransformer defaultTransformer = null;
40

    
41
	
42
	private boolean doMetaData = true;
43
	private boolean doSpecimen = true;
44

    
45
	private Method functionMetaDataDetailed = null; 
46
	private ITcsXmlPlaceholderClass placeholderClass;
47
	
48
	//	rdfNamespace
49
	Namespace tcsXmlNamespace;
50

    
51
	protected static Namespace nsTcsXml = Namespace.getNamespace("http://www.tdwg.org/schemas/tcs/1.01");
52
	
53
//	@Autowired
54
//	TcsXmlMetaDataImport tcsXmlMetaDataImport;
55
//	@Autowired
56
//	TcsXmlSpecimensImport tcsXmlSpecimensIO;
57
//	@Autowired
58
//	TcsXmlPublicationsImport tcsXmlPublicationsIO;
59
//	@Autowired
60
//	TcsXmlTaxonNameImport tcsXmlTaxonNameIO;
61
//	@Autowired
62
//	TcsXmlTaxonNameRelationsImport tcsXmlTaxonNameRelationsIO;
63
//	@Autowired
64
//	TcsXmlTaxonImport tcsXmlTaxonIO;
65
//	@Autowired
66
//	TcsXmlTaxonRelationsImport tcsXmlTaxonRelationsIO;
67
	
68
	protected void makeIoClassList(){
69
//		ioBeans = new String[]{
70
//				"tcsXmlMetaDataImport"
71
//				, "tcsXmlSpecimensIO"
72
//				, "tcsXmlPublicationsIO"
73
//				, "tcsXmlTaxonNameIO"
74
//				, "tcsXmlTaxonNameRelationsIO"
75
//				, "tcsXmlTaxonIO"
76
//				, "tcsXmlTaxonRelationsIO"	
77
//		};
78
		
79
		ioClassList = new Class[]{
80
			TcsXmlMetaDataImport.class
81
			, TcsXmlSpecimensImport.class
82
			, TcsXmlPublicationsImport.class
83
			, TcsXmlTaxonNameImport.class
84
			, TcsXmlTaxonNameRelationsImport.class
85
			, TcsXmlTaxonImport.class
86
			, TcsXmlTaxonRelationsImport.class
87
		};
88
	};
89
	
90
	public static TcsXmlImportConfigurator NewInstance(String url,
91
			ICdmDataSource destination){
92
		return new TcsXmlImportConfigurator(url, destination);
93
	}
94
	
95
	/**
96
	 * @param berlinModelSource
97
	 * @param sourceReference
98
	 * @param destination
99
	 */
100
	private TcsXmlImportConfigurator() {
101
		super(defaultTransformer);
102
//		setSource(url);
103
//		setDestination(destination);
104
	}
105
	
106
	/**
107
	 * @param berlinModelSource
108
	 * @param sourceReference
109
	 * @param destination
110
	 */
111
	private TcsXmlImportConfigurator(String url, ICdmDataSource destination) {
112
		super(defaultTransformer);
113
		setSource(url);
114
		setDestination(destination);
115
	}
116
	
117
	
118

    
119
	/* (non-Javadoc)
120
	 * @see eu.etaxonomy.cdm.io.common.IImportConfigurator#getNewState()
121
	 */
122
	public TcsXmlImportState getNewState() {
123
		return new TcsXmlImportState(this);
124
	}
125

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

    
175

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

    
191

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

    
207
	public void setTcsXmlNamespace(Namespace tcsXmlNamespace) {
208
		this.tcsXmlNamespace = tcsXmlNamespace;
209
	}
210
	
211

    
212
	/**
213
	 * @return the funMetaDataDetailed
214
	 */
215
	public Method getFunctionMetaDataDetailed() {
216
		if (functionMetaDataDetailed == null){
217
			functionMetaDataDetailed = getDefaultFunction(TcsXmlMetaDataImport.class, "defaultMetaDataDetailedFunction");
218
		}
219
		return functionMetaDataDetailed;
220
		
221
	}
222

    
223
	/**
224
	 * @param funMetaDataDetailed the funMetaDataDetailed to set
225
	 */
226
	public void setFunctionMetaDataDetailed(Method functionMetaDataDetailed) {
227
		this.functionMetaDataDetailed = functionMetaDataDetailed;
228
	}
229
	
230
	/**
231
	 * @return the doMetaData
232
	 */
233
	public boolean isDoMetaData() {
234
		return doMetaData;
235
	}
236

    
237
	/**
238
	 * @param doMetaData the doMetaData to set
239
	 */
240
	public void setDoMetaData(boolean doMetaData) {
241
		this.doMetaData = doMetaData;
242
	}
243

    
244

    
245
	/**
246
	 * @return the doSpecimen
247
	 */
248
	public boolean isDoSpecimen() {
249
		return doSpecimen;
250
	}
251

    
252
	/**
253
	 * @param doSpecimen the doSpecimen to set
254
	 */
255
	public void setDoSpecimen(boolean doSpecimen) {
256
		this.doSpecimen = doSpecimen;
257
	}
258

    
259
	/**
260
	 * @return the placeholderClass
261
	 */
262
	public ITcsXmlPlaceholderClass getPlaceholderClass() {
263
		if (placeholderClass == null){
264
			placeholderClass = new DefaultTcsXmlPlaceholders();
265
		}
266
		return placeholderClass;
267
	}
268

    
269
	/**
270
	 * @param placeholderClass the placeholderClass to set
271
	 */
272
	public void setPlaceholderClass(ITcsXmlPlaceholderClass placeholderClass) {
273
		this.placeholderClass = placeholderClass;
274
	}
275

    
276
	
277
}
(3-3/11)