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