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