1 4 package com.zerog.ia.customcode.util.fileutils; 5 6 import java.io.*; 7 8 import com.zerog.ia.api.pub.*; 9 10 18 public class DeleteFile extends CustomCodeAction 19 { 20 private static final String INSTALL_MESSAGE = "Removing files"; 21 private static final String UNINSTALL_MESSAGE = ""; 22 private static final String ERR_MSG = "DeleteFile: no file specified."; 23 private static final String FILE_VAR_NAME = "$DeleteFile_File$"; 24 private boolean isLoaded = false; 25 38 public void install( InstallerProxy ip ) throws InstallException 39 { 40 41 if(isLoaded == true) 42 return; 43 isLoaded = true; 44 45 47 String fileToDelete = ip.substitute( FILE_VAR_NAME ); 48 49 53 if ( fileToDelete.equals("") ) 54 { 55 error( fileToDelete ); 56 } 57 else 58 { 59 try { 60 deleteFile( fileToDelete ); 61 } catch ( IOException ioe ) { 62 throw new NonfatalInstallException( ioe.getMessage() ); 63 } 64 } 65 } 66 67 75 public void uninstall( UninstallerProxy up ) throws InstallException 76 { 77 } 78 79 85 public String getInstallStatusMessage() 86 { 87 return INSTALL_MESSAGE; 88 } 89 90 96 public String getUninstallStatusMessage() 97 { 98 return UNINSTALL_MESSAGE; 99 } 100 101 104 public static void deleteFile( String fileToDelete ) throws IOException 105 { 106 deleteFile( new File( fileToDelete ) ); 107 } 108 109 112 public static void deleteFile( File fileToDelete ) throws IOException 113 { 114 if ( fileToDelete.isFile() ) 115 { 116 if ( ! fileToDelete.delete() ) 117 { 118 throw new IOException( "Couldn't delete file: " 119 + fileToDelete.getAbsolutePath() ); 120 } 121 } 122 else 123 { 124 throw new IOException( 125 "Couldn't delete file because file is a directory: " + 126 fileToDelete.getAbsolutePath() ); 127 } 128 } 129 130 133 private void error( String path ) 134 { 135 System.err.println( ERR_MSG ); 136 System.err.println( "Path: " + path ); 137 } 138 } 139 | Popular Tags |