Revision fe43cd3b
Added by Andreas Müller over 8 years ago
cdmlib-model/src/main/java/eu/etaxonomy/cdm/model/taxon/Synonym.java | ||
---|---|---|
38 | 38 |
import eu.etaxonomy.cdm.model.common.IRelated; |
39 | 39 |
import eu.etaxonomy.cdm.model.name.TaxonNameBase; |
40 | 40 |
import eu.etaxonomy.cdm.model.reference.Reference; |
41 |
import eu.etaxonomy.cdm.strategy.cache.common.IIdentifiableEntityCacheStrategy;
|
|
41 |
import eu.etaxonomy.cdm.strategy.cache.taxon.ITaxonCacheStrategy;
|
|
42 | 42 |
import eu.etaxonomy.cdm.strategy.cache.taxon.TaxonBaseDefaultCacheStrategy; |
43 | 43 |
import eu.etaxonomy.cdm.validation.Level2; |
44 | 44 |
|
... | ... | |
67 | 67 |
@Indexed(index = "eu.etaxonomy.cdm.model.taxon.TaxonBase") |
68 | 68 |
@Audited |
69 | 69 |
@Configurable |
70 |
public class Synonym extends TaxonBase<IIdentifiableEntityCacheStrategy<Synonym>> implements IRelated<SynonymRelationship>{
|
|
70 |
public class Synonym extends TaxonBase<ITaxonCacheStrategy<Synonym>> implements IRelated<SynonymRelationship>{
|
|
71 | 71 |
private static final long serialVersionUID = -454067515022159757L; |
72 | 72 |
|
73 | 73 |
@SuppressWarnings("unused") |
cdmlib-model/src/main/java/eu/etaxonomy/cdm/model/taxon/Taxon.java | ||
---|---|---|
59 | 59 |
import eu.etaxonomy.cdm.model.name.HomotypicalGroup; |
60 | 60 |
import eu.etaxonomy.cdm.model.name.TaxonNameBase; |
61 | 61 |
import eu.etaxonomy.cdm.model.reference.Reference; |
62 |
import eu.etaxonomy.cdm.strategy.cache.common.IIdentifiableEntityCacheStrategy;
|
|
62 |
import eu.etaxonomy.cdm.strategy.cache.taxon.ITaxonCacheStrategy;
|
|
63 | 63 |
import eu.etaxonomy.cdm.strategy.cache.taxon.TaxonBaseDefaultCacheStrategy; |
64 | 64 |
|
65 | 65 |
/** |
... | ... | |
93 | 93 |
@ClassBridge(impl = GroupByTaxonClassBridge.class), |
94 | 94 |
@ClassBridge(impl = TaxonRelationshipClassBridge.class) |
95 | 95 |
}) |
96 |
public class Taxon extends TaxonBase<IIdentifiableEntityCacheStrategy<Taxon>> |
|
96 |
public class Taxon |
|
97 |
extends TaxonBase<ITaxonCacheStrategy<Taxon>> |
|
97 | 98 |
implements IRelated<RelationshipBase>, IDescribable<TaxonDescription>, Cloneable{ |
99 |
|
|
98 | 100 |
private static final long serialVersionUID = -584946869762749006L; |
99 | 101 |
private static final Logger logger = Logger.getLogger(Taxon.class); |
100 | 102 |
|
... | ... | |
282 | 284 |
ReflectionUtils.setField(field, description, null); |
283 | 285 |
descriptions.remove(description); |
284 | 286 |
} |
285 |
|
|
286 |
|
|
287 |
|
|
288 |
|
|
287 | 289 |
public void removeDescription(TaxonDescription description, boolean removeElements){ |
288 | 290 |
if (removeElements){ |
289 | 291 |
Set<DescriptionElementBase> elements = new HashSet<DescriptionElementBase>(description.getElements()); |
... | ... | |
1849 | 1851 |
public void clearDescriptions() { |
1850 | 1852 |
this.descriptions = new HashSet<TaxonDescription>(); |
1851 | 1853 |
} |
1852 |
|
|
1854 |
|
|
1853 | 1855 |
@Override |
1854 |
public void setCacheStrategy(IIdentifiableEntityCacheStrategy<Taxon> cacheStrategy){
|
|
1856 |
public void setCacheStrategy(ITaxonCacheStrategy<Taxon> cacheStrategy){
|
|
1855 | 1857 |
this.cacheStrategy = cacheStrategy; |
1856 | 1858 |
} |
1857 | 1859 |
} |
cdmlib-model/src/main/java/eu/etaxonomy/cdm/model/taxon/TaxonBase.java | ||
---|---|---|
10 | 10 |
package eu.etaxonomy.cdm.model.taxon; |
11 | 11 |
|
12 | 12 |
import java.lang.reflect.Method; |
13 |
import java.util.List; |
|
13 | 14 |
|
14 | 15 |
import javax.persistence.Entity; |
15 | 16 |
import javax.persistence.FetchType; |
... | ... | |
43 | 44 |
import eu.etaxonomy.cdm.model.name.Rank; |
44 | 45 |
import eu.etaxonomy.cdm.model.name.TaxonNameBase; |
45 | 46 |
import eu.etaxonomy.cdm.model.reference.Reference; |
46 |
import eu.etaxonomy.cdm.strategy.cache.common.IIdentifiableEntityCacheStrategy; |
|
47 |
import eu.etaxonomy.cdm.strategy.cache.TaggedText; |
|
48 |
import eu.etaxonomy.cdm.strategy.cache.taxon.ITaxonCacheStrategy; |
|
47 | 49 |
import eu.etaxonomy.cdm.validation.Level2; |
48 | 50 |
import eu.etaxonomy.cdm.validation.Level3; |
49 | 51 |
import eu.etaxonomy.cdm.validation.annotation.TaxonNameCannotBeAcceptedAndSynonym; |
... | ... | |
90 | 92 |
impl = AcceptedTaxonBridge.class), |
91 | 93 |
@ClassBridge(impl = eu.etaxonomy.cdm.hibernate.search.NomenclaturalSortOrderBrigde.class) |
92 | 94 |
}) |
93 |
public abstract class TaxonBase<S extends IIdentifiableEntityCacheStrategy> extends IdentifiableEntity<S> implements IPublishable, Cloneable {
|
|
95 |
public abstract class TaxonBase<S extends ITaxonCacheStrategy> extends IdentifiableEntity<S> implements IPublishable, Cloneable {
|
|
94 | 96 |
private static final long serialVersionUID = -3589185949928938529L; |
95 | 97 |
private static final Logger logger = Logger.getLogger(TaxonBase.class); |
96 | 98 |
|
... | ... | |
202 | 204 |
// return title; |
203 | 205 |
// } |
204 | 206 |
|
207 |
@Transient |
|
208 |
public List<TaggedText> getTaggedTitle(){ |
|
209 |
return getCacheStrategy().getTaggedTitle(this); |
|
210 |
} |
|
211 |
|
|
212 |
|
|
213 |
|
|
205 | 214 |
/** |
206 | 215 |
* Returns the {@link TaxonNameBase taxon name} used in <i>this</i> (abstract) taxon. |
207 | 216 |
*/ |
... | ... | |
209 | 218 |
return this.name; |
210 | 219 |
} |
211 | 220 |
|
212 |
/* |
|
213 |
* @see #getName |
|
214 |
*/ |
|
215 | 221 |
public void setName(TaxonNameBase name) { |
216 | 222 |
if (this.name != null){ |
217 | 223 |
this.name.getTaxonBases().remove(this); |
... | ... | |
322 | 328 |
|
323 | 329 |
@Transient |
324 | 330 |
public abstract boolean isOrphaned(); |
331 |
|
|
332 |
|
|
333 |
/** |
|
334 |
* @return |
|
335 |
*/ |
|
336 |
@Transient |
|
337 |
public Rank getNullSafeRank() { |
|
338 |
return name == null ? null : name.getRank(); |
|
339 |
} |
|
340 |
|
|
341 |
@Override |
|
342 |
public void setCacheStrategy(S cacheStrategy) { |
|
343 |
this.cacheStrategy = cacheStrategy; |
|
344 |
} |
|
345 |
|
|
325 | 346 |
//*********************** CLONE ********************************************************/ |
326 | 347 |
|
327 | 348 |
/** |
... | ... | |
348 | 369 |
|
349 | 370 |
} |
350 | 371 |
|
351 |
/** |
|
352 |
* @return |
|
353 |
*/ |
|
354 |
@Transient |
|
355 |
public Rank getNullSafeRank() { |
|
356 |
return name == null ? null : name.getRank(); |
|
357 |
} |
|
358 |
|
|
359 | 372 |
|
360 | 373 |
} |
cdmlib-model/src/main/java/eu/etaxonomy/cdm/strategy/cache/TagEnum.java | ||
---|---|---|
1 | 1 |
/** |
2 | 2 |
* Copyright (C) 2007 EDIT |
3 |
* European Distributed Institute of Taxonomy
|
|
3 |
* European Distributed Institute of Taxonomy |
|
4 | 4 |
* http://www.e-taxonomy.eu |
5 |
*
|
|
5 |
* |
|
6 | 6 |
* The contents of this file are subject to the Mozilla Public License Version 1.1 |
7 | 7 |
* See LICENSE.TXT at the top of this package for the full license terms. |
8 | 8 |
*/ |
... | ... | |
14 | 14 |
/** |
15 | 15 |
* Tags for atomised taxon name strings and atomised reference citation strings. |
16 | 16 |
* Used by {@link TaggedText}. |
17 |
*
|
|
17 |
* |
|
18 | 18 |
* @author a.kohlbecker |
19 | 19 |
* @version 1.0 |
20 | 20 |
* @created 13.12.2007 12:04:15 |
21 | 21 |
* |
22 | 22 |
*/ |
23 | 23 |
public enum TagEnum { |
24 |
|
|
24 |
|
|
25 | 25 |
/** |
26 | 26 |
* A taxon name including genus name, epithet etc. |
27 | 27 |
*/ |
... | ... | |
31 | 31 |
*/ |
32 | 32 |
rank, |
33 | 33 |
/** |
34 |
* Non-atomised addition to a taxon name not ruled by a nomenclatural code |
|
34 |
* Non-atomised addition to a taxon name or a taxon not ruled by a nomenclatural code
|
|
35 | 35 |
*/ |
36 | 36 |
appendedPhrase, |
37 | 37 |
/** |
38 |
* The authors of a reference, also used in taxon names
|
|
38 |
* The authors of a reference, also used in taxon names |
|
39 | 39 |
*/ |
40 | 40 |
authors, |
41 | 41 |
/** |
... | ... | |
51 | 51 |
*/ |
52 | 52 |
year, |
53 | 53 |
/** |
54 |
* A full taxon name including all name information and nomenclatural
|
|
54 |
* A full taxon name including all name information and nomenclatural |
|
55 | 55 |
* reference information |
56 | 56 |
*/ |
57 | 57 |
fullName, |
58 | 58 |
/** |
59 |
* The nomenclatural status of a name
|
|
59 |
* The nomenclatural status of a name |
|
60 | 60 |
*/ |
61 | 61 |
nomStatus, |
62 | 62 |
/** |
63 |
* A separator to separate two tags () .
|
|
64 |
* A separator should include all needed whitespaces. So adding of whitespace
|
|
63 |
* A separator to separate two tags () . |
|
64 |
* A separator should include all needed whitespaces. So adding of whitespace |
|
65 | 65 |
* is not needed if a separator is given. |
66 | 66 |
*/ |
67 | 67 |
separator, |
68 | 68 |
/** |
69 |
* The hybrid sign.
|
|
69 |
* The hybrid sign. |
|
70 | 70 |
*/ |
71 |
hybridSign |
|
71 |
hybridSign, |
|
72 |
|
|
72 | 73 |
; |
73 |
|
|
74 |
|
|
74 |
|
|
75 |
|
|
75 | 76 |
public boolean isName(){ |
76 | 77 |
return this == name; |
77 | 78 |
} |
cdmlib-model/src/main/java/eu/etaxonomy/cdm/strategy/cache/TaggedCacheHelper.java | ||
---|---|---|
1 |
// $Id$ |
|
2 |
/** |
|
3 |
* Copyright (C) 2015 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.cache; |
|
11 |
|
|
12 |
import java.util.List; |
|
13 |
import java.util.SortedSet; |
|
14 |
import java.util.Stack; |
|
15 |
import java.util.TreeSet; |
|
16 |
|
|
17 |
/** |
|
18 |
* @author a.mueller |
|
19 |
* @date 09.09.2015 |
|
20 |
* |
|
21 |
*/ |
|
22 |
public class TaggedCacheHelper { |
|
23 |
|
|
24 |
/** |
|
25 |
* Creates a string from tagged text by concatenating all tags with a whitespace. |
|
26 |
* @param tags |
|
27 |
* @return the concatenated string |
|
28 |
* @see #createString(List, HTMLTagRules) |
|
29 |
*/ |
|
30 |
public static String createString(List<TaggedText> tags) { |
|
31 |
StringBuffer result = new StringBuffer(); |
|
32 |
|
|
33 |
boolean isSeparator; |
|
34 |
boolean wasSeparator = true; //true for start tag |
|
35 |
for (TaggedText tag: tags){ |
|
36 |
isSeparator = tag.getType().isSeparator(); |
|
37 |
if (! wasSeparator && ! isSeparator ){ |
|
38 |
result.append(" "); |
|
39 |
} |
|
40 |
result.append(tag.getText()); |
|
41 |
wasSeparator = isSeparator; |
|
42 |
} |
|
43 |
return result.toString().trim(); |
|
44 |
} |
|
45 |
|
|
46 |
|
|
47 |
/** |
|
48 |
* Creates a string from tagged text by concatenating all tags. If no separator tag is defined |
|
49 |
* tags are seperated by simple whitespace. |
|
50 |
* @param tags |
|
51 |
* @return |
|
52 |
*/ |
|
53 |
public static String createString(List<TaggedText> tags, HTMLTagRules htmlRules) { |
|
54 |
if (htmlRules == null){ |
|
55 |
return createString(tags); |
|
56 |
} |
|
57 |
//add whitespace separators |
|
58 |
int index = 0; |
|
59 |
boolean wasSeparator = true; |
|
60 |
while (index < tags.size()){ |
|
61 |
|
|
62 |
if (! tags.get(index).isSeparator()){ |
|
63 |
if (wasSeparator == false){ |
|
64 |
tags.add(index++, TaggedText.NewWhitespaceInstance()); |
|
65 |
}else{ |
|
66 |
wasSeparator = false; |
|
67 |
} |
|
68 |
}else{ |
|
69 |
wasSeparator = true; |
|
70 |
} |
|
71 |
index++; |
|
72 |
} |
|
73 |
|
|
74 |
//create String |
|
75 |
StringBuffer result = new StringBuffer(); |
|
76 |
|
|
77 |
Stack<String> htmlStack = new Stack<String>(); |
|
78 |
for (int i = 0; i < tags.size(); i++ ){ |
|
79 |
TaggedText tag = tags.get(i); |
|
80 |
TagEnum thisType = tag.getType(); |
|
81 |
TagEnum lastType = (i == 0? null : tags.get(i - 1).getType()); |
|
82 |
TagEnum nextType = (i + 1 >= tags.size() ? null : tags.get(i + 1).getType()); |
|
83 |
|
|
84 |
boolean isSeparator = tag.getType().isSeparator(); |
|
85 |
// boolean lastEqual = tag.getType().equals(lastType); |
|
86 |
// boolean nextEqual = tag.getType().equals(nextType); |
|
87 |
// boolean bothEqual = lastEqual && nextEqual; |
|
88 |
|
|
89 |
//compute list of rules (tags) |
|
90 |
SortedSet<String> separatorRules; |
|
91 |
if (isSeparator){ |
|
92 |
separatorRules = getCommonRules(htmlRules.getRule(lastType), htmlRules.getRule(nextType)); |
|
93 |
}else{ |
|
94 |
separatorRules = htmlRules.getRule(thisType); |
|
95 |
} |
|
96 |
|
|
97 |
//Close all tags not used anymore and remove all common tags from list of rules |
|
98 |
for (int j = 0 ; j < htmlStack.size() ; j++){ |
|
99 |
String html = htmlStack.get(j); |
|
100 |
if (! separatorRules.contains(html)){ |
|
101 |
closeHtml(result, htmlStack, j); |
|
102 |
break; |
|
103 |
}else{ |
|
104 |
separatorRules.remove(html); |
|
105 |
} |
|
106 |
} |
|
107 |
|
|
108 |
//open all tags not yet existing |
|
109 |
if (! isSeparator){ |
|
110 |
for (String rule : separatorRules){ |
|
111 |
htmlStack.add(rule); |
|
112 |
result.append("<" + rule + ">"); |
|
113 |
} |
|
114 |
} |
|
115 |
|
|
116 |
//add whitespace |
|
117 |
if (lastType != null && ! lastType.isSeparator() && ! isSeparator && nextType != null){ |
|
118 |
result.append(" "); |
|
119 |
} |
|
120 |
result.append(tag.getText()); |
|
121 |
} |
|
122 |
closeHtml(result, htmlStack, 0); |
|
123 |
return result.toString(); |
|
124 |
} |
|
125 |
|
|
126 |
|
|
127 |
private static void closeHtml(StringBuffer result, Stack<String> htmlStack, int index) { |
|
128 |
while (htmlStack.size() > index){ |
|
129 |
String closeHtml = htmlStack.pop(); |
|
130 |
result.append("</" + closeHtml + ">"); |
|
131 |
} |
|
132 |
} |
|
133 |
|
|
134 |
private static SortedSet<String> getCommonRules(SortedSet<String> rules1,SortedSet<String> rules2) { |
|
135 |
SortedSet<String> result = new TreeSet<String>(); |
|
136 |
for (String str : rules1){ |
|
137 |
if (rules2.contains(str)){ |
|
138 |
result.add(str); |
|
139 |
} |
|
140 |
} |
|
141 |
return result; |
|
142 |
} |
|
143 |
} |
cdmlib-model/src/main/java/eu/etaxonomy/cdm/strategy/cache/name/NameCacheStrategyBase.java | ||
---|---|---|
1 |
/** |
|
2 |
* Copyright (C) 2007 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 |
package eu.etaxonomy.cdm.strategy.cache.name; |
|
10 |
|
|
11 |
import java.util.List; |
|
12 |
import java.util.UUID; |
|
13 |
|
|
14 |
import org.apache.log4j.Logger; |
|
15 |
|
|
16 |
import eu.etaxonomy.cdm.model.name.TaxonNameBase; |
|
17 |
import eu.etaxonomy.cdm.strategy.StrategyBase; |
|
18 |
import eu.etaxonomy.cdm.strategy.cache.HTMLTagRules; |
|
19 |
import eu.etaxonomy.cdm.strategy.cache.TaggedText; |
|
20 |
|
|
21 |
/** |
|
22 |
* @author AM |
|
23 |
* |
|
24 |
*/ |
|
25 |
public abstract class NameCacheStrategyBase<T extends TaxonNameBase> extends StrategyBase implements INameCacheStrategy<T> { |
|
26 |
@SuppressWarnings("unused") |
|
27 |
private static final Logger logger = Logger.getLogger(NameCacheStrategyBase.class); |
|
28 |
|
|
29 |
final static UUID uuid = UUID.fromString("817ae5b5-3ac2-414b-a134-a9ae86cba040"); |
|
30 |
|
|
31 |
/** |
|
32 |
* Constructor |
|
33 |
*/ |
|
34 |
public NameCacheStrategyBase() { |
|
35 |
super(); |
|
36 |
} |
|
37 |
|
|
38 |
|
|
39 |
/** |
|
40 |
* Generates and returns the title cache of the given name. |
|
41 |
* The title cache in general includes the name and the authorship and year for some types of names. |
|
42 |
* |
|
43 |
* @see eu.etaxonomy.cdm.strategy.INameCacheStrategy#getTitleCache(eu.etaxonomy.cdm.model.common.CdmBase) |
|
44 |
* @see eu.etaxonomy.cdm.strategy.cache.common.IIdentifiableEntityCacheStrategy#getTitleCache(eu.etaxonomy.cdm.model.common.IdentifiableEntity) |
|
45 |
*/ |
|
46 |
public abstract String getTitleCache(T name); |
|
47 |
|
|
48 |
|
|
49 |
/* (non-Javadoc) |
|
50 |
* @see eu.etaxonomy.cdm.strategy.cache.name.INameCacheStrategy#getTitleCache(eu.etaxonomy.cdm.model.name.TaxonNameBase, eu.etaxonomy.cdm.strategy.cache.HTMLTagRules) |
|
51 |
*/ |
|
52 |
public abstract String getTitleCache(T name, HTMLTagRules rules); |
|
53 |
|
|
54 |
|
|
55 |
/* (non-Javadoc) |
|
56 |
* @see eu.etaxonomy.cdm.strategy.cache.name.INameCacheStrategy#getFullTitleCache(eu.etaxonomy.cdm.model.name.TaxonNameBase) |
|
57 |
*/ |
|
58 |
public abstract String getFullTitleCache(T name); |
|
59 |
|
|
60 |
/* (non-Javadoc) |
|
61 |
* @see eu.etaxonomy.cdm.strategy.cache.name.INameCacheStrategy#getFullTitleCache(eu.etaxonomy.cdm.model.name.TaxonNameBase, eu.etaxonomy.cdm.strategy.cache.HTMLTagRules) |
|
62 |
*/ |
|
63 |
public abstract String getFullTitleCache(T name, HTMLTagRules rules); |
|
64 |
|
|
65 |
/* (non-Javadoc) |
|
66 |
* @see eu.etaxonomy.cdm.strategy.cache.name.INameCacheStrategy#getTaggedTitle(eu.etaxonomy.cdm.model.name.TaxonNameBase) |
|
67 |
*/ |
|
68 |
public abstract List<TaggedText> getTaggedTitle(T taxonNameBase); |
|
69 |
|
|
70 |
/* (non-Javadoc) |
|
71 |
* @see eu.etaxonomy.cdm.strategy.cache.name.INameCacheStrategy#getTaggedFullTitle(eu.etaxonomy.cdm.model.name.TaxonNameBase) |
|
72 |
*/ |
|
73 |
public abstract List<TaggedText> getTaggedFullTitle(T taxonNameBase); |
|
74 |
|
|
75 |
} |
|
1 |
/** |
|
2 |
* Copyright (C) 2007 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 |
package eu.etaxonomy.cdm.strategy.cache.name; |
|
10 |
|
|
11 |
import java.util.List; |
|
12 |
import java.util.UUID; |
|
13 |
|
|
14 |
import org.apache.log4j.Logger; |
|
15 |
|
|
16 |
import eu.etaxonomy.cdm.model.name.TaxonNameBase; |
|
17 |
import eu.etaxonomy.cdm.strategy.StrategyBase; |
|
18 |
import eu.etaxonomy.cdm.strategy.cache.HTMLTagRules; |
|
19 |
import eu.etaxonomy.cdm.strategy.cache.TaggedText; |
|
20 |
|
|
21 |
/** |
|
22 |
* @author AM |
|
23 |
*/ |
|
24 |
public abstract class NameCacheStrategyBase<T extends TaxonNameBase> extends StrategyBase implements INameCacheStrategy<T> { |
|
25 |
@SuppressWarnings("unused") |
|
26 |
private static final Logger logger = Logger.getLogger(NameCacheStrategyBase.class); |
|
27 |
|
|
28 |
final static UUID uuid = UUID.fromString("817ae5b5-3ac2-414b-a134-a9ae86cba040"); |
|
29 |
|
|
30 |
/** |
|
31 |
* Constructor |
|
32 |
*/ |
|
33 |
public NameCacheStrategyBase() { |
|
34 |
super(); |
|
35 |
} |
|
36 |
|
|
37 |
|
|
38 |
/** |
|
39 |
* Generates and returns the title cache of the given name. |
|
40 |
* The title cache in general includes the name and the authorship and year for some types of names. |
|
41 |
* |
|
42 |
* @see eu.etaxonomy.cdm.strategy.INameCacheStrategy#getTitleCache(eu.etaxonomy.cdm.model.common.CdmBase) |
|
43 |
* @see eu.etaxonomy.cdm.strategy.cache.common.IIdentifiableEntityCacheStrategy#getTitleCache(eu.etaxonomy.cdm.model.common.IdentifiableEntity) |
|
44 |
*/ |
|
45 |
@Override |
|
46 |
public abstract String getTitleCache(T name); |
|
47 |
|
|
48 |
@Override |
|
49 |
public abstract String getTitleCache(T name, HTMLTagRules rules); |
|
50 |
|
|
51 |
@Override |
|
52 |
public abstract String getFullTitleCache(T name); |
|
53 |
|
|
54 |
@Override |
|
55 |
public abstract String getFullTitleCache(T name, HTMLTagRules rules); |
|
56 |
|
|
57 |
@Override |
|
58 |
public abstract List<TaggedText> getTaggedTitle(T taxonNameBase); |
|
59 |
|
|
60 |
@Override |
|
61 |
public abstract List<TaggedText> getTaggedFullTitle(T taxonNameBase); |
|
62 |
|
|
63 |
} |
cdmlib-model/src/main/java/eu/etaxonomy/cdm/strategy/cache/name/NonViralNameDefaultCacheStrategy.java | ||
---|---|---|
12 | 12 |
import java.util.Iterator; |
13 | 13 |
import java.util.List; |
14 | 14 |
import java.util.Set; |
15 |
import java.util.SortedSet; |
|
16 |
import java.util.Stack; |
|
17 |
import java.util.TreeSet; |
|
18 | 15 |
import java.util.UUID; |
19 | 16 |
|
20 | 17 |
import org.apache.commons.lang.StringUtils; |
... | ... | |
38 | 35 |
import eu.etaxonomy.cdm.model.reference.INomenclaturalReference; |
39 | 36 |
import eu.etaxonomy.cdm.strategy.cache.HTMLTagRules; |
40 | 37 |
import eu.etaxonomy.cdm.strategy.cache.TagEnum; |
38 |
import eu.etaxonomy.cdm.strategy.cache.TaggedCacheHelper; |
|
41 | 39 |
import eu.etaxonomy.cdm.strategy.cache.TaggedText; |
42 | 40 |
import eu.etaxonomy.cdm.strategy.exceptions.UnknownCdmTypeException; |
43 | 41 |
import eu.etaxonomy.cdm.strategy.parser.NonViralNameParserImplRegExBase; |
... | ... | |
52 | 50 |
* existing methods, e.g. a CacheStrategy for zoological names should overwrite getAuthorAndExAuthor |
53 | 51 |
* @author a.mueller |
54 | 52 |
*/ |
55 |
public class NonViralNameDefaultCacheStrategy<T extends NonViralName<?>> extends NameCacheStrategyBase<T> implements INonViralNameCacheStrategy<T> { |
|
53 |
public class NonViralNameDefaultCacheStrategy<T extends NonViralName<?>> |
|
54 |
extends NameCacheStrategyBase<T> |
|
55 |
implements INonViralNameCacheStrategy<T> { |
|
56 | 56 |
private static final Logger logger = Logger.getLogger(NonViralNameDefaultCacheStrategy.class); |
57 | 57 |
private static final long serialVersionUID = -6577757501563212669L; |
58 | 58 |
|
... | ... | |
184 | 184 |
return result; |
185 | 185 |
} |
186 | 186 |
} |
187 |
|
|
187 |
|
|
188 | 188 |
@Override |
189 | 189 |
public String getFullTitleCache(T nonViralName, HTMLTagRules htmlTagRules) { |
190 | 190 |
List<TaggedText> tags = getTaggedFullTitle(nonViralName); |
... | ... | |
218 | 218 |
} |
219 | 219 |
|
220 | 220 |
|
221 |
/** |
|
222 |
* Creates a string from tagged text by concatenating all tags. If do seperator tag is defined |
|
223 |
* tags are seperated by simple whitespace. |
|
224 |
* @param tags |
|
225 |
* @return |
|
226 |
*/ |
|
227 |
protected static String createString(List<TaggedText> tags) { |
|
228 |
StringBuffer result = new StringBuffer(); |
|
229 |
|
|
230 |
boolean isSeparator; |
|
231 |
boolean wasSeparator = true; //true for start tag |
|
232 |
for (TaggedText tag: tags){ |
|
233 |
isSeparator = tag.getType().isSeparator(); |
|
234 |
if (! wasSeparator && ! isSeparator ){ |
|
235 |
result.append(" "); |
|
236 |
} |
|
237 |
result.append(tag.getText()); |
|
238 |
wasSeparator = isSeparator; |
|
239 |
} |
|
240 |
return result.toString().trim(); |
|
241 |
} |
|
242 |
|
|
243 |
protected static String createString(List<TaggedText> tags, HTMLTagRules htmlRules) { |
|
244 |
if (htmlRules == null){ |
|
245 |
return createString(tags); |
|
246 |
} |
|
247 |
//add whitespace separators |
|
248 |
int index = 0; |
|
249 |
boolean wasSeparator = true; |
|
250 |
while (index < tags.size()){ |
|
251 |
|
|
252 |
if (! tags.get(index).isSeparator()){ |
|
253 |
if (wasSeparator == false){ |
|
254 |
tags.add(index++, TaggedText.NewWhitespaceInstance()); |
|
255 |
}else{ |
|
256 |
wasSeparator = false; |
|
257 |
} |
|
258 |
}else{ |
|
259 |
wasSeparator = true; |
|
260 |
} |
|
261 |
index++; |
|
262 |
} |
|
263 |
|
|
264 |
//create String |
|
265 |
StringBuffer result = new StringBuffer(); |
|
266 |
|
|
267 |
Stack<String> htmlStack = new Stack<String>(); |
|
268 |
for (int i = 0; i < tags.size(); i++ ){ |
|
269 |
TaggedText tag = tags.get(i); |
|
270 |
TagEnum thisType = tag.getType(); |
|
271 |
TagEnum lastType = (i == 0? null : tags.get(i - 1).getType()); |
|
272 |
TagEnum nextType = (i + 1 >= tags.size() ? null : tags.get(i + 1).getType()); |
|
273 |
|
|
274 |
boolean isSeparator = tag.getType().isSeparator(); |
|
275 |
// boolean lastEqual = tag.getType().equals(lastType); |
|
276 |
// boolean nextEqual = tag.getType().equals(nextType); |
|
277 |
// boolean bothEqual = lastEqual && nextEqual; |
|
278 |
|
|
279 |
//compute list of rules (tags) |
|
280 |
SortedSet<String> separatorRules; |
|
281 |
if (isSeparator){ |
|
282 |
separatorRules = getCommonRules(htmlRules.getRule(lastType), htmlRules.getRule(nextType)); |
|
283 |
}else{ |
|
284 |
separatorRules = htmlRules.getRule(thisType); |
|
285 |
} |
|
286 |
|
|
287 |
//Close all tags not used anymore and remove all common tags from list of rules |
|
288 |
for (int j = 0 ; j < htmlStack.size() ; j++){ |
|
289 |
String html = htmlStack.get(j); |
|
290 |
if (! separatorRules.contains(html)){ |
|
291 |
closeHtml(result, htmlStack, j); |
|
292 |
break; |
|
293 |
}else{ |
|
294 |
separatorRules.remove(html); |
|
295 |
} |
|
296 |
} |
|
297 |
|
|
298 |
//open all tags not yet existing |
|
299 |
if (! isSeparator){ |
|
300 |
for (String rule : separatorRules){ |
|
301 |
htmlStack.add(rule); |
|
302 |
result.append("<" + rule + ">"); |
|
303 |
} |
|
304 |
} |
|
305 |
|
|
306 |
//add whitespace |
|
307 |
if (lastType != null && ! lastType.isSeparator() && ! isSeparator && nextType != null){ |
|
308 |
result.append(" "); |
|
309 |
} |
|
310 |
result.append(tag.getText()); |
|
311 |
} |
|
312 |
closeHtml(result, htmlStack, 0); |
|
313 |
return result.toString(); |
|
314 |
} |
|
315 | 221 |
|
316 | 222 |
|
317 |
private static void closeHtml(StringBuffer result, Stack<String> htmlStack, int index) { |
|
318 |
while (htmlStack.size() > index){ |
|
319 |
String closeHtml = htmlStack.pop(); |
|
320 |
result.append("</" + closeHtml + ">"); |
|
321 |
} |
|
322 |
} |
|
323 |
|
|
324 |
private static SortedSet<String> getCommonRules(SortedSet<String> rules1,SortedSet<String> rules2) { |
|
325 |
SortedSet<String> result = new TreeSet<String>(); |
|
326 |
for (String str : rules1){ |
|
327 |
if (rules2.contains(str)){ |
|
328 |
result.add(str); |
|
329 |
} |
|
330 |
} |
|
331 |
return result; |
|
332 |
} |
|
223 |
|
|
333 | 224 |
|
334 | 225 |
|
335 | 226 |
// ******************* Authorship ******************************/ |
... | ... | |
462 | 353 |
Iterator<NomenclaturalStatus> iterator = ncStati.iterator(); |
463 | 354 |
List<TaggedText> nomStatusTags = new ArrayList<TaggedText>(); |
464 | 355 |
while (iterator.hasNext()) { |
465 |
NomenclaturalStatus ncStatus = (NomenclaturalStatus)iterator.next();
|
|
356 |
NomenclaturalStatus ncStatus = iterator.next(); |
|
466 | 357 |
// since the NewInstance method of nomencatural status allows null as parameter |
467 | 358 |
// we have to check for null values here |
468 | 359 |
String suffix = "not defined"; |
... | ... | |
529 | 420 |
} |
530 | 421 |
} |
531 | 422 |
return tags; |
532 |
|
|
533 | 423 |
} |
534 | 424 |
|
535 | 425 |
/** |
... | ... | |
599 | 489 |
if (nonViralName.isInfraSpecific()){ |
600 | 490 |
//species part |
601 | 491 |
tags = getSpeciesTaggedNameCache(nonViralName); |
602 |
|
|
492 |
|
|
603 | 493 |
//author |
604 | 494 |
String authorCache = getAuthorshipCache(nonViralName); |
605 | 495 |
if (StringUtils.isNotBlank(authorCache)){ |
606 | 496 |
tags.add(new TaggedText(TagEnum.authors, authorCache)); |
607 | 497 |
} |
608 |
|
|
609 |
|
|
498 |
|
|
499 |
|
|
610 | 500 |
//infra species marker |
611 | 501 |
if (nonViralName.getRank() == null || !nonViralName.getRank().isInfraSpecific()){ |
612 | 502 |
//TODO handle exception |
... | ... | |
617 | 507 |
tags.add(new TaggedText(TagEnum.rank, infraSpeciesMarker)); |
618 | 508 |
} |
619 | 509 |
} |
620 |
|
|
510 |
|
|
621 | 511 |
//infra species |
622 | 512 |
String infraSpeciesPart = CdmUtils.Nz(nonViralName.getInfraSpecificEpithet()).trim(); |
623 | 513 |
if (StringUtils.isNotBlank(infraSpeciesPart)){ |
624 | 514 |
tags.add(new TaggedText(TagEnum.name, infraSpeciesPart)); |
625 | 515 |
} |
626 |
|
|
516 |
|
|
627 | 517 |
} else if (nonViralName.isInfraGeneric()){ |
628 | 518 |
//genus part |
629 | 519 |
tags =getGenusOrUninomialTaggedNameCache(nonViralName); |
630 |
|
|
631 |
|
|
520 |
|
|
521 |
|
|
632 | 522 |
//infra species marker |
633 | 523 |
if (nonViralName.getRank() == null || !nonViralName.getRank().isInfraGeneric()){ |
634 | 524 |
//TODO handle exception |
... | ... | |
643 | 533 |
tags.add(new TaggedText(TagEnum.rank, infraGenericMarker)); |
644 | 534 |
} |
645 | 535 |
} |
646 |
|
|
536 |
|
|
647 | 537 |
//infra species |
648 | 538 |
String infraGenericPart = CdmUtils.Nz(nonViralName.getInfraGenericEpithet()).trim(); |
649 | 539 |
if (StringUtils.isNotBlank(infraGenericPart)){ |
650 | 540 |
tags.add(new TaggedText(TagEnum.name, infraGenericPart)); |
651 | 541 |
} |
652 |
|
|
542 |
|
|
653 | 543 |
} |
654 | 544 |
|
655 | 545 |
return tags; |
... | ... | |
742 | 632 |
infraGenericMarker = "'undefined infrageneric rank'"; |
743 | 633 |
} |
744 | 634 |
String infraGenEpi = CdmUtils.Nz(nonViralName.getInfraGenericEpithet()).trim(); |
745 |
|
|
635 |
|
|
746 | 636 |
addInfraGenericPart(nonViralName, tags, infraGenericMarker, infraGenEpi); |
747 | 637 |
|
748 | 638 |
addAppendedTaggedPhrase(tags, nonViralName); |
... | ... | |
751 | 641 |
|
752 | 642 |
|
753 | 643 |
/** |
754 |
* Default implementation for the infrageneric part of a name.
|
|
644 |
* Default implementation for the infrageneric part of a name. |
|
755 | 645 |
* This is usually the infrageneric marker and the infrageneric epitheton. But may be implemented differently e.g. for zoological |
756 | 646 |
* names the infrageneric epitheton may be surrounded by brackets and the marker left out. |
757 | 647 |
* @param nonViralName |
... | ... | |
779 | 669 |
List<TaggedText> result = getSpeciesTaggedNameCache(nonViralName); |
780 | 670 |
return result; |
781 | 671 |
} |
782 |
|
|
783 |
|
|
672 |
|
|
673 |
|
|
784 | 674 |
List<TaggedText> tags = getGenusAndSpeciesTaggedPart(nonViralName); |
785 | 675 |
|
786 | 676 |
addSpeciesAggregateTaggedEpithet(tags, nonViralName); |
... | ... | |
922 | 812 |
String originalNameString; |
923 | 813 |
TaxonNameBase<?,?> originalName = nameRel.getFromName(); |
924 | 814 |
if (!originalName.isInstanceOf(NonViralName.class)){ |
925 |
originalNameString = originalName.getTitleCache();
|
|
815 |
originalNameString = originalName.getTitleCache(); |
|
926 | 816 |
}else{ |
927 | 817 |
NonViralName<?> originalNvName = CdmBase.deproxy(originalName, NonViralName.class); |
928 |
originalNameString = makeOriginalNameString(currentName, originalNvName, originalNameTaggs);
|
|
818 |
originalNameString = makeOriginalNameString(currentName, originalNvName, originalNameTaggs); |
|
929 | 819 |
} |
930 | 820 |
originalNameStrings.add("'" + originalNameString +"'"); |
931 | 821 |
} |
... | ... | |
962 | 852 |
originalNameString = originalName.getFullTitleCache(); |
963 | 853 |
} |
964 | 854 |
String[] originalNameSplit = originalNameString.split("\\s+"); |
965 |
|
|
855 |
|
|
966 | 856 |
//get current name parts |
967 | 857 |
String currentNameString = createString(currentNameTags); |
968 | 858 |
String[] currentNameSplit = currentNameString.split("\\s+"); |
969 |
|
|
859 |
|
|
970 | 860 |
//compute string |
971 | 861 |
String result = originalNameString; |
972 | 862 |
for (int i = 0; i < Math.min(originalNameSplit.length, currentNameSplit.length); i++){ |
... | ... | |
976 | 866 |
} |
977 | 867 |
//old |
978 | 868 |
// if (originalName.getGenusOrUninomial() != null && originalName.getGenusOrUninomial().equals(currentName.getGenusOrUninomial())){ |
979 |
//
|
|
869 |
// |
|
980 | 870 |
// } |
981 | 871 |
return result; |
982 | 872 |
} |
... | ... | |
997 | 887 |
} |
998 | 888 |
|
999 | 889 |
|
890 |
/** |
|
891 |
* @param tags |
|
892 |
* @return |
|
893 |
*/ |
|
894 |
private String createString(List<TaggedText> tags) { |
|
895 |
return TaggedCacheHelper.createString(tags); |
|
896 |
} |
|
897 |
|
|
898 |
/** |
|
899 |
* @param tags |
|
900 |
* @param htmlTagRules |
|
901 |
* @return |
|
902 |
*/ |
|
903 |
private String createString(List<TaggedText> tags, HTMLTagRules htmlTagRules) { |
|
904 |
return TaggedCacheHelper.createString(tags, htmlTagRules); |
|
905 |
} |
|
906 |
|
|
907 |
|
|
908 |
|
|
1000 | 909 |
} |
cdmlib-model/src/main/java/eu/etaxonomy/cdm/strategy/cache/taxon/ITaxonCacheStrategy.java | ||
---|---|---|
1 |
/** |
|
2 |
* Copyright (C) 2007 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 |
package eu.etaxonomy.cdm.strategy.cache.taxon; |
|
10 |
|
|
11 |
import java.util.List; |
|
12 |
|
|
13 |
import eu.etaxonomy.cdm.model.taxon.TaxonBase; |
|
14 |
import eu.etaxonomy.cdm.strategy.cache.HTMLTagRules; |
|
15 |
import eu.etaxonomy.cdm.strategy.cache.TaggedText; |
|
16 |
import eu.etaxonomy.cdm.strategy.cache.common.IIdentifiableEntityCacheStrategy; |
|
17 |
|
|
18 |
/** |
|
19 |
* A name cache rendering strategy for all TaxonNameBase subclasses. |
|
20 |
* Different TaxonNameBase subclasses could have different strategies. |
|
21 |
* |
|
22 |
* @author a.mueller |
|
23 |
* |
|
24 |
* @param <T> The concrete TaxonName class this strategy applies for |
|
25 |
*/ |
|
26 |
public interface ITaxonCacheStrategy<T extends TaxonBase> extends IIdentifiableEntityCacheStrategy<T> { |
|
27 |
|
|
28 |
/** |
|
29 |
* Returns a list of name typified tokens that together make up the name (including authorship etc.). |
|
30 |
* A token (taggedText) is a string and a type which indicates which part of a name the text |
|
31 |
* belongs to. Types may be name (indicating a core part of the name, e.g. a name epithet), |
|
32 |
* author (indicating an authorship part), rank, reference, etc.). |
|
33 |
* <BR> |
|
34 |
* Example: ["Abies"/name,"alba"/name,Rank.SUBSPECIES/rank,"alpina"/name, |
|
35 |
* "Greuther (L.)"/authorship] |
|
36 |
* |
|
37 |
* @param taxonNameBase |
|
38 |
* @return the tagged list, <code>null</code> if taxonName is <code>null</code> |
|
39 |
*/ |
|
40 |
public List<TaggedText> getTaggedTitle(T taxonBase); |
|
41 |
|
|
42 |
|
|
43 |
/** |
|
44 |
* Returns the title cache tagged by html tags according to tag rules. |
|
45 |
* @param nonViralName |
|
46 |
* @param htmlTagRules |
|
47 |
* @return |
|
48 |
*/ |
|
49 |
public String getTitleCache(T taxonBase, HTMLTagRules htmlTagRules); |
|
50 |
|
|
51 |
} |
cdmlib-model/src/main/java/eu/etaxonomy/cdm/strategy/cache/taxon/TaxonBaseDefaultCacheStrategy.java | ||
---|---|---|
9 | 9 |
|
10 | 10 |
package eu.etaxonomy.cdm.strategy.cache.taxon; |
11 | 11 |
|
12 |
import java.util.ArrayList; |
|
13 |
import java.util.List; |
|
12 | 14 |
import java.util.UUID; |
13 | 15 |
|
14 | 16 |
import org.apache.commons.lang.StringUtils; |
... | ... | |
19 | 21 |
import eu.etaxonomy.cdm.model.reference.Reference; |
20 | 22 |
import eu.etaxonomy.cdm.model.taxon.TaxonBase; |
21 | 23 |
import eu.etaxonomy.cdm.strategy.StrategyBase; |
22 |
import eu.etaxonomy.cdm.strategy.cache.common.IIdentifiableEntityCacheStrategy; |
|
24 |
import eu.etaxonomy.cdm.strategy.cache.HTMLTagRules; |
|
25 |
import eu.etaxonomy.cdm.strategy.cache.TagEnum; |
|
26 |
import eu.etaxonomy.cdm.strategy.cache.TaggedCacheHelper; |
|
27 |
import eu.etaxonomy.cdm.strategy.cache.TaggedText; |
|
28 |
import eu.etaxonomy.cdm.strategy.cache.name.INameCacheStrategy; |
|
29 |
|
|
30 |
public class TaxonBaseDefaultCacheStrategy<T extends TaxonBase> |
|
31 |
extends StrategyBase |
|
32 |
implements ITaxonCacheStrategy<T> { |
|
23 | 33 |
|
24 |
public class TaxonBaseDefaultCacheStrategy<T extends TaxonBase> extends StrategyBase implements |
|
25 |
IIdentifiableEntityCacheStrategy<T> { |
|
26 | 34 |
private static final long serialVersionUID = 5769890979070021350L; |
27 | 35 |
final static UUID uuid = UUID.fromString("931e48f0-2033-11de-8c30-0800200c9a66"); |
28 | 36 |
|
... | ... | |
31 | 39 |
return uuid; |
32 | 40 |
} |
33 | 41 |
|
34 |
@Override |
|
35 |
public String getTitleCache(T taxonBase) { |
|
36 |
String title; |
|
37 |
if (taxonBase.isProtectedTitleCache()){ |
|
38 |
return taxonBase.getTitleCache(); |
|
39 |
}else if (taxonBase.getName() != null && taxonBase.getName().getTitleCache() != null){ |
|
40 |
String namePart = getNamePart(taxonBase); |
|
41 |
|
|
42 |
title = namePart + " sec. "; |
|
43 |
title += getSecundumPart(taxonBase); |
|
44 |
}else{ |
|
45 |
title = taxonBase.toString(); |
|
46 |
} |
|
47 |
if (taxonBase.isDoubtful()){ |
|
48 |
title = "?" + title; |
|
49 |
} |
|
50 |
return title; |
|
51 |
} |
|
42 |
@Override |
|
43 |
public String getTitleCache(T taxonBase) { |
|
44 |
return getTitleCache(taxonBase, null); |
|
45 |
} |
|
52 | 46 |
|
53 |
/** |
|
54 |
* @param taxonBase |
|
55 |
* @param title |
|
56 |
* @return |
|
57 |
*/ |
|
58 |
private String getSecundumPart(T taxonBase) { |
|
59 |
String result; |
|
60 |
Reference<?> sec = taxonBase.getSec(); |
|
61 |
if (sec != null){ |
|
62 |
if (sec.getCacheStrategy() != null && |
|
63 |
sec.getAuthorship() != null && |
|
64 |
isNotBlank(sec.getAuthorship().getTitleCache()) && |
|
65 |
isNotBlank(sec.getYear())){ |
|
66 |
result = sec.getCacheStrategy().getCitation(sec); |
|
67 |
// sec.getAuthorTeam().getTitleCache() + sec.getYear(); |
|
68 |
}else{ |
|
69 |
result = taxonBase.getSec().getTitleCache(); |
|
70 |
} |
|
71 |
}else{ |
|
72 |
result = "???"; |
|
73 |
} |
|
74 |
return result; |
|
75 |
} |
|
47 |
|
|
48 |
// @Override |
|
49 |
// public String getTitleCache(T taxonBase) { |
|
50 |
// String title; |
|
51 |
// if (taxonBase.isProtectedTitleCache()){ |
|
52 |
// return taxonBase.getTitleCache(); |
|
53 |
// }else if (taxonBase.getName() != null && taxonBase.getName().getTitleCache() != null){ |
|
54 |
// String namePart = getNamePart(taxonBase); |
|
55 |
// |
|
56 |
// title = namePart + " sec. "; |
|
57 |
// title += getSecundumPart(taxonBase); |
|
58 |
// }else{ |
|
59 |
// title = taxonBase.toString(); |
|
60 |
// } |
|
61 |
// if (taxonBase.isDoubtful()){ |
|
62 |
// title = "?" + title; |
|
63 |
// } |
|
64 |
// return title; |
|
65 |
// } |
|
66 |
|
|
67 |
// /** |
|
68 |
// * @param taxonBase |
|
69 |
// * @param title |
|
70 |
// * @return |
|
71 |
// */ |
|
72 |
// private String getSecundumPart(T taxonBase) { |
|
73 |
// String result; |
|
74 |
// Reference<?> sec = taxonBase.getSec(); |
|
75 |
// if (sec != null){ |
|
76 |
// if (sec.getCacheStrategy() != null && |
|
77 |
// sec.getAuthorship() != null && |
|
78 |
// isNotBlank(sec.getAuthorship().getTitleCache()) && |
|
79 |
// isNotBlank(sec.getYear())){ |
|
80 |
// result = sec.getCacheStrategy().getCitation(sec); |
|
81 |
//// sec.getAuthorTeam().getTitleCache() + sec.getYear(); |
|
82 |
// }else{ |
|
83 |
// result = taxonBase.getSec().getTitleCache(); |
|
84 |
// } |
|
85 |
// }else{ |
|
86 |
// result = "???"; |
|
87 |
// } |
|
88 |
// return result; |
|
89 |
// } |
|
76 | 90 |
|
77 | 91 |
/** |
78 | 92 |
* @param name |
... | ... | |
91 | 105 |
return result; |
92 | 106 |
} |
93 | 107 |
|
108 |
@Override |
|
109 |
public List<TaggedText> getTaggedTitle(T taxonBase) { |
|
110 |
if (taxonBase == null){ |
|
111 |
return null; |
|
112 |
} |
|
113 |
|
|
114 |
List<TaggedText> tags = new ArrayList<TaggedText>(); |
|
115 |
|
|
116 |
if (taxonBase.isDoubtful()){ |
|
117 |
tags.add(new TaggedText(TagEnum.separator, "?")); |
|
118 |
} |
|
119 |
if (taxonBase.isProtectedTitleCache()){ |
|
120 |
//protected title cache |
|
121 |
tags.add(new TaggedText(TagEnum.name, taxonBase.getTitleCache())); |
|
122 |
}else{ |
|
123 |
//name |
|
124 |
List<TaggedText> nameTags = getNameTags(taxonBase); |
|
125 |
|
|
126 |
if (nameTags.size() > 0){ |
|
127 |
tags.addAll(nameTags); |
|
128 |
|
|
129 |
//sec. |
|
130 |
tags.add(new TaggedText(TagEnum.separator, " sec. ")); |
|
131 |
|
|
132 |
//ref. |
|
133 |
List<TaggedText> secTags = getSecundumTags(taxonBase); |
|
134 |
tags.addAll(secTags); |
|
135 |
}else{ |
|
136 |
tags.add(new TaggedText(TagEnum.fullName, taxonBase.toString())); |
|
137 |
} |
|
138 |
} |
|
139 |
return tags; |
|
140 |
} |
|
141 |
|
|
142 |
private List<TaggedText> getSecundumTags(T taxonBase) { |
|
143 |
List<TaggedText> tags = new ArrayList<TaggedText>(); |
|
144 |
|
|
145 |
Reference<?> ref = taxonBase.getSec(); |
|
146 |
ref = HibernateProxyHelper.deproxy(ref, Reference.class); |
|
147 |
if (ref != null){ |
|
148 |
if (ref.getCacheStrategy() != null && |
|
149 |
ref.getAuthorship() != null && |
|
150 |
isNotBlank(ref.getAuthorship().getTitleCache()) && |
|
151 |
isNotBlank(ref.getYear())){ |
|
152 |
String citation = ref.getCacheStrategy().getCitation(ref); |
|
153 |
// sec.getAuthorTeam().getTitleCache() + sec.getYear(); |
|
154 |
tags.add(new TaggedText(TagEnum.reference, citation)); |
|
155 |
}else{ |
|
156 |
tags.add(new TaggedText(TagEnum.reference, ref.getTitleCache())); |
|
157 |
} |
|
158 |
}else{ |
|
159 |
tags.add(new TaggedText(TagEnum.reference, "???")); |
|
160 |
} |
|
161 |
return tags; |
|
162 |
} |
|
163 |
|
|
164 |
private List<TaggedText> getNameTags(T taxonBase) { |
|
165 |
List<TaggedText> tags = new ArrayList<TaggedText>(); |
|
166 |
TaxonNameBase<?,INameCacheStrategy<TaxonNameBase>> name = taxonBase.getName(); |
|
167 |
if (name != null){ |
|
168 |
if (taxonBase.isUseNameCache() && name.isInstanceOf(NonViralName.class)){ |
|
169 |
NonViralName<?> nvn = HibernateProxyHelper.deproxy(name, NonViralName.class); |
|
170 |
List<TaggedText> nameCacheTags = nvn.getCacheStrategy().getTaggedName(nvn); |
|
171 |
tags.addAll(nameCacheTags); |
|
172 |
}else{ |
|
173 |
List<TaggedText> nameTags = name.getTaggedName(); |
|
174 |
tags.addAll(nameTags); |
|
175 |
} |
|
176 |
if (StringUtils.isNotBlank(taxonBase.getAppendedPhrase())){ |
|
177 |
tags.add(new TaggedText(TagEnum.appendedPhrase, taxonBase.getAppendedPhrase().trim())); |
|
178 |
} |
|
179 |
} |
|
180 |
return tags; |
|
181 |
} |
|
182 |
|
|
183 |
@Override |
|
184 |
public String getTitleCache(T taxonBase, HTMLTagRules htmlTagRules) { |
|
185 |
List<TaggedText> tags = getTaggedTitle(taxonBase); |
|
186 |
if (tags == null){ |
|
187 |
return null; |
|
188 |
}else{ |
|
189 |
String result = TaggedCacheHelper.createString(tags, htmlTagRules); |
|
190 |
return result; |
|
191 |
} |
|
192 |
} |
|
193 |
|
|
194 |
|
|
195 |
|
|
94 | 196 |
} |
cdmlib-model/src/main/java/eu/etaxonomy/cdm/strategy/cache/taxon/TaxonBaseShortSecCacheStrategy.java | ||
---|---|---|
1 |
package eu.etaxonomy.cdm.strategy.cache.taxon; |
|
2 |
|
|
3 |
|
|
4 |
/** |
|
5 |
* Copyright (C) 2015 EDIT |
|
6 |
* European Distributed Institute of Taxonomy |
|
7 |
* http://www.e-taxonomy.eu |
|
8 |
* |
|
9 |
* The contents of this file are subject to the Mozilla Public License Version 1.1 |
|
10 |
* See LICENSE.TXT at the top of this package for the full license terms. |
|
11 |
*/ |
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
import java.util.UUID; |
|
16 |
|
|
17 |
import org.apache.commons.lang.StringUtils; |
|
18 |
|
|
19 |
import eu.etaxonomy.cdm.hibernate.HibernateProxyHelper; |
|
20 |
import eu.etaxonomy.cdm.model.agent.Person; |
|
21 |
import eu.etaxonomy.cdm.model.agent.Team; |
|
22 |
import eu.etaxonomy.cdm.model.name.NonViralName; |
|
23 |
import eu.etaxonomy.cdm.model.name.TaxonNameBase; |
|
24 |
import eu.etaxonomy.cdm.model.reference.Reference; |
|
25 |
import eu.etaxonomy.cdm.model.taxon.TaxonBase; |
|
26 |
import eu.etaxonomy.cdm.strategy.StrategyBase; |
|
27 |
import eu.etaxonomy.cdm.strategy.cache.common.IIdentifiableEntityCacheStrategy; |
|
28 |
|
|
29 |
public class TaxonBaseShortSecCacheStrategy<T extends TaxonBase> extends StrategyBase implements |
|
30 |
IIdentifiableEntityCacheStrategy<T> { |
|
31 |
|
|
32 |
final static UUID uuid = UUID.fromString("931e48f0-2033-11de-8c30-0800200c9a66"); |
|
33 |
|
|
34 |
@Override |
|
35 |
protected UUID getUuid() { |
|
36 |
return uuid; |
|
37 |
} |
|
38 |
|
|
39 |
public String getTitleCache(T taxonBase) { |
|
40 |
String title; |
|
41 |
if (taxonBase.getName() != null && taxonBase.getName().getTitleCache() != null){ |
|
42 |
String namePart = getNamePart(taxonBase); |
|
43 |
|
|
44 |
title = namePart + " sec. "; |
|
45 |
title += getSecundumPart(taxonBase); |
|
46 |
}else{ |
|
47 |
title = taxonBase.toString(); |
|
48 |
} |
|
49 |
if (taxonBase.isDoubtful()){ |
|
50 |
title = "?" + title; |
|
51 |
} |
|
52 |
return title; |
|
53 |
} |
|
54 |
|
|
55 |
/** |
|
56 |
* @param taxonBase |
|
57 |
* @param title |
|
58 |
* @return |
|
59 |
*/ |
|
60 |
private String getSecundumPart(T taxonBase) { |
|
61 |
String result = "???"; |
|
62 |
Reference<?> sec = taxonBase.getSec(); |
|
63 |
sec = HibernateProxyHelper.deproxy(sec, Reference.class); |
|
64 |
if (sec != null){ |
|
65 |
if (sec.isProtectedTitleCache()){ |
|
66 |
return sec.getTitleCache(); |
|
67 |
} |
|
68 |
if (sec.getAuthorship() != null){ |
|
69 |
|
|
70 |
if (sec.getAuthorship().isInstanceOf(Team.class)){ |
|
71 |
Team authorTeam = HibernateProxyHelper.deproxy(sec.getAuthorship(), Team.class); |
|
72 |
if (authorTeam.getTeamMembers().size() > 2){ |
|
73 |
if (authorTeam.getTeamMembers().get(0).getLastname() != null){ |
|
74 |
result = authorTeam.getTeamMembers().get(0).getLastname() + " & al."; |
|
75 |
} else { |
|
76 |
result = authorTeam.getTeamMembers().get(0).getTitleCache(); |
|
77 |
result = result + " & al."; |
|
78 |
} |
|
79 |
} else if (authorTeam.getTeamMembers().size() == 2){ |
|
80 |
String firstAuthor; |
|
81 |
if (authorTeam.getTeamMembers().get(0).getLastname() != null){ |
|
82 |
firstAuthor = authorTeam.getTeamMembers().get(0).getLastname(); |
|
83 |
}else{ |
|
84 |
firstAuthor = authorTeam.getTeamMembers().get(0).getTitleCache(); |
|
85 |
} |
|
86 |
String secondAuthor; |
|
87 |
if (authorTeam.getTeamMembers().get(1).getLastname() != null){ |
|
88 |
secondAuthor = authorTeam.getTeamMembers().get(1).getLastname(); |
|
89 |
}else{ |
|
90 |
secondAuthor = authorTeam.getTeamMembers().get(1).getTitleCache(); |
|
91 |
} |
|
92 |
result = firstAuthor + " & " + secondAuthor; |
|
93 |
|
|
94 |
} else{ |
|
95 |
if (authorTeam.getTeamMembers().get(0).getLastname() != null){ |
|
96 |
result = authorTeam.getTeamMembers().get(0).getLastname(); |
|
97 |
} else { |
|
98 |
result = authorTeam.getTeamMembers().get(0).getTitleCache(); |
|
99 |
} |
|
100 |
} |
|
101 |
|
|
102 |
} else { |
|
103 |
Person author = HibernateProxyHelper.deproxy(sec.getAuthorship(), Person.class); |
|
104 |
if (author.getLastname() != null){ |
|
105 |
result = author.getLastname(); |
|
106 |
} else{ |
|
107 |
result = author.getTitleCache(); |
|
108 |
} |
|
109 |
} |
|
110 |
if (result != null){ |
|
111 |
result = result.replaceAll("[A-Z]\\.", ""); |
|
112 |
} |
|
113 |
if (sec.getYear() != null && result != null){ |
|
114 |
result = result.concat(" (" + sec.getYear()+")"); |
|
115 |
} |
|
116 |
}else{ |
|
117 |
result = taxonBase.getSec().getTitleCache(); |
|
118 |
} |
|
119 |
} |
|
120 |
return result; |
|
121 |
} |
|
122 |
|
|
123 |
/** |
|
124 |
* @param name |
|
125 |
*/ |
|
126 |
private String getNamePart(TaxonBase<?> taxonBase) { |
|
127 |
TaxonNameBase<?,?> nameBase = taxonBase.getName(); |
|
128 |
String result = nameBase.getTitleCache(); |
|
129 |
//use name cache instead of title cache if required |
|
130 |
if (taxonBase.isUseNameCache() && nameBase.isInstanceOf(NonViralName.class)){ |
|
131 |
NonViralName<?> nvn = HibernateProxyHelper.deproxy(nameBase, NonViralName.class); |
|
132 |
result = nvn.getNameCache(); |
|
133 |
} |
|
134 |
if (StringUtils.isNotBlank(taxonBase.getAppendedPhrase())){ |
|
135 |
result = result.trim() + " " + taxonBase.getAppendedPhrase().trim(); |
|
136 |
} |
|
137 |
return result; |
|
138 |
} |
|
139 |
|
|
140 |
} |
|
141 |
|
|
142 |
|
|
1 |
package eu.etaxonomy.cdm.strategy.cache.taxon; |
|
2 |
|
|
3 |
|
|
4 |
/** |
|
5 |
* Copyright (C) 2015 EDIT |
|
6 |
* European Distributed Institute of Taxonomy |
|
7 |
* http://www.e-taxonomy.eu |
|
8 |
* |
|
9 |
* The contents of this file are subject to the Mozilla Public License Version 1.1 |
|
10 |
* See LICENSE.TXT at the top of this package for the full license terms. |
|
11 |
*/ |
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
import java.util.ArrayList; |
|
16 |
import java.util.List; |
|
17 |
import java.util.UUID; |
|
18 |
|
|
19 |
import org.apache.commons.lang.StringUtils; |
|
20 |
|
|
21 |
import eu.etaxonomy.cdm.hibernate.HibernateProxyHelper; |
|
22 |
import eu.etaxonomy.cdm.model.agent.Person; |
|
23 |
import eu.etaxonomy.cdm.model.agent.Team; |
|
24 |
import eu.etaxonomy.cdm.model.name.NonViralName; |
|
25 |
import eu.etaxonomy.cdm.model.name.TaxonNameBase; |
|
26 |
import eu.etaxonomy.cdm.model.reference.Reference; |
|
27 |
import eu.etaxonomy.cdm.model.taxon.TaxonBase; |
|
28 |
import eu.etaxonomy.cdm.strategy.StrategyBase; |
|
29 |
import eu.etaxonomy.cdm.strategy.cache.HTMLTagRules; |
|
30 |
import eu.etaxonomy.cdm.strategy.cache.TagEnum; |
|
31 |
import eu.etaxonomy.cdm.strategy.cache.TaggedCacheHelper; |
|
32 |
import eu.etaxonomy.cdm.strategy.cache.TaggedText; |
|
33 |
import eu.etaxonomy.cdm.strategy.cache.name.INameCacheStrategy; |
|
34 |
|
|
35 |
public class TaxonBaseShortSecCacheStrategy<T extends TaxonBase> |
|
36 |
extends StrategyBase |
|
37 |
implements ITaxonCacheStrategy<T> { |
|
38 |
|
|
39 |
final static UUID uuid = UUID.fromString("931e48f0-2033-11de-8c30-0800200c9a66"); |
|
40 |
|
|
41 |
@Override |
|
42 |
protected UUID getUuid() { |
|
43 |
return uuid; |
|
44 |
} |
|
45 |
|
|
46 |
// @Override |
|
47 |
// public String getTitleCache(T taxonBase) { |
|
48 |
// return getTitleCache(taxonBase, null); |
|
49 |
// } |
|
50 |
|
|
51 |
@Override |
|
52 |
public String getTitleCache(T taxonBase) { |
|
53 |
String title; |
|
54 |
if (taxonBase.getName() != null && taxonBase.getName().getTitleCache() != null){ |
|
55 |
String namePart = getNamePart(taxonBase); |
|
56 |
|
|
57 |
title = namePart + " sec. "; |
|
58 |
title += getSecundumPart(taxonBase); |
|
59 |
}else{ |
|
60 |
title = taxonBase.toString(); |
|
61 |
} |
|
62 |
if (taxonBase.isDoubtful()){ |
|
63 |
title = "?" + title; |
|
64 |
} |
|
65 |
return title; |
|
66 |
} |
|
67 |
|
|
68 |
/** |
|
69 |
* @param taxonBase |
|
70 |
* @param title |
|
71 |
* @return |
|
72 |
*/ |
|
73 |
private String getSecundumPart(T taxonBase) { |
|
74 |
String result = "???"; |
|
75 |
Reference<?> sec = taxonBase.getSec(); |
|
76 |
sec = HibernateProxyHelper.deproxy(sec, Reference.class); |
|
77 |
if (sec != null){ |
|
78 |
if (sec.isProtectedTitleCache()){ |
|
79 |
return sec.getTitleCache(); |
|
80 |
} |
|
81 |
if (sec.getAuthorship() != null){ |
|
82 |
|
|
83 |
if (sec.getAuthorship().isInstanceOf(Team.class)){ |
|
84 |
Team authorTeam = HibernateProxyHelper.deproxy(sec.getAuthorship(), Team.class); |
|
85 |
if (authorTeam.getTeamMembers().size() > 2){ |
|
86 |
if (authorTeam.getTeamMembers().get(0).getLastname() != null){ |
|
87 |
result = authorTeam.getTeamMembers().get(0).getLastname() + " & al."; |
|
88 |
} else { |
|
89 |
result = authorTeam.getTeamMembers().get(0).getTitleCache(); |
|
90 |
result = result + " & al."; |
|
91 |
} |
|
92 |
} else if (authorTeam.getTeamMembers().size() == 2){ |
|
93 |
String firstAuthor; |
|
94 |
if (authorTeam.getTeamMembers().get(0).getLastname() != null){ |
|
95 |
firstAuthor = authorTeam.getTeamMembers().get(0).getLastname(); |
|
96 |
}else{ |
|
97 |
firstAuthor = authorTeam.getTeamMembers().get(0).getTitleCache(); |
|
98 |
} |
|
99 |
String secondAuthor; |
|
100 |
if (authorTeam.getTeamMembers().get(1).getLastname() != null){ |
|
101 |
secondAuthor = authorTeam.getTeamMembers().get(1).getLastname(); |
|
102 |
}else{ |
|
103 |
secondAuthor = authorTeam.getTeamMembers().get(1).getTitleCache(); |
|
104 |
} |
|
105 |
result = firstAuthor + " & " + secondAuthor; |
|
106 |
|
|
107 |
} else{ |
|
108 |
if (authorTeam.getTeamMembers().get(0).getLastname() != null){ |
|
109 |
result = authorTeam.getTeamMembers().get(0).getLastname(); |
|
110 |
} else { |
|
111 |
result = authorTeam.getTeamMembers().get(0).getTitleCache(); |
|
112 |
} |
|
113 |
} |
|
114 |
|
|
115 |
} else { |
|
116 |
Person author = HibernateProxyHelper.deproxy(sec.getAuthorship(), Person.class); |
|
117 |
if (author.getLastname() != null){ |
|
118 |
result = author.getLastname(); |
|
119 |
} else{ |
|
120 |
result = author.getTitleCache(); |
|
121 |
} |
|
122 |
} |
|
123 |
if (result != null){ |
|
124 |
result = result.replaceAll("[A-Z]\\.", ""); |
|
125 |
} |
|
126 |
if (sec.getYear() != null && result != null){ |
|
127 |
result = result.concat(" (" + sec.getYear()+")"); |
|
128 |
} |
|
129 |
}else{ |
|
130 |
result = taxonBase.getSec().getTitleCache(); |
|
131 |
} |
|
132 |
} |
|
133 |
return result; |
|
134 |
} |
|
135 |
|
|
136 |
/** |
|
137 |
* @param name |
|
138 |
*/ |
|
139 |
private String getNamePart(TaxonBase<?> taxonBase) { |
|
140 |
TaxonNameBase<?,?> nameBase = taxonBase.getName(); |
|
141 |
String result = nameBase.getTitleCache(); |
|
142 |
//use name cache instead of title cache if required |
|
143 |
if (taxonBase.isUseNameCache() && nameBase.isInstanceOf(NonViralName.class)){ |
|
144 |
NonViralName<?> nvn = HibernateProxyHelper.deproxy(nameBase, NonViralName.class); |
|
145 |
result = nvn.getNameCache(); |
|
146 |
} |
|
147 |
if (StringUtils.isNotBlank(taxonBase.getAppendedPhrase())){ |
|
148 |
result = result.trim() + " " + taxonBase.getAppendedPhrase().trim(); |
|
149 |
} |
|
150 |
return result; |
|
151 |
} |
|
152 |
|
|
153 |
@Override |
|
154 |
public List<TaggedText> getTaggedTitle(T taxonBase) { |
|
155 |
if (taxonBase == null){ |
|
156 |
return null; |
|
157 |
} |
|
158 |
|
|
159 |
List<TaggedText> tags = new ArrayList<TaggedText>(); |
|
160 |
|
|
161 |
if (taxonBase.isProtectedTitleCache()){ |
|
162 |
//protected title cache |
|
163 |
tags.add(new TaggedText(TagEnum.name, taxonBase.getTitleCache())); |
|
164 |
return tags; |
|
165 |
}else{ |
|
166 |
//name |
|
167 |
TaxonNameBase<?,INameCacheStrategy<TaxonNameBase>> name = taxonBase.getName(); |
|
168 |
if (name != null){ |
|
169 |
//TODO |
|
170 |
List<TaggedText> nameTags = name.getCacheStrategy().getTaggedTitle(name); |
|
171 |
tags.addAll(nameTags); |
|
172 |
} |
|
173 |
|
|
174 |
//sec. |
|
175 |
tags.add(new TaggedText(TagEnum.separator, "sec.")); |
|
176 |
|
|
177 |
//ref. |
|
178 |
Reference<?> ref = taxonBase.getSec(); |
|
179 |
ref = HibernateProxyHelper.deproxy(ref, Reference.class); |
|
180 |
if (ref != null){ |
|
181 |
List<TaggedText> secTags = getSecReferenceTags(ref); |
|
182 |
tags.addAll(secTags); |
|
183 |
}else{ |
|
184 |
tags.add(new TaggedText(TagEnum.reference, "???")); |
|
185 |
} |
|
186 |
} |
|
187 |
return tags; |
|
188 |
} |
|
189 |
|
|
190 |
/** |
|
191 |
* @param ref |
|
192 |
*/ |
|
193 |
private List<TaggedText> getSecReferenceTags(Reference<?> sec) { |
|
194 |
List<TaggedText> tags = new ArrayList<TaggedText>(); |
|
195 |
|
|
196 |
if (sec.isProtectedTitleCache()){ |
|
197 |
tags.add(new TaggedText(TagEnum.reference, sec.getTitleCache())); |
|
198 |
}else{ |
|
199 |
if (sec.getAuthorship() != null){ |
|
200 |
List<TaggedText> authorTags; |
|
201 |
if (sec.getAuthorship().isInstanceOf(Team.class)){ |
|
202 |
authorTags = handleTeam(sec); |
|
203 |
} else { |
|
204 |
authorTags = handlePerson(sec); |
|
205 |
} |
|
206 |
tags.addAll(authorTags); |
Also available in: Unified diff
Implement taggedTitle for taxon base #5229