Add duration filter to all templates.
[demoscenemusic.git] / src / main / java / net / pterodactylus / demoscenemusic / template / UserAccessor.java
1 /*
2  * DemosceneMusic - UserAccessor.java - Copyright © 2012 David Roden
3  *
4  * This program is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation, either version 3 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
16  */
17
18 package net.pterodactylus.demoscenemusic.template;
19
20 import net.pterodactylus.demoscenemusic.data.User;
21 import net.pterodactylus.util.template.Accessor;
22 import net.pterodactylus.util.template.ReflectionAccessor;
23 import net.pterodactylus.util.template.TemplateContext;
24
25 /**
26  * {@link Accessor} implementation that extends the {@link User} by the
27  * following members:
28  * <ul>
29  * <li><tt>god</tt> - returns {@code true} if the user’s level is
30  * {@link User#LEVEL_GOD} or higher.</li>
31  * <li><tt>user</tt> - returns {@code true} if the user’s level is
32  * {@link User#LEVEL_USER} or higher.</li>
33  * </ul>
34  *
35  * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
36  */
37 public class UserAccessor extends ReflectionAccessor {
38
39         /**
40          * {@inheritDoc}
41          */
42         @Override
43         public Object get(TemplateContext templateContext, Object object, String member) {
44                 User user = (User) object;
45                 if ("god".equals(member)) {
46                         return user.getLevel() >= User.LEVEL_GOD;
47                 } else if ("user".equals(member)) {
48                         return user.getLevel() >= User.LEVEL_USER;
49                 }
50                 return super.get(templateContext, object, member);
51         }
52
53 }