Revision 006a8952
Added by Andreas Müller almost 9 years ago
app-import/src/main/java/eu/etaxonomy/cdm/io/redlist/bfnXml/BfnXmlImportConfigurator.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.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 |
} |
|
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.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 Logger logger = Logger.getLogger(BfnXmlImportConfigurator.class); |
|
38 |
|
|
39 |
//TODO |
|
40 |
private static IInputTransformer defaultTransformer = null; |
|
41 |
|
|
42 |
|
|
43 |
private boolean doMetaData = true; |
|
44 |
private boolean doTaxonNames = true; |
|
45 |
private boolean doFeature = true; |
|
46 |
private boolean doAdditionalTerms = true; |
|
47 |
|
|
48 |
private boolean doInformationImport = true; |
|
49 |
private boolean fillSecondList = false; |
|
50 |
private boolean hasSecondList = false; |
|
51 |
|
|
52 |
|
|
53 |
|
|
54 |
public boolean isFillSecondList() { |
|
55 |
return fillSecondList; |
|
56 |
} |
|
57 |
|
|
58 |
public void setFillSecondList(boolean fillSecondList) { |
|
59 |
this.fillSecondList = fillSecondList; |
|
60 |
} |
|
61 |
|
|
62 |
|
|
63 |
// rdfNamespace |
|
64 |
Namespace bfnXmlNamespace; |
|
65 |
|
|
66 |
private NomenclaturalCode nomenclaturalCode = null; |
|
67 |
|
|
68 |
@SuppressWarnings("unchecked") |
|
69 |
@Override |
|
70 |
protected void makeIoClassList(){ |
|
71 |
ioClassList = new Class[]{ |
|
72 |
BfnXmlImportAddtionalTerms.class, |
|
73 |
BfnXmlImportMetaData.class, |
|
74 |
BfnXmlImportFeature.class, |
|
75 |
BfnXmlImportTaxonName.class |
|
76 |
}; |
|
77 |
}; |
|
78 |
|
|
79 |
public static BfnXmlImportConfigurator NewInstance(URI uri, |
|
80 |
ICdmDataSource destination){ |
|
81 |
return new BfnXmlImportConfigurator(uri, destination); |
|
82 |
} |
|
83 |
|
|
84 |
/** |
|
85 |
* @param berlinModelSource |
|
86 |
* @param sourceReference |
|
87 |
* @param destination |
|
88 |
*/ |
|
89 |
private BfnXmlImportConfigurator() { |
|
90 |
super(defaultTransformer); |
|
91 |
} |
|
92 |
|
|
93 |
/** |
|
94 |
* @param berlinModelSource |
|
95 |
* @param sourceReference |
|
96 |
* @param destination |
|
97 |
*/ |
|
98 |
private BfnXmlImportConfigurator(URI uri, ICdmDataSource destination) { |
|
99 |
super(defaultTransformer); |
|
100 |
setSource(uri); |
|
101 |
setDestination(destination); |
|
102 |
} |
|
103 |
|
|
104 |
|
|
105 |
@Override |
|
106 |
public BfnXmlImportState getNewState() { |
|
107 |
return new BfnXmlImportState(this); |
|
108 |
} |
|
109 |
|
|
110 |
/** |
|
111 |
* @return |
|
112 |
*/ |
|
113 |
public Element getSourceRoot(){ |
|
114 |
URI source = getSource(); |
|
115 |
try { |
|
116 |
URL url; |
|
117 |
url = source.toURL(); |
|
118 |
Object o = url.getContent(); |
|
119 |
InputStream is = (InputStream)o; |
|
120 |
Element root = XmlHelp.getRoot(is); |
|
121 |
makeNamespaces(root); |
|
122 |
return root; |
|
123 |
} catch (MalformedURLException e) { |
|
124 |
e.printStackTrace(); |
|
125 |
}catch (Exception e) { |
|
126 |
// TODO Auto-generated catch block |
|
127 |
e.printStackTrace(); |
|
128 |
} |
|
129 |
return null; |
|
130 |
} |
|
131 |
|
|
132 |
private boolean makeNamespaces(Element root){ |
|
133 |
bfnXmlNamespace = root.getNamespace(); |
|
134 |
if (bfnXmlNamespace == null |
|
135 |
/**|| tcNamespace == null |
|
136 |
* || tnNamespace == null |
|
137 |
* || commonNamespace == null |
|
138 |
* || geoNamespace == null |
|
139 |
* || publicationNamespace == null*/){ |
|
140 |
logger.warn("At least one Namespace is NULL"); |
|
141 |
} |
|
142 |
return true; |
|
143 |
} |
|
144 |
|
|
145 |
@Override |
|
146 |
public Reference getSourceReference() { |
|
147 |
//TODO |
|
148 |
if (this.sourceReference == null){ |
|
149 |
logger.warn("getSource Reference not yet fully implemented"); |
|
150 |
sourceReference = ReferenceFactory.newDatabase(); |
|
151 |
sourceReference.setTitleCache("", true); |
|
152 |
} |
|
153 |
return sourceReference; |
|
154 |
} |
|
155 |
|
|
156 |
@Override |
|
157 |
public String getSourceNameString() { |
|
158 |
if (this.getSource() == null){ |
|
159 |
return null; |
|
160 |
}else{ |
|
161 |
return this.getSource().toString(); |
|
162 |
} |
|
163 |
} |
|
164 |
|
|
165 |
public Namespace getBfnXmlNamespace() { |
|
166 |
return bfnXmlNamespace; |
|
167 |
} |
|
168 |
|
|
169 |
public void setBfnXmlNamespace(Namespace bfnXmlNamespace) { |
|
170 |
this.bfnXmlNamespace = bfnXmlNamespace; |
|
171 |
} |
|
172 |
|
|
173 |
public boolean isDoTaxonNames() { |
|
174 |
return doTaxonNames; |
|
175 |
} |
|
176 |
public void setDoTaxonNames(boolean doTaxonNames) { |
|
177 |
this.doTaxonNames = doTaxonNames; |
|
178 |
} |
|
179 |
|
|
180 |
/** |
|
181 |
* @return the doMetaData |
|
182 |
*/ |
|
183 |
public boolean isDoMetaData() { |
|
184 |
return doMetaData; |
|
185 |
} |
|
186 |
|
|
187 |
/** |
|
188 |
* @param doMetaData the doMetaData to set |
|
189 |
*/ |
|
190 |
public void setDoMetaData(boolean doMetaData) { |
|
191 |
this.doMetaData = doMetaData; |
|
192 |
} |
|
193 |
|
|
194 |
|
|
195 |
public boolean isDoInformationImport() { |
|
196 |
return doInformationImport; |
|
197 |
} |
|
198 |
|
|
199 |
public void setDoInformationImport(boolean doInformationImport) { |
|
200 |
this.doInformationImport = doInformationImport; |
|
201 |
} |
|
202 |
|
|
203 |
public boolean isHasSecondList() { |
|
204 |
return hasSecondList; |
|
205 |
} |
|
206 |
|
|
207 |
public void setHasSecondList(boolean hasSecondList) { |
|
208 |
this.hasSecondList = hasSecondList; |
|
209 |
} |
|
210 |
|
|
211 |
public void setNomenclaturalCode(NomenclaturalCode nomenclaturalCode) { |
|
212 |
this.nomenclaturalCode = nomenclaturalCode; |
|
213 |
} |
|
214 |
|
|
215 |
@Override |
|
216 |
public NomenclaturalCode getNomenclaturalCode(){ |
|
217 |
return nomenclaturalCode; |
|
218 |
} |
|
219 |
|
|
220 |
/** |
|
221 |
* @return the doFeature |
|
222 |
*/ |
|
223 |
public boolean isDoFeature() { |
|
224 |
return doFeature; |
|
225 |
} |
|
226 |
|
|
227 |
|
|
228 |
/** |
|
229 |
* @param doFeature the doFeature to set |
|
230 |
*/ |
|
231 |
public void setDoFeature(boolean doFeature) { |
|
232 |
this.doFeature = doFeature; |
|
233 |
} |
|
234 |
|
|
235 |
/** |
|
236 |
* @return the doAdditionalTerms |
|
237 |
*/ |
|
238 |
public boolean isDoAdditionalTerms() { |
|
239 |
return doAdditionalTerms; |
|
240 |
} |
|
241 |
|
|
242 |
/** |
|
243 |
* @param doAdditionalTerms the doAdditionalTerms to set |
|
244 |
*/ |
|
245 |
public void setDoAdditionalTerms(boolean doAdditionalTerms) { |
|
246 |
this.doAdditionalTerms = doAdditionalTerms; |
|
247 |
} |
|
248 |
} |
Also available in: Unified diff
latest changes to BfN Import