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
.common
.TimePeriod
;
19 import eu
.etaxonomy
.cdm
.model
.reference
.INomenclaturalReference
;
20 import eu
.etaxonomy
.cdm
.model
.reference
.Reference
;
22 public class BookSectionDefaultCacheStrategy
<T
extends Reference
> extends NomRefDefaultCacheStrategyBase
<T
> implements INomenclaturalReferenceCacheStrategy
<T
> {
23 private static final Logger logger
= Logger
.getLogger(BookSectionDefaultCacheStrategy
.class);
25 public static final String UNDEFINED_BOOK
= "- undefined book -";
26 private String afterSectionAuthor
= " - ";
27 private String afterNomRefBookAuthor
= ", ";
28 private String inBook
= "in ";
29 private String blank
= " ";
31 final static UUID uuid
= UUID
.fromString("f9c53f20-addd-4d2f-9697-ef1fe727deba");
34 * @see eu.etaxonomy.cdm.strategy.StrategyBase#getUuid()
37 protected UUID
getUuid() {
46 public static BookSectionDefaultCacheStrategy
NewInstance(){
47 return new BookSectionDefaultCacheStrategy();
53 private BookSectionDefaultCacheStrategy(){
60 * @see eu.etaxonomy.cdm.strategy.cache.reference.INomenclaturalReferenceCacheStrategy#getTokenizedNomenclaturalTitel(eu.etaxonomy.cdm.model.reference.INomenclaturalReference)
63 public String
getTokenizedNomenclaturalTitel(T bookSection
) {
64 if (bookSection
== null /* || bookSection.getInReference() == null */){
67 Reference inBook
= bookSection
.getInReference();
69 //use booksection's publication date if it exists
70 if ( (bookSection
.getDatePublished() != null && bookSection
.getDatePublished().getStart() != null) || inBook
== null){
71 BookDefaultCacheStrategy
<Reference
> bookStrategy
= BookDefaultCacheStrategy
.NewInstance();
72 result
= inBook
== null ?
"" : bookStrategy
.getNomRefTitleWithoutYearAndAuthor(inBook
);
73 result
+= INomenclaturalReference
.MICRO_REFERENCE_TOKEN
;
74 result
= addYear(result
, bookSection
);
76 //else use book's publication date
77 result
= inBook
.getNomenclaturalCitation(INomenclaturalReference
.MICRO_REFERENCE_TOKEN
);
78 result
= result
.replace(beforeMicroReference
+ INomenclaturalReference
.MICRO_REFERENCE_TOKEN
, INomenclaturalReference
.MICRO_REFERENCE_TOKEN
);
80 result
= getBookAuthorPart(bookSection
.getInReference(), afterNomRefBookAuthor
) + result
;
81 result
= "in " + result
;
86 * @see eu.etaxonomy.cdm.strategy.cache.reference.INomenclaturalReferenceCacheStrategy#getTitleCache(eu.etaxonomy.cdm.model.reference.INomenclaturalReference)
89 public String
getTitleCache(T bookSection
) {
90 boolean hasBook
= (bookSection
.getInBook() != null);
94 result
= bookSection
.getInReference().getTitleCache();
96 result
= "- undefined book -";
100 result
= inBook
+ result
;
103 String title
= CdmUtils
.Nz(bookSection
.getTitle());
104 if (title
.length() > 0){
105 result
= title
+ blank
+ result
;
109 TeamOrPersonBase
<?
> sectionTeam
= bookSection
.getAuthorTeam();
110 String sectionAuthor
= CdmUtils
.Nz(sectionTeam
== null ?
"" : sectionTeam
.getTitleCache());
111 result
= sectionAuthor
+ afterSectionAuthor
+ result
;
114 if (bookSection
.getDatePublished() != null && ! bookSection
.getDatePublished().isEmpty()){
115 String bookSectionDate
= bookSection
.getDatePublished().toString();
116 if (hasBook
&& bookSection
.getInBook().getDatePublished() != null){
117 TimePeriod bookDate
= bookSection
.getInBook().getDatePublished();
118 String bookDateString
= bookDate
.getYear();
119 if (CdmUtils
.isNotEmpty(bookDateString
)){
120 int pos
= StringUtils
.lastIndexOf(result
, bookDateString
);
122 result
= result
.substring(0, pos
) + bookSectionDate
+ result
.substring(pos
+ bookDateString
.length());
124 logger
.warn("BookDateString (" + bookDateString
+ ") could not be found in result (" + result
+")");
127 result
= result
+ beforeYear
+ bookSectionDate
+ afterYear
;
130 result
= result
+ beforeYear
+ bookSectionDate
+ afterYear
;
136 private String
getBookAuthorPart(Reference book
, String seperator
){
140 TeamOrPersonBase
<?
> team
= book
.getAuthorTeam();
141 String result
= CdmUtils
.Nz( team
== null ?
"" : team
.getTitleCache());
142 if (! result
.trim().equals("")){
143 result
= result
+ seperator
;
150 * @see eu.etaxonomy.cdm.strategy.cache.reference.NomRefDefaultCacheStrategyBase#getNomRefTitleWithoutYearAndAuthor(eu.etaxonomy.cdm.model.reference.Reference)
153 protected String
getNomRefTitleWithoutYearAndAuthor(T reference
) {
154 // not needed in BookSection
155 logger
.warn("Questionable procedure call. Procedure not implemented because not needed. ");