KickJava   Java API By Example, From Geeks To Geeks.

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


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 JahiaHomepageLink holds information used to define homepage of type Link.
26  * Home page definition of this type holds a page id that refers to the page that
27  * should be used as Home page.
28  *
29  * @author Khue ng
30  * @see HomepageTypes.HOMEPAGE_LINK
31  * @version 1.0
32  */

33 public final class JahiaHomepageLink extends JahiaHomepage
34 {
35     private static String JavaDoc CLASS_NAME = JahiaHomepageLink.class.getName();
36     
37     private static final String JavaDoc PAGEID = "pageid";
38
39     private JahiaHomepagesPersistance hpp;
40
41
42     /**
43      * Constructor, subclass must have exact constructor signature.
44      *
45      * @param Integer id, the unique identifier
46      * @param String name, the name
47      * @param String descr, the descr
48      * @param Integer type, the type
49      * @param String sitekey, the site key
50      * @param Hashtable props, the properties
51      * @param Integer aclID, the acl
52      */

53     JahiaHomepageLink( Integer JavaDoc id,
54                         String JavaDoc name,
55                         String JavaDoc descr,
56                         Integer JavaDoc type,
57                         String JavaDoc siteKey,
58                         Hashtable JavaDoc props,
59                         Integer JavaDoc aclID ){
60     
61         super(id,name,descr,type,siteKey,props,aclID);
62     }
63
64     
65     //-------------------------------------------------------------------------
66
/**
67      * Return the internal page id that refers to a Jahia Page.
68      *
69      * @return int the internal page id or -1 if not defined.
70      */

71     public int getPageID(){
72         Integer JavaDoc pageID = (Integer JavaDoc)props.get(PAGEID);
73         if ( pageID == null ){
74             return -1;
75         }
76         return pageID.intValue();
77     }
78     
79     //-------------------------------------------------------------------------
80
/**
81      * Set the page ID
82      *
83      * @param int the id
84      */

85     public void setPageID(int id){
86         props.put(PAGEID,new Integer JavaDoc(id));
87     }
88
89     //--------------------------------------------------------------------------
90
/**
91      * Save its state.
92      *
93      */

94     void save()
95     throws JahiaException {
96         
97         JahiaHomepagesPersistance.getInstance().save(this);
98         saveProperties();
99     }
100
101     //--------------------------------------------------------------------------
102
/**
103      * Delete.
104      *
105      */

106     void delete()
107     throws JahiaException {
108
109         JahiaHomepagesPersistance.getInstance().delete(getID());
110         deleteProperties();
111     }
112
113     //-------------------------------------------------------------------------
114
/**
115      * Load extra properties from storage
116      *
117      */

118     void loadProperties() throws JahiaException{
119         
120         if ( props == null )
121             props = new Hashtable JavaDoc();
122         
123         String JavaDoc value = null;
124
125         value = JahiaHomepagesPersistance.getInstance().getProperty(this,PAGEID);
126         if ( value != null ){
127             try {
128                 props.put(PAGEID,new Integer JavaDoc(value));
129             } catch ( Throwable JavaDoc t ){
130                 t.printStackTrace();
131             }
132         }
133     }
134     
135     //-------------------------------------------------------------------------
136
/**
137      * Save extra properties in storage
138      *
139      */

140     void saveProperties() throws JahiaException{
141         
142         deleteProperties();
143         
144         String JavaDoc value = null;
145         
146         value = Integer.toString(getPageID());
147         if ( value != null )
148             JahiaHomepagesPersistance.getInstance().addProperty(this,PAGEID,value);
149
150     }
151
152     //-------------------------------------------------------------------------
153
/**
154      * Delete extra properties in storage
155      *
156      */

157     void deleteProperties() throws JahiaException{
158         
159         JahiaHomepagesPersistance.getInstance().deleteProperties(this);
160     }
161
162
163     //--------------------------------------------------------------------------
164
/**
165      * Return a string representation of the home page and it's internal state.
166      *
167      * @return A string representation of this home page.
168      */

169     public String JavaDoc toString (){
170         
171         StringBuffer JavaDoc buff= new StringBuffer JavaDoc("String rep. of a ");
172         buff.append(CLASS_NAME);
173         buff.append(" bean :\n");
174         buff.append(" id :");
175         buff.append(getID());
176         // TODO . complete
177
return buff.toString();
178         
179     }
180
181     //--------------------------------------------------------------------------
182
/**
183      * Return a clone.
184      *
185      * @return Object the clone.
186      */

187     public Object JavaDoc clone (){
188         
189         Hashtable JavaDoc hash = null;
190         if ( getProperties() != null ){
191             hash = new Hashtable JavaDoc();
192             if ( props.get(PAGEID) != null )
193                 hash.put(PAGEID,new Integer JavaDoc(getPageID()));
194         }
195         
196         JahiaHomepageLink clone =
197                 new JahiaHomepageLink( new Integer JavaDoc(getID()),
198                                         getName(),
199                                         getDescr(),
200                                         new Integer JavaDoc(getType()),
201                                         getSiteKey(),
202                                         hash,
203                                         new Integer JavaDoc(getAclID()) );
204         return clone;
205     }
206
207
208 }
209
Popular Tags