001 /** 002 * iFish - An iRiver iHP jukebox database creation tool 003 * 004 * Copyright (C) 2009 Richard "Shred" Körber 005 * http://ifish.shredzone.org 006 * 007 * This program is free software: you can redistribute it and/or modify 008 * it under the terms of the GNU General Public License as published by 009 * the Free Software Foundation, either version 3 of the License, or 010 * (at your option) any later version. 011 * 012 * This program is distributed in the hope that it will be useful, 013 * but WITHOUT ANY WARRANTY; without even the implied warranty of 014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 015 * GNU General Public License for more details. 016 * 017 * You should have received a copy of the GNU General Public License 018 * along with this program. If not, see <http://www.gnu.org/licenses/>. 019 */ 020 package net.shredzone.ifish.db; 021 022 import java.io.*; 023 024 /** 025 * If a class is implementing the RenameCallback, it will be invoked 026 * during database synchronisation, if a directory or file name is 027 * longer than 52 characters. Its task is to either rename the file 028 * to fit the filename length constrains, or throw an DatabaseException 029 * to abort the database creation. 030 * <p> 031 * Currently, directory renaming is not supported! 032 * 033 * @author Richard Körber <dev@shredzone.de> 034 * @version $Id: RenameCallback.java 291 2009-04-28 21:29:27Z shred $ 035 */ 036 public interface RenameCallback { 037 038 /** 039 * A directory name exceeded the maximum length of 52 characters. 040 * This method will either rename the directory and return the new 041 * directory name, or throw a DatabaseException. 042 * <p> 043 * <em>NOTE:</em> Currently, directory renaming is not supported, 044 * so an implementation MUST always throw a DatabaseException. 045 * 046 * @param base Base directory (jukebox mount point) 047 * @param directory Directory with the bad name 048 * @return Directory's new name 049 * @throws DatabaseException Directory could not be renamed 050 * @throws IOException An IO error occured during nenaming 051 */ 052 public File renameDirectory( File base, File directory ) 053 throws DatabaseException, IOException; 054 055 /** 056 * A file name exceeded the maximum length of 52 characters. 057 * This method will either rename the file and return the new 058 * file name, or throw a DatabaseException. 059 * 060 * @param base Base directory (jukebox mount point) 061 * @param file File with the bad name 062 * @return New file name 063 * @throws DatabaseException Directory could not be renamed 064 * @throws IOException An IO error occured during nenaming 065 */ 066 public File renameFile( File base, File file ) 067 throws DatabaseException, IOException; 068 069 /*--------------------------------------------------------------------*/ 070 071 /** 072 * A default implementation of the RenameCallback which will always 073 * fail throwing a DatabaseException. 074 */ 075 public static class DefaultRenameCallback implements RenameCallback { 076 077 /** 078 * A directory name exceeded the maximum length of 52 characters. 079 * This method will always throw an exception 080 * 081 * @param base Base directory (jukebox mount point) 082 * @param directory Directory with the bad name 083 * @return Directory's new name, null if this directory is to be ignored 084 * @throws DatabaseException Directory could not be renamed 085 * @throws IOException An IO error occured during nenaming 086 */ 087 @Override 088 public File renameDirectory( File base, File directory ) 089 throws DatabaseException, IOException { 090 throw new DatabaseException( "path name too long: "+directory ); 091 } 092 093 /** 094 * A file name exceeded the maximum length of 52 characters. 095 * This method will always throw a DatabaseException. 096 * 097 * @param base Base directory (jukebox mount point) 098 * @param file File with the bad name 099 * @return New file name, null if this file is to be ignored 100 * @throws DatabaseException Directory could not be renamed 101 * @throws IOException An IO error occured during nenaming 102 */ 103 @Override 104 public File renameFile( File base, File file ) 105 throws DatabaseException, IOException { 106 throw new DatabaseException( "file name too long: "+file ); 107 } 108 } 109 110 } 111