KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jahia > services > homepages > JahiaHomepageNew


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
// NK - 17 Dec. 2001 :
14
//
15

16 package org.jahia.services.homepages;
17
18
19 import java.util.Hashtable JavaDoc;
20
21 import org.jahia.exceptions.JahiaException;
22
23
24 /**
25  * A JahiaHomepageNew holds information used to define homepage of type New.
26  * Home page definition of this type holds extra information like the template to use for the page to create,
27  * the parent page id ( where to insert the new page ), and default right setting.
28  *
29  * @author Khue ng
30  * @see HomepagesTypes.HOMEPAGE_NEW
31  * @version 1.0
32  */

33 public final class JahiaHomepageNew extends JahiaHomepage
34 {
35     private static String JavaDoc CLASS_NAME = JahiaHomepageNew.class.getName();
36     
37     // template to use
38
private static final String JavaDoc TEMPLATE = "template";
39
40     // where to insert the new page ( or subtree )
41
private static final String JavaDoc PARENT_PAGEID = "parent_pageid";
42
43     private JahiaHomepagesPersistance hpp;
44
45     
46     /**
47      * Constructor, subclass must have exact constructor signature.
48      *
49      * @param Integer id, the unique identifier
50      * @param String name, the name
51      * @param String descr, the descr
52      * @param Integer type, the type
53      * @param String sitekey, the site key
54      * @param Hashtable props, the properties
55      * @param Integer aclID, the acl
56      */

57     JahiaHomepageNew( Integer JavaDoc id,
58                         String JavaDoc name,
59                         String JavaDoc descr,
60                         Integer JavaDoc type,
61                         String JavaDoc siteKey,
62                         Hashtable JavaDoc props,
63                         Integer JavaDoc aclID ){
64     
65         super(id,name,descr,type,siteKey,props,aclID);
66     }
67
68     //-------------------------------------------------------------------------
69
/**
70      * Return the id of the page to use as parent for the new homepage.
71      *
72      * @return int the parent page id, -1 if not defined.
73      */

74     public int getParentPageID(){
75         Integer JavaDoc id = (Integer JavaDoc)props.get(PARENT_PAGEID);
76         if ( id == null ){
77             return -1;
78         }
79         return id.intValue();
80     }
81     
82     //-------------------------------------------------------------------------
83
/**
84      * Set the parent page ID
85      *
86      * @param int the parent page id
87      */

88     public void setParentPageID(int pageID) throws JahiaException{
89         props.put(PARENT_PAGEID,new Integer JavaDoc(pageID));
90     }
91
92     //-------------------------------------------------------------------------
93
/**
94      * Return the id of the template to use when creating the page.
95      *
96      * @return int the template id, -1 if not defined.
97      */

98     public int getTemplateID(){
99         Integer JavaDoc id = (Integer JavaDoc)props.get(TEMPLATE);
100         if ( id == null ){
101             return -1;
102         }
103         return id.intValue();
104     }
105     
106     //-------------------------------------------------------------------------
107
/**
108      * Set the template ID
109      *
110      * @param int the template id
111      */

112     public void setTemplateID(int id) throws JahiaException{
113         props.put(TEMPLATE,new Integer JavaDoc(id));
114     }
115
116     //--------------------------------------------------------------------------
117
/**
118      * Save its state.
119      *
120      */

121     void save()
122     throws JahiaException {
123         
124         JahiaHomepagesPersistance.getInstance().save(this);
125         saveProperties();
126     }
127
128     //--------------------------------------------------------------------------
129
/**
130      * Delete.
131      *
132      */

133     void delete()
134     throws JahiaException {
135
136         JahiaHomepagesPersistance.getInstance().delete(getID());
137         deleteProperties();
138     }
139
140     //-------------------------------------------------------------------------
141
/**
142      * Load extra properties from storage
143      *
144      */

145     void loadProperties() throws JahiaException{
146         
147         if ( props == null )
148             props = new Hashtable JavaDoc();
149         
150         String JavaDoc value = null;
151
152         value = JahiaHomepagesPersistance.getInstance().getProperty(this,TEMPLATE);
153         if ( value != null ){
154             try {
155                 props.put(TEMPLATE,new Integer JavaDoc(value));
156             } catch ( Throwable JavaDoc t ){
157                 t.printStackTrace();
158             }
159         }
160
161         value = JahiaHomepagesPersistance.getInstance().getProperty(this,PARENT_PAGEID);
162         if ( value != null ){
163             try {
164                 props.put(PARENT_PAGEID,new Integer JavaDoc(value));
165             } catch ( Throwable JavaDoc t ){
166                 t.printStackTrace();
167             }
168         }
169
170     }
171
172     //-------------------------------------------------------------------------
173
/**
174      * Save extra properties in storage
175      *
176      */

177     void saveProperties() throws JahiaException{
178         
179         deleteProperties();
180         
181         String JavaDoc value = null;
182         
183         value = Integer.toString(getTemplateID());
184         if ( value != null )
185             JahiaHomepagesPersistance.getInstance().addProperty(this,TEMPLATE,value);
186
187         value = Integer.toString(getParentPageID());
188         if ( value != null )
189             JahiaHomepagesPersistance.getInstance().addProperty(this,PARENT_PAGEID,value);
190
191     }
192
193     //-------------------------------------------------------------------------
194
/**
195      * Delete extra properties in storage
196      *
197      */

198     void deleteProperties() throws JahiaException{
199         
200         JahiaHomepagesPersistance.getInstance().deleteProperties(this);
201     }
202
203     //--------------------------------------------------------------------------
204
/**
205      * Return a string representation of the home page and it's internal state.
206      *
207      * @return A string representation of this home page.
208      */

209     public String JavaDoc toString (){
210         
211         StringBuffer JavaDoc buff= new StringBuffer JavaDoc("String rep. of a ");
212         buff.append(CLASS_NAME);
213         buff.append(" bean :\n");
214         buff.append(" id :");
215         buff.append(getID());
216         // TODO . complete
217
return buff.toString();
218         
219     }
220
221     //--------------------------------------------------------------------------
222
/**
223      * Return a clone.
224      *
225      * @return JahiaHomepage, the clone.
226      */

227     public Object JavaDoc clone (){
228         
229         Hashtable JavaDoc hash = null;
230         if ( getProperties() != null ){
231             hash = new Hashtable JavaDoc();
232             if ( props.get(PARENT_PAGEID) != null )
233                 hash.put(PARENT_PAGEID,new Integer JavaDoc(getParentPageID()));
234             if ( props.get(TEMPLATE) != null )
235                 hash.put(TEMPLATE,new Integer JavaDoc(getTemplateID()));
236
237         }
238         
239         JahiaHomepageNew clone =
240                 new JahiaHomepageNew( new Integer JavaDoc(getID()),
241                                         getName(),
242                                         getDescr(),
243                                         new Integer JavaDoc(getType()),
244                                         getSiteKey(),
245                                         hash,
246                                         new Integer JavaDoc(getAclID()) );
247         return clone;
248     }
249
250
251 }
252
Popular Tags