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
|
|
10
|
package eu.etaxonomy.cdm.strategy.cache.reference;
|
11
|
|
12
|
import java.util.UUID;
|
13
|
|
14
|
import org.apache.commons.lang.StringUtils;
|
15
|
import org.apache.log4j.Logger;
|
16
|
|
17
|
import eu.etaxonomy.cdm.common.CdmUtils;
|
18
|
import eu.etaxonomy.cdm.model.agent.TeamOrPersonBase;
|
19
|
import eu.etaxonomy.cdm.model.reference.Reference;
|
20
|
import eu.etaxonomy.cdm.strategy.StrategyBase;
|
21
|
|
22
|
/**
|
23
|
* @author a.mueller
|
24
|
* @created 29.06.2008
|
25
|
*/
|
26
|
public class JournalDefaultCacheStrategy extends StrategyBase implements IReferenceBaseCacheStrategy {
|
27
|
private static final long serialVersionUID = 8495999505123620960L;
|
28
|
|
29
|
|
30
|
@SuppressWarnings("unused")
|
31
|
private static final Logger logger = Logger.getLogger(JournalDefaultCacheStrategy.class);
|
32
|
|
33
|
|
34
|
protected String beforeYear = ". ";
|
35
|
protected String afterYear = "";
|
36
|
protected String afterAuthor = ", ";
|
37
|
|
38
|
// private String blank = " ";
|
39
|
// private String comma = ",";
|
40
|
// private String dot =".";
|
41
|
|
42
|
final static UUID uuid = UUID.fromString("c84846cd-c862-462e-81b8-53cf4100ed32");
|
43
|
|
44
|
/* (non-Javadoc)
|
45
|
* @see eu.etaxonomy.cdm.strategy.StrategyBase#getUuid()
|
46
|
*/
|
47
|
@Override
|
48
|
protected UUID getUuid() {
|
49
|
return uuid;
|
50
|
}
|
51
|
|
52
|
|
53
|
/**
|
54
|
* Factory method
|
55
|
* @return
|
56
|
*/
|
57
|
public static JournalDefaultCacheStrategy NewInstance(){
|
58
|
return new JournalDefaultCacheStrategy();
|
59
|
}
|
60
|
|
61
|
/**
|
62
|
* Constructor
|
63
|
*/
|
64
|
private JournalDefaultCacheStrategy(){
|
65
|
super();
|
66
|
}
|
67
|
|
68
|
|
69
|
@Override
|
70
|
public String getTitleCache(Reference journal) {
|
71
|
return getTitleCache(journal, false);
|
72
|
|
73
|
|
74
|
}
|
75
|
|
76
|
|
77
|
@Override
|
78
|
public String getAbbrevTitleCache(Reference journal) {
|
79
|
return getTitleCache(journal, true);
|
80
|
}
|
81
|
|
82
|
|
83
|
private String getTitleCache(Reference journal, boolean isAbbrev){
|
84
|
if (journal == null){
|
85
|
return null;
|
86
|
}
|
87
|
|
88
|
String title = CdmUtils.getPreferredNonEmptyString(journal.getTitle(), journal.getAbbrevTitle(), isAbbrev, true);
|
89
|
|
90
|
String result = title;
|
91
|
|
92
|
// //delete .
|
93
|
// while (result.endsWith(".")){
|
94
|
// result = result.substring(0, result.length()-1);
|
95
|
// }
|
96
|
|
97
|
// result = addYear(result, journal);
|
98
|
|
99
|
|
100
|
TeamOrPersonBase<?> team = journal.getAuthorTeam();
|
101
|
if (team != null){
|
102
|
String author = CdmUtils.getPreferredNonEmptyString(team.getTitleCache(), team.getNomenclaturalTitle(), isAbbrev, true);
|
103
|
if (StringUtils.isNotBlank(author)){
|
104
|
result = author + afterAuthor + result;
|
105
|
}
|
106
|
}
|
107
|
return result;
|
108
|
}
|
109
|
|
110
|
|
111
|
public String getCitation(Reference referenceBase) {
|
112
|
StringBuilder stringBuilder = new StringBuilder();
|
113
|
|
114
|
TeamOrPersonBase<?> team = referenceBase.getAuthorTeam();
|
115
|
if (team != null && ! (team.getTitleCache() == null) && ! team.getTitleCache().trim().equals("")){
|
116
|
//String author = CdmUtils.Nz(team == null? "" : team.getTitleCache());
|
117
|
stringBuilder.append(team.getTitleCache() + afterAuthor);
|
118
|
}
|
119
|
|
120
|
String year = CdmUtils.Nz(referenceBase.getYear());
|
121
|
if (!"".equals(year)){
|
122
|
stringBuilder.append(beforeYear + year);
|
123
|
}
|
124
|
|
125
|
return stringBuilder.toString();
|
126
|
}
|
127
|
|
128
|
|
129
|
}
|