KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > opencms > db > CmsPublishedResource


1 /*
2  * File : $Source: /usr/local/cvs/opencms/src/org/opencms/db/CmsPublishedResource.java,v $
3  * Date : $Date: 2006/03/27 14:52:26 $
4  * Version: $Revision: 1.31 $
5  *
6  * This library is part of OpenCms -
7  * the Open Source Content Mananagement System
8  *
9  * Copyright (c) 2005 Alkacon Software GmbH (http://www.alkacon.com)
10  *
11  * This library is free software; you can redistribute it and/or
12  * modify it under the terms of the GNU Lesser General Public
13  * License as published by the Free Software Foundation; either
14  * version 2.1 of the License, or (at your option) any later version.
15  *
16  * This library is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19  * Lesser General Public License for more details.
20  *
21  * For further information about Alkacon Software GmbH, please see the
22  * company website: http://www.alkacon.com
23  *
24  * For further information about OpenCms, please see the
25  * project website: http://www.opencms.org
26  *
27  * You should have received a copy of the GNU Lesser General Public
28  * License along with this library; if not, write to the Free Software
29  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
30  */

31
32 package org.opencms.db;
33
34 import org.opencms.file.CmsResource;
35 import org.opencms.util.CmsUUID;
36
37 import java.io.Serializable JavaDoc;
38
39 /**
40  * Represents the state of a published resource *before* it got published.<p>
41  *
42  * This allows various subsequent tasks in the Cms app. (e.g. exporting files and folders)
43  * to identify published resources after a resource or project was published.<p>
44  *
45  * The values to fill this container are read from the Cms publish history database table
46  * that is written during each publishing process.<p>
47  *
48  * @author Thomas Weckert
49  *
50  * @version $Revision: 1.31 $
51  *
52  * @since 6.0.0
53  *
54  * @see org.opencms.db.I_CmsProjectDriver#readPublishedResources(CmsDbContext, int, CmsUUID)
55  */

