From 3abc078471d7e7516599eda01de011a23c328d63 Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Wed, 12 Jan 2011 10:28:44 +0100 Subject: [PATCH] =?utf8?q?Move=20=E2=80=9Cfields=E2=80=9D=20functionality?= =?utf8?q?=20into=20Profile,=20remove=20ProfileAccessor.?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .../java/net/pterodactylus/sone/data/Profile.java | 17 +++++++- .../sone/template/ProfileAccessor.java | 51 ---------------------- .../net/pterodactylus/sone/web/WebInterface.java | 3 -- 3 files changed, 16 insertions(+), 55 deletions(-) delete mode 100644 src/main/java/net/pterodactylus/sone/template/ProfileAccessor.java diff --git a/src/main/java/net/pterodactylus/sone/data/Profile.java b/src/main/java/net/pterodactylus/sone/data/Profile.java index 8dec42a..64aeae4 100644 --- a/src/main/java/net/pterodactylus/sone/data/Profile.java +++ b/src/main/java/net/pterodactylus/sone/data/Profile.java @@ -20,6 +20,7 @@ package net.pterodactylus.sone.data; import java.util.ArrayList; import java.util.Collections; import java.util.HashMap; +import java.util.LinkedHashMap; import java.util.List; import java.util.Map; @@ -332,10 +333,24 @@ public class Profile implements Fingerprintable { * * @return The fields of this profile */ - public List getFields() { + public List getFieldNames() { return Collections.unmodifiableList(fields); } + /** + * Returns all field names and their values, ordered the same way + * {@link #getFieldNames()} returns the names of the fields. + * + * @return All field names and values + */ + public Map getFields() { + Map fields = new LinkedHashMap(); + for (String field : getFieldNames()) { + fields.put(field, getField(field)); + } + return fields; + } + // // PRIVATE METHODS // diff --git a/src/main/java/net/pterodactylus/sone/template/ProfileAccessor.java b/src/main/java/net/pterodactylus/sone/template/ProfileAccessor.java deleted file mode 100644 index 52f39dd..0000000 --- a/src/main/java/net/pterodactylus/sone/template/ProfileAccessor.java +++ /dev/null @@ -1,51 +0,0 @@ -/* - * 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 e18521c..6085ff8 100644 --- a/src/main/java/net/pterodactylus/sone/web/WebInterface.java +++ b/src/main/java/net/pterodactylus/sone/web/WebInterface.java @@ -36,7 +36,6 @@ 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; @@ -49,7 +48,6 @@ 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; @@ -161,7 +159,6 @@ 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())); -- 2.7.4