<dependency>
<groupId>net.pterodactylus</groupId>
<artifactId>utils</artifactId>
- <version>0.7.8</version>
+ <version>0.7.9-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>junit</groupId>
import net.pterodactylus.util.io.Closer;
import net.pterodactylus.util.logging.Logging;
import net.pterodactylus.util.service.AbstractService;
-import net.pterodactylus.util.template.DefaultTemplateFactory;
import net.pterodactylus.util.template.ReflectionAccessor;
import net.pterodactylus.util.template.Template;
+import net.pterodactylus.util.template.TemplateContext;
+import net.pterodactylus.util.template.TemplateContextFactory;
import net.pterodactylus.util.template.TemplateException;
+import net.pterodactylus.util.template.TemplateParser;
import net.pterodactylus.util.template.XmlFilter;
import freenet.client.async.ManifestElement;
import freenet.keys.FreenetURI;
private static volatile int insertionDelay = 60;
/** The template factory used to create the templates. */
- private static final DefaultTemplateFactory templateFactory = new DefaultTemplateFactory();
+ private static final TemplateContextFactory templateContextFactory = new TemplateContextFactory();
static {
- templateFactory.addAccessor(Object.class, new ReflectionAccessor());
- templateFactory.addFilter("xml", new XmlFilter());
+ templateContextFactory.addAccessor(Object.class, new ReflectionAccessor());
+ templateContextFactory.addFilter("xml", new XmlFilter());
}
/** The UTF-8 charset. */
*/
@SuppressWarnings("synthetic-access")
private ManifestElement createManifestElement(String name, String contentType, String templateName) {
- InputStreamReader templateInputStreamReader;
- Template template = templateFactory.createTemplate(templateInputStreamReader = new InputStreamReader(getClass().getResourceAsStream(templateName), utf8Charset));
+ InputStreamReader templateInputStreamReader = null;
+ Template template;
try {
- template.parse();
+ templateInputStreamReader = new InputStreamReader(getClass().getResourceAsStream(templateName), utf8Charset);
+ template = TemplateParser.parse(templateInputStreamReader);
} catch (TemplateException te1) {
logger.log(Level.SEVERE, "Could not parse template “" + templateName + "”!", te1);
return null;
Closer.close(templateInputStreamReader);
}
- template.set("currentSone", soneProperties);
- template.set("version", SonePlugin.VERSION);
+ TemplateContext templateContext = templateContextFactory.createTemplateContext();
+ templateContext.set("currentSone", soneProperties);
+ templateContext.set("version", SonePlugin.VERSION);
StringWriter writer = new StringWriter();
StringBucket bucket = null;
try {
- template.render(writer);
+ template.render(templateContext, writer);
bucket = new StringBucket(writer.toString(), utf8Charset);
return new ManifestElement(name, bucket, contentType, bucket.size());
} catch (TemplateException te1) {
import java.util.Map;
-import net.pterodactylus.util.template.DataProvider;
import net.pterodactylus.util.template.Filter;
+import net.pterodactylus.util.template.TemplateContext;
import freenet.l10n.BaseL10n;
/**
* {@inheritDoc}
*/
@Override
- public String format(DataProvider dataProvider, Object data, Map<String, String> parameters) {
+ public String format(TemplateContext templateContext, Object data, Map<String, String> parameters) {
return l10n.getString(String.valueOf(data));
}
*/
public ListNotification(String id, String key, Template template) {
super(id, template);
- template.set(key, elements);
- template.set("notification", this);
+ template.getInitialContext().set(key, elements);
}
//
import net.pterodactylus.sone.data.Sone;
import net.pterodactylus.util.template.Accessor;
-import net.pterodactylus.util.template.DataProvider;
import net.pterodactylus.util.template.ReflectionAccessor;
+import net.pterodactylus.util.template.TemplateContext;
/**
* {@link Accessor} for {@link Collection}s that adds a couple of specialized
* {@inheritDoc}
*/
@Override
- public Object get(DataProvider dataProvider, Object object, String member) {
+ public Object get(TemplateContext templateContext, Object object, String member) {
if (object == null) {
return null;
}
}
return soneNames.toString();
}
- return super.get(dataProvider, object, member);
+ return super.get(templateContext, object, member);
}
}
import java.util.Map;
-import net.pterodactylus.util.template.DataProvider;
import net.pterodactylus.util.template.Filter;
+import net.pterodactylus.util.template.TemplateContext;
/**
* Converts the {@link String} {@link String#valueOf(Object) representation} of
* {@inheritDoc}
*/
@Override
- public Object format(DataProvider dataProvider, Object data, Map<String, String> parameters) {
+ public Object format(TemplateContext templateContext, Object data, Map<String, String> parameters) {
return String.valueOf(data).replaceAll("[^a-zA-Z0-9-]", "_");
}
import java.util.Map;
import net.pterodactylus.sone.web.page.Page.Request;
-import net.pterodactylus.util.template.DataProvider;
import net.pterodactylus.util.template.Plugin;
+import net.pterodactylus.util.template.TemplateContext;
/**
- * Extracts a page number from a {@link Request}’s parameters and stores it in a
- * {@link DataProvider}.
+ * Extracts a page number from a {@link Request}’s parameters and stores it in
+ * the {@link TemplateContext}.
*
* @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
*/
* {@inheritDoc}
*/
@Override
- public void execute(DataProvider dataProvider, Map<String, String> parameters) {
+ public void execute(TemplateContext templateContext, Map<String, String> parameters) {
String requestKey = parameters.get("request");
String parameter = parameters.get("parameter");
String pageKey = parameters.get("key");
pageKey = "page";
}
- Request request = (Request) dataProvider.get(requestKey);
+ Request request = (Request) templateContext.get(requestKey);
String pageString = request.getHttpRequest().getParam(parameter);
int page = 0;
try {
} catch (NumberFormatException nfe1) {
/* ignore. */
}
- dataProvider.set(pageKey, page);
+ templateContext.set(pageKey, page);
}
}
import net.pterodactylus.sone.freenet.wot.Identity;
import net.pterodactylus.sone.freenet.wot.OwnIdentity;
import net.pterodactylus.util.template.Accessor;
-import net.pterodactylus.util.template.DataProvider;
import net.pterodactylus.util.template.ReflectionAccessor;
+import net.pterodactylus.util.template.TemplateContext;
/**
* {@link Accessor} implementation that adds a “uniqueNickname” member to an
* {@inheritDoc}
*/
@Override
- public Object get(DataProvider dataProvider, Object object, String member) {
+ public Object get(TemplateContext templateContext, Object object, String member) {
Identity identity = (Identity) object;
if ("uniqueNickname".equals(member)) {
int minLength = -1;
} while (!found && (minLength < 43));
return getAbbreviatedNickname(identity, minLength);
}
- return super.get(dataProvider, object, member);
+ return super.get(templateContext, object, member);
}
//
import java.util.Map;
import net.pterodactylus.util.number.Hex;
-import net.pterodactylus.util.template.DataProvider;
import net.pterodactylus.util.template.Filter;
+import net.pterodactylus.util.template.TemplateContext;
/**
* Escapes double quotes, backslashes, carriage returns and line feeds, and
* {@inheritDoc}
*/
@Override
- public Object format(DataProvider dataProvider, Object data, Map<String, String> parameters) {
+ public Object format(TemplateContext templateContext, Object data, Map<String, String> parameters) {
StringBuilder javascriptString = new StringBuilder();
javascriptString.append('"');
for (char c : String.valueOf(data).toCharArray()) {
import net.pterodactylus.util.notify.Notification;
import net.pterodactylus.util.notify.NotificationManager;
-import net.pterodactylus.util.template.DataProvider;
import net.pterodactylus.util.template.ReflectionAccessor;
+import net.pterodactylus.util.template.TemplateContext;
/**
* Adds additional properties to a {@link NotificationManager}.
* {@inheritDoc}
*/
@Override
- public Object get(DataProvider dataProvider, Object object, String member) {
+ public Object get(TemplateContext templateContext, Object object, String member) {
NotificationManager notificationManager = (NotificationManager) object;
if ("all".equals(member)) {
List<Notification> notifications = new ArrayList<Notification>(notificationManager.getNotifications());
Collections.sort(notifications, Notification.LAST_UPDATED_TIME_SORTER);
return notifications;
}
- return super.get(dataProvider, object, member);
+ return super.get(templateContext, object, member);
}
}
import net.pterodactylus.sone.data.Sone;
import net.pterodactylus.sone.text.FreenetLinkParser;
import net.pterodactylus.sone.text.FreenetLinkParserContext;
-import net.pterodactylus.util.template.DataProvider;
import net.pterodactylus.util.template.Filter;
-import net.pterodactylus.util.template.TemplateFactory;
+import net.pterodactylus.util.template.TemplateContext;
+import net.pterodactylus.util.template.TemplateContextFactory;
/**
* Filter that filters a given text through a {@link FreenetLinkParser}.
private final FreenetLinkParser linkParser;
/**
- * Creates a new parser filter.
+ * Creates a new filter that runs its input through a
+ * {@link FreenetLinkParser}.
*
- * @param templateFactory
- * The template factory for the link parser
+ * @param templateContextFactory
+ * The context factory for rendering the parts
*/
- public ParserFilter(TemplateFactory templateFactory) {
- this.linkParser = new FreenetLinkParser(templateFactory);
+ public ParserFilter(TemplateContextFactory templateContextFactory) {
+ linkParser = new FreenetLinkParser(templateContextFactory);
}
/**
* {@inheritDoc}
*/
@Override
- public Object format(DataProvider dataProvider, Object data, Map<String, String> parameters) {
+ public Object format(TemplateContext templateContext, Object data, Map<String, String> parameters) {
String text = String.valueOf(data);
String soneKey = parameters.get("sone");
if (soneKey == null) {
soneKey = "sone";
}
- Sone sone = (Sone) dataProvider.get(soneKey);
+ Sone sone = (Sone) templateContext.get(soneKey);
FreenetLinkParserContext context = new FreenetLinkParserContext(sone);
try {
return linkParser.parse(context, new StringReader(text));
import net.pterodactylus.sone.core.Core;
import net.pterodactylus.sone.data.Post;
import net.pterodactylus.sone.data.Sone;
-import net.pterodactylus.util.template.DataProvider;
import net.pterodactylus.util.template.ReflectionAccessor;
+import net.pterodactylus.util.template.TemplateContext;
/**
* Accessor for {@link Post} objects that adds additional properties:
* {@inheritDoc}
*/
@Override
- public Object get(DataProvider dataProvider, Object object, String member) {
+ public Object get(TemplateContext templateContext, Object object, String member) {
Post post = (Post) object;
if ("replies".equals(member)) {
return core.getReplies(post);
} else if (member.equals("likes")) {
return core.getLikes(post);
} else if (member.equals("liked")) {
- Sone currentSone = (Sone) dataProvider.get("currentSone");
+ Sone currentSone = (Sone) templateContext.get("currentSone");
return (currentSone != null) && (currentSone.isLikedPostId(post.getId()));
} else if (member.equals("new")) {
return core.isNewPost(post.getId(), false);
}
- return super.get(dataProvider, object, member);
+ return super.get(templateContext, object, member);
}
}
import net.pterodactylus.sone.data.Reply;
import net.pterodactylus.sone.data.Sone;
import net.pterodactylus.util.template.Accessor;
-import net.pterodactylus.util.template.DataProvider;
import net.pterodactylus.util.template.ReflectionAccessor;
+import net.pterodactylus.util.template.TemplateContext;
/**
* {@link Accessor} implementation that adds a couple of properties to
* {@inheritDoc}
*/
@Override
- public Object get(DataProvider dataProvider, Object object, String member) {
+ public Object get(TemplateContext templateContext, Object object, String member) {
Reply reply = (Reply) object;
if ("likes".equals(member)) {
return core.getLikes(reply);
} else if (member.equals("liked")) {
- Sone currentSone = (Sone) dataProvider.get("currentSone");
+ Sone currentSone = (Sone) templateContext.get("currentSone");
return (currentSone != null) && (currentSone.isLikedReplyId(reply.getId()));
} else if (member.equals("new")) {
return core.isNewReply(reply.getId(), false);
}
- return super.get(dataProvider, object, member);
+ return super.get(templateContext, object, member);
}
}
import java.util.Map.Entry;
import net.pterodactylus.sone.web.page.Page.Request;
-import net.pterodactylus.util.template.DataProvider;
import net.pterodactylus.util.template.Filter;
+import net.pterodactylus.util.template.TemplateContext;
/**
* This filter expects a {@link Request} as input and outputs a {@link URI} that
* {@inheritDoc}
*/
@Override
- public Object format(DataProvider dataProvider, Object data, Map<String, String> parameters) {
+ public Object format(TemplateContext templateContext, Object data, Map<String, String> parameters) {
Request request = (Request) data;
String name = parameters.get("name");
String nameKey = parameters.get("nameKey");
if (nameKey != null) {
- name = String.valueOf(dataProvider.get(nameKey));
+ name = String.valueOf(templateContext.get(nameKey));
}
String key = parameters.get("key");
String value = null;
if (key != null) {
- value = String.valueOf(dataProvider.get(key));
+ value = String.valueOf(templateContext.get(key));
}
if (value == null) {
value = parameters.get("value");
import net.pterodactylus.sone.freenet.wot.Trust;
import net.pterodactylus.util.logging.Logging;
import net.pterodactylus.util.template.Accessor;
-import net.pterodactylus.util.template.DataProvider;
import net.pterodactylus.util.template.ReflectionAccessor;
+import net.pterodactylus.util.template.TemplateContext;
/**
* {@link Accessor} for {@link Sone}s that adds a couple of properties to Sones.
* <dt>friend</dt>
* <dd>Will return {@code true} if the sone in question is a friend of the
* currently logged in Sone (as determined by accessing the “currentSone”
- * variable of the given {@link DataProvider}).</dd>
+ * variable of the given {@link TemplateContext}).</dd>
* <dt>current</dt>
* <dd>Will return {@code true} if the sone in question is the currently logged
* in Sone.</dd>
* {@inheritDoc}
*/
@Override
- public Object get(DataProvider dataProvider, Object object, String member) {
+ public Object get(TemplateContext templateContext, Object object, String member) {
Sone sone = (Sone) object;
if (member.equals("niceName")) {
return getNiceName(sone);
} else if (member.equals("local")) {
return sone.getInsertUri() != null;
} else if (member.equals("friend")) {
- Sone currentSone = (Sone) dataProvider.get("currentSone");
+ Sone currentSone = (Sone) templateContext.get("currentSone");
return (currentSone != null) && currentSone.hasFriend(sone.getId());
} else if (member.equals("current")) {
- Sone currentSone = (Sone) dataProvider.get("currentSone");
+ Sone currentSone = (Sone) templateContext.get("currentSone");
return (currentSone != null) && currentSone.equals(sone);
} else if (member.equals("modified")) {
return core.isModifiedSone(sone);
} else if (member.equals("locked")) {
return core.isLocked(sone);
} else if (member.equals("trust")) {
- Sone currentSone = (Sone) dataProvider.get("currentSone");
+ Sone currentSone = (Sone) templateContext.get("currentSone");
if (currentSone == null) {
return null;
}
}
return trust;
}
- return super.get(dataProvider, object, member);
+ return super.get(templateContext, object, member);
}
//
import java.util.Map;
-import net.pterodactylus.util.template.DataProvider;
import net.pterodactylus.util.template.Filter;
+import net.pterodactylus.util.template.TemplateContext;
/**
* {@link Filter} implementation that executes
* {@inheritDoc}
*/
@Override
- public Object format(DataProvider dataProvider, Object data, Map<String, String> parameters) {
+ public Object format(TemplateContext templateContext, Object data, Map<String, String> parameters) {
String startString = parameters.get("start");
String lengthString = parameters.get("length");
int start = 0;
import net.pterodactylus.sone.freenet.wot.Trust;
import net.pterodactylus.util.template.Accessor;
-import net.pterodactylus.util.template.DataProvider;
import net.pterodactylus.util.template.ReflectionAccessor;
+import net.pterodactylus.util.template.TemplateContext;
/**
* {@link Accessor} implementation for {@link Trust} values, adding the
* {@inheritDoc}
*/
@Override
- public Object get(DataProvider dataProvider, Object object, String member) {
+ public Object get(TemplateContext templateContext, Object object, String member) {
Trust trust = (Trust) object;
if ("assigned".equals(member)) {
return trust.getExplicit() != null;
} else if ("hasDistance".equals(member)) {
return (trust.getDistance() != null) && (trust.getDistance() != Integer.MAX_VALUE);
}
- return super.get(dataProvider, object, member);
+ return super.get(templateContext, object, member);
}
}
import java.util.Map;
-import net.pterodactylus.util.template.DataProvider;
import net.pterodactylus.util.template.Filter;
+import net.pterodactylus.util.template.TemplateContext;
import freenet.l10n.BaseL10n;
/**
* {@inheritDoc}
*/
@Override
- public Object format(DataProvider dataProvider, Object data, Map<String, String> parameters) {
+ public Object format(TemplateContext templateContext, Object data, Map<String, String> parameters) {
if (data instanceof Long) {
if ((Long) data == 0) {
return l10nHandler.getString(unknownKey);
import java.util.regex.Pattern;
import net.pterodactylus.util.logging.Logging;
-import net.pterodactylus.util.template.TemplateFactory;
+import net.pterodactylus.util.template.TemplateContextFactory;
+import net.pterodactylus.util.template.TemplateParser;
import freenet.keys.FreenetURI;
/**
}
/** The template factory. */
- private final TemplateFactory templateFactory;
+ private final TemplateContextFactory templateContextFactory;
/**
* Creates a new freenet link parser.
*
- * @param templateFactory
- * The template factory
+ * @param templateContextFactory
+ * The template context factory
*/
- public FreenetLinkParser(TemplateFactory templateFactory) {
- this.templateFactory = templateFactory;
+ public FreenetLinkParser(TemplateContextFactory templateContextFactory) {
+ this.templateContextFactory = templateContextFactory;
}
//
* @return The part that displays the given text
*/
private Part createPlainTextPart(String text) {
- return new TemplatePart(templateFactory.createTemplate(new StringReader("<% text|html>"))).set("text", text);
+ return new TemplatePart(templateContextFactory, TemplateParser.parse(new StringReader("<% text|html>"))).set("text", text);
}
/**
* @return The part that displays the link
*/
private Part createInternetLinkPart(String link, String name) {
- return new TemplatePart(templateFactory.createTemplate(new StringReader("<a class=\"internet\" href=\"/<% link|html>\" title=\"<% link|html>\"><% name|html></a>"))).set("link", link).set("name", name);
+ return new TemplatePart(templateContextFactory, TemplateParser.parse(new StringReader("<a class=\"internet\" href=\"/<% link|html>\" title=\"<% link|html>\"><% name|html></a>"))).set("link", link).set("name", name);
}
/**
* @return The part that displays the link
*/
private Part createFreenetLinkPart(String link, String name) {
- return new TemplatePart(templateFactory.createTemplate(new StringReader("<a class=\"freenet\" href=\"/<% link|html>\" title=\"<% link|html>\"><% name|html></a>"))).set("link", link).set("name", name);
+ return new TemplatePart(templateContextFactory, TemplateParser.parse(new StringReader("<a class=\"freenet\" href=\"/<% link|html>\" title=\"<% link|html>\"><% name|html></a>"))).set("link", link).set("name", name);
}
/**
* @return The part that displays the link
*/
private Part createTrustedFreenetLinkPart(String link, String name) {
- return new TemplatePart(templateFactory.createTemplate(new StringReader("<a class=\"freenet-trusted\" href=\"/<% link|html>\" title=\"<% link|html>\"><% name|html></a>"))).set("link", link).set("name", name);
+ return new TemplatePart(templateContextFactory, TemplateParser.parse(new StringReader("<a class=\"freenet-trusted\" href=\"/<% link|html>\" title=\"<% link|html>\"><% name|html></a>"))).set("link", link).set("name", name);
}
}
import java.io.Writer;
import net.pterodactylus.util.template.Template;
+import net.pterodactylus.util.template.TemplateContext;
+import net.pterodactylus.util.template.TemplateContextFactory;
+import net.pterodactylus.util.template.TemplateException;
/**
* {@link Part} implementation that is rendered using a {@link Template}.
*
* @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
*/
-public class TemplatePart implements Part {
+public class TemplatePart implements Part, net.pterodactylus.util.template.Part {
+
+ /** The template context factory. */
+ private final TemplateContextFactory templateContextFactory;
/** The template to render for this part. */
private final Template template;
/**
* Creates a new template part.
*
+ * @param templateContextFactory
+ * The template context factory
* @param template
* The template to render
*/
- public TemplatePart(Template template) {
+ public TemplatePart(TemplateContextFactory templateContextFactory, Template template) {
+ this.templateContextFactory = templateContextFactory;
this.template = template;
}
* @return This template part (for method chaining)
*/
public TemplatePart set(String key, Object value) {
- template.set(key, value);
+ template.getInitialContext().set(key, value);
return this;
}
*/
@Override
public void render(Writer writer) throws IOException {
- template.render(writer);
+ template.render(templateContextFactory.createTemplateContext().mergeContext(template.getInitialContext()), writer);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void render(TemplateContext templateContext, Writer writer) throws TemplateException {
+ template.render(templateContext.mergeContext(template.getInitialContext()), writer);
}
}
package net.pterodactylus.sone.web;
-import net.pterodactylus.util.template.DataProvider;
import net.pterodactylus.util.template.Template;
+import net.pterodactylus.util.template.TemplateContext;
import net.pterodactylus.util.version.Version;
/**
* {@inheritDoc}
*/
@Override
- protected void processTemplate(Request request, DataProvider dataProvider) throws RedirectException {
- super.processTemplate(request, dataProvider);
- dataProvider.set("version", version);
+ protected void processTemplate(Request request, TemplateContext templateContext) throws RedirectException {
+ super.processTemplate(request, templateContext);
+ templateContext.set("version", version);
}
}
import net.pterodactylus.sone.data.Post;
import net.pterodactylus.sone.data.Sone;
import net.pterodactylus.sone.web.page.Page.Request.Method;
-import net.pterodactylus.util.template.DataProvider;
import net.pterodactylus.util.template.Template;
+import net.pterodactylus.util.template.TemplateContext;
/**
* This page lets the user create a new {@link Post}.
* {@inheritDoc}
*/
@Override
- protected void processTemplate(Request request, DataProvider dataProvider) throws RedirectException {
- super.processTemplate(request, dataProvider);
+ protected void processTemplate(Request request, TemplateContext templateContext) throws RedirectException {
+ super.processTemplate(request, templateContext);
String returnPage = request.getHttpRequest().getPartAsStringFailsafe("returnPage", 256);
if (request.getMethod() == Method.POST) {
String text = request.getHttpRequest().getPartAsStringFailsafe("text", 65536).trim();
webInterface.getCore().createPost(currentSone, recipient, System.currentTimeMillis(), text);
throw new RedirectException(returnPage);
}
- dataProvider.set("errorTextEmpty", true);
+ templateContext.set("errorTextEmpty", true);
}
- dataProvider.set("returnPage", returnPage);
+ templateContext.set("returnPage", returnPage);
}
}
import net.pterodactylus.sone.data.Post;
import net.pterodactylus.sone.data.Sone;
import net.pterodactylus.sone.web.page.Page.Request.Method;
-import net.pterodactylus.util.template.DataProvider;
import net.pterodactylus.util.template.Template;
+import net.pterodactylus.util.template.TemplateContext;
/**
* This page lets the user post a reply to a post.
* {@inheritDoc}
*/
@Override
- protected void processTemplate(Request request, DataProvider dataProvider) throws RedirectException {
- super.processTemplate(request, dataProvider);
+ protected void processTemplate(Request request, TemplateContext templateContext) throws RedirectException {
+ super.processTemplate(request, templateContext);
String postId = request.getHttpRequest().getPartAsStringFailsafe("post", 36);
String text = request.getHttpRequest().getPartAsStringFailsafe("text", 65536).trim();
String returnPage = request.getHttpRequest().getPartAsStringFailsafe("returnPage", 256);
webInterface.getCore().createReply(currentSone, post, text);
throw new RedirectException(returnPage);
}
- dataProvider.set("errorTextEmpty", true);
+ templateContext.set("errorTextEmpty", true);
}
- dataProvider.set("postId", postId);
- dataProvider.set("text", text);
- dataProvider.set("returnPage", returnPage);
+ templateContext.set("postId", postId);
+ templateContext.set("text", text);
+ templateContext.set("returnPage", returnPage);
}
}
import net.pterodactylus.sone.freenet.wot.OwnIdentity;
import net.pterodactylus.sone.web.page.Page.Request.Method;
import net.pterodactylus.util.logging.Logging;
-import net.pterodactylus.util.template.DataProvider;
import net.pterodactylus.util.template.Template;
+import net.pterodactylus.util.template.TemplateContext;
import freenet.clients.http.ToadletContext;
/**
* {@inheritDoc}
*/
@Override
- protected void processTemplate(Request request, DataProvider dataProvider) throws RedirectException {
- super.processTemplate(request, dataProvider);
+ protected void processTemplate(Request request, TemplateContext templateContext) throws RedirectException {
+ super.processTemplate(request, templateContext);
List<OwnIdentity> ownIdentitiesWithoutSone = getOwnIdentitiesWithoutSone(webInterface.getCore());
- dataProvider.set("identitiesWithoutSone", ownIdentitiesWithoutSone);
+ templateContext.set("identitiesWithoutSone", ownIdentitiesWithoutSone);
if (request.getMethod() == Method.POST) {
String id = request.getHttpRequest().getPartAsStringFailsafe("identity", 44);
OwnIdentity selectedIdentity = null;
}
}
if (selectedIdentity == null) {
- dataProvider.set("errorNoIdentity", true);
+ templateContext.set("errorNoIdentity", true);
return;
}
/* create Sone. */
import net.pterodactylus.sone.data.Post;
import net.pterodactylus.sone.data.Sone;
import net.pterodactylus.sone.web.page.Page.Request.Method;
-import net.pterodactylus.util.template.DataProvider;
import net.pterodactylus.util.template.Template;
+import net.pterodactylus.util.template.TemplateContext;
/**
* Lets the user delete a post they made.
* {@inheritDoc}
*/
@Override
- protected void processTemplate(Request request, DataProvider dataProvider) throws RedirectException {
- super.processTemplate(request, dataProvider);
+ protected void processTemplate(Request request, TemplateContext templateContext) throws RedirectException {
+ super.processTemplate(request, templateContext);
if (request.getMethod() == Method.GET) {
String postId = request.getHttpRequest().getParam("post");
String returnPage = request.getHttpRequest().getParam("returnPage");
Post post = webInterface.getCore().getPost(postId);
- dataProvider.set("post", post);
- dataProvider.set("returnPage", returnPage);
+ templateContext.set("post", post);
+ templateContext.set("returnPage", returnPage);
return;
} else if (request.getMethod() == Method.POST) {
String postId = request.getHttpRequest().getPartAsStringFailsafe("post", 36);
} else if (request.getHttpRequest().isPartSet("abortDelete")) {
throw new RedirectException(returnPage);
}
- dataProvider.set("post", post);
- dataProvider.set("returnPage", returnPage);
+ templateContext.set("post", post);
+ templateContext.set("returnPage", returnPage);
}
}
import net.pterodactylus.sone.data.Profile.Field;
import net.pterodactylus.sone.data.Sone;
import net.pterodactylus.sone.web.page.Page.Request.Method;
-import net.pterodactylus.util.template.DataProvider;
import net.pterodactylus.util.template.Template;
+import net.pterodactylus.util.template.TemplateContext;
/**
* Page that lets the user confirm the deletion of a profile field.
* {@inheritDoc}
*/
@Override
- protected void processTemplate(Request request, DataProvider dataProvider) throws RedirectException {
- super.processTemplate(request, dataProvider);
+ protected void processTemplate(Request request, TemplateContext templateContext) throws RedirectException {
+ super.processTemplate(request, templateContext);
Sone currentSone = getCurrentSone(request.getToadletContext());
Profile profile = currentSone.getProfile();
}
/* set current values in template. */
- dataProvider.set("field", field);
+ templateContext.set("field", field);
}
}
import net.pterodactylus.sone.data.Reply;
import net.pterodactylus.sone.data.Sone;
import net.pterodactylus.sone.web.page.Page.Request.Method;
-import net.pterodactylus.util.template.DataProvider;
import net.pterodactylus.util.template.Template;
+import net.pterodactylus.util.template.TemplateContext;
/**
* This page lets the user delete a reply.
* {@inheritDoc}
*/
@Override
- protected void processTemplate(Request request, DataProvider dataProvider) throws RedirectException {
- super.processTemplate(request, dataProvider);
+ protected void processTemplate(Request request, TemplateContext templateContext) throws RedirectException {
+ super.processTemplate(request, templateContext);
String replyId = request.getHttpRequest().getPartAsStringFailsafe("reply", 36);
Reply reply = webInterface.getCore().getReply(replyId);
String returnPage = request.getHttpRequest().getPartAsStringFailsafe("returnPage", 256);
throw new RedirectException(returnPage);
}
}
- dataProvider.set("reply", reply);
- dataProvider.set("returnPage", returnPage);
+ templateContext.set("reply", reply);
+ templateContext.set("returnPage", returnPage);
}
}
import net.pterodactylus.sone.data.Sone;
import net.pterodactylus.sone.web.page.Page.Request.Method;
-import net.pterodactylus.util.template.DataProvider;
import net.pterodactylus.util.template.Template;
+import net.pterodactylus.util.template.TemplateContext;
/**
* Lets the user delete a Sone. Of course the Sone is not really deleted from
* {@inheritDoc}
*/
@Override
- protected void processTemplate(Request request, DataProvider dataProvider) throws RedirectException {
- super.processTemplate(request, dataProvider);
+ protected void processTemplate(Request request, TemplateContext templateContext) throws RedirectException {
+ super.processTemplate(request, templateContext);
if (request.getMethod() == Method.POST) {
if (request.getHttpRequest().isPartSet("deleteSone")) {
Sone currentSone = getCurrentSone(request.getToadletContext());
package net.pterodactylus.sone.web;
import net.pterodactylus.util.notify.Notification;
-import net.pterodactylus.util.template.DataProvider;
import net.pterodactylus.util.template.Template;
+import net.pterodactylus.util.template.TemplateContext;
/**
* Page that lets the user dismiss a notification.
* {@inheritDoc}
*/
@Override
- protected void processTemplate(Request request, DataProvider dataProvider) throws RedirectException {
- super.processTemplate(request, dataProvider);
+ protected void processTemplate(Request request, TemplateContext templateContext) throws RedirectException {
+ super.processTemplate(request, templateContext);
String notificationId = request.getHttpRequest().getPartAsStringFailsafe("notification", 36);
Notification notification = webInterface.getNotifications().getNotification(notificationId);
if ((notification != null) && notification.isDismissable()) {
import net.pterodactylus.sone.core.Core;
import net.pterodactylus.sone.data.Sone;
import net.pterodactylus.sone.web.page.Page.Request.Method;
-import net.pterodactylus.util.template.DataProvider;
import net.pterodactylus.util.template.Template;
+import net.pterodactylus.util.template.TemplateContext;
/**
* Page that lets the user distrust another Sone. This will assign a
* {@inheritDoc}
*/
@Override
- protected void processTemplate(Request request, DataProvider dataProvider) throws RedirectException {
- super.processTemplate(request, dataProvider);
+ protected void processTemplate(Request request, TemplateContext templateContext) throws RedirectException {
+ super.processTemplate(request, templateContext);
if (request.getMethod() == Method.POST) {
String returnPage = request.getHttpRequest().getPartAsStringFailsafe("returnPage", 256);
String identity = request.getHttpRequest().getPartAsStringFailsafe("sone", 44);
import net.pterodactylus.sone.data.Profile.Field;
import net.pterodactylus.sone.data.Sone;
import net.pterodactylus.sone.web.page.Page.Request.Method;
-import net.pterodactylus.util.template.DataProvider;
import net.pterodactylus.util.template.Template;
+import net.pterodactylus.util.template.TemplateContext;
/**
* Page that lets the user edit the name of a profile field.
* {@inheritDoc}
*/
@Override
- protected void processTemplate(Request request, DataProvider dataProvider) throws RedirectException {
- super.processTemplate(request, dataProvider);
+ protected void processTemplate(Request request, TemplateContext templateContext) throws RedirectException {
+ super.processTemplate(request, templateContext);
Sone currentSone = getCurrentSone(request.getToadletContext());
Profile profile = currentSone.getProfile();
currentSone.setProfile(profile);
throw new RedirectException("editProfile.html#profile-fields");
}
- dataProvider.set("duplicateFieldName", true);
+ templateContext.set("duplicateFieldName", true);
}
/* store current values in template. */
- dataProvider.set("field", field);
+ templateContext.set("field", field);
}
}
import net.pterodactylus.sone.data.Sone;
import net.pterodactylus.sone.web.page.Page.Request.Method;
import net.pterodactylus.util.number.Numbers;
-import net.pterodactylus.util.template.DataProvider;
import net.pterodactylus.util.template.Template;
+import net.pterodactylus.util.template.TemplateContext;
import freenet.clients.http.ToadletContext;
/**
* {@inheritDoc}
*/
@Override
- protected void processTemplate(Request request, DataProvider dataProvider) throws RedirectException {
- super.processTemplate(request, dataProvider);
+ protected void processTemplate(Request request, TemplateContext templateContext) throws RedirectException {
+ super.processTemplate(request, templateContext);
ToadletContext toadletContenxt = request.getToadletContext();
Sone currentSone = getCurrentSone(toadletContenxt);
Profile profile = currentSone.getProfile();
webInterface.getCore().saveSone(currentSone);
throw new RedirectException("editProfile.html#profile-fields");
} catch (IllegalArgumentException iae1) {
- dataProvider.set("fieldName", fieldName);
- dataProvider.set("duplicateFieldName", true);
+ templateContext.set("fieldName", fieldName);
+ templateContext.set("duplicateFieldName", true);
}
} else {
String id = getFieldId(request, "delete-field-");
}
}
}
- dataProvider.set("firstName", firstName);
- dataProvider.set("middleName", middleName);
- dataProvider.set("lastName", lastName);
- dataProvider.set("birthDay", birthDay);
- dataProvider.set("birthMonth", birthMonth);
- dataProvider.set("birthYear", birthYear);
- dataProvider.set("fields", fields);
+ templateContext.set("firstName", firstName);
+ templateContext.set("middleName", middleName);
+ templateContext.set("lastName", lastName);
+ templateContext.set("birthDay", birthDay);
+ templateContext.set("birthMonth", birthMonth);
+ templateContext.set("birthYear", birthYear);
+ templateContext.set("fields", fields);
}
//
import net.pterodactylus.sone.data.Sone;
import net.pterodactylus.sone.web.page.Page.Request.Method;
-import net.pterodactylus.util.template.DataProvider;
import net.pterodactylus.util.template.Template;
+import net.pterodactylus.util.template.TemplateContext;
/**
* This page lets the user follow another Sone.
* {@inheritDoc}
*/
@Override
- protected void processTemplate(Request request, DataProvider dataProvider) throws RedirectException {
- super.processTemplate(request, dataProvider);
+ protected void processTemplate(Request request, TemplateContext templateContext) throws RedirectException {
+ super.processTemplate(request, templateContext);
if (request.getMethod() == Method.POST) {
String soneId = request.getHttpRequest().getPartAsStringFailsafe("sone", 44);
String returnPage = request.getHttpRequest().getPartAsStringFailsafe("returnPage", 256);
import net.pterodactylus.sone.data.Sone;
import net.pterodactylus.util.collection.Pagination;
import net.pterodactylus.util.number.Numbers;
-import net.pterodactylus.util.template.DataProvider;
import net.pterodactylus.util.template.Template;
+import net.pterodactylus.util.template.TemplateContext;
/**
* The index page shows the main page of Sone. This page will contain the posts
* {@inheritDoc}
*/
@Override
- protected void processTemplate(Request request, DataProvider dataProvider) throws RedirectException {
- super.processTemplate(request, dataProvider);
+ protected void processTemplate(Request request, TemplateContext templateContext) throws RedirectException {
+ super.processTemplate(request, templateContext);
Sone currentSone = getCurrentSone(request.getToadletContext());
List<Post> allPosts = new ArrayList<Post>();
allPosts.addAll(currentSone.getPosts());
}
Collections.sort(allPosts, Post.TIME_COMPARATOR);
Pagination<Post> pagination = new Pagination<Post>(allPosts, 25).setPage(Numbers.safeParseInteger(request.getHttpRequest().getParam("page"), 0));
- dataProvider.set("pagination", pagination);
- dataProvider.set("posts", pagination.getItems());
+ templateContext.set("pagination", pagination);
+ templateContext.set("posts", pagination.getItems());
}
/**
* {@inheritDoc}
*/
@Override
- protected void postProcess(Request request, DataProvider dataProvider) {
+ protected void postProcess(Request request, TemplateContext templateContext) {
@SuppressWarnings("unchecked")
- List<Post> posts = (List<Post>) dataProvider.get("posts");
+ List<Post> posts = (List<Post>) templateContext.get("posts");
for (Post post : posts) {
webInterface.getCore().markPostKnown(post);
for (Reply reply : webInterface.getCore().getReplies(post)) {
import net.pterodactylus.sone.data.Sone;
import net.pterodactylus.util.collection.Pagination;
import net.pterodactylus.util.number.Numbers;
-import net.pterodactylus.util.template.DataProvider;
import net.pterodactylus.util.template.Template;
+import net.pterodactylus.util.template.TemplateContext;
/**
* This page shows all known Sones.
* {@inheritDoc}
*/
@Override
- protected void processTemplate(Request request, DataProvider dataProvider) throws RedirectException {
- super.processTemplate(request, dataProvider);
+ protected void processTemplate(Request request, TemplateContext templateContext) throws RedirectException {
+ super.processTemplate(request, templateContext);
List<Sone> knownSones = new ArrayList<Sone>(webInterface.getCore().getSones());
Collections.sort(knownSones, Sone.NICE_NAME_COMPARATOR);
Pagination<Sone> sonePagination = new Pagination<Sone>(knownSones, 25).setPage(Numbers.safeParseInteger(request.getHttpRequest().getParam("page"), 0));
- dataProvider.set("pagination", sonePagination);
- dataProvider.set("knownSones", sonePagination.getItems());
+ templateContext.set("pagination", sonePagination);
+ templateContext.set("knownSones", sonePagination.getItems());
}
/**
* {@inheritDoc}
*/
@Override
- protected void postProcess(Request request, DataProvider dataProvider) {
- super.postProcess(request, dataProvider);
+ protected void postProcess(Request request, TemplateContext templateContext) {
+ super.postProcess(request, templateContext);
@SuppressWarnings("unchecked")
- List<Sone> sones = (List<Sone>) dataProvider.get("knownSones");
+ List<Sone> sones = (List<Sone>) templateContext.get("knownSones");
for (Sone sone : sones) {
webInterface.getCore().markSoneKnown(sone);
}
import net.pterodactylus.sone.data.Post;
import net.pterodactylus.sone.data.Sone;
import net.pterodactylus.sone.web.page.Page.Request.Method;
-import net.pterodactylus.util.template.DataProvider;
import net.pterodactylus.util.template.Template;
+import net.pterodactylus.util.template.TemplateContext;
/**
* Page that lets the user like a {@link Post}.
* {@inheritDoc}
*/
@Override
- protected void processTemplate(Request request, DataProvider dataProvider) throws RedirectException {
- super.processTemplate(request, dataProvider);
+ protected void processTemplate(Request request, TemplateContext templateContext) throws RedirectException {
+ super.processTemplate(request, templateContext);
if (request.getMethod() == Method.POST) {
String type=request.getHttpRequest().getPartAsStringFailsafe("type", 16);
String id = request.getHttpRequest().getPartAsStringFailsafe(type, 36);
package net.pterodactylus.sone.web;
import net.pterodactylus.sone.data.Sone;
-import net.pterodactylus.util.template.DataProvider;
import net.pterodactylus.util.template.Template;
+import net.pterodactylus.util.template.TemplateContext;
/**
* This page lets the user lock a {@link Sone} to prevent it from being
* {@inheritDoc}
*/
@Override
- protected void processTemplate(Request request, DataProvider dataProvider) throws RedirectException {
- super.processTemplate(request, dataProvider);
+ protected void processTemplate(Request request, TemplateContext templateContext) throws RedirectException {
+ super.processTemplate(request, templateContext);
String soneId = request.getHttpRequest().getPartAsStringFailsafe("sone", 44);
Sone sone = webInterface.getCore().getLocalSone(soneId, false);
if (sone != null) {
import net.pterodactylus.sone.freenet.wot.OwnIdentity;
import net.pterodactylus.sone.web.page.Page.Request.Method;
import net.pterodactylus.util.logging.Logging;
-import net.pterodactylus.util.template.DataProvider;
import net.pterodactylus.util.template.Template;
+import net.pterodactylus.util.template.TemplateContext;
import freenet.clients.http.ToadletContext;
/**
* {@inheritDoc}
*/
@Override
- protected void processTemplate(Request request, DataProvider dataProvider) throws RedirectException {
- super.processTemplate(request, dataProvider);
+ protected void processTemplate(Request request, TemplateContext templateContext) throws RedirectException {
+ super.processTemplate(request, templateContext);
/* get all own identities. */
List<Sone> localSones = new ArrayList<Sone>(webInterface.getCore().getLocalSones());
Collections.sort(localSones, Sone.NICE_NAME_COMPARATOR);
- dataProvider.set("sones", localSones);
+ templateContext.set("sones", localSones);
if (request.getMethod() == Method.POST) {
String soneId = request.getHttpRequest().getPartAsStringFailsafe("sone-id", 100);
Sone selectedSone = webInterface.getCore().getLocalSone(soneId, false);
}
}
List<OwnIdentity> ownIdentitiesWithoutSone = CreateSonePage.getOwnIdentitiesWithoutSone(webInterface.getCore());
- dataProvider.set("identitiesWithoutSone", ownIdentitiesWithoutSone);
+ templateContext.set("identitiesWithoutSone", ownIdentitiesWithoutSone);
}
/**
package net.pterodactylus.sone.web;
-import net.pterodactylus.util.template.DataProvider;
import net.pterodactylus.util.template.Template;
+import net.pterodactylus.util.template.TemplateContext;
import freenet.clients.http.ToadletContext;
/**
* {@inheritDoc}
*/
@Override
- protected void processTemplate(Request request, DataProvider dataProvider) throws RedirectException {
+ protected void processTemplate(Request request, TemplateContext templateContext) throws RedirectException {
setCurrentSone(request.getToadletContext(), null);
- super.processTemplate(request, dataProvider);
+ super.processTemplate(request, templateContext);
throw new RedirectException("index.html");
}
import net.pterodactylus.sone.data.Post;
import net.pterodactylus.sone.data.Reply;
import net.pterodactylus.sone.data.Sone;
-import net.pterodactylus.util.template.DataProvider;
import net.pterodactylus.util.template.Template;
+import net.pterodactylus.util.template.TemplateContext;
/**
* Page that lets the user mark a number of {@link Sone}s, {@link Post}s, or
* {@inheritDoc}
*/
@Override
- protected void processTemplate(Request request, DataProvider dataProvider) throws RedirectException {
- super.processTemplate(request, dataProvider);
+ protected void processTemplate(Request request, TemplateContext templateContext) throws RedirectException {
+ super.processTemplate(request, templateContext);
String type = request.getHttpRequest().getPartAsStringFailsafe("type", 5);
if (!type.equals("sone") && !type.equals("post") && !type.equals("reply")) {
throw new RedirectException("invalid.html");
import net.pterodactylus.sone.core.Options;
import net.pterodactylus.sone.web.page.Page.Request.Method;
import net.pterodactylus.util.number.Numbers;
-import net.pterodactylus.util.template.DataProvider;
import net.pterodactylus.util.template.Template;
+import net.pterodactylus.util.template.TemplateContext;
/**
* This page lets the user edit the options of the Sone plugin.
* {@inheritDoc}
*/
@Override
- protected void processTemplate(Request request, DataProvider dataProvider) throws RedirectException {
- super.processTemplate(request, dataProvider);
+ protected void processTemplate(Request request, TemplateContext templateContext) throws RedirectException {
+ super.processTemplate(request, templateContext);
Options options = webInterface.getCore().getOptions();
if (request.getMethod() == Method.POST) {
Integer insertionDelay = Numbers.safeParseInteger(request.getHttpRequest().getPartAsStringFailsafe("insertion-delay", 16));
webInterface.getCore().saveConfiguration();
throw new RedirectException(getPath());
}
- dataProvider.set("insertion-delay", options.getIntegerOption("InsertionDelay").get());
- dataProvider.set("positive-trust", options.getIntegerOption("PositiveTrust").get());
- dataProvider.set("negative-trust", options.getIntegerOption("NegativeTrust").get());
- dataProvider.set("trust-comment", options.getStringOption("TrustComment").get());
- dataProvider.set("sone-rescue-mode", options.getBooleanOption("SoneRescueMode").get());
- dataProvider.set("clear-on-next-restart", options.getBooleanOption("ClearOnNextRestart").get());
- dataProvider.set("really-clear-on-next-restart", options.getBooleanOption("ReallyClearOnNextRestart").get());
+ templateContext.set("insertion-delay", options.getIntegerOption("InsertionDelay").get());
+ templateContext.set("positive-trust", options.getIntegerOption("PositiveTrust").get());
+ templateContext.set("negative-trust", options.getIntegerOption("NegativeTrust").get());
+ templateContext.set("trust-comment", options.getStringOption("TrustComment").get());
+ templateContext.set("sone-rescue-mode", options.getBooleanOption("SoneRescueMode").get());
+ templateContext.set("clear-on-next-restart", options.getBooleanOption("ClearOnNextRestart").get());
+ templateContext.set("really-clear-on-next-restart", options.getBooleanOption("ReallyClearOnNextRestart").get());
}
}
import net.pterodactylus.sone.main.SonePlugin;
import net.pterodactylus.sone.web.page.Page;
import net.pterodactylus.sone.web.page.TemplatePage;
-import net.pterodactylus.util.template.DataProvider;
import net.pterodactylus.util.template.Template;
+import net.pterodactylus.util.template.TemplateContext;
import freenet.clients.http.SessionManager.Session;
import freenet.clients.http.ToadletContext;
* Whether this page requires a login
*/
public SoneTemplatePage(String path, Template template, String pageTitleKey, WebInterface webInterface, boolean requireLogin) {
- super(path, template, webInterface.getL10n(), pageTitleKey, "noPermission.html");
+ super(path, webInterface.getTemplateContextFactory(), template, webInterface.getL10n(), pageTitleKey, "noPermission.html");
this.webInterface = webInterface;
this.requireLogin = requireLogin;
- template.set("webInterface", webInterface);
+ template.getInitialContext().set("webInterface", webInterface);
}
//
* {@inheritDoc}
*/
@Override
- protected void processTemplate(Request request, DataProvider dataProvider) throws RedirectException {
- super.processTemplate(request, dataProvider);
- dataProvider.set("currentSone", getCurrentSone(request.getToadletContext(), false));
- dataProvider.set("request", request);
- dataProvider.set("currentVersion", SonePlugin.VERSION);
- dataProvider.set("hasLatestVersion", webInterface.getCore().getUpdateChecker().hasLatestVersion());
- dataProvider.set("latestVersion", webInterface.getCore().getUpdateChecker().getLatestVersion());
- dataProvider.set("latestVersionTime", webInterface.getCore().getUpdateChecker().getLatestVersionDate());
+ protected void processTemplate(Request request, TemplateContext templateContext) throws RedirectException {
+ super.processTemplate(request, templateContext);
+ templateContext.set("currentSone", getCurrentSone(request.getToadletContext(), false));
+ templateContext.set("request", request);
+ templateContext.set("currentVersion", SonePlugin.VERSION);
+ templateContext.set("hasLatestVersion", webInterface.getCore().getUpdateChecker().hasLatestVersion());
+ templateContext.set("latestVersion", webInterface.getCore().getUpdateChecker().getLatestVersion());
+ templateContext.set("latestVersionTime", webInterface.getCore().getUpdateChecker().getLatestVersionDate());
}
/**
import net.pterodactylus.sone.core.Core;
import net.pterodactylus.sone.data.Sone;
import net.pterodactylus.sone.web.page.Page.Request.Method;
-import net.pterodactylus.util.template.DataProvider;
import net.pterodactylus.util.template.Template;
+import net.pterodactylus.util.template.TemplateContext;
/**
* Page that lets the user trust another Sone. This will assign a configurable
* {@inheritDoc}
*/
@Override
- protected void processTemplate(Request request, DataProvider dataProvider) throws RedirectException {
- super.processTemplate(request, dataProvider);
+ protected void processTemplate(Request request, TemplateContext templateContext) throws RedirectException {
+ super.processTemplate(request, templateContext);
if (request.getMethod() == Method.POST) {
String returnPage = request.getHttpRequest().getPartAsStringFailsafe("returnPage", 256);
String identity = request.getHttpRequest().getPartAsStringFailsafe("sone", 44);
import net.pterodactylus.sone.data.Sone;
import net.pterodactylus.sone.web.page.Page.Request.Method;
-import net.pterodactylus.util.template.DataProvider;
import net.pterodactylus.util.template.Template;
+import net.pterodactylus.util.template.TemplateContext;
/**
* This page lets the user unfollow another Sone.
* {@inheritDoc}
*/
@Override
- protected void processTemplate(Request request, DataProvider dataProvider) throws RedirectException {
- super.processTemplate(request, dataProvider);
+ protected void processTemplate(Request request, TemplateContext templateContext) throws RedirectException {
+ super.processTemplate(request, templateContext);
if (request.getMethod() == Method.POST) {
String soneId = request.getHttpRequest().getPartAsStringFailsafe("sone", 44);
String returnPage = request.getHttpRequest().getPartAsStringFailsafe("returnPage", 256);
import net.pterodactylus.sone.data.Post;
import net.pterodactylus.sone.data.Sone;
import net.pterodactylus.sone.web.page.Page.Request.Method;
-import net.pterodactylus.util.template.DataProvider;
import net.pterodactylus.util.template.Template;
+import net.pterodactylus.util.template.TemplateContext;
/**
* Page that lets the user unlike a {@link Post}.
* {@inheritDoc}
*/
@Override
- protected void processTemplate(Request request, DataProvider dataProvider) throws RedirectException {
- super.processTemplate(request, dataProvider);
+ protected void processTemplate(Request request, TemplateContext templateContext) throws RedirectException {
+ super.processTemplate(request, templateContext);
if (request.getMethod() == Method.POST) {
String type = request.getHttpRequest().getPartAsStringFailsafe("type", 16);
String id = request.getHttpRequest().getPartAsStringFailsafe(type, 36);
package net.pterodactylus.sone.web;
import net.pterodactylus.sone.data.Sone;
-import net.pterodactylus.util.template.DataProvider;
import net.pterodactylus.util.template.Template;
+import net.pterodactylus.util.template.TemplateContext;
/**
* This page lets the user unlock a {@link Sone} to allow its insertion.
* {@inheritDoc}
*/
@Override
- protected void processTemplate(Request request, DataProvider dataProvider) throws RedirectException {
- super.processTemplate(request, dataProvider);
+ protected void processTemplate(Request request, TemplateContext templateContext) throws RedirectException {
+ super.processTemplate(request, templateContext);
String soneId = request.getHttpRequest().getPartAsStringFailsafe("sone", 44);
Sone sone = webInterface.getCore().getLocalSone(soneId, false);
if (sone != null) {
import net.pterodactylus.sone.core.Core;
import net.pterodactylus.sone.data.Sone;
import net.pterodactylus.sone.web.page.Page.Request.Method;
-import net.pterodactylus.util.template.DataProvider;
import net.pterodactylus.util.template.Template;
+import net.pterodactylus.util.template.TemplateContext;
/**
* Page that lets the user untrust another Sone. This will remove all trust
* {@inheritDoc}
*/
@Override
- protected void processTemplate(Request request, DataProvider dataProvider) throws RedirectException {
- super.processTemplate(request, dataProvider);
+ protected void processTemplate(Request request, TemplateContext templateContext) throws RedirectException {
+ super.processTemplate(request, templateContext);
if (request.getMethod() == Method.POST) {
String returnPage = request.getHttpRequest().getPartAsStringFailsafe("returnPage", 256);
String identity = request.getHttpRequest().getPartAsStringFailsafe("sone", 44);
import net.pterodactylus.sone.data.Post;
import net.pterodactylus.sone.data.Reply;
-import net.pterodactylus.util.template.DataProvider;
import net.pterodactylus.util.template.Template;
+import net.pterodactylus.util.template.TemplateContext;
/**
* This page lets the user view a post and all its replies.
* {@inheritDoc}
*/
@Override
- protected void processTemplate(Request request, DataProvider dataProvider) throws RedirectException {
- super.processTemplate(request, dataProvider);
+ protected void processTemplate(Request request, TemplateContext templateContext) throws RedirectException {
+ super.processTemplate(request, templateContext);
String postId = request.getHttpRequest().getParam("post");
Post post = webInterface.getCore().getPost(postId);
- dataProvider.set("post", post);
+ templateContext.set("post", post);
}
/**
* {@inheritDoc}
*/
@Override
- protected void postProcess(Request request, DataProvider dataProvider) {
- Post post = (Post) dataProvider.get("post");
+ protected void postProcess(Request request, TemplateContext templateContext) {
+ Post post = (Post) templateContext.get("post");
webInterface.getCore().markPostKnown(post);
for (Reply reply : webInterface.getCore().getReplies(post)) {
webInterface.getCore().markReplyKnown(reply);
import net.pterodactylus.sone.data.Post;
import net.pterodactylus.sone.data.Reply;
import net.pterodactylus.sone.data.Sone;
-import net.pterodactylus.util.template.DataProvider;
import net.pterodactylus.util.template.Template;
+import net.pterodactylus.util.template.TemplateContext;
/**
* Lets the user browser another Sone.
* {@inheritDoc}
*/
@Override
- protected void processTemplate(Request request, DataProvider dataProvider) throws RedirectException {
- super.processTemplate(request, dataProvider);
+ protected void processTemplate(Request request, TemplateContext templateContext) throws RedirectException {
+ super.processTemplate(request, templateContext);
String soneId = request.getHttpRequest().getParam("sone");
Sone sone = webInterface.getCore().getSone(soneId, false);
- dataProvider.set("sone", sone);
+ templateContext.set("sone", sone);
}
/**
* {@inheritDoc}
*/
@Override
- protected void postProcess(Request request, DataProvider dataProvider) {
- Sone sone = (Sone) dataProvider.get("sone");
+ protected void postProcess(Request request, TemplateContext templateContext) {
+ Sone sone = (Sone) templateContext.get("sone");
if (sone == null) {
return;
}
import net.pterodactylus.util.notify.NotificationManager;
import net.pterodactylus.util.notify.TemplateNotification;
import net.pterodactylus.util.template.DateFilter;
-import net.pterodactylus.util.template.DefaultTemplateFactory;
+import net.pterodactylus.util.template.HtmlFilter;
import net.pterodactylus.util.template.MatchFilter;
import net.pterodactylus.util.template.PaginationPlugin;
+import net.pterodactylus.util.template.Provider;
import net.pterodactylus.util.template.ReflectionAccessor;
+import net.pterodactylus.util.template.ReplaceFilter;
+import net.pterodactylus.util.template.StoreFilter;
import net.pterodactylus.util.template.Template;
+import net.pterodactylus.util.template.TemplateContext;
+import net.pterodactylus.util.template.TemplateContextFactory;
import net.pterodactylus.util.template.TemplateException;
-import net.pterodactylus.util.template.TemplateFactory;
-import net.pterodactylus.util.template.TemplateProvider;
+import net.pterodactylus.util.template.TemplateParser;
import net.pterodactylus.util.template.XmlFilter;
import net.pterodactylus.util.thread.Ticker;
import net.pterodactylus.util.version.Version;
/** The form password. */
private final String formPassword;
- /** The template factory. */
- private DefaultTemplateFactory templateFactory;
+ /** The template context factory. */
+ private final TemplateContextFactory templateContextFactory;
/** The “new Sone” notification. */
private final ListNotification<Sone> newSoneNotification;
* @param sonePlugin
* The Sone plugin
*/
+ @SuppressWarnings("synthetic-access")
public WebInterface(SonePlugin sonePlugin) {
this.sonePlugin = sonePlugin;
formPassword = sonePlugin.pluginRespirator().getToadletContainer().getFormPassword();
- templateFactory = new DefaultTemplateFactory();
- 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(Identity.class, new IdentityAccessor(getCore()));
- templateFactory.addAccessor(NotificationManager.class, new NotificationManagerAccessor());
- templateFactory.addAccessor(Trust.class, new TrustAccessor());
- templateFactory.addFilter("date", new DateFilter());
- templateFactory.addFilter("l10n", new L10nFilter(getL10n()));
- templateFactory.addFilter("substring", new SubstringFilter());
- templateFactory.addFilter("xml", new XmlFilter());
- templateFactory.addFilter("change", new RequestChangeFilter());
- templateFactory.addFilter("match", new MatchFilter());
- templateFactory.addFilter("css", new CssClassNameFilter());
- templateFactory.addFilter("js", new JavascriptFilter());
- templateFactory.addFilter("parse", new ParserFilter(templateFactory));
- templateFactory.addFilter("unknown", new UnknownDateFilter(getL10n(), "View.Sone.Text.UnknownDate"));
- templateFactory.addPlugin("getpage", new GetPagePlugin());
- templateFactory.addPlugin("paginate", new PaginationPlugin());
- templateFactory.setTemplateProvider(new ClassPathTemplateProvider(templateFactory));
- templateFactory.addTemplateObject("formPassword", formPassword);
+ templateContextFactory = new TemplateContextFactory();
+ templateContextFactory.addAccessor(Object.class, new ReflectionAccessor());
+ templateContextFactory.addAccessor(Collection.class, new CollectionAccessor());
+ templateContextFactory.addAccessor(Sone.class, new SoneAccessor(getCore()));
+ templateContextFactory.addAccessor(Post.class, new PostAccessor(getCore()));
+ templateContextFactory.addAccessor(Reply.class, new ReplyAccessor(getCore()));
+ templateContextFactory.addAccessor(Identity.class, new IdentityAccessor(getCore()));
+ templateContextFactory.addAccessor(NotificationManager.class, new NotificationManagerAccessor());
+ templateContextFactory.addAccessor(Trust.class, new TrustAccessor());
+ templateContextFactory.addFilter("date", new DateFilter());
+ templateContextFactory.addFilter("html", new HtmlFilter());
+ templateContextFactory.addFilter("replace", new ReplaceFilter());
+ templateContextFactory.addFilter("store", new StoreFilter());
+ templateContextFactory.addFilter("l10n", new L10nFilter(getL10n()));
+ templateContextFactory.addFilter("substring", new SubstringFilter());
+ templateContextFactory.addFilter("xml", new XmlFilter());
+ templateContextFactory.addFilter("change", new RequestChangeFilter());
+ templateContextFactory.addFilter("match", new MatchFilter());
+ templateContextFactory.addFilter("css", new CssClassNameFilter());
+ templateContextFactory.addFilter("js", new JavascriptFilter());
+ templateContextFactory.addFilter("parse", new ParserFilter(templateContextFactory));
+ templateContextFactory.addFilter("unknown", new UnknownDateFilter(getL10n(), "View.Sone.Text.UnknownDate"));
+ templateContextFactory.addPlugin("getpage", new GetPagePlugin());
+ templateContextFactory.addPlugin("paginate", new PaginationPlugin());
+ templateContextFactory.addProvider(Provider.TEMPLATE_CONTEXT_PROVIDER);
+ templateContextFactory.addProvider(new ClassPathTemplateProvider());
+ templateContextFactory.addTemplateObject("formPassword", formPassword);
/* create notifications. */
- Template newSoneNotificationTemplate = templateFactory.createTemplate(createReader("/templates/notify/newSoneNotification.html"));
+ Template newSoneNotificationTemplate = TemplateParser.parse(createReader("/templates/notify/newSoneNotification.html"));
newSoneNotification = new ListNotification<Sone>("new-sone-notification", "sones", newSoneNotificationTemplate);
- Template newPostNotificationTemplate = templateFactory.createTemplate(createReader("/templates/notify/newPostNotification.html"));
+ Template newPostNotificationTemplate = TemplateParser.parse(createReader("/templates/notify/newPostNotification.html"));
newPostNotification = new ListNotification<Post>("new-post-notification", "posts", newPostNotificationTemplate);
- Template newReplyNotificationTemplate = templateFactory.createTemplate(createReader("/templates/notify/newReplyNotification.html"));
+ Template newReplyNotificationTemplate = TemplateParser.parse(createReader("/templates/notify/newReplyNotification.html"));
newReplyNotification = new ListNotification<Reply>("new-replies-notification", "replies", newReplyNotificationTemplate);
- Template rescuingSonesTemplate = templateFactory.createTemplate(createReader("/templates/notify/rescuingSonesNotification.html"));
+ Template rescuingSonesTemplate = TemplateParser.parse(createReader("/templates/notify/rescuingSonesNotification.html"));
rescuingSonesNotification = new ListNotification<Sone>("sones-being-rescued-notification", "sones", rescuingSonesTemplate);
- Template sonesRescuedTemplate = templateFactory.createTemplate(createReader("/templates/notify/sonesRescuedNotification.html"));
+ Template sonesRescuedTemplate = TemplateParser.parse(createReader("/templates/notify/sonesRescuedNotification.html"));
sonesRescuedNotification = new ListNotification<Sone>("sones-rescued-notification", "sones", sonesRescuedTemplate);
- Template lockedSonesTemplate = templateFactory.createTemplate(createReader("/templates/notify/lockedSonesNotification.html"));
+ Template lockedSonesTemplate = TemplateParser.parse(createReader("/templates/notify/lockedSonesNotification.html"));
lockedSonesNotification = new ListNotification<Sone>("sones-locked-notification", "sones", lockedSonesTemplate);
- Template newVersionTemplate = templateFactory.createTemplate(createReader("/templates/notify/newVersionNotification.html"));
+ Template newVersionTemplate = TemplateParser.parse(createReader("/templates/notify/newVersionNotification.html"));
newVersionNotification = new TemplateNotification("new-version-notification", newVersionTemplate);
}
}
/**
+ * Returns the template context factory of the web interface.
+ *
+ * @return The template context factory
+ */
+ public TemplateContextFactory getTemplateContextFactory() {
+ return templateContextFactory;
+ }
+
+ /**
* Returns the current session, creating a new session if there is no
* current session.
*
*/
public void setFirstStart(boolean firstStart) {
if (firstStart) {
- Template firstStartNotificationTemplate = templateFactory.createTemplate(createReader("/templates/notify/firstStartNotification.html"));
+ Template firstStartNotificationTemplate = TemplateParser.parse(createReader("/templates/notify/firstStartNotification.html"));
Notification firstStartNotification = new TemplateNotification("first-start-notification", firstStartNotificationTemplate);
notificationManager.addNotification(firstStartNotification);
}
*/
public void setNewConfig(boolean newConfig) {
if (newConfig && !hasFirstStartNotification()) {
- Template configNotReadNotificationTemplate = templateFactory.createTemplate(createReader("/templates/notify/configNotReadNotification.html"));
+ Template configNotReadNotificationTemplate = TemplateParser.parse(createReader("/templates/notify/configNotReadNotification.html"));
Notification configNotReadNotification = new TemplateNotification("config-not-read-notification", configNotReadNotificationTemplate);
notificationManager.addNotification(configNotReadNotification);
}
registerToadlets();
/* notification templates. */
- Template startupNotificationTemplate = templateFactory.createTemplate(createReader("/templates/notify/startupNotification.html"));
+ Template startupNotificationTemplate = TemplateParser.parse(createReader("/templates/notify/startupNotification.html"));
final TemplateNotification startupNotification = new TemplateNotification("startup-notification", startupNotificationTemplate);
notificationManager.addNotification(startupNotification);
}
}, "Sone Startup Notification Remover");
- Template wotMissingNotificationTemplate = templateFactory.createTemplate(createReader("/templates/notify/wotMissingNotification.html"));
+ Template wotMissingNotificationTemplate = TemplateParser.parse(createReader("/templates/notify/wotMissingNotification.html"));
final TemplateNotification wotMissingNotification = new TemplateNotification("wot-missing-notification", wotMissingNotificationTemplate);
Ticker.getInstance().registerEvent(System.currentTimeMillis() + (15 * 1000), new Runnable() {
* Register all toadlets.
*/
private void registerToadlets() {
- Template emptyTemplate = templateFactory.createTemplate(new StringReader(""));
- Template loginTemplate = templateFactory.createTemplate(createReader("/templates/login.html"));
- Template indexTemplate = templateFactory.createTemplate(createReader("/templates/index.html"));
- Template knownSonesTemplate = templateFactory.createTemplate(createReader("/templates/knownSones.html"));
- Template createSoneTemplate = templateFactory.createTemplate(createReader("/templates/createSone.html"));
- Template createPostTemplate = templateFactory.createTemplate(createReader("/templates/createPost.html"));
- Template createReplyTemplate = templateFactory.createTemplate(createReader("/templates/createReply.html"));
- Template editProfileTemplate = templateFactory.createTemplate(createReader("/templates/editProfile.html"));
- Template editProfileFieldTemplate = templateFactory.createTemplate(createReader("/templates/editProfileField.html"));
- Template deleteProfileFieldTemplate = templateFactory.createTemplate(createReader("/templates/deleteProfileField.html"));
- Template viewSoneTemplate = templateFactory.createTemplate(createReader("/templates/viewSone.html"));
- Template viewPostTemplate = templateFactory.createTemplate(createReader("/templates/viewPost.html"));
- Template deletePostTemplate = templateFactory.createTemplate(createReader("/templates/deletePost.html"));
- Template deleteReplyTemplate = templateFactory.createTemplate(createReader("/templates/deleteReply.html"));
- Template deleteSoneTemplate = templateFactory.createTemplate(createReader("/templates/deleteSone.html"));
- Template noPermissionTemplate = templateFactory.createTemplate(createReader("/templates/noPermission.html"));
- Template optionsTemplate = templateFactory.createTemplate(createReader("/templates/options.html"));
- Template aboutTemplate = templateFactory.createTemplate(createReader("/templates/about.html"));
- Template invalidTemplate = templateFactory.createTemplate(createReader("/templates/invalid.html"));
- Template postTemplate = templateFactory.createTemplate(createReader("/templates/include/viewPost.html"));
- Template replyTemplate = templateFactory.createTemplate(createReader("/templates/include/viewReply.html"));
+ Template emptyTemplate = TemplateParser.parse(new StringReader(""));
+ Template loginTemplate = TemplateParser.parse(createReader("/templates/login.html"));
+ Template indexTemplate = TemplateParser.parse(createReader("/templates/index.html"));
+ Template knownSonesTemplate = TemplateParser.parse(createReader("/templates/knownSones.html"));
+ Template createSoneTemplate = TemplateParser.parse(createReader("/templates/createSone.html"));
+ Template createPostTemplate = TemplateParser.parse(createReader("/templates/createPost.html"));
+ Template createReplyTemplate = TemplateParser.parse(createReader("/templates/createReply.html"));
+ Template editProfileTemplate = TemplateParser.parse(createReader("/templates/editProfile.html"));
+ Template editProfileFieldTemplate = TemplateParser.parse(createReader("/templates/editProfileField.html"));
+ Template deleteProfileFieldTemplate = TemplateParser.parse(createReader("/templates/deleteProfileField.html"));
+ Template viewSoneTemplate = TemplateParser.parse(createReader("/templates/viewSone.html"));
+ Template viewPostTemplate = TemplateParser.parse(createReader("/templates/viewPost.html"));
+ Template deletePostTemplate = TemplateParser.parse(createReader("/templates/deletePost.html"));
+ Template deleteReplyTemplate = TemplateParser.parse(createReader("/templates/deleteReply.html"));
+ Template deleteSoneTemplate = TemplateParser.parse(createReader("/templates/deleteSone.html"));
+ Template noPermissionTemplate = TemplateParser.parse(createReader("/templates/noPermission.html"));
+ Template optionsTemplate = TemplateParser.parse(createReader("/templates/options.html"));
+ Template aboutTemplate = TemplateParser.parse(createReader("/templates/about.html"));
+ Template invalidTemplate = TemplateParser.parse(createReader("/templates/invalid.html"));
+ Template postTemplate = TemplateParser.parse(createReader("/templates/include/viewPost.html"));
+ Template replyTemplate = TemplateParser.parse(createReader("/templates/include/viewReply.html"));
PageToadletFactory pageToadletFactory = new PageToadletFactory(sonePlugin.pluginRespirator().getHLSimpleClient(), "/Sone/");
pageToadlets.add(pageToadletFactory.createPageToadlet(new IndexPage(indexTemplate, this), "Index"));
try {
return new InputStreamReader(getClass().getResourceAsStream(resourceName), "UTF-8");
} catch (UnsupportedEncodingException uee1) {
+ System.out.println(" fail.");
return null;
}
}
*/
@Override
public void updateFound(Version version, long releaseTime) {
- newVersionNotification.set("version", version);
- newVersionNotification.set("releaseTime", releaseTime);
+ newVersionNotification.getTemplateContext().set("version", version);
+ newVersionNotification.getTemplateContext().set("releaseTime", releaseTime);
notificationManager.addNotification(newVersionNotification);
}
*
* @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
*/
- private class ClassPathTemplateProvider implements TemplateProvider {
-
- /** The template factory. */
- @SuppressWarnings("hiding")
- private final TemplateFactory templateFactory;
-
- /**
- * Creates a new template provider that locates templates on the
- * classpath.
- *
- * @param templateFactory
- * The template factory to create the templates
- */
- public ClassPathTemplateProvider(TemplateFactory templateFactory) {
- this.templateFactory = templateFactory;
- }
+ private class ClassPathTemplateProvider implements Provider {
/**
* {@inheritDoc}
*/
@Override
@SuppressWarnings("synthetic-access")
- public Template getTemplate(String templateName) {
+ public Template getTemplate(TemplateContext templateContext, String templateName) {
Reader templateReader = createReader("/templates/" + templateName);
if (templateReader == null) {
return null;
}
- Template template = templateFactory.createTemplate(templateReader);
+ Template template = null;
try {
- template.parse();
+ template = TemplateParser.parse(templateReader);
} catch (TemplateException te1) {
logger.log(Level.WARNING, "Could not parse template “" + templateName + "” for inclusion!", te1);
}
import net.pterodactylus.sone.web.WebInterface;
import net.pterodactylus.util.io.Closer;
import net.pterodactylus.util.json.JsonObject;
-import net.pterodactylus.util.template.DataProvider;
import net.pterodactylus.util.template.Template;
+import net.pterodactylus.util.template.TemplateContext;
import net.pterodactylus.util.template.TemplateException;
/**
jsonPost.put("recipient", (post.getRecipient() == null) ? null : post.getRecipient().getId());
jsonPost.put("time", post.getTime());
StringWriter stringWriter = new StringWriter();
- DataProvider dataProvider = postTemplate.createDataProvider();
- dataProvider.set("post", post);
- dataProvider.set("currentSone", currentSone);
+ TemplateContext templateContext = webInterface.getTemplateContextFactory().createTemplateContext();
+ templateContext.set("post", post);
+ templateContext.set("currentSone", currentSone);
try {
- postTemplate.render(dataProvider, stringWriter);
+ postTemplate.render(templateContext, stringWriter);
} catch (TemplateException te1) {
/* TODO - shouldn’t happen. */
} finally {
import net.pterodactylus.sone.web.WebInterface;
import net.pterodactylus.util.io.Closer;
import net.pterodactylus.util.json.JsonObject;
-import net.pterodactylus.util.template.DataProvider;
import net.pterodactylus.util.template.Template;
+import net.pterodactylus.util.template.TemplateContext;
import net.pterodactylus.util.template.TemplateException;
/**
jsonReply.put("soneId", reply.getSone().getId());
jsonReply.put("time", reply.getTime());
StringWriter stringWriter = new StringWriter();
- DataProvider dataProvider = replyTemplate.createDataProvider();
- dataProvider.set("reply", reply);
- dataProvider.set("currentSone", currentSone);
+ TemplateContext templateContext = webInterface.getTemplateContextFactory().createTemplateContext();
+ templateContext.set("reply", reply);
+ templateContext.set("currentSone", currentSone);
try {
- replyTemplate.render(dataProvider, stringWriter);
+ replyTemplate.render(templateContext, stringWriter);
} catch (TemplateException te1) {
/* TODO - shouldn’t happen. */
} finally {
package net.pterodactylus.sone.web.ajax;
+import java.io.IOException;
+import java.io.StringWriter;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import net.pterodactylus.util.json.JsonArray;
import net.pterodactylus.util.json.JsonObject;
import net.pterodactylus.util.notify.Notification;
+import net.pterodactylus.util.notify.TemplateNotification;
/**
* The “get status” AJAX handler returns all information that is necessary to
* The notification to create a JSON object
* @return The JSON object
*/
- private static JsonObject createJsonNotification(Notification notification) {
+ private JsonObject createJsonNotification(Notification notification) {
JsonObject jsonNotification = new JsonObject();
jsonNotification.put("id", notification.getId());
- jsonNotification.put("text", notification.toString());
+ StringWriter notificationWriter = new StringWriter();
+ try {
+ if (notification instanceof TemplateNotification) {
+ ((TemplateNotification) notification).render(webInterface.getTemplateContextFactory().createTemplateContext().mergeContext(((TemplateNotification) notification).getTemplateContext()), notificationWriter);
+ } else {
+ notification.render(notificationWriter);
+ }
+ } catch (IOException ioe1) {
+ /* StringWriter never throws, ignore. */
+ }
+ jsonNotification.put("text", notificationWriter.toString());
jsonNotification.put("createdTime", notification.getCreatedTime());
jsonNotification.put("lastUpdatedTime", notification.getLastUpdatedTime());
jsonNotification.put("dismissable", notification.isDismissable());
import net.pterodactylus.sone.web.page.Page.Request.Method;
import net.pterodactylus.util.logging.Logging;
-import net.pterodactylus.util.template.DataProvider;
import net.pterodactylus.util.template.Template;
+import net.pterodactylus.util.template.TemplateContext;
+import net.pterodactylus.util.template.TemplateContextFactory;
import freenet.clients.http.LinkEnabledCallback;
import freenet.clients.http.PageMaker;
import freenet.clients.http.PageNode;
/** The path of the page. */
private final String path;
+ /** The template context factory. */
+ private final TemplateContextFactory templateContextFactory;
+
/** The template to render. */
private final Template template;
*
* @param path
* The path of the page
+ * @param templateContextFactory
+ * The template context factory
* @param template
* The template to render
* @param l10n
* The target to redirect to if a POST request does not contain
* the correct form password
*/
- public TemplatePage(String path, Template template, BaseL10n l10n, String pageTitleKey, String invalidFormPasswordRedirectTarget) {
+ public TemplatePage(String path, TemplateContextFactory templateContextFactory, Template template, BaseL10n l10n, String pageTitleKey, String invalidFormPasswordRedirectTarget) {
this.path = path;
+ this.templateContextFactory = templateContextFactory;
this.template = template;
this.l10n = l10n;
this.pageTitleKey = pageTitleKey;
pageNode.addForwardLink("icon", shortcutIcon);
}
- DataProvider dataProvider = template.createDataProvider();
+ TemplateContext templateContext = templateContextFactory.createTemplateContext();
+ templateContext.mergeContext(template.getInitialContext());
try {
long start = System.nanoTime();
- processTemplate(request, dataProvider);
+ processTemplate(request, templateContext);
long finish = System.nanoTime();
logger.log(Level.FINEST, "Template was rendered in " + ((finish - start) / 1000) / 1000.0 + "ms.");
} catch (RedirectException re1) {
}
StringWriter stringWriter = new StringWriter();
- template.render(dataProvider, stringWriter);
+ template.render(templateContext, stringWriter);
pageNode.content.addChild("%", stringWriter.toString());
- postProcess(request, dataProvider);
+ postProcess(request, templateContext);
return new Response(200, "OK", "text/html", pageNode.outer.generate());
}
*
* @param request
* The request that is rendered
- * @param dataProvider
- * The data provider to set variables in
+ * @param templateContext
+ * The template context to set variables in
* @throws RedirectException
* if the processing page wants to redirect after processing
*/
- protected void processTemplate(Request request, DataProvider dataProvider) throws RedirectException {
+ protected void processTemplate(Request request, TemplateContext templateContext) throws RedirectException {
/* do nothing. */
}
*
* @param request
* The request being processed
- * @param dataProvider
- * The data provider that supplied the rendered data
+ * @param templateContext
+ * The template context that supplied the rendered data
*/
- protected void postProcess(Request request, DataProvider dataProvider) {
+ protected void postProcess(Request request, TemplateContext templateContext) {
/* do nothing. */
}
/**
* Exception that can be thrown to signal that a subclassed {@link Page}
* wants to redirect the user during the
- * {@link TemplatePage#processTemplate(net.pterodactylus.sone.web.page.Page.Request, DataProvider)}
+ * {@link TemplatePage#processTemplate(net.pterodactylus.sone.web.page.Page.Request, TemplateContext)}
* method call.
*
* @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
<h1><%= Page.ViewSone.PostList.Title|l10n|insert needle="{sone}" key=sone.niceName|html></h1>
<div id="posts">
- <%getpage parameter=postPage>
- <%paginate list=sone.posts pagesize=25>
+ <%:getpage parameter=postPage>
+ <%:paginate list=sone.posts pagesize=25>
<%= postPage|store key=pageParameter>
<%include include/pagination.html>
<%foreach pagination.items post>