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