KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > config > backup > ZipStorage


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the License). You may not use this file except in
5  * compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * https://glassfish.dev.java.net/public/CDDLv1.0.html or
9  * glassfish/bootstrap/legal/CDDLv1.0.txt.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * Header Notice in each file and include the License file
15  * at glassfish/bootstrap/legal/CDDLv1.0.txt.
16  * If applicable, add the following below the CDDL Header,
17  * with the fields enclosed by brackets [] replaced by
18  * you own identifying information:
19  * "Portions Copyrighted [year] [name of copyright owner]"
20  *
21  * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
22  */

23
24 /*
25  * ZipStorage.java
26  *
27  * Created on January 30, 2004, 7:15 PM
28  */

29
30 package com.sun.enterprise.config.backup;
31
32 import com.sun.enterprise.config.backup.util.FileListerRelative;
33 import com.sun.enterprise.config.backup.util.FileUtils;
34 import com.sun.enterprise.config.backup.util.ZipFileException;
35 import com.sun.enterprise.config.backup.util.ZipWriter;
36 import java.io.*;
37
38 /**
39  * This class implements storing backups as zip files.
40  * @author Byron Nevins
41  */

42 class ZipStorage
43 {
44     /**
45      * @param req
46      * @throws BackupException
47      */

48     ZipStorage(BackupRequest req) throws BackupException
49     {
50         if(req == null)
51             throw new BackupException("backup-res.NoBackupRequest", getClass().getName() + ".ctor");
52         
53         request = req;
54     }
55     
56     /**
57      * Backups the files to a zip file.
58      * @throws BackupException if there were any errors writing the file.
59      */

60     void store() throws BackupException
61     {
62         String JavaDoc zipName = FileUtils.safeGetCanonicalPath(request.backupFile);
63         String JavaDoc domainDirName = FileUtils.safeGetCanonicalPath(request.domainDir);
64         
65         FileListerRelative lister = new FileListerRelative(request.domainDir);
66         lister.keepEmptyDirectories(); // we want to restore any empty directories too!
67
String JavaDoc[] files = lister.getFiles();
68         
69         LoggerHelper.fine("Writing " + zipName);
70         
71         try
72         {
73             ZipWriter writer = new ZipWriter(zipName, domainDirName, files);
74
75             if(request.excludeDirs != null && request.excludeDirs.length > 0)
76                 writer.excludeDirs(request.excludeDirs);
77             
78             writer.safeWrite();
79         }
80         catch(ZipFileException zfe)
81         {
82             throw new BackupException("backup-res.ZipBackupError", zfe, zipName);
83         }
84     }
85
86     ///////////////////////////////////////////////////////////////////////////
87

88     void write() throws BackupException
89     {
90         
91     }
92
93     ///////////////////////////////////////////////////////////////////////////
94

95     private BackupRequest request;
96 }
97
Popular Tags