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.reference;
|
10
|
|
11
|
import java.util.UUID;
|
12
|
|
13
|
import org.apache.log4j.Logger;
|
14
|
|
15
|
import eu.etaxonomy.cdm.common.CdmUtils;
|
16
|
import eu.etaxonomy.cdm.model.agent.TeamOrPersonBase;
|
17
|
import eu.etaxonomy.cdm.model.reference.Reference;
|
18
|
import eu.etaxonomy.cdm.strategy.StrategyBase;
|
19
|
/**
|
20
|
* @author a.mueller
|
21
|
* @created 08-Aug-2008 22:06:45
|
22
|
*/
|
23
|
public class ReferenceDefaultCacheStrategy<T extends Reference> extends StrategyBase implements IReferenceBaseCacheStrategy<T> {
|
24
|
@SuppressWarnings("unused")
|
25
|
private static final Logger logger = Logger.getLogger(ReferenceDefaultCacheStrategy.class);
|
26
|
|
27
|
/**
|
28
|
* Constructor
|
29
|
*/
|
30
|
public ReferenceDefaultCacheStrategy(){
|
31
|
super();
|
32
|
}
|
33
|
public static ReferenceDefaultCacheStrategy NewInstance(){
|
34
|
return new ReferenceDefaultCacheStrategy();
|
35
|
}
|
36
|
|
37
|
|
38
|
|
39
|
protected String beforeYear = ". ";
|
40
|
protected String afterYear = "";
|
41
|
protected String afterAuthor = ", ";
|
42
|
|
43
|
private String blank = " ";
|
44
|
private String comma = ",";
|
45
|
private String dot =".";
|
46
|
|
47
|
final static UUID uuid = UUID.fromString("763fe4a0-c79f-4f14-9693-631680225ec3");
|
48
|
|
49
|
|
50
|
@Override
|
51
|
public String getAbbrevTitleCache(T reference) {
|
52
|
return getTitleCache(reference, true);
|
53
|
}
|
54
|
|
55
|
@Override
|
56
|
public String getTitleCache(T strictReferenceBase) {
|
57
|
return getTitleCache(strictReferenceBase, false);
|
58
|
}
|
59
|
|
60
|
private String getTitleCache(T ref, boolean isAbbrev) {
|
61
|
String result = "";
|
62
|
if (ref == null){
|
63
|
return null;
|
64
|
}
|
65
|
String titel = CdmUtils.getPreferredNonEmptyString(ref.getTitle(), ref.getAbbrevTitle(), isAbbrev, true);
|
66
|
//titelAbbrev
|
67
|
String titelAbbrevPart = "";
|
68
|
if (isNotBlank(titel)){
|
69
|
result = titel + blank;
|
70
|
}
|
71
|
//delete .
|
72
|
while (result.endsWith(".")){
|
73
|
result = result.substring(0, result.length()-1);
|
74
|
}
|
75
|
|
76
|
result = addYear(result, ref);
|
77
|
TeamOrPersonBase<?> team = ref.getAuthorTeam();
|
78
|
if (team != null){
|
79
|
String author = CdmUtils.getPreferredNonEmptyString(team.getTitleCache(), team.getNomenclaturalTitle(), isAbbrev, true);
|
80
|
if (isNotBlank(author)){
|
81
|
result = author + afterAuthor + result;
|
82
|
}
|
83
|
}
|
84
|
return result;
|
85
|
}
|
86
|
|
87
|
protected String addYear(String string, T ref){
|
88
|
String result;
|
89
|
if (string == null){
|
90
|
return null;
|
91
|
}
|
92
|
String year = CdmUtils.Nz(ref.getYear());
|
93
|
if ("".equals(year)){
|
94
|
result = string + afterYear;
|
95
|
}else{
|
96
|
result = string + beforeYear + year + afterYear;
|
97
|
}
|
98
|
return result;
|
99
|
}
|
100
|
|
101
|
public String getCitation(T referenceBase) {
|
102
|
StringBuilder stringBuilder = new StringBuilder();
|
103
|
|
104
|
TeamOrPersonBase<?> team = referenceBase.getAuthorTeam();
|
105
|
if (team != null && ! (team.getTitleCache() == null) && ! team.getTitleCache().trim().equals("")){
|
106
|
//String author = CdmUtils.Nz(team == null? "" : team.getTitleCache());
|
107
|
stringBuilder.append(team.getTitleCache() + afterAuthor);
|
108
|
}
|
109
|
|
110
|
String year = CdmUtils.Nz(referenceBase.getYear());
|
111
|
if (!"".equals(year)){
|
112
|
stringBuilder.append(beforeYear + year);
|
113
|
}
|
114
|
|
115
|
return stringBuilder.toString();
|
116
|
}
|
117
|
|
118
|
|
119
|
|
120
|
@Override
|
121
|
protected UUID getUuid() {
|
122
|
return UUID.fromString("919dbf70-33e7-11de-b418-0800200c9a66");
|
123
|
}
|
124
|
|
125
|
|
126
|
/**
|
127
|
*
|
128
|
* @param referenceTitleCache
|
129
|
* @param authorTitleCache
|
130
|
* @return
|
131
|
*/
|
132
|
public static String putAuthorToEndOfString(String referenceTitleCache, String authorTitleCache) {
|
133
|
if(authorTitleCache != null){
|
134
|
referenceTitleCache = referenceTitleCache.replace(authorTitleCache + ", ", "");
|
135
|
referenceTitleCache += " - " + authorTitleCache;
|
136
|
}
|
137
|
return referenceTitleCache;
|
138
|
}
|
139
|
|
140
|
}
|