| Line | Hits | Source |
|---|---|---|
| 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 | ||
| 34 | 1 | public class BackupDescriptor { |
| 35 | ||
| 36 | 1 | 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 | */ | |
| 51 | 2 | public BackupDescriptor(File artifactDirectory) { |
| 52 | ||
| 53 | 2 | this.artifactDirectory = artifactDirectory; |
| 54 | ||
| 55 | 2 | this.crc32ChecksumFile = new File(artifactDirectory,JDBSConstant.CRC32_FILE_NAME); |
| 56 | 2 | if(!crc32ChecksumFile.exists())logger.error("CRC32Checksum file doesn't exists..."); |
| 57 | ||
| 58 | 2 | this.md5DigestFile = new File(artifactDirectory, JDBSConstant.MD5_FILE_NAME); |
| 59 | 2 | if(!md5DigestFile.exists())logger.error("MD5Digest file doesn't exists..."); |
| 60 | ||
| 61 | 2 | this.md5SignedFile = new File(artifactDirectory, JDBSConstant.MD5_FILE_NAME+JDBSConstant.DOTTED_SIGNED_EXTENSION); |
| 62 | 2 | if(!md5SignedFile.exists())logger.error("MD5Digest signed file doesn't exists..."); |
| 63 | ||
| 64 | 2 | this.x509CertificateFile = new File(artifactDirectory, JDBSConstant.CERTIFICATE_FILE_NAME); |
| 65 | 2 | if(!x509CertificateFile.exists())logger.error("X509Certificate file doesn't exists..."); |
| 66 | ||
| 67 | 2 | this.infoFile = new File(artifactDirectory, JDBSConstant.XML_INFO_FILE_NAME); |
| 68 | 2 | if(!infoFile.exists())logger.error("Info file doesn't exists..."); |
| 69 | ||
| 70 | 2 | this.backupFile = new File(""+artifactDirectory+File.separatorChar+artifactDirectory.getName()+JDBSConstant.DOTTED_ZIP_EXTENSION); |
| 71 | 2 | if(!backupFile.exists())logger.error("Backup file doesn't exists..."); |
| 72 | ||
| 73 | ||
| 74 | ||
| 75 | 2 | } |
| 76 | ||
| 77 | ||
| 78 | /** | |
| 79 | * @return Returns the backupFile. | |
| 80 | */ | |
| 81 | public File getBackupFile() { | |
| 82 | 0 | return backupFile; |
| 83 | } | |
| 84 | ||
| 85 | ||
| 86 | /** | |
| 87 | * @return Returns the crc32ChecksumFile. | |
| 88 | */ | |
| 89 | public File getCrc32ChecksumFile() { | |
| 90 | 2 | return crc32ChecksumFile; |
| 91 | } | |
| 92 | ||
| 93 | public String getCrc32ChecksumValue(){ | |
| 94 | try { | |
| 95 | 0 | return FileUtil.fileContent(getCrc32ChecksumFile()); |
| 96 | 0 | } catch (IOException e) { |
| 97 | // TODO Auto-generated catch block | |
| 98 | 0 | e.printStackTrace(); |
| 99 | } | |
| 100 | 0 | return null; |
| 101 | } | |
| 102 | ||
| 103 | ||
| 104 | /** | |
| 105 | * @return Returns the md5DigestFile. | |
| 106 | */ | |
| 107 | public File getMd5DigestFile() { | |
| 108 | 0 | return md5DigestFile; |
| 109 | } | |
| 110 | ||
| 111 | public String getMd5DigestValue(){ | |
| 112 | try { | |
| 113 | 0 | return FileUtil.fileContent(getMd5DigestFile()); |
| 114 | 0 | } catch (IOException e) { |
| 115 | // TODO Auto-generated catch block | |
| 116 | 0 | e.printStackTrace(); |
| 117 | } | |
| 118 | 0 | return null; |
| 119 | } | |
| 120 | ||
| 121 | ||
| 122 | /** | |
| 123 | * @return Returns the md5SignedFile. | |
| 124 | */ | |
| 125 | public File getMd5SignedFile() { | |
| 126 | 0 | return md5SignedFile; |
| 127 | } | |
| 128 | ||
| 129 | ||
| 130 | /** | |
| 131 | * @return Returns the x509CertificateFile. | |
| 132 | */ | |
| 133 | public File getX509CertificateFile() { | |
| 134 | 0 | return x509CertificateFile; |
| 135 | } | |
| 136 | ||
| 137 | /** | |
| 138 | * @return Returns the infoFile. | |
| 139 | */ | |
| 140 | public File getInfoFile() { | |
| 141 | 0 | return infoFile; |
| 142 | } | |
| 143 | ||
| 144 | public Backup getBackup(){ | |
| 145 | 0 | if(this.backup == null && this.infoFile.exists()){ |
| 146 | try{ | |
| 147 | 0 | DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); |
| 148 | 0 | factory.setIgnoringComments(true); |
| 149 | 0 | factory.setValidating(false); |
| 150 | 0 | factory.setIgnoringElementContentWhitespace(true); |
| 151 | 0 | DocumentBuilder docBuilder = factory.newDocumentBuilder(); |
| 152 | 0 | Document document = docBuilder.parse(new FileInputStream(infoFile)); |
| 153 | 0 | this.backup = new Backup(document); |
| 154 | 0 | }catch(Exception ex){ |
| 155 | 0 | ex.printStackTrace(); |
| 156 | 0 | } |
| 157 | } | |
| 158 | 0 | return this.backup; |
| 159 | } | |
| 160 | ||
| 161 | ||
| 162 | ||
| 163 | ||
| 164 | /* (non-Javadoc) | |
| 165 | * @see java.lang.Object#toString() | |
| 166 | */ | |
| 167 | @Override | |
| 168 | public String toString() { | |
| 169 | 1 | StringBuffer stringBuffer = new StringBuffer(); |
| 170 | 1 | stringBuffer.append("CRC32ChecksumFile: "+this.getCrc32ChecksumFile() + " size in Byte: " + FileUtil.fileSizeInByte(this.getCrc32ChecksumFile())); |
| 171 | 0 | stringBuffer.append("\n"); |
| 172 | 0 | stringBuffer.append("MD5DigestFile: "+this.getMd5DigestFile() + " size in Byte: " + FileUtil.fileSizeInByte(this.getMd5DigestFile())); |
| 173 | 0 | stringBuffer.append("\n"); |
| 174 | 0 | stringBuffer.append("MD5SignedFile: "+this.getMd5SignedFile() + " size in Byte: " + FileUtil.fileSizeInByte(this.getMd5SignedFile())); |
| 175 | 0 | stringBuffer.append("\n"); |
| 176 | 0 | stringBuffer.append("X509CertificateFile: "+this.getX509CertificateFile() + " size in Byte: " + FileUtil.fileSizeInByte(this.getX509CertificateFile())); |
| 177 | 0 | stringBuffer.append("\n"); |
| 178 | 0 | stringBuffer.append("InfoFile: "+this.getInfoFile() + " size in Byte: " + FileUtil.fileSizeInByte(this.getInfoFile())); |
| 179 | 0 | stringBuffer.append("\n"); |
| 180 | 0 | stringBuffer.append("BackupFile: "+this.getBackupFile() + " size in Byte: " + FileUtil.fileSizeInByte(this.getBackupFile())); |
| 181 | 0 | stringBuffer.append("\n"); |
| 182 | 0 | stringBuffer.append("Total size in Byte: " + FileUtil.fileSizeInByte(new File(this.getBackupFile().getParent()))); |
| 183 | ||
| 184 | 0 | return stringBuffer.toString(); |
| 185 | } | |
| 186 | ||
| 187 | ||
| 188 | /** | |
| 189 | * @return Returns the artifactDirectory. | |
| 190 | */ | |
| 191 | public File getArtifactDirectory() { | |
| 192 | 2 | return artifactDirectory; |
| 193 | } | |
| 194 | ||
| 195 | } |
|
this report was generated by version 1.0.5 of jcoverage. |
copyright © 2003, jcoverage ltd. all rights reserved. |