Project

General

Profile

Download (5.5 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.in;
11

    
12
/**
13
 * @author a.oppermann
14
 * @since 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.name.NomenclaturalCode;
32
import eu.etaxonomy.cdm.model.reference.Reference;
33
import eu.etaxonomy.cdm.model.reference.ReferenceFactory;
34

    
35
@Component
36
public class BfnXmlImportConfigurator extends ImportConfiguratorBase<BfnXmlImportState, URI>  {
37
    private static final long serialVersionUID = -1647291548711127385L;
38

    
39
    private static final Logger logger = Logger.getLogger(BfnXmlImportConfigurator.class);
40

    
41
	//TODO
42
	private static IInputTransformer defaultTransformer = null;
43

    
44

    
45
	private boolean doMetaData = true;
46
	private boolean doTaxonNames = true;
47
    private boolean doFeature = true;
48
    private boolean doAdditionalTerms = true;
49

    
50
    private boolean doInformationImport = true;
51
    private boolean hasSecondList = false;
52

    
53

    
54
	//	rdfNamespace
55
	Namespace bfnXmlNamespace;
56

    
57
	private NomenclaturalCode nomenclaturalCode = null;
58

    
59
	@SuppressWarnings("unchecked")
60
	@Override
61
	protected void makeIoClassList(){
62
		ioClassList = new Class[]{
63
		        BfnXmlImportReferences.class,
64
				BfnXmlImportAddtionalTerms.class,
65
				BfnXmlImportMetaData.class,
66
				BfnXmlImportFeature.class,
67
				BfnXmlImportTaxonName.class
68
		};
69
	}
70

    
71
	public static BfnXmlImportConfigurator NewInstance(URI uri,
72
			ICdmDataSource destination){
73
		return new BfnXmlImportConfigurator(uri, destination);
74
	}
75

    
76
	/**
77
	 * @param berlinModelSource
78
	 * @param sourceReference
79
	 * @param destination
80
	 */
81
	private BfnXmlImportConfigurator() {
82
		super(defaultTransformer);
83
	}
84

    
85
	/**
86
	 * @param berlinModelSource
87
	 * @param sourceReference
88
	 * @param destination
89
	 */
90
	private BfnXmlImportConfigurator(URI uri, ICdmDataSource destination) {
91
		super(defaultTransformer);
92
		setSource(uri);
93
		setDestination(destination);
94
	}
95

    
96

    
97
	@Override
98
	public BfnXmlImportState getNewState() {
99
		return new BfnXmlImportState(this);
100
	}
101

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

    
124
	private boolean makeNamespaces(Element root){
125
		bfnXmlNamespace = root.getNamespace();
126
		if (bfnXmlNamespace == null
127
				/**|| tcNamespace == null
128
				 * || tnNamespace == null
129
				 * || commonNamespace == null
130
				 * ||	geoNamespace == null
131
				 * || publicationNamespace == null*/){
132
			logger.warn("At least one Namespace is NULL");
133
		}
134
		return true;
135
	}
136

    
137
	@Override
138
	public Reference getSourceReference() {
139
		//TODO
140
		if (this.sourceReference == null){
141
			logger.warn("getSource Reference not yet fully implemented");
142
			sourceReference = ReferenceFactory.newDatabase();
143
			sourceReference.setTitleCache("", true);
144
		}
145
		return sourceReference;
146
	}
147

    
148
	@Override
149
    public String getSourceNameString() {
150
		if (this.getSource() == null){
151
			return null;
152
		}else{
153
			return this.getSource().toString();
154
		}
155
	}
156

    
157
	public Namespace getBfnXmlNamespace() {
158
		return bfnXmlNamespace;
159
	}
160
	public void setBfnXmlNamespace(Namespace bfnXmlNamespace) {
161
		this.bfnXmlNamespace = bfnXmlNamespace;
162
	}
163

    
164
	public boolean isDoTaxonNames() {
165
		return doTaxonNames;
166
	}
167
	public void setDoTaxonNames(boolean doTaxonNames) {
168
		this.doTaxonNames = doTaxonNames;
169
	}
170

    
171
	/**
172
	 * @return the doMetaData
173
	 */
174
	public boolean isDoMetaData() {
175
		return doMetaData;
176
	}
177
	/**
178
	 * @param doMetaData the doMetaData to set
179
	 */
180
	public void setDoMetaData(boolean doMetaData) {
181
		this.doMetaData = doMetaData;
182
	}
183

    
184

    
185
	public boolean isDoInformationImport() {
186
		return doInformationImport;
187
	}
188
	public void setDoInformationImport(boolean doInformationImport) {
189
		this.doInformationImport = doInformationImport;
190
	}
191

    
192
	public boolean isHasSecondList() {
193
		return hasSecondList;
194
	}
195
	public void setHasSecondList(boolean hasSecondList) {
196
		this.hasSecondList = hasSecondList;
197
	}
198

    
199
	@Override
200
    public void setNomenclaturalCode(NomenclaturalCode nomenclaturalCode) {
201
		this.nomenclaturalCode = nomenclaturalCode;
202
	}
203
	@Override
204
    public NomenclaturalCode getNomenclaturalCode(){
205
		return nomenclaturalCode;
206
	}
207

    
208
    /**
209
     * @return the doFeature
210
     */
211
    public boolean isDoFeature() {
212
        return doFeature;
213
    }
214
    /**
215
     * @param doFeature the doFeature to set
216
     */
217
    public void setDoFeature(boolean doFeature) {
218
        this.doFeature = doFeature;
219
    }
220

    
221
    /**
222
     * @return the doAdditionalTerms
223
     */
224
    public boolean isDoAdditionalTerms() {
225
        return doAdditionalTerms;
226
    }
227
    /**
228
     * @param doAdditionalTerms the doAdditionalTerms to set
229
     */
230
    public void setDoAdditionalTerms(boolean doAdditionalTerms) {
231
        this.doAdditionalTerms = doAdditionalTerms;
232
    }
233
}
(3-3/9)