2 * Copyright (C) 2007 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
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.
9 package eu
.etaxonomy
.cdm
.strategy
.cache
.reference
;
11 import java
.util
.UUID
;
13 import org
.apache
.log4j
.Logger
;
15 import eu
.etaxonomy
.cdm
.common
.CdmUtils
;
16 import eu
.etaxonomy
.cdm
.model
.agent
.TeamOrPersonBase
;
17 import eu
.etaxonomy
.cdm
.model
.reference
.IJournal
;
18 import eu
.etaxonomy
.cdm
.model
.reference
.Reference
;
20 public class ArticleDefaultCacheStrategy
extends NomRefDefaultCacheStrategyBase
implements INomenclaturalReferenceCacheStrategy
{
21 private static final long serialVersionUID
= -1639068590864589314L;
23 @SuppressWarnings("unused")
24 private static final Logger logger
= Logger
.getLogger(ArticleDefaultCacheStrategy
.class);
26 public static final String UNDEFINED_JOURNAL
= "- undefined journal -";
27 private String prefixReferenceJounal
= "in";
28 private String blank
= " ";
29 private String comma
= ",";
30 private String prefixSeries
= "ser.";
33 final static UUID uuid
= UUID
.fromString("0d45343a-0c8a-4a64-97ca-e94974b65c96");
36 protected UUID
getUuid() {
45 public static ArticleDefaultCacheStrategy
NewInstance(){
46 return new ArticleDefaultCacheStrategy();
52 private ArticleDefaultCacheStrategy(){
57 public String
getTitleCache(Reference article
) {
58 if (article
.isProtectedTitleCache()){
59 return article
.getTitleCache();
61 String result
= getTitleWithoutYearAndAuthor(article
, false);
62 result
= addYear(result
, article
, false);
63 TeamOrPersonBase
<?
> team
= article
.getAuthorship();
64 result
= CdmUtils
.concat(" ", article
.getTitle(), result
);
65 if (team
!= null && isNotBlank(team
.getTitleCache())){
66 String authorSeparator
= isNotBlank(article
.getTitle())? afterAuthor
: " ";
67 result
= team
.getTitleCache() + authorSeparator
+ result
;
73 public String
getAbbrevTitleCache(Reference article
) {
74 if (article
.isProtectedAbbrevTitleCache()){
75 return article
.getAbbrevTitleCache();
77 String result
= getTitleWithoutYearAndAuthor(article
, true);
78 result
= addYear(result
, article
, false);
79 TeamOrPersonBase
<?
> team
= article
.getAuthorship();
80 String articleTitle
= CdmUtils
.getPreferredNonEmptyString(article
.getAbbrevTitle(), article
.getTitle(), false, true);
81 result
= CdmUtils
.concat(" ", articleTitle
, result
); //Article should maybe left out for nomenclatural references (?)
82 if (team
!= null && isNotBlank(team
.getNomenclaturalTitle())){
83 String authorSeparator
= isNotBlank(articleTitle
) ? afterAuthor
: " ";
84 result
= team
.getNomenclaturalTitle() + authorSeparator
+ result
;
90 protected String
getTitleWithoutYearAndAuthor(Reference article
, boolean isAbbrev
){
94 IJournal journal
= article
.getInReference();
95 boolean hasJournal
= (journal
!= null);
99 journalTitel
= CdmUtils
.getPreferredNonEmptyString(journal
.getTitle(), journal
.getAbbrevTitle(), isAbbrev
, true);
101 journalTitel
= UNDEFINED_JOURNAL
;
104 String series
= Nz(article
.getSeriesPart()).trim();
105 String volume
= Nz(article
.getVolume()).trim();
107 boolean needsComma
= false;
109 String nomRefCache
= "";
112 nomRefCache
= prefixReferenceJounal
+ blank
;
115 if (isNotBlank(journalTitel
)){
116 nomRefCache
= nomRefCache
+ journalTitel
;
117 needsComma
= makeNeedsComma(needsComma
, nomRefCache
, volume
, series
);
119 nomRefCache
= nomRefCache
+ blank
;
124 nomRefCache
= getSeriesAndVolPart(series
, volume
, needsComma
, nomRefCache
);
127 while (nomRefCache
.endsWith(".")){
128 nomRefCache
= nomRefCache
.substring(0, nomRefCache
.length()-1);
131 return nomRefCache
.trim();
134 private boolean makeNeedsComma(boolean needsComma
, String nomRefCache
, String volume
, String series
) {
138 nomRefCache
= nomRefCache
.toLowerCase();
139 int serIndex
= nomRefCache
.indexOf(" ser. ");
140 int sectIndex
= nomRefCache
.indexOf(" sect. ");
141 int abtIndex
= nomRefCache
.indexOf(" abt. ");
142 int index
= Math
.max(Math
.max(serIndex
, sectIndex
), abtIndex
);
143 int commaIndex
= nomRefCache
.indexOf(",", index
);
144 if (index
> -1 && commaIndex
== -1 && isNotBlank(volume
)){
146 }else if (isNotBlank(series
)){
154 protected String
getSeriesAndVolPart(String series
, String volume
,
155 boolean needsComma
, String nomRefCache
) {
157 String seriesPart
= "";
158 if (isNotBlank(series
)){
160 if (CdmUtils
.isNumeric(series
)){
161 seriesPart
= prefixSeries
+ blank
+ seriesPart
;
164 seriesPart
= comma
+ blank
+ seriesPart
;
168 nomRefCache
+= seriesPart
;
172 String volumePart
= "";
173 if (!"".equals(volume
)){
176 volumePart
= comma
+ blank
+ volumePart
;
178 //needsComma = false;
180 nomRefCache
+= volumePart
;