KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > raptus > owxv3 > modules > filemgr > FileMgrDeleteObject


1 /*
2  * eAdmin/OWX
3  * Copyright (C) 1996-2003 OWX-Project Team <owx-team@gmx.net>
4  */

5
6 package com.raptus.owxv3.modules.filemgr;
7
8 import java.io.File JavaDoc;
9 import java.sql.SQLException JavaDoc;
10
11 import com.raptus.owxv3.*;
12 import com.raptus.owxv3.api.*;
13
14
15
16 /**
17  * <table width="100%" border="0">
18  * <tr>
19  * <td width="24%"><b>Filename</b></td><td width="76%">FileMgrDeleteObject.java</td>
20  * </tr>
21  * <tr>
22  * <td width="24%"><b>Author</b></td><td width="76%">REEA</td>
23  * </tr>
24  * <tr>
25  * <td width="24%"><b>Date</b></td><td width="76%">25th of September 2001</td>
26  * </tr>
27  * </table>
28  * <hr>
29  * <table width="100%" border="0">
30  * <tr>
31  * <td width="24%"><b>Date / Author</b></td><td width="76%"><b>Changes</b></td>
32  * </tr>
33  * </table>
34  * <hr>
35  * <table width="100%" border="0">
36  * <tr>
37  * <td>This class is performing the deleting of a file from the hard disk and from the database</td>
38  * </tr>
39  * </table>
40  * <hr>
41  */

42 public class FileMgrDeleteObject extends Object JavaDoc
43 //extends BusinessObject no use for this time to extend BusinessObject
44
{
45
46     /**
47      *The repository where a file is saved
48      */

49     protected String JavaDoc repository=null;
50
51
52     /**
53      * A GlobalResources object that will br used do the database modifications
54      */

55     protected GlobalResources gres = null;
56
57     /**
58      *The constructor, we need a Vmodule object to read from the owx-configuration file
59      */

60     public FileMgrDeleteObject(VModule vm,GlobalResources g){
61         gres=g;
62         XMLConfigManager cm = XMLConfigManager.getInstance();
63         //repository =vm.getStringProperty(FileMgrConstants.VMODULE_PROPERTY_REPOSITORY);
64
repository=cm.getPropertyByTree("virtualhost/vmodules/vmodule?name="+vm.getIdentification()+"/properties/property?name=file/property?name=repository","value");
65         if(! repository.endsWith(File.separator) )repository=repository+File.separator;
66     }
67
68     /**
69      *This method deletes the file first from the database then fisically from the disk
70      *If the database delete fails the file wont' be deleted
71      */

72
73     public boolean deleteFile(int fileid) throws SQLException JavaDoc{
74
75         GResFile gresfile=gres.loadFile(fileid);
76         if(gresfile.getUsageCount()!=0) return false;
77         String JavaDoc filename=gresfile.getFileName();
78         File JavaDoc fileondisk=new File JavaDoc(repository+gresfile.getType()+File.separator+filename);
79
80         gres.deleteFile(gresfile);
81
82         boolean success=fileondisk.delete();
83
84        if(success) return true;
85
86        return false;
87
88
89     }
90
91
92 }
93
Popular Tags