Project

General

Profile

Revision d4657a24

IDd4657a24db2ed076dca13036495e6ea1c84c14f2
Parent cb3409ef
Child ee537bcd

Added by Andreas Müller over 7 years ago

better handling of abbreviated title cache in references, series -> seriesPart and some improvements in the reference cache strategies #4280, #4239

View differences:

.gitattributes
995 995
cdmlib-model/src/main/java/eu/etaxonomy/cdm/strategy/cache/reference/ReferenceDefaultCacheStrategy.java -text
996 996
cdmlib-model/src/main/java/eu/etaxonomy/cdm/strategy/cache/reference/SectionDefaultCacheStrategy.java -text
997 997
cdmlib-model/src/main/java/eu/etaxonomy/cdm/strategy/cache/reference/ThesisDefaultCacheStrategy.java -text
998
cdmlib-model/src/main/java/eu/etaxonomy/cdm/strategy/cache/reference/WebPageDefaultCacheStrategy.java -text
998 999
cdmlib-model/src/main/java/eu/etaxonomy/cdm/strategy/cache/taxon/TaxonBaseDefaultCacheStrategy.java -text
999 1000
cdmlib-model/src/main/java/eu/etaxonomy/cdm/strategy/exceptions/StringNotParsableException.java -text
1000 1001
cdmlib-model/src/main/java/eu/etaxonomy/cdm/strategy/exceptions/UnknownCdmTypeException.java -text
cdmlib-model/src/main/java/eu/etaxonomy/cdm/model/reference/IArticle.java
29 29
	/**
30 30
	 * Returns the series information for this article
31 31
	 */
32
	public String getSeries();
32
	public String getSeriesPart();
33 33

  
34 34
	/**
35 35
	 * Sets the series information for this article
36 36
	 * @param series
37 37
	 */
38
	public void setSeries(String series);
38
	public void setSeriesPart(String series);
39 39
	
40 40
	
41 41
	
cdmlib-model/src/main/java/eu/etaxonomy/cdm/model/reference/IGeneric.java
43 43
	/**
44 44
	 * Returns the series of this generic reference
45 45
	 */
46
	public String getSeries();
46
	public String getSeriesPart();
47 47
	
48 48
	/**
49 49
	 * Sets the series for this generic reference
50 50
	 * @param series
51 51
	 */
52
	public void setSeries(String series);
52
	public void setSeriesPart(String series);
53 53
	
54 54
	/**
55 55
	 * Returns the pages (page span this reference covers in its in-reference) 
cdmlib-model/src/main/java/eu/etaxonomy/cdm/model/reference/Reference.java
9 9

  
10 10
package eu.etaxonomy.cdm.model.reference;
11 11

  
12
import java.beans.PropertyChangeEvent;
13
import java.beans.PropertyChangeListener;
12 14
import java.net.URI;
13 15
import java.util.List;
14 16

  
......
176 178
    //TODO Val #3379
177 179
//    @NullOrNotEmpty
178 180
	@Length(max = 255)
181
    @Deprecated //series and seriesPart are duplicates #4293 
179 182
	protected String series;
180 183

  
181 184
    @XmlElement(name = "Volume")
......
365 368
	protected Reference(ReferenceType type) {
366 369
		this.type = type;
367 370
	}
371
	
372
	@Override
373
    protected void initListener(){
374
        PropertyChangeListener listener = new PropertyChangeListener() {
375
            @Override
376
            public void propertyChange(PropertyChangeEvent ev) {
377
            	if (!ev.getPropertyName().equals("titleCache") && !ev.getPropertyName().equals("abbrevTitleCache") && !ev.getPropertyName().equals("cacheStrategy")){
378
            		if (! isProtectedTitleCache()){
379
            			titleCache = null;	
380
            		}
381
            		if (! isProtectedAbbrevTitleCache()){
382
            			abbrevTitleCache = null;	
383
            		}
384
            	}
385
            }
386
        };
387
        addPropertyChangeListener(listener);
388
    }
368 389

  
369 390

  
370 391
//*************************** GETTER / SETTER ******************************************/
......
427 448
		this.editor = editor;
428 449
	}
429 450

  
430
	@Override
431
    public String getSeries() {
432
		return series;
433
	}
434

  
435
	@Override
436
    public void setSeries(String series) {
437
		this.series = series;
438
	}
451
//	@Override
452
//    public String getSeries() {
453
//		return series;
454
//	}
455
//
456
//	@Override
457
//    public void setSeries(String series) {
458
//		this.series = series;
459
//	}
439 460

  
440 461
	@Override
