KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jahia > services > pages > JahiaPageInfo


1 // $Id: JahiaPageInfo.java 16768 2007-03-15 10:13:38Z bpapez $
2
//
3
//
4
// ____.
5
// __/\ ______| |__/\. _______
6
// __ .____| | \ | +----+ \
7
// _______| /--| | | - \ _ | : - \_________
8
// \\______: :---| : : | : | \________>
9
// |__\---\_____________:______: :____|____:_____\
10
// /_____|
11
//
12
// . . . i n j a h i a w e t r u s t . . .
13
//
14

15
16 package org.jahia.services.pages;
17
18 import org.jahia.exceptions.JahiaException;
19 import org.jahia.services.version.EntryStateable;
20 import java.io.Serializable JavaDoc;
21
22 /**
23  * This class is used internally in Jahia to keep the page information stored
24  * in the database. Each time a page is loaded it's information are stored
25  * into the cache using this class.<br/>
26  * <br/>
27  * This class knows how to save it's content, but it's not an automatic process
28  * to avoid one database access for each little change made to the page data.
29  * Therefore a call to the {@link #commitChanges commitChanges()} method is
30  * needed to save the update information to the database.
31  *
32  * @author Fulco Houkes
33  * @version 1.0
34  */

35 class JahiaPageInfo implements PageInfoInterface, EntryStateable, Serializable JavaDoc {
36     private int mID; // page unique identification number
37
private int mSiteID; // site unique identification number
38
private int mParentID; // parent page ID
39
private int mPageType; // page type
40
private String JavaDoc mTitle; // page title
41
private int mPageTemplateID; // page definition ID
42
private String JavaDoc mRemoteURL; // external URL (not a jahia internal link)
43
private int mPageLinkID; // if the page is an internal link, hold the page ID
44
private String JavaDoc mCreator; // creator's user name
45
private String JavaDoc mDoc; // date of creation
46
private int mCounter; // page access counter
47
private int mAclID; // access control list ID
48

49     private String JavaDoc mLanguageCode;
50     private int mVersionID;
51     private int mVersionStatus;
52
53     // these variables are
54
private int mTempParentID; // temporary, parent page ID
55
private int mTempAclID; // temporary, access control list ID
56
private int mTempPageType; // temporary, page type
57
private String JavaDoc mTempTitle; // temporary, page title
58
private int mTempPageTemplateID; // temporary, page definition ID
59
private String JavaDoc mTempRemoteURL; // temporary, external URL (not a jahia internal link)
60
private int mTempPageLinkID; // temporary, if the page is an internal link, hold the page ID
61

62     private boolean mDataChanged = false; // true if the internal state of the page
63
// has been changed with a setxxxx method.
64

65     private int mHashCode = -1; // used to avoid recalculating hash code if
66
// nothing has changed.
67

68
69     private static JahiaPagesDB mPageDB = JahiaPagesDB.getInstance ();
70
71
72     /*
73     protected JahiaPageInfo (int ID, int jahiaID, int parentID, int pageType,
74                              String title, int pageTemplateID, String remoteURL,
75                              int pageLinkID, String creator, String doc,
76                              int counter, int aclID) {
77         this(ID, jahiaID, parentID, pageType, title, pageTemplateID, remoteURL,
78              pageLinkID, creator, doc, counter, aclID, 0, 0, "*");
79     }
80     */

81
82     //-------------------------------------------------------------------------
83
/**
84      * constructor
85      */

86     protected JahiaPageInfo (int ID, int jahiaID, int parentID, int pageType,
87                              String JavaDoc title, int pageTemplateID, String JavaDoc remoteURL,
88                              int pageLinkID, String JavaDoc creator, String JavaDoc doc,
89                              int counter, int aclID,
90                              int versionID, int versionStatus, String JavaDoc languageCode) {
91         mID = ID;
92         mSiteID = jahiaID;
93         mParentID = parentID;
94         mTitle = title;
95         mCreator = creator;
96         mDoc = doc;
97         mCounter = counter;
98         mAclID = aclID;
99         mPageType = pageType;
100         mPageTemplateID = pageTemplateID;
101         mVersionID = versionID;
102         mVersionStatus = versionStatus;
103         mLanguageCode = languageCode;
104
105         if (remoteURL == null) {
106             mRemoteURL = NO_REMOTE_URL;
107         } else {
108             mRemoteURL = remoteURL;
109         }
110
111         mPageLinkID = pageLinkID;
112
113         // temporary variables
114
mTempParentID = mParentID;
115         mTempAclID = mAclID;
116         mTempPageType = mPageType;
117         mTempTitle = mTitle;
118         mTempPageTemplateID = pageTemplateID;
119         mTempRemoteURL = mRemoteURL;
120         mTempPageLinkID = mPageLinkID;
121         mDataChanged = false;
122     } // end constructor
123

124
125     public boolean equals (Object JavaDoc obj) {
126         if (!(obj instanceof JahiaPageInfo)) {
127             return false;
128         }
129         JahiaPageInfo rightPageInfo = (JahiaPageInfo) obj;
130         return ((getID () == rightPageInfo.getID ()) &&
131                 (getWorkflowState () == rightPageInfo.getWorkflowState ()) &&
132                 (getVersionID () == rightPageInfo.getVersionID ()) &&
133                 (getLanguageCode ().equals (rightPageInfo.getLanguageCode ())));
134     }
135
136     public int hashCode () {
137         if ((mDataChanged) || (mHashCode == -1)) {
138             StringBuffer JavaDoc buff = new StringBuffer JavaDoc(30);
139             buff.append(mID);
140             buff.append("_");
141             buff.append(mVersionID);
142             buff.append("_");
143             buff.append(mVersionStatus);
144             buff.append("_");
145             buff.append(mLanguageCode);
146             mHashCode = buff.toString ().hashCode ();
147         }
148         return mHashCode;
149     }
150
151     //-------------------------------------------------------------------------
152
/**
153      * Return the page's unique identification number.
154      *
155      * @return Return the page ID.
156      */

157     public int getID () {
158         return mID;
159     }
160
161     //-------------------------------------------------------------------------
162
/**
163      * Return the site ID in which the page is located.
164      *
165      * @return Return the page site ID.
166      */

167     public int getJahiaID () {
168         return mSiteID;
169     }
170
171     //-------------------------------------------------------------------------
172
/**
173      * Return the parent page unique identification number.
174      *
175      * @return Return the parent page ID.
176      */

177     public int getParentID () {
178         return mParentID;
179     }
180
181     //-------------------------------------------------------------------------
182
/**
183      * Return the page definition ID.
184      *
185      * @return Return the page definition ID.
186      */

187     public int getPageTemplateID () {
188         return mPageTemplateID;
189     }
190
191     //-------------------------------------------------------------------------
192
/**
193      * Return the page title.
194      *
195      * @return Return the page title.
196      */

197     public String JavaDoc getTitle () {
198         return mTitle;
199     }
200
201     //-------------------------------------------------------------------------
202
/**
203      * Return the user nickname who created the page. This nickname is the
204      * user name used internally by Jahia.
205      *
206      * @return Return the creator nickname.
207      */

208     public String JavaDoc getCreator () {
209         return mCreator;
210     }
211
212     //-------------------------------------------------------------------------
213
/**
214      * Return the page's date of creation in ms from 1975.
215      *
216      * @return Return the date of creation.
217      */

218     public String JavaDoc getDoc () {
219         return mDoc;
220     }
221
222     //-------------------------------------------------------------------------
223
/**
224      * Return the page's hit counter.
225      *
226      * @return Return the page counter.
227      */

228     public int getCounter () {
229         return mCounter;
230     }
231
232     //-------------------------------------------------------------------------
233
/**
234      * Return the ACL unique identification number.
235      *
236      * @return Return the ACL ID.
237      */

238     public int getAclID () {
239         return mAclID;
240     }
241
242     //-------------------------------------------------------------------------
243
/**
244      * Return the page type
245      *
246      * @return Return the page type
247      */

248     public int getPageType () {
249         return mPageType;
250     }
251
252     //-------------------------------------------------------------------------
253
/**
254      * Return the remote URL in case the page is an external reference (a non
255      * Jahia page. If the page is not an external URL, "<no url>" is returned.
256      *
257      * @return Return the remote URL.
258      */

259     public String JavaDoc getRemoteURL () {
260         return mRemoteURL;
261     }
262
263     //-------------------------------------------------------------------------
264
/**
265      * Return the internal jahia page ID in case the page is an internal
266      * jahia link.
267      *
268      * @return Return the page link ID.
269      */

270     public int getPageLinkID () {
271         return mPageLinkID;
272     }
273
274
275
276
277     //-------------------------------------------------------------------------
278
/**
279      * Change the page title.
280      *
281      * @param value String holding the new page title.
282      */

283     public synchronized void setTitle (String JavaDoc value) {
284         mTempTitle = value;
285         mDataChanged = true;
286     }
287
288     //-------------------------------------------------------------------------
289
/**
290      * Change the page type. By changing this information, be aware to change
291      * also the according remote URL or page link ID information. See the
292      * methods {@link #setPageLinkID setPageLinkID()} and
293      * {@link #setRemoteURL setRemoteURL()}.
294      *
295      * @param pageType The new page type.
296      */

297     public synchronized void setPageType (int value) {
298         mTempPageType = value;
299
300         switch (value) {
301             case TYPE_LINK:
302                 // the page in a link to an internal page. Disable the
303
// remote URL.
304
mTempRemoteURL = NO_REMOTE_URL;
305                 break;
306
307             case TYPE_URL:
308                 // the page is an extenal URL, disable the internal page link.
309
mTempPageLinkID = TERMINATION_PAGE_ID;
310                 break;
311
312             case TYPE_DIRECT:
313                 // the page is a REAL page, disable the internal and external
314
// links.
315
mTempRemoteURL = NO_REMOTE_URL;
316                 mTempPageLinkID = TERMINATION_PAGE_ID;
317                 break;
318         }
319         mDataChanged = true;
320     }
321
322     //-------------------------------------------------------------------------
323
/**
324      * Set the parent ID, which must point to an existing page.
325      *
326      * @param value The new parent ID.
327      */

328     public synchronized void setParentID (int value) {
329         mTempParentID = value;
330         mDataChanged = true;
331     }
332
333     /**
334      * Set the ACL ID to an existing ACL.
335      *
336      * @param aclID
337      */

338     public synchronized void setAclID (int aclID) {
339         mTempAclID = aclID;
340         mDataChanged = true;
341     }
342
343     //-------------------------------------------------------------------------
344
/**
345      * Set the new remote URL. The page type will change accordingly.
346      *
347      * @param value The new remoteURL.
348      */

349     public synchronized void setRemoteURL (String JavaDoc value) {
350         mTempRemoteURL = value;
351         mTempPageType = TYPE_URL;
352         mTempPageLinkID = TERMINATION_PAGE_ID;
353         mDataChanged = true;
354     }
355
356     //-------------------------------------------------------------------------
357
/**
358      * Set the new remote URL. The page type will NOT change accordingly.
359      *
360      * @param value The new remoteURL.
361      */

362     public synchronized void setRemoteURLWithoutType (String JavaDoc value) {
363         mTempRemoteURL = value;
364         mDataChanged = true;
365     }
366
367     //-------------------------------------------------------------------------
368
/**
369      * Set the new internal link ID. This ID must be an existing page ID.
370      *
371      * @param value The new page link ID.
372      */

373     public synchronized void setPageLinkID (int value) {
374         mTempPageLinkID = value;
375         mTempPageType = TYPE_LINK;
376         mTempRemoteURL = NO_REMOTE_URL;
377         mDataChanged = true;
378     }
379
380
381     //-------------------------------------------------------------------------
382
/**
383      * Set the new page defintion ID. The ID must point to a existing page
384      * definition.
385      *
386      * @param value The new page defintion ID.
387      */

388     public synchronized final void setPageTemplateID (int value) {
389         mTempPageTemplateID = value;
390         mDataChanged = true;
391     }
392
393
394     //-------------------------------------------------------------------------
395
/**
396      * Commit into the database all the previous changes on the page.
397      *
398      * @throws JahiaException Throws a JahiaException if the data could not
399      * be saved successfully into the database.
400      */

401     public synchronized void commitChanges () throws JahiaException
402     {
403         commitChanges(true);
404     }
405
406     //-------------------------------------------------------------------------
407
/** Commit into the database all the previous changes on the page.
408      *
409      * @param commitToDB, if true, store in db, else only copy temporary change
410      * to effective values.
411      *
412      * @exception JahiaException Throws a JahiaException if the data could not
413      * be saved successfully into the database.
414      */

415     public synchronized void commitChanges (boolean commitToDB)
416     throws JahiaException
417     {
418         // commit only if the data has really changed
419
if (mDataChanged) {
420             // commit the modified changes.
421
mParentID = mTempParentID;
422             mAclID = mTempAclID;
423             mPageType = mTempPageType;
424             mTitle = mTempTitle;
425             mPageTemplateID = mTempPageTemplateID;
426             mRemoteURL = mTempRemoteURL;
427             mPageLinkID = mTempPageLinkID;
428             if ( commitToDB ){
429                 // commit the changes into the database.
430
mPageDB.updatePageInfo (this, mVersionID, mVersionStatus);
431                 mDataChanged = false;
432             }
433             mRemoteURL = mTempRemoteURL;
434             mPageLinkID = mTempPageLinkID;
435
436             // commit the changes into the database.
437
mPageDB.updatePageInfo (this, mVersionID, mVersionStatus);
438             mDataChanged = false;
439         }
440     }
441
442     //-------------------------------------------------------------------------
443
/**
444      * Increment by one unit the page hit counter.
445      */

446     public synchronized void incrementCounter () {
447         mCounter++;
448         mDataChanged = true;
449     }
450
451     //-------------------------------------------------------------------------
452
/**
453      * clone page info
454      *
455      * @param aclID int The id to asociate to the cloned page
456      * @param newParentID int The id of the parent.
457      * if newParentID = -1, get the parent ID of the page to clone.
458      * @param pageID int the new id of the cloned page.
459      * @param dateOfCreation String the current date.
460      *
461      * @return Return the cloned JahiaPageInfo
462      */

463     protected JahiaPageInfo clonePageInfo (int aclID, int newParentID,
464                                            int pageID, String JavaDoc dateOfCreation) {
465         if (newParentID == -1) {
466             newParentID = mParentID;
467         }
468         // String Title = "clonedTitle";
469
return new JahiaPageInfo (pageID, mSiteID, newParentID, mPageType,
470                 mTitle, mPageTemplateID, mRemoteURL,
471                 mPageLinkID, mCreator, dateOfCreation,
472                 mCounter, aclID,
473                 mVersionID, mVersionStatus, mLanguageCode);
474     }
475
476     protected JahiaPageInfo clonePageInfo (int versionID, int versionStatus,
477                                            String JavaDoc languageCode) {
478         JahiaPageInfo newPageInfo = new JahiaPageInfo (mID, mSiteID, mParentID, mPageType,
479                 mTitle, mPageTemplateID, mRemoteURL,
480                 mPageLinkID, mCreator, mDoc,
481                 mCounter, mAclID, versionID, versionStatus,
482                 languageCode);
483         newPageInfo.mTempAclID = mTempAclID;
484         newPageInfo.mTempPageLinkID = mTempPageLinkID;
485         newPageInfo.mTempPageTemplateID = mTempPageTemplateID;
486         newPageInfo.mTempPageType= mTempPageType;
487         newPageInfo.mTempParentID = mTempParentID;
488         newPageInfo.mTempRemoteURL = mTempRemoteURL;
489         newPageInfo.mTempTitle = mTempTitle;
490         newPageInfo.mDataChanged = mDataChanged;
491         return newPageInfo;
492     }
493
494     public String JavaDoc getLanguageCode () {
495         return mLanguageCode;
496     }
497
498     public int getVersionID () {
499         return mVersionID;
500     }
501
502     public int getWorkflowState () {
503         return mVersionStatus;
504     }
505
506     public void setVersionID (int newVersionID) {
507         mVersionID = newVersionID;
508         mDataChanged = true;
509     }
510
511     public void setVersionStatus (int newVersionStatus) {
512         mVersionStatus = newVersionStatus;
513         mDataChanged = true;
514     }
515
516     public void setLanguageCode (String JavaDoc newLanguageCode) {
517         newLanguageCode = mLanguageCode;
518         mDataChanged = true;
519     }
520
521     public String JavaDoc toString () {
522         StringBuffer JavaDoc result = new StringBuffer JavaDoc ();
523         result.append ("JahiaPageInfo:\n");
524         result.append (" id =" + mID + "\n");
525         result.append (" siteID =" + mSiteID + "\n");
526         result.append (" parentID=" + mParentID + "\n");
527         result.append (" pageType=" + mPageType + "\n");
528         result.append (" title=" + mTitle + "\n");
529         result.append (" pageTemplateID=" + mPageTemplateID + "\n");
530         result.append (" remoteURL=" + mRemoteURL + "\n");
531         result.append (" pageLinkID=" + mPageLinkID + "\n");
532         result.append (" creator=" + mCreator + "\n");
533         result.append (" date of creation=" + mDoc + "\n");
534         result.append (" counter=" + mCounter + "\n");
535         result.append (" aclID=" + mAclID + "\n");
536         result.append (" versionID=" + mVersionID + "\n");
537         result.append (" versionStatus=" + mVersionStatus + "\n");
538         result.append (" languageCode=" + mLanguageCode + "\n");
539         return result.toString ();
540     }
541
542 } // end JahiaPage
543
Popular Tags