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