/* * 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.model.filesystem; import java.io.File; import java.io.IOException; import java.util.List; import org.wamblee.cache.Cache; import org.wamblee.photos.model.PhotoEntry; /** * Callback interface used to find a photo entry by id. */ class FindByIdCallback implements EntryFoundCallback { /** * Id of the entry to look for. */ private String _id; /** * Search result or null if not found yet. */ private PhotoEntry _entry; /** * Cache to use. */ private Cache _cache; /** * Constructs the callback. * @param aId Photo entry id to look for. */ public FindByIdCallback(String aId, Cache aCache) { _id = aId; _entry = null; _cache = aCache; } /** * Gets the entry that was found. * @return Photo entry or null if not found. */ public PhotoEntry getEntry() { return _entry; } /* * (non-Javadoc) * @see org.wamblee.photos.model.file.EntryFoundCallback#photoFound(java.io.File, java.io.File, java.lang.String) */ public boolean photoFound(List aEntries, File aThumbnail, File aPhoto, String aPath) { if ( FileSystemPhoto.getId(aPath).equals(_id)) { _entry = new FileSystemPhoto(aThumbnail, aPhoto, aPath); return false; } return true; // continue search. } /* * (non-Javadoc) * @see org.wamblee.photos.model.file.EntryFoundCallback#albumFound(java.io.File, java.lang.String) */ public boolean albumFound(List aEntries, File aAlbum, String aPath) throws IOException { FileSystemAlbum albumEntry = new FileSystemAlbum(aAlbum, aPath, _cache); if ( aAlbum.getName().equals(_id)) { _entry = albumEntry; return false; } return albumEntry.traverse(albumEntry.getPath(), aEntries, aAlbum, this); // continue search. } }