import state more generic (-> also tcsRdf)
[cdmlib.git] / cdmlib-io / src / main / java / eu / etaxonomy / cdm / io / tcsrdf / TcsRdfImportConfigurator.java
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.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.model.reference.Database;
25 import eu.etaxonomy.cdm.model.reference.ReferenceBase;
26
27 /**
28 * @author a.mueller
29 * @created 29.05.2008
30 * @version 1.0
31 */
32 public class TcsRdfImportConfigurator extends ImportConfiguratorBase<TcsRdfImportState> implements IImportConfigurator {
33 private static final Logger logger = Logger.getLogger(TcsRdfImportConfigurator.class);
34
35 //rdfNamespace
36 Namespace rdfNamespace;
37 //TaxonConcept namespace
38 Namespace tcNamespace;
39 //TaxonName namespace
40 Namespace tnNamespace;
41 //TDWG common namespace
42 Namespace commonNamespace;
43 //TDWG geoNamespace
44 Namespace geoNamespace;
45 //publicationNamespace
46 Namespace publicationNamespace;
47
48 //TODO
49 protected static Namespace nsTcom = Namespace.getNamespace("http://rs.tdwg.org/ontology/voc/Common#");
50 protected static Namespace nsTn = Namespace.getNamespace("http://rs.tdwg.org/ontology/voc/TaxonName#");
51 protected static Namespace nsTgeo = Namespace.getNamespace("http://rs.tdwg.org/ontology/voc/GeographicRegion#");
52 protected static Namespace nsTc = Namespace.getNamespace("http://rs.tdwg.org/ontology/voc/TaxonConcept#");
53 protected static Namespace nsTpub = Namespace.getNamespace("http://rs.tdwg.org/ontology/voc/PublicationCitation#");
54 protected static Namespace nsTpalm = Namespace.getNamespace("http://wp5.e-taxonomy.eu/import/palmae/common");
55
56 protected void makeIoClassList(){
57 ioClassList = new Class[]{
58 TcsRdfReferenceImport.class
59 , TcsRdfTaxonNameImport.class
60 , TcsRdfTaxonNameRelationsImport.class
61 , TcsRdfTaxonImport.class
62 , TcsRdfTaxonRelationsImport.class
63 };
64 };
65
66 public static TcsRdfImportConfigurator NewInstance(String url,
67 ICdmDataSource destination){
68 return new TcsRdfImportConfigurator(url, destination);
69 }
70
71 //TODO for spring use only
72 private TcsRdfImportConfigurator(){
73
74 }
75
76
77 /**
78 * @param berlinModelSource
79 * @param sourceReference
80 * @param destination
81 */
82 private TcsRdfImportConfigurator(String url, ICdmDataSource destination) {
83 super();
84 setSource(url);
85 setDestination(destination);
86 }
87
88
89 /* (non-Javadoc)
90 * @see eu.etaxonomy.cdm.io.common.ImportConfiguratorBase#getSource()
91 */
92 public String getSource() {
93 return (String)super.getSource();
94 }
95
96 /**
97 * @param file
98 */
99 public void setSource(String file) {
100 super.setSource(file);
101 }
102
103 /**
104 * @return
105 */
106 public Element getSourceRoot(){
107 String source = getSource();
108 try {
109 URL url;
110 url = new URL(source);
111 Object o = url.getContent();
112 InputStream is = (InputStream)o;
113 Element root = XmlHelp.getRoot(is);
114 makeNamespaces(root);
115 return root;
116 } catch (MalformedURLException e) {
117 e.printStackTrace();
118 }catch (Exception e) {
119 // TODO Auto-generated catch block
120 e.printStackTrace();
121 }
122 return null;
123 }
124
125 private boolean makeNamespaces(Element root){
126 //String strTnNamespace = "http://rs.tdwg.org/ontology/voc/TaxonName#";
127 //Namespace taxonNameNamespace = Namespace.getNamespace("tn", strTnNamespace);
128
129 String prefix;
130 rdfNamespace = root.getNamespace();
131 prefix = "tc";
132 tcNamespace = root.getNamespace(prefix);
133 prefix = "tn";
134 tnNamespace = root.getNamespace(prefix);
135 prefix = "tcom";
136 commonNamespace = root.getNamespace(prefix);
137 prefix = "tgeo";
138 geoNamespace = root.getNamespace(prefix);
139 prefix = "tpub";
140 publicationNamespace = root.getNamespace(prefix);
141 if (rdfNamespace == null || tcNamespace == null || tnNamespace == null ||
142 commonNamespace == null || geoNamespace == null || publicationNamespace == null){
143 logger.warn("At least one Namespace is NULL");
144 }
145 return true;
146 }
147
148
149 /* (non-Javadoc)
150 * @see eu.etaxonomy.cdm.io.common.ImportConfiguratorBase#getSourceReference()
151 */
152 @Override
153 public ReferenceBase getSourceReference() {
154 //TODO
155 if (this.sourceReference == null){
156 logger.warn("getSource Reference not yet fully implemented");
157 sourceReference = Database.NewInstance();
158 sourceReference.setTitleCache("XXX");
159 }
160 return sourceReference;
161 }
162
163
164 /* (non-Javadoc)
165 * @see eu.etaxonomy.cdm.io.common.IImportConfigurator#getSourceNameString()
166 */
167 public String getSourceNameString() {
168 if (this.getSource() == null){
169 return null;
170 }else{
171 return this.getSource();
172 }
173 }
174
175 public Namespace getRdfNamespace() {
176 return rdfNamespace;
177 }
178
179 public void setRdfNamespace(Namespace rdfNamespace) {
180 this.rdfNamespace = rdfNamespace;
181 }
182
183 public Namespace getTcNamespace() {
184 return tcNamespace;
185 }
186
187 public void setTcNamespace(Namespace tcNamespace) {
188 this.tcNamespace = tcNamespace;
189 }
190
191 public Namespace getTnNamespace() {
192 return tnNamespace;
193 }
194
195 public void setTnNamespace(Namespace tnNamespace) {
196 this.tnNamespace = tnNamespace;
197 }
198
199 public Namespace getCommonNamespace() {
200 return commonNamespace;
201 }
202
203 public void setCommonNamespace(Namespace commonNamespace) {
204 this.commonNamespace = commonNamespace;
205 }
206
207 public Namespace getGeoNamespace() {
208 return geoNamespace;
209 }
210
211 public void setGeoNamespace(Namespace geoNamespace) {
212 this.geoNamespace = geoNamespace;
213 }
214
215 public Namespace getPublicationNamespace() {
216 return publicationNamespace;
217 }
218
219 public void setPublicationNamespace(Namespace publicationNamespace) {
220 this.publicationNamespace = publicationNamespace;
221 }
222
223
224
225
226 }