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.Article;
|
17
|
import eu.etaxonomy.cdm.model.reference.BibtexReference;
|
18
|
import eu.etaxonomy.cdm.model.reference.Book;
|
19
|
import eu.etaxonomy.cdm.model.reference.INomenclaturalReference;
|
20
|
import eu.etaxonomy.cdm.strategy.StrategyBase;
|
21
|
|
22
|
public class BibtexDefaultCacheStrategy <T extends BibtexReference> extends NomRefDefaultCacheStrategyBase<T> implements INomenclaturalReferenceCacheStrategy<T> {
|
23
|
private static final Logger logger = Logger.getLogger(BibtexDefaultCacheStrategy.class);
|
24
|
|
25
|
private String prefixSeries = "ser.";
|
26
|
private String prefixVolume = "vol.";
|
27
|
private String prefixReferenceJounal = "in";
|
28
|
private String blank = " ";
|
29
|
private String comma = ",";
|
30
|
private String dot =".";
|
31
|
|
32
|
final static UUID uuid = UUID.fromString("ede34ca3-6cf7-4821-b975-046275f60d24");
|
33
|
|
34
|
/* (non-Javadoc)
|
35
|
* @see eu.etaxonomy.cdm.strategy.StrategyBase#getUuid()
|
36
|
*/
|
37
|
@Override
|
38
|
protected UUID getUuid() {
|
39
|
return uuid;
|
40
|
}
|
41
|
|
42
|
|
43
|
/**
|
44
|
* Factory method
|
45
|
* @return
|
46
|
*/
|
47
|
public static BibtexDefaultCacheStrategy NewInstance(){
|
48
|
return new BibtexDefaultCacheStrategy();
|
49
|
}
|
50
|
|
51
|
/**
|
52
|
* Constructor
|
53
|
*/
|
54
|
private BibtexDefaultCacheStrategy(){
|
55
|
super();
|
56
|
}
|
57
|
|
58
|
protected String getNomRefTitleWithoutYearAndAuthor(T article){
|
59
|
|
60
|
if (true){
|
61
|
//TODO
|
62
|
logger.warn("not yet implemented");
|
63
|
return null;
|
64
|
}
|
65
|
|
66
|
|
67
|
|
68
|
|
69
|
|
70
|
if (article == null){
|
71
|
return null;
|
72
|
}
|
73
|
//TODO
|
74
|
String titelAbbrev = CdmUtils.Nz(article.getTitle());
|
75
|
//TODO
|
76
|
String series = ""; //nomenclaturalReference.getSeries();
|
77
|
String volume = CdmUtils.Nz(article.getVolume());
|
78
|
|
79
|
String nomRefCache = "";
|
80
|
boolean lastCharIsDouble;
|
81
|
Integer len;
|
82
|
String lastChar;
|
83
|
String character =".";
|
84
|
len = titelAbbrev.length();
|
85
|
if (len > 0){lastChar = titelAbbrev.substring(len-1, len);}
|
86
|
//lastCharIsDouble = f_core_CompareStrings(RIGHT(@TitelAbbrev,1),character);
|
87
|
lastCharIsDouble = titelAbbrev.equals(character);
|
88
|
|
89
|
// if(lastCharIsDouble && edition.length() == 0 && series.length() == 0 && volume.length() == 0 && refYear.length() > 0 ){
|
90
|
// titelAbbrev = titelAbbrev.substring(1, len-1); // SUBSTRING(@TitelAbbrev,1,@LEN-1)
|
91
|
// }
|
92
|
|
93
|
|
94
|
boolean needsComma = false;
|
95
|
|
96
|
//inJournal
|
97
|
nomRefCache = prefixReferenceJounal + blank;
|
98
|
|
99
|
//titelAbbrev
|
100
|
String titelAbbrevPart = "";
|
101
|
if (!"".equals(titelAbbrev)){
|
102
|
nomRefCache = titelAbbrev + blank;
|
103
|
}
|
104
|
|
105
|
//inSeries
|
106
|
String seriesPart = "";
|
107
|
if (!"".equals(series)){
|
108
|
seriesPart = series;
|
109
|
if (isNumeric(series)){
|
110
|
seriesPart = prefixSeries + blank + seriesPart;
|
111
|
}
|
112
|
if (needsComma){
|
113
|
seriesPart = comma + seriesPart;
|
114
|
}
|
115
|
needsComma = true;
|
116
|
}
|
117
|
nomRefCache += seriesPart;
|
118
|
|
119
|
|
120
|
//volume Part
|
121
|
String volumePart = "";
|
122
|
if (!"".equals(volume)){
|
123
|
volumePart = volume;
|
124
|
if (needsComma){
|
125
|
volumePart = comma + blank + volumePart;
|
126
|
}
|
127
|
//needsComma = false;
|
128
|
}
|
129
|
nomRefCache += volumePart;
|
130
|
|
131
|
//delete .
|
132
|
while (nomRefCache.endsWith(".")){
|
133
|
nomRefCache = nomRefCache.substring(0, nomRefCache.length()-1);
|
134
|
}
|
135
|
|
136
|
return nomRefCache;
|
137
|
}
|
138
|
|
139
|
private boolean isNumeric(String string){
|
140
|
if (string == null){
|
141
|
return false;
|
142
|
}
|
143
|
try {
|
144
|
Double.valueOf(string);
|
145
|
return true;
|
146
|
} catch (NumberFormatException e) {
|
147
|
return false;
|
148
|
}
|
149
|
|
150
|
}
|
151
|
|
152
|
|
153
|
|
154
|
}
|