From f369ff9385daf0bd73c4444b5af9d4bf9a4e3ff6 Mon Sep 17 00:00:00 2001 From: Adam Collins Date: Tue, 9 Jul 2024 10:38:57 +1000 Subject: [PATCH] #602 improve display of concatenated occurrence properties --- .../ala/biocache/hubs/OccurrenceTagLib.groovy | 29 ++++++++++++++++--- 1 file changed, 25 insertions(+), 4 deletions(-) diff --git a/grails-app/taglib/au/org/ala/biocache/hubs/OccurrenceTagLib.groovy b/grails-app/taglib/au/org/ala/biocache/hubs/OccurrenceTagLib.groovy index 9c342009..cc067755 100644 --- a/grails-app/taglib/au/org/ala/biocache/hubs/OccurrenceTagLib.groovy +++ b/grails-app/taglib/au/org/ala/biocache/hubs/OccurrenceTagLib.groovy @@ -702,13 +702,13 @@ class OccurrenceTagLib { def tagBody if (cr.processed && cr.raw && cr.processed == cr.raw) { - tagBody = cr.processed + tagBody = pipeWhitespace(cr.processed) } else if (!cr.raw && cr.processed) { - tagBody = cr.processed + tagBody = pipeWhitespace(cr.processed) } else if (cr.raw && !cr.processed) { - tagBody = cr.raw + tagBody = pipeWhitespace(cr.raw) } else { - tagBody = "${cr.processed}
${alatag.message(code:"alatag.supplied.as")} ${cr.raw}" + tagBody = "${pipeWhitespace(cr.processed)}
${alatag.message(code:"alatag.supplied.as")} ${cr.raw}" } output += occurrenceTableRow(annotate:"true", section:"dataset", fieldCode:"${key}", fieldName:"${label}") { tagBody @@ -718,6 +718,11 @@ class OccurrenceTagLib { out << output } + def pipeWhitespace(str) { + // inject whitespace around pipe + str.replaceAll("(?<=\\S)\\|(?=\\S)", " | ") + } + def formatDynamicLabel(str){ if(str){ str.substring(0, str.length() - 2).replaceAll("_", " ") @@ -1048,9 +1053,24 @@ class OccurrenceTagLib { * @return output sanitized HTML String */ String sanitizeBodyText(String input, Boolean openInNewWindow = true) { + // input can be concatenated values, so we need to split it, but only when it is not escaped HTML +// if (input.contains("|")) { +// String output = "" +// String [] inputParts = input.split("\\|") +// for (String part : inputParts) { +// // retain the separator with whitespace +// if (output.size() > 0) { +// output += " | " +// } +// output += sanitizeBodyText(part.trim(), openInNewWindow) +// } +// return output +// } + // text with HTML tags will be escaped, so first we need to unescape it String unescapedHtml = StringEscapeUtils.unescapeHtml(input) // Sanitize the HTML and only allow links with valid URLs, span and br tags + log.error(unescapedHtml) PolicyFactory policy = new HtmlPolicyBuilder() .allowElements("a") .allowElements("br") @@ -1065,6 +1085,7 @@ class OccurrenceTagLib { .allowAttributes("id").onElements("span") .toFactory() String sanitizedHtml = policy.sanitize(unescapedHtml) + log.error(sanitizedHtml) if (openInNewWindow) { // hack to force links to be opened in new window/tab