55 |
55 |
|
56 |
56 |
private final static UUID uuid = UUID.fromString("63e669ca-c6be-4a8a-b157-e391c22580f9");
|
57 |
57 |
|
58 |
|
//article
|
59 |
|
public static final String UNDEFINED_JOURNAL = "undefined journal " + UTF8.EN_DASH;
|
60 |
58 |
private static final String afterAuthor = ": ";
|
61 |
|
|
62 |
|
//book
|
63 |
|
|
64 |
|
//(book?) section
|
65 |
|
private static final String afterSectionAuthor = ": ";
|
66 |
59 |
private static final String afterInRefAuthor = ", "; //TODO needs discussion
|
67 |
60 |
|
|
61 |
//article
|
|
62 |
public static final String UNDEFINED_JOURNAL = "undefined journal " + UTF8.EN_DASH;
|
68 |
63 |
|
69 |
64 |
//in reference
|
70 |
|
private String biblioInSeparator = UTF8.EN_DASH + " In: "; //#9529
|
|
65 |
private static String biblioInSeparator = " " + UTF8.EN_DASH + " In: "; //#9529
|
71 |
66 |
private String biblioArticleInSeparator = UTF8.EN_DASH + " "; //#9529
|
|
67 |
private String webpageUriSeparator = " "+UTF8.EN_DASH+" ";
|
72 |
68 |
|
73 |
69 |
//common
|
74 |
70 |
private static final String blank = " ";
|
... | ... | |
126 |
122 |
result = titleCacheDefaultReference(reference, isNotAbbrev);
|
127 |
123 |
}
|
128 |
124 |
if (reference.getType() == ReferenceType.WebPage && reference.getUri() != null && !result.contains(reference.getUri().toString())){
|
129 |
|
result = CdmUtils.concat(" "+UTF8.EN_DASH+" ", result, reference.getUri().toString());
|
|
125 |
result = CdmUtils.concat(webpageUriSeparator, result, reference.getUri().toString());
|
130 |
126 |
}
|
131 |
127 |
if(reference.getAccessed() != null){
|
132 |
128 |
//TODO still a bit preliminary, also brackets may change in future
|
... | ... | |
214 |
210 |
|
215 |
211 |
//section, book section or generic with inRef
|
216 |
212 |
private String titleCacheRealInRef(Reference reference, boolean isAbbrev) {
|
217 |
|
ReferenceType type = reference.getType();
|
|
213 |
|
218 |
214 |
Reference inRef = reference.getInReference();
|
219 |
|
boolean hasInRef = (inRef != null);
|
220 |
215 |
|
221 |
|
String inRefAuthorAndTitle;
|
222 |
|
//copy from InRefDefaultCacheStrategyBase
|
223 |
|
if (inRef != null){
|
224 |
|
String inRefTitle = TitleWithoutYearAndAuthorHelper.getTitleWithoutYearAndAuthor(inRef, isAbbrev, false);
|
225 |
|
TeamOrPersonBase<?> inRefAuthor = inRef.getAuthorship();
|
226 |
|
String authorStr = (inRefAuthor == null)? "" : CdmUtils.getPreferredNonEmptyString(inRefAuthor.getTitleCache(),
|
227 |
|
inRefAuthor.getNomenclaturalTitle(), isAbbrev, trim);
|
228 |
|
inRefAuthorAndTitle = CdmUtils.concat(afterInRefAuthor, authorStr, inRefTitle);
|
229 |
|
}else{
|
230 |
|
inRefAuthorAndTitle = String.format("- undefined %s -", getUndefinedLabel(type));
|
|
216 |
String inRefPart = getInRefAuthorAndTitle(inRef, reference.getType(), isAbbrev);
|
|
217 |
if (inRef != null && !inRef.isArticle()){
|
|
218 |
inRefPart = addInRefPages(inRef, inRefPart);
|
|
219 |
}
|
|
220 |
inRefPart = CdmUtils.addTrailingDotIfNotExists(inRefPart);
|
|
221 |
inRefPart = biblioInSeparator + inRefPart;
|
|
222 |
if (inRef != null && inRef.isBookSection()){
|
|
223 |
String inInRefPart = getInRefAuthorAndTitle(inRef.getInReference(), inRef.getType(), isAbbrev);
|
|
224 |
inInRefPart = CdmUtils.addTrailingDotIfNotExists(inInRefPart);
|
|
225 |
inInRefPart = biblioInSeparator + inInRefPart;
|
|
226 |
inRefPart += inInRefPart;
|
231 |
227 |
}
|
232 |
|
inRefAuthorAndTitle = CdmUtils.addTrailingDotIfNotExists(inRefAuthorAndTitle);
|
233 |
|
|
234 |
|
//in
|
235 |
|
String result = biblioInSeparator + inRefAuthorAndTitle;
|
236 |
228 |
|
237 |
229 |
//section title
|
238 |
230 |
String title = CdmUtils.getPreferredNonEmptyString(
|
... | ... | |
241 |
233 |
title = title.substring(0, title.length() - 1);
|
242 |
234 |
}
|
243 |
235 |
//pages
|
244 |
|
String pages = getPages(reference);
|
245 |
|
if (isNotBlank(pages)){
|
246 |
|
title = CdmUtils.concat(", ", title, pages);
|
247 |
|
}
|
|
236 |
title = addInRefPages(reference, title);
|
|
237 |
|
|
238 |
String result;
|
248 |
239 |
if (title.length() > 0){
|
249 |
|
result = title.trim() + "." + blank + result;
|
|
240 |
result = title.trim() + "." + inRefPart;
|
|
241 |
}else{
|
|
242 |
result = inRefPart;
|
250 |
243 |
}
|
251 |
244 |
|
252 |
245 |
//section author
|
... | ... | |
256 |
249 |
|
257 |
250 |
//date
|
258 |
251 |
String dateStr = null;
|
259 |
|
VerbatimTimePeriod date = (reference.getDatePublished() != null && ! reference.getDatePublished().isEmpty())? reference.getDatePublished() : null;
|
260 |
|
if (date == null && hasInRef && reference.getInReference().getDatePublished() != null && !reference.getInReference().getDatePublished().isEmpty()){
|
|
252 |
VerbatimTimePeriod date = reference.hasDatePublished() ? reference.getDatePublished() : null;
|
|
253 |
if (date == null && inRef != null && inRef.hasDatePublished()){
|
261 |
254 |
date = reference.getInReference().getDatePublished();
|
|
255 |
if (date == null && inRef.isSection() && inRef.getInReference() != null && inRef.getInReference().hasDatePublished()){
|
|
256 |
date = inRef.getInReference().getDatePublished();
|
|
257 |
}
|
262 |
258 |
}
|
263 |
259 |
if (date != null){
|
264 |
260 |
dateStr = date.getYear();
|
... | ... | |
266 |
262 |
|
267 |
263 |
String authorAndYear = CdmUtils.concat(" ", authorStr, dateStr);
|
268 |
264 |
|
269 |
|
String sep = result.startsWith(biblioInSeparator)? " ": afterSectionAuthor;
|
|
265 |
String sep = result.startsWith(biblioInSeparator)? "": afterAuthor;
|
270 |
266 |
result = CdmUtils.concat(sep, authorAndYear, result);
|
271 |
267 |
|
272 |
268 |
return result;
|
273 |
269 |
}
|
274 |
270 |
|
|
271 |
private String addInRefPages(Reference reference, String title) {
|
|
272 |
String pages = getPages(reference);
|
|
273 |
if (isNotBlank(pages)){
|
|
274 |
title = CdmUtils.concat(", ", title, pages);
|
|
275 |
}
|
|
276 |
return title;
|
|
277 |
}
|
|
278 |
|
|
279 |
private String getInRefAuthorAndTitle(Reference inRef, ReferenceType type, boolean isAbbrev) {
|
|
280 |
String inRefAuthorAndTitle;
|
|
281 |
if (inRef != null){
|
|
282 |
String inRefTitle = TitleWithoutYearAndAuthorHelper.getTitleWithoutYearAndAuthor(inRef, isAbbrev, false);
|
|
283 |
TeamOrPersonBase<?> inRefAuthor = inRef.getAuthorship();
|
|
284 |
String authorStr = (inRefAuthor == null)? "" : CdmUtils.getPreferredNonEmptyString(inRefAuthor.getTitleCache(),
|
|
285 |
inRefAuthor.getNomenclaturalTitle(), isAbbrev, trim);
|
|
286 |
inRefAuthorAndTitle = CdmUtils.concat(afterInRefAuthor, authorStr, inRefTitle);
|
|
287 |
}else{
|
|
288 |
inRefAuthorAndTitle = String.format("- undefined %s -", getUndefinedLabel(type));
|
|
289 |
}
|
|
290 |
|
|
291 |
return inRefAuthorAndTitle;
|
|
292 |
}
|
|
293 |
|
275 |
294 |
private static final String pageNoRe = "[0-9iIvVxXlLcCdDmM]+";
|
276 |
295 |
private String getPages(Reference reference) {
|
277 |
296 |
|
278 |
|
if (isBlank(reference.getPages())){
|
|
297 |
if (reference == null || isBlank(reference.getPages())){
|
279 |
298 |
return null;
|
280 |
299 |
}else if (reference.getPages().matches(pageNoRe + "\\s*[-"+UTF8.EN_DASH+"]\\s*"+ pageNoRe)){
|
281 |
300 |
return "pp. " + reference.getPages();
|
... | ... | |
380 |
399 |
}else if (type == ReferenceType.Generic){
|
381 |
400 |
return "generic reference";
|
382 |
401 |
}else if (type == ReferenceType.Section){
|
383 |
|
return "in reference";
|
|
402 |
return "in-reference";
|
384 |
403 |
} else {
|
385 |
|
return type.getLabel();
|
|
404 |
return "in-reference for " + type.getLabel();
|
386 |
405 |
}
|
387 |
406 |
}
|
388 |
407 |
|
ref #9326, ref #3764 fix secion in book-section handling and some cleanup in ReferenceDefaultCacheStrategy