56 public class CmsPublishedResource implements Serializable JavaDoc, Cloneable JavaDoc, Comparable JavaDoc {
57
58     /** Serial version UID required for safe serialization. */
59     private static final long serialVersionUID = -1054065812825770479L;
60
61     /** The backup tag ID of the published resource. */
62     private int m_backupTagId;
63
64     /** Indicates if the published resource is a folder or a file. */
65     private boolean m_isFolder;
66
67     /** The resource ID of the published resource.<p> */
68     private CmsUUID m_resourceId;
69
70     /** The state of the resource *before* it was published.<p> */
71     private int m_resourceState;
72
73     /** The type of the published resource.<p> */
74     private int m_resourceType;
75
76     /** The root path of the published resource.<p> */
77     private String JavaDoc m_rootPath;
78
79     /** The count of siblings of the published resource. */
80     private int m_siblingCount;
81
82     /** The structure ID of the published resource.<p> */
83     private CmsUUID m_structureId;
84
85     /**
86      * Creates an object for published VFS resources.<p>
87      *
88      * Do not write objects created with this constructor to db, since the backup tag id is not set.<p>
89      *
90      * @param resource an CmsResource object to create a CmsPublishedResource from
91      */

92     public CmsPublishedResource(CmsResource resource) {
93
94         m_structureId = resource.getStructureId();
95         m_resourceId = resource.getResourceId();
96         m_backupTagId = -1;
97         m_rootPath = resource.getRootPath();
98         m_resourceType = resource.getTypeId();
99         m_resourceState = resource.getState();
100         m_siblingCount = resource.getSiblingCount();
101         m_isFolder = resource.isFolder();
102     }
103
104     /**
105      * Creates an object for published VFS resources.<p>
106      *
107      * @param resource an CmsResource object to create a CmsPublishedResource from
108      * @param backupTagId the backup tag id
109      */

110     public CmsPublishedResource(CmsResource resource, int backupTagId) {
111
112         m_structureId = resource.getStructureId();
113         m_resourceId = resource.getResourceId();
114         m_backupTagId = backupTagId;
115         m_rootPath = resource.getRootPath();
116         m_resourceType = resource.getTypeId();
117         m_resourceState = resource.getState();
118         m_siblingCount = resource.getSiblingCount();
119         m_isFolder = resource.isFolder();
120     }
121
122     /**
123      * Creates an object for published VFS resources.<p>
124      *
125      * @param structureId the structure ID of the published resource
126      * @param resourceId the resource ID of the published resource
127      * @param backupTagId the resource's tag ID in the backup tables
128      * @param rootPath the root path of the published resource
129      * @param resourceType the type of the published resource
130      * @param isFolder indicates if the published resource is a folder or a file
131      * @param resourceState the state of the resource *before* it was published
132      * @param siblingCount count of siblings of the published resource
133      */

134     public CmsPublishedResource(
135         CmsUUID structureId,
136         CmsUUID resourceId,
137         int backupTagId,
138         String JavaDoc rootPath,
139         int resourceType,
140         boolean isFolder,
141         int resourceState,
142         int siblingCount) {
143
144         m_structureId = structureId;
145         m_resourceId = resourceId;
146         m_backupTagId = backupTagId;
147         m_rootPath = rootPath;
148         m_resourceType = resourceType;
149         m_resourceState = resourceState;
150         m_siblingCount = siblingCount;
151         m_isFolder = isFolder;
152     }
153
154     /**
155      * @see java.lang.Comparable#compareTo(java.lang.Object)
156      */

157     public int compareTo(Object JavaDoc obj) {
158
159         if (obj == this) {
160             return 0;
161         }
162         if (obj instanceof CmsPublishedResource) {
163             if (m_rootPath != null) {
164                 return m_rootPath.compareTo(((CmsPublishedResource)obj).m_rootPath);
165             }
166         }
167         return 0;
168     }
169
170     /**
171      * @see java.lang.Object#equals(java.lang.Object)
172      */

173     public boolean equals(Object JavaDoc obj) {
174
175         if (obj == this) {
176             return true;
177         }
178         if (obj instanceof CmsPublishedResource) {
179             if (m_structureId.isNullUUID()) {
180                 return ((CmsPublishedResource)obj).m_resourceId.equals(m_resourceId);
181             } else {
182                 return ((CmsPublishedResource)obj).m_structureId.equals(m_structureId);
183             }
184         }
185         return false;
186     }
187
188     /**
189      * Returns the backup tag ID of the published resource.<p>
190      *
191      * @return the backup tag ID of the published resource
192      */

193     public int getBackupTagId() {
194
195         return m_backupTagId;
196     }
197
198     /**
199      * Returns the resource ID of the published resource.<p>
200      *
201      * @return the resource ID of the published resource
202      */

203     public CmsUUID getResourceId() {
204
205         return m_resourceId;
206     }
207
208     /**
209      * Returns the root path of the published resource.<p>
210      *
211      * @return the root path of the published resource
212      */

213     public String JavaDoc getRootPath() {
214
215         return m_rootPath;
216     }
217
218     /**
219      * Returns the count of siblings of the published resource.<p>
220      *
221      * If a resource has no sibling, the total sibling count for this resource is <code>1</code>,
222      * if a resource has <code>n</code> siblings, the sibling count is <code>n + 1</code>.<p>
223      *
224      * @return the count of siblings of the published resource
225      */

226     public int getSiblingCount() {
227
228         return m_siblingCount;
229     }
230
231     /**
232      * Returns the resource state of the published resource.<p>
233      *
234      * @return the resource state of the published resource
235      */

236     public int getState() {
237
238         return m_resourceState;
239     }
240
241     /**
242      * Returns the structure ID of the published resource.<p>
243      *
244      * @return the structure ID of the published resource
245      */

246     public CmsUUID getStructureId() {
247
248         return m_structureId;
249     }
250
251     /**
252      * Returns the resource type of the published resource.<p>
253      *
254      * @return the resource type of the published resource
255      */

256     public int getType() {
257
258         return m_resourceType;
259     }
260
261     /**
262      * @see java.lang.Object#hashCode()
263      */

264     public int hashCode() {
265
266         return m_structureId.isNullUUID() ? m_resourceId.hashCode() : m_structureId.hashCode();
267     }
268
269     /**
270      * Checks if the resource is changed.<p>
271      *
272      * @return true if the resource is changed
273      */

274     public boolean isChanged() {
275
276         return getState() == CmsResource.STATE_CHANGED;
277     }
278
279     /**
280      * Checks if the resource is deleted.<p>
281      *
282      * @return true if the resource is deleted
283      */

284     public boolean isDeleted() {
285
286         return getState() == CmsResource.STATE_DELETED;
287     }
288
289     /**
290      * Determines if this resource is a file.<p>
291      *
292      * @return true if this resource is a file, false otherwise
293      */

294     public boolean isFile() {
295
296         return !m_isFolder;
297     }
298
299     /**
300      * Checks if this resource is a folder.<p>
301      *
302      * @return true if this is is a folder
303      */

304     public boolean isFolder() {
305
306         return m_isFolder;
307     }
308
309     /**
310      * Checks if the resource is new.<p>
311      *
312      * @return true if the resource is new
313      */

314     public boolean isNew() {
315
316         return getState() == CmsResource.STATE_NEW;
317     }
318
319     /**
320      * Checks if the resource is unchanged.<p>
321      *
322      * @return true if the resource is unchanged
323      */

324     public boolean isUnChanged() {
325
326         return getState() == CmsResource.STATE_UNCHANGED;
327     }
328
329     /**
330      * Checks if this published resource represents a VFS resource.<p>
331      *
332      * If the published resource has no structure id, it is considered to be
333      * no VFS resource.<p>
334      *
335      * @return true if this published resource is a VFS resource
336      */

337     public boolean isVfsResource() {
338
339         return !getStructureId().equals(CmsUUID.getNullUUID());
340     }
341
342     /**
343      * @see java.lang.Object#toString()
344      */

345     public String JavaDoc toString() {
346
347         StringBuffer JavaDoc result = new StringBuffer JavaDoc(128);
348
349         result.append("[");
350         result.append(this.getClass().getName());
351         result.append(": root path: ");
352         result.append(m_rootPath);
353         result.append(", structure ID: ");
354         result.append(m_structureId);
355         result.append(", resource ID: ");
356         result.append(m_resourceId);
357         result.append(", backup tag ID: ");
358         result.append(m_backupTagId);
359         result.append(", siblings: ");
360         result.append(m_siblingCount);
361         result.append(", state: ");
362         result.append(m_resourceState);
363         result.append(", type: ");
364         result.append(m_resourceType);
365         result.append("]");
366
367         return result.toString();
368     }
369
370     /**
371      * @see java.lang.Object#finalize()
372      */

373     protected void finalize() throws Throwable JavaDoc {
374
375         try {
376             m_structureId = null;
377             m_resourceId = null;
378             m_rootPath = null;
379         } catch (Throwable JavaDoc t) {
380             // ignore
381
}
382         super.finalize();
383     }
384 }
Popular Tags