X-Git-Url: https://git.pterodactylus.net/?p=Sone.git;a=blobdiff_plain;f=src%2Fmain%2Fjava%2Fnet%2Fpterodactylus%2Fsone%2Fweb%2FWebInterface.java;h=9023ccf36cacbf70a71fc1a0844be8e7b2ac3126;hp=14c2c09cd7f3336322f7555912324bc115f94da9;hb=07ca98b45465f7a442e695fbfb6f59100260f39b;hpb=ecf753a31601e558b681daab0598009fe9eec99a diff --git a/src/main/java/net/pterodactylus/sone/web/WebInterface.java b/src/main/java/net/pterodactylus/sone/web/WebInterface.java index 14c2c09..9023ccf 100644 --- a/src/main/java/net/pterodactylus/sone/web/WebInterface.java +++ b/src/main/java/net/pterodactylus/sone/web/WebInterface.java @@ -84,11 +84,18 @@ import net.pterodactylus.sone.web.ajax.UntrustAjaxPage; import net.pterodactylus.sone.web.page.PageToadlet; import net.pterodactylus.sone.web.page.PageToadletFactory; import net.pterodactylus.sone.web.page.StaticPage; +import net.pterodactylus.util.cache.Cache; +import net.pterodactylus.util.cache.CacheException; +import net.pterodactylus.util.cache.CacheItem; +import net.pterodactylus.util.cache.DefaultCacheItem; +import net.pterodactylus.util.cache.MemoryCache; +import net.pterodactylus.util.cache.ValueRetriever; import net.pterodactylus.util.logging.Logging; import net.pterodactylus.util.notify.Notification; import net.pterodactylus.util.notify.NotificationManager; import net.pterodactylus.util.notify.TemplateNotification; import net.pterodactylus.util.template.DateFilter; +import net.pterodactylus.util.template.FormatFilter; import net.pterodactylus.util.template.HtmlFilter; import net.pterodactylus.util.template.MatchFilter; import net.pterodactylus.util.template.PaginationPlugin; @@ -193,6 +200,7 @@ public class WebInterface implements CoreListener { templateContextFactory.addFilter("js", new JavascriptFilter()); templateContextFactory.addFilter("parse", new ParserFilter(templateContextFactory)); templateContextFactory.addFilter("unknown", new UnknownDateFilter(getL10n(), "View.Sone.Text.UnknownDate")); + templateContextFactory.addFilter("format", new FormatFilter()); templateContextFactory.addPlugin("getpage", new GetPagePlugin()); templateContextFactory.addPlugin("paginate", new PaginationPlugin()); templateContextFactory.addProvider(Provider.TEMPLATE_CONTEXT_PROVIDER); @@ -301,6 +309,10 @@ public class WebInterface implements CoreListener { * currently logged in */ public Sone getCurrentSone(ToadletContext toadletContext, boolean create) { + Set localSones = getCore().getLocalSones(); + if (localSones.size() == 1) { + return localSones.iterator().next(); + } return getCurrentSone(getCurrentSession(toadletContext, create)); } @@ -753,8 +765,9 @@ public class WebInterface implements CoreListener { * {@inheritDoc} */ @Override - public void updateFound(Version version, long releaseTime) { - newVersionNotification.getTemplateContext().set("version", version); + public void updateFound(Version version, long releaseTime, long latestEdition) { + newVersionNotification.getTemplateContext().set("latestVersion", version); + newVersionNotification.getTemplateContext().set("latestEdition", latestEdition); newVersionNotification.getTemplateContext().set("releaseTime", releaseTime); notificationManager.addNotification(newVersionNotification); } @@ -768,12 +781,44 @@ public class WebInterface implements CoreListener { */ private class ClassPathTemplateProvider implements Provider { + /** Cache for templates. */ + private final Cache templateCache = new MemoryCache(new ValueRetriever() { + + @Override + @SuppressWarnings("synthetic-access") + public CacheItem