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.
10 package eu
.etaxonomy
.cdm
.strategy
.cache
.reference
;
12 import org
.apache
.commons
.lang
.StringUtils
;
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
.INomenclaturalReference
;
18 import eu
.etaxonomy
.cdm
.model
.reference
.Reference
;
19 import eu
.etaxonomy
.cdm
.strategy
.StrategyBase
;
25 public abstract class NomRefDefaultCacheStrategyBase
extends StrategyBase
implements INomenclaturalReferenceCacheStrategy
{
26 private static final long serialVersionUID
= -725290113353165022L;
28 @SuppressWarnings("unused")
29 private static final Logger logger
= Logger
.getLogger(NomRefDefaultCacheStrategyBase
.class);
31 protected String beforeYear
= ". ";
32 protected String beforeMicroReference
= ": ";
33 protected String afterYear
= "";
34 protected String afterAuthor
= ", ";
38 public String
getTokenizedNomenclaturalTitel(Reference ref
) {
39 String result
= getTitleWithoutYearAndAuthor(ref
, true);
40 result
+= INomenclaturalReference
.MICRO_REFERENCE_TOKEN
;
41 result
= addYear(result
, ref
, true);
46 public String
getTitleCache(Reference nomenclaturalReference
) {
47 return getTitleCache(nomenclaturalReference
, false);
51 public String
getAbbrevTitleCache(Reference nomenclaturalReference
) {
52 return getTitleCache(nomenclaturalReference
, true);
55 private String
getTitleCache(Reference ref
, boolean isAbbrev
) {
57 if (isAbbrev
&& ref
.isProtectedAbbrevTitleCache()){
58 return ref
.getAbbrevTitleCache();
59 }else if (!isAbbrev
&& ref
.isProtectedTitleCache()){
60 return ref
.getTitleCache();
62 String result
= getTitleWithoutYearAndAuthor(ref
, isAbbrev
);
63 result
= addYear(result
, ref
, false);
64 TeamOrPersonBase
<?
> team
= ref
.getAuthorTeam();
67 String teamTitle
= CdmUtils
.getPreferredNonEmptyString(team
.getTitleCache(), team
.getNomenclaturalTitle(), isAbbrev
, true);
68 if (teamTitle
.length() > 0 ){
69 String concat
= isNotBlank(result
) ? afterAuthor
: "";
70 result
= team
.getTitleCache() + concat
+ result
;
77 protected abstract String
getTitleWithoutYearAndAuthor(Reference reference
, boolean isAbbrev
);
81 public String
getCitation(Reference referenceBase
) {
82 StringBuilder stringBuilder
= new StringBuilder();
84 String nextConcat
= "";
86 TeamOrPersonBase
<?
> team
= referenceBase
.getAuthorTeam();
87 if (team
!= null && ! (team
.getTitleCache() == null) && ! team
.getTitleCache().trim().equals("")){
88 stringBuilder
.append(team
.getTitleCache() );
89 nextConcat
= afterAuthor
;
92 String year
= referenceBase
.getYear();
93 if (StringUtils
.isNotBlank(year
)){
94 stringBuilder
.append(nextConcat
+ year
);
97 return stringBuilder
.toString();
102 public String
getBeforeMicroReference(){
103 return beforeMicroReference
;
106 protected String
addYear(String string
, Reference nomRef
, boolean useFullDatePublished
){
111 String year
= useFullDatePublished ? nomRef
.getDatePublishedString() : nomRef
.getYear();
112 if (StringUtils
.isBlank(year
)){
113 result
= string
+ afterYear
;
115 String concat
= isBlank(string
) ?
"" : string
.endsWith(".")?
" " : beforeYear
;
116 result
= string
+ concat
+ year
+ afterYear
;
122 public String
getNomenclaturalCitation(Reference nomenclaturalReference
, String microReference
) {
123 if (nomenclaturalReference
.isProtectedTitleCache()){
124 return nomenclaturalReference
.getTitleCache();
126 String result
= getTokenizedNomenclaturalTitel(nomenclaturalReference
);
127 microReference
= CdmUtils
.Nz(microReference
);
128 if (StringUtils
.isNotBlank(microReference
)){
129 microReference
= getBeforeMicroReference() + microReference
;
131 result
= result
.replaceAll(INomenclaturalReference
.MICRO_REFERENCE_TOKEN
, microReference
);