KickJava   Java API By Example, From Geeks To Geeks.

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


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

14 package org.jahia.services.pages;
15
16 import org.jahia.content.ContentObject;
17 import org.jahia.content.ContentPageXRefManager;
18 import org.jahia.exceptions.JahiaException;
19 import org.jahia.exceptions.JahiaTemplateNotFoundException;
20 import org.jahia.params.ParamBean;
21 import org.jahia.registries.ServicesRegistry;
22 import org.jahia.services.acl.ACLResourceInterface;
23 import org.jahia.services.acl.JahiaACLException;
24 import org.jahia.services.acl.JahiaBaseACL;
25 import org.jahia.services.cache.CacheFactory;
26 import org.jahia.services.cache.HtmlCache;
27 import org.jahia.services.sites.JahiaSite;
28 import org.jahia.services.usermanager.JahiaUser;
29 import org.jahia.services.usermanager.JahiaUserManagerService;
30 import org.jahia.services.version.ActivationTestResults;
31 import org.jahia.services.version.EntryLoadRequest;
32 import org.jahia.services.version.JahiaSaveVersion;
33 import org.jahia.services.version.StateModificationContext;
34 import org.jahia.utils.JahiaTools;
35
36 import java.util.*;
37 import java.io.Serializable JavaDoc;
38
39
40 /**
41  * <p>Title: Jahia Page</p>
42  * <p>Description: Represents a Jahia page for a specified language and
43  * version. This is strongly attached to the instance of the ParamBean
44  * object passed in the constructor. There can be multiple JahiaPage in memory
45  * at once, but only one ContentPage for all the languages and all the
46  * versions. </p>
47  * <p>Copyright: Copyright (c) 2002</p>
48  * <p>Company: </p>
49  *
50  * @author Eric Vassalli
51  * @author Fulco Houkes
52  * @author Serge Huber
53  * @version 2.0
54  */

