KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > opencms > workplace > CmsWorkplaceSettings


1 /*
2  * File : $Source: /usr/local/cvs/opencms/src/org/opencms/workplace/CmsWorkplaceSettings.java,v $
3  * Date : $Date: 2006/03/27 14:52:43 $
4  * Version: $Revision: 1.57 $
5  *
6  * This library is part of OpenCms -
7  * the Open Source Content Mananagement System
8  *
9  * Copyright (c) 2005 Alkacon Software GmbH (http://www.alkacon.com)
10  *
11  * This library is free software; you can redistribute it and/or
12  * modify it under the terms of the GNU Lesser General Public
13  * License as published by the Free Software Foundation; either
14  * version 2.1 of the License, or (at your option) any later version.
15  *
16  * This library is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19  * Lesser General Public License for more details.
20  *
21  * For further information about Alkacon Software GmbH, please see the
22  * company website: http://www.alkacon.com
23  *
24  * For further information about OpenCms, please see the
25  * project website: http://www.opencms.org
26  *
27  * You should have received a copy of the GNU Lesser General Public
28  * License along with this library; if not, write to the Free Software
29  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
30  */

31
32 package org.opencms.workplace;
33
34 import org.opencms.db.CmsPublishList;
35 import org.opencms.db.CmsUserSettings;
36 import org.opencms.file.CmsResource;
37 import org.opencms.file.CmsUser;
38 import org.opencms.file.collectors.I_CmsResourceCollector;
39 import org.opencms.i18n.CmsMessageContainer;
40 import org.opencms.main.OpenCms;
41 import org.opencms.workplace.explorer.CmsExplorer;
42 import org.opencms.workplace.tools.CmsToolUserData;
43
44 import java.util.HashMap JavaDoc;
45 import java.util.Map JavaDoc;
46
47 /**
48  * Object to conveniently access and modify the state of the workplace for a user,
49  * will be stored in the session of a user.<p>
50  *
51  * @author Alexander Kandzior
52  *
53  * @version $Revision: 1.57 $
54  *
55  * @since 6.0.0
56  */

