Project

General

Profile

Download (10.7 KB) Statistics
| Branch: | Tag: | Revision:
1
// $Id$
2
/**
3
* Copyright (C) 2007 EDIT
4
* European Distributed Institute of Taxonomy 
5
* http://www.e-taxonomy.eu
6
* 
7
* The contents of this file are subject to the Mozilla Public License Version 1.1
8
* See LICENSE.TXT at the top of this package for the full license terms.
9
*/
10

    
11
package eu.etaxonomy.cdm.io.markup;
12

    
13
import java.util.ArrayList;
14
import java.util.HashMap;
15
import java.util.HashSet;
16
import java.util.List;
17
import java.util.Map;
18
import java.util.Set;
19
import java.util.UUID;
20

    
21
import org.apache.log4j.Logger;
22

    
23
import eu.etaxonomy.cdm.io.common.XmlImportState;
24
import eu.etaxonomy.cdm.io.common.mapping.IInputTransformer;
25
import eu.etaxonomy.cdm.model.agent.TeamOrPersonBase;
26
import eu.etaxonomy.cdm.model.common.AnnotatableEntity;
27
import eu.etaxonomy.cdm.model.common.Language;
28
import eu.etaxonomy.cdm.model.description.Feature;
29
import eu.etaxonomy.cdm.model.description.FeatureNode;
30
import eu.etaxonomy.cdm.model.description.PolytomousKey;
31
import eu.etaxonomy.cdm.model.description.PolytomousKeyNode;
32
import eu.etaxonomy.cdm.model.location.NamedArea;
33
import eu.etaxonomy.cdm.model.media.Media;
34
import eu.etaxonomy.cdm.model.taxon.Taxon;
35

    
36
/**
37
 * @author a.mueller
38
 * @created 11.05.2009
39
 * @version 1.0
40
 */
