KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jahia > data > files > JahiaFileField


1 //
2
// ____.
3
// __/\ ______| |__/\. _______
4
// __ .____| | \ | +----+ \
5
// _______| /--| | | - \ _ | : - \_________
6
// \\______: :---| : : | : | \________>
7
// |__\---\_____________:______: :____|____:_____\
8
// /_____|
9
//
10
// . . . i n j a h i a w e t r u s t . . .
11
//
12
//
13
//
14
// JahiaFileField
15
//
16
// NK 02.02.2001
17
//
18
//
19

20 package org.jahia.data.files;
21
22 import java.util.Properties JavaDoc;
23
24 import org.jahia.utils.JahiaTools;
25
26 /**
27  * Class JahiaFileField.<br>
28  * A file field item <br>
29  *
30  * @author Khue ng
31  * @version 1.0
32  */

33 public class JahiaFileField extends JahiaFile implements Cloneable JavaDoc {
34
35     static public String JavaDoc FIELD_FILE_TITLE_PROP = "field_file_title";
36     static public String JavaDoc FIELD_FILE_FILEID_PROP = "field_file_fileid";
37     static public String JavaDoc FIELD_FILE_VERSION_PROP = "field_file_version";
38
39     /** the id **/
40     private int id = -1;
41     /** Properties **/
42     private Properties JavaDoc properties = new Properties JavaDoc();
43
44     /**
45      * Constructor
46      *
47      */

48     protected JahiaFileField(){
49     }
50
51     /**
52      *
53      * @param fileItem
54      * @param properties, if null, not set
55      */

56     public JahiaFileField( JahiaFile fileItem,
57                             Properties JavaDoc properties ){
58         if ( properties != null ){
59             this.properties = properties;
60         }
61
62         if ( fileItem != null ){
63             setFile(fileItem);
64         }
65
66         // default value
67
if ( this.getFileFieldTitle() == null
68              || "".equals(this.getFileFieldTitle()) ){
69             this.setFileFieldTitle(fileItem.getTitle());
70         }
71
72     }
73
74     public int getID(){
75         return this.id;
76     }
77
78     public void setID(int id){
79         this.id = id;
80     }
81
82     public void setFile(JahiaFile fileItem){
83         if ( fileItem == null ){
84             return;
85         }
86         setFileID(fileItem.getFileID());
87         setFilemanagerID(fileItem.getFilemanagerID());
88         setFolderID(fileItem.getFolderID());
89         setUploadUser(fileItem.getUploadUser());
90         setRealName(fileItem.getRealName());
91         setStorageName(fileItem.getStorageName());
92         setLastModifDate(fileItem.getLastModifDate());
93         setSize(fileItem.getSize());
94         setType(fileItem.getType());
95         setTitle(fileItem.getTitle());
96         setDescr(fileItem.getDescr());
97         setVersion(fileItem.getVersion());
98         setState(fileItem.getState());
99
100         this.setProperty(JahiaFileField.FIELD_FILE_FILEID_PROP,
101                          String.valueOf(fileItem.getFileID()));
102
103         this.setProperty(JahiaFileField.FIELD_FILE_VERSION_PROP,fileItem.getVersion());
104
105         if ( this.getFileFieldTitle() == null ){
106             this.setFileFieldTitle(fileItem.getTitle());
107         }
108
109     }
110
111     public String JavaDoc getFileFieldTitle(){
112         if ( properties == null ){
113             return null;
114         }
115         return JahiaTools.text2html((String JavaDoc)properties.get(FIELD_FILE_TITLE_PROP));
116     }
117
118     public void setFileFieldTitle(String JavaDoc title){
119        if ( title == null ){
120            return;
121        }
122         setProperty(FIELD_FILE_TITLE_PROP,title);
123     }
124
125     public void setProperty(String JavaDoc name, String JavaDoc value){
126         if ( properties == null ){
127             properties = new Properties JavaDoc();
128         }
129         properties.setProperty(name,value);
130     }
131
132     public Properties JavaDoc getProperties(){
133         return this.properties;
134     }
135
136     public void setProperties(Properties JavaDoc properties){
137         if ( properties != null ){
138             this.properties = properties;
139         }
140     }
141
142     public Object JavaDoc clone(){
143
144         JahiaFile file =
145                 new JahiaFile(this.getFilemanagerID(),
146                 this.getFolderID(),this.getUploadUser(),this.getRealName(),
147                 this.getStorageName(),this.getLastModifDate(),this.getSize(),
148                 this.getType(),this.getTitle(),this.getDescr(),this.getVersion(),this.getState());
149         file.setFileID(this.getFileID());
150
151         Properties JavaDoc props = (Properties JavaDoc)this.properties.clone();
152
153         JahiaFileField clone = new JahiaFileField(file,props);
154
155         return clone;
156     }
157 }
Popular Tags