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 eu.etaxonomy.cdm.common.URI;
|
15
|
import java.net.URL;
|
16
|
|
17
|
import org.apache.logging.log4j.LogManager;import org.apache.logging.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.XmlImportConfiguratorBase;
|
26
|
import eu.etaxonomy.cdm.io.common.mapping.IInputTransformer;
|
27
|
import eu.etaxonomy.cdm.io.sdd.SDDTransformer;
|
28
|
import eu.etaxonomy.cdm.model.reference.Reference;
|
29
|
import eu.etaxonomy.cdm.model.reference.ReferenceFactory;
|
30
|
|
31
|
/**
|
32
|
* @author h.fradin
|
33
|
* @since 24.10.2008
|
34
|
*/
|
35
|
public class SDDImportConfigurator extends XmlImportConfiguratorBase<SDDImportState> implements IImportConfigurator, IMatchingImportConfigurator {
|
36
|
private static final long serialVersionUID = -960998183005112130L;
|
37
|
|
38
|
private static final Logger logger = LogManager.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
|
@Override
|
49
|
protected void makeIoClassList(){
|
50
|
ioClassList = new Class[]{
|
51
|
SDDImport.class
|
52
|
};
|
53
|
};
|
54
|
|
55
|
public static SDDImportConfigurator NewInstance(URI uri, ICdmDataSource destination){
|
56
|
return new SDDImportConfigurator(uri, destination);
|
57
|
}
|
58
|
|
59
|
|
60
|
/**
|
61
|
* @param berlinModelSource
|
62
|
* @param sourceReference
|
63
|
* @param destination
|
64
|
*/
|
65
|
private SDDImportConfigurator(URI uri, ICdmDataSource destination) {
|
66
|
super(defaultTransformer);
|
67
|
setSource(uri);
|
68
|
setDestination(destination);
|
69
|
}
|
70
|
|
71
|
|
72
|
@Override
|
73
|
public SDDImportState getNewState() {
|
74
|
return new SDDImportState(this);
|
75
|
}
|
76
|
|
77
|
|
78
|
/**
|
79
|
* @return
|
80
|
*/
|
81
|
public Element getSourceRoot(){
|
82
|
try {
|
83
|
URL url;
|
84
|
url = getSource().toURL();
|
85
|
Object o = url.getContent();
|
86
|
InputStream is = (InputStream)o;
|
87
|
Element root = XmlHelp.getRoot(is);
|
88
|
makeNamespaces(root);
|
89
|
return root;
|
90
|
} catch (MalformedURLException e) {
|
91
|
e.printStackTrace();
|
92
|
}catch (Exception e) {
|
93
|
// TODO Auto-generated catch block
|
94
|
e.printStackTrace();
|
95
|
}
|
96
|
return null;
|
97
|
}
|
98
|
|
99
|
private boolean makeNamespaces(Element root){
|
100
|
sddNamespace = root.getNamespace();
|
101
|
return true;
|
102
|
}
|
103
|
|
104
|
@Override
|
105
|
public Reference getSourceReference() {
|
106
|
//TODO
|
107
|
if (this.sourceReference == null){
|
108
|
logger.warn("getSource Reference not yet fully implemented");
|
109
|
sourceReference = ReferenceFactory.newDatabase();
|
110
|
sourceReference.setTitleCache("XXX", true);
|
111
|
}
|
112
|
return sourceReference;
|
113
|
}
|
114
|
|
115
|
@Override
|
116
|
public String getSourceNameString() {
|
117
|
if (this.getSource() == null){
|
118
|
return null;
|
119
|
}else{
|
120
|
return this.getSource().toString();
|
121
|
}
|
122
|
}
|
123
|
|
124
|
public Namespace getSddNamespace() {
|
125
|
return sddNamespace;
|
126
|
}
|
127
|
|
128
|
public void setSddNamespace(Namespace xmlNamespace) {
|
129
|
this.sddNamespace = xmlNamespace;
|
130
|
}
|
131
|
|
132
|
/**
|
133
|
* @param doMatchTaxa the doMatchTaxa to set
|
134
|
*/
|
135
|
@Override
|
136
|
public void setReuseExistingTaxaWhenPossible(boolean doMatchTaxa) {
|
137
|
this.doMatchTaxa = doMatchTaxa;
|
138
|
}
|
139
|
|
140
|
/**
|
141
|
* @return the doMatchTaxa
|
142
|
*/
|
143
|
@Override
|
144
|
public boolean isReuseExistingTaxaWhenPossible() {
|
145
|
return doMatchTaxa;
|
146
|
}
|
147
|
}
|