/*
- * Sone - ParserFilter.java - Copyright © 2011–2013 David Roden
+ * Sone - ParserFilter.java - Copyright © 2011–2015 David Roden
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
package net.pterodactylus.sone.template;
+import static java.lang.String.valueOf;
+import static net.pterodactylus.sone.utils.NumberParsers.parseInt;
+
import java.io.IOException;
import java.io.StringReader;
import java.io.StringWriter;
import net.pterodactylus.util.template.TemplateContextFactory;
import net.pterodactylus.util.template.TemplateParser;
-import com.google.common.base.Optional;
-import com.google.common.primitives.Ints;
-
/**
* Filter that filters a given text through a {@link SoneTextParser}.
*
*/
@Override
public Object format(TemplateContext templateContext, Object data, Map<String, Object> parameters) {
- String text = String.valueOf(data);
- int length = Optional.fromNullable(Ints.tryParse(String.valueOf(parameters.get("length")))).or(-1);
- int cutOffLength = Optional.fromNullable(Ints.tryParse(String.valueOf(parameters.get("cut-off-length")))).or(length);
+ String text = valueOf(data);
+ int length = parseInt(valueOf(parameters.get("length")), -1);
+ int cutOffLength = parseInt(valueOf(parameters.get("cut-off-length")), length);
Object sone = parameters.get("sone");
if (sone instanceof String) {
- sone = core.getSone((String) sone, false);
+ sone = core.getSone((String) sone).orNull();
}
FreenetRequest request = (FreenetRequest) templateContext.get("request");
SoneTextParserContext context = new SoneTextParserContext(request, (Sone) sone);