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();
+ try {
+ return linkParser.parse(new StringReader(text));
+ } catch (IOException ioe1) {
+ /* ignore. */
+ }
}
return super.get(dataProvider, object, member);
}
package net.pterodactylus.sone.template;
+import java.io.IOException;
+import java.io.StringReader;
+
import net.pterodactylus.sone.core.Core;
import net.pterodactylus.sone.data.Reply;
import net.pterodactylus.sone.data.Sone;
+import net.pterodactylus.sone.text.FreenetLinkParser;
import net.pterodactylus.util.template.Accessor;
import net.pterodactylus.util.template.DataProvider;
import net.pterodactylus.util.template.ReflectionAccessor;
+import net.pterodactylus.util.template.TemplateFactory;
/**
* {@link Accessor} implementation that adds a couple of properties to
*/
public class ReplyAccessor extends ReflectionAccessor {
+ /** Parser for Freenet links. */
+ private final FreenetLinkParser linkParser;
+
/** The core. */
private final Core core;
*
* @param core
* The core
+ * @param templateFactory
+ * The template factory for the text parser
*/
- public ReplyAccessor(Core core) {
+ public ReplyAccessor(Core core, TemplateFactory templateFactory) {
this.core = core;
+ linkParser = new FreenetLinkParser(templateFactory);
}
/**
return (currentSone != null) && (currentSone.isLikedReplyId(reply.getId()));
} else if (member.equals("new")) {
return core.isNewReply(reply.getId(), false);
+ } else if (member.equals("text")) {
+ String text = reply.getText();
+ try {
+ return linkParser.parse(new StringReader(text));
+ } catch (IOException ioe1) {
+ /* ignore. */
+ }
}
return super.get(dataProvider, object, member);
}
templateFactory.addAccessor(Object.class, new ReflectionAccessor());
templateFactory.addAccessor(Collection.class, new CollectionAccessor());
templateFactory.addAccessor(Sone.class, new SoneAccessor(getCore()));
- templateFactory.addAccessor(Post.class, new PostAccessor(getCore()));
- templateFactory.addAccessor(Reply.class, new ReplyAccessor(getCore()));
+ templateFactory.addAccessor(Post.class, new PostAccessor(getCore(), templateFactory));
+ templateFactory.addAccessor(Reply.class, new ReplyAccessor(getCore(), templateFactory));
templateFactory.addAccessor(Identity.class, new IdentityAccessor(getCore()));
templateFactory.addAccessor(NotificationManager.class, new NotificationManagerAccessor());
templateFactory.addFilter("date", new DateFilter());
<div class="inner-part">
<div>
<div class="author profile-link"><a href="viewSone.html?sone=<% post.sone.id|html>"><% post.sone.niceName|html></a></div>
- <div class="text"><% post.text|html></div>
+ <div class="text"><% post.text></div>
</div>
<div class="status-line">
<div class="time"><a href="viewPost.html?post=<% post.id|html>"><% post.time|date format="MMM d, yyyy, HH:mm:ss"></a></div>
<div class="inner-part">
<div>
<div class="author profile-link"><a href="viewSone.html?sone=<% reply.sone.id|html>"><% reply.sone.niceName|html></a></div>
- <div class="text"><% reply.text|html></div>
+ <div class="text"><% reply.text></div>
</div>
<div class="status-line">
<div class="time"><% reply.time|date format="MMM d, yyyy, HH:mm:ss"></div>