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
.model
.reference
.Database
;
25 import eu
.etaxonomy
.cdm
.model
.reference
.ReferenceBase
;
32 public class TcsRdfImportConfigurator
extends ImportConfiguratorBase
<TcsRdfImportState
> implements IImportConfigurator
{
33 private static final Logger logger
= Logger
.getLogger(TcsRdfImportConfigurator
.class);
36 Namespace rdfNamespace
;
37 //TaxonConcept namespace
38 Namespace tcNamespace
;
40 Namespace tnNamespace
;
41 //TDWG common namespace
42 Namespace commonNamespace
;
44 Namespace geoNamespace
;
45 //publicationNamespace
46 Namespace publicationNamespace
;
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");
56 protected void makeIoClassList(){
57 ioClassList
= new Class
[]{
58 TcsRdfReferenceImport
.class
59 , TcsRdfTaxonNameImport
.class
60 , TcsRdfTaxonNameRelationsImport
.class
61 , TcsRdfTaxonImport
.class
62 , TcsRdfTaxonRelationsImport
.class
66 public static TcsRdfImportConfigurator
NewInstance(String url
,
67 ICdmDataSource destination
){
68 return new TcsRdfImportConfigurator(url
, destination
);
71 //TODO for spring use only
72 private TcsRdfImportConfigurator(){
78 * @param berlinModelSource
79 * @param sourceReference
82 private TcsRdfImportConfigurator(String url
, ICdmDataSource destination
) {
85 setDestination(destination
);
90 * @see eu.etaxonomy.cdm.io.common.ImportConfiguratorBase#getSource()
92 public String
getSource() {
93 return (String
)super.getSource();
99 public void setSource(String file
) {
100 super.setSource(file
);
106 public Element
getSourceRoot(){
107 String source
= getSource();
110 url
= new URL(source
);
111 Object o
= url
.getContent();
112 InputStream is
= (InputStream
)o
;
113 Element root
= XmlHelp
.getRoot(is
);
114 makeNamespaces(root
);
116 } catch (MalformedURLException e
) {
118 }catch (Exception e
) {
119 // TODO Auto-generated catch block
125 private boolean makeNamespaces(Element root
){
126 //String strTnNamespace = "http://rs.tdwg.org/ontology/voc/TaxonName#";
127 //Namespace taxonNameNamespace = Namespace.getNamespace("tn", strTnNamespace);
130 rdfNamespace
= root
.getNamespace();
132 tcNamespace
= root
.getNamespace(prefix
);
134 tnNamespace
= root
.getNamespace(prefix
);
136 commonNamespace
= root
.getNamespace(prefix
);
138 geoNamespace
= root
.getNamespace(prefix
);
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");
150 * @see eu.etaxonomy.cdm.io.common.ImportConfiguratorBase#getSourceReference()
153 public ReferenceBase
getSourceReference() {
155 if (this.sourceReference
== null){
156 logger
.warn("getSource Reference not yet fully implemented");
157 sourceReference
= Database
.NewInstance();
158 sourceReference
.setTitleCache("XXX");
160 return sourceReference
;
165 * @see eu.etaxonomy.cdm.io.common.IImportConfigurator#getSourceNameString()
167 public String
getSourceNameString() {
168 if (this.getSource() == null){
171 return this.getSource();
175 public Namespace
getRdfNamespace() {
179 public void setRdfNamespace(Namespace rdfNamespace
) {
180 this.rdfNamespace
= rdfNamespace
;
183 public Namespace
getTcNamespace() {
187 public void setTcNamespace(Namespace tcNamespace
) {
188 this.tcNamespace
= tcNamespace
;
191 public Namespace
getTnNamespace() {
195 public void setTnNamespace(Namespace tnNamespace
) {
196 this.tnNamespace
= tnNamespace
;
199 public Namespace
getCommonNamespace() {
200 return commonNamespace
;
203 public void setCommonNamespace(Namespace commonNamespace
) {
204 this.commonNamespace
= commonNamespace
;
207 public Namespace
getGeoNamespace() {
211 public void setGeoNamespace(Namespace geoNamespace
) {
212 this.geoNamespace
= geoNamespace
;
215 public Namespace
getPublicationNamespace() {
216 return publicationNamespace
;
219 public void setPublicationNamespace(Namespace publicationNamespace
) {
220 this.publicationNamespace
= publicationNamespace
;