441 462
    public String getVolume() {
......
872 893
		}
873 894
	}
874 895

  
875
	/* (non-Javadoc)
876
	 * @see eu.etaxonomy.cdm.model.common.IdentifiableEntity#generateTitle()
877
	 */
896

  
878 897
	@Override
879 898
    public String generateTitle() {
880 899
		rectifyCacheStrategy();
......
922 941
	}
923 942

  
924 943

  
925

  
926
	/* (non-Javadoc)
927
	 * @see eu.etaxonomy.cdm.model.common.IParsable#getHasProblem()
928
	 */
929 944
	@Override
930 945
    public int getParsingProblem(){
931 946
		return this.parsingProblem;
932 947
	}
933 948

  
934
	/* (non-Javadoc)
935
	 * @see eu.etaxonomy.cdm.model.common.IParsable#setHasProblem(boolean)
936
	 */
937 949
	@Override
938 950
    public void setParsingProblem(int parsingProblem){
939 951
		this.parsingProblem = parsingProblem;
940 952
	}
941 953

  
942
	/* (non-Javadoc)
943
	 * @see eu.etaxonomy.cdm.model.common.IParsable#hasProblem()
944
	 */
945 954
	@Override
946 955
    public boolean hasProblem(){
947 956
		return parsingProblem != 0;
948 957
	}
949 958

  
950
	/* (non-Javadoc)
951
	 * @see eu.etaxonomy.cdm.model.common.IParsable#hasProblem(eu.etaxonomy.cdm.strategy.parser.ParserProblem)
952
	 */
953 959
	@Override
954 960
    public boolean hasProblem(ParserProblem problem) {
955 961
		return getParsingProblems().contains(problem);
956 962
	}
957 963

  
958

  
959
	/* (non-Javadoc)
960
	 * @see eu.etaxonomy.cdm.model.common.IParsable#problemStarts()
961
	 */
962 964
	@Override
963 965
    public int getProblemStarts(){
964 966
		return this.problemStarts;
965 967
	}
966 968

  
967
	/* (non-Javadoc)
968
	 * @see eu.etaxonomy.cdm.model.common.IParsable#setProblemStarts(int)
969
	 */
970 969
	@Override
971 970
    public void setProblemStarts(int start) {
972 971
		this.problemStarts = start;
973 972
	}
974 973

  
975
	/* (non-Javadoc)
976
	 * @see eu.etaxonomy.cdm.model.common.IParsable#problemEnds()
977
	 */
978 974
	@Override
979 975
    public int getProblemEnds(){
980 976
		return this.problemEnds;
981 977
	}
982 978

  
983
	/* (non-Javadoc)
984
	 * @see eu.etaxonomy.cdm.model.common.IParsable#setProblemEnds(int)
985
	 */
986 979
	@Override
987 980
    public void setProblemEnds(int end) {
988 981
		this.problemEnds = end;
989 982
	}
990 983

  
991
	/* (non-Javadoc)
992
	 * @see eu.etaxonomy.cdm.model.common.IParsable#addProblem(eu.etaxonomy.cdm.strategy.parser.NameParserWarning)
993
	 */
994 984
	@Override
995 985
    public void addParsingProblem(ParserProblem warning){
996 986
		parsingProblem = ParserProblem.addProblem(parsingProblem, warning);
997 987
	}
998 988

  
999
	/* (non-Javadoc)
1000
	 * @see eu.etaxonomy.cdm.model.common.IParsable#removeParsingProblem(eu.etaxonomy.cdm.strategy.parser.ParserProblem)
1001
	 */
1002 989
	@Override
1003 990
    public void removeParsingProblem(ParserProblem problem) {
1004 991
		parsingProblem = ParserProblem.removeProblem(parsingProblem, problem);
1005 992
	}
1006 993

  
1007
	/* (non-Javadoc)
1008
	 * @see eu.etaxonomy.cdm.model.common.IParsable#getParsingProblems()
1009
	 */
1010 994
	@Override
1011 995
    @Transient
