Coverage details for base.jdbs.BackupDescriptor

LineHitsSource
1 /*******************************************************************************
2  *InternetCafe is a software solution that helps the management of Cybercafes
3  * according with the ITALIAN DECREE LAW ON ANTI-TERROR MEASURES, 27 JULY 2005.
4  * Copyright (C) 2006 Guido Angelo Ingenito
5  
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version 2
9  * of the License, or (at your option) any later version.
10  
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19  *******************************************************************************/
20 package base.jdbs;
21  
22 import java.io.File;
23 import java.io.FileInputStream;
24 import java.io.IOException;
25  
26 import javax.xml.parsers.DocumentBuilder;
27 import javax.xml.parsers.DocumentBuilderFactory;
28  
29 import org.apache.log4j.Logger;
30 import org.w3c.dom.Document;
31  
32 import base.util.FileUtil;
33  
341public class BackupDescriptor {
35     
361    private static final transient Logger logger = Logger.getLogger(BackupDescriptor.class.getName());
37     
38     private final File crc32ChecksumFile;
39     private final File md5DigestFile;
40     private final File md5SignedFile;
41     private final File x509CertificateFile;
42     private final File infoFile;
43     private final File backupFile;
44     private final File artifactDirectory;
45     private Backup backup;
46     
47     /**
48      * This is the default constructor.
49      * @param artifactDirectory The directory associated to a backup.
50      */
512    public BackupDescriptor(File artifactDirectory) {
52         
532        this.artifactDirectory = artifactDirectory;
54         
552        this.crc32ChecksumFile = new File(artifactDirectory,JDBSConstant.CRC32_FILE_NAME);
562        if(!crc32ChecksumFile.exists())logger.error("CRC32Checksum file doesn't exists...");
57         
582        this.md5DigestFile = new File(artifactDirectory, JDBSConstant.MD5_FILE_NAME);
592        if(!md5DigestFile.exists())logger.error("MD5Digest file doesn't exists...");
60         
612        this.md5SignedFile = new File(artifactDirectory, JDBSConstant.MD5_FILE_NAME+JDBSConstant.DOTTED_SIGNED_EXTENSION);
622        if(!md5SignedFile.exists())logger.error("MD5Digest signed file doesn't exists...");
63     
642        this.x509CertificateFile = new File(artifactDirectory, JDBSConstant.CERTIFICATE_FILE_NAME);
652        if(!x509CertificateFile.exists())logger.error("X509Certificate file doesn't exists...");
66  
672        this.infoFile = new File(artifactDirectory, JDBSConstant.XML_INFO_FILE_NAME);
682        if(!infoFile.exists())logger.error("Info file doesn't exists...");
69         
702        this.backupFile = new File(""+artifactDirectory+File.separatorChar+artifactDirectory.getName()+JDBSConstant.DOTTED_ZIP_EXTENSION);
712        if(!backupFile.exists())logger.error("Backup file doesn't exists...");
72         
73         
74         
752    }
76  
77  
78     /**
79      * @return Returns the backupFile.
80      */
81     public File getBackupFile() {
820        return backupFile;
83     }
84  
85  
86     /**
87      * @return Returns the crc32ChecksumFile.
88      */
89     public File getCrc32ChecksumFile() {
902        return crc32ChecksumFile;
91     }
92     
93     public String getCrc32ChecksumValue(){
94         try {
950            return FileUtil.fileContent(getCrc32ChecksumFile());
960        } catch (IOException e) {
97             // TODO Auto-generated catch block
980            e.printStackTrace();
99         }
1000        return null;
101     }
102  
103  
104     /**
105      * @return Returns the md5DigestFile.
106      */
107     public File getMd5DigestFile() {
1080        return md5DigestFile;
109     }
110     
111     public String getMd5DigestValue(){
112         try {
1130            return FileUtil.fileContent(getMd5DigestFile());
1140        } catch (IOException e) {
115             // TODO Auto-generated catch block
1160            e.printStackTrace();
117         }
1180        return null;
119     }
120  
121  
122     /**
123      * @return Returns the md5SignedFile.
124      */
125     public File getMd5SignedFile() {
1260        return md5SignedFile;
127     }
128  
129  
130     /**
131      * @return Returns the x509CertificateFile.
132      */
133     public File getX509CertificateFile() {
1340        return x509CertificateFile;
135     }
136     
137     /**
138      * @return Returns the infoFile.
139      */
140     public File getInfoFile() {
1410        return infoFile;
142     }
143     
144     public Backup getBackup(){
1450        if(this.backup == null && this.infoFile.exists()){
146             try{
1470                DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
1480                factory.setIgnoringComments(true);
1490                factory.setValidating(false);
1500                factory.setIgnoringElementContentWhitespace(true);
1510                DocumentBuilder docBuilder = factory.newDocumentBuilder();
1520                Document document = docBuilder.parse(new FileInputStream(infoFile));
1530                this.backup = new Backup(document);
1540            }catch(Exception ex){
1550                ex.printStackTrace();
1560            }
157         }
1580        return this.backup;
159     }
160  
161     
162  
163  
164     /* (non-Javadoc)
165      * @see java.lang.Object#toString()
166      */
167     @Override
168     public String toString() {
1691        StringBuffer stringBuffer = new StringBuffer();
1701        stringBuffer.append("CRC32ChecksumFile: "+this.getCrc32ChecksumFile() + " size in Byte: " + FileUtil.fileSizeInByte(this.getCrc32ChecksumFile()));
1710        stringBuffer.append("\n");
1720        stringBuffer.append("MD5DigestFile: "+this.getMd5DigestFile() + " size in Byte: " + FileUtil.fileSizeInByte(this.getMd5DigestFile()));
1730        stringBuffer.append("\n");
1740        stringBuffer.append("MD5SignedFile: "+this.getMd5SignedFile() + " size in Byte: " + FileUtil.fileSizeInByte(this.getMd5SignedFile()));
1750        stringBuffer.append("\n");
1760        stringBuffer.append("X509CertificateFile: "+this.getX509CertificateFile() + " size in Byte: " + FileUtil.fileSizeInByte(this.getX509CertificateFile()));
1770        stringBuffer.append("\n");
1780        stringBuffer.append("InfoFile: "+this.getInfoFile() + " size in Byte: " + FileUtil.fileSizeInByte(this.getInfoFile()));
1790        stringBuffer.append("\n");
1800        stringBuffer.append("BackupFile: "+this.getBackupFile() + " size in Byte: " + FileUtil.fileSizeInByte(this.getBackupFile()));
1810        stringBuffer.append("\n");
1820        stringBuffer.append("Total size in Byte: " + FileUtil.fileSizeInByte(new File(this.getBackupFile().getParent())));
183         
1840        return stringBuffer.toString();
185     }
186  
187  
188     /**
189      * @return Returns the artifactDirectory.
190      */
191     public File getArtifactDirectory() {
1922        return artifactDirectory;
193     }
194  
195 }

this report was generated by version 1.0.5 of jcoverage.
visit www.jcoverage.com for updates.

copyright © 2003, jcoverage ltd. all rights reserved.
Java is a trademark of Sun Microsystems, Inc. in the United States and other countries.