KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jahia > data > templates > JahiaTemplatesPackage


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
// JahiaTemplatesPackage
15
//
16
// NK 16.01.2001
17
//
18
//
19

20 package org.jahia.data.templates;
21
22 import java.io.File JavaDoc;
23 import java.util.Vector JavaDoc;
24
25 /**
26  * Holds Informations about a templates package
27  *
28  * @author Khue ng
29  * @version 1.0
30  */

31 public class JahiaTemplatesPackage {
32     
33     /** the file or directory name from which data are loaded **/
34     private String JavaDoc m_FileName;
35     /** the full path to the source file or directory **/
36     private String JavaDoc m_FilePath;
37     /** the package type **/
38     private int m_Type ; // 1=jar,2=directory
39
/** jar package **/
40     private static final int JAR = 1;
41     /** directory **/
42     private static final int DIR = 2;
43
44     /** Name of the package **/
45     private String JavaDoc m_Name;
46     /** The Folder Name where to extract package contents **/
47     private String JavaDoc m_RootFolder;
48     /** The name of the jar file containing classes used by this package **/
49     private String JavaDoc m_ClassesFile;
50     /** The Package Provider Name **/
51     private String JavaDoc m_Provider;
52     /** The Package thumbnail image file Name entry **/
53     private String JavaDoc m_Thumbnail;
54     
55     /** The Templates descs list *
56      * @associates JahiaTemplateDef*/

57     private Vector JavaDoc m_TemplatesList = new Vector JavaDoc();
58
59     /** An optional id ( can be set and used as identifier ) **/
60     private int m_ID;
61     
62     /**
63      * the description file
64      */

65     public static final String JavaDoc DESCR_FILE = "templates_descr.txt";
66
67     /**
68      * Constructor
69      *
70      */

71     public JahiaTemplatesPackage (
72                                     String JavaDoc name,
73                                     String JavaDoc rootFolder,
74                                     String JavaDoc classesFile,
75                                     String JavaDoc providerName,
76                                     String JavaDoc thumbnail
77                                 )
78     {
79         m_Name = name;
80         m_RootFolder = rootFolder;
81         m_ClassesFile = classesFile;
82         m_Provider = providerName;
83         m_Thumbnail = thumbnail;
84     }
85
86     /**
87      * Return the id
88      *
89      * @return (int) the id
90      */

91     public int getID(){
92       
93         return m_ID;
94     }
95
96
97     /**
98      * Set the id
99      * @param (int) the id
100      */

101     public void setID(int id){
102       
103         m_ID = id;
104     }
105
106
107     /**
108      * Return the template name
109      *
110      * @return (String) the name of the template
111      */

112     public String JavaDoc getName(){
113       
114         return m_Name;
115     }
116
117
118     /**
119      * Set the name
120      * @param (String) the name of the template
121      */

122     protected void setName(String JavaDoc name){
123       
124         m_Name = name;
125     }
126
127
128     /**
129      * Return the Root Folder
130      *
131      * @return (String) the Root Folder of the templates
132      */

133     public String JavaDoc getRootFolder(){
134       
135         return m_RootFolder;
136     }
137
138
139     /**
140      * Set the Root Folder
141      *
142      * @param (String) the Root Folder of the templates
143      */

144     protected void setRootFolder(String JavaDoc folder){
145       
146         m_RootFolder = folder;
147     }
148
149
150     /**
151      * Return the Classes File name
152      *
153      * @return (String) the Classes File name
154      */

155     public String JavaDoc getClassesFile(){
156       
157         return m_ClassesFile;
158     }
159
160
161     /**
162      * Set the Classes file
163      *
164      * @param (String) the Classes file name
165      */

166     protected void setClassesFile(String JavaDoc classesFile){
167       
168         m_ClassesFile = classesFile;
169     }
170
171
172     /**
173      * Return true if the classesFile is not null and length>0
174      *
175      * @return (boolean) true if m_ClassesFile != null && length>0
176      */

177     public boolean hasClasses(){
178       
179         return (m_ClassesFile != null && m_ClassesFile.length()>0);
180     }
181
182
183     /**
184      * Return the provider name
185      *
186      * @return (String) the name of the Provider
187      */

188     public String JavaDoc getProvider(){
189       
190         return m_Provider;
191     }
192
193
194     /**
195      * Set the Provider
196      * @param (String) the name of the Provider
197      */

198     protected void setProvider(String JavaDoc provider){
199       
200         m_Provider = provider;
201     }
202
203
204    /**
205     * Return the thumbnail file name
206     *
207     * @return (String) the thumbnail file name
208     */

209    public String JavaDoc getThumbnail(){
210
211       return m_Thumbnail;
212    }
213
214
215    /**
216     * Set the thumbnail file name
217     * @param (String) the file name
218     */

219    public void setThumbnail(String JavaDoc val){
220
221       m_Thumbnail = val;
222    }
223
224
225    /**
226     * Return the home page template.
227     *
228     * @return (JahiaTemplateDef) , the Home page template or null if no defined home page template
229     */

230    public JahiaTemplateDef getHomePageTemplate(){
231         
232         int size = m_TemplatesList.size();
233         JahiaTemplateDef template = null;
234         for ( int i=0 ; i<size ; i++ ){
235             template = (JahiaTemplateDef)m_TemplatesList.get(i);
236             if ( template.isHomePage() ){
237                 return template;
238             }
239         }
240         return null;
241    }
242
243     /**
244      * Set the Templates Descrition List
245      *
246      * @params (Vector) templatesList, the list of templates definitions
247      */

248     protected void setTemplates(Vector JavaDoc templatesList){
249       
250         m_TemplatesList = templatesList;
251    
252     }
253     
254     /**
255      * Get the Templates Descrition List
256      *
257      * @return (Vector) the Vector of templates definitions list
258      */

259     public Vector JavaDoc getTemplates(){
260       
261         return m_TemplatesList;
262     }
263
264    
265     /**
266      * Add a Template Definition in the Templates list
267      *
268      * @param (JahiaTemplate) tempDef
269      */

270     public void addTemplateDef(JahiaTemplateDef tempDef ){
271       
272         m_TemplatesList.add(tempDef);
273     }
274    
275
276     /**
277      * get the source filename
278      *
279      */

280     public String JavaDoc getFileName(){
281         return this.m_FileName;
282     }
283
284
285     /**
286      * set the source filename
287      *
288      */

289     protected void setFileName(String JavaDoc name){
290         this.m_FileName = name;
291
292         if ( name.endsWith(".jar") ){
293             m_Type = JAR;
294         } else {
295             m_Type = DIR;
296         }
297     }
298
299
300     /**
301      * get the file path
302      *
303      */

304     public String JavaDoc getFilePath(){
305         return this.m_FilePath;
306     }
307
308
309     /**
310      * set the file path
311      *
312      */

313     public void setFilePath(String JavaDoc path){
314         this.m_FilePath = path;
315         File JavaDoc f = new File JavaDoc(path);
316         this.setFileName(f.getName());
317     }
318
319
320     /**
321      * if the source is a file
322      *
323      */

324     public boolean isFile(){
325         return (m_Type == JAR);
326     }
327
328
329     /**
330      * if the source is a directory
331      *
332      */

333     public boolean isDirectory(){
334         return ( m_Type == DIR );
335     }
336     
337
338     
339 } // end JahiaTemplatesPackage
340
Popular Tags