1012 996
	public List<ParserProblem> getParsingProblems() {
cdmlib-model/src/main/java/eu/etaxonomy/cdm/model/reference/ReferenceFactory.java
160 160
	 * @param referenceType
161 161
	 * @return
162 162
	 */
163
	public static Reference newReference(ReferenceType referenceType) {
163
	public static Reference<?> newReference(ReferenceType referenceType) {
164 164
		if (referenceType == null){
165 165
			return null;
166 166
		}
......
197 197
				return newBook();
198 198
			case Generic:
199 199
				return newGeneric();
200
			case Section:
201
				return newSection();
200 202
			default:
201 203
				logger.warn("Unknown reference type " + referenceType.getMessage() + ". Created generic reference instead.");
202 204
				return newGeneric();	
cdmlib-model/src/main/java/eu/etaxonomy/cdm/model/reference/ReferenceType.java
32 32
import eu.etaxonomy.cdm.strategy.cache.reference.ReferenceDefaultCacheStrategy;
33 33
import eu.etaxonomy.cdm.strategy.cache.reference.SectionDefaultCacheStrategy;
34 34
import eu.etaxonomy.cdm.strategy.cache.reference.ThesisDefaultCacheStrategy;
35
import eu.etaxonomy.cdm.strategy.cache.reference.WebPageDefaultCacheStrategy;
35 36

  
36 37

  
37 38
/**
......
152 153
			return ThesisDefaultCacheStrategy.NewInstance();
153 154
		case Section:
154 155
			return SectionDefaultCacheStrategy.NewInstance();
156
		case WebPage:
157
			return WebPageDefaultCacheStrategy.NewInstance();
155 158
        default:
156 159
            return ReferenceDefaultCacheStrategy.NewInstance();
157 160
		}
cdmlib-model/src/main/java/eu/etaxonomy/cdm/strategy/cache/reference/ArticleDefaultCacheStrategy.java
10 10

  
11 11
import java.util.UUID;
12 12

  
13
import org.apache.commons.lang.StringUtils;
14 13
import org.apache.log4j.Logger;
15 14

  
16 15
import eu.etaxonomy.cdm.common.CdmUtils;
......
62 61
		result = addYear(result, article, false);
63 62
		TeamOrPersonBase<?> team = article.getAuthorTeam();
64 63
		result = CdmUtils.concat(" ", article.getTitle(), result);
65
		if (team != null &&  StringUtils.isNotBlank(team.getTitleCache())){
66
			String authorSeparator = StringUtils.isNotBlank(article.getTitle())? afterAuthor : " ";
64
		if (team != null &&  isNotBlank(team.getTitleCache())){
65
			String authorSeparator = isNotBlank(article.getTitle())? afterAuthor : " ";
67 66
			result = team.getTitleCache() + authorSeparator + result;
68 67
		}
69 68
		return result;
......
79 78
		TeamOrPersonBase<?> team = article.getAuthorTeam();
80 79
		String articleTitle = CdmUtils.getPreferredNonEmptyString(article.getAbbrevTitle(), article.getTitle(), false, true);
81 80
		result = CdmUtils.concat(" ", articleTitle, result);  //Article should maybe left out for nomenclatural references (?)
82
		if (team != null &&  StringUtils.isNotBlank(team.getNomenclaturalTitle())){
83
			String authorSeparator = StringUtils.isNotBlank(articleTitle) ? afterAuthor : " ";
81
		if (team != null &&  isNotBlank(team.getNomenclaturalTitle())){
82
			String authorSeparator = isNotBlank(articleTitle) ? afterAuthor : " ";
84 83
			result = team.getNomenclaturalTitle() + authorSeparator + result;
85 84
		}
86 85
		return result;
......
101 100
			journalTitel = UNDEFINED_JOURNAL;
102 101
		}
103 102
		
104
		String series = Nz(article.getSeries()).trim();
103
		String series = Nz(article.getSeriesPart()).trim();
105 104
		String volume = Nz(article.getVolume()).trim();
106 105
		
107 106
		boolean needsComma = false;
......
110 109

  
111 110
		//inJournal
112 111
		nomRefCache = prefixReferenceJounal + blank; 
113
		
112
				
114 113
		//titelAbbrev
115 114
		if (isNotBlank(journalTitel)){
116
			nomRefCache = nomRefCache + journalTitel + blank; 
115
			nomRefCache = nomRefCache + journalTitel;
116
			needsComma = makeNeedsComma(needsComma, nomRefCache, volume, series);
117
			if (! needsComma){
118
				nomRefCache = nomRefCache + blank;
119
			}
117 120
		}
118 121
		
122
		//series and vol.
119 123
		nomRefCache = getSeriesAndVolPart(series, volume, needsComma, nomRefCache);
120
		
124
				
121 125
		//delete "."
122 126
		while (nomRefCache.endsWith(".")){
123 127
			nomRefCache = nomRefCache.substring(0, nomRefCache.length()-1);
......
126 130
		return nomRefCache.trim();
127 131
	}
128 132
	
133
	private boolean makeNeedsComma(boolean needsComma, String nomRefCache, String volume, String series) {
134
		if (needsComma){
135
			return true;
136
		}else{
137
			nomRefCache = nomRefCache.toLowerCase();
138
			int serIndex = nomRefCache.indexOf(" ser. ");
139
			int sectIndex = nomRefCache.indexOf(" sect. ");
140
			int abtIndex = nomRefCache.indexOf(" abt. ");
141
			int index = Math.max(Math.max(serIndex, sectIndex), abtIndex);
142
			int commaIndex = nomRefCache.indexOf(",", index);
143
			if (index > -1 && commaIndex == -1 && isNotBlank(volume)){
144
				return true;
145
			}else if (isNotBlank(series)){
146
				return true;
147
			}else{
148
				return false;
149
			}
150
		}
151
	}
152

  
153

  
129 154
	protected String getSeriesAndVolPart(String series, String volume,
130 155
			boolean needsComma, String nomRefCache) {
131 156
		//inSeries
......
135 160
			if (CdmUtils.isNumeric(series)){
136 161
				seriesPart = prefixSeries + blank + seriesPart;
137 162
			}
138
			if (needsComma){
139
				seriesPart = comma + seriesPart;
140
			}
163
//			if (needsComma){
164
				seriesPart = comma + blank + seriesPart;
165
//			}
141 166
			needsComma = true;
142 167
		}
143 168
		nomRefCache += seriesPart;
cdmlib-model/src/main/java/eu/etaxonomy/cdm/strategy/cache/reference/BookDefaultCacheStrategy.java
23 23
	private static final Logger logger = Logger.getLogger(BookDefaultCacheStrategy.class);
24 24
	
25 25
	private String prefixEdition = "ed.";
26
	private String prefixSeries = "ser.";
26
	private String prefixSeries = ", ser.";
27 27
	private String prefixVolume = "vol.";
28 28
	private String blank = " ";
29 29
	private String comma = ",";
......
60 60
		}
61 61
		//TODO
62 62
		String title = CdmUtils.getPreferredNonEmptyString(ref.getTitle(), ref.getAbbrevTitle(), isAbbrev, true);
63
		String edition = CdmUtils.Nz(ref.getEdition()).trim();
64
		//TODO
65
		String series = ""; //nomenclaturalReference.getSeries();
63
		String edition = Nz(ref.getEdition()).trim();
64
		String series = ""; //TODO ref.getSeries();  //SeriesPart is handled later
65
		String refSeriesPart = Nz(ref.getSeriesPart()); 
66 66
		String volume = CdmUtils.Nz(ref.getVolume()).trim();
67 67
		String refYear = "";  //TODO nomenclaturalReference.getYear();
68 68

  
69 69

  
70 70
		String nomRefCache = "";
71
		boolean lastCharIsDouble;
72 71
		Integer len;
73
		String lastChar;
72
		String lastChar = "";
74 73
		String character =".";
75 74
		len = title.length();
76 75
		if (len > 0){
77 76
			lastChar = title.substring(len-1, len);
78 77
		}
79 78
		//lastCharIsDouble = f_core_CompareStrings(RIGHT(@TitelAbbrev,1),character);
80
		lastCharIsDouble = title.equals(character);
79
		boolean lastCharIsDouble = title.equals(character);
81 80

  
82
		if(lastCharIsDouble  && edition.length() == 0 && series.length() == 0 && volume.length() == 0 && refYear.length() > 0 ){
81
		if(lastCharIsDouble  && edition.length() == 0 && refSeriesPart.length() == 0 && volume.length() == 0 && refYear.length() > 0 ){
83 82
			title =  title.substring(1, len-1); //  SUBSTRING(@TitelAbbrev,1,@LEN-1)
84 83
		}
85 84

  
......
87 86
		boolean needsComma = false;
88 87
		//titelAbbrev
89 88
		if (!"".equals(title) ){
90
			String postfix = StringUtils.isNotBlank(edition) ? "" : blank; 
89
			String postfix = isNotBlank(edition + refSeriesPart) ? "" : blank; 
91 90
			nomRefCache = title + postfix; 
92 91
		}
93 92
		//edition
......
103 102
		
104 103
		//inSeries
105 104
		String seriesPart = "";
106
		if (StringUtils.isNotBlank(series)){
107
			seriesPart = series;
108
			if (isNumeric(series)){
105
		if (StringUtils.isNotBlank(refSeriesPart)){
106
			seriesPart = refSeriesPart;
107
			if (isNumeric(refSeriesPart)){
109 108
				seriesPart = prefixSeries + blank + seriesPart;
110 109
			}
111 110
			if (needsComma){
......
122 121
			volumePart = volume;
123 122
			if (needsComma){
124 123
				volumePart = comma + blank + volumePart;
124
			}else{
125
				volumePart = "" + volumePart;
125 126
			}
126 127
			//needsComma = false;
127 128
		}
cdmlib-model/src/main/java/eu/etaxonomy/cdm/strategy/cache/reference/GenericDefaultCacheStrategy.java
32 32
	
33 33
	private String prefixEdition = "ed.";
34 34
	private String prefixSeries = "ser.";
35
	private String prefixVolume = "vol.";
35
//	private String prefixVolume = "vol.";
36 36
	private String blank = " ";
37 37
	private String comma = ",";
38
	private String dot =".";
38
//	private String dot =".";
39 39
	
40 40
	final static UUID uuid = UUID.fromString("95cceb30-6b16-4dc3-8243-c15e746565bc");
41 41
	
......
70 70
		String titel = CdmUtils.getPreferredNonEmptyString(genericReference.getTitle(), genericReference.getAbbrevTitle(), isAbbrev, true);
71 71
		String edition = CdmUtils.Nz(genericReference.getEdition());
72 72
		//TODO
73
		String series = CdmUtils.Nz(genericReference.getSeries()).trim(); //nomenclaturalReference.getSeries();
73
		String series = CdmUtils.Nz(genericReference.getSeriesPart()).trim(); //nomenclaturalReference.getSeries();
74 74
		String volume = CdmUtils.Nz(genericReference.getVolume()).trim();
75 75

  
76 76
		String nomRefCache = "";
cdmlib-model/src/main/java/eu/etaxonomy/cdm/strategy/cache/reference/INomenclaturalReferenceCacheStrategy.java
13 13
import eu.etaxonomy.cdm.model.reference.Reference;
14 14

  
15 15
/**
16
 * A reference cache rendering strategy for all subclasses implementing INomenclaturalReference.
16
 * A reference formatting strategy for all subclasses implementing INomenclaturalReference.
17 17
 * @author a.mueller
18 18
 *
19 19
 * @param <T> The concrete Reference class this strategy applies for
20 20
 */
21 21
public interface INomenclaturalReferenceCacheStrategy extends IReferenceBaseCacheStrategy {
22 22
	
23
	
24
	/**
25
	 * returns the composed scientific taxon name string without authors nor year
26
	 * @param object
27
	 * @return
28
	 */
29
	public String getTitleCache(Reference nomenclaturalReference);
30
	
31
	/**
32
	 * returns the composed author string 
33
	 * @param object
34
	 * @return
35
	 */
36
	public String getTokenizedNomenclaturalTitel(Reference referenceBase);
23
//	
24
//	/**
25
//	 * Returns the composed author string 
26
//	 * @param object
27
//	 * @return
28
//	 */
29
//	public String getTokenizedNomenclaturalTitel(Reference referenceBase);
37 30
	
38 31
	/**
39 32
	 * Returns the character sequence before the micro reference (e.g. ": ") 
cdmlib-model/src/main/java/eu/etaxonomy/cdm/strategy/cache/reference/InRefDefaultCacheStrategyBase.java
79 79
			return "";
80 80
		}
81 81
		TeamOrPersonBase<?> team = book.getAuthorTeam();
82
		String result = CdmUtils.Nz( team == null ? "" : team.getTitleCache());
82
		String result = Nz( team == null ? "" : team.getNomenclaturalTitle());
83 83
		if (! result.trim().equals("")){
84 84
			result = result + seperator;	
85 85
		}
......
105 105
		boolean hasInRef = (inRef != null);
106 106
		// get inRef part
107 107
		if (hasInRef){
108
			result = CdmUtils.getPreferredNonEmptyString(inRef.getTitleCache(), inRef.getAbbrevTitle(), isAbbrev, true)  ;
108
			result = CdmUtils.getPreferredNonEmptyString(inRef.getTitleCache(), inRef.getAbbrevTitleCache(), isAbbrev, true)  ;
109 109
		}else{
110 110
			if ( ! inRefIsObligatory){
111 111
				return super.getTitleCache(thisRef);
......
146 146
						logger.warn("InRefDateString (" + inRefDateString + ") could not be found in result (" + result +")");
147 147
					}
148 148
				}else{
149
					result = result + beforeYear + thisRefDate + afterYear;
149
					//avoid duplicate dots ('..')
150
					String bYearSeparator = result.substring(result.length() -1).equals(beforeYear.substring(0, 1)) ? beforeYear.substring(1) : beforeYear;
151
					result = result + bYearSeparator + thisRefDate + afterYear;
150 152
				}
151 153
			}else{
152 154
				result = result + beforeYear + thisRefDate + afterYear;
cdmlib-model/src/main/java/eu/etaxonomy/cdm/strategy/cache/reference/JournalDefaultCacheStrategy.java
16 16

  
17 17
import eu.etaxonomy.cdm.common.CdmUtils;
18 18
import eu.etaxonomy.cdm.model.agent.TeamOrPersonBase;
19
import eu.etaxonomy.cdm.model.reference.IJournal;
20 19
import eu.etaxonomy.cdm.model.reference.Reference;
21 20
import eu.etaxonomy.cdm.strategy.StrategyBase;
22 21

  
......
25 24
 * @created 29.06.2008
26 25
 */
27 26
public class JournalDefaultCacheStrategy extends StrategyBase implements IReferenceBaseCacheStrategy {
27
	private static final long serialVersionUID = 8495999505123620960L;
28

  
29

  
28 30
	@SuppressWarnings("unused")
29 31
	private static final Logger logger = Logger.getLogger(JournalDefaultCacheStrategy.class);
30 32

  
cdmlib-model/src/main/java/eu/etaxonomy/cdm/strategy/cache/reference/NomRefDefaultCacheStrategyBase.java
25 25
public abstract class NomRefDefaultCacheStrategyBase extends StrategyBase implements INomenclaturalReferenceCacheStrategy{
26 26
	private static final long serialVersionUID = -725290113353165022L;
27 27

  
28
	@SuppressWarnings("unused")
29 28
	private static final Logger logger = Logger.getLogger(NomRefDefaultCacheStrategyBase.class);
30 29
	
31 30
	protected String beforeYear = ". ";
......
34 33
	protected String afterAuthor = ", ";	
35 34
	
36 35

  
37
	@Override
38
	public String getTokenizedNomenclaturalTitel(Reference ref) {
39
		String result =  getTitleWithoutYearAndAuthor(ref, true);
36
	/**
37
	 * Returns the nomenclatural title with micro reference represented as token
38
	 * which can later be replaced by the real data.
39
	 * 
40
	 * @see INomenclaturalReference#MICRO_REFERENCE_TOKEN
41
	 * 
42
	 * @param ref The reference
43
	 * @return
44
	 */
45
	protected String getTokenizedNomenclaturalTitel(Reference ref) {
46
		String result = getTitleWithoutYearAndAuthor(ref, true);
40 47
		result += INomenclaturalReference.MICRO_REFERENCE_TOKEN;
41 48
		result = addYear(result, ref, true);
42 49
		return result;
......
67 74
			String teamTitle = CdmUtils.getPreferredNonEmptyString(team.getTitleCache(), team.getNomenclaturalTitle(), isAbbrev, true);
68 75
			if (teamTitle.length() > 0 ){
69 76
				String concat = isNotBlank(result) ? afterAuthor : "";
70
				result = team.getTitleCache() + concat + result;
77
				result = teamTitle + concat + result;
71 78
			}
72 79
			
73 80
		}
74 81
		return result;
75 82
	}
76 83
	
77
	protected abstract String getTitleWithoutYearAndAuthor(Reference reference, boolean isAbbrev);
84
	protected abstract String getTitleWithoutYearAndAuthor(Reference<?> reference, boolean isAbbrev);
78 85

  
79 86
	
80 87
	@Override
......
84 91
		String nextConcat = "";
85 92
		
86 93
		TeamOrPersonBase<?> team = referenceBase.getAuthorTeam();
87
		if (team != null &&  ! (team.getTitleCache() == null) && ! team.getTitleCache().trim().equals("")){
94
		if (team != null &&  isNotBlank(team.getTitleCache())){
88 95
			stringBuilder.append(team.getTitleCache() );
89 96
			nextConcat = afterAuthor;
90 97
		}
......
109 116
			return null;
110 117
		}
111 118
		String year = useFullDatePublished ? nomRef.getDatePublishedString() : nomRef.getYear();
112
		if (StringUtils.isBlank(year)){
119
		if (isBlank(year)){
113 120
			result = string + afterYear;
114 121
		}else{
115
			String concat = isBlank(string)  ? "" : string.endsWith(".")? " " : beforeYear;
122
			String concat = isBlank(string)  ? "" : string.endsWith(".")  ? " " : beforeYear;
116 123
			result = string + concat + year + afterYear;
117 124
		}
118 125
		return result;
......
120 127
	
121 128
	@Override
122 129
	public String getNomenclaturalCitation(Reference nomenclaturalReference, String microReference) {
123
		if (nomenclaturalReference.isProtectedTitleCache()){
124
			return nomenclaturalReference.getTitleCache();
130
		if (nomenclaturalReference.isProtectedAbbrevTitleCache()){
131
			String cache = nomenclaturalReference.getAbbrevTitleCache();
132
			return handleDetailAndYearForPreliminary(nomenclaturalReference, cache, microReference);
133
			
125 134
		}
126 135
		String result = getTokenizedNomenclaturalTitel(nomenclaturalReference);
127
		microReference = CdmUtils.Nz(microReference);
136
		//if no data is available and only titleCache is protected take the protected title
137
		//this is to avoid empty cache if someone forgets to set also the abbrevTitleCache
138
		//we need to think about handling protected not separate for abbrevTitleCache  and titleCache 
139
		if (result.equals(INomenclaturalReference.MICRO_REFERENCE_TOKEN) && nomenclaturalReference.isProtectedTitleCache() ){
140
			String cache = nomenclaturalReference.getTitleCache();
141
			return handleDetailAndYearForPreliminary(nomenclaturalReference, cache, microReference);
142
		}
143
		
144
		microReference = Nz(microReference);
128 145
		if (StringUtils.isNotBlank(microReference)){
129 146
			microReference = getBeforeMicroReference() + microReference;
130 147
			if (microReference.endsWith(".")  && result.contains(INomenclaturalReference.MICRO_REFERENCE_TOKEN + ".") ){
131 148
				microReference = microReference.substring(0, microReference.length() - 1);
132 149
			}
133 150
		}
134
		result = result.replaceAll(INomenclaturalReference.MICRO_REFERENCE_TOKEN, microReference);
151
		result = replaceMicroRefToken(microReference, result);
135 152
		if (result.startsWith(". ")){  //only year available, remove '. '
136 153
			result = result.substring(2);
137 154
		}
138 155
		return result;
139 156
	}
140 157

  
158
	/**
159
	 * @param microReference
160
	 * @param result
161
	 * @return
162
	 */
163
	private String replaceMicroRefToken(String microReference, String string) {
164
		int index = string.indexOf(INomenclaturalReference.MICRO_REFERENCE_TOKEN);
165
		String before = string.substring(0, index);
166
		String after = string.substring(index + INomenclaturalReference.MICRO_REFERENCE_TOKEN.length() );
167
		microReference = microReference.trim();   //needed ?
168
		if (after.length() > 0){
169
			if (  ("".equals(microReference) && before.endsWith(after.substring(0,1)) || microReference.endsWith(after.substring(0,1)))){
170
				after = after.substring(1);
171
			}
172
		}
173
		String result = before + microReference + after;
174
		return result;
175
	}
176

  
177
	/**
178
	 * @param nomenclaturalReference
179
	 * @param microRef
180
	 * @return
181
	 */
182
	private String handleDetailAndYearForPreliminary(Reference<?> nomenclaturalReference, String cache, String microReference) {
183
		String microRef = isNotBlank(microReference) ? getBeforeMicroReference() + microReference : "";
184
		if (cache == null){
185
			logger.warn("Cache is null. This should never be the case.");
186
			cache = "";
187
		}
188
		String	result = cache + (cache.contains(microRef) ? "" : microRef);
189

  
190
		String date = nomenclaturalReference.getDatePublishedString();
191
		if (isNotBlank(date) && ! result.contains(date)){
192
			result = result + beforeYear + date;
193
		}
194
		return result;
195
	}
196

  
141 197
}
cdmlib-model/src/main/java/eu/etaxonomy/cdm/strategy/cache/reference/ReferenceDefaultCacheStrategy.java
24 24
	private static final long serialVersionUID = 4350124746874497766L;
25 25
	@SuppressWarnings("unused")
26 26
	private static final Logger logger = Logger.getLogger(ReferenceDefaultCacheStrategy.class);
27
	
28
	/**
29
	 * Constructor
30
	 */
31
	public ReferenceDefaultCacheStrategy(){
32
		super();
33
	}
34
	public static ReferenceDefaultCacheStrategy NewInstance(){
35
		return new ReferenceDefaultCacheStrategy();
36
	}
37
	
38
	
27

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

  
39 30
	
40 31
	protected String beforeYear = ". ";
41 32
	protected String afterYear = "";
......
44 35
	private String blank = " ";
45 36
	private String comma = ",";
46 37
	private String dot =".";
38

  
39
	
40
// ****************** FACTORY *******************************/	
41
	
42
	public static ReferenceDefaultCacheStrategy NewInstance(){
43
		return new ReferenceDefaultCacheStrategy();
44
	}
45
	
46
// ***************** CONSTRUCTOR ********************************/
47
	
48
	/**
49
	 * Constructor
50
	 */
51
	private ReferenceDefaultCacheStrategy(){
52
		super();
53
	}
54

  
55
	
47 56
	
48
	final static UUID uuid = UUID.fromString("763fe4a0-c79f-4f14-9693-631680225ec3");
49 57
	
50 58

  
51 59
	@Override
cdmlib-model/src/main/java/eu/etaxonomy/cdm/strategy/cache/reference/ThesisDefaultCacheStrategy.java
16 16
import eu.etaxonomy.cdm.model.reference.Reference;
17 17

  
18 18
public class ThesisDefaultCacheStrategy extends NomRefDefaultCacheStrategyBase implements  INomenclaturalReferenceCacheStrategy {
19
	@SuppressWarnings("unused")
19 20
	private static final Logger logger = Logger.getLogger(ThesisDefaultCacheStrategy.class);
20 21
	
21 22

  
cdmlib-model/src/main/java/eu/etaxonomy/cdm/strategy/cache/reference/WebPageDefaultCacheStrategy.java
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.common.CdmUtils;
16
import eu.etaxonomy.cdm.model.reference.Reference;
17

  
18
public class WebPageDefaultCacheStrategy extends NomRefDefaultCacheStrategyBase implements  INomenclaturalReferenceCacheStrategy {
19
	private static final long serialVersionUID = 7432751464904190022L;
20

  
21

  
22
	@SuppressWarnings("unused")
23
	private static final Logger logger = Logger.getLogger(WebPageDefaultCacheStrategy.class);
24
	
25

  
26
	private String prefixEdition = "ed.";
27
	private String prefixSeries = "ser.";
28
	private String prefixVolume = "vol.";
29
	private String blank = " ";
30
	private String comma = ",";
31
	private String dot =".";
32
	
33
	final static UUID uuid = UUID.fromString("7b36b548-88ee-4180-afc1-4b860db85fa5");
34
	
35
	@Override
36
	protected UUID getUuid() {
37
		return uuid; 
38
	}
39
	
40
	
41
	/**
42
	 * Factory method
43
	 * @return
44
	 */
45
	public static WebPageDefaultCacheStrategy NewInstance(){
46
		return new WebPageDefaultCacheStrategy();
47
	}
48
	
49
	/**
50
	 * Constructor
51
	 */
52
	private WebPageDefaultCacheStrategy(){
53
		super();
54
	}
55

  
56

  
57
	@Override
58
	public String getAbbrevTitleCache(Reference thesis) {
59
		return getTitleWithoutYearAndAuthor(thesis, true);
60
	}
61
	
62
	@Override
63
	protected String getTitleWithoutYearAndAuthor(Reference thesis, boolean isAbbrev){
64
		//FIXME this is only a very fast copy and paste from "Generic". Must still be cleaned !
65
		
66
		//titelAbbrev
67
		//TODO
68
		String titelAbbrev = CdmUtils.getPreferredNonEmptyString(thesis.getTitle(), thesis.getAbbrevTitle(), isAbbrev, true);
69
		
70
		//titelAbbrev
71
		String nomRefCache = titelAbbrev + blank;
72
	
73
		//delete .
74
		while (nomRefCache.endsWith(".")){
75
			nomRefCache = nomRefCache.substring(0, nomRefCache.length()-1);
76
		}
77
		
78
		return nomRefCache.trim();
79
	}
80

  
81

  
82
}

Also available in: Unified diff

Add picture from clipboard (Maximum size: 40 MB)