Project

General

Profile

Download (4.11 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.log4j.Logger;
14

    
15
import eu.etaxonomy.cdm.model.common.CdmBase;
16
import eu.etaxonomy.cdm.model.reference.INomenclaturalReference;
17
import eu.etaxonomy.cdm.model.reference.Reference;
18
import eu.etaxonomy.cdm.model.reference.ReferenceType;
19

    
20
public class SectionDefaultCacheStrategy extends InRefDefaultCacheStrategyBase implements INomenclaturalReferenceCacheStrategy {
21
	private static final long serialVersionUID = -4534389083526558368L;
22
	private static final Logger logger = Logger.getLogger(SectionDefaultCacheStrategy.class);
23

    
24
	final static UUID uuid = UUID.fromString("a7150cd3-107b-4169-ac84-71ffe3219152");
25

    
26
	private static final String inRefTypeStr = "in reference";
27

    
28
	private static final boolean inRefIsObligatory = true;
29

    
30
	@Override
31
	protected UUID getUuid() {
32
		return uuid;
33
	}
34

    
35
	@Override
36
	protected String getInRefType() {
37
		return inRefTypeStr;
38
	}
39

    
40
	/**
41
	 * Factory method
42
	 * @return
43
	 */
44
	public static SectionDefaultCacheStrategy NewInstance(){
45
		return new SectionDefaultCacheStrategy();
46
	}
47

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

    
55
	@Override
56
	protected String getTitleWithoutYearAndAuthor(Reference reference, boolean isAbbrev) {
57
		// not needed in Section
58
		logger.warn("Questionable procedure call. Procedure not implemented because not needed. ");
59
		return null;
60
	}
61

    
62
	@Override
63
	public String getTokenizedNomenclaturalTitel(Reference section) {
64
		//generic == null
65
		if (section == null /* || generic.getInReference() == null */){
66
			return null;
67
		}
68
		Reference inRef = CdmBase.deproxy(section.getInReference(), Reference.class);
69
		if (inRef != null && inRef.getInReference() == null){
70
			//this is a simple inRef (not an in-in-Ref) which can be handled by InRefDefaultCacheStrategy
71
			return super.getTokenizedNomenclaturalTitel(section, inRefIsObligatory);
72
		}
73

    
74
		Reference inInRef = CdmBase.deproxy(inRef.getInReference(), Reference.class);
75
		String result;
76

    
77
		IReferenceBaseCacheStrategy inRefStrategy = inInRef.getCacheStrategy();
78
		if (! (inRefStrategy instanceof NomRefDefaultCacheStrategyBase)){
79
			inRefStrategy= inRef.getCacheStrategy();
80
			if (! (inRefStrategy instanceof NomRefDefaultCacheStrategyBase)){
81
				logger.warn("Neither inReference nor inInReference is a nomenclatural reference. This is not correct or not handled yet. Generic Cache Strategy used instead");
82
				inRefStrategy = ReferenceType.Generic.getCacheStrategy();
83
				result = ((NomRefDefaultCacheStrategyBase)inRefStrategy).getTitleWithoutYearAndAuthor(inInRef, true);
84
				//FIXME: vol. etc., http://dev.e-taxonomy.eu/trac/ticket/2862  (comment taken from super.getTokenizedNomenclaturalTitel())
85
			}else{
86
				result = ((NomRefDefaultCacheStrategyBase)inRefStrategy).getTitleWithoutYearAndAuthor(inRef, true);
87
			}
88
		}else{
89
			result = ((NomRefDefaultCacheStrategyBase)inRefStrategy).getTitleWithoutYearAndAuthor(inInRef, true);
90
		}
91
		result += INomenclaturalReference.MICRO_REFERENCE_TOKEN;
92

    
93
		Reference dataReference = (section.hasDatePublished() ? section : inRef.hasDatePublished() ? inRef : inInRef);
94

    
95
		result = addYear(result, dataReference, true);
96

    
97
		result = getInRefAuthorPart(inInRef, afterInRefAuthor) + result;
98
		if (! result.startsWith("in ")){
99
			result = "in " +  result;
100
		}
101
		return result;
102
	}
103

    
104
	@Override
105
	public String getTitleCache(Reference thisRef) {
106
		return super.getTitleCache(thisRef, inRefIsObligatory, false);
107
	}
108

    
109
	@Override
110
	public String getAbbrevTitleCache(Reference thisRef) {
111
		return super.getTitleCache(thisRef, inRefIsObligatory, true);
112
	}
113

    
114
	@Override  //only for testing
115
	public String getNomenclaturalCitation(Reference nomenclaturalReference, String microReference){
116
		return super.getNomenclaturalCitation(nomenclaturalReference, microReference);
117
	}
118

    
119
}
(12-12/14)