KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jahia > gui > GuiBean


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
// GuiBean
14
// EV 03.11.2000
15
// DJ 02.02.2001 - added ACL check for link display
16
// JB 16.05.2001
17
//
18

19 package org.jahia.gui;
20
21 import java.util.Enumeration JavaDoc;
22
23 import javax.servlet.http.HttpServletRequest JavaDoc;
24
25 import org.jahia.bin.Jahia;
26 import org.jahia.content.ContentObject;
27 import org.jahia.data.containers.JahiaContainer;
28 import org.jahia.data.containers.JahiaContainerList;
29 import org.jahia.data.containers.JahiaContainerListPagination;
30 import org.jahia.data.fields.JahiaField;
31 import org.jahia.data.fields.LoadFlags;
32 import org.jahia.engines.JahiaEngine;
33 import org.jahia.engines.containerlistproperties.ContainerListProperties_Engine;
34 import org.jahia.exceptions.JahiaException;
35 import org.jahia.params.ParamBean;
36 import org.jahia.registries.EnginesRegistry;
37 import org.jahia.registries.ServicesRegistry;
38 import org.jahia.services.acl.ACLResource;
39 import org.jahia.services.acl.ACLResourceInterface;
40 import org.jahia.services.containers.ContentContainer;
41 import org.jahia.services.containers.ContentContainerList;
42 import org.jahia.services.fields.ContentField;
43 import org.jahia.services.lock.LockKey;
44 import org.jahia.services.pages.ContentPage;
45 import org.jahia.services.pages.JahiaPage;
46 import org.jahia.services.pages.JahiaPageDefinition;
47 import org.jahia.services.pages.JahiaPageService;
48 import org.jahia.services.usermanager.JahiaUser;
49 import org.jahia.utils.JahiaTools;
50
51 public class GuiBean {
52
53     private static org.apache.log4j.Logger logger =
54         org.apache.log4j.Logger.getLogger(GuiBean.class);
55
56     private ParamBean jParams;
57     private HTMLToolBox html;
58     private JahiaUser currentUser;
59     private JahiaPage thePage;
60
61
62     /***
63         * constructor
64         * EV 03.11.2000
65         *
66         */

67     public GuiBean( ParamBean jahiaParams )
68     {
69         this.jParams = jahiaParams;
70         this.html = new HTMLToolBox( this, jParams );
71         this.currentUser = jahiaParams.getUser();
72         this.thePage = jahiaParams.getPage();
73     } // end constructor
74

75
76     /***
77         * html
78         * EV 15.12.2000
79         *
80         */

81     public HTMLToolBox html()
82     {
83         return html;
84     } // end constructor
85

86
87
88     /***
89         * drawHttpPath
90         * EV 21.11.2000
91         *
92         */

93     public String JavaDoc drawHttpPath()
94     {
95         if (jParams != null) {
96             return jParams.settings().getJahiaTemplatesHttpPath();
97         } else {
98             return "";
99         }
100     } // end drawHttpPath
101

102
103     /***
104         * drawHttpPath
105         * JB 25.04.2001
106         *
107         */

108     public String JavaDoc drawHttpPath(String JavaDoc theTemplateFolderName)
109     {
110         if (jParams != null) {
111             return jParams.settings().getJahiaTemplatesHttpPath() + theTemplateFolderName;
112         } else {
113             return "";
114         }
115     } // end drawHttpPath
116

117
118     //-------------------------------------------------------------------------
119
/**
120      */

121     public String JavaDoc drawHttpJspContext (HttpServletRequest JavaDoc req){
122
123         StringBuffer JavaDoc path = new StringBuffer JavaDoc();
124         path.append(req.getRequestURI().substring(0,req.getRequestURI().lastIndexOf("/")));
125         return path.toString();
126     }
127
128     /***
129         * drawPageLink
130         * EV 21.11.2000
131         *
132         */

133     public String JavaDoc drawPageLink(int thePageID)
134     throws JahiaException
135     {
136         String JavaDoc result = "";
137
138         if (jParams != null) {
139             // Get the current page
140
JahiaPage currentPage = jParams.getPage();
141             if (currentPage != null) {
142                 result = jParams.composePageUrl(thePageID, jParams.getLocale().toString());
143             }
144         }
145         return result;
146     } // end drawPageLink
147

148
149     /**
150      * EV 21.11.2000
151      *
152      */

153     public String JavaDoc drawSwitchModeLink()
154     throws JahiaException
155     {
156         String JavaDoc result = "";
157
158         if (jParams != null) {
159             // Get the current page
160
JahiaPage currentPage = jParams.getPage();
161             if (currentPage != null) {
162                 // Check the write permission on the page
163
if (currentPage.checkWriteAccess (jParams.getUser())) {
164                     if (jParams.getOperationMode().equals( ParamBean.NORMAL )
165                         || jParams.getOperationMode().equals( ParamBean.COMPARE )) {
166                         result = jParams.composeOperationUrl( ParamBean.EDIT, "" );
167                     } else {
168                         result = jParams.composeOperationUrl( ParamBean.NORMAL, "" );
169                     }
170                 }
171             }
172         }
173         return result;
174     } // end drawSwitchModeLink
175

176     /**
177      * Builds an URL to the current page in view mode
178      * @return
179      * @throws JahiaException
180      */

181     public String JavaDoc drawNormalModeLink()
182     throws JahiaException
183     {
184         String JavaDoc result = "";
185
186         if (jParams != null) {
187             // Get the current page
188
JahiaPage currentPage = jParams.getPage();
189             if (currentPage != null) {
190                 // Check the write permission on the page
191
result = jParams.composeOperationUrl( ParamBean.NORMAL, "" );
192             }
193         }
194         return result;
195     }
196
197     /**
198      * Builds an URL to the current page in edit mode, only if the current
199      * user has that right. If not an empty string is returned.
200      * @return The URL to the current page in edit mode
201      * @throws JahiaException
202      */

203     public String JavaDoc drawEditModeLink()
204       throws JahiaException
205     {
206         String JavaDoc result = "";
207
208         if (jParams != null) {
209             // Get the current page
210
JahiaPage currentPage = jParams.getPage();
211 // ISM: access check must be done in ParamBean.composeOperationUrl()
212
if (currentPage != null)
213                 result = jParams.composeOperationUrl(ParamBean.EDIT, "");
214         }
215         return result;
216     }
217
218     /**
219      * Builds an URL to the current page in edit mode, only if the current
220      * user has that right. If not an empty string is returned.
221      *
222      * @param revisionDiffID, 0 to compare with staging.
223      * @param operationMode
224      * @return
225      * @throws JahiaException
226      */

227     public String JavaDoc drawRevDifferenceModeLink(int revisionDiffID, String JavaDoc operationMode)
228     throws JahiaException
229     {
230         String JavaDoc result = "";
231
232         // FIXME : work only with EDIT MODE !
233
//String opMode = ParamBean.EDIT;
234
String JavaDoc opMode = operationMode;
235
236         if (jParams != null) {
237             // Get the current page
238
JahiaPage currentPage = jParams.getPage();
239             if (currentPage != null) {
240                 /* NK : EDIT_MODE_PAGE_ACCESS_ISSUE */
241                 // Check the write permission on the page
242
if (currentPage.checkWriteAccess (jParams.getUser())
243                   || currentPage.checkAdminAccess (jParams.getUser())) {
244                     result = jParams.composeRevDifferenceUrl(revisionDiffID,opMode,"");
245                 } else {
246                     result = "";
247                 }
248                 //result = jParams.composeRevDifferenceUrl(revisionDiffID,opMode,"");
249
}
250         }
251         return result;
252     }
253
254     /**
255      * Builds an URL to the current page in staging preview mode, only if
256      * the current user has that right. If not an empty string is returned.
257      * @return
258      * @throws JahiaException
259      */

260     public String JavaDoc drawPreviewModeLink()
261     throws JahiaException
262     {
263         String JavaDoc result = "";
264
265         if (jParams != null) {
266             // Get the current page
267
JahiaPage currentPage = jParams.getPage();
268             if (currentPage != null)
269             {
270               /* NK : EDIT_MODE_PAGE_ACCESS_ISSUE */
271               // ISM: check must be done in ParamBean.composeOperationUrl()!
272
result = jParams.composeOperationUrl( ParamBean.PREVIEW, "" );
273             }
274         }
275         return result;
276     }
277
278     /**
279      * Build an URL containing the language code the displayed page should
280      * switch to.
281      *
282      * @param code The iso639 language code
283      * @return The URL string composed
284      * @throws JahiaException
285      */

286     public String JavaDoc drawPageLanguageSwitch(String JavaDoc code)
287             throws JahiaException {
288
289         String JavaDoc result = "";
290         if (jParams != null) {
291             // Get the current page
292
JahiaPage currentPage = jParams.getPage();
293             if (currentPage != null) {
294                 result = jParams.composeLanguageURL(code);
295             }
296         }
297         return result;
298     }
299
300
301     public String JavaDoc drawPopupLoginUrl()
302     throws JahiaException
303     { return drawUrl( "login", "/pid/" + jParams.getPageID() ); }
304
305     public String JavaDoc drawPopupLoginUrl( int destinationPageID )
306     throws JahiaException
307     { return drawUrl( "login", "/pid/" + destinationPageID ); }
308
309     public String JavaDoc drawLoginUrl()
310     throws JahiaException
311     { return drawUrl( "login", "/pid/" + jParams.getPageID() + "?screen=save" ); }
312
313     public String JavaDoc drawLoginUrl( int destinationPageID )
314     throws JahiaException
315     { return drawUrl( "login", "/pid/" + destinationPageID + "?screen=save" ); }
316     // end drawLoginUrl
317

318
319     // this draw logout is called by the other ones too
320
public String JavaDoc drawPopupLogoutUrl( int destinationPageID )
321     throws JahiaException
322     {
323         String JavaDoc result = "";
324         if ( jParams.getUser().getUsername()!= "guest" )
325         {
326             result = drawUrl( "logout", new Integer JavaDoc(destinationPageID) );
327         }
328         return result;
329     }
330
331     public String JavaDoc drawPopupLogoutUrl()
332     throws JahiaException
333     { return drawPopupLogoutUrl( jParams.getPageID() ); }
334
335     public String JavaDoc drawLogoutUrl( int destinationPageID )
336     throws JahiaException
337     { return drawPopupLogoutUrl( destinationPageID ); }
338     // end drawLogoutUrl
339

340     public String JavaDoc drawLogoutUrl()
341     throws JahiaException
342     { return drawPopupLogoutUrl( jParams.getPageID() ); }
343
344     /**
345      *
346      * @param theField
347      * @return
348      * @throws JahiaException
349      * @deprecated
350      */

351     public String JavaDoc drawUpdateFieldUrl( JahiaField theField )
352             throws JahiaException {
353         ContentField contentField = theField.getContentField();
354         return drawUrlCheckWriteAccess( "updatefield", contentField );
355     }
356
357     /**
358      *
359      * @param contentField
360      * @return
361      * @throws JahiaException
362      */

363     public String JavaDoc drawUpdateFieldUrl(ContentField contentField)
364             throws JahiaException {
365         return drawUrlCheckWriteAccess("updatefield", contentField);
366     }
367
368     /**
369      *
370      * @param contentContainerList
371      * @return
372      * @throws JahiaException
373      */

374     public String JavaDoc drawAddContainerUrl(JahiaContainerList jahiaContainerList )
375             throws JahiaException {
376         if (jahiaContainerList != null) {
377             return drawUrlCheckWriteAccess( "addcontainer", jahiaContainerList );
378         } else {
379             JahiaException je = new JahiaException( "Accessing non-existing data",
380                 "GuiBean : Trying to access to non-existing containerlist (addContainerUrl)",
381                 JahiaException.DATA_ERROR, JahiaException.WARNING_SEVERITY );
382             logger.warn("Trying to generate URL for null container list", je);
383             return "";
384         }
385     }
386
387     /**
388      *
389      * @param theContainer
390      * @return
391      * @throws JahiaException
392      * @deprecated
393      */

394     public String JavaDoc drawUpdateContainerUrl( JahiaContainer theContainer )
395             throws JahiaException {
396         ContentContainer contentContainer = theContainer.getContentContainer();
397         return drawUrlCheckWriteAccess( "updatecontainer", contentContainer );
398     }
399
400     /**
401      *
402      * @param contentContainer
403      * @return
404      * @throws JahiaException
405      */

406     public String JavaDoc drawUpdateContainerUrl(ContentContainer contentContainer)
407             throws JahiaException {
408         return drawUrlCheckWriteAccess( "updatecontainer", contentContainer );
409     }
410
411
412     /**
413      *
414      * @param theContainer
415      * @return
416      * @throws JahiaException
417      * @deprecated
418      */

419     public String JavaDoc drawDeleteContainerUrl( JahiaContainer theContainer )
420             throws JahiaException {
421          ContentContainer contentContainer = theContainer.getContentContainer();
422         return drawUrlCheckWriteAccess( "deletecontainer", contentContainer);
423     }
424
425     /**
426      *
427      * @param contentContainer
428      * @return
429      * @throws JahiaException
430      */

431     public String JavaDoc drawDeleteContainerUrl(ContentContainer contentContainer)
432             throws JahiaException {
433         return drawUrlCheckWriteAccess( "deletecontainer", contentContainer);
434     }
435
436     public String JavaDoc drawWorkflowUrl()
437         throws JahiaException {
438
439         return drawUrl("workflow", jParams.getPage());
440     }
441
442     public String JavaDoc drawLockUrl(LockKey lockKey)
443             throws JahiaException {
444         return drawUrl("lock", lockKey);
445     }
446
447     public String JavaDoc drawPagePropertiesUrl()
448     throws JahiaException { return drawUrl( "pageproperties", jParams.getPage() ); }
449
450     public String JavaDoc drawUpdateTemplateUrl( JahiaPageDefinition theTemplate )
451     throws JahiaException
452     {
453         return drawUrlCheckWriteAccess( "template", theTemplate );
454     }
455
456     /**
457      *
458      * @param theContainerList
459      * @return
460      * @throws JahiaException
461      * @deprecated
462      */

463     public String JavaDoc drawContainerListPropertiesUrl( JahiaContainerList theContainerList )
464             throws JahiaException {
465         ContentContainerList contentContainerList = theContainerList.getContentContainerList();
466         return drawUrlCheckWriteAccess( "containerlistproperties", contentContainerList );
467     }
468
469     /**
470      *
471      * @param contentContainerList
472      * @return
473      * @throws JahiaException
474      */

475     public String JavaDoc drawContainerListPropertiesUrl(ContentContainerList contentContainerList)
476             throws JahiaException {
477         if (contentContainerList != null) {
478             return drawUrlCheckWriteAccess("containerlistproperties",
479                                            contentContainerList);
480         } else {
481             return "";
482         }
483     }
484
485     /**
486      * Generates an URL for a NEXT WINDOW on a containerlist.
487      *
488      * @param theContainerList the containerList for which to generate the URL
489      * @param pageStep the number of pages to skip through.
490      * @param newWindowSize the size of the window (optional). -1 to keep
491      * current window size.
492      * @param boolean scrollingValueOnly if true, return only the scrolling
493      * value , i.e. '5_10' , instead of the full url.
494      *
495      * @return the URL for the operation specified.
496      *
497      * @throws JahiaException on error accessing containerList definitions either
498      * in memory or in the database.
499      * @author Serge Huber
500      */

501     public String JavaDoc drawContainerListNextWindowPageURL( JahiaContainerList theContainerList,
502                                                 int pageStep,
503                                                 int newWindowSize,
504                                                 boolean scrollingValueOnly )
505
506     throws JahiaException {
507         return drawContainerListWindowPageURL( theContainerList, pageStep,
508                                                newWindowSize,
509                                                scrollingValueOnly);
510     }
511
512     /**
513      * Generates an URL for a PREVIOUS WINDOW on a containerlist.
514      *
515      * @param theContainerList the containerList for which to generate the URL
516      * @param pageStep the number of pages to skip through.
517      * @param newWindowSize the size of the window (optional). -1 to keep
518      * current window size.
519      * @param boolean scrollingValueOnly if true, return only the scrolling
520      * value , i.e. '5_10' , instead of the full url.
521      *
522      * @return the URL for the operation specified.
523      *
524      * @throws JahiaException on error accessing containerList definitions either
525      * in memory or in the database.
526      * @author Serge Huber
527      */

528     public String JavaDoc drawContainerListPreviousWindowPageURL ( JahiaContainerList theContainerList,
529                                                      int pageStep,
530                                                      int newWindowSize,
531                                                      boolean scrollingValueOnly )
532     throws JahiaException {
533         return drawContainerListWindowPageURL( theContainerList, -pageStep,
534                                                newWindowSize,
535                                                scrollingValueOnly);
536     }
537
538     /**
539      * Generates an URL that allows navigation within a scrollable container
540      * list.
541      *
542      * @param theContainerList the containerList for which to generate the URL
543      * @param pageStep the number of pages to switch, this may be positive or
544      * negative, going both ways.
545      * @param windowSize the size of the window, optional (set to -1 if deactivated).
546      * @param boolean scrollingValueOnly if true, return only the scrolling value,
547      * i.e. '5_10' , instead of the full url.
548      *
549      * @return the URL generated for this operation. Size and offset are correct
550      * to match containerList size.
551      *
552      * @throws JahiaException on error accessing containerList definitions either
553      * in memory or in the database.
554      * @author Serge Huber
555      */

556     public String JavaDoc drawContainerListWindowPageURL ( JahiaContainerList theContainerList,
557                                                    int pageStep,
558                                                    int newWindowSize,
559                                                    boolean scrollingValueOnly )
560     throws JahiaException {
561
562         if ( theContainerList == null ){
563             return null;
564         }
565
566         JahiaContainerListPagination cListPagination = theContainerList.getCtnListPagination();
567         if ( cListPagination == null || cListPagination.getWindowSize()!=newWindowSize )
568         {
569             cListPagination = new JahiaContainerListPagination(theContainerList,jParams, newWindowSize);
570             theContainerList.setCtnListPagination(cListPagination);
571         }
572
573         // For next & previous button check
574
if ( !cListPagination.isValid() || (cListPagination.getNbPages()<2) ){
575             // feature is deactivated.
576
return null;
577         }
578
579         // For previous button check
580
if ( (cListPagination.getCurrentPageIndex()==1) && (pageStep<0) ){
581             // feature is deactivated.
582
return null;
583         }
584
585         // For next button check
586
int nextPage = cListPagination.getCurrentPageIndex()+1;
587         if ( (nextPage>cListPagination.getNbPages()) && (pageStep>0) ){
588             // feature is deactivated.
589
return null;
590         }
591
592         int windowSize = cListPagination.getWindowSize();
593         int windowOffset = cListPagination.getWindowOffset();
594         windowOffset += pageStep * windowSize;
595
596         // we now have all the correct values, let's build the URL...
597
String JavaDoc paramName = "ctnscroll_" + theContainerList.getDefinition().getName();
598         String JavaDoc paramValue = Integer.toString(windowSize) + "_" +
599                             Integer.toString(windowOffset);
600
601         if ( scrollingValueOnly ){
602             return paramValue;
603         }
604
605         /** @todo this is really ugly... let's remember to clean it up... */
606         String JavaDoc cacheStatus = jParams.getCacheStatus();
607         jParams.setCacheStatus(ParamBean.CACHE_OFFONCE);
608         String JavaDoc curPageURL = jParams.composePageUrl(jParams.getPageID(), jParams.getLocale().toString());
609         jParams.setCacheStatus(cacheStatus);
610         curPageURL += "/" + paramName + "/" + paramValue;
611         return curPageURL;
612     }
613
614     /**
615      * Generates an URL that allows navigation within a scrollable container
616      * list.
617      *
618      * @param JahiaContainerList the container list with a valid JahiaContainerListPagination bean.
619      * @param int pageStep must be bigger than 0.
620      * @param boolean scrollingValueOnly if true, return only the scrolling value , i.e. '5_10' , instead of the full url.
621      *
622      * @return the URL generated for this operation.
623      *
624      * @throws JahiaException on error accessing containerList definitions either
625      * in memory or in the database.
626      * @author NK
627      */

628     public String JavaDoc drawContainerListWindowPageURL ( JahiaContainerList containerList,
629                                                    int pageStep,
630                                                    boolean scrollingValueOnly )
631
632     throws JahiaException {
633
634         if ( containerList == null || containerList.getCtnListPagination()== null ||
635              !containerList.getCtnListPagination().isValid() || (pageStep <= 0) ){
636             return null;
637         }
638
639         String JavaDoc paramName = "ctnscroll_" + containerList.getDefinition().getName();
640         String JavaDoc paramValue = Integer.toString(containerList.getCtnListPagination().getWindowSize()) + "_" +
641                             Integer.toString((pageStep-1)*containerList.getCtnListPagination().getWindowSize());
642
643         if ( scrollingValueOnly ){
644             return paramValue;
645         }
646
647         /** @todo this is really ugly... let's remember to clean it up... */
648         String JavaDoc cacheStatus = jParams.getCacheStatus();
649         jParams.setCacheStatus(ParamBean.CACHE_OFFONCE);
650         String JavaDoc curPageURL = jParams.composePageUrl(jParams.getPageID(), jParams.getLocale().toString());
651         jParams.setCacheStatus(cacheStatus);
652         curPageURL += "/" + paramName + "/" + paramValue;
653         return curPageURL;
654     }
655
656     public String JavaDoc drawSearchUrl()
657     throws JahiaException { return drawUrl( "search", null ); }
658     // end drawSearchUrl
659

660     public String JavaDoc drawMySettingsUrl () throws JahiaException {
661         return drawUrl ("mysettings", null);
662     }
663     
664     public String JavaDoc drawMySettingsUrl(Object JavaDoc theObj) throws JahiaException
665     {
666       return drawUrl("mysettings", theObj);
667     }
668
669     public String JavaDoc drawNewUserRegistrationUrl () throws JahiaException {
670         return drawUrl("newuserregistration", null);
671     }
672
673     public String JavaDoc drawNewUserRegistrationUrl(Object JavaDoc theObj)
674       throws JahiaException
675     {
676       return drawUrl("newuserregistration", theObj);
677     }
678     
679     public String JavaDoc drawSiteMapUrl()
680     throws JahiaException { return drawUrl( "sitemap", null ); }
681     // end drawSiteMapUrl
682

683     /***
684         * drawAdministrationLauncher
685         * MJ 21.03.2001
686         *
687         */

688     public String JavaDoc drawAdministrationLauncher()
689     throws JahiaException {
690
691         return jParams.getResponse().encodeURL(jParams.getRequest().getContextPath() + Jahia.getInitAdminServletPath() + "?do=passthru");
692
693     }
694     // end drawAdministrationLauncher
695

696
697     /***
698         * drawUrl
699         * EV 15.12.2000
700         *
701         */

702     private String JavaDoc drawUrl( String JavaDoc engineName, Object JavaDoc theObj )
703     throws JahiaException
704     {
705         String JavaDoc htmlResult = "";
706         JahiaEngine theEngine = (JahiaEngine) EnginesRegistry.getInstance().getEngine( engineName );
707         if (theEngine.authoriseRender(jParams)) {
708             htmlResult = theEngine.renderLink( jParams, theObj );
709         }
710         return htmlResult;
711     }
712     // end drawUrl
713

714     private String JavaDoc drawUrlCheckWriteAccess(String JavaDoc engineName, Object JavaDoc anObject)
715             throws JahiaException {
716         JahiaEngine theEngine = (JahiaEngine) EnginesRegistry.getInstance().getEngine(engineName);
717         if (theEngine.authoriseRender(jParams)) {
718            if (anObject instanceof ContentObject) {
719                ContentObject contentObject = (ContentObject)anObject;
720                if (contentObject.checkWriteAccess(currentUser)) {
721                    return theEngine.renderLink( jParams, anObject );
722                }
723            } else if (anObject instanceof ACLResourceInterface) {
724                if (ACLResource.checkWriteAccess((ACLResourceInterface)anObject,currentUser)) {
725                    return theEngine.renderLink( jParams, anObject );
726                }
727            } else if (anObject instanceof JahiaContainerList) {
728                // this is mostly used to generate the add container URL when
729
// a container list doesn't yet exist (created at the same time
730
// as the first container).
731
JahiaContainerList containerList = (JahiaContainerList)anObject;
732                if (engineName.equals(ContainerListProperties_Engine.ENGINE_NAME) ){
733                    if (containerList.getID() == 0 && jParams.getPage().checkAdminAccess(currentUser)
734                        || containerList.getID() != 0 && containerList.checkWriteAccess(currentUser) ) {
735                        return theEngine.renderLink( jParams, anObject );
736                    }
737                } else {
738                    // Add Container
739
boolean hasWriteAccess = false;
740                  if (containerList.getID() != 0)
741                    hasWriteAccess = containerList.checkWriteAccess(currentUser);
742                  else
743                  {
744                    int parentId = containerList.getParentEntryID();
745                    if (parentId != 0)
746                    {
747                      JahiaContainer parent = ServicesRegistry.getInstance()
748                        .getJahiaContainersService().loadContainer(
749                          parentId, LoadFlags.ALL, jParams,
750                          jParams.getEntryLoadRequest());
751                      if (parent != null)
752                        hasWriteAccess = parent.checkWriteAccess(currentUser);
753                      else
754                        parentId = 0;
755                    }
756                    if (parentId == 0)
757                    {
758                      hasWriteAccess = jParams.getPage().checkWriteAccess(
759                        currentUser);
760                    }
761                  }
762                  if (hasWriteAccess)
763                    return theEngine.renderLink(jParams, anObject);
764                }
765            }
766
767         }
768         return "";
769     }
770
771     /***
772         * drawUsername
773         * JB 25.04.2001
774         *
775         */

776     public String JavaDoc drawUsername()
777     {
778         if (jParams != null) {
779             return currentUser.getUsername();
780         } else {
781             return "";
782         }
783     } // end drawUsername
784

785
786     /**
787      * JB 25.04.2001
788      */

789     public boolean isEditMode()
790     {
791         if (jParams != null) {
792             return jParams.getOperationMode().equals(ParamBean.EDIT);
793         } else {
794             return false;
795         }
796     } // end isEditMode
797

798     public boolean isNormalMode()
799     {
800         if (jParams != null) {
801             return jParams.getOperationMode().equals(ParamBean.NORMAL);
802         } else {
803             return false;
804         }
805     }
806
807     public boolean isCompareMode()
808     {
809         if (jParams != null) {
810             return jParams.getOperationMode().equals(ParamBean.COMPARE);
811         } else {
812             return false;
813         }
814     }
815
816     public boolean isPreviewMode()
817     {
818         if (jParams != null) {
819             return jParams.getOperationMode().equals(ParamBean.PREVIEW);
820         } else {
821             return false;
822         }
823     }
824
825     /***
826         * isLogged
827         * JB 25.04.2001
828         *
829         */

830     public boolean isLogged()
831     {
832         if (jParams != null) {
833             /* EP : 2004-17-06 : change the test to avoid null pointer exception */
834             if (!"guest".equals(currentUser.getUsername())) {
835                 return true;
836             } else {
837                 return false;
838             }
839         } else {
840             return false;
841         }
842     } // end isLogged
843

844
845     /***
846         * isPageInPath
847         * JB 25.04.2001
848         *
849         */

850     public boolean isPageInPath( int destPageID )
851     throws JahiaException
852     {
853         if (jParams != null) {
854             Enumeration JavaDoc thePath = thePage.getContentPagePath(jParams.getOperationMode(), currentUser);
855             while (thePath.hasMoreElements()) {
856                 ContentPage aPage = (ContentPage) thePath.nextElement();
857                 if (aPage.getID() == destPageID) {
858                     return true;
859                 }
860             }
861         }
862         return false;
863     } // end isPageInPath
864

865
866     /***
867         * isPageInPath
868         * JB 25.04.2001
869         *
870         */

871     public boolean isPageInPath( int destPageID, int levels )
872     throws JahiaException
873     {
874         if (jParams != null) {
875             Enumeration JavaDoc thePath = thePage.getContentPagePath(levels, jParams.getOperationMode(), currentUser);
876             while (thePath.hasMoreElements()) {
877                 ContentPage aPage = (ContentPage) thePath.nextElement();
878                 if (aPage.getID() == destPageID) {
879                     return true;
880                 }
881             }
882         }
883         return false;
884     } // end isPageInPath
885

886
887     /***
888         * isNS
889         * JB 16.05.2001
890         *
891         */

892     public boolean isNS(HttpServletRequest JavaDoc req)
893     {
894         String JavaDoc userAgent = req.getHeader( "user-agent" );
895         if (userAgent != null) {
896             if (userAgent.indexOf( "Mozilla" ) != -1) {
897                 if (userAgent.indexOf( "MSIE" ) == -1) {
898                     return true;
899                 }
900             }
901         }
902         return false;
903     } // end isNS
904

905
906     /***
907         * isNS4
908         * JB 16.05.2001
909         *
910         */

911     public boolean isNS4(HttpServletRequest JavaDoc req)
912     {
913         String JavaDoc userAgent = req.getHeader( "user-agent" );
914         if (userAgent != null) {
915             if (userAgent.indexOf( "Mozilla/4" ) != -1) {
916                 if (userAgent.indexOf( "MSIE" ) == -1) {
917                     return true;
918                 }
919             }
920         }
921         return false;
922     } // end isNS4
923

924
925     /***
926         * isNS6
927         * JB 16.05.2001
928         *
929         */

930     public boolean isNS6(HttpServletRequest JavaDoc req)
931     {
932         String JavaDoc userAgent = req.getHeader( "user-agent" );
933         if (userAgent != null) {
934             if (userAgent.indexOf( "Mozilla/5" ) != -1) {
935                 return true;
936             }
937         }
938         return false;
939     } // end isNS6
940

941
942     /***
943         * isIE
944         * JB 16.05.2001
945         *
946         */

947     public boolean isIE(HttpServletRequest JavaDoc req)
948     {
949         String JavaDoc userAgent = req.getHeader( "user-agent" );
950         if (userAgent != null) {
951             if (userAgent.indexOf( "MSIE" ) != -1) {
952                 return true;
953             }
954         }
955         return false;
956     } // end isIE
957

958
959     /***
960         * isIE4
961         * JB 16.05.2001
962         *
963         */

964     public boolean isIE4(HttpServletRequest JavaDoc req)
965     {
966         String JavaDoc userAgent = req.getHeader( "user-agent" );
967         if (userAgent != null) {
968             if (userAgent.indexOf( "MSIE 4" ) != -1) {
969                 return true;
970             }
971         }
972         return false;
973     } // end isIE4
974

975
976     /***
977         * isIE5
978         * JB 16.05.2001
979         *
980         */

981     public boolean isIE5(HttpServletRequest JavaDoc req)
982     {
983         String JavaDoc userAgent = req.getHeader( "user-agent" );
984         if (userAgent != null) {
985             if (userAgent.indexOf( "MSIE 5" ) != -1) {
986                 return true;
987             }
988         }
989         return false;
990     } // end isIE5
991

992
993     /***
994         * isIE6
995         * JB 16.05.2001
996         *
997         */

998     public boolean isIE6(HttpServletRequest JavaDoc req)
999     {
1000        String JavaDoc userAgent = req.getHeader( "user-agent" );
1001        if (userAgent != null) {
1002            if (userAgent.indexOf( "MSIE 6" ) != -1) {
1003                return true;
1004            }
1005        }
1006        return false;
1007    } // end isIE6
1008

1009    /***
1010     * isIE6
1011     * JB 16.05.2001
1012     *
1013     */

1014   public boolean isIE7(HttpServletRequest JavaDoc req)
1015   {
1016       String JavaDoc userAgent = req.getHeader( "user-agent" );
1017       if (userAgent != null) {
1018           if (userAgent.indexOf( "MSIE 7" ) != -1) {
1019               return true;
1020           }
1021       }
1022       return false;
1023   } // end isIE7
1024

1025    
1026    /***
1027     * isOpera
1028     *
1029     */

1030     public boolean isOpera(HttpServletRequest JavaDoc req)
1031     {
1032         String JavaDoc userAgent = req.getHeader( "user-agent" );
1033         if (userAgent != null) {
1034             userAgent = userAgent.toLowerCase();
1035             if (userAgent.indexOf( "opera" ) != -1) {
1036                 return true;
1037             }
1038         }
1039         return false;
1040     } // end isOpera
1041

1042    /***
1043        * isWindow
1044        * JB 13.11.2001
1045        *
1046        */

1047    public boolean isWindow(HttpServletRequest JavaDoc req)
1048    {
1049        String JavaDoc userAgent = req.getHeader( "user-agent" );
1050        if (userAgent != null) {
1051            if (userAgent.indexOf( "Win" ) != -1) {
1052                return true;
1053            }
1054        }
1055        return false;
1056    } // end isWindow
1057

1058
1059    /***
1060        * isUnix
1061        * JB 13.11.2001
1062        *
1063        */

1064    public boolean isUnix(HttpServletRequest JavaDoc req)
1065    {
1066        String JavaDoc userAgent = req.getHeader( "user-agent" );
1067        if (userAgent != null) {
1068            if (userAgent.indexOf( "X11" ) != -1) {
1069                return true;
1070            }
1071        }
1072        return false;
1073    } // end isUnix
1074

1075
1076    /***
1077        * isMac
1078        * JB 13.11.2001
1079        *
1080        */

1081    public boolean isMac(HttpServletRequest JavaDoc req)
1082    {
1083        String JavaDoc userAgent = req.getHeader( "user-agent" );
1084        if (userAgent != null) {
1085            if (userAgent.indexOf( "Mac" ) != -1) {
1086                return true;
1087            }
1088        }
1089        return false;
1090    } // end isMac
1091

1092
1093    /***
1094        * checkWriteAccess
1095        * JB 25.04.2001
1096        *
1097        */

1098    public boolean checkWriteAccess()
1099    {
1100        if (thePage.checkWriteAccess( currentUser )) {
1101            return true;
1102        }
1103        return false;
1104    } // end checkWriteAccess
1105

1106    /**
1107     * Cuts and prepares a String for display at a specified length, by
1108     * appending "..." characters at the end and then replacing all the space
1109     * characters with "&nbsp;" characters, and finally encoding the string for
1110     * HTML output (by replacing all non ISO-8859-1 characters with &#XX;
1111     * encoding).
1112     *
1113     * @param in the String to cut and prepare for output.
1114     * @param len the length at which to cut it. If the string is shorter than
1115     * the length then the string will be returned unmodified.
1116     *
1117     * @return the cut string with "..." at the end if it was cut, and encoded
1118     * for HTML output.
1119     *
1120     * @author JB 25.04.2001, PV 18.06.2001 bug fix
1121     */

1122    public static String JavaDoc glueTitle( String JavaDoc in, int len )
1123    {
1124        if (in == null){
1125            return null;
1126        }
1127        in = JahiaTools.html2text(in);
1128        if ( (in.length()) > len && (len > 2)) {
1129            in = in.substring( 0, len - 3 ) + "...";
1130        }
1131        in = JahiaTools.replacePattern(in," ","&nbsp;");
1132        in = JahiaTools.text2html(in);
1133        return in;
1134    } // end glueTitle
1135

1136
1137    /**
1138     * Returns the page ID of the page that is at the specific level in the
1139     * page page of the current page. So if we have the following path :
1140     * page1 -> page2 -> page3 (current page)
1141     *
1142     * level 0 = -1 (too low, will always return -1)
1143     * level 1 = page1 (root page ID)
1144     * level 2 = page2
1145     * level 3 = page3
1146     * level 4 = -1 (doesn't exist)
1147     *
1148     * @param level the offset from the root page, specifying the number of
1149     * levels to go down in the tree, 1-based.
1150     * @return an integer specifying the page ID of the desired level in the
1151     * page path, or -1 if level was too big.
1152     * @throws JahiaException thrown if we have trouble retrieving the page's
1153     * path.
1154     * @author JB 25.04.2001
1155     */

1156    public int getLevelID( int level )
1157    throws JahiaException
1158    {
1159        Enumeration JavaDoc thePath = thePage.getContentPagePath(jParams.getOperationMode(), currentUser);
1160        int count_loop = 0;
1161        while (thePath.hasMoreElements()) {
1162           ContentPage aPage = (ContentPage) thePath.nextElement();
1163           count_loop++;
1164           if (count_loop == (level)) {
1165               return aPage.getID();
1166           }
1167        }
1168        return -1;
1169    } // end getLevelID
1170

1171
1172    /**
1173     * Returns the depth of the current page.
1174     * @return an integer specifying the depth in the page tree of the current
1175     * page, or -1 in the case of an error.
1176     * @throws JahiaException thrown if we had trouble retrieving the page's
1177     * path.
1178     * @author JB 25.04.2001
1179     */

1180    public int getLevel()
1181    throws JahiaException
1182    {
1183        Enumeration JavaDoc thePath = thePage.getContentPagePath(jParams.getOperationMode(), this.currentUser);
1184        int count_loop = 0;
1185        while (thePath.hasMoreElements()) {
1186           ContentPage aPage = (ContentPage) thePath.nextElement();
1187           count_loop++;
1188           if (aPage.getID() == thePage.getID()) {
1189               return count_loop;
1190           }
1191        }
1192        return -1;
1193    } // end getLevel
1194

1195
1196    /***
1197     * getHomePage, return the site's home page
1198     * @deprecated, use getContentHomePage
1199     */

1200    public JahiaPage getHomePage()
1201    throws JahiaException
1202    {
1203        if ( jParams.getSite() == null )
1204            return null;
1205
1206        JahiaPageService pageService = ServicesRegistry.getInstance().getJahiaPageService();
1207
1208        // finds origin page
1209
JahiaPage originPage = pageService.lookupPage(jParams.getSite().getHomePageID()
1210                ,jParams.getEntryLoadRequest(),jParams.getOperationMode(),jParams.getUser(),false);
1211
1212        return originPage;
1213
1214    } // end getHomePage
1215

1216    /***
1217     * getHomePage, return the site's home page as ContentPage
1218     */

1219    public ContentPage getContentHomePage()
1220    throws JahiaException
1221    {
1222        if ( jParams.getSite() == null )
1223            return null;
1224        return ContentPage.getPage(jParams.getSite().getHomePageID());
1225
1226    } // end getHomePage
1227

1228} // end GuiBean
1229
Popular Tags