From: David ‘Bombe’ Roden Date: Thu, 26 Jul 2012 09:56:17 +0000 (+0200) Subject: Add accessor for custom properties. X-Git-Url: https://git.pterodactylus.net/?a=commitdiff_plain;h=0dba6059126d63506663488f7f0f5bacd9a91e0f;p=demoscenemusic.git Add accessor for custom properties. --- diff --git a/src/main/java/net/pterodactylus/demoscenemusic/core/TemplateServlet.java b/src/main/java/net/pterodactylus/demoscenemusic/core/TemplateServlet.java index def7ea1..c1090f2 100644 --- a/src/main/java/net/pterodactylus/demoscenemusic/core/TemplateServlet.java +++ b/src/main/java/net/pterodactylus/demoscenemusic/core/TemplateServlet.java @@ -38,10 +38,12 @@ import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import net.pterodactylus.demoscenemusic.data.Artist; +import net.pterodactylus.demoscenemusic.data.Properties; 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.PropertiesAccessor; import net.pterodactylus.demoscenemusic.template.UserAccessor; import net.pterodactylus.util.io.Closer; import net.pterodactylus.util.io.StreamCopier; @@ -82,6 +84,7 @@ public class TemplateServlet extends HttpServlet { templateContextFactory.addAccessor(Object.class, new ReflectionAccessor()); templateContextFactory.addAccessor(User.class, new UserAccessor()); + templateContextFactory.addAccessor(Properties.class, new PropertiesAccessor()); templateContextFactory.addFilter("html", new HtmlFilter()); CollectionSortFilter sortFilter = new CollectionSortFilter(); diff --git a/src/main/java/net/pterodactylus/demoscenemusic/template/PropertiesAccessor.java b/src/main/java/net/pterodactylus/demoscenemusic/template/PropertiesAccessor.java new file mode 100644 index 0000000..4e9bf5b --- /dev/null +++ b/src/main/java/net/pterodactylus/demoscenemusic/template/PropertiesAccessor.java @@ -0,0 +1,47 @@ +/* + * DemosceneMusic - PropertiesAccessor.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 . + */ + +package net.pterodactylus.demoscenemusic.template; + +import net.pterodactylus.demoscenemusic.data.Base; +import net.pterodactylus.demoscenemusic.data.Properties; +import net.pterodactylus.util.template.Accessor; +import net.pterodactylus.util.template.TemplateContext; + +/** + * {@link Accessor} implementation that can access the properties of the custom + * {@link Properties} of a data container. + * + * @see Base#getProperties() + * @author David ‘Bombe’ Roden + */ +public class PropertiesAccessor implements Accessor { + + // + // ACCESSOR METHODS + // + + /** + * {@inheritDoc} + */ + @Override + public Object get(TemplateContext templateContext, Object object, String member) { + Properties properties = (Properties) object; + return properties.get(member); + } + +}