Project

General

Profile

Download (5.73 KB) Statistics
| Branch: | 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.redlist.bfnXml;
11

    
12
/**
13
 * @author a.oppermann
14
 * @date 03.07.2013
15
 *
16
 */
17
import java.io.InputStream;
18
import java.net.MalformedURLException;
19
import java.net.URI;
20
import java.net.URL;
21

    
22
import org.apache.log4j.Logger;
23
import org.jdom.Element;
24
import org.jdom.Namespace;
25
import org.springframework.stereotype.Component;
26

    
27
import eu.etaxonomy.cdm.common.XmlHelp;
28
import eu.etaxonomy.cdm.database.ICdmDataSource;
29
import eu.etaxonomy.cdm.io.common.ImportConfiguratorBase;
30
import eu.etaxonomy.cdm.io.common.mapping.IInputTransformer;
31
import eu.etaxonomy.cdm.model.reference.Reference;
32
import eu.etaxonomy.cdm.model.reference.ReferenceFactory;
33

    
34
@Component
35
public class BfnXmlImportConfigurator extends ImportConfiguratorBase<BfnXmlImportState, URI>  {
36
	private static final Logger logger = Logger.getLogger(BfnXmlImportConfigurator.class);
37

    
38
	//TODO
39
	private static IInputTransformer defaultTransformer = null;
40

    
41

    
42
	private boolean doMetaData = true;
43
	private boolean doTaxonNames = true;
44
    private boolean doFeature = true;
45
    private boolean doAdditionalTerms = true;
46

    
47
    private boolean doInformationImport = true;
48
    private boolean fillSecondList = false;
49
    private boolean hasSecondList = false;
50

    
51

    
52

    
53
    public boolean isFillSecondList() {
54
		return fillSecondList;
55
	}
56

    
57
	public void setFillSecondList(boolean fillSecondList) {
58
		this.fillSecondList = fillSecondList;
59
	}
60

    
61

    
62
	//	rdfNamespace
63
	Namespace bfnXmlNamespace;
64

    
65
	private String nomenclaturalCode = null;
66

    
67
	@SuppressWarnings("unchecked")
68
	@Override
69
	protected void makeIoClassList(){
70
		ioClassList = new Class[]{
71
				BfnXmlImportAddtionalTerms.class,
72
				BfnXmlImportMetaData.class,
73
				BfnXmlImportFeature.class,
74
				BfnXmlImportTaxonName.class
75
		};
76
	};
77

    
78
	public static BfnXmlImportConfigurator NewInstance(URI uri,
79
			ICdmDataSource destination){
80
		return new BfnXmlImportConfigurator(uri, destination);
81
	}
82

    
83
	/**
84
	 * @param berlinModelSource
85
	 * @param sourceReference
86
	 * @param destination
87
	 */
88
	private BfnXmlImportConfigurator() {
89
		super(defaultTransformer);
90
	}
91

    
92
	/**
93
	 * @param berlinModelSource
94
	 * @param sourceReference
95
	 * @param destination
96
	 */
97
	private BfnXmlImportConfigurator(URI uri, ICdmDataSource destination) {
98
		super(defaultTransformer);
99
		setSource(uri);
100
		setDestination(destination);
101
	}
102

    
103

    
104
	@Override
105
	public BfnXmlImportState getNewState() {
106
		return new BfnXmlImportState(this);
107
	}
108

    
109
	/**
110
	 * @return
111
	 */
112
	public Element getSourceRoot(){
113
		URI source = getSource();
114
		try {
115
			URL url;
116
			url = source.toURL();
117
			Object o = url.getContent();
118
			InputStream is = (InputStream)o;
119
			Element root = XmlHelp.getRoot(is);
120
			makeNamespaces(root);
121
			return root;
122
		} catch (MalformedURLException e) {
123
			e.printStackTrace();
124
		}catch (Exception e) {
125
			// TODO Auto-generated catch block
126
			e.printStackTrace();
127
		}
128
		return null;
129
	}
130

    
131
	private boolean makeNamespaces(Element root){
132
		bfnXmlNamespace = root.getNamespace();
133
		if (bfnXmlNamespace == null
134
				/**|| tcNamespace == null
135
				 * || tnNamespace == null
136
				 * || commonNamespace == null
137
				 * ||	geoNamespace == null
138
				 * || publicationNamespace == null*/){
139
			logger.warn("At least one Namespace is NULL");
140
		}
141
		return true;
142
	}
143

    
144
	@Override
145
	public Reference getSourceReference() {
146
		//TODO
147
		if (this.sourceReference == null){
148
			logger.warn("getSource Reference not yet fully implemented");
149
			sourceReference = ReferenceFactory.newDatabase();
150
			sourceReference.setTitleCache("", true);
151
		}
152
		return sourceReference;
153
	}
154

    
155
	@Override
156
    public String getSourceNameString() {
157
		if (this.getSource() == null){
158
			return null;
159
		}else{
160
			return this.getSource().toString();
161
		}
162
	}
163

    
164
	public Namespace getBfnXmlNamespace() {
165
		return bfnXmlNamespace;
166
	}
167

    
168
	public void setBfnXmlNamespace(Namespace bfnXmlNamespace) {
169
		this.bfnXmlNamespace = bfnXmlNamespace;
170
	}
171

    
172
	public boolean isDoTaxonNames() {
173
		return doTaxonNames;
174
	}
175
	public void setDoTaxonNames(boolean doTaxonNames) {
176
		this.doTaxonNames = doTaxonNames;
177
	}
178

    
179
	/**
180
	 * @return the doMetaData
181
	 */
182
	public boolean isDoMetaData() {
183
		return doMetaData;
184
	}
185

    
186
	/**
187
	 * @param doMetaData the doMetaData to set
188
	 */
189
	public void setDoMetaData(boolean doMetaData) {
190
		this.doMetaData = doMetaData;
191
	}
192

    
193

    
194
	public boolean isDoInformationImport() {
195
		return doInformationImport;
196
	}
197

    
198
	public void setDoInformationImport(boolean doInformationImport) {
199
		this.doInformationImport = doInformationImport;
200
	}
201

    
202
	public boolean isHasSecondList() {
203
		return hasSecondList;
204
	}
205

    
206
	public void setHasSecondList(boolean hasSecondList) {
207
		this.hasSecondList = hasSecondList;
208
	}
209

    
210
	public void setNomenclaturalSig(String nomenclaturalCode) {
211
		this.nomenclaturalCode = nomenclaturalCode;
212
	}
213

    
214
	public String getNomenclaturalSig(){
215
		return nomenclaturalCode;
216
	}
217

    
218
    /**
219
     * @return the doFeature
220
     */
221
    public boolean isDoFeature() {
222
        return doFeature;
223
    }
224

    
225

    
226
    /**
227
     * @param doFeature the doFeature to set
228
     */
229
    public void setDoFeature(boolean doFeature) {
230
        this.doFeature = doFeature;
231
    }
232

    
233
    /**
234
     * @return the doAdditionalTerms
235
     */
236
    public boolean isDoAdditionalTerms() {
237
        return doAdditionalTerms;
238
    }
239

    
240
    /**
241
     * @param doAdditionalTerms the doAdditionalTerms to set
242
     */
243
    public void setDoAdditionalTerms(boolean doAdditionalTerms) {
244
        this.doAdditionalTerms = doAdditionalTerms;
245
    }
246
}
(3-3/8)