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.eflora;
|
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.UUID;
|
17
|
|
18
|
import org.apache.log4j.Logger;
|
19
|
import org.jdom.Element;
|
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.mapping.IInputTransformer;
|
27
|
import eu.etaxonomy.cdm.io.eflora.EfloraImportState;
|
28
|
import eu.etaxonomy.cdm.model.reference.Reference;
|
29
|
import eu.etaxonomy.cdm.model.reference.ReferenceFactory;
|
30
|
|
31
|
@Component
|
32
|
public class EfloraImportConfigurator extends ImportConfiguratorBase<EfloraImportState, URI> implements IImportConfigurator {
|
33
|
private static final Logger logger = Logger.getLogger(EfloraImportConfigurator.class);
|
34
|
|
35
|
public static EfloraImportConfigurator NewInstance(URI uri, ICdmDataSource destination){
|
36
|
return new EfloraImportConfigurator(uri, destination);
|
37
|
}
|
38
|
|
39
|
private boolean doTaxa = true;
|
40
|
|
41
|
|
42
|
//TODO
|
43
|
private static IInputTransformer defaultTransformer = null;
|
44
|
private String classificationTitle = "E-Flora Import";
|
45
|
private String sourceReferenceTitle = "E-Flora";
|
46
|
private UUID defaultLanguageUuid;
|
47
|
|
48
|
//TODO move to state, but a state gets lost after each import.invoke, so I can't move this information
|
49
|
//from the one import to another import in case I run 2 imports in line
|
50
|
private UUID lastTaxonUuid;
|
51
|
|
52
|
//if true, the keys will be printed after they have been created
|
53
|
private boolean doPrintKeys = false;
|
54
|
|
55
|
|
56
|
/* (non-Javadoc)
|
57
|
* @see eu.etaxonomy.cdm.io.common.ImportConfiguratorBase#makeIoClassList()
|
58
|
*/
|
59
|
protected void makeIoClassList(){
|
60
|
ioClassList = new Class[]{
|
61
|
EfloraTaxonImport.class
|
62
|
};
|
63
|
};
|
64
|
|
65
|
protected EfloraImportConfigurator() {
|
66
|
super(defaultTransformer);
|
67
|
}
|
68
|
|
69
|
|
70
|
/**
|
71
|
*
|
72
|
*/
|
73
|
protected EfloraImportConfigurator(IInputTransformer transformer) {
|
74
|
super(transformer);
|
75
|
}
|
76
|
|
77
|
|
78
|
/**
|
79
|
* @param url
|
80
|
* @param destination
|
81
|
*/
|
82
|
protected EfloraImportConfigurator(URI uri, ICdmDataSource destination) {
|
83
|
super(defaultTransformer);
|
84
|
setSource(uri);
|
85
|
setDestination(destination);
|
86
|
}
|
87
|
|
88
|
/**
|
89
|
* @param url
|
90
|
* @param destination
|
91
|
*/
|
92
|
protected EfloraImportConfigurator(URI uri, ICdmDataSource destination, IInputTransformer transformer) {
|
93
|
super(transformer);
|
94
|
setSource(uri);
|
95
|
setDestination(destination);
|
96
|
}
|
97
|
|
98
|
|
99
|
/* (non-Javadoc)
|
100
|
* @see eu.etaxonomy.cdm.io.common.IImportConfigurator#getNewState()
|
101
|
*/
|
102
|
public EfloraImportState getNewState() {
|
103
|
return new EfloraImportState(this);
|
104
|
}
|
105
|
|
106
|
/**
|
107
|
* @return
|
108
|
*/
|
109
|
public Element getSourceRoot(){
|
110
|
try {
|
111
|
URL url = getSource().toURL();
|
112
|
Object o = url.getContent();
|
113
|
InputStream is = (InputStream)o;
|
114
|
Element root = XmlHelp.getRoot(is);
|
115
|
// makeNamespaces(root);
|
116
|
return root;
|
117
|
} catch (MalformedURLException e) {
|
118
|
e.printStackTrace();
|
119
|
}catch (Exception e) {
|
120
|
// TODO Auto-generated catch block
|
121
|
e.printStackTrace();
|
122
|
}
|
123
|
return null;
|
124
|
}
|
125
|
|
126
|
|
127
|
/* (non-Javadoc)
|
128
|
* @see eu.etaxonomy.cdm.io.common.ImportConfiguratorBase#getSourceReference()
|
129
|
*/
|
130
|
@Override
|
131
|
public Reference getSourceReference() {
|
132
|
//TODO
|
133
|
if (this.sourceReference == null){
|
134
|
logger.warn("getSource Reference not yet fully implemented");
|
135
|
sourceReference = ReferenceFactory.newGeneric();
|
136
|
sourceReference.setTitleCache(sourceReferenceTitle, true);
|
137
|
}
|
138
|
return sourceReference;
|
139
|
}
|
140
|
|
141
|
|
142
|
/* (non-Javadoc)
|
143
|
* @see eu.etaxonomy.cdm.io.common.IImportConfigurator#getSourceNameString()
|
144
|
*/
|
145
|
public String getSourceNameString() {
|
146
|
if (this.getSource() == null){
|
147
|
return null;
|
148
|
}else{
|
149
|
return this.getSource().toString();
|
150
|
}
|
151
|
}
|
152
|
|
153
|
public void setClassificationTitle(String classificationTitle) {
|
154
|
this.classificationTitle = classificationTitle;
|
155
|
}
|
156
|
|
157
|
public String getClassificationTitle() {
|
158
|
return classificationTitle;
|
159
|
}
|
160
|
|
161
|
|
162
|
|
163
|
public UUID getLastTaxonUuid() {
|
164
|
return lastTaxonUuid;
|
165
|
}
|
166
|
|
167
|
public void setLastTaxonUuid(UUID lastTaxonUuid) {
|
168
|
this.lastTaxonUuid = lastTaxonUuid;
|
169
|
}
|
170
|
|
171
|
public void setDoPrintKeys(boolean doPrintKeys) {
|
172
|
this.doPrintKeys = doPrintKeys;
|
173
|
}
|
174
|
|
175
|
public boolean isDoPrintKeys() {
|
176
|
return doPrintKeys;
|
177
|
}
|
178
|
|
179
|
public UUID getDefaultLanguageUuid() {
|
180
|
return this.defaultLanguageUuid;
|
181
|
}
|
182
|
|
183
|
public void setDefaultLanguageUuid(UUID defaultLanguageUuid) {
|
184
|
this.defaultLanguageUuid = defaultLanguageUuid;
|
185
|
}
|
186
|
|
187
|
public boolean isDoTaxa() {
|
188
|
return doTaxa;
|
189
|
}
|
190
|
public void setDoTaxa(boolean doTaxa) {
|
191
|
this.doTaxa = doTaxa;
|
192
|
}
|
193
|
|
194
|
|
195
|
|
196
|
|
197
|
|
198
|
}
|