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