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