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.sdd;
|
11
|
|
12
|
import java.io.InputStream;
|
13
|
import java.net.MalformedURLException;
|
14
|
import java.net.URL;
|
15
|
|
16
|
import org.apache.log4j.Logger;
|
17
|
import org.jdom.Element;
|
18
|
import org.jdom.Namespace;
|
19
|
|
20
|
import eu.etaxonomy.cdm.common.XmlHelp;
|
21
|
import eu.etaxonomy.cdm.database.ICdmDataSource;
|
22
|
import eu.etaxonomy.cdm.io.common.IImportConfigurator;
|
23
|
import eu.etaxonomy.cdm.io.common.IMatchingImportConfigurator;
|
24
|
import eu.etaxonomy.cdm.io.common.ImportConfiguratorBase;
|
25
|
import eu.etaxonomy.cdm.io.common.ImportStateBase;
|
26
|
import eu.etaxonomy.cdm.io.common.mapping.IInputTransformer;
|
27
|
import eu.etaxonomy.cdm.model.reference.IDatabase;
|
28
|
import eu.etaxonomy.cdm.model.reference.ReferenceBase;
|
29
|
import eu.etaxonomy.cdm.model.reference.ReferenceFactory;
|
30
|
|
31
|
/**
|
32
|
* @author h.fradin
|
33
|
* @created 24.10.2008
|
34
|
* @version 1.0
|
35
|
*/
|
36
|
public class SDDImportConfigurator extends ImportConfiguratorBase implements IImportConfigurator, IMatchingImportConfigurator {
|
37
|
private static final Logger logger = Logger.getLogger(SDDImportConfigurator.class);
|
38
|
|
39
|
//TODO
|
40
|
private static IInputTransformer defaultTransformer = null;
|
41
|
|
42
|
private boolean doMatchTaxa = false;
|
43
|
|
44
|
//xml xmlNamespace
|
45
|
Namespace sddNamespace;
|
46
|
|
47
|
protected void makeIoClassList(){
|
48
|
ioClassList = new Class[]{
|
49
|
SDDImport.class
|
50
|
};
|
51
|
};
|
52
|
|
53
|
public static SDDImportConfigurator NewInstance(String url,
|
54
|
ICdmDataSource destination){
|
55
|
return new SDDImportConfigurator(url, destination);
|
56
|
}
|
57
|
|
58
|
|
59
|
/**
|
60
|
* @param berlinModelSource
|
61
|
* @param sourceReference
|
62
|
* @param destination
|
63
|
*/
|
64
|
private SDDImportConfigurator(String url, ICdmDataSource destination) {
|
65
|
super(defaultTransformer);
|
66
|
setSource(url);
|
67
|
setDestination(destination);
|
68
|
}
|
69
|
|
70
|
|
71
|
|
72
|
|
73
|
/* (non-Javadoc)
|
74
|
* @see eu.etaxonomy.cdm.io.common.IImportConfigurator#getNewState()
|
75
|
*/
|
76
|
public SDDImportState getNewState() {
|
77
|
return new SDDImportState(this);
|
78
|
}
|
79
|
|
80
|
/* (non-Javadoc)
|
81
|
* @see eu.etaxonomy.cdm.io.common.ImportConfiguratorBase#getSource()
|
82
|
*/
|
83
|
public String getSource() {
|
84
|
return (String)super.getSource();
|
85
|
}
|
86
|
|
87
|
/**
|
88
|
* @param file
|
89
|
*/
|
90
|
public void setSource(String file) {
|
91
|
super.setSource(file);
|
92
|
}
|
93
|
|
94
|
/**
|
95
|
* @return
|
96
|
*/
|
97
|
public Element getSourceRoot(){
|
98
|
String source = getSource();
|
99
|
try {
|
100
|
URL url;
|
101
|
url = new URL(source);
|
102
|
Object o = url.getContent();
|
103
|
InputStream is = (InputStream)o;
|
104
|
Element root = XmlHelp.getRoot(is);
|
105
|
makeNamespaces(root);
|
106
|
return root;
|
107
|
} catch (MalformedURLException e) {
|
108
|
e.printStackTrace();
|
109
|
}catch (Exception e) {
|
110
|
// TODO Auto-generated catch block
|
111
|
e.printStackTrace();
|
112
|
}
|
113
|
return null;
|
114
|
}
|
115
|
|
116
|
private boolean makeNamespaces(Element root){
|
117
|
sddNamespace = root.getNamespace();
|
118
|
return true;
|
119
|
}
|
120
|
|
121
|
|
122
|
/* (non-Javadoc)
|
123
|
* @see eu.etaxonomy.cdm.io.common.ImportConfiguratorBase#getSourceReference()
|
124
|
*/
|
125
|
@Override
|
126
|
public ReferenceBase getSourceReference() {
|
127
|
//TODO
|
128
|
if (this.sourceReference == null){
|
129
|
logger.warn("getSource Reference not yet fully implemented");
|
130
|
sourceReference = ReferenceFactory.newDatabase();
|
131
|
sourceReference.setTitleCache("XXX", true);
|
132
|
}
|
133
|
return sourceReference;
|
134
|
}
|
135
|
|
136
|
|
137
|
/* (non-Javadoc)
|
138
|
* @see eu.etaxonomy.cdm.io.common.IImportConfigurator#getSourceNameString()
|
139
|
*/
|
140
|
public String getSourceNameString() {
|
141
|
if (this.getSource() == null){
|
142
|
return null;
|
143
|
}else{
|
144
|
return this.getSource();
|
145
|
}
|
146
|
}
|
147
|
|
148
|
public Namespace getSddNamespace() {
|
149
|
return sddNamespace;
|
150
|
}
|
151
|
|
152
|
public void setSddNamespace(Namespace xmlNamespace) {
|
153
|
this.sddNamespace = xmlNamespace;
|
154
|
}
|
155
|
|
156
|
/**
|
157
|
* @param doMatchTaxa the doMatchTaxa to set
|
158
|
*/
|
159
|
public void setDoMatchTaxa(boolean doMatchTaxa) {
|
160
|
this.doMatchTaxa = doMatchTaxa;
|
161
|
}
|
162
|
|
163
|
/**
|
164
|
* @return the doMatchTaxa
|
165
|
*/
|
166
|
public boolean isDoMatchTaxa() {
|
167
|
return doMatchTaxa;
|
168
|
}
|
169
|
}
|