Skip to content

Commit

Permalink
Merge branch 'release/1.9.9'
Browse files Browse the repository at this point in the history
  • Loading branch information
patkyn committed Jul 7, 2020
2 parents 746fdfb + d0ef9ad commit 963368f
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 9 deletions.
2 changes: 1 addition & 1 deletion CollectoryGrailsPlugin.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class CollectoryGrailsPlugin {
def authenticateService

// the plugin version
def version = "1.9.9-SNAPSHOT"
def version = "1.9.9"
// the version or versions of Grails the plugin is designed for
def grailsVersion = "2.5 > *"
// resources that are excluded from plugin packaging
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -705,7 +705,7 @@ class EmlRenderService {
*/
def handleLinks(str) {
if (str) {
def urlMatch = /\[(http:\S*)\b ([^\]]*)\]/ // [http: + text to next word boundary + space + all text until next ]
def urlMatch = /\[(https?:\S*)\b ([^\]]*)\]/ // [(http + s(optional) + : + text to next word boundary + space + all text until next ]
str = str.replaceAll(urlMatch) {s1, s2, s3 ->
"${s2} (${s3})"
}
Expand Down
7 changes: 4 additions & 3 deletions grails-app/services/au/org/ala/collectory/IptService.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ import groovy.util.slurpersupport.GPathResult
import javax.activation.DataSource
import java.nio.charset.StandardCharsets
import java.sql.Timestamp
import java.text.SimpleDateFormat
import java.time.LocalDateTime
import java.time.format.DateTimeFormatter

/**
* Collect datasets from an IPT service and update the metadata.
Expand All @@ -34,7 +35,7 @@ class IptService {
/** Source of the RSS feed */
static final RSS_PATH = "rss.do"
/** Parse RFC 822 date/times */
static final RFC822_PARSER = new SimpleDateFormat('EEE, d MMM yyyy HH:mm:ss Z')
static final RFC822_FORMATTER = DateTimeFormatter.RFC_1123_DATE_TIME

/** Fields that we can derive from the RSS feed */
protected rssFields = [
Expand All @@ -45,7 +46,7 @@ class IptService {
dataCurrency: { item ->
def pd = item.pubDate?.text()

pd == null || pd.isEmpty() ? null : new Timestamp(RFC822_PARSER.parse(pd).getTime())
pd == null || pd.isEmpty() ? null : Timestamp.valueOf(LocalDateTime.parse(pd, RFC822_FORMATTER))
},
lastChecked: { item -> new Timestamp(System.currentTimeMillis()) },
provenance: { item -> "Published dataset" },
Expand Down
27 changes: 23 additions & 4 deletions grails-app/taglib/au/org/ala/collectory/CollectoryTagLib.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -848,7 +848,7 @@ class CollectoryTagLib {

// in-line links
if (!attrs.noLink) {
def urlMatch = /[^\[](http:\S*)\b/ // word boundary + http: + non-whitespace + word boundary
def urlMatch = /[^\[](https?:\S*)\b/ // [http + s(optional) + : + word boundary + http: + non-whitespace + word boundary
text = text.replaceAll(urlMatch) {s1, s2 ->
if (s2.indexOf('ala.org.au') > 0)
" <a href='${s2}'>${s2}</a>"
Expand All @@ -859,7 +859,7 @@ class CollectoryTagLib {

// wiki-like links
if (!attrs.noLink) {
def urlMatch = /\[(http:\S*)\b ([^\]]*)\]/ // [http: + text to next word boundary + space + all text ubtil next ]
def urlMatch = /\[(https?:\S*)\b ([^\]]*)\]/ // [http + s(optional) + : + text to next word boundary + space + all text ubtil next ]
text = text.replaceAll(urlMatch) {s1, s2, s3 ->
if (s2.indexOf('ala.org.au') > 0)
"<a href='${s2}'>${s3}</a>"
Expand Down Expand Up @@ -2056,10 +2056,29 @@ class CollectoryTagLib {
}
}

/***
* A quick test to check if the url is valid.
* @param targetUrl - the url to check
* @return true if the url is valid
* false if the url is invalid
*/
private boolean isUrlValid(String targetUrl) {
try {
def u = new java.net.URL(targetUrl).openStream()
u.close()
return true
} catch(Exception e){
return false
}
return false
}

def externalLink = { attrs ->
def href = attrs.href
if (!attrs.href?.startsWith("http://")) {
href = "http://" + href
if (!attrs.href?.startsWith("http")) {
String httpHref = "http://" + href
// A quick test to check if http url is valid and default it to https otherwise.
href = isUrlValid(httpHref)? httpHref: "https://" + href
}
out << """<a class="external_icon" target="_blank" href="${href}">${attrs.href}</a>"""
}
Expand Down

0 comments on commit 963368f

Please sign in to comment.