001/*
002 * This library is part of OpenCms -
003 * the Open Source Content Management System
004 *
005 * Copyright (c) Alkacon Software GmbH & Co. KG (http://www.alkacon.com)
006 *
007 * This library is free software; you can redistribute it and/or
008 * modify it under the terms of the GNU Lesser General Public
009 * License as published by the Free Software Foundation; either
010 * version 2.1 of the License, or (at your option) any later version.
011 *
012 * This library is distributed in the hope that it will be useful,
013 * but WITHOUT ANY WARRANTY; without even the implied warranty of
014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
015 * Lesser General Public License for more details.
016 *
017 * For further information about Alkacon Software GmbH & Co. KG, please see the
018 * company website: http://www.alkacon.com
019 *
020 * For further information about OpenCms, please see the
021 * project website: http://www.opencms.org
022 *
023 * You should have received a copy of the GNU Lesser General Public
024 * License along with this library; if not, write to the Free Software
025 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
026 */
027
028package org.opencms.file.history;
029
030import org.opencms.db.CmsResourceState;
031import org.opencms.file.CmsFolder;
032import org.opencms.file.CmsObject;
033import org.opencms.main.CmsException;
034import org.opencms.security.CmsPrincipal;
035import org.opencms.util.CmsUUID;
036
037/**
038 * A historical version of a file in the OpenCms VFS resource history.<p>
039 *
040 * @since 6.9.1
041 */
042public class CmsHistoryFolder extends CmsFolder implements I_CmsHistoryResource {
043
044    /** Serial version UID required for safe serialization. */
045    private static final long serialVersionUID = -374285965677032786L;
046
047    /** The structure id of the parent of this historical resource. */
048    private CmsUUID m_parentId;
049
050    /** The publish tag of this historical resource. */
051    private int m_publishTag;
052
053    /** The version number of the resource part for this historical resource. */
054    private int m_resourceVersion;
055
056    /** The version number of the structure part for this historical resource. */
057    private int m_structureVersion;
058
059    /**
060     * Constructor from a history resource.<p>
061     *
062     * @param resource the base history resource
063     */
064    public CmsHistoryFolder(I_CmsHistoryResource resource) {
065
066        this(
067            resource.getPublishTag(),
068            resource.getStructureId(),
069            resource.getResourceId(),
070            resource.getRootPath(),
071            resource.getTypeId(),
072            resource.getFlags(),
073            resource.getProjectLastModified(),
074            resource.getState(),
075            resource.getDateCreated(),
076            resource.getUserCreated(),
077            resource.getDateLastModified(),
078            resource.getUserLastModified(),
079            resource.getDateReleased(),
080            resource.getDateExpired(),
081            resource.getVersion(),
082            resource.getParentId(),
083            resource.getResourceVersion(),
084            resource.getStructureVersion());
085    }
086
087    /**
088     * Default Constructor.<p>
089     *
090     * @param publishTag the publish tag of this historical resource
091     * @param structureId the id of this resources structure record
092     * @param resourceId the id of this resources resource record
093     * @param path the filename of this resouce
094     * @param type the type of this resource
095     * @param flags the flags of this resource
096     * @param projectId the project id this resource was last modified in
097     * @param state the state of this resource
098     * @param dateCreated the creation date of this resource
099     * @param userCreated the id of the user who created this resource
100     * @param dateLastModified the date of the last modification of this resource
101     * @param userLastModified the id of the user who did the last modification of this resource
102     * @param dateReleased the release date of this resource
103     * @param dateExpired the expiration date of this resource
104     * @param version the version number of this resource
105     * @param parentId structure id of the parent of this historical resource
106     * @param resourceVersion the version number of the resource part for this historical resource
107     * @param structureVersion the version number of the structure part for this historical resource
108     */
109    public CmsHistoryFolder(
110        int publishTag,
111        CmsUUID structureId,
112        CmsUUID resourceId,
113        String path,
114        int type,
115        int flags,
116        CmsUUID projectId,
117        CmsResourceState state,
118        long dateCreated,
119        CmsUUID userCreated,
120        long dateLastModified,
121        CmsUUID userLastModified,
122        long dateReleased,
123        long dateExpired,
124        int version,
125        CmsUUID parentId,
126        int resourceVersion,
127        int structureVersion) {
128
129        super(
130            structureId,
131            resourceId,
132            path,
133            type,
134            flags,
135            projectId,
136            state,
137            dateCreated,
138            userCreated,
139            dateLastModified,
140            userLastModified,
141            dateReleased,
142            dateExpired,
143            version);
144
145        m_publishTag = publishTag;
146        m_parentId = parentId;
147        m_resourceVersion = resourceVersion;
148        m_structureVersion = structureVersion;
149    }
150
151    /**
152     * Returns a clone of this Objects instance.<p>
153     *
154     * @return a clone of this instance
155     */
156    @Override
157    public Object clone() {
158
159        return new CmsHistoryFolder(
160            getPublishTag(),
161            getStructureId(),
162            getResourceId(),
163            getRootPath(),
164            getTypeId(),
165            getFlags(),
166            getProjectLastModified(),
167            getState(),
168            getDateCreated(),
169            getUserCreated(),
170            getDateLastModified(),
171            getUserLastModified(),
172            getDateReleased(),
173            getDateExpired(),
174            getVersion(),
175            getParentId(),
176            getResourceVersion(),
177            getStructureVersion());
178    }
179
180    /**
181     * @see org.opencms.file.history.I_CmsHistoryResource#getParentId()
182     */
183    public CmsUUID getParentId() {
184
185        return m_parentId;
186    }
187
188    /**
189     * @see org.opencms.file.history.I_CmsHistoryResource#getPublishTag()
190     */
191    public int getPublishTag() {
192
193        return m_publishTag;
194    }
195
196    /**
197     * @see org.opencms.file.history.I_CmsHistoryResource#getResourceVersion()
198     */
199    public int getResourceVersion() {
200
201        return m_resourceVersion;
202    }
203
204    /**
205     * @see org.opencms.file.history.I_CmsHistoryResource#getStructureVersion()
206     */
207    public int getStructureVersion() {
208
209        return m_structureVersion;
210    }
211
212    /**
213     * Returns the name of the user that created this resource.<p>
214     *
215     * @param cms the current cms context
216     *
217     * @return the name of the user that created this resource
218     */
219    public String getUserCreatedName(CmsObject cms) {
220
221        try {
222            return CmsPrincipal.readPrincipalIncludingHistory(cms, getUserCreated()).getName();
223        } catch (CmsException e) {
224            return getUserCreated().toString();
225        }
226    }
227
228    /**
229     * Returns the name of the user that last modified this resource.<p>
230     *
231     * @param cms the current cms context
232     *
233     * @return the name of the user that last modified this resource
234     */
235    public String getUserLastModifiedName(CmsObject cms) {
236
237        try {
238            return CmsPrincipal.readPrincipalIncludingHistory(cms, getUserLastModified()).getName();
239        } catch (CmsException e) {
240            return getUserLastModified().toString();
241        }
242    }
243
244    /**
245     * @see org.opencms.file.CmsResource#toString()
246     */
247    @Override
248    public String toString() {
249
250        StringBuffer result = new StringBuffer();
251
252        result.append("[");
253        result.append(super.toString());
254        result.append(", resource version: ");
255        result.append(m_resourceVersion);
256        result.append(", structure version ");
257        result.append(m_structureVersion);
258        result.append(", parent id: ");
259        result.append(m_parentId);
260        result.append(", publish tag: ");
261        result.append(m_publishTag);
262        result.append("]");
263
264        return result.toString();
265    }
266}