--- /dev/null
+/*
+ * Sone - AlbumAccessor.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 <http://www.gnu.org/licenses/>.
+ */
+
+package net.pterodactylus.sone.template;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import net.pterodactylus.sone.data.Album;
+import net.pterodactylus.util.template.Accessor;
+import net.pterodactylus.util.template.DataProvider;
+import net.pterodactylus.util.template.ReflectionAccessor;
+
+/**
+ * {@link Accessor} implementation for {@link Album}s. A property named
+ * “backlinks” is added, it returns links to all parents and the owner Sone of
+ * an album.
+ *
+ * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
+ */
+public class AlbumAccessor extends ReflectionAccessor {
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public Object get(DataProvider dataProvider, Object object, String member) {
+ Album album = (Album) object;
+ if ("backlinks".equals(member)) {
+ List<Map<String, String>> backlinks = new ArrayList<Map<String, String>>();
+ Album currentAlbum = album;
+ while (currentAlbum != null) {
+ backlinks.add(0, createLink("imageBrowser.html?album=" + album.getId(), album.getName()));
+ currentAlbum = currentAlbum.getParent();
+ }
+ backlinks.add(0, createLink("viewSone.html?sone=" + album.getSone().getId(), SoneAccessor.getNiceName(album.getSone())));
+ return backlinks;
+ }
+ return super.get(dataProvider, object, member);
+ }
+
+ //
+ // PRIVATE METHODS
+ //
+
+ /**
+ * Creates a map containing mappings for “target” and “link.”
+ *
+ * @param target
+ * The target to link to
+ * @param name
+ * The name of the link
+ * @return The created map containing the mappings
+ */
+ private Map<String, String> createLink(String target, String name) {
+ Map<String, String> link = new HashMap<String, String>();
+ link.put("target", target);
+ link.put("name", name);
+ return link;
+ }
+
+}
import net.pterodactylus.sone.core.Core;
import net.pterodactylus.sone.core.CoreListener;
+import net.pterodactylus.sone.data.Album;
import net.pterodactylus.sone.data.Post;
import net.pterodactylus.sone.data.Reply;
import net.pterodactylus.sone.data.Sone;
import net.pterodactylus.sone.freenet.wot.Identity;
import net.pterodactylus.sone.main.SonePlugin;
import net.pterodactylus.sone.notify.ListNotification;
+import net.pterodactylus.sone.template.AlbumAccessor;
import net.pterodactylus.sone.template.CollectionAccessor;
import net.pterodactylus.sone.template.CssClassNameFilter;
import net.pterodactylus.sone.template.GetPagePlugin;
templateFactory.addAccessor(Sone.class, new SoneAccessor(getCore()));
templateFactory.addAccessor(Post.class, new PostAccessor(getCore(), templateFactory));
templateFactory.addAccessor(Reply.class, new ReplyAccessor(getCore(), templateFactory));
+ templateFactory.addAccessor(Album.class, new AlbumAccessor());
templateFactory.addAccessor(Identity.class, new IdentityAccessor(getCore()));
templateFactory.addAccessor(NotificationManager.class, new NotificationManagerAccessor());
templateFactory.addFilter("date", new DateFilter());