1
|
// $Id$
|
2
|
/**
|
3
|
* Copyright (C) 2009 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
|
package eu.etaxonomy.cdm.strategy;
|
11
|
|
12
|
import java.util.ArrayList;
|
13
|
import java.util.Date;
|
14
|
import java.util.List;
|
15
|
|
16
|
import eu.etaxonomy.cdm.hibernate.HibernateProxyHelper;
|
17
|
import eu.etaxonomy.cdm.model.agent.Team;
|
18
|
import eu.etaxonomy.cdm.model.name.NonViralName;
|
19
|
import eu.etaxonomy.cdm.model.name.Rank;
|
20
|
import eu.etaxonomy.cdm.model.name.TaxonNameBase;
|
21
|
import eu.etaxonomy.cdm.strategy.cache.name.INameCacheStrategy;
|
22
|
|
23
|
/**
|
24
|
* @author a.kohlbecker
|
25
|
* @date 29.03.2011
|
26
|
*
|
27
|
* @deprecated use List<TaggedText> methods in according cache strategies instead. Will be removed with version 3.1.
|
28
|
*/
|
29
|
@Deprecated
|
30
|
public class TaggedTextGenerator {
|
31
|
|
32
|
/**
|
33
|
* FIXME ugly method - this functionality mainly be performed by ChachStrategies ?
|
34
|
*
|
35
|
* @param taxonNameBase
|
36
|
* @return
|
37
|
* @deprecated use List<TaggedText> methods in according cache strategies instead. Will be removed with next major version.
|
38
|
*/
|
39
|
@Deprecated
|
40
|
public static List<TaggedText> getTaggedName(TaxonNameBase<TaxonNameBase<?,?>, INameCacheStrategy<TaxonNameBase<?,?>>> taxonNameBase){
|
41
|
|
42
|
List<TaggedText> tags = new ArrayList<TaggedText>();
|
43
|
|
44
|
/**
|
45
|
* taxonNameBase.getHibernateLazyInitializer().getImplementation();
|
46
|
* class eu.etaxonomy.cdm.model.name.TaxonNameBase$$EnhancerByCGLIB$$3683183d
|
47
|
* @link( CGLIBLazyInitializer.getImplementation())
|
48
|
*/
|
49
|
// if(taxonNameBase instanceof HibernateProxy) {
|
50
|
// LazyInitializer lazyInitializer = ((HibernateProxy)taxonNameBase).getHibernateLazyInitializer();
|
51
|
// taxonNameBase = (TaxonNameBase)lazyInitializer.getImplementation();
|
52
|
// }
|
53
|
taxonNameBase = HibernateProxyHelper.deproxy(taxonNameBase, TaxonNameBase.class);
|
54
|
|
55
|
//FIXME rude hack:
|
56
|
if(!(taxonNameBase instanceof NonViralName)){
|
57
|
return tags;
|
58
|
}
|
59
|
|
60
|
// --- end of rude hack
|
61
|
//FIXME infrageneric epithets are not yet handled!
|
62
|
// - infraGenericEpithet "Cicerbita"
|
63
|
// - infraSpecificEpithet null
|
64
|
|
65
|
List<Object> taggedName = taxonNameBase.getCacheStrategy().getTaggedNameDeprecated(taxonNameBase);
|
66
|
for (Object token : taggedName){
|
67
|
TaggedText tag = new TaggedText();
|
68
|
if (String.class.isInstance(token)){
|
69
|
tag.setText((String)token);
|
70
|
tag.setType(TagEnum.name);
|
71
|
}
|
72
|
else if (Rank.class.isInstance(token)){
|
73
|
Rank r = (Rank)token;
|
74
|
tag.setText(r.getAbbreviation());
|
75
|
tag.setType(TagEnum.rank);
|
76
|
}
|
77
|
else if (Date.class.isInstance(token)){
|
78
|
Date d = (Date)token;
|
79
|
tag.setText(String.valueOf(d.getYear()));
|
80
|
tag.setType(TagEnum.year);
|
81
|
}
|
82
|
else if (Team.class.isInstance(token)){
|
83
|
Team t = (Team)token;
|
84
|
tag.setText(String.valueOf(t.getTitleCache()));
|
85
|
tag.setType(TagEnum.authors);
|
86
|
}
|
87
|
|
88
|
if (tag!=null){
|
89
|
tags.add(tag);
|
90
|
}
|
91
|
}
|
92
|
return tags;
|
93
|
}
|
94
|
|
95
|
|
96
|
|
97
|
}
|