refactoring the references for imports...
[cdmlib.git] / cdmlib-io / src / main / java / eu / etaxonomy / cdm / io / reference / endnote / in / EndnoteImportConfigurator.java
1 /**
2 * Copyright (C) 2009 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.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.model.reference.IDatabase;
27 import eu.etaxonomy.cdm.model.reference.ReferenceBase;
28 import eu.etaxonomy.cdm.model.reference.ReferenceFactory;
29
30 @Component
31 public class EndnoteImportConfigurator extends ImportConfiguratorBase<EndnoteImportState> implements IImportConfigurator {
32 private static final Logger logger = Logger.getLogger(EndnoteImportConfigurator.class);
33
34 public static EndnoteImportConfigurator NewInstance(String url,
35 ICdmDataSource destination){
36 return new EndnoteImportConfigurator(url, destination);
37 }
38
39 private boolean doRecords = true;
40 // private boolean doSpecimen = true;
41
42 private Method functionRecordsDetailed = null;
43 private IEndnotePlaceholderClass placeholderClass;
44
45 // rdfNamespace
46 Namespace EndnoteNamespace;
47
48 protected void makeIoClassList(){
49 ioClassList = new Class[]{
50 EndnoteRecordsImport.class
51 };
52 };
53
54 /**
55 * @param berlinModelSource
56 * @param sourceReference
57 * @param destination
58 */
59 private EndnoteImportConfigurator() {
60 super();
61 // setSource(url);
62 // setDestination(destination);
63 }
64
65 /**
66 * @param berlinModelSource
67 * @param sourceReference
68 * @param destination
69 */
70 private EndnoteImportConfigurator(String url, ICdmDataSource destination) {
71 super();
72 setSource(url);
73 setDestination(destination);
74 }
75
76
77
78 /* (non-Javadoc)
79 * @see eu.etaxonomy.cdm.io.common.IImportConfigurator#getNewState()
80 */
81 public EndnoteImportState getNewState() {
82 return new EndnoteImportState(this);
83 }
84
85 /* (non-Javadoc)
86 * @see eu.etaxonomy.cdm.io.common.ImportConfiguratorBase#getSource()
87 */
88 public String getSource() {
89 return (String)super.getSource();
90 }
91
92 /**
93 * @param file
94 */
95 public void setSource(String file) {
96 super.setSource(file);
97 }
98
99 /**
100 * @return
101 */
102 public Element getSourceRoot(){
103 String source = getSource();
104 try {
105 URL url;
106 url = new URL(source);
107 Object o = url.getContent();
108 InputStream is = (InputStream)o;
109 Element root = XmlHelp.getRoot(is);
110 makeNamespaces(root);
111 return root;
112 } catch (MalformedURLException e) {
113 e.printStackTrace();
114 }catch (Exception e) {
115 // TODO Auto-generated catch block
116 e.printStackTrace();
117 }
118 return null;
119 }
120
121 private boolean makeNamespaces(Element root){
122 EndnoteNamespace = root.getNamespace();
123 if (EndnoteNamespace == null){
124 logger.warn("At least one Namespace is NULL");
125 }
126 return true;
127 }
128
129 /* (non-Javadoc)
130 * @see eu.etaxonomy.cdm.io.common.ImportConfiguratorBase#getSourceReference()
131 */
132 @Override
133 public ReferenceBase getSourceReference() {
134 //TODO
135 if (this.sourceReference == null){
136 logger.warn("getSource Reference not yet fully implemented");
137 ReferenceFactory refFactory = ReferenceFactory.newInstance();
138 sourceReference = refFactory.newDatabase();
139 sourceReference.setTitleCache("XXX");
140 }
141 return sourceReference;
142 }
143
144 /* (non-Javadoc)
145 * @see eu.etaxonomy.cdm.io.common.IImportConfigurator#getSourceNameString()
146 */
147 public String getSourceNameString() {
148 if (this.getSource() == null){
149 return null;
150 }else{
151 return this.getSource();
152 }
153 }
154
155 public Namespace getEndnoteNamespace() {
156 return EndnoteNamespace;
157 }
158
159 public void setEndnoteNamespace(Namespace EndnoteNamespace) {
160 this.EndnoteNamespace = EndnoteNamespace;
161 }
162
163
164 /**
165 * @return the funMetaDataDetailed
166 */
167 public Method getFunctionRecordsDetailed() {
168 if (functionRecordsDetailed == null){
169 functionRecordsDetailed = getDefaultFunction(EndnoteRecordsImport.class, "defaultRecordsDetailedFunction");
170 }
171 return functionRecordsDetailed;
172
173 }
174
175 /**
176 * @param funMetaDataDetailed the funMetaDataDetailed to set
177 */
178 public void setFunctionRecordsDetailed(Method functionRecordsDetailed) {
179 this.functionRecordsDetailed = functionRecordsDetailed;
180 }
181
182 /**
183 * @return the doMetaData
184 */
185 public boolean isDoRecords() {
186 return doRecords;
187 }
188
189 /**
190 * @param doMetaData the doMetaData to set
191 */
192 public void setDoRecords(boolean doRecords) {
193 this.doRecords = doRecords;
194 }
195
196 /**
197 * @return the doSpecimen
198 */
199 // public boolean isDoSpecimen() {
200 // return doSpecimen;
201 // }
202
203 /**
204 * @param doSpecimen the doSpecimen to set
205 */
206 // public void setDoSpecimen(boolean doSpecimen) {
207 // this.doSpecimen = doSpecimen;
208 // }
209
210 /**
211 * @return the placeholderClass
212 */
213 public IEndnotePlaceholderClass getPlaceholderClass() {
214 if (placeholderClass == null){
215 placeholderClass = new IEndnotePlaceholderClass();
216 }
217 return placeholderClass;
218 }
219
220 /**
221 * @param placeholderClass the placeholderClass to set
222 */
223 public void setPlaceholderClass(IEndnotePlaceholderClass placeholderClass) {
224 this.placeholderClass = placeholderClass;
225 }
226
227 }