Project

General

Profile

Download (3.82 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.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.Reference;
18
import eu.etaxonomy.cdm.strategy.StrategyBase;
19
import eu.etaxonomy.cdm.strategy.cache.reference.IReferenceCacheStrategy;
20
/**
21
 * @author a.mueller
22
 * @created 08-Aug-2008 22:06:45
23
 */
24
public class ReferenceDefaultCacheStrategy extends StrategyBase implements IReferenceCacheStrategy {
25
	private static final long serialVersionUID = 4350124746874497766L;
26
	@SuppressWarnings("unused")
27
	private static final Logger logger = Logger.getLogger(ReferenceDefaultCacheStrategy.class);
28

    
29
	final static UUID uuid = UUID.fromString("763fe4a0-c79f-4f14-9693-631680225ec3");
30

    
31

    
32
	protected String beforeYear = ". ";
33
	protected String afterYear = "";
34
	protected String afterAuthor = ", ";
35

    
36
	private String blank = " ";
37

    
38

    
39
// ****************** FACTORY *******************************/
40

    
41
	public static ReferenceDefaultCacheStrategy NewInstance(){
42
		return new ReferenceDefaultCacheStrategy();
43
	}
44

    
45
// ***************** CONSTRUCTOR ********************************/
46

    
47
	/**
48
	 * Constructor
49
	 */
50
	private ReferenceDefaultCacheStrategy(){
51
		super();
52
	}
53

    
54

    
55

    
56

    
57

    
58
	@Override
59
	public String getFullAbbrevTitleString(Reference reference) {
60
		return getTitleCache(reference, true);
61
	}
62

    
63
	@Override
64
	public String getTitleCache(Reference reference) {
65
		return getTitleCache(reference, false);
66
	}
67

    
68
	private String getTitleCache(Reference ref, boolean isAbbrev) {
69
		String result = "";
70
		if (ref == null){
71
			return null;
72
		}
73
		String titel = CdmUtils.getPreferredNonEmptyString(ref.getTitle(), ref.getAbbrevTitle(), isAbbrev, true);
74
		//titelAbbrev
75
		if (isNotBlank(titel)){
76
			result = titel + blank;
77
		}
78
		//delete .
79
		while (result.endsWith(".")){
80
			result = result.substring(0, result.length()-1);
81
		}
82

    
83
		result = addYear(result, ref);
84
		TeamOrPersonBase<?> team = ref.getAuthorship();
85
		if (team != null){
86
			String author = CdmUtils.getPreferredNonEmptyString(team.getTitleCache(), team.getNomenclaturalTitle(), isAbbrev, true);
87
			if (isNotBlank(author)){
88
				result = author + afterAuthor + result;
89
			}
90
		}
91
		return result;
92
	}
93

    
94
	protected String addYear(String string, Reference ref){
95
		String result;
96
		if (string == null){
97
			return null;
98
		}
99
		String year = CdmUtils.Nz(ref.getYear());
100
		if ("".equals(year)){
101
			result = string + afterYear;
102
		}else{
103
			result = string + beforeYear + year + afterYear;
104
		}
105
		return result;
106
	}
107

    
108
	@Override
109
	public String getCitation(Reference referenceBase) {
110
		StringBuilder stringBuilder = new StringBuilder();
111

    
112
		TeamOrPersonBase<?> team = referenceBase.getAuthorship();
113
		if (team != null &&  ! (team.getTitleCache() == null) && ! team.getTitleCache().trim().equals("")){
114
			//String author = CdmUtils.Nz(team == null? "" : team.getTitleCache());
115
			stringBuilder.append(team.getTitleCache() + afterAuthor);
116
		}
117

    
118
		String year = CdmUtils.Nz(referenceBase.getYear());
119
		if (!"".equals(year)){
120
			stringBuilder.append(beforeYear + year);
121
		}
122

    
123
		return stringBuilder.toString();
124
	}
125

    
126

    
127

    
128
	@Override
129
	protected UUID getUuid() {
130
		return UUID.fromString("919dbf70-33e7-11de-b418-0800200c9a66");
131
	}
132

    
133

    
134
	/**
135
	 *
136
	 * @param referenceTitleCache
137
	 * @param authorTitleCache
138
	 * @return
139
	 */
140
	public static String putAuthorToEndOfString(String referenceTitleCache, String authorTitleCache) {
141
		if(authorTitleCache != null){
142
			referenceTitleCache = referenceTitleCache.replace(authorTitleCache + ", ", "");
143
			referenceTitleCache += " - " + authorTitleCache;
144
		}
145
		return referenceTitleCache;
146
	}
147

    
148
}
(9-9/12)