001: /*
002: * File : $Source: /usr/local/cvs/opencms/src/org/opencms/db/CmsPublishedResource.java,v $
003: * Date : $Date: 2008-02-27 12:05:42 $
004: * Version: $Revision: 1.35 $
005: *
006: * This library is part of OpenCms -
007: * the Open Source Content Management System
008: *
009: * Copyright (c) 2002 - 2008 Alkacon Software GmbH (http://www.alkacon.com)
010: *
011: * This library is free software; you can redistribute it and/or
012: * modify it under the terms of the GNU Lesser General Public
013: * License as published by the Free Software Foundation; either
014: * version 2.1 of the License, or (at your option) any later version.
015: *
016: * This library is distributed in the hope that it will be useful,
017: * but WITHOUT ANY WARRANTY; without even the implied warranty of
018: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
019: * Lesser General Public License for more details.
020: *
021: * For further information about Alkacon Software GmbH, please see the
022: * company website: http://www.alkacon.com
023: *
024: * For further information about OpenCms, please see the
025: * project website: http://www.opencms.org
026: *
027: * You should have received a copy of the GNU Lesser General Public
028: * License along with this library; if not, write to the Free Software
029: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
030: */
031:
032: package org.opencms.db;
033:
034: import org.opencms.file.CmsResource;
035: import org.opencms.util.CmsUUID;
036:
037: import java.io.Serializable;
038:
039: /**
040: * Represents the state of a published resource *before* it got published.<p>
041: *
042: * This allows various subsequent tasks in the Cms app. (e.g. exporting files and folders)
043: * to identify published resources after a resource or project was published.<p>
044: *
045: * The values to fill this container are read from the Cms publish history database table
046: * that is written during each publishing process.<p>
047: *
048: * @author Thomas Weckert
049: *
050: * @version $Revision: 1.35 $
051: *
052: * @since 6.0.0
053: *
054: * @see org.opencms.db.I_CmsProjectDriver#readPublishedResources(CmsDbContext, CmsUUID)
055: */
056: public class CmsPublishedResource implements Serializable, Comparable {
057:
058: /**
059: * Add new resource states under consideration of the move operation.<p>
060: */
061: public static class CmsPublishedResourceState extends
062: CmsResourceState {
063:
064: private static final long serialVersionUID = -2901049208546972463L;
065:
066: /**
067: * protected constructor.<p>
068: *
069: * @param state an integer representing the state
070: * @param abbrev an abbreviation character
071: */
072: protected CmsPublishedResourceState(int state, char abbrev) {
073:
074: super (state, abbrev);
075: }
076:
077: /**
078: * Returns the corresponding resource state for this publish resource state.<p>
079: *
080: * @return the corresponding resource state
081: */
082: public CmsResourceState getResourceState() {
083:
084: if (this == STATE_MOVED_SOURCE) {
085: return CmsResource.STATE_DELETED;
086: } else if (this == STATE_MOVED_DESTINATION) {
087: return CmsResource.STATE_NEW;
088: } else {
089: return null;
090: }
091: }
092: }
093:
094: /** Additional state for moved resources, the (new) destination of the moved resource. */
095: public static final CmsPublishedResourceState STATE_MOVED_DESTINATION = new CmsPublishedResourceState(
096: 12, 'M');
097:
098: /** Additional state for moved resources, the (deleted) source of the moved resource. */
099: public static final CmsPublishedResourceState STATE_MOVED_SOURCE = new CmsPublishedResourceState(
100: 11, ' ');
101:
102: /** Serial version UID required for safe serialization. */
103: private static final long serialVersionUID = -1054065812825770479L;
104:
105: /** Indicates if the published resource is a folder or a file. */
106: private boolean m_isFolder;
107:
108: /** falg to signal if the resource was moved. */
109: private boolean m_isMoved;
110:
111: /** The publish tag of the published resource. */
112: private int m_publishTag;
113:
114: /** The resource ID of the published resource.<p> */
115: private CmsUUID m_resourceId;
116:
117: /** The state of the resource *before* it was published.<p> */
118: private CmsResourceState m_resourceState;
119:
120: /** The type of the published resource.<p> */
121: private int m_resourceType;
122:
123: /** The root path of the published resource.<p> */
124: private String m_rootPath;
125:
126: /** The count of siblings of the published resource. */
127: private int m_siblingCount;
128:
129: /** The structure ID of the published resource.<p> */
130: private CmsUUID m_structureId;
131:
132: /**
133: * Creates an object for published VFS resources.<p>
134: *
135: * Do not write objects created with this constructor to db, since the publish tag is not set.<p>
136: *
137: * @param resource an CmsResource object to create a CmsPublishedResource from
138: */
139: public CmsPublishedResource(CmsResource resource) {
140:
141: this (resource, -1);
142: }
143:
144: /**
145: * Creates an object for published VFS resources.<p>
146: *
147: * @param resource an CmsResource object to create a CmsPublishedResource from
148: * @param publishTag the publish Tag
149: */
150: public CmsPublishedResource(CmsResource resource, int publishTag) {
151:
152: this (resource, publishTag, resource.getState());
153: }
154:
155: /**
156: * Creates an object for published VFS resources.<p>
157: *
158: * @param resource an CmsResource object to create a CmsPublishedResource from
159: * @param state the resource state
160: * @param publishTag the publish tag
161: */
162: public CmsPublishedResource(CmsResource resource, int publishTag,
163: CmsResourceState state) {
164:
165: this (resource.getStructureId(), resource.getResourceId(),
166: publishTag, resource.getRootPath(), resource
167: .getTypeId(), resource.isFolder(), state,
168: resource.getSiblingCount());
169: }
170:
171: /**
172: * Creates an object for published VFS resources.<p>
173: *
174: * @param structureId the structure ID of the published resource
175: * @param resourceId the resource ID of the published resource
176: * @param publishTag the publish tag
177: * @param rootPath the root path of the published resource
178: * @param resourceType the type of the published resource
179: * @param isFolder indicates if the published resource is a folder or a file
180: * @param resourceState the state of the resource *before* it was published
181: * @param siblingCount count of siblings of the published resource
182: */
183: public CmsPublishedResource(CmsUUID structureId,
184: CmsUUID resourceId, int publishTag, String rootPath,
185: int resourceType, boolean isFolder,
186: CmsResourceState resourceState, int siblingCount) {
187:
188: m_structureId = structureId;
189: m_resourceId = resourceId;
190: m_publishTag = publishTag;
191: m_rootPath = rootPath;
192: m_resourceType = resourceType;
193: m_isFolder = isFolder;
194: if (resourceState instanceof CmsPublishedResourceState) {
195: m_resourceState = ((CmsPublishedResourceState) resourceState)
196: .getResourceState();
197: m_isMoved = true;
198: } else {
199: m_resourceState = resourceState;
200: }
201: m_siblingCount = siblingCount;
202: }
203:
204: /**
205: * @see java.lang.Comparable#compareTo(java.lang.Object)
206: */
207: public int compareTo(Object obj) {
208:
209: if (obj == this ) {
210: return 0;
211: }
212: if (obj instanceof CmsPublishedResource) {
213: if (m_rootPath != null) {
214: return m_rootPath
215: .compareTo(((CmsPublishedResource) obj).m_rootPath);
216: }
217: }
218: return 0;
219: }
220:
221: /**
222: * @see java.lang.Object#equals(java.lang.Object)
223: */
224: public boolean equals(Object obj) {
225:
226: if (obj == this ) {
227: return true;
228: }
229: if (obj instanceof CmsPublishedResource) {
230: if (m_structureId.isNullUUID()) {
231: return ((CmsPublishedResource) obj).m_resourceId
232: .equals(m_resourceId);
233: } else {
234: return ((CmsPublishedResource) obj).m_structureId
235: .equals(m_structureId);
236: }
237: }
238: return false;
239: }
240:
241: /**
242: * Returns the publish tag of the published resource.<p>
243: *
244: * @return the publish tag of the published resource
245: *
246: * @deprecated Use {@link #getPublishTag()} instead
247: */
248: public int getBackupTagId() {
249:
250: return getPublishTag();
251: }
252:
253: /**
254: * Returns the resource state including move operation information.<p>
255: *
256: * @return the resource state including move operation information
257: */
258: public CmsResourceState getMovedState() {
259:
260: if (!m_isMoved) {
261: return getState();
262: } else if (getState().isDeleted()) {
263: return STATE_MOVED_SOURCE;
264: } else if (getState().isNew()) {
265: return STATE_MOVED_DESTINATION;
266: } else {
267: // should never happen
268: return getState();
269: }
270: }
271:
272: /**
273: * Returns the publish tag of the published resource.<p>
274: *
275: * @return the publish tag of the published resource
276: */
277: public int getPublishTag() {
278:
279: return m_publishTag;
280: }
281:
282: /**
283: * Returns the resource ID of the published resource.<p>
284: *
285: * @return the resource ID of the published resource
286: */
287: public CmsUUID getResourceId() {
288:
289: return m_resourceId;
290: }
291:
292: /**
293: * Returns the root path of the published resource.<p>
294: *
295: * @return the root path of the published resource
296: */
297: public String getRootPath() {
298:
299: return m_rootPath;
300: }
301:
302: /**
303: * Returns the count of siblings of the published resource.<p>
304: *
305: * If a resource has no sibling, the total sibling count for this resource is <code>1</code>,
306: * if a resource has <code>n</code> siblings, the sibling count is <code>n + 1</code>.<p>
307: *
308: * @return the count of siblings of the published resource
309: */
310: public int getSiblingCount() {
311:
312: return m_siblingCount;
313: }
314:
315: /**
316: * Returns the resource state of the published resource.<p>
317: *
318: * @return the resource state of the published resource
319: */
320: public CmsResourceState getState() {
321:
322: return m_resourceState;
323: }
324:
325: /**
326: * Returns the structure ID of the published resource.<p>
327: *
328: * @return the structure ID of the published resource
329: */
330: public CmsUUID getStructureId() {
331:
332: return m_structureId;
333: }
334:
335: /**
336: * Returns the resource type of the published resource.<p>
337: *
338: * @return the resource type of the published resource
339: */
340: public int getType() {
341:
342: return m_resourceType;
343: }
344:
345: /**
346: * @see java.lang.Object#hashCode()
347: */
348: public int hashCode() {
349:
350: return m_structureId.isNullUUID() ? m_resourceId.hashCode()
351: : m_structureId.hashCode();
352: }
353:
354: /**
355: * Determines if this resource is a file.<p>
356: *
357: * @return true if this resource is a file, false otherwise
358: */
359: public boolean isFile() {
360:
361: return !m_isFolder;
362: }
363:
364: /**
365: * Checks if this resource is a folder.<p>
366: *
367: * @return true if this is is a folder
368: */
369: public boolean isFolder() {
370:
371: return m_isFolder;
372: }
373:
374: /**
375: * Returns <code>true</code> if the resource has been moved.<p>
376: *
377: * @return <code>true</code> if the resource has been moved
378: */
379: public boolean isMoved() {
380:
381: return m_isMoved;
382: }
383:
384: /**
385: * Checks if this published resource represents a VFS resource.<p>
386: *
387: * If the published resource has no structure id, it is considered to be
388: * no VFS resource.<p>
389: *
390: * @return true if this published resource is a VFS resource
391: *
392: * @deprecated no longer needed
393: */
394: public boolean isVfsResource() {
395:
396: return !getStructureId().equals(CmsUUID.getNullUUID());
397: }
398:
399: /**
400: * @see java.lang.Object#toString()
401: */
402: public String toString() {
403:
404: StringBuffer result = new StringBuffer(128);
405:
406: result.append("[");
407: result.append(this .getClass().getName());
408: result.append(": root path: ");
409: result.append(m_rootPath);
410: result.append(", structure ID: ");
411: result.append(m_structureId);
412: result.append(", resource ID: ");
413: result.append(m_resourceId);
414: result.append(", publish tag: ");
415: result.append(m_publishTag);
416: result.append(", siblings: ");
417: result.append(m_siblingCount);
418: result.append(", state: ");
419: result.append(m_resourceState);
420: result.append(", type: ");
421: result.append(m_resourceType);
422: result.append("]");
423:
424: return result.toString();
425: }
426: }
|