55 public class JahiaPage implements PageInfoInterface, ACLResourceInterface, Comparator, Serializable JavaDoc {
56     private static org.apache.log4j.Logger logger =
57             org.apache.log4j.Logger.getLogger (JahiaPage.class);
58
59
60     // lock parameter names constants
61
private static final String JavaDoc LOCK_USER_PARAMETER = "user";
62     private static final String JavaDoc LOCK_PAGE_PARAMETER = "page";
63     private static final String JavaDoc LOCK_ENGINE_NAME_PARAMETER = "engineName";
64
65     // private JahiaPageInfo mPageInfo;
66
private ContentPage mContentPage = null;
67     private JahiaPageDefinition mPageTemplate;
68     private JahiaBaseACL mACL;
69     private EntryLoadRequest mEntryLoadRequest = null;
70
71     private JahiaPageDefinition mTempPageTemplate;
72     private Map mProperties = null;
73
74     private boolean declared = false;
75
76
77     //-------------------------------------------------------------------------
78
protected JahiaPage (ContentPage contentPage,
79                          JahiaPageDefinition pageTemplate,
80                          JahiaBaseACL acl,
81                          EntryLoadRequest loadRequest)
82             throws JahiaException {
83
84         mContentPage = contentPage;
85
86         mPageTemplate = pageTemplate;
87         mACL = acl;
88         mEntryLoadRequest = loadRequest;
89
90         // Coherence check here
91
// if the loadRequest is active, but the page exist only in staging
92
// ( for some reason, it was not actived ), so change the loadRequest to
93
// staging ohterwhise calls to getType(), getJahiaID() will fail !!!!
94
EntryLoadRequest newLoadRequest = loadRequest;
95         if (contentPage != null && !contentPage.hasActiveEntries ()
96                 && loadRequest != null && loadRequest.isCurrent ()) {
97             newLoadRequest =
98                     new EntryLoadRequest (EntryLoadRequest.STAGING_WORKFLOW_STATE,
99                             0, loadRequest.getLocales ());
100             newLoadRequest.setWithDeleted (loadRequest.isWithDeleted ());
101             newLoadRequest.setWithMarkedForDeletion (loadRequest.isWithMarkedForDeletion ());
102             mEntryLoadRequest = newLoadRequest;
103         }
104         if (mPageTemplate == null) {
105             // retrieve the staging
106
mPageTemplate = contentPage.getPageTemplate (newLoadRequest);
107         }
108
109         mTempPageTemplate = mPageTemplate;
110
111     }
112
113     /**
114      * Return the internal contentPage
115      *
116      * @return
117      */

118     public ContentPage getContentPage () {
119         return this.mContentPage;
120     }
121
122     //-------------------------------------------------------------------------
123
private boolean checkAccess (JahiaUser user, int permission, boolean checkChilds) {
124         if (user == null) {
125             return false;
126         }
127
128         // Test the access rights
129
boolean result = false;
130         try {
131             result = mACL.getPermission (user, permission);
132             if(!result && checkChilds) {
133                 List childs = getContentPage().getChilds(user, (EntryLoadRequest)null);
134                 for (int i = 0; i < childs.size() && !result; i++) {
135                     ContentObject contentObject = (ContentObject) childs.get(i);
136                     if(!(contentObject instanceof ContentPage))
137                     result = contentObject.checkAccess(user, permission,checkChilds);
138                 }
139             }
140         } catch (JahiaACLException ex) {
141             // if an error occured, just return false;
142
} catch (JahiaException ex) {
143             // if an error occured, just return false;
144
}
145
146         //if (!result) {
147
// logger.debug("Permission denied for user ["+user.getUsername()+"::"+
148
// user.getName()+"] to page ["+getID ()+
149
// "] for access permission ["+permission+"]");
150
//} else {
151
// logger.debug("Permission granted for user ["+user.getUsername()+"::"+
152
// user.getName()+"] to page ["+getID()+
153
// "] for access permission ["+permission+"]");
154
//}
155

156         return result;
157     }
158
159
160     //-------------------------------------------------------------------------
161
/**
162      * Check if the user has administration access on the specified page. Admin
163      * access means having the ability to add pages, containers and fields, but
164      * also giving rights to users to the different objects/applications in the
165      * specified page.
166      *
167      * @param user Reference to the user.
168      *
169      * @return Return true if the user has read access for the specified page,
170      * or false in any other case.
171      */

172     public final boolean checkAdminAccess (JahiaUser user) {
173         return checkAccess (user, JahiaBaseACL.ADMIN_RIGHTS, false);
174     }
175     
176     public final boolean checkAdminAccess (JahiaUser user,boolean checkChilds) {
177         return checkAccess (user, JahiaBaseACL.ADMIN_RIGHTS, checkChilds);
178     }
179
180
181     //-------------------------------------------------------------------------
182
/**
183      * Check if the user has read access on the specified page. Read access means
184      * having the rights to display and read the page.
185      *
186      * @param user Reference to the user.
187      *
188      * @return Return true if the user has read access for the specified page,
189      * or false in any other case.
190      */

191     public final boolean checkReadAccess (JahiaUser user) {
192         return checkAccess (user, JahiaBaseACL.READ_RIGHTS, false);
193     }
194
195
196     //-------------------------------------------------------------------------
197
/**
198      * Check if the user has Write access on the specified page. Write access means
199      * adding new pages, containers and fields in the specified page.
200      *
201      * @param user Reference to the user.
202      *
203      * @return Return true if the user has read access for the specified page,
204      * or false in any other case.
205      */

206     public final boolean checkWriteAccess (JahiaUser user) {
207         return checkAccess (user, JahiaBaseACL.WRITE_RIGHTS, false);
208     }
209
210     public final boolean checkWriteAccess (JahiaUser user,boolean checkChilds) {
211         return checkAccess (user, JahiaBaseACL.WRITE_RIGHTS,checkChilds);
212     }
213
214     //-------------------------------------------------------------------------
215
/**
216      * Check if the Guest user of a site has read access.
217      *
218      * @param siteID the site id.
219      *
220      * @return Return true if the site's guest user has read access for this page,
221      * or false in any other case.
222      */

223     public final boolean checkGuestAccess (int siteID) {
224         // get the User Manager service instance.
225
JahiaUserManagerService userMgr = ServicesRegistry.getInstance ().
226                 getJahiaUserManagerService ();
227         if (userMgr == null)
228             return false;
229
230         JahiaUser theUser = userMgr.lookupUser (siteID, JahiaUserManagerService.GUEST_USERNAME);
231         if (theUser == null)
232             return false;
233
234         return checkAccess (theUser, JahiaBaseACL.READ_RIGHTS, false);
235     }
236
237
238     //-------------------------------------------------------------------------
239
/**
240      * Commit the changes made in the page object to the database.
241      *
242      * @param flushCaches specifies whether we should flush all the caches
243      * corresponding to this page update (useful for example when we have
244      * modified a page title that will be display on multiple other pages).
245      *
246      * @throws JahiaException raised if there were problems either updating
247      * the persistant data or flushing the cache.
248      * @todo this is called even for a page counter update, can we avoid that
249      * in the future ?
250      */

251     public void commitChanges (boolean flushCaches)
252             throws JahiaException {
253         logger.debug ("called.");
254
255         if (flushCaches) {
256             // let's flush the cache of all the pages referencing this one.
257
int siteID = getJahiaID ();
258             JahiaSite site = ServicesRegistry.getInstance ().getJahiaSitesService ().getSite (
259                     siteID);
260             if (site == null) {
261                 logger.debug ("Invalid site for page, cannot flush cache.");
262             } else {
263                 Set refPages = ContentPageXRefManager.getInstance ().getPageIDs (getID ());
264                 Iterator refPagesIter = refPages.iterator ();
265
266                 // Get the cache instance and invalidate the related page entries
267
HtmlCache htmlCache = CacheFactory.getHtmlCache ();
268                 if (htmlCache == null)
269                     logger.warn ("Could not get the HTML cache instance!!");
270
271                 while (refPagesIter.hasNext ()) {
272                     Integer JavaDoc curPageID = (Integer JavaDoc) refPagesIter.next ();
273                     if (htmlCache != null)
274                         htmlCache.invalidatePageEntries (curPageID.toString ());
275                 }
276
277                 // let's flush this page's cache...
278
if (htmlCache != null)
279                     htmlCache.invalidatePageEntries (Integer.toString (getID ()));
280             }
281         }
282
283         mContentPage.commitChanges (flushCaches);
284         mPageTemplate = mTempPageTemplate;
285     }
286
287
288     //-------------------------------------------------------------------------
289
/**
290      * Return the page's ACL object.
291      *
292      * @return Return the page's ACL.
293      */

294     public final JahiaBaseACL getACL () {
295         return mACL;
296     }
297
298
299     //-------------------------------------------------------------------------
300
/**
301      * Return the ACL unique identification number.
302      *
303      * @return Return the ACL ID.
304      */

305     public final int getAclID () {
306         int id = -1;
307         try {
308             id = mACL.getID ();
309         } catch (JahiaACLException ex) {
310             // This exception should not happen ... :)
311
}
312         return id;
313     }
314
315
316     //-------------------------------------------------------------------------
317
/**
318      * Return the page's hit counter.
319      *
320      * @return Return the page counter.
321      */

322     public final int getCounter () {
323         return mContentPage.getCounter (mEntryLoadRequest);
324     }
325
326
327     //-------------------------------------------------------------------------
328
/**
329      * Return the user nickname who created the page. This nickname is the
330      * user name used internally by Jahia.
331      *
332      * @return Return the creator nickname.
333      */

334     public final String JavaDoc getCreator () {
335         return mContentPage.getCreator ();
336     }
337
338
339     //-------------------------------------------------------------------------
340
/**
341      * Return the page's date of creation in ms from 1975.
342      *
343      * @return Return the date of creation.
344      */

345     public final String JavaDoc getDoc () {
346         return mContentPage.getDoc ();
347     }
348
349
350     //-------------------------------------------------------------------------
351
/**
352      * Return the page's unique identification number.
353      *
354      * @return Return the page ID.
355      */

356     public final int getID () {
357         return mContentPage.getID ();
358     }
359
360
361     //-------------------------------------------------------------------------
362
/**
363      * Return the site ID in which the page is located.
364      *
365      * @return Return the page site ID.
366      */

367     public final int getJahiaID () {
368         return mContentPage.getJahiaID ();
369     }
370
371
372     //-------------------------------------------------------------------------
373
/**
374      * Return the reference on the page definition object.
375      *
376      * @return Return the page definition object.
377      */

378     public final JahiaPageDefinition getPageTemplate () {
379         return mPageTemplate;
380     }
381
382
383     //-------------------------------------------------------------------------
384
/**
385      * Return the page definition ID.
386      *
387      * @return Return the page definition ID.
388      */

389     public final int getPageTemplateID () {
390         return mContentPage.getPageTemplateID (mEntryLoadRequest);
391     }
392
393     //-------------------------------------------------------------------------
394
/**
395      * Return the internal jahia page ID in case the page is an internal
396      * jahia link.
397      *
398      * @return Return the page link ID.
399      */

400     public final int getPageLinkID () {
401         return mContentPage.getPageLinkID (mEntryLoadRequest);
402     }
403
404
405     //-------------------------------------------------------------------------
406
/**
407      * Return the page type
408      *
409      * @return Return the page type
410      */

411     public final int getPageType () {
412         return mContentPage.getPageType (mEntryLoadRequest);
413     }
414
415
416     //-------------------------------------------------------------------------
417
/**
418      * Return the parent page unique identification number.
419      *
420      * @return Return the parent page ID.
421      */

422     public final int getParentID () {
423         return mContentPage.getParentID (mEntryLoadRequest);
424     }
425
426
427     //-------------------------------------------------------------------------
428
/**
429      * Return the remote URL in case the page is an external reference (a non
430      * Jahia page. If the page is not an external URL, "<no url>" is returned.
431      *
432      * @return Return the remote URL.
433      */

434     public final String JavaDoc getRemoteURL () {
435         return mContentPage.getRemoteURL (mEntryLoadRequest);
436     }
437
438
439     //-------------------------------------------------------------------------
440
/**
441      * Return the page title.
442      *
443      * @return Return the page title.
444      */

445     public final String JavaDoc getTitle () {
446         return JahiaTools.text2html (mContentPage.getTitle (mEntryLoadRequest));
447     }
448
449
450     //-------------------------------------------------------------------------
451
/**
452      * Increment by one unit the page hit counter.
453      */

454     public final void incrementCounter () {
455         mContentPage.incrementCounter (mEntryLoadRequest);
456     }
457
458     //-------------------------------------------------------------------------
459
/**
460      * Set the new page defintion ID. The ID must point to a existing page
461      * definition.
462      *
463      * @param value The new page defintion ID.
464      *
465      * @throws JahiaException Throw this exception on any error. Only ERROR type error should
466      * be catched, all the other failures should be thrown further.
467      * @throws JahiaTemplateNotFoundException raised in case the template
468      * is not found.
469      */

470     public void setPageTemplateID (int value)
471             throws JahiaException, JahiaTemplateNotFoundException {
472         mContentPage.setPageTemplateID (value, mEntryLoadRequest);
473     }
474
475
476     //-------------------------------------------------------------------------
477
public void setPageTemplate (JahiaPageDefinition value)
478             throws JahiaTemplateNotFoundException, JahiaException {
479         mContentPage.setPageTemplate (value, mEntryLoadRequest);
480     }
481
482
483     //-------------------------------------------------------------------------
484
/**
485      * Set the new internal link ID. This ID must be an existing page ID.
486      *
487      * @param value The new page link ID.
488      */

489     public final void setPageLinkID (int value) {
490         mContentPage.setPageLinkID (value, mEntryLoadRequest);
491     }
492
493
494     //-------------------------------------------------------------------------
495
/**
496      * Change the page type. By changing this information, be aware to change
497      * also the according remote URL or page link ID information. See the
498      * methods {@link #setPageLinkID setPageLinkID()} and
499      * {@link #setRemoteURL setRemoteURL()}.
500      *
501      * @param value The new page type.
502      */

503     public final void setPageType (int value)
504             throws JahiaException {
505         mContentPage.setPageType (value, mEntryLoadRequest);
506     }
507
508
509     /**
510      * Set the ACL ID. Actually used when a page has change it's type. Passing from
511      * URL link or DIRECT page to a Jahia page LINK type and vice versa.
512      * WARNING ! Be careful with this method. Use it if it is really necessary
513      * to change the ACL ID page.
514      *
515      * @param aclID The ACL ID to set.
516      *
517      * @throws JahiaException
518      */

519     public final void setAclID (int aclID)
520             throws JahiaException {
521         mContentPage.setAclID (aclID, mEntryLoadRequest);
522     }
523
524     //-------------------------------------------------------------------------
525
/**
526      * Set the new remote URL. The page type will change accordingly.
527      *
528      * @param value The new remoteURL.
529      */

530     public final void setRemoteURL (String JavaDoc value)
531             throws JahiaException {
532         mContentPage.setRemoteURL (value, mEntryLoadRequest);
533     }
534
535
536     //-------------------------------------------------------------------------
537
/**
538      * Change the page title.
539      *
540      * @param value String holding the new page title.
541      */

542     public final void setTitle (String JavaDoc value) {
543         mContentPage.setTitle (value, mEntryLoadRequest);
544     }
545
546     //--------------------------------------------------------------------------
547
/**
548      * Set the titles for a set of languages
549      *
550      * @param languageCode
551      * @param title
552      */

553     public final void setTitle (String JavaDoc languageCode, String JavaDoc title)
554             throws JahiaException {
555         mContentPage.setTitle (languageCode, title, mEntryLoadRequest);
556     }
557
558     //--------------------------------------------------------------------------
559
/**
560      * Set the titles for a set of languages
561      *
562      * @param languagesSet a set of languages as String for which to set the title.
563      * @param titles hashtable of key/value pair ( languageCode/title value )
564      */

565     public final void setTitles (Set languagesSet, Hashtable titles)
566             throws JahiaException {
567         mContentPage.setTitles (languagesSet, titles, mEntryLoadRequest);
568     }
569
570     //-------------------------------------------------------------------------
571
/**
572      * Return the page URL
573      * for backward compatibility.
574      *
575      * @return Return the page URL string.
576      *
577      * @deprecated please use the getURL() instead in order to comply to
578      * Sun's conventions
579      */

580     public String JavaDoc getUrl (ParamBean jParams)
581             throws JahiaException {
582         return getURL (jParams);
583     } // end getUrl
584

585
586     //-------------------------------------------------------------------------
587
/**
588      * Return the page URL
589      *
590      * @return Return the page URL string.
591      */

592     public String JavaDoc getURL (ParamBean jParams)
593             throws JahiaException {
594         String JavaDoc outURL = "";
595         switch (getPageType ()) {
596             case (TYPE_DIRECT):
597                 if (jParams != null) {
598                     outURL = jParams.composePageUrl (getID ());
599                 }
600                 break;
601
602             case (TYPE_LINK):
603                 if (jParams != null) {
604                     int linkPageID = -1;
605                     try {
606                         linkPageID = getPageLinkID ();
607                         if (linkPageID != -1) {
608                             ContentPage linkPage = ContentPage.getPage (linkPageID, false);
609                             // require at least read access
610
if (linkPage.checkReadAccess (jParams.getUser ())) {
611                                 outURL = jParams.composePageUrl (linkPageID);
612                             } else {
613                                 //logger.debug("No read access to linked page [" + linkPageID + "]");
614
}
615                         }
616                     } catch (Throwable JavaDoc t) {
617                         logger.debug (
618                                 "Exception creating link url with page[" + linkPageID + "]", t);
619                     }
620                 }
621                 break;
622             case (TYPE_URL):
623                 outURL = getRemoteURL ();
624                 break;
625         }
626         return outURL;
627     } // end getURL
628

629
630
631     //-------------------------------------------------------------------------
632
/**
633      * Return the page path. The page path consist of all the parent pages of
634      * the specified page until the site's root page.
635      *
636      * @return Return a enumeration of JahiaPage objects. The returned
637      * Enumeration is always non-null, but might have no pages if the
638      * specified page has not childs, or if no childs matching the
639      * loading flag were found.
640      *
641      * @deprecated used getContentPagePath
642      */

643     public Enumeration getPagePath (String JavaDoc operationMode, JahiaUser user)
644             throws JahiaException {
645         Vector thePath = ServicesRegistry.getInstance ().getJahiaPageService ().getPagePath (getID (), mEntryLoadRequest, operationMode,
646                 user);
647         if (thePath != null) {
648             return thePath.elements ();
649         }
650         return null;
651     } // end getPath
652

653     //-------------------------------------------------------------------------
654
/**
655      * Return the page path. The page path consist of all the parent pages of
656      * the specified page until the site's root page.
657      *
658      * @return Return a enumeration of JahiaPage objects. The returned
659      * Enumeration is always non-null, but might have no pages if the
660      * specified page has not childs, or if no childs matching the
661      * loading flag were found.
662      */

663     public Enumeration getContentPagePath (String JavaDoc operationMode, JahiaUser user)
664             throws JahiaException {
665         Vector thePath = ServicesRegistry.getInstance ().getJahiaPageService ().getContentPagePath (getID (), mEntryLoadRequest,
666                 operationMode, user);
667         if (thePath != null) {
668             return thePath.elements ();
669         }
670         return null;
671     } // end getPath
672

673     //-------------------------------------------------------------------------
674
/**
675      * Return the page path. The page path consist of all the parent pages of
676      * the specified page until the site's root page.
677      *
678      * @param levels an integer specifying the offset of levels to retrieve.
679      * So if the page is a depth level 5 and we specify that we want to retrieve
680      * only 2 levels, only levels 4 and 5 will be returned by this method.
681      *
682      * @return Return a enumeration of JahiaPage objects. The returned
683      * Enumeration is always non-null, but might have no pages if the
684      * specified page has not childs, or if no childs matching the
685      * loading flag were found.
686      *
687      * @deprecated use getContentPagePath
688      */

689     public Enumeration getPagePath (int levels, String JavaDoc operationMode, JahiaUser user)
690             throws JahiaException {
691         Vector thePath = ServicesRegistry.getInstance ().getJahiaPageService ().getPagePath (getID (), mEntryLoadRequest, operationMode,
692                 user);
693         if (thePath != null) {
694             int fromIndex = 0;
695             if ((thePath.size () - levels) > 0) {
696                 fromIndex = thePath.size () - levels;
697             }
698             List theShortPathList = thePath.subList (fromIndex, thePath.size ());
699             Vector theShortPathVector = new Vector (theShortPathList);
700 // Vector theShortPath = new Vector();
701
// for (int i = (thePath.size() - levels); i < thePath.size(); i++) {
702
// theShortPath.add(thePath.get(i));
703
// }
704
return theShortPathVector.elements ();
705         }
706         return null;
707     } // end getPath
708

709     //-------------------------------------------------------------------------
710
/**
711      * Return the page path. The page path consist of all the parent pages of
712      * the specified page until the site's root page.
713      *
714      * @param levels an integer specifying the offset of levels to retrieve.
715      * So if the page is a depth level 5 and we specify that we want to retrieve
716      * only 2 levels, only levels 4 and 5 will be returned by this method.
717      *
718      * @return Return a enumeration of ContentPage objects. The returned
719      * Enumeration is always non-null, but might have no pages if the
720      * specified page has not childs, or if no childs matching the
721      * loading flag were found.
722      */

723     public Enumeration getContentPagePath (int levels, String JavaDoc operationMode, JahiaUser user)
724             throws JahiaException {
725         Vector thePath = ServicesRegistry.getInstance ().getJahiaPageService ().getContentPagePath (getID (), mEntryLoadRequest,
726                 operationMode, user);
727         if (thePath != null) {
728             int fromIndex = 0;
729             if ((thePath.size () - levels) > 0) {
730                 fromIndex = thePath.size () - levels;
731             }
732             List theShortPathList = thePath.subList (fromIndex, thePath.size ());
733             Vector theShortPathVector = new Vector (theShortPathList);
734             return theShortPathVector.elements ();
735         }
736         return null;
737     } // end getPath
738

739
740     //-------------------------------------------------------------------------
741
/**
742      * Return an enumeration holding all the child pages of the specified page.
743      * The loading flag filters the kind of pages to return.
744      *
745      * @return Return an Enumeration of JahiaPage objects. Return null if not
746      * the current page has not childs.
747      *
748      * @throws JahiaException Return this exception if any failure occured.
749      */

750     public Enumeration getChilds ()
751             throws JahiaException {
752         Vector childs = ServicesRegistry.getInstance ().getJahiaPageService ().getPageChilds (getID (), PageLoadFlags.ALL,
753                 mEntryLoadRequest);
754         if (childs != null) {
755             return childs.elements ();
756         }
757         return null;
758     } // end getChilds
759

760     public Enumeration getChilds (JahiaUser user)
761             throws JahiaException {
762         Vector childs = ServicesRegistry.getInstance ().getJahiaPageService ().getPageChilds (getID (), PageLoadFlags.ALL, user);
763         // logger.debug("Nb child found " + childs.size());
764
if (childs != null) {
765             return childs.elements ();
766         }
767         return null;
768     } // end getChilds
769

770     //-------------------------------------------------------------------------
771
/**
772      * Compare between two objects, sort by their name
773      *
774      * @param c1 left-side object
775      * @param c2 right-side object
776      *
777      * @return <0 if c1 < c2, 0 if c1=c2, >0 if c1>c2
778      *
779      * @throws ClassCastException if the objects where not of type JahiaPage.
780      */

781     public int compare (Object JavaDoc c1, Object JavaDoc c2) throws ClassCastException JavaDoc {
782
783         return ((JahiaPage) c1)
784                 .getTitle ().toLowerCase ()
785                 .compareTo (((JahiaPage) c2).getTitle ().toLowerCase ());
786
787     }
788
789
790     //-------------------------------------------------------------------------
791
public String JavaDoc toString () {
792         StringBuffer JavaDoc output = new StringBuffer JavaDoc ();
793         output.append ("Detail of page [");
794         output.append (getID ());
795         output.append ("] :\n");
796         output.append (" - Site ID [");
797         output.append (getJahiaID ());
798         output.append ("]\n");
799         output.append (" - Parent ID [");
800         output.append (getParentID ());
801         output.append ("]\n");
802         output.append (" - Type [");
803         output.append (PAGE_TYPE_NAMES[getPageType ()]);
804         output.append ("]\n");
805         output.append (" - Ttitle [");
806         output.append (getTitle ());
807         output.append ("]\n");
808         output.append (" - Template ID [");
809         output.append (getPageTemplateID ());
810         output.append ("]\n");
811         output.append (" - Remote URL [");
812         output.append (getRemoteURL ());
813         output.append ("]\n");
814         output.append (" - Link ID [");
815         output.append (getPageLinkID ());
816         output.append ("]\n");
817         output.append (" - Creator [");
818         output.append (getCreator ());
819         output.append ("]\n");
820         output.append (" - Creation date [");
821         output.append (getDoc ());
822         output.append ("]\n");
823         output.append (" - Counter [");
824         output.append (getCounter ());
825         output.append ("]\n");
826         output.append (" - ACL ID [");
827         output.append (getAclID ());
828         output.append ("]\n");
829         output.append (" - EntryLoadRequest=" + mEntryLoadRequest + "\n");
830
831         return output.toString ();
832     }
833
834     private boolean checkPropertiesAvailability ()
835             throws JahiaException {
836         if (mProperties == null) {
837             // properties never yet loaded, let's do it as quickly as we can.
838
mProperties = PagePropertyDB.getInstance ().getPageProperties (getID ());
839         }
840         if (mProperties == null) {
841             logger.debug ("Error while loading page properties !");
842             return false;
843         }
844         return true;
845     }
846
847
848     /**
849      * Retrieves a page's local property by name
850      *
851      * @param name a String containing the name of the page property to
852      * return.
853      *
854      * @return the PageProperty if it could be found for this page, or null
855      * if not found.
856      *
857      * @throws JahiaException raised if there was a problem accessing the
858      * backend systems that contain the properties
859      */

860     public PageProperty getPageLocalProperty (String JavaDoc name)
861             throws JahiaException {
862         if (checkPropertiesAvailability ()) {
863             PageProperty prop = (PageProperty) mProperties.get (name);
864             return prop;
865         } else {
866             logger.debug ("Error accessing page property " + name +
867                     " probably doesn't exist yet...");
868             return null;
869         }
870     }
871
872     /**
873      * Retrieves a page property value. If the property couldn't be found for
874      * this page, and that this page has a parent, this method will go up
875      * the page hierarchy to look for this property. This method retrieves the
876      * default value for a property, ignoring multi-language values if they
877      * exist.
878      *
879      * @param name a String containing the name of the page property to
880      * return.
881      *
882      * @return a String containing the value of the page property or null if
883      * the property couldn't be found.
884      *
885      * @throws JahiaException raised if there was a problem accessing the
886      * backend systems that contain the properties
887      */

888     public String JavaDoc getProperty (String JavaDoc name)
889             throws JahiaException {
890         PageProperty curProp = getPageLocalProperty (name);
891         if (curProp != null) {
892             return curProp.getValue ();
893         } else {
894             // we could find it locally, let's try to find it in the parent if
895
// this object has one.
896
if (getParentID () > 0) {
897                 // we are not in the case of the root page or a page without
898
// a parent
899
JahiaPage parentPage = ServicesRegistry.getInstance ().getJahiaPageService ().lookupPage (getParentID (),
900                         mEntryLoadRequest);
901                 if (parentPage != null) {
902                     // let's recursively look for the property in parent
903
// pages
904
return parentPage.getProperty (name);
905                 }
906             }
907             return null;
908         }
909     }
910
911     /**
912      * Retrieves the page property value corresponding to the specified
913      * language code. If the property is not defined for this page, this
914      * method will try to walk up the page hierarchy to find it.
915      *
916      * @param name the name of the property to retrieve
917      * @param languageCode the RFC 3066 language code for which to retrieve
918      * the page property value
919      *
920      * @return a String containing the property value for the given language OR
921      * the default value if it couldn't be found.
922      *
923      * @throws JahiaException raised if there was a problem accessing the
924      * backend systems that contain the properties
925      */

926     public String JavaDoc getProperty (String JavaDoc name, String JavaDoc languageCode)
927             throws JahiaException {
928         PageProperty curProp = getPageLocalProperty (name);
929         if (curProp != null) {
930             return curProp.getValue (languageCode);
931         } else {
932             // we could find it locally, let's try to find it in the parent if
933
// this object has one.
934
if (getParentID () > 0) {
935                 // we are not in the case of the root page or a page without
936
// a parent
937
JahiaPage parentPage = ServicesRegistry.getInstance ().getJahiaPageService ().lookupPage (getParentID (),
938                         mEntryLoadRequest);
939                 if (parentPage != null) {
940                     // let's recursively look for the property in parent
941
// pages
942
return parentPage.getProperty (name, languageCode);
943                 }
944             }
945             return null;
946         }
947     }
948
949     /**
950      * Sets a page property value. This updates both the in-memory and
951      * persistant systems simultaneously so it might have a performance
952      * impact. This sets the default value of the property.
953      *
954      * @param name the name of the page property to be set
955      * @param value the value of the page property
956      *
957      * @throws JahiaException raised if there was a problem accessing the
958      * backend systems that contain the properties
959      */

960     public void setProperty (String JavaDoc name, String JavaDoc value)
961             throws JahiaException {
962         PagePropertyDB.getInstance ().setPageProperty (getID(), name, value);
963     }
964
965     /**
966      * Sets a page property value. This updates both the in-memory and
967      * persistant systems simultaneously so it might have a performance
968      * impact. This sets the value for a given language code of the page
969      * property
970      *
971      * @param name the name of the page property to be set
972      * @param languageCode the RFC 3066 language code for which to store
973      * the property value.
974      * @param value the value of the page property
975      *
976      * @throws JahiaException raised if there was a problem accessing the
977      * backend systems that contain the properties
978      */

979     public void setProperty (String JavaDoc name, String JavaDoc languageCode, String JavaDoc value)
980             throws JahiaException {
981         PagePropertyDB.getInstance ().setPageProperty (getID(), name, languageCode, value);
982     }
983
984     /**
985      * Remove a property. This updates both the in-memory and
986      * persistant systems simultaneously so it might have a performance
987      * impact.
988      *
989      * @param name the name of the page property to be removed
990      *
991      * @throws JahiaException raised if there was a problem accessing the
992      * backend systems that contain the properties
993      */

994     public void removeProperty (String JavaDoc name)
995             throws JahiaException {
996         PageProperty targetProperty = null;
997         if (mProperties != null) {
998             targetProperty = getPageLocalProperty(name);
999             if (targetProperty != null) {
1000                mProperties.remove(name);
1001                PagePropertyDB.getInstance().removePageProperty(targetProperty);
1002            }
1003        }
1004    }
1005
1006    /**
1007     * The purpose of this method is to "activate" all the data that is in the
1008     * staging state. This destroys all internal staging versions so make sure
1009     * you call this only when really ready to active. For changing staging
1010     * status use the other method : changeStagingStatus also in this class.
1011     *
1012     * @param saveVersion the version save information needed in the case we
1013     * validate the page's content.
1014     * @param user the user making the activation
1015     * @param withContent if true it means we activate the content of the page,
1016     * not just the page entry.
1017     *
1018     * @throws JahiaException in the case there is an error while validating
1019     * the page's content (if withContent=true of course)
1020     */

1021    public ActivationTestResults activeStagingVersion (
1022            Set languageCodes,
1023            JahiaSaveVersion saveVersion,
1024            JahiaUser user,
1025            ParamBean jParams,
1026            StateModificationContext stateModifContext)
1027            throws JahiaException {
1028        /** @todo FIXME add null checks here ! */
1029        boolean versioningActive = ServicesRegistry.getInstance ().getJahiaVersionService ()
1030                .isVersioningEnabled (jParams.getSiteID ());
1031        return mContentPage.activeStagingEntries (languageCodes, versioningActive, saveVersion,
1032                user, jParams, stateModifContext);
1033    }
1034
1035    /**
1036     * Tests if a page is valid for activation.
1037     *
1038     * @param versioningActive
1039     * @param saveVersion
1040     * @param user
1041     * @param jParams
1042     * @param withSubPages
1043     *
1044     * @return an ActivationTestResults object that contains the status of
1045     * the activation tests, including error and warning messages.
1046     *
1047     * @throws JahiaException
1048     */

1049    public ActivationTestResults isValidForActivation (
1050            Set languageCodes,
1051            JahiaSaveVersion saveVersion,
1052            JahiaUser user,
1053            ParamBean jParams,
1054            StateModificationContext stateModifContext)
1055            throws JahiaException {
1056        boolean versioningActive = ServicesRegistry.getInstance ().getJahiaVersionService ()
1057                .isVersioningEnabled (jParams.getSiteID ());
1058        return mContentPage.isValidForActivation (languageCodes, versioningActive, saveVersion,
1059                user, jParams, stateModifContext);
1060    }
1061
1062    /**
1063     * Changes the status of the staging page infos. This is used to switch
1064     * to another status, before going to active status. No versioning is
1065     * done during a staging status change.
1066     *
1067     * @param newVersionStatus the new status mode. This must be bigger or
1068     * equal to JahiaLoadVersion.STAGING, otherwise this method will exist
1069     * immediately.
1070     */

1071    public void changeStagingStatus (Set languageCodes, int newVersionStatus,
1072                                     ParamBean jParams,
1073                                     StateModificationContext stateModifContext)
1074            throws JahiaException {
1075        mContentPage.changeStagingStatus (languageCodes, newVersionStatus,
1076                jParams, stateModifContext);
1077    }
1078
1079    /**
1080     * Returns true if the page has active entries
1081     *
1082     * @return true if the page has at least an active state. false if there
1083     * are only staged entries.
1084     */

1085    public boolean hasActiveEntries () {
1086        return mContentPage.hasActiveEntries ();
1087    }
1088
1089    /**
1090     * Return true if the page has specified 'pageInfos' entries in the specified
1091     * language.
1092     *
1093     * @param pageInfosFlag Kind of page infos desired. This parameter can associate
1094     * the previous constants. For example ACTIVE_PAGE_INFOS | STAGING_PAGE_INFOS
1095     * look for both active and staged pages and return the appropriate result.
1096     * @param languageCode The specified language code.
1097     *
1098     * @return True if it is at least one entry for this page.
1099     */

1100    public boolean hasEntry (int pageInfosFlag, String JavaDoc languageCode) {
1101        return mContentPage.hasEntries (pageInfosFlag, languageCode);
1102    }
1103
1104    public Map getLanguagesStates (boolean withContent) {
1105        return mContentPage.getLanguagesStates (withContent);
1106    }
1107
1108}
1109
Popular Tags