Search in sources :

Example 1 with JacksonResource

use of org.onehippo.cms7.crisp.core.resource.jackson.JacksonResource in project hippo by NHS-digital-website.

the class SvgSimpleJacksonRestTemplateResourceResolver method isCacheable.

@Override
public boolean isCacheable(final Resource resource) {
    if (this.isCacheEnabled() && resource instanceof JacksonResource) {
        String data = resource.getValue("data", String.class);
        if (Objects.nonNull(data)) {
            byte[] decodedBytes = Base64.getDecoder().decode(data);
            String decodedString = new String(decodedBytes);
            Matcher regexMatcher = svgPattern.matcher(decodedString);
            if (regexMatcher.find()) {
                return true;
            } else {
                log.warn("Could not cache SVG resource. Its body contained: " + decodedString);
            }
        }
    }
    return false;
}
Also used : JacksonResource(org.onehippo.cms7.crisp.core.resource.jackson.JacksonResource) Matcher(java.util.regex.Matcher)

Aggregations

Matcher (java.util.regex.Matcher)1 JacksonResource (org.onehippo.cms7.crisp.core.resource.jackson.JacksonResource)1