X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Fmain%2Fjava%2Fnet%2Fpterodactylus%2Fsone%2Ftemplate%2FPostAccessor.java;h=746ed256593a57703e616748222151ccde1933c8;hb=74f4317a5515c53c39690c8d75f396c472e20ae9;hp=574eb1cf8929361c51482117683dd0a80a38552c;hpb=fbc4cd017e9453094a63f92a87951caa31d8de71;p=Sone.git diff --git a/src/main/java/net/pterodactylus/sone/template/PostAccessor.java b/src/main/java/net/pterodactylus/sone/template/PostAccessor.java index 574eb1c..746ed25 100644 --- a/src/main/java/net/pterodactylus/sone/template/PostAccessor.java +++ b/src/main/java/net/pterodactylus/sone/template/PostAccessor.java @@ -17,11 +17,16 @@ 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: @@ -34,6 +39,9 @@ import net.pterodactylus.util.template.ReflectionAccessor; */ public class PostAccessor extends ReflectionAccessor { + /** Parser for Freenet links. */ + private final FreenetLinkParser linkParser; + /** The core to get the replies from. */ private final Core core; @@ -42,9 +50,12 @@ public class PostAccessor extends ReflectionAccessor { * * @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); } /** @@ -61,7 +72,14 @@ public class PostAccessor extends ReflectionAccessor { Sone currentSone = (Sone) dataProvider.getData("currentSone"); return (currentSone != null) && (currentSone.isLikedPostId(post.getId())); } else if (member.equals("new")) { - return core.isNewPost(post.getId()); + return core.isNewPost(post.getId(), false); + } else if (member.equals("text")) { + String text = post.getText(); + try { + return linkParser.parse(new StringReader(text)); + } catch (IOException ioe1) { + /* ignore. */ + } } return super.get(dataProvider, object, member); }