Project

General

Profile

Download (4.55 KB) Statistics
| Branch: | Tag: | Revision:
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.commons.lang.StringUtils;
14
import org.apache.log4j.Logger;
15

    
16
import eu.etaxonomy.cdm.common.CdmUtils;
17
import eu.etaxonomy.cdm.model.agent.TeamOrPersonBase;
18
import eu.etaxonomy.cdm.model.reference.IJournal;
19
import eu.etaxonomy.cdm.model.reference.Reference;
20

    
21
public class ArticleDefaultCacheStrategy <T extends Reference> extends NomRefDefaultCacheStrategyBase<T> implements  INomenclaturalReferenceCacheStrategy<T> {
22
	@SuppressWarnings("unused")
23
	private static final Logger logger = Logger.getLogger(ArticleDefaultCacheStrategy.class);
24
	
25
	public static final String UNDEFINED_JOURNAL = "- undefined journal -";
26
	private String prefixReferenceJounal = "in";
27
	private String blank = " ";
28
	private String comma = ",";
29
	private String prefixSeries = "ser.";
30
	
31
	final static UUID uuid = UUID.fromString("0d45343a-0c8a-4a64-97ca-e94974b65c96");
32
	
33
	/* (non-Javadoc)
34
	 * @see eu.etaxonomy.cdm.strategy.StrategyBase#getUuid()
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
	
58
	
59
	@Override
60
	public String getTitleCache(T article) {
61
		if (article.isProtectedTitleCache()){
62
			return article.getTitleCache();
63
		}
64
		String result =  getTitleWithoutYearAndAuthor(article, false);
65
		result = addYear(result, article, false);
66
		TeamOrPersonBase<?> team = article.getAuthorTeam();
67
		result = CdmUtils.concat(" ", article.getTitle(), result);
68
		if (team != null &&  StringUtils.isNotBlank(team.getTitleCache())){
69
			String authorSeparator = StringUtils.isNotBlank(article.getTitle())? afterAuthor : " ";
70
			result = team.getTitleCache() + authorSeparator + result;
71
		}
72
		return result;
73
	}
74

    
75
	@Override
76
	public String getAbbrevTitleCache(T article) {
77
		if (article.isProtectedAbbrevTitleCache()){
78
			return article.getAbbrevTitleCache();
79
		}
80
		String result =  getTitleWithoutYearAndAuthor(article, true);
81
		result = addYear(result, article, false);
82
		TeamOrPersonBase<?> team = article.getAuthorTeam();
83
		result = CdmUtils.concat(" ", article.getTitle(), result);
84
		if (team != null &&  StringUtils.isNotBlank(team.getNomenclaturalTitle())){
85
			String authorSeparator = StringUtils.isNotBlank(article.getTitle())? afterAuthor : " ";
86
			result = team.getNomenclaturalTitle() + authorSeparator + result;
87
		}
88
		return result;
89
	}
90

    
91
	@Override
92
	protected String getTitleWithoutYearAndAuthor(T article, boolean isAbbrev){
93
		if (article == null){
94
			return null;
95
		}
96
		IJournal journal = article.getInReference();
97
		boolean hasJournal = (journal != null);
98
		
99
		String journalTitel;
100
		if (hasJournal){
101
			journalTitel = CdmUtils.getPreferredNonEmptyString(journal.getTitle(), journal.getAbbrevTitle(), isAbbrev, true);
102
		}else{
103
			journalTitel = UNDEFINED_JOURNAL;
104
		}
105
		
106
		String series = Nz(article.getSeries()).trim();
107
		String volume = Nz(article.getVolume()).trim();
108
		
109
		boolean needsComma = false;
110
		
111
		String nomRefCache = "";
112

    
113
		//inJournal
114
		nomRefCache = prefixReferenceJounal + blank; 
115
		
116
		//titelAbbrev
117
		if (isNotBlank(journalTitel)){
118
			nomRefCache = nomRefCache + journalTitel + blank; 
119
		}
120
		
121
		nomRefCache = getSeriesAndVolPart(series, volume, needsComma, nomRefCache);
122
		
123
		//delete "."
124
		while (nomRefCache.endsWith(".")){
125
			nomRefCache = nomRefCache.substring(0, nomRefCache.length()-1);
126
		}
127
		
128
		return nomRefCache.trim();
129
	}
130
	
131
	protected String getSeriesAndVolPart(String series, String volume,
132
			boolean needsComma, String nomRefCache) {
133
		//inSeries
134
		String seriesPart = "";
135
		if (isNotBlank(series)){
136
			seriesPart = series;
137
			if (CdmUtils.isNumeric(series)){
138
				seriesPart = prefixSeries + blank + seriesPart;
139
			}
140
			if (needsComma){
141
				seriesPart = comma + seriesPart;
142
			}
143
			needsComma = true;
144
		}
145
		nomRefCache += seriesPart;
146
		
147
		
148
		//volume Part
149
		String volumePart = "";
150
		if (!"".equals(volume)){
151
			volumePart = volume;
152
			if (needsComma){
153
				volumePart = comma + blank + volumePart;
154
			}
155
			//needsComma = false;
156
		}
157
		nomRefCache += volumePart;
158
		return nomRefCache;
159
	}
160

    
161
}
(1-1/12)