import net.pterodactylus.util.template.TemplateContextFactory;
import net.pterodactylus.util.template.TemplateParser;
+import com.google.common.base.Function;
import com.google.common.base.Optional;
/**
if (image == null) {
return null;
}
- String imageClass = valueOf(parameters.get("class"));
+ String imageClass = Optional.fromNullable(parameters.get("class")).transform(getStringValue()).orNull();
int maxWidth = parseInt(valueOf(parameters.get("max-width")), MAX_VALUE);
int maxHeight = parseInt(valueOf(parameters.get("max-height")), MAX_VALUE);
String mode = valueOf(parameters.get("mode"));
- String title = valueOf(parameters.get("title"));
+ String title = Optional.fromNullable(parameters.get("title")).transform(getStringValue()).orNull();
TemplateContext linkTemplateContext = templateContextFactory.createTemplateContext();
linkTemplateContext.set("class", imageClass);
linkTemplateContext.set("src", "/" + image.getKey());
linkTemplateContext.set("forceDownload", true);
} else {
- linkTemplateContext.set("src", "getImage.html?image=" + image.getId());
+ linkTemplateContext.set("src", "getImage.html?image=" + image.getInternalId());
}
int imageWidth = image.getWidth();
int imageHeight = image.getHeight();
return stringWriter.toString();
}
+ private Function<Object, String> getStringValue() {
+ return new Function<Object, String>() {
+ @Override
+ public String apply(Object input) {
+ return (input != null) ? input.toString() : null;
+ }
+ };
+ }
+
}