import net.pterodactylus.demoscenemusic.data.Artist;
import net.pterodactylus.demoscenemusic.data.Style;
import net.pterodactylus.demoscenemusic.data.Track;
+import net.pterodactylus.demoscenemusic.data.User;
import net.pterodactylus.demoscenemusic.page.ServletRequest;
+import net.pterodactylus.demoscenemusic.template.UserAccessor;
import net.pterodactylus.util.io.Closer;
import net.pterodactylus.util.io.StreamCopier;
import net.pterodactylus.util.template.ClassPathTemplateProvider;
core = (Core) config.getServletContext().getAttribute("core");
templateContextFactory.addAccessor(Object.class, new ReflectionAccessor());
+ templateContextFactory.addAccessor(User.class, new UserAccessor());
templateContextFactory.addFilter("html", new HtmlFilter());
CollectionSortFilter sortFilter = new CollectionSortFilter();
--- /dev/null
+/*
+ * DemosceneMusic - UserAccessor.java - Copyright © 2012 David Roden
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+package net.pterodactylus.demoscenemusic.template;
+
+import net.pterodactylus.demoscenemusic.data.User;
+import net.pterodactylus.util.template.Accessor;
+import net.pterodactylus.util.template.ReflectionAccessor;
+import net.pterodactylus.util.template.TemplateContext;
+
+/**
+ * {@link Accessor} implementation that extends the {@link User} by the
+ * following members:
+ * <ul>
+ * <li><tt>god</tt> - returns {@code true} if the user’s level is
+ * {@link User#LEVEL_GOD} or higher.</li>
+ * <li><tt>user</tt> - returns {@code true} if the user’s level is
+ * {@link User#LEVEL_USER} or higher.</li>
+ * </ul>
+ *
+ * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
+ */
+public class UserAccessor extends ReflectionAccessor {
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public Object get(TemplateContext templateContext, Object object, String member) {
+ User user = (User) object;
+ if ("god".equals(member)) {
+ return user.getLevel() >= User.LEVEL_GOD;
+ } else if ("user".equals(member)) {
+ return user.getLevel() >= User.LEVEL_USER;
+ }
+ return super.get(templateContext, object, member);
+ }
+
+}