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.old;
|
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.IJournal;
|
18
|
import eu.etaxonomy.cdm.model.reference.Reference;
|
19
|
import eu.etaxonomy.cdm.strategy.cache.reference.NewDefaultReferenceCacheStrategy;
|
20
|
|
21
|
public class ArticleDefaultCacheStrategy extends NomRefDefaultCacheStrategyBase {
|
22
|
private static final long serialVersionUID = -1639068590864589314L;
|
23
|
|
24
|
@SuppressWarnings("unused")
|
25
|
private static final Logger logger = Logger.getLogger(ArticleDefaultCacheStrategy.class);
|
26
|
|
27
|
// public static final String UNDEFINED_JOURNAL = "- undefined journal -";
|
28
|
private String prefixReferenceJounal = "in";
|
29
|
private String blank = " ";
|
30
|
private String comma = ",";
|
31
|
private String prefixSeries = "ser.";
|
32
|
|
33
|
|
34
|
final static UUID uuid = UUID.fromString("0d45343a-0c8a-4a64-97ca-e94974b65c96");
|
35
|
|
36
|
@Override
|
37
|
protected UUID getUuid() {
|
38
|
return uuid;
|
39
|
}
|
40
|
|
41
|
|
42
|
/**
|
43
|
* Factory method
|
44
|
* @return
|
45
|
*/
|
46
|
public static ArticleDefaultCacheStrategy NewInstance(){
|
47
|
return new ArticleDefaultCacheStrategy();
|
48
|
}
|
49
|
|
50
|
/**
|
51
|
* Constructor
|
52
|
*/
|
53
|
private ArticleDefaultCacheStrategy(){
|
54
|
super();
|
55
|
}
|
56
|
|
57
|
@Override
|
58
|
public String getTitleCache(Reference article) {
|
59
|
if (article.isProtectedTitleCache()){
|
60
|
return article.getTitleCache();
|
61
|
}
|
62
|
String result = getTitleWithoutYearAndAuthor(article, false);
|
63
|
result = addYear(result, article, false);
|
64
|
TeamOrPersonBase<?> team = article.getAuthorship();
|
65
|
result = CdmUtils.concat(" ", article.getTitle(), result);
|
66
|
if (team != null && isNotBlank(team.getTitleCache())){
|
67
|
String authorSeparator = isNotBlank(article.getTitle())? afterAuthor : " ";
|
68
|
result = team.getTitleCache() + authorSeparator + result;
|
69
|
}
|
70
|
return result;
|
71
|
}
|
72
|
|
73
|
@Override
|
74
|
public String getFullAbbrevTitleString(Reference article) {
|
75
|
if (article.isProtectedAbbrevTitleCache()){
|
76
|
return article.getAbbrevTitleCache();
|
77
|
}
|
78
|
String result = getTitleWithoutYearAndAuthor(article, true);
|
79
|
result = addYear(result, article, false);
|
80
|
TeamOrPersonBase<?> team = article.getAuthorship();
|
81
|
String articleTitle = CdmUtils.getPreferredNonEmptyString(article.getAbbrevTitle(), article.getTitle(), false, true);
|
82
|
result = CdmUtils.concat(" ", articleTitle, result); //Article should maybe left out for nomenclatural references (?)
|
83
|
if (team != null && isNotBlank(team.getNomenclaturalTitle())){
|
84
|
String authorSeparator = isNotBlank(articleTitle) ? afterAuthor : " ";
|
85
|
result = team.getNomenclaturalTitle() + authorSeparator + result;
|
86
|
}
|
87
|
return result;
|
88
|
}
|
89
|
|
90
|
@Override
|
91
|
protected String getTitleWithoutYearAndAuthor(Reference article, boolean isAbbrev){
|
92
|
if (article == null){
|
93
|
return null;
|
94
|
}
|
95
|
IJournal journal = article.getInReference();
|
96
|
|
97
|
String journalTitel;
|
98
|
if (journal != null){
|
99
|
journalTitel = CdmUtils.getPreferredNonEmptyString(journal.getTitle(), journal.getAbbrevTitle(), isAbbrev, true);
|
100
|
}else{
|
101
|
journalTitel = NewDefaultReferenceCacheStrategy.UNDEFINED_JOURNAL;
|
102
|
}
|
103
|
|
104
|
String series = Nz(article.getSeriesPart()).trim();
|
105
|
String volume = Nz(article.getVolume()).trim();
|
106
|
|
107
|
boolean needsComma = false;
|
108
|
|
109
|
String nomRefCache = "";
|
110
|
|
111
|
//inJournal
|
112
|
nomRefCache = prefixReferenceJounal + blank;
|
113
|
|
114
|
//titelAbbrev
|
115
|
if (isNotBlank(journalTitel)){
|
116
|
nomRefCache = nomRefCache + journalTitel;
|
117
|
needsComma = makeNeedsComma(needsComma, nomRefCache, volume, series);
|
118
|
if (! needsComma){
|
119
|
nomRefCache = nomRefCache + blank;
|
120
|
}
|
121
|
}
|
122
|
|
123
|
//series and vol.
|
124
|
nomRefCache = getSeriesAndVolPart(series, volume, needsComma, nomRefCache);
|
125
|
|
126
|
//delete "."
|
127
|
while (nomRefCache.endsWith(".")){
|
128
|
nomRefCache = nomRefCache.substring(0, nomRefCache.length()-1);
|
129
|
}
|
130
|
|
131
|
return nomRefCache.trim();
|
132
|
}
|
133
|
|
134
|
private boolean makeNeedsComma(boolean needsComma, String nomRefCache, String volume, String series) {
|
135
|
if (needsComma){
|
136
|
return true;
|
137
|
}else{
|
138
|
nomRefCache = nomRefCache.toLowerCase();
|
139
|
int serIndex = nomRefCache.indexOf(" ser. ");
|
140
|
int sectIndex = nomRefCache.indexOf(" sect. ");
|
141
|
int abtIndex = nomRefCache.indexOf(" abt. ");
|
142
|
int index = Math.max(Math.max(serIndex, sectIndex), abtIndex);
|
143
|
int commaIndex = nomRefCache.indexOf(",", index);
|
144
|
if (index > -1 && commaIndex == -1 && isNotBlank(volume)){
|
145
|
return true;
|
146
|
}else if (isNotBlank(series)){
|
147
|
return true;
|
148
|
}else{
|
149
|
return false;
|
150
|
}
|
151
|
}
|
152
|
}
|
153
|
|
154
|
protected String getSeriesAndVolPart(String series, String volume,
|
155
|
boolean needsComma, String nomRefCache) {
|
156
|
//inSeries
|
157
|
String seriesPart = "";
|
158
|
if (isNotBlank(series)){
|
159
|
seriesPart = series;
|
160
|
if (CdmUtils.isNumeric(series)){
|
161
|
seriesPart = prefixSeries + blank + seriesPart;
|
162
|
}
|
163
|
// if (needsComma){
|
164
|
seriesPart = comma + blank + seriesPart;
|
165
|
// }
|
166
|
needsComma = true;
|
167
|
}
|
168
|
nomRefCache += seriesPart;
|
169
|
|
170
|
|
171
|
//volume Part
|
172
|
String volumePart = "";
|
173
|
if (!"".equals(volume)){
|
174
|
volumePart = volume;
|
175
|
if (needsComma){
|
176
|
volumePart = comma + blank + volumePart;
|
177
|
}
|
178
|
//needsComma = false;
|
179
|
}
|
180
|
nomRefCache += volumePart;
|
181
|
return nomRefCache;
|
182
|
}
|
183
|
}
|