/* * Copyright 2005 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.wamblee.photos.tapestry; import org.apache.tapestry.IAsset; import org.apache.tapestry.asset.ContextAsset; import org.apache.tapestry.request.RequestContext; import org.apache.tapestry.resource.ContextResourceLocation; import org.wamblee.photos.model.Album; import org.wamblee.photos.model.Path; import org.wamblee.photos.model.Photo; import org.wamblee.photos.model.PhotoEntry; /** * Photo bean class for presenting a photo in a jsp. */ public class PhotoPage extends PhotoEntryBean { public static final String PAGE_NAME = "Photo"; private static final String IMAGE_URL_PREFIX = "image"; public PhotoPage() { super(); initializeImpl(); } /* (non-Javadoc) * @see org.wamblee.photos.tapestry.PhotoEntryBean#initialize() */ @Override protected void initialize() { super.initialize(); initializeImpl(); } private void initializeImpl() { // Empty } public EntryRef getPrev() { Album album = getParentAlbum(); Photo prev = album.findPhotoBefore(getId()); if (prev == null) { return null; } return new EntryRef(prev.getPath(), true, true); } public EntryRef getNext() { Album album = getParentAlbum(); Photo next = album.findPhotoAfter(getId()); if ( next == null ) { return null; } return new EntryRef(next.getPath(), true, true); } public void setPhotoObject(PhotoEntry entry) { super.setRelativePath(entry.getPath()); } /** * @return */ private Album getParentAlbum() { Path path = new Path(getRelativePath()); Path parent = path.parent(); Album album = getPhotoAlbum(getRequestCycle()).getAlbum(parent.toString()); return album; } public IAsset getCurrentImage() { RequestContext context = getPage().getRequestCycle().getRequestContext(); String url = context.getResponse().encodeURL(IMAGE_URL_PREFIX + getRelativePath()); ContextResourceLocation resourceLocation = new ContextResourceLocation( context.getServlet().getServletContext(), "/" + url); return new ContextAsset(resourceLocation, null); } }