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
.commons
.lang
.StringUtils
;
14 import org
.apache
.log4j
.Logger
;
16 import eu
.etaxonomy
.cdm
.common
.CdmUtils
;
17 import eu
.etaxonomy
.cdm
.model
.agent
.TeamOrPersonBase
;
18 import eu
.etaxonomy
.cdm
.model
.reference
.IJournal
;
19 import eu
.etaxonomy
.cdm
.model
.reference
.Reference
;
21 public class ArticleDefaultCacheStrategy
<T
extends Reference
> extends NomRefDefaultCacheStrategyBase
<T
> implements INomenclaturalReferenceCacheStrategy
<T
> {
22 @SuppressWarnings("unused")
23 private static final Logger logger
= Logger
.getLogger(ArticleDefaultCacheStrategy
.class);
25 public static final String UNDEFINED_JOURNAL
= "- undefined journal -";
26 private String prefixReferenceJounal
= "in";
27 private String blank
= " ";
28 private String comma
= ",";
29 private String prefixSeries
= "ser.";
31 final static UUID uuid
= UUID
.fromString("0d45343a-0c8a-4a64-97ca-e94974b65c96");
34 * @see eu.etaxonomy.cdm.strategy.StrategyBase#getUuid()
37 protected UUID
getUuid() {
46 public static ArticleDefaultCacheStrategy
NewInstance(){
47 return new ArticleDefaultCacheStrategy();
53 private ArticleDefaultCacheStrategy(){
60 public String
getTitleCache(T article
) {
61 if (article
.isProtectedTitleCache()){
62 return article
.getTitleCache();
64 String result
= getTitleWithoutYearAndAuthor(article
, false);
65 result
= addYear(result
, article
, false);
66 TeamOrPersonBase
<?
> team
= article
.getAuthorTeam();
67 result
= CdmUtils
.concat(" ", article
.getTitle(), result
);
68 if (team
!= null && StringUtils
.isNotBlank(team
.getTitleCache())){
69 String authorSeparator
= StringUtils
.isNotBlank(article
.getTitle())? afterAuthor
: " ";
70 result
= team
.getTitleCache() + authorSeparator
+ result
;
76 public String
getAbbrevTitleCache(T article
) {
77 if (article
.isProtectedAbbrevTitleCache()){
78 return article
.getAbbrevTitleCache();
80 String result
= getTitleWithoutYearAndAuthor(article
, true);
81 result
= addYear(result
, article
, false);
82 TeamOrPersonBase
<?
> team
= article
.getAuthorTeam();
83 String articleTitle
= CdmUtils
.getPreferredNonEmptyString(article
.getAbbrevTitle(), article
.getTitle(), false, true);
84 result
= CdmUtils
.concat(" ", articleTitle
, result
); //Article should maybe left out for nomenclatural references (?)
85 if (team
!= null && StringUtils
.isNotBlank(team
.getNomenclaturalTitle())){
86 String authorSeparator
= StringUtils
.isNotBlank(articleTitle
) ? afterAuthor
: " ";
87 result
= team
.getNomenclaturalTitle() + authorSeparator
+ result
;
93 protected String
getTitleWithoutYearAndAuthor(T article
, boolean isAbbrev
){
97 IJournal journal
= article
.getInReference();
98 boolean hasJournal
= (journal
!= null);
102 journalTitel
= CdmUtils
.getPreferredNonEmptyString(journal
.getTitle(), journal
.getAbbrevTitle(), isAbbrev
, true);
104 journalTitel
= UNDEFINED_JOURNAL
;
107 String series
= Nz(article
.getSeries()).trim();
108 String volume
= Nz(article
.getVolume()).trim();
110 boolean needsComma
= false;
112 String nomRefCache
= "";
115 nomRefCache
= prefixReferenceJounal
+ blank
;
118 if (isNotBlank(journalTitel
)){
119 nomRefCache
= nomRefCache
+ journalTitel
+ blank
;
122 nomRefCache
= getSeriesAndVolPart(series
, volume
, needsComma
, nomRefCache
);
125 while (nomRefCache
.endsWith(".")){
126 nomRefCache
= nomRefCache
.substring(0, nomRefCache
.length()-1);
129 return nomRefCache
.trim();
132 protected String
getSeriesAndVolPart(String series
, String volume
,
133 boolean needsComma
, String nomRefCache
) {
135 String seriesPart
= "";
136 if (isNotBlank(series
)){
138 if (CdmUtils
.isNumeric(series
)){
139 seriesPart
= prefixSeries
+ blank
+ seriesPart
;
142 seriesPart
= comma
+ seriesPart
;
146 nomRefCache
+= seriesPart
;
150 String volumePart
= "";
151 if (!"".equals(volume
)){
154 volumePart
= comma
+ blank
+ volumePart
;
156 //needsComma = false;
158 nomRefCache
+= volumePart
;