Source code: com/opencms/file/CmsBackupResource.java
1 /*
2 * File : $Source: /usr/local/cvs/opencms/src/com/opencms/file/CmsBackupResource.java,v $
3 * Date : $Date: 2003/04/01 15:20:18 $
4 * Version: $Revision: 1.4 $
5 *
6 * This library is part of OpenCms -
7 * the Open Source Content Mananagement System
8 *
9 * Copyright (C) 2001 The OpenCms Group
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 OpenCms, please see the
22 * OpenCms Website: http://www.opencms.org
23 *
24 * You should have received a copy of the GNU Lesser General Public
25 * License along with this library; if not, write to the Free Software
26 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
27 */
28
29 package com.opencms.file;
30
31
32 import java.io.*;
33
34 /**
35 * Describes a backup resource in the Cms.
36 *
37 * @author Edna Falkenhan
38 * @version $Revision: 1.4 $ $Date: 2003/04/01 15:20:18 $
39 */
40 public class CmsBackupResource extends CmsResource implements Cloneable,Serializable {
41
42 /**
43 * The id of the version.
44 */
45 private int m_versionId = C_UNKNOWN_ID;
46
47 /**
48 * The name of the owner.
49 */
50 private String m_ownerName = "";
51
52 /**
53 * The name of the group.
54 */
55 private String m_groupName = "";
56
57 /**
58 * The name of the last user who had modified the resource.
59 */
60 private String m_lastModifiedByName = "";
61
62 /**
63 * The content of the file
64 */
65 private byte[] m_fileContent;
66
67 /**
68 * Constructor, creates a new CmsBackupResource object.
69 *
70 * @param versionId The versionId of the resource
71 * @param resourceId The database Id.
72 * @param parentId The database Id of the parent folder.
73 * @param fileId The id of the content.
74 * @param resourceName The name (including complete path) of the resouce.
75 * @param resourceType The type of this resource.
76 * @param rescourceFlags The flags of thei resource.
77 * @param userId The id of the user of this resource.
78 * @param userName The name of the user of this resource.
79 * @param groupId The id of the group of this resource.
80 * @param groupName The name of the group of this resource.
81 * @param projectId The project id this resource belongs to.
82 * @param accessFlags The access flags of this resource.
83 * @param state The state of this resource.
84 * @param lockedBy The user id of the user who has locked this resource.
85 * @param launcherType The launcher that is require to process this recource.
86 * @param launcherClassname The name of the Java class invoked by the launcher.
87 * @param dateCreated The creation date of this resource.
88 * @param dateLastModified The date of the last modification of the resource.
89 * @param fileContent Then content of the file.
90 * @param resourceLastModifiedBy The user who changed the file.
91 * @param lastModifiedByName The name of user who changed the file.
92 * @param size The size of the file content.
93 */
94 public CmsBackupResource(int versionId, int resourceId, int parentId, int fileId,
95 String resourceName, int resourceType, int resourceFlags,
96 int user, String userName, int group, String groupName,
97 int projectId, int accessFlags, int state,
98 int launcherType, String launcherClassname,
99 long dateCreated, long dateLastModified,
100 int resourceLastModifiedBy, String lastModifiedByName,
101 byte[] fileContent,int size, int lockedInProject){
102
103 // create the CmsResource.
104 super(resourceId, parentId, fileId,
105 resourceName,resourceType,resourceFlags,
106 user,group,projectId,
107 accessFlags,state,C_UNKNOWN_ID,
108 launcherType,launcherClassname,
109 dateCreated,dateLastModified,
110 resourceLastModifiedBy,size, lockedInProject);
111
112 // set content and size.
113 m_fileContent=fileContent;
114
115 // set version id
116 m_versionId = versionId;
117
118 // set owner name
119 m_ownerName = userName;
120
121 // set group name
122 m_groupName = groupName;
123
124 // set lastModifiedByName
125 m_lastModifiedByName = lastModifiedByName;
126
127 }
128 /**
129 * Clones the CmsFile by creating a new CmsFolder.
130 * @return Cloned CmsFile.
131 */
132 public Object clone() {
133 byte[] newContent = new byte[ this.getContents().length ];
134 System.arraycopy(getContents(), 0, newContent, 0, getContents().length);
135
136 return new CmsBackupResource(this.getVersionId(), this.getResourceId(), this.getParentId(),
137 this.getFileId(), new String(this.getAbsolutePath()),
138 this.getType(), this.getFlags(), this.getOwnerId(),
139 this.getOwnerName(), this.getGroupId(), this.getGroupName(),
140 this.getProjectId(), this.getAccessFlags(), this.getState(),
141 this.getLauncherType(),
142 new String(this.getLauncherClassname()), this.getDateCreated(),
143 this.getDateLastModified(),this.getResourceLastModifiedBy(),
144 this.getLastModifiedByName(),
145 newContent, this.getLength(), this.getLockedInProject());
146 }
147 /**
148 * Gets the content of this file.
149 *
150 * @return the content of this file.
151 */
152 public byte[] getContents() {
153 return m_fileContent;
154 }
155
156 /**
157 * Gets the version id of this resource.
158 *
159 * @return the version id of this resource.
160 */
161 public int getVersionId() {
162 return m_versionId;
163 }
164
165 /**
166 * Gets the name of the owner of this resource.
167 *
168 * @return the name of the owner of this resource.
169 */
170 public String getOwnerName() {
171 return m_ownerName;
172 }
173
174 /**
175 * Gets the name of the group of this resource.
176 *
177 * @return the name of the group of this resource.
178 */
179 public String getGroupName() {
180 return m_groupName;
181 }
182
183 /**
184 * Gets the name of the user who changed this resource.
185 *
186 * @return the name of the user who changed this resource.
187 */
188 public String getLastModifiedByName() {
189 return m_lastModifiedByName;
190 }
191
192 /**
193 * Gets the file-extension.
194 *
195 * @return the file extension. If this file has no extension, it returns
196 * a empty string ("").
197 */
198 public String getExtension(){
199 String name=null;
200 String extension="";
201 int dot;
202
203 name=this.getName();
204 // check if this file has an extension.
205 dot=name.lastIndexOf(".");
206 if (dot> 0) {
207 extension=name.substring(dot,name.length());
208 }
209 return extension;
210 }
211 }