57 public class CmsWorkplaceSettings {
58
59     private I_CmsResourceCollector m_collector;
60     private String JavaDoc m_currentSite;
61     private Object JavaDoc m_dialogObject;
62     private CmsMessageContainer m_errorMessage;
63     private String JavaDoc m_explorerFlaturl;
64     private String JavaDoc m_explorerMode;
65     private int m_explorerPage;
66     private String JavaDoc m_explorerProjectFilter;
67     private int m_explorerProjectId;
68     private Map JavaDoc m_explorerResource;
69     private boolean m_explorerShowLinks;
70     private Map JavaDoc m_frameUris;
71     private String JavaDoc m_galleryType;
72     private Map JavaDoc m_lastUsedGalleries;
73     private Object JavaDoc m_listObject;
74     private String JavaDoc m_permissionDetailView;
75     private int m_project;
76     private CmsPublishList m_publishList;
77     private Map JavaDoc m_resourceTypes;
78     private CmsToolUserData m_toolUserData;
79     private Map JavaDoc m_treeSite;
80     private Map JavaDoc m_treeType;
81     private CmsUser m_user;
82     private CmsUserSettings m_userSettings;
83     private String JavaDoc m_viewStartup;
84     private String JavaDoc m_viewUri;
85
86     /**
87      * Constructor, only package visible.<p>
88      */

89     CmsWorkplaceSettings() {
90
91         m_explorerPage = 1;
92         m_explorerResource = new HashMap JavaDoc();
93         m_treeType = new HashMap JavaDoc();
94         m_treeSite = new HashMap JavaDoc();
95         m_resourceTypes = new HashMap JavaDoc();
96         m_frameUris = new HashMap JavaDoc();
97         m_lastUsedGalleries = new HashMap JavaDoc();
98         m_currentSite = OpenCms.getSiteManager().getDefaultSite().getSiteRoot();
99     }
100
101     /**
102      * Returns the collector object.<p>
103      *
104      * Use this mechanism for transferring a resource collector between
105      * several page instances of an interactive dialog. <p>
106      *
107      * @return the dialog object
108      */

109     public I_CmsResourceCollector getCollector() {
110
111         return m_collector;
112     }
113
114     /**
115      * Returns the dialog object.<p>
116      *
117      * Use this mechanism for transferring a complex object between
118      * several page instances of an interactive dialog. This is usually
119      * required when editing a complex object in a dialog of the "Administration" view.<p>
120      *
121      * @return the dialog object
122      */

123     public Object JavaDoc getDialogObject() {
124
125         return m_dialogObject;
126     }
127
128     /**
129      * Returns the error message to display in the workplace.<p>
130      *
131      * @return the error message to display in the workplace
132      */

133     public CmsMessageContainer getErrorMessage() {
134
135         return m_errorMessage;
136     }
137
138     /**
139      * Returns the explorer flat url.<p>
140      *
141      * @return the explorer flat url
142      */

143     public String JavaDoc getExplorerFlaturl() {
144
145         return m_explorerFlaturl;
146     }
147
148     /**
149      * Returns the current explorer mode.<p>
150      *
151      * @return the current explorer mode
152      */

153     public String JavaDoc getExplorerMode() {
154
155         return m_explorerMode;
156     }
157
158     /**
159      * Returns the currently selected page in the explorer view.<p>
160      *
161      * @return the currently selected page in the explorer view
162      */

163     public int getExplorerPage() {
164
165         return m_explorerPage;
166     }
167
168     /**
169      * Gets the explorer project filter for the project view.<p>
170      *
171      * This parameter is used in the administration to filter
172      * files belonging to a project.
173      *
174      * @return the explorer project filter
175      */

176     public String JavaDoc getExplorerProjectFilter() {
177
178         return m_explorerProjectFilter;
179     }
180
181     /**
182      * Gets the explorer project id for the project view.<p>
183      *
184      * This parameter is used in the administration to filter
185      * files belonging to a selected project.
186      *
187      * @return the explorer project id
188      */

189     public int getExplorerProjectId() {
190
191         return m_explorerProjectId;
192     }
193
194     /**
195      * Returns the current resource to be displayed in the explorer.<p>
196      *
197      * @return the current resource to be displayed in the explorer
198      */

199     public String JavaDoc getExplorerResource() {
200
201         // get the current explorer mode
202
String JavaDoc mode = getExplorerMode();
203         if (mode == null) {
204             mode = CmsExplorer.VIEW_EXPLORER;
205         }
206         if (CmsExplorer.VIEW_EXPLORER.equals(mode)) {
207             // append the current site to the key when in explorer view mode
208
mode += "_" + getSite() + "/";
209         }
210         // get the resource for the given mode
211
String JavaDoc resource = (String JavaDoc)m_explorerResource.get(mode);
212         if (resource == null) {
213             resource = "/";
214         }
215         return resource;
216     }
217
218     /**
219      * Returns if the explorer should show VFS links of a resource.<p>
220      *
221      * @return true, if VFS links should be shown, otherwise false
222      */

223     public boolean getExplorerShowLinks() {
224
225         return m_explorerShowLinks;
226     }
227
228     /**
229      * Returns the frame URIs of the currently loaded frameset, with the frame names as keys.<p>
230      *
231      * @return the frame URIs of the currently loaded frameset
232      */

233     public Map JavaDoc getFrameUris() {
234
235         return m_frameUris;
236     }
237
238     /**
239      * Returns the current gallery type name.<p>
240      *
241      * @return the current gallery type name
242      */

243     public String JavaDoc getGalleryType() {
244
245         return m_galleryType;
246     }
247
248     /**
249      * Returns the last saved gallery for the given gallery type id.<p>
250      *
251      * @param galleryTypeId the type id of the gallery
252      * @return the last saved gallery for the given gallery type id
253      */

254     public String JavaDoc getLastUsedGallery(int galleryTypeId) {
255
256         return (String JavaDoc)m_lastUsedGalleries.get(String.valueOf(galleryTypeId));
257     }
258
259     /**
260      * Returns the list dialog object.<p>
261      *
262      * Use this mechanism for transfering a html list object between
263      * several page instances of an interactive dialog. This is usually
264      * required when having several lists in a tool or when a list action
265      * another list displays of the "Administration" view.<p>
266      *
267      * @return the dialog object
268      *
269      * @see org.opencms.workplace.list.A_CmsListDialog#getListObject(Class, CmsWorkplaceSettings)
270      */

271     public Object JavaDoc getListObject() {
272
273         return m_listObject;
274     }
275
276     /**
277      * Returns the current detail grade of the view.<p>
278      *
279      * @return value of the details.
280      */

281     public String JavaDoc getPermissionDetailView() {
282
283         return m_permissionDetailView;
284     }
285
286     /**
287      * Returns the currently selected project of the workplace user.<p>
288      *
289      * @return the currently selected project of the workplace user
290      */

291     public int getProject() {
292
293         return m_project;
294     }
295
296     /**
297      * Returns the publish list.<p>
298      *
299      * @return the publishList
300      */

301     public CmsPublishList getPublishList() {
302
303         return m_publishList;
304     }
305
306     /**
307      * Returns a Map with all visible resource types for the current user, with the IDs as key values.<p>
308      *
309      * @return Map with all visible resource types
310      */

311     public Map JavaDoc getResourceTypes() {
312
313         return m_resourceTypes;
314     }
315
316     /**
317      * Returns the current site for the user.<p>
318      *
319      * @return the current site for the user
320      */

321     public String JavaDoc getSite() {
322
323         return m_currentSite;
324     }
325
326     /**
327      * Returns the new admin view tool User Data.<p>
328      *
329      * @return the tool User Data
330      */

331     public CmsToolUserData getToolUserData() {
332
333         return m_toolUserData;
334     }
335
336     /**
337      * Returns the tree resource uri for the specified tree type.<p>
338      *
339      * @param type the type of the tree
340      * @return the tree resource uri for the specified tree type
341      */

342     public String JavaDoc getTreeResource(String JavaDoc type) {
343
344         String JavaDoc result = (String JavaDoc)m_treeType.get(type);
345         if (result == null) {
346             result = "/";
347         }
348         return result;
349     }
350
351     /**
352      * Returns the tree site uri for the specified tree type.<p>
353      *
354      * @param type the type of the tree
355      * @return the tree site uri for the specified tree type
356      */

357     public String JavaDoc getTreeSite(String JavaDoc type) {
358
359         String JavaDoc result = (String JavaDoc)m_treeSite.get(type);
360         return result;
361     }
362
363     /**
364      * Returns the current workplace user.<p>
365      *
366      * @return the current workplace user
367      */

368     public CmsUser getUser() {
369
370         return m_user;
371     }
372
373     /**
374      * Returns the current workplace user settings object.<p>
375      *
376      * @return the current workplace user settings object
377      */

378     public CmsUserSettings getUserSettings() {
379
380         return m_userSettings;
381     }
382
383     /**
384      * Returns the view startup page.<p>
385      *
386      * The view startup page can be used to directly load a specific workplace dialog or other workplace resource in the
387      * OpenCms workplace base frameset after the user logs in.<p>
388      *
389      * @return the view startup page
390      */

391     public String JavaDoc getViewStartup() {
392
393         return m_viewStartup;
394     }
395
396     /**
397      * Returns the current view Uri selected in the workplace.<p>
398      *
399      * @return the current view Uri selected in the workplace
400      */

401     public String JavaDoc getViewUri() {
402
403         return m_viewUri;
404     }
405
406     /**
407      * Checks if the current view is the administration view.<p>
408      *
409      * @return true if the current view is the administration view, otherwise false
410      */

411     public boolean isViewAdministration() {
412
413         return (getViewUri().endsWith("/system/workplace/action/administration.html") || getViewUri().endsWith(
414             "/system/workplace/action/tasks.html"));
415     }
416
417     /**
418      * Checks if the current view is the explorer view.<p>
419      *
420      * @return true if the current view is the explorer view, otherwise false
421      */

422     public boolean isViewExplorer() {
423
424         return getViewUri().endsWith(CmsWorkplace.FILE_EXPLORER_FILELIST);
425     }
426
427     /**
428      * Sets the collector object.<p>
429      *
430      * Use this mechanism for transferring a resource collector between
431      * several page instances of an interactive dialog.<p>
432      *
433      * @param collector the dialog object to set
434      */

435     public void setCollector(I_CmsResourceCollector collector) {
436
437         m_collector = collector;
438     }
439
440     /**
441      * Sets the dialog object.<p>
442      *
443      * Use this mechanism for transferring a complex object between
444      * several page instances of an interactive dialog. This is usually
445      * required when editing a complex object in a dialog of the "Administration" view.<p>
446      *
447      * @param dialogObject the dialog object to set
448      */

449     public void setDialogObject(Object JavaDoc dialogObject) {
450
451         m_dialogObject = dialogObject;
452     }
453
454     /**
455      * Sets the error message to display in the workplace.<p>
456      *
457      * @param errorMessage the error message to display in the workplace
458      */

459     public void setErrorMessage(CmsMessageContainer errorMessage) {
460
461         m_errorMessage = errorMessage;
462     }
463
464     /**
465      * Sets the explorer flat url.<p>
466      *
467      * @param value the explorer flat url
468      */

469     public void setExplorerFlaturl(String JavaDoc value) {
470
471         m_explorerFlaturl = value;
472     }
473
474     /**
475      * Sets the current explorer mode.<p>
476      *
477      * @param value the current explorer mode
478      */

479     public void setExplorerMode(String JavaDoc value) {
480
481         m_explorerMode = value;
482     }
483
484     /**
485      * Sets the currently selected page in the explorer view.<p>
486      *
487      * @param page the currently selected page in the explorer view
488      */

489     public void setExplorerPage(int page) {
490
491         m_explorerPage = page;
492     }
493
494     /**
495      * Sets the explorer project filter for the project view.<p>
496      *
497      * @param value the explorer project filter
498      */

499     public void setExplorerProjectFilter(String JavaDoc value) {
500
501         m_explorerProjectFilter = value;
502     }
503
504     /**
505      * Sets the explorer project id for the project view.<p>
506      *
507      * @param value the explorer project id
508      */

509     public void setExplorerProjectId(int value) {
510
511         m_explorerProjectId = value;
512     }
513
514     /**
515      * Sets the current resource to be displayed in the explorer.<p>
516      *
517      * @param value the current resource to be displayed in the explorer
518      */

519     public synchronized void setExplorerResource(String JavaDoc value) {
520
521         if (value == null) {
522             return;
523         }
524         // get the current explorer mode
525
String JavaDoc mode = getExplorerMode();
526         if (mode == null) {
527             mode = CmsExplorer.VIEW_EXPLORER;
528         }
529         if (CmsExplorer.VIEW_EXPLORER.equals(mode)) {
530             // append the current site to the key when in explorer view mode
531
mode += "_" + getSite() + "/";
532         }
533
534         // set the resource for the given mode
535
if (value.startsWith(CmsResource.VFS_FOLDER_SYSTEM + "/")
536             && (!value.startsWith(m_currentSite))
537             && (!CmsExplorer.VIEW_GALLERY.equals(getExplorerMode()))) {
538             // restrict access to /system/
539
m_explorerResource.put(mode, "/");
540         } else {
541             m_explorerResource.put(mode, value);
542         }
543     }
544
545     /**
546      * Sets the explorer view to show VFS links of a resource.<p>
547      *
548      * @param b true, if VFS links should be shown, otherwise false
549      */

550     public void setExplorerShowLinks(boolean b) {
551
552         m_explorerShowLinks = b;
553     }
554
555     /**
556      * Sets the current gallery type name.<p>
557      *
558      * @param currentGallery the current gallery type name to set
559      */

560     public void setGalleryType(String JavaDoc currentGallery) {
561
562         m_galleryType = currentGallery;
563     }
564
565     /**
566      * Saves the last gallery.<p>
567      *
568      * @param galleryTypeId the type id of the gallery as key
569      * @param gallerypath the resourcepath of the gallery
570      */

571     public void setLastUsedGallery(int galleryTypeId, String JavaDoc gallerypath) {
572
573         m_lastUsedGalleries.put(String.valueOf(galleryTypeId), gallerypath);
574     }
575
576     /**
577      * Sets the list object.<p>
578      *
579      * Use this mechanism for transfering a html list object between
580      * several page instances of an interactive dialog. This is usually
581      * required when having several lists in a tool or when a list action
582      * another list displays of the "Administration" view.<p>
583      *
584      * @param listObject the list object to set
585      *
586      * @see org.opencms.workplace.list.A_CmsListDialog#setListObject(Class, org.opencms.workplace.list.CmsHtmlList)
587      */

588     public void setListObject(Object JavaDoc listObject) {
589
590         m_listObject = listObject;
591     }
592
593     /**
594      * Sets the current detail grade of the view.<p>
595      *
596      * @param value the current details.
597      */

598     public void setPermissionDetailView(String JavaDoc value) {
599
600         m_permissionDetailView = value;
601     }
602
603     /**
604      * Sets the currently selected project of the workplace user.<p>
605      *
606      * @param project the currently selected project of thw workplace user
607      */

608     public void setProject(int project) {
609
610         m_project = project;
611     }
612
613     /**
614      * Sets the publish list.<p>
615      *
616      * @param publishList the publishList to set
617      */

618     public void setPublishList(CmsPublishList publishList) {
619
620         m_publishList = publishList;
621     }
622
623     /**
624      * Sets all visible resource types for the current user, with the IDs as key values.<p>
625      *
626      * @param value Map with all visible resource types
627      */

628     public void setResourceTypes(Map JavaDoc value) {
629
630         m_resourceTypes = value;
631     }
632
633     /**
634      * Sets the current site for the user.<p>
635      *
636      * @param value the current site for the user
637      */

638     public void setSite(String JavaDoc value) {
639
640         if ((value != null) && !value.equals(m_currentSite)) {
641             m_currentSite = value;
642             m_treeType = new HashMap JavaDoc();
643         }
644     }
645
646     /**
647      * Sets the new admin view tool User Data.<p>
648      *
649      * @param toolUserData the tool User Data to set
650      */

651     public void setToolUserData(CmsToolUserData toolUserData) {
652
653         m_toolUserData = toolUserData;
654     }
655
656     /**
657      * Sets the tree resource uri for the specified tree type.<p>
658      *
659      * @param type the type of the tree
660      * @param value the resource uri to set for the type
661      */

662     public void setTreeResource(String JavaDoc type, String JavaDoc value) {
663
664         if (value == null) {
665             return;
666         }
667         if (value.startsWith(CmsResource.VFS_FOLDER_SYSTEM + "/") && (!value.startsWith(m_currentSite))) {
668             // restrict access to /system/
669
value = "/";
670         }
671         m_treeType.put(type, value);
672     }
673
674     /**
675      * Sets the tree resource uri for the specified tree type.<p>
676      *
677      * @param type the type of the tree
678      * @param value the resource uri to set for the type
679      */

680     public void setTreeSite(String JavaDoc type, String JavaDoc value) {
681
682         if (value == null) {
683             return;
684         }
685         m_treeSite.put(type, value);
686     }
687
688     /**
689      * Sets the current workplace user.<p>
690      *
691      * @param user the current workplace user
692      */

693     public void setUser(CmsUser user) {
694
695         m_user = user;
696     }
697
698     /**
699      * Sets the current workplace user settings object.<p>
700      *
701      * @param userSettings the current workplace user settings object
702      */

703     public void setUserSettings(CmsUserSettings userSettings) {
704
705         m_userSettings = userSettings;
706     }
707
708     /**
709      * Sets the view startup page.<p>
710      *
711      * The view startup page can be used to directly load a specific workplace dialog or other workplace resource in the
712      * OpenCms workplace base frameset after the user logs in.<p>
713      *
714      * @param viewStartup the view startup page to set
715      */

716     public void setViewStartup(String JavaDoc viewStartup) {
717
718         m_viewStartup = viewStartup;
719     }
720
721     /**
722      * Sets the view Uri for the workplace.<p>
723      *
724      * @param string the view Uri for the workplace
725      */

726     public void setViewUri(String JavaDoc string) {
727
728         m_viewUri = string;
729     }
730 }
Popular Tags