41
public class MarkupImportState extends XmlImportState<MarkupImportConfigurator, MarkupDocumentImport>{
42
	@SuppressWarnings("unused")
43
	private static final Logger logger = Logger.getLogger(MarkupImportState.class);
44
	
45

    
46
	private UnmatchedLeads unmatchedLeads;
47
	private boolean onlyNumberedTaxaExist; //attribute in <key>
48

    
49
	private Set<FeatureNode> featureNodesToSave = new HashSet<FeatureNode>();
50
	
51
	private Set<PolytomousKeyNode> polytomousKeyNodesToSave = new HashSet<PolytomousKeyNode>();
52
	
53
	private PolytomousKey currentKey;
54
	
55
	private TeamOrPersonBase<?> currentCollector;
56
	
57
	private Set<NamedArea> currentAreas = new HashSet<NamedArea>();
58
	
59
	private Language defaultLanguage;
60
	
61
	private Taxon currentTaxon;
62
	private String currentTaxonNum;
63
	
64
	private boolean taxonInClassification = true;
65
	
66
	private String latestGenusEpithet = null;
67
	
68
	private boolean isCitation = false;
69
	private boolean isNameType = false;
70
	private boolean isProParte = false;
71
	
72
	private String baseMediaUrl = null;
73
	
74
	private Map<String, FootnoteDataHolder> footnoteRegister = new HashMap<String, FootnoteDataHolder>();
75
	
76
	private Map<String, Media> figureRegister = new HashMap<String, Media>();
77
	
78
	private Map<String, Set<AnnotatableEntity>> footnoteRefRegister = new HashMap<String, Set<AnnotatableEntity>>();
79
	private Map<String, Set<AnnotatableEntity>> figureRefRegister = new HashMap<String, Set<AnnotatableEntity>>();
80
	
81
	private Map<String, UUID> areaMap = new HashMap<String, UUID>();
82
	
83
	private Map<String,UUID> unknownFeaturesUuids = new HashMap<String, UUID>();
84
	
85
	private List<FeatureSorterInfo> currentGeneralFeatureSorterList;  //keep in multiple imports
86
	private List<FeatureSorterInfo> currentCharFeatureSorterList; //keep in multiple imports
87
	private Map<String,List<FeatureSorterInfo>> generalFeatureSorterListMap = new HashMap<String, List<FeatureSorterInfo>>();  //keep in multiple imports
88
	private Map<String,List<FeatureSorterInfo>> charFeatureSorterListMap = new HashMap<String, List<FeatureSorterInfo>>(); //keep in multiple imports
89
	
90
	
91
	/**
92
	 * This method resets all those variables that should not be reused from one import to another.
93
	 * @see MarkupImportConfigurator#isReuseExistingState()
94
	 * @see MarkupImportConfigurator#getNewState()
95
	 */
96
	protected void reset(){
97
		featureNodesToSave = new HashSet<FeatureNode>();
98
		polytomousKeyNodesToSave = new HashSet<PolytomousKeyNode>();
99
		currentKey = null;
100
		defaultLanguage = null;
101
		currentTaxon = null;
102
		currentCollector = null;
103
		footnoteRegister = new HashMap<String, FootnoteDataHolder>();
104
		figureRegister = new HashMap<String, Media>();
105
		footnoteRefRegister = new HashMap<String, Set<AnnotatableEntity>>();
106
		figureRefRegister = new HashMap<String, Set<AnnotatableEntity>>();
107
		currentAreas = new HashSet<NamedArea>();
108
	}
109
	
110
		
111
//**************************** CONSTRUCTOR ******************************************/
112
	
113
	public MarkupImportState(MarkupImportConfigurator config) {
114
		super(config);
115
		if (getTransformer() == null){
116
			IInputTransformer newTransformer = config.getTransformer();
117
			if (newTransformer == null){
118
				newTransformer = new MarkupTransformer();
119
			}
120
			setTransformer(newTransformer);
121
		}
122
	}
123

    
124
// ********************************** GETTER / SETTER *************************************/	
125
	
126
	public UnmatchedLeads getUnmatchedLeads() {
127
		return unmatchedLeads;
128
	}
129

    
130
	public void setUnmatchedLeads(UnmatchedLeads unmatchedKeys) {
131
		this.unmatchedLeads = unmatchedKeys;
132
	}
133

    
134
	public void setFeatureNodesToSave(Set<FeatureNode> featureNodesToSave) {
135
		this.featureNodesToSave = featureNodesToSave;
136
	}
137

    
138
	public Set<FeatureNode> getFeatureNodesToSave() {
139
		return featureNodesToSave;
140
	}
141

    
142
	public Set<PolytomousKeyNode> getPolytomousKeyNodesToSave() {
143
		return polytomousKeyNodesToSave;
144
	}
145
	
146
	public void setPolytomousKeyNodesToSave(Set<PolytomousKeyNode> polytomousKeyNodesToSave) {
147
		this.polytomousKeyNodesToSave = polytomousKeyNodesToSave;
148
	}
149
	
150
	public Language getDefaultLanguage() {
151
		return this.defaultLanguage;
152
	}
153

    
154
	public void setDefaultLanguage(Language defaultLanguage){
155
		this.defaultLanguage = defaultLanguage;
156
	}
157

    
158
	
159
	public void setCurrentTaxon(Taxon currentTaxon) {
160
		this.currentTaxon = currentTaxon;
161
	}
162

    
163
	public Taxon getCurrentTaxon() {
164
		return currentTaxon;
165
	}
166
	
167
	public void setCurrentTaxonNum(String currentTaxonNum) {
168
		this.currentTaxonNum = currentTaxonNum;
169
	}
170

    
171
	public String getCurrentTaxonNum() {
172
		return currentTaxonNum;
173
	}
174

    
175

    
176

    
177
	/**
178
	 * Is the import currently handling a citation?
179
	 * @return
180
	 */
181
	public boolean isCitation() {
182
		return isCitation;
183
	}
184
	
185
	public void setCitation(boolean isCitation) {
186
		this.isCitation = isCitation;
187
	}
188

    
189

    
190
	public boolean isNameType() {
191
		return isNameType;
192
	}
193
	
194
	public void setNameType(boolean isNameType) {
195
		this.isNameType = isNameType;
196
	}
197

    
198
	public void setProParte(boolean isProParte) {
199
		this.isProParte = isProParte;
200
	}
201

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

    
206
	public void setBaseMediaUrl(String baseMediaUrl) {
207
		this.baseMediaUrl = baseMediaUrl;
208
	}
209

    
210
	public String getBaseMediaUrl() {
211
		return baseMediaUrl;
212
	}
213

    
214
	
215
	
216
	public void registerFootnote(FootnoteDataHolder footnote) {
217
		footnoteRegister.put(footnote.id, footnote);
218
	}
219

    
220
	public FootnoteDataHolder getFootnote(String key) {
221
		return footnoteRegister.get(key);
222
	}
223
	
224
	
225
	public void registerFigure(String key, Media figure) {
226
		figureRegister.put(key, figure);
227
	}
228

    
229
	public Media getFigure(String key) {
230
		return figureRegister.get(key);
231
	}
232

    
233
	public Set<AnnotatableEntity> getFootnoteDemands(String footnoteId){
234
		return footnoteRefRegister.get(footnoteId);
235
	}
236
	
237
	public void putFootnoteDemands(String footnoteId, Set<AnnotatableEntity> demands){
238
		footnoteRefRegister.put(footnoteId, demands);
239
	}
240
	
241

    
242
	public Set<AnnotatableEntity> getFigureDemands(String figureId){
243
		return figureRefRegister.get(figureId);
244
	}
245
	
246
	public void putFigureDemands(String figureId, Set<AnnotatableEntity> demands){
247
		figureRefRegister.put(figureId, demands);
248
	}
249

    
250
	/**
251
	 * @param key
252
	 */
253
	public void setCurrentKey(PolytomousKey key) {
254
		this.currentKey = key;
255
	}
256
	
257
	/**
258
	 * @return the currentKey
259
	 */
260
	public PolytomousKey getCurrentKey() {
261
		return currentKey;
262
	}
263

    
264
	/**
265
	 * @param key
266
	 * @return
267
	 * @see java.util.Map#get(java.lang.Object)
268
	 */
269
	public UUID getAreaUuid(Object key) {
270
		return areaMap.get(key);
271
	}
272

    
273
	/**
274
	 * @param key
275
	 * @param value
276
	 * @return
277
	 * @see java.util.Map#put(java.lang.Object, java.lang.Object)
278
	 */
279
	public UUID putAreaUuid(String key, UUID value) {
280
		return areaMap.put(key, value);
281
	}
282

    
283
	public void putUnknownFeatureUuid(String featureLabel, UUID featureUuid) {
284
		this.unknownFeaturesUuids.put(featureLabel, featureUuid);
285
	}
286

    
287
	public boolean isOnlyNumberedTaxaExist() {
288
		return onlyNumberedTaxaExist;
289
	}
290

    
291
	public void setOnlyNumberedTaxaExist(boolean onlyNumberedTaxaExist) {
292
		this.onlyNumberedTaxaExist = onlyNumberedTaxaExist;
293
	}
294

    
295
	public Map<String,List<FeatureSorterInfo>> getGeneralFeatureSorterListMap() {
296
		return generalFeatureSorterListMap;
297
	}
298
	public Map<String,List<FeatureSorterInfo>> getCharFeatureSorterListMap() {
299
		return charFeatureSorterListMap;
300
	}
301
	
302
	public UUID getUnknownFeatureUuid(String featureLabel){
303
		return this.unknownFeaturesUuids.get(featureLabel);
304
	}
305
	
306

    
307
	/**
308
	 * Adds new lists to the feature sorter list maps using the given key.
309
	 * If at least 1 list already existed for the given key, true is returned. False
310
	 * @param key Key that identifies the feature sorter list.
311
	 * @return <code>true</code> if at least 1 list already exited for the given key. <code>false</code> otherwise.
312
	 */
313
	public boolean addNewFeatureSorterLists(String key) {
314
		//general feature sorter list
315
		List<FeatureSorterInfo> generalList = new ArrayList<FeatureSorterInfo>();
316
		List<FeatureSorterInfo> previous1 = this.generalFeatureSorterListMap.put(key, generalList);
317
		currentGeneralFeatureSorterList = generalList;
318
		
319
		//character feature sorter list
320
		List<FeatureSorterInfo> charList = new ArrayList<FeatureSorterInfo>();
321
		List<FeatureSorterInfo> previous2 = this.charFeatureSorterListMap.put(key, charList);
322
		currentCharFeatureSorterList = charList;
323
		
324
		return (previous1 != null || previous2 != null);
325
	}
326

    
327
	/**
328
	 * 
329
	 * @param feature
330
	 */
331
	public void putFeatureToCharSorterList(Feature feature) {
332
		currentCharFeatureSorterList.add(new FeatureSorterInfo(feature)); 
333
		
334
	}
335

    
336
	/**
337
	 * 
338
	 * @param feature
339
	 */
340
	public void putFeatureToGeneralSorterList(Feature feature) {
341
		currentGeneralFeatureSorterList.add(new FeatureSorterInfo(feature)); 
342
		
343
	}
344

    
345
	public String getLatestGenusEpithet() {
346
		return latestGenusEpithet;
347
	}
348

    
349
	public void setLatestGenusEpithet(String latestGenusEpithet) {
350
		this.latestGenusEpithet = latestGenusEpithet;
351
	}
352

    
353

    
354
	public boolean isTaxonInClassification() {
355
		return taxonInClassification;
356
	}
357

    
358

    
359
	public void setTaxonInClassification(boolean taxonInClassification) {
360
		this.taxonInClassification = taxonInClassification;
361
	}
362

    
363

    
364
	public TeamOrPersonBase<?> getCurrentCollector() {
365
		return currentCollector;
366
	}
367

    
368

    
369
	public void setCurrentCollector(TeamOrPersonBase<?> currentCollector) {
370
		this.currentCollector = currentCollector;
371
	}
372

    
373

    
374
	public void addCurrentArea(NamedArea area) {
375
		currentAreas.add(area);	
376
	}
377

    
378

    
379
	public Set<NamedArea> getCurrentAreas() {
380
		return currentAreas;
381
	}
382
	
383
	public void removeCurrentAreas(){
384
		currentAreas.clear();
385
	}
386

    
387

    
388
}
(10-10/17)