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.backup; | |
21 | ||
22 | import java.io.File; | |
23 | import java.util.Date; | |
24 | ||
25 | import org.w3c.dom.Document; | |
26 | import org.w3c.dom.Element; | |
27 | import org.w3c.dom.Node; | |
28 | import org.w3c.dom.NodeList; | |
29 | ||
30 | import base.ICXmlTags; | |
31 | ||
32 | public class Backup { | |
33 | private final int id; | |
34 | ||
35 | private String name; | |
36 | ||
37 | private String description; | |
38 | ||
39 | private Date date; | |
40 | 0 | |
41 | private String dbLocationPath; | |
42 | ||
43 | private String zipLocationPath; | |
44 | ||
45 | 0 | private long size = -1; |
46 | 0 | |
47 | /** | |
48 | * @param id | |
49 | * The backup's id. | |
50 | * @param name | |
51 | * The backup's name. | |
52 | * @param description | |
53 | * The backup's description. | |
54 | * @param date | |
55 | * The backup's date. | |
56 | 0 | * @param dbLocationPath |
57 | 0 | * The backup's database file dbLocationPath. |
58 | 0 | * @param zipLocationPath |
59 | 0 | */ |
60 | 0 | protected Backup(int id, String name, String description, Date date, |
61 | 0 | String dbLocationPath, String zipLocationPath) { |
62 | 0 | this.id = id; |
63 | 0 | this.name = name; |
64 | 0 | this.description = description; |
65 | 0 | this.date = date; |
66 | 0 | this.dbLocationPath = dbLocationPath; |
67 | 0 | this.zipLocationPath = zipLocationPath; |
68 | 0 | } |
69 | 0 | |
70 | 0 | public Backup(Document document) { |
71 | 0 | NodeList detailsNodeList = document |
72 | 0 | .getElementsByTagName(ICXmlTags.BACKUP_DETAILS_TAG); |
73 | 0 | Node detailsNode = detailsNodeList.item(0); |
74 | ||
75 | 0 | this.id = new Integer(detailsNode.getAttributes().getNamedItem( |
76 | ICXmlTags.BACKUP_ID_ATTRIBUTE).getNodeValue()); | |
77 | 0 | this.name = detailsNode.getAttributes().getNamedItem( |
78 | ICXmlTags.BACKUP_NAME_ATTRIBUTE).getNodeValue(); | |
79 | 0 | this.date = new Date(new Long(detailsNode.getAttributes().getNamedItem( |
80 | 0 | ICXmlTags.BACKUP_DATE_ATTRIBUTE).getNodeValue())); |
81 | 0 | |
82 | 0 | for (int i = 0; i < detailsNode.getChildNodes().getLength(); i++) { |
83 | 0 | if (detailsNode.getChildNodes().item(i).getNodeName().equals( |
84 | 0 | ICXmlTags.BACKUP_DB_LOCATION_PATH_TAG)) { |
85 | 0 | this.dbLocationPath = detailsNode.getChildNodes().item(i) |
86 | .getAttributes().getNamedItem( | |
87 | ICXmlTags.BACKUP_DB_LOCATION_PATH_ATTRIBUTE) | |
88 | 0 | .getNodeValue(); |
89 | 0 | } |
90 | 0 | |
91 | 0 | if (detailsNode.getChildNodes().item(i).getNodeName().equals( |
92 | ICXmlTags.BACKUP_DESCRIPTION_TAG)) { | |
93 | 0 | this.description = detailsNode.getChildNodes().item(i) |
94 | .getAttributes().getNamedItem( | |
95 | 0 | ICXmlTags.BACKUP_DESCRIPTION_ATTRIBUTE) |
96 | .getNodeValue(); | |
97 | } | |
98 | 0 | } |
99 | 0 | } |
100 | ||
101 | 0 | /** |
102 | * @return Returns the date. | |
103 | */ | |
104 | public Date getDate() { | |
105 | 0 | return date; |
106 | } | |
107 | ||
108 | /** | |
109 | 0 | * @param date |
110 | 0 | * The date to set. |
111 | */ | |
112 | protected void setDate(Date date) { | |
113 | 0 | this.date = date; |
114 | 0 | } |
115 | ||
116 | 0 | /** |
117 | * @return Returns the description. | |
118 | */ | |
119 | public String getDescription() { | |
120 | 0 | return description; |
121 | } | |
122 | ||
123 | /** | |
124 | 0 | * @param description |
125 | 0 | * The description to set. |
126 | */ | |
127 | 0 | protected void setDescription(String description) { |
128 | 0 | this.description = description; |
129 | 0 | } |
130 | ||
131 | 0 | /** |
132 | 0 | * @return Returns the name. |
133 | 0 | */ |
134 | public String getName() { | |
135 | 0 | return name; |
136 | } | |
137 | ||
138 | /** | |
139 | 0 | * @param name |
140 | 0 | * The name to set. |
141 | */ | |
142 | protected void setName(String name) { | |
143 | 0 | this.name = name; |
144 | 0 | } |
145 | ||
146 | 0 | /** |
147 | * @return Returns the dbLocationPath. | |
148 | 0 | */ |
149 | 0 | public String getDbLocationPath() { |
150 | 0 | return dbLocationPath; |
151 | 0 | } |
152 | 0 | |
153 | 0 | /** |
154 | 0 | * @return Returns the id. |
155 | 0 | */ |
156 | 0 | public int getId() { |
157 | 0 | return id; |
158 | 0 | } |
159 | 0 | |
160 | 0 | public String getBackupFileName() { |
161 | 0 | return this.getDbLocationPath().substring( |
162 | 0 | this.getDbLocationPath().lastIndexOf("" + File.pathSeparator), |
163 | 0 | this.getDbLocationPath().length()); |
164 | 0 | } |
165 | 0 | |
166 | 0 | /** |
167 | 0 | * @return Returns the zipLocationPath. |
168 | */ | |
169 | 0 | public String getZipLocationPath() { |
170 | 0 | return zipLocationPath; |
171 | 0 | } |
172 | 0 | |
173 | 0 | /** |
174 | 0 | * @param currentBackupLocationPath |
175 | 0 | * The currentBackupLocationPath to set. |
176 | 0 | */ |
177 | public void setCurrentBackupLocationPath(String currentBackupLocationPath) { | |
178 | 0 | this.zipLocationPath = currentBackupLocationPath; |
179 | 0 | } |
180 | 0 | |
181 | 0 | public Node toXml(Document document) { |
182 | 0 | Element detailsElement = document |
183 | 0 | .createElement(ICXmlTags.BACKUP_DETAILS_TAG); |
184 | 0 | |
185 | 0 | detailsElement.setAttribute(ICXmlTags.BACKUP_ID_ATTRIBUTE, "" |
186 | 0 | + this.getId()); |
187 | 0 | detailsElement.setAttribute(ICXmlTags.BACKUP_NAME_ATTRIBUTE, this |
188 | 0 | .getName()); |
189 | 0 | detailsElement.setAttribute(ICXmlTags.BACKUP_DATE_ATTRIBUTE, "" |
190 | 0 | + this.getDate().getTime()); |
191 | 0 | |
192 | 0 | Element originalDestinationPathElement = document |
193 | 0 | .createElement(ICXmlTags.BACKUP_DB_LOCATION_PATH_TAG); |
194 | ||
195 | 0 | originalDestinationPathElement.setAttribute( |
196 | 0 | ICXmlTags.BACKUP_DB_LOCATION_PATH_ATTRIBUTE, this |
197 | 0 | .getDbLocationPath()); |
198 | 0 | detailsElement.appendChild(originalDestinationPathElement); |
199 | 0 | |
200 | 0 | Element descriptionElement = document |
201 | 0 | .createElement(ICXmlTags.BACKUP_DESCRIPTION_TAG); |
202 | ||
203 | 0 | descriptionElement.setAttribute(ICXmlTags.BACKUP_DESCRIPTION_ATTRIBUTE, |
204 | this.getDescription()); | |
205 | 0 | detailsElement.appendChild(descriptionElement); |
206 | ||
207 | 0 | return detailsElement; |
208 | 0 | } |
209 | 0 | |
210 | 0 | /** |
211 | * @param dbLocationPath | |
212 | * The dbLocationPath to set. | |
213 | */ | |
214 | protected void setDbLocationPath(String dbLocationPath) { | |
215 | 0 | this.dbLocationPath = dbLocationPath; |
216 | 0 | } |
217 | 0 | |
218 | 0 | /** |
219 | * @param zipLocationPath | |
220 | * The zipLocationPath to set. | |
221 | */ | |
222 | 0 | protected void setZipLocationPath(String zipLocationPath) { |
223 | 0 | this.zipLocationPath = zipLocationPath; |
224 | 0 | } |
225 | 0 | |
226 | 0 | /** |
227 | 0 | * @return Returns the size. |
228 | 0 | */ |
229 | 0 | public long getSize() { |
230 | 0 | if (getZipLocationPath() == null) { |
231 | 0 | return size = -1; |
232 | 0 | } |
233 | ||
234 | 0 | File zipFile = new File(getZipLocationPath()); |
235 | ||
236 | 0 | if (!zipFile.exists()) { |
237 | 0 | return size = -1; |
238 | } | |
239 | ||
240 | 0 | return (size != -1) ? size : (size = BackupFactory |
241 | .fileSizeInKB(zipFile)); | |
242 | } | |
243 | } |
this report was generated by version 1.0.5 of jcoverage. |
copyright © 2003, jcoverage ltd. all rights reserved. |