X-Git-Url: https://git.pterodactylus.net/?p=Sone.git;a=blobdiff_plain;f=src%2Fmain%2Fjava%2Fnet%2Fpterodactylus%2Fsone%2Ftemplate%2FImageAccessor.java;fp=src%2Fmain%2Fjava%2Fnet%2Fpterodactylus%2Fsone%2Ftemplate%2FImageAccessor.java;h=1c06d31bc4e5af5cca78a27d2c08843bdec21f47;hp=0000000000000000000000000000000000000000;hb=9a884536fcf2d56a822b8db44bbc9ca56a61cea2;hpb=2a3193f488ecff7496d7464e2e2213c82a2708a3 diff --git a/src/main/java/net/pterodactylus/sone/template/ImageAccessor.java b/src/main/java/net/pterodactylus/sone/template/ImageAccessor.java new file mode 100644 index 0000000..1c06d31 --- /dev/null +++ b/src/main/java/net/pterodactylus/sone/template/ImageAccessor.java @@ -0,0 +1,64 @@ +/* + * Sone - ImageAccessor.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 net.pterodactylus.sone.data.Album; +import net.pterodactylus.sone.data.Image; +import net.pterodactylus.util.template.Accessor; +import net.pterodactylus.util.template.ReflectionAccessor; +import net.pterodactylus.util.template.TemplateContext; + +/** + * {@link Accessor} implementation for {@link Image} objects. It adds the + * following properties: + * + * + * @author David ‘Bombe’ Roden + */ +public class ImageAccessor extends ReflectionAccessor { + + /** + * {@inheritDoc} + */ + @Override + public Object get(TemplateContext templateContext, Object object, String member) { + Image image = (Image) object; + if ("next".equals(member)) { + Album album = image.getAlbum(); + int imagePosition = album.getImages().indexOf(image); + if (imagePosition < album.getImages().size() - 1) { + return album.getImages().get(imagePosition + 1); + } + return null; + } else if ("previous".equals(member)) { + Album album = image.getAlbum(); + int imagePosition = album.getImages().indexOf(image); + if (imagePosition > 0) { + return album.getImages().get(imagePosition - 1); + } + return null; + } + return super.get(templateContext, object, member); + } + +}