Project

General

Profile

Download (11.6 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.reference.Reference;
35
import eu.etaxonomy.cdm.model.taxon.Taxon;
36

    
37
/**
38
 * @author a.mueller
39
 * @created 11.05.2009
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 TeamOrPersonBase<?> latestAuthorInHomotype = null;
69
	private Reference<?> latestReferenceInHomotype = null;
70
	
71
	private boolean isCitation = false;
72
	private boolean isNameType = false;
73
	private boolean isProParte = false;
74
	
75
	private String baseMediaUrl = null;
76
	
77
	private Map<String, FootnoteDataHolder> footnoteRegister = new HashMap<String, FootnoteDataHolder>();
78
	
79
	private Map<String, Media> figureRegister = new HashMap<String, Media>();
80
	
81
	private Map<String, Set<AnnotatableEntity>> footnoteRefRegister = new HashMap<String, Set<AnnotatableEntity>>();
82
	private Map<String, Set<AnnotatableEntity>> figureRefRegister = new HashMap<String, Set<AnnotatableEntity>>();
83
	
84
	private Map<String, UUID> areaMap = new HashMap<String, UUID>();
85
	
86
	private Map<String,UUID> unknownFeaturesUuids = new HashMap<String, UUID>();
87
	
88
	private List<FeatureSorterInfo> currentGeneralFeatureSorterList;  //keep in multiple imports
89
	private List<FeatureSorterInfo> currentCharFeatureSorterList; //keep in multiple imports
90
	private Map<String,List<FeatureSorterInfo>> generalFeatureSorterListMap = new HashMap<String, List<FeatureSorterInfo>>();  //keep in multiple imports
91
	private Map<String,List<FeatureSorterInfo>> charFeatureSorterListMap = new HashMap<String, List<FeatureSorterInfo>>(); //keep in multiple imports
92
	
93
	
94
	/**
95
	 * This method resets all those variables that should not be reused from one import to another.
96
	 * @see MarkupImportConfigurator#isReuseExistingState()
97
	 * @see MarkupImportConfigurator#getNewState()
98
	 */
99
	protected void reset(){
100
		featureNodesToSave = new HashSet<FeatureNode>();
101
		polytomousKeyNodesToSave = new HashSet<PolytomousKeyNode>();
102
		currentKey = null;
103
		defaultLanguage = null;
104
		currentTaxon = null;
105
		currentCollector = null;
106
		footnoteRegister = new HashMap<String, FootnoteDataHolder>();
107
		figureRegister = new HashMap<String, Media>();
108
		footnoteRefRegister = new HashMap<String, Set<AnnotatableEntity>>();
109
		figureRefRegister = new HashMap<String, Set<AnnotatableEntity>>();
110
		currentAreas = new HashSet<NamedArea>();
111
		
112
		this.resetUuidTermMaps();
113
	}
114
	
115
		
116
//**************************** CONSTRUCTOR ******************************************/
117
	
118
	public MarkupImportState(MarkupImportConfigurator config) {
119
		super(config);
120
		if (getTransformer() == null){
121
			IInputTransformer newTransformer = config.getTransformer();
122
			if (newTransformer == null){
123
				newTransformer = new MarkupTransformer();
124
			}
125
			setTransformer(newTransformer);
126
		}
127
	}
128

    
129
// ********************************** GETTER / SETTER *************************************/	
130
	
131
	public UnmatchedLeads getUnmatchedLeads() {
132
		return unmatchedLeads;
133
	}
134

    
135
	public void setUnmatchedLeads(UnmatchedLeads unmatchedKeys) {
136
		this.unmatchedLeads = unmatchedKeys;
137
	}
138

    
139
	public void setFeatureNodesToSave(Set<FeatureNode> featureNodesToSave) {
140
		this.featureNodesToSave = featureNodesToSave;
141
	}
142

    
143
	public Set<FeatureNode> getFeatureNodesToSave() {
144
		return featureNodesToSave;
145
	}
146

    
147
	public Set<PolytomousKeyNode> getPolytomousKeyNodesToSave() {
148
		return polytomousKeyNodesToSave;
149
	}
150
	
151
	public void setPolytomousKeyNodesToSave(Set<PolytomousKeyNode> polytomousKeyNodesToSave) {
152
		this.polytomousKeyNodesToSave = polytomousKeyNodesToSave;
153
	}
154
	
155
	public Language getDefaultLanguage() {
156
		return this.defaultLanguage;
157
	}
158

    
159
	public void setDefaultLanguage(Language defaultLanguage){
160
		this.defaultLanguage = defaultLanguage;
161
	}
162

    
163
	
164
	public void setCurrentTaxon(Taxon currentTaxon) {
165
		this.currentTaxon = currentTaxon;
166
	}
167

    
168
	public Taxon getCurrentTaxon() {
169
		return currentTaxon;
170
	}
171
	
172
	public void setCurrentTaxonNum(String currentTaxonNum) {
173
		this.currentTaxonNum = currentTaxonNum;
174
	}
175

    
176
	public String getCurrentTaxonNum() {
177
		return currentTaxonNum;
178
	}
179

    
180

    
181

    
182
	/**
183
	 * Is the import currently handling a citation?
184
	 * @return
185
	 */
186
	public boolean isCitation() {
187
		return isCitation;
188
	}
189
	
190
	public void setCitation(boolean isCitation) {
191
		this.isCitation = isCitation;
192
	}
193

    
194

    
195
	public boolean isNameType() {
196
		return isNameType;
197
	}
198
	
199
	public void setNameType(boolean isNameType) {
200
		this.isNameType = isNameType;
201
	}
202

    
203
	public void setProParte(boolean isProParte) {
204
		this.isProParte = isProParte;
205
	}
206

    
207
	public boolean isProParte() {
208
		return isProParte;
209
	}
210

    
211
	public void setBaseMediaUrl(String baseMediaUrl) {
212
		this.baseMediaUrl = baseMediaUrl;
213
	}
214

    
215
	public String getBaseMediaUrl() {
216
		return baseMediaUrl;
217
	}
218

    
219
	
220
	
221
	public void registerFootnote(FootnoteDataHolder footnote) {
222
		footnoteRegister.put(footnote.id, footnote);
223
	}
224

    
225
	public FootnoteDataHolder getFootnote(String key) {
226
		return footnoteRegister.get(key);
227
	}
228
	
229
	
230
	public void registerFigure(String key, Media figure) {
231
		figureRegister.put(key, figure);
232
	}
233

    
234
	public Media getFigure(String key) {
235
		return figureRegister.get(key);
236
	}
237

    
238
	public Set<AnnotatableEntity> getFootnoteDemands(String footnoteId){
239
		return footnoteRefRegister.get(footnoteId);
240
	}
241
	
242
	public void putFootnoteDemands(String footnoteId, Set<AnnotatableEntity> demands){
243
		footnoteRefRegister.put(footnoteId, demands);
244
	}
245
	
246

    
247
	public Set<AnnotatableEntity> getFigureDemands(String figureId){
248
		return figureRefRegister.get(figureId);
249
	}
250
	
251
	public void putFigureDemands(String figureId, Set<AnnotatableEntity> demands){
252
		figureRefRegister.put(figureId, demands);
253
	}
254

    
255
	/**
256
	 * @param key
257
	 */
258
	public void setCurrentKey(PolytomousKey key) {
259
		this.currentKey = key;
260
	}
261
	
262
	/**
263
	 * @return the currentKey
264
	 */
265
	public PolytomousKey getCurrentKey() {
266
		return currentKey;
267
	}
268

    
269
	/**
270
	 * @param key
271
	 * @return
272
	 * @see java.util.Map#get(java.lang.Object)
273
	 */
274
	public UUID getAreaUuid(Object key) {
275
		return areaMap.get(key);
276
	}
277

    
278
	/**
279
	 * @param key
280
	 * @param value
281
	 * @return
282
	 * @see java.util.Map#put(java.lang.Object, java.lang.Object)
283
	 */
284
	public UUID putAreaUuid(String key, UUID value) {
285
		return areaMap.put(key, value);
286
	}
287

    
288
	public void putUnknownFeatureUuid(String featureLabel, UUID featureUuid) {
289
		this.unknownFeaturesUuids.put(featureLabel, featureUuid);
290
	}
291

    
292
	public boolean isOnlyNumberedTaxaExist() {
293
		return onlyNumberedTaxaExist;
294
	}
295

    
296
	public void setOnlyNumberedTaxaExist(boolean onlyNumberedTaxaExist) {
297
		this.onlyNumberedTaxaExist = onlyNumberedTaxaExist;
298
	}
299

    
300
	public Map<String,List<FeatureSorterInfo>> getGeneralFeatureSorterListMap() {
301
		return generalFeatureSorterListMap;
302
	}
303
	public Map<String,List<FeatureSorterInfo>> getCharFeatureSorterListMap() {
304
		return charFeatureSorterListMap;
305
	}
306
	
307
	public UUID getUnknownFeatureUuid(String featureLabel){
308
		return this.unknownFeaturesUuids.get(featureLabel);
309
	}
310
	
311

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

    
332
	/**
333
	 * 
334
	 * @param feature
335
	 */
336
	public FeatureSorterInfo putFeatureToCharSorterList(Feature feature) {
337
		FeatureSorterInfo featureSorterInfo = new FeatureSorterInfo(feature);
338
		currentCharFeatureSorterList.add(featureSorterInfo);
339
		return featureSorterInfo;
340
	}
341
	
342
	public FeatureSorterInfo getLatestCharFeatureSorterInfo() {
343
		return currentCharFeatureSorterList.get(currentCharFeatureSorterList.size() - 1);
344
	}
345

    
346
	
347
	/**
348
	 * 
349
	 * @param feature
350
	 */
351
	public void putFeatureToGeneralSorterList(Feature feature) {
352
		currentGeneralFeatureSorterList.add(new FeatureSorterInfo(feature)); 
353
		
354
	}
355

    
356
	public String getLatestGenusEpithet() {
357
		return latestGenusEpithet;
358
	}
359

    
360
	public void setLatestGenusEpithet(String latestGenusEpithet) {
361
		this.latestGenusEpithet = latestGenusEpithet;
362
	}
363

    
364

    
365
	public boolean isTaxonInClassification() {
366
		return taxonInClassification;
367
	}
368

    
369

    
370
	public void setTaxonInClassification(boolean taxonInClassification) {
371
		this.taxonInClassification = taxonInClassification;
372
	}
373

    
374

    
375
	public TeamOrPersonBase<?> getCurrentCollector() {
376
		return currentCollector;
377
	}
378

    
379

    
380
	public void setCurrentCollector(TeamOrPersonBase<?> currentCollector) {
381
		this.currentCollector = currentCollector;
382
	}
383

    
384

    
385
	public void addCurrentArea(NamedArea area) {
386
		currentAreas.add(area);	
387
	}
388

    
389

    
390
	public Set<NamedArea> getCurrentAreas() {
391
		return currentAreas;
392
	}
393
	
394
	public void removeCurrentAreas(){
395
		currentAreas.clear();
396
	}
397

    
398

    
399
	public TeamOrPersonBase<?> getLatestAuthorInHomotype() {
400
		return latestAuthorInHomotype;
401
	}
402

    
403

    
404
	public void setLatestAuthorInHomotype(TeamOrPersonBase<?> latestAuthorInHomotype) {
405
		this.latestAuthorInHomotype = latestAuthorInHomotype;
406
	}
407

    
408

    
409
	public Reference<?> getLatestReferenceInHomotype() {
410
		return latestReferenceInHomotype;
411
	}
412

    
413

    
414
	public void setLatestReferenceInHomotype(Reference<?> latestReferenceInHomotype) {
415
		this.latestReferenceInHomotype = latestReferenceInHomotype;
416
	}
417

    
418

    
419
}
(11-11/19)