/* * 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.IRequestCycle; import org.wamblee.photos.model.Album; import org.wamblee.photos.model.Path; import org.wamblee.photos.model.Photo; import org.wamblee.photos.model.PhotoEntry; /** * Base class for a photo or album page. */ public abstract class PhotoEntryBean extends PhotosProtectedPage { protected static final String IMAGE_URL_PREFIX = "image"; /** * Relative path of the item. */ private Path _relativePath; /** * Constructs the item. */ public PhotoEntryBean() { _relativePath = new Path("/"); } /* (non-Javadoc) * @see org.apache.tapestry.AbstractPage#initialize() */ @Override protected void initialize() { _relativePath = new Path("/"); } /** * @return Returns the photoAlbum. */ public PhotoAlbum getPhotoAlbum(IRequestCycle aCycle) { return ((PhotosEngine)getEngine()).getPhotoAlbum(aCycle); } /** * @return Returns the relativePath. */ public String getRelativePath() { return _relativePath.toString(); } /** * @param relativePath The relativePath to set. */ public void setRelativePath(String relativePath) { if ( relativePath == null ) { // TODO investigate why null is passed //throw new IllegalArgumentException("relativePath is null"); _relativePath = new Path("/"); return; } _relativePath = new Path(relativePath); } /** * @return True if the item is a photo. */ public boolean isPhoto() { return getEntry() instanceof Photo; } /** * @return True if the item is an album. */ public boolean isAlbum() { return getEntry() instanceof Album; } /** * Gets the corresponding photo entry. * @return Photo entry. */ protected PhotoEntry getEntry() { return getPhotoAlbum(getRequestCycle()).getEntry(getRelativePath()); } /** * Gets the id of the item. */ public String getId() { return _relativePath.getId(); } /** * @return Parent of the item. */ public Album getParentEntry() { String path = getEntry().getPath(); path = new Path(path).parent().toString(); return (Album)getPhotoAlbum(getRequestCycle()).getEntry(path); } /** * Gets a reference to the home page. * @return Home page reference. */ public AlbumPageRef getHome() { return new AlbumPageRef(1, 0, "/", !getRelativePath().equals("/")); } /** * Gets a reference to the parent. * @return Parent page reference. */ public AlbumPageRef getParent() { Path path = new Path(getRelativePath()); if ( path.isRoot() ) { return new AlbumPageRef(1, 0, "", false); } return new AlbumPageRef(1, 0, path.parent().toString(), true); } /** * @return The engine for the photos application. */ protected PhotosEngine getPhotosEngine() { return (PhotosEngine)getEngine(); } }