package net.pterodactylus.sone.template;
+import java.io.IOException;
+import java.io.StringReader;
+
import net.pterodactylus.sone.core.Core;
import net.pterodactylus.sone.data.Post;
import net.pterodactylus.sone.data.Sone;
+import net.pterodactylus.sone.text.FreenetLinkParser;
import net.pterodactylus.util.template.DataProvider;
import net.pterodactylus.util.template.ReflectionAccessor;
+import net.pterodactylus.util.template.TemplateFactory;
/**
* Accessor for {@link Post} objects that adds additional properties:
*/
public class PostAccessor extends ReflectionAccessor {
+ /** Parser for Freenet links. */
+ private final FreenetLinkParser linkParser;
+
/** The core to get the replies from. */
private final Core core;
*
* @param core
* The core to get the replies from
+ * @param templateFactory
+ * The template factory for the text parser
*/
- public PostAccessor(Core core) {
+ public PostAccessor(Core core, TemplateFactory templateFactory) {
this.core = core;
+ linkParser = new FreenetLinkParser(templateFactory);
}
/**
return (currentSone != null) && (currentSone.isLikedPostId(post.getId()));
} else if (member.equals("new")) {
return core.isNewPost(post.getId(), false);
+ } else if (member.equals("text")) {
+ String text = post.getText();
+ if (text == null) {
+ return null;
+ }
+ try {
+ return linkParser.parse(new StringReader(text));
+ } catch (IOException ioe1) {
+ /* ignore. */
+ }
}
return super.get(dataProvider, object, member);
}