From 78443031f591347e11bad7e3cc8d80df6c30ce1d Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Sun, 10 Nov 2013 15:28:12 +0100 Subject: [PATCH] React correctly when parameters are not given. --- .../java/net/pterodactylus/sone/template/ImageLinkFilter.java | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) 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); + } + } -- 2.7.4