Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: com/opencms/file/CmsFile.java


1   /*
2   * File   : $Source: /usr/local/cvs/opencms/src/com/opencms/file/CmsFile.java,v $
3   * Date   : $Date: 2003/04/01 15:20:18 $
4   * Version: $Revision: 1.16 $
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  import java.io.*;
32  
33  /**
34   * Describes a file in the Cms.
35   *
36   * @author Michael Emmerich
37   * @version $Revision: 1.16 $ $Date: 2003/04/01 15:20:18 $
38   */
39  public class CmsFile extends CmsResource implements Cloneable,Serializable {
40  
41      /**
42       * The content of the file.
43       */
44      private byte[] m_fileContent;
45  
46       /**
47        * Constructor, creates a new CmsFile object.
48        *
49        * @param resourceId The database Id.
50        * @param parentId The database Id of the parent folder.
51        * @param fileId The id of the content.
52        * @param resourceName The name (including complete path) of the resouce.
53        * @param resourceType The type of this resource.
54        * @param rescourceFlags The flags of thei resource.
55        * @param userId The id of the user of this resource.
56        * @param groupId The id of the group of this resource.
57        * @param projectId The project id this resource belongs to.
58        * @param accessFlags The access flags of this resource.
59        * @param state The state of this resource.
60        * @param lockedBy The user id of the user who has locked this resource.
61        * @param launcherType The launcher that is require to process this recource.
62        * @param launcherClassname The name of the Java class invoked by the launcher.
63        * @param dateCreated The creation date of this resource.
64        * @param dateLastModified The date of the last modification of the resource.
65        * @param fileContent Then content of the file.
66        * @param resourceLastModifiedBy The user who changed the file.
67        * @param size The size of the file content.
68        */
69       public CmsFile(int resourceId, int parentId, int fileId,
70                          String resourceName, int resourceType, int resourceFlags,
71                          int user, int group, int projectId,
72                          int accessFlags, int state, int lockedBy,
73                          int launcherType, String launcherClassname,
74                          long dateCreated, long dateLastModified,
75                          int resourceLastModifiedBy,
76                          byte[] fileContent,int size, int lockedInProject){
77  
78          // create the CmsResource.
79          super(resourceId, parentId, fileId,
80                resourceName,resourceType,resourceFlags,
81                user,group,projectId,
82                accessFlags,state,lockedBy,
83                launcherType,launcherClassname,
84                dateCreated,dateLastModified,
85                resourceLastModifiedBy,size, lockedInProject);
86  
87          // set content and size.
88          m_fileContent=fileContent;
89  
90     }
91      /**
92      * Clones the CmsFile by creating a new CmsFolder.
93      * @return Cloned CmsFile.
94      */
95      public Object clone() {
96          byte[] newContent = new byte[ this.getContents().length ];
97          System.arraycopy(getContents(), 0, newContent, 0, getContents().length);
98  
99          return new CmsFile(this.getResourceId(), this.getParentId(), this.getFileId(),
100                              new String(this.getResourceName()),this.getType(),
101                              this.getFlags(), this.getOwnerId(), this.getGroupId(),
102                              this.getProjectId(),this.getAccessFlags(),
103                              this.getState(),this.isLockedBy(), this.getLauncherType(),
104                              new String(this.getLauncherClassname()), this.getDateCreated(),
105                              this.getDateLastModified(),this.getResourceLastModifiedBy(),
106                              newContent, this.getLength(), this.getLockedInProject());
107     }
108     /**
109      * Gets the content of this file.
110      *
111      * @return the content of this file.
112      */
113     public byte[] getContents() {
114       return m_fileContent;
115     }
116     /**
117      * Gets the file-extension.
118      *
119      * @return the file extension. If this file has no extension, it returns
120      * a empty string ("").
121      */
122     public String getExtension(){
123         String name=null;
124         String extension="";
125         int dot;
126 
127         name=this.getName();
128         // check if this file has an extension.
129         dot=name.lastIndexOf(".");
130         if (dot> 0) {
131             extension=name.substring(dot,name.length());
132         }
133         return extension;
134     }
135     /**
136      * Sets the content of this file.
137      *
138      * @param value the content of this file.
139      */
140     public void setContents(byte[] value) {
141         m_fileContent=value;
142         if (m_fileContent.length >0 ) {
143             m_size=m_fileContent.length;
144         }
145     }
146 }