From: David ‘Bombe’ Roden Date: Sun, 10 Nov 2013 14:28:12 +0000 (+0100) Subject: React correctly when parameters are not given. X-Git-Url: https://git.pterodactylus.net/?a=commitdiff_plain;h=78443031f591347e11bad7e3cc8d80df6c30ce1d;p=Sone.git React correctly when parameters are not given. --- diff --git a/src/main/java/net/pterodactylus/sone/template/ImageLinkFilter.java b/src/main/java/net/pterodactylus/sone/template/ImageLinkFilter.java index 692b1cb..ea863f9 100644 --- a/src/main/java/net/pterodactylus/sone/template/ImageLinkFilter.java +++ b/src/main/java/net/pterodactylus/sone/template/ImageLinkFilter.java @@ -73,11 +73,11 @@ public class ImageLinkFilter implements Filter { if (image == null) { return null; } - String imageClass = String.valueOf(parameters.get("class")); + String imageClass = getParameterAsString(parameters, "class"); int maxWidth = Numbers.safeParseInteger(parameters.get("max-width"), Integer.MAX_VALUE); int maxHeight = Numbers.safeParseInteger(parameters.get("max-height"), Integer.MAX_VALUE); - String mode = String.valueOf(parameters.get("mode")); - String title = String.valueOf(parameters.get("title")); + String mode = getParameterAsString(parameters, "mode"); + String title = getParameterAsString(parameters, "title"); TemplateContext linkTemplateContext = templateContextFactory.createTemplateContext(); linkTemplateContext.set("class", imageClass); @@ -111,4 +111,9 @@ public class ImageLinkFilter implements Filter { return stringWriter.toString(); } + private static String getParameterAsString(Map parameters, String key) { + Object parameter = parameters.get(key); + return (parameter == null) ? null : String.valueOf(parameter); + } + }