2 * Copyright (C) 2007 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
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.
10 package eu
.etaxonomy
.cdm
.io
.tcsrdf
;
12 import java
.io
.InputStream
;
13 import java
.net
.MalformedURLException
;
16 import org
.apache
.log4j
.Logger
;
17 import org
.jdom
.Element
;
18 import org
.jdom
.Namespace
;
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
.model
.reference
.Database
;
26 import eu
.etaxonomy
.cdm
.model
.reference
.ReferenceBase
;
33 public class TcsRdfImportConfigurator
extends ImportConfiguratorBase
<TcsRdfImportState
> implements IImportConfigurator
{
34 private static final Logger logger
= Logger
.getLogger(TcsRdfImportConfigurator
.class);
37 Namespace rdfNamespace
;
38 //TaxonConcept namespace
39 Namespace tcNamespace
;
41 Namespace tnNamespace
;
42 //TDWG common namespace
43 Namespace commonNamespace
;
45 Namespace geoNamespace
;
46 //publicationNamespace
47 Namespace publicationNamespace
;
50 protected static Namespace nsTcom
= Namespace
.getNamespace("http://rs.tdwg.org/ontology/voc/Common#");
51 protected static Namespace nsTn
= Namespace
.getNamespace("http://rs.tdwg.org/ontology/voc/TaxonName#");
52 protected static Namespace nsTgeo
= Namespace
.getNamespace("http://rs.tdwg.org/ontology/voc/GeographicRegion#");
53 protected static Namespace nsTc
= Namespace
.getNamespace("http://rs.tdwg.org/ontology/voc/TaxonConcept#");
54 protected static Namespace nsTpub
= Namespace
.getNamespace("http://rs.tdwg.org/ontology/voc/PublicationCitation#");
55 protected static Namespace nsTpalm
= Namespace
.getNamespace("http://wp5.e-taxonomy.eu/import/palmae/common");
57 protected void makeIoClassList(){
58 ioClassList
= new Class
[]{
59 TcsRdfReferenceImport
.class
60 , TcsRdfTaxonNameImport
.class
61 , TcsRdfTaxonNameRelationsImport
.class
62 , TcsRdfTaxonImport
.class
63 , TcsRdfTaxonRelationsImport
.class
67 public static TcsRdfImportConfigurator
NewInstance(String url
,
68 ICdmDataSource destination
){
69 return new TcsRdfImportConfigurator(url
, destination
);
72 //TODO for spring use only
73 private TcsRdfImportConfigurator(){
79 * @param berlinModelSource
80 * @param sourceReference
83 private TcsRdfImportConfigurator(String url
, ICdmDataSource destination
) {
86 setDestination(destination
);
91 * @see eu.etaxonomy.cdm.io.common.ImportConfiguratorBase#getSource()
93 public String
getSource() {
94 return (String
)super.getSource();
100 public void setSource(String file
) {
101 super.setSource(file
);
107 public Element
getSourceRoot(){
108 String source
= getSource();
111 url
= new URL(source
);
112 Object o
= url
.getContent();
113 InputStream is
= (InputStream
)o
;
114 Element root
= XmlHelp
.getRoot(is
);
115 makeNamespaces(root
);
117 } catch (MalformedURLException e
) {
119 }catch (Exception e
) {
120 // TODO Auto-generated catch block
126 private boolean makeNamespaces(Element root
){
127 //String strTnNamespace = "http://rs.tdwg.org/ontology/voc/TaxonName#";
128 //Namespace taxonNameNamespace = Namespace.getNamespace("tn", strTnNamespace);
131 rdfNamespace
= root
.getNamespace();
133 tcNamespace
= root
.getNamespace(prefix
);
135 tnNamespace
= root
.getNamespace(prefix
);
137 commonNamespace
= root
.getNamespace(prefix
);
139 geoNamespace
= root
.getNamespace(prefix
);
141 publicationNamespace
= root
.getNamespace(prefix
);
142 if (rdfNamespace
== null || tcNamespace
== null || tnNamespace
== null ||
143 commonNamespace
== null || geoNamespace
== null || publicationNamespace
== null){
144 logger
.warn("At least one Namespace is NULL");
151 * @see eu.etaxonomy.cdm.io.common.ImportConfiguratorBase#getSourceReference()
154 public ReferenceBase
getSourceReference() {
156 if (this.sourceReference
== null){
157 logger
.warn("getSource Reference not yet fully implemented");
158 sourceReference
= Database
.NewInstance();
159 sourceReference
.setTitleCache("XXX");
161 return sourceReference
;
166 * @see eu.etaxonomy.cdm.io.common.IImportConfigurator#getSourceNameString()
168 public String
getSourceNameString() {
169 if (this.getSource() == null){
172 return this.getSource();
176 public Namespace
getRdfNamespace() {
180 public void setRdfNamespace(Namespace rdfNamespace
) {
181 this.rdfNamespace
= rdfNamespace
;
184 public Namespace
getTcNamespace() {
188 public void setTcNamespace(Namespace tcNamespace
) {
189 this.tcNamespace
= tcNamespace
;
192 public Namespace
getTnNamespace() {
196 public void setTnNamespace(Namespace tnNamespace
) {
197 this.tnNamespace
= tnNamespace
;
200 public Namespace
getCommonNamespace() {
201 return commonNamespace
;
204 public void setCommonNamespace(Namespace commonNamespace
) {
205 this.commonNamespace
= commonNamespace
;
208 public Namespace
getGeoNamespace() {
212 public void setGeoNamespace(Namespace geoNamespace
) {
213 this.geoNamespace
= geoNamespace
;
216 public Namespace
getPublicationNamespace() {
217 return publicationNamespace
;
220 public void setPublicationNamespace(Namespace publicationNamespace
) {
221 this.publicationNamespace
= publicationNamespace
;
225 * @see eu.etaxonomy.cdm.io.common.IImportConfigurator#getNewState()
227 public TcsRdfImportState
getNewState() {
228 return new TcsRdfImportState(this);