1
2
3
4
5
6
7
8
9
10 package eu.etaxonomy.cdm.io.tcsrdf;
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.mapping.IInputTransformer;
25 import eu.etaxonomy.cdm.model.reference.IDatabase;
26 import eu.etaxonomy.cdm.model.reference.ReferenceBase;
27 import eu.etaxonomy.cdm.model.reference.ReferenceFactory;
28
29
30
31
32
33
34 public class TcsRdfImportConfigurator extends ImportConfiguratorBase<TcsRdfImportState> implements IImportConfigurator {
35 private static final Logger logger = Logger.getLogger(TcsRdfImportConfigurator.class);
36
37
38
39 private static IInputTransformer defaultTransformer = null;
40
41
42
43 private boolean isPublishReferences = true;
44
45
46 private Namespace rdfNamespace;
47
48 private Namespace tcNamespace;
49
50 private Namespace tnNamespace;
51
52 private Namespace commonNamespace;
53
54 private Namespace geoNamespace;
55
56 private Namespace publicationNamespace;
57
58 private Namespace palmNamespace;
59
60
61 protected static Namespace nsTcom = Namespace.getNamespace("http://rs.tdwg.org/ontology/voc/Common#");
62 protected static Namespace nsTn = Namespace.getNamespace("http://rs.tdwg.org/ontology/voc/TaxonName#");
63 protected static Namespace nsTgeo = Namespace.getNamespace("http://rs.tdwg.org/ontology/voc/GeographicRegion#");
64 protected static Namespace nsTc = Namespace.getNamespace("http://rs.tdwg.org/ontology/voc/TaxonConcept#");
65 protected static Namespace nsTpub = Namespace.getNamespace("http://rs.tdwg.org/ontology/voc/PublicationCitation#");
66 protected static Namespace nsTpalm = Namespace.getNamespace("http://wp5.e-taxonomy.eu/import/palmae/common");
67
68 protected void makeIoClassList(){
69 ioClassList = new Class[]{
70 TcsRdfReferenceImport.class
71 , TcsRdfTaxonNameImport.class
72 , TcsRdfTaxonNameRelationsImport.class
73 , TcsRdfTaxonImport.class
74 , TcsRdfTaxonRelationsImport.class
75 };
76 };
77
78 public static TcsRdfImportConfigurator NewInstance(String url,
79 ICdmDataSource destination){
80 return new TcsRdfImportConfigurator(url, destination);
81 }
82
83
84 private TcsRdfImportConfigurator(){
85 super(defaultTransformer);
86
87 }
88
89
90
91
92
93
94
95 private TcsRdfImportConfigurator(String url, ICdmDataSource destination) {
96 super(defaultTransformer);
97 setSource(url);
98 setDestination(destination);
99 }
100
101
102
103
104
105 public String getSource() {
106 return (String)super.getSource();
107 }
108
109
110
111
112 public void setSource(String file) {
113 super.setSource(file);
114 }
115
116
117
118
119 public Element getSourceRoot(){
120 String source = getSource();
121 try {
122 URL url;
123 url = new URL(source);
124 Object o = url.getContent();
125 InputStream is = (InputStream)o;
126 Element root = XmlHelp.getRoot(is);
127 makeNamespaces(root);
128 return root;
129 } catch (MalformedURLException e) {
130 e.printStackTrace();
131 }catch (Exception e) {
132
133 e.printStackTrace();
134 }
135 return null;
136 }
137
138 private boolean makeNamespaces(Element root){
139
140
141
142 String prefix;
143 rdfNamespace = root.getNamespace();
144 prefix = "tc";
145 tcNamespace = root.getNamespace(prefix);
146 prefix = "tn";
147 tnNamespace = root.getNamespace(prefix);
148 prefix = "tcom";
149 commonNamespace = root.getNamespace(prefix);
150 prefix = "tgeo";
151 geoNamespace = root.getNamespace(prefix);
152 prefix = "tpub";
153 publicationNamespace = root.getNamespace(prefix);
154
155 prefix = "tpalm";
156 palmNamespace = root.getNamespace(prefix);
157
158 if (rdfNamespace == null || tcNamespace == null || tnNamespace == null ||
159 commonNamespace == null || geoNamespace == null || publicationNamespace == null
160 || palmNamespace == null){
161 logger.warn("At least one Namespace is NULL");
162 }
163 return true;
164 }
165
166
167
168
169
170 @Override
171 public ReferenceBase getSourceReference() {
172
173 if (this.sourceReference == null){
174 logger.warn("getSource Reference not yet fully implemented");
175 ReferenceFactory refFactory = ReferenceFactory.newInstance();
176 sourceReference = refFactory.newDatabase();
177 sourceReference.setTitleCache("XXX", true);
178 }
179 return sourceReference;
180 }
181
182
183
184
185
186 public String getSourceNameString() {
187 if (this.getSource() == null){
188 return null;
189 }else{
190 return this.getSource();
191 }
192 }
193
194 public Namespace getRdfNamespace() {
195 return rdfNamespace;
196 }
197
198 public void setRdfNamespace(Namespace rdfNamespace) {
199 this.rdfNamespace = rdfNamespace;
200 }
201
202 public Namespace getTcNamespace() {
203 return tcNamespace;
204 }
205
206 public void setTcNamespace(Namespace tcNamespace) {
207 this.tcNamespace = tcNamespace;
208 }
209
210 public Namespace getTnNamespace() {
211 return tnNamespace;
212 }
213
214 public void setTnNamespace(Namespace tnNamespace) {
215 this.tnNamespace = tnNamespace;
216 }
217
218 public Namespace getCommonNamespace() {
219 return commonNamespace;
220 }
221
222 public void setCommonNamespace(Namespace commonNamespace) {
223 this.commonNamespace = commonNamespace;
224 }
225
226 public Namespace getGeoNamespace() {
227 return geoNamespace;
228 }
229
230 public void setGeoNamespace(Namespace geoNamespace) {
231 this.geoNamespace = geoNamespace;
232 }
233
234 public Namespace getPublicationNamespace() {
235 return publicationNamespace;
236 }
237
238 public void setPublicationNamespace(Namespace publicationNamespace) {
239 this.publicationNamespace = publicationNamespace;
240 }
241
242
243
244 public Namespace getPalmNamespace() {
245 return palmNamespace;
246 }
247
248
249
250
251 public void setPalmNamespace(Namespace palmNamespace) {
252 this.palmNamespace = palmNamespace;
253 }
254
255
256
257
258
259 public boolean isPublishReferences() {
260 return isPublishReferences;
261 }
262
263
264
265
266 public void setPublishReferences(boolean isPublishReferences) {
267 this.isPublishReferences = isPublishReferences;
268 }
269
270
271
272
273 public TcsRdfImportState getNewState() {
274 return new TcsRdfImportState(this);
275 }
276
277
278
279
280 }