1
2
3
4
5
6
7
8
9
10 package eu.etaxonomy.cdm.io.reference.endnote.in;
11
12 import java.io.InputStream;
13 import java.lang.reflect.Method;
14 import java.net.MalformedURLException;
15 import java.net.URL;
16
17 import org.apache.log4j.Logger;
18 import org.jdom.Element;
19 import org.jdom.Namespace;
20 import org.springframework.stereotype.Component;
21
22 import eu.etaxonomy.cdm.common.XmlHelp;
23 import eu.etaxonomy.cdm.database.ICdmDataSource;
24 import eu.etaxonomy.cdm.io.common.IImportConfigurator;
25 import eu.etaxonomy.cdm.io.common.ImportConfiguratorBase;
26 import eu.etaxonomy.cdm.io.common.ImportStateBase;
27 import eu.etaxonomy.cdm.io.common.IImportConfigurator.CHECK;
28 import eu.etaxonomy.cdm.io.common.mapping.IInputTransformer;
29 import eu.etaxonomy.cdm.io.jaxb.JaxbExport;
30 import eu.etaxonomy.cdm.model.reference.IDatabase;
31 import eu.etaxonomy.cdm.model.reference.ReferenceBase;
32 import eu.etaxonomy.cdm.model.reference.ReferenceFactory;
33
34 @Component
35 public class EndnoteImportConfigurator extends ImportConfiguratorBase<EndnoteImportState> implements IImportConfigurator {
36 private static final Logger logger = Logger.getLogger(EndnoteImportConfigurator.class);
37
38 public static EndnoteImportConfigurator NewInstance(String url,
39 ICdmDataSource destination){
40 return new EndnoteImportConfigurator(url, destination);
41 }
42
43 private boolean doRecords = true;
44
45
46 private Method functionRecordsDetailed = null;
47 private IEndnotePlaceholderClass placeholderClass;
48
49
50 private static IInputTransformer defaultTransformer = null;
51
52
53
54 Namespace EndnoteNamespace;
55
56
57
58
59
60
61
62
63
64
65
66
67 private EndnoteImportConfigurator() {
68 super(defaultTransformer);
69
70
71 }
72
73
74
75
76
77 private EndnoteImportConfigurator(String url, ICdmDataSource destination) {
78 super(defaultTransformer);
79 setSource(url);
80 setDestination(destination);
81 }
82
83
84
85
86
87
88 public EndnoteImportState getNewState() {
89 return new EndnoteImportState(this);
90 }
91
92
93
94
95 public String getSource() {
96 return (String)super.getSource();
97 }
98
99
100
101
102 public void setSource(String file) {
103 super.setSource(file);
104 }
105
106
107
108
109 public Element getSourceRoot(){
110 String source = getSource();
111 try {
112 URL url;
113 url = new URL(source);
114 Object o = url.getContent();
115 InputStream is = (InputStream)o;
116 Element root = XmlHelp.getRoot(is);
117 makeNamespaces(root);
118 return root;
119 } catch (MalformedURLException e) {
120 e.printStackTrace();
121 }catch (Exception e) {
122
123 e.printStackTrace();
124 }
125 return null;
126 }
127
128 private boolean makeNamespaces(Element root){
129 EndnoteNamespace = root.getNamespace();
130 if (EndnoteNamespace == null){
131 logger.warn("At least one Namespace is NULL");
132 }
133 return true;
134 }
135
136
137
138
139 @Override
140 public ReferenceBase getSourceReference() {
141
142 if (this.sourceReference == null){
143 logger.warn("getSource Reference not yet fully implemented");
144 ReferenceFactory refFactory = ReferenceFactory.newInstance();
145 sourceReference = refFactory.newDatabase();
146 sourceReference.setTitleCache("XXX", true);
147 }
148 return sourceReference;
149 }
150
151
152
153
154 public String getSourceNameString() {
155 if (this.getSource() == null){
156 return null;
157 }else{
158 return this.getSource();
159 }
160 }
161
162 public Namespace getEndnoteNamespace() {
163 return EndnoteNamespace;
164 }
165
166 public void setEndnoteNamespace(Namespace EndnoteNamespace) {
167 this.EndnoteNamespace = EndnoteNamespace;
168 }
169
170
171
172
173
174 public Method getFunctionRecordsDetailed() {
175 if (functionRecordsDetailed == null){
176
177
178 }
179 return functionRecordsDetailed;
180
181 }
182
183
184
185
186 public void setFunctionRecordsDetailed(Method functionRecordsDetailed) {
187 this.functionRecordsDetailed = functionRecordsDetailed;
188 }
189
190
191
192
193 public boolean isDoRecords() {
194 return doRecords;
195 }
196
197
198
199
200 public void setDoRecords(boolean doRecords) {
201 this.doRecords = doRecords;
202 }
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221 public IEndnotePlaceholderClass getPlaceholderClass() {
222 if (placeholderClass == null){
223 placeholderClass = new IEndnotePlaceholderClass();
224 }
225 return placeholderClass;
226 }
227
228
229
230
231 public void setPlaceholderClass(IEndnotePlaceholderClass placeholderClass) {
232 this.placeholderClass = placeholderClass;
233 }
234
235 @Override
236 protected void makeIoClassList() {
237
238
239 }
240
241
242 }