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 private static final long serialVersionUID
= -1639068590864589314L;
24 @SuppressWarnings("unused")
25 private static final Logger logger
= Logger
.getLogger(ArticleDefaultCacheStrategy
.class);
27 public static final String UNDEFINED_JOURNAL
= "- undefined journal -";
28 private String prefixReferenceJounal
= "in";
29 private String blank
= " ";
30 private String comma
= ",";
31 private String prefixSeries
= "ser.";
33 final static UUID uuid
= UUID
.fromString("0d45343a-0c8a-4a64-97ca-e94974b65c96");
36 * @see eu.etaxonomy.cdm.strategy.StrategyBase#getUuid()
39 protected UUID
getUuid() {
48 public static ArticleDefaultCacheStrategy
NewInstance(){
49 return new ArticleDefaultCacheStrategy();
55 private ArticleDefaultCacheStrategy(){
62 public String
getTitleCache(T article
) {
63 if (article
.isProtectedTitleCache()){
64 return article
.getTitleCache();
66 String result
= getTitleWithoutYearAndAuthor(article
, false);
67 result
= addYear(result
, article
, false);
68 TeamOrPersonBase
<?
> team
= article
.getAuthorTeam();
69 result
= CdmUtils
.concat(" ", article
.getTitle(), result
);
70 if (team
!= null && StringUtils
.isNotBlank(team
.getTitleCache())){
71 String authorSeparator
= StringUtils
.isNotBlank(article
.getTitle())? afterAuthor
: " ";
72 result
= team
.getTitleCache() + authorSeparator
+ result
;
78 public String
getAbbrevTitleCache(T article
) {
79 if (article
.isProtectedAbbrevTitleCache()){
80 return article
.getAbbrevTitleCache();
82 String result
= getTitleWithoutYearAndAuthor(article
, true);
83 result
= addYear(result
, article
, false);
84 TeamOrPersonBase
<?
> team
= article
.getAuthorTeam();
85 String articleTitle
= CdmUtils
.getPreferredNonEmptyString(article
.getAbbrevTitle(), article
.getTitle(), false, true);
86 result
= CdmUtils
.concat(" ", articleTitle
, result
); //Article should maybe left out for nomenclatural references (?)
87 if (team
!= null && StringUtils
.isNotBlank(team
.getNomenclaturalTitle())){
88 String authorSeparator
= StringUtils
.isNotBlank(articleTitle
) ? afterAuthor
: " ";
89 result
= team
.getNomenclaturalTitle() + authorSeparator
+ result
;
95 protected String
getTitleWithoutYearAndAuthor(T article
, boolean isAbbrev
){
99 IJournal journal
= article
.getInReference();
100 boolean hasJournal
= (journal
!= null);
104 journalTitel
= CdmUtils
.getPreferredNonEmptyString(journal
.getTitle(), journal
.getAbbrevTitle(), isAbbrev
, true);
106 journalTitel
= UNDEFINED_JOURNAL
;
109 String series
= Nz(article
.getSeries()).trim();
110 String volume
= Nz(article
.getVolume()).trim();
112 boolean needsComma
= false;
114 String nomRefCache
= "";
117 nomRefCache
= prefixReferenceJounal
+ blank
;
120 if (isNotBlank(journalTitel
)){
121 nomRefCache
= nomRefCache
+ journalTitel
+ 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 protected String
getSeriesAndVolPart(String series
, String volume
,
135 boolean needsComma
, String nomRefCache
) {
137 String seriesPart
= "";
138 if (isNotBlank(series
)){
140 if (CdmUtils
.isNumeric(series
)){
141 seriesPart
= prefixSeries
+ blank
+ seriesPart
;
144 seriesPart
= comma
+ seriesPart
;
148 nomRefCache
+= seriesPart
;
152 String volumePart
= "";
153 if (!"".equals(volume
)){
156 volumePart
= comma
+ blank
+ volumePart
;
158 //needsComma = false;
160 nomRefCache
+= volumePart
;