Project

General

Profile

Download (6.03 KB) Statistics
| Branch: | Tag: | Revision:
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.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
	static final CHECK check = CHECK.IMPORT_WITHOUT_CHECK;
38
	
39
	public static EndnoteImportConfigurator NewInstance(String url,
40
			ICdmDataSource destination){
41
		return new EndnoteImportConfigurator(url, destination);
42
	}
43
	
44
	private boolean doRecords = true;
45
//	private boolean doSpecimen = true;
46

    
47
	private Method functionRecordsDetailed = null; 
48
	private IEndnotePlaceholderClass placeholderClass;
49
	
50
	//TODO
51
	private static IInputTransformer defaultTransformer = null;
52

    
53
	
54
	//	rdfNamespace
55
	Namespace EndnoteNamespace;
56
/*TODO: wieder zur?ck!!!
57
	protected void makeIoClassList(){
58
		ioClassList = new Class[]{
59
			EndnoteRecordsImport.class
60
		};
61
	};
62
*/
63
	/**
64
	 * @param berlinModelSource
65
	 * @param sourceReference
66
	 * @param destination
67
	 */
68
	private EndnoteImportConfigurator() {
69
		super(defaultTransformer);
70
//		setSource(url);
71
//		setDestination(destination);
72
	}
73
	
74
	/**
75
	 * @param url
76
	 * @param destination
77
	 */
78
	private EndnoteImportConfigurator(String url, ICdmDataSource destination) {
79
		super(defaultTransformer);
80
		setSource(url);
81
		setDestination(destination);
82
	}
83
	
84
	
85

    
86
	/* (non-Javadoc)
87
	 * @see eu.etaxonomy.cdm.io.common.IImportConfigurator#getNewState()
88
	 */
89
	public EndnoteImportState getNewState() {
90
		return new EndnoteImportState(this);
91
	}
92

    
93
	/* (non-Javadoc)
94
	 * @see eu.etaxonomy.cdm.io.common.ImportConfiguratorBase#getSource()
95
	 */
96
	public String getSource() {
97
		return (String)super.getSource();
98
	}
99
	
100
	/**
101
	 * @param file
102
	 */
103
	public void setSource(String file) {
104
		super.setSource(file);
105
	}
106
	
107
	/**
108
	 * @return
109
	 */
110
	public Element getSourceRoot(){
111
		String source = getSource();
112
		try {
113
			URL url;
114
			url = new URL(source);
115
			Object o = url.getContent();
116
			InputStream is = (InputStream)o;
117
			Element root = XmlHelp.getRoot(is);
118
			makeNamespaces(root);
119
			return root;
120
		} catch (MalformedURLException e) {
121
			e.printStackTrace();
122
		}catch (Exception e) {
123
			// TODO Auto-generated catch block
124
			e.printStackTrace();
125
		}
126
		return null;
127
	}
128
	
129
	private boolean makeNamespaces(Element root){
130
		EndnoteNamespace = root.getNamespace();
131
		if (EndnoteNamespace == null){
132
			logger.warn("At least one Namespace is NULL");
133
		}
134
		return true;
135
	}
136

    
137
	/* (non-Javadoc)
138
	 * @see eu.etaxonomy.cdm.io.common.ImportConfiguratorBase#getSourceReference()
139
	 */
140
	@Override
141
	public ReferenceBase getSourceReference() {
142
		//TODO
143
		if (this.sourceReference == null){
144
			logger.warn("getSource Reference not yet fully implemented");
145
			ReferenceFactory refFactory = ReferenceFactory.newInstance();
146
			sourceReference = refFactory.newDatabase();
147
			sourceReference.setTitleCache("XXX");
148
		}
149
		return sourceReference;
150
	}
151

    
152
	/* (non-Javadoc)
153
	 * @see eu.etaxonomy.cdm.io.common.IImportConfigurator#getSourceNameString()
154
	 */
155
	public String getSourceNameString() {
156
		if (this.getSource() == null){
157
			return null;
158
		}else{
159
			return this.getSource();
160
		}
161
	}
162
	
163
	public Namespace getEndnoteNamespace() {
164
		return EndnoteNamespace;
165
	}
166

    
167
	public void setEndnoteNamespace(Namespace EndnoteNamespace) {
168
		this.EndnoteNamespace = EndnoteNamespace;
169
	}
170
	
171

    
172
	/**
173
	 * @return the funMetaDataDetailed
174
	 */
175
	public Method getFunctionRecordsDetailed() {
176
		if (functionRecordsDetailed == null){
177
			//TODO!!!
178
		//	functionRecordsDetailed = getDefaultFunction(EndnoteRecordsImport.class, "defaultRecordsDetailedFunction");
179
		}
180
		return functionRecordsDetailed;
181
		
182
	}
183

    
184
	/**
185
	 * @param funMetaDataDetailed the funMetaDataDetailed to set
186
	 */
187
	public void setFunctionRecordsDetailed(Method functionRecordsDetailed) {
188
		this.functionRecordsDetailed = functionRecordsDetailed;
189
	}
190
	
191
	/**
192
	 * @return the doMetaData
193
	 */
194
	public boolean isDoRecords() {
195
		return doRecords;
196
	}
197

    
198
	/**
199
	 * @param doMetaData the doMetaData to set
200
	 */
201
	public void setDoRecords(boolean doRecords) {
202
		this.doRecords = doRecords;
203
	}
204

    
205
	/**
206
	 * @return the doSpecimen
207
	 */
208
//	public boolean isDoSpecimen() {
209
//		return doSpecimen;
210
//	}
211

    
212
	/**
213
	 * @param doSpecimen the doSpecimen to set
214
	 */
215
//	public void setDoSpecimen(boolean doSpecimen) {
216
//		this.doSpecimen = doSpecimen;
217
//	}
218

    
219
	/**
220
	 * @return the placeholderClass
221
	 */
222
	public IEndnotePlaceholderClass getPlaceholderClass() {
223
		if (placeholderClass == null){
224
			placeholderClass = new IEndnotePlaceholderClass();
225
		}
226
		return placeholderClass;
227
	}
228

    
229
	/**
230
	 * @param placeholderClass the placeholderClass to set
231
	 */
232
	public void setPlaceholderClass(IEndnotePlaceholderClass placeholderClass) {
233
		this.placeholderClass = placeholderClass;
234
	}
235

    
236
	@Override
237
	protected void makeIoClassList() {
238
		ioClassList = new Class[] {
239
				EndNoteImportBase.class,
240
		};
241
		
242
	}
243

    
244
	
245
}
(2-2/5)