From: David ‘Bombe’ Roden Date: Mon, 10 Jan 2011 11:10:39 +0000 (+0100) Subject: Add accessor for profile fields. X-Git-Tag: 0.4^2~9^2~47 X-Git-Url: https://git.pterodactylus.net/?a=commitdiff_plain;h=2cee36b47bf421ab43be6ca5a6be7fdb67441418;p=Sone.git Add accessor for profile fields. --- diff --git a/src/main/java/net/pterodactylus/sone/template/ProfileAccessor.java b/src/main/java/net/pterodactylus/sone/template/ProfileAccessor.java new file mode 100644 index 0000000..52f39dd --- /dev/null +++ b/src/main/java/net/pterodactylus/sone/template/ProfileAccessor.java @@ -0,0 +1,51 @@ +/* + * Sone - ProfileAccessor.java - Copyright © 2011 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.sone.template; + +import java.util.LinkedHashMap; +import java.util.Map; + +import net.pterodactylus.sone.data.Profile; +import net.pterodactylus.util.template.Accessor; +import net.pterodactylus.util.template.DataProvider; +import net.pterodactylus.util.template.ReflectionAccessor; + +/** + * {@link Accessor} for {@link Profile}s, especially for the profile fields. + * + * @author David ‘Bombe’ Roden + */ +public class ProfileAccessor extends ReflectionAccessor { + + /** + * {@inheritDoc} + */ + @Override + public Object get(DataProvider dataProvider, Object object, String member) { + Profile profile = (Profile) object; + if ("fields".equals(member)) { + Map fields = new LinkedHashMap(); + for (String field : profile.getFields()) { + fields.put(field, profile.getField(field)); + } + return fields; + } + return super.get(dataProvider, object, member); + } + +} diff --git a/src/main/java/net/pterodactylus/sone/web/WebInterface.java b/src/main/java/net/pterodactylus/sone/web/WebInterface.java index 6085ff8..e18521c 100644 --- a/src/main/java/net/pterodactylus/sone/web/WebInterface.java +++ b/src/main/java/net/pterodactylus/sone/web/WebInterface.java @@ -36,6 +36,7 @@ import java.util.logging.Logger; import net.pterodactylus.sone.core.Core; import net.pterodactylus.sone.core.CoreListener; import net.pterodactylus.sone.data.Post; +import net.pterodactylus.sone.data.Profile; import net.pterodactylus.sone.data.Reply; import net.pterodactylus.sone.data.Sone; import net.pterodactylus.sone.freenet.L10nFilter; @@ -48,6 +49,7 @@ import net.pterodactylus.sone.template.GetPagePlugin; import net.pterodactylus.sone.template.IdentityAccessor; import net.pterodactylus.sone.template.NotificationManagerAccessor; import net.pterodactylus.sone.template.PostAccessor; +import net.pterodactylus.sone.template.ProfileAccessor; import net.pterodactylus.sone.template.ReplyAccessor; import net.pterodactylus.sone.template.RequestChangeFilter; import net.pterodactylus.sone.template.SoneAccessor; @@ -159,6 +161,7 @@ public class WebInterface implements CoreListener { templateFactory.addAccessor(Object.class, new ReflectionAccessor()); templateFactory.addAccessor(Collection.class, new CollectionAccessor()); templateFactory.addAccessor(Sone.class, new SoneAccessor(getCore())); + templateFactory.addAccessor(Profile.class, new ProfileAccessor()); templateFactory.addAccessor(Post.class, new PostAccessor(getCore(), templateFactory)); templateFactory.addAccessor(Reply.class, new ReplyAccessor(getCore(), templateFactory)); templateFactory.addAccessor(Identity.class, new IdentityAccessor(getCore()));