001: /*
002: * File : $Source: /usr/local/cvs/opencms/src/org/opencms/workplace/CmsWorkplaceSettings.java,v $
003: * Date : $Date: 2008-02-27 12:05:45 $
004: * Version: $Revision: 1.60 $
005: *
006: * This library is part of OpenCms -
007: * the Open Source Content Management System
008: *
009: * Copyright (c) 2002 - 2008 Alkacon Software GmbH (http://www.alkacon.com)
010: *
011: * This library is free software; you can redistribute it and/or
012: * modify it under the terms of the GNU Lesser General Public
013: * License as published by the Free Software Foundation; either
014: * version 2.1 of the License, or (at your option) any later version.
015: *
016: * This library is distributed in the hope that it will be useful,
017: * but WITHOUT ANY WARRANTY; without even the implied warranty of
018: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
019: * Lesser General Public License for more details.
020: *
021: * For further information about Alkacon Software GmbH, please see the
022: * company website: http://www.alkacon.com
023: *
024: * For further information about OpenCms, please see the
025: * project website: http://www.opencms.org
026: *
027: * You should have received a copy of the GNU Lesser General Public
028: * License along with this library; if not, write to the Free Software
029: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
030: */
031:
032: package org.opencms.workplace;
033:
034: import org.opencms.db.CmsPublishList;
035: import org.opencms.db.CmsUserSettings;
036: import org.opencms.file.CmsResource;
037: import org.opencms.file.CmsUser;
038: import org.opencms.file.collectors.I_CmsResourceCollector;
039: import org.opencms.i18n.CmsMessageContainer;
040: import org.opencms.main.OpenCms;
041: import org.opencms.util.CmsUUID;
042: import org.opencms.workplace.explorer.CmsExplorer;
043: import org.opencms.workplace.tools.CmsToolUserData;
044:
045: import java.util.HashMap;
046: import java.util.Map;
047:
048: /**
049: * Object to conveniently access and modify the state of the workplace for a user,
050: * will be stored in the session of a user.<p>
051: *
052: * @author Alexander Kandzior
053: *
054: * @version $Revision: 1.60 $
055: *
056: * @since 6.0.0
057: */
058: public class CmsWorkplaceSettings {
059:
060: private I_CmsResourceCollector m_collector;
061: private String m_currentSite;
062: private Object m_dialogObject;
063: private CmsMessageContainer m_errorMessage;
064: private String m_explorerFlaturl;
065: private String m_explorerMode;
066: private int m_explorerPage;
067: private String m_explorerProjectFilter;
068: private CmsUUID m_explorerProjectId;
069: private Map m_explorerResource;
070: private Map m_frameUris;
071: private String m_galleryType;
072: private Map m_lastUsedGalleries;
073: private Object m_listObject;
074: private String m_permissionDetailView;
075: private CmsUUID m_project;
076: private CmsPublishList m_publishList;
077: private CmsToolUserData m_toolUserData;
078: private Map m_treeSite;
079: private Map m_treeType;
080: private CmsUser m_user;
081: private CmsUserSettings m_userSettings;
082: private String m_viewStartup;
083: private String m_viewUri;
084:
085: /**
086: * Constructor, only package visible.<p>
087: */
088: CmsWorkplaceSettings() {
089:
090: m_explorerPage = 1;
091: m_explorerResource = new HashMap();
092: m_treeType = new HashMap();
093: m_treeSite = new HashMap();
094: m_frameUris = new HashMap();
095: m_lastUsedGalleries = new HashMap();
096: m_currentSite = OpenCms.getSiteManager().getDefaultSite()
097: .getSiteRoot();
098: }
099:
100: /**
101: * Returns the collector object.<p>
102: *
103: * Use this mechanism for transferring a resource collector between
104: * several page instances of an interactive dialog. <p>
105: *
106: * @return the dialog object
107: */
108: public I_CmsResourceCollector getCollector() {
109:
110: return m_collector;
111: }
112:
113: /**
114: * Returns the dialog object.<p>
115: *
116: * Use this mechanism for transferring a complex object between
117: * several page instances of an interactive dialog. This is usually
118: * required when editing a complex object in a dialog of the "Administration" view.<p>
119: *
120: * @return the dialog object
121: */
122: public Object getDialogObject() {
123:
124: return m_dialogObject;
125: }
126:
127: /**
128: * Returns the error message to display in the workplace.<p>
129: *
130: * @return the error message to display in the workplace
131: */
132: public CmsMessageContainer getErrorMessage() {
133:
134: return m_errorMessage;
135: }
136:
137: /**
138: * Returns the explorer flat url.<p>
139: *
140: * @return the explorer flat url
141: */
142: public String getExplorerFlaturl() {
143:
144: return m_explorerFlaturl;
145: }
146:
147: /**
148: * Returns the current explorer mode.<p>
149: *
150: * @return the current explorer mode
151: */
152: public String getExplorerMode() {
153:
154: return m_explorerMode;
155: }
156:
157: /**
158: * Returns the currently selected page in the explorer view.<p>
159: *
160: * @return the currently selected page in the explorer view
161: */
162: public int getExplorerPage() {
163:
164: return m_explorerPage;
165: }
166:
167: /**
168: * Gets the explorer project filter for the project view.<p>
169: *
170: * This parameter is used in the administration to filter
171: * files belonging to a project.
172: *
173: * @return the explorer project filter
174: */
175: public String getExplorerProjectFilter() {
176:
177: return m_explorerProjectFilter;
178: }
179:
180: /**
181: * Gets the explorer project id for the project view.<p>
182: *
183: * This parameter is used in the administration to filter
184: * files belonging to a selected project.
185: *
186: * @return the explorer project id
187: */
188: public CmsUUID getExplorerProjectId() {
189:
190: return m_explorerProjectId;
191: }
192:
193: /**
194: * Returns the current resource to be displayed in the explorer.<p>
195: *
196: * @return the current resource to be displayed in the explorer
197: */
198: public String getExplorerResource() {
199:
200: // get the current explorer mode
201: String mode = getExplorerMode();
202: if (mode == null) {
203: mode = CmsExplorer.VIEW_EXPLORER;
204: }
205: if (CmsExplorer.VIEW_EXPLORER.equals(mode)) {
206: // append the current site to the key when in explorer view mode
207: mode += "_" + getSite() + "/";
208: }
209: // get the resource for the given mode
210: String resource = (String) m_explorerResource.get(mode);
211: if (resource == null) {
212: resource = "/";
213: }
214: return resource;
215: }
216:
217: /**
218: * Returns the frame URIs of the currently loaded frameset, with the frame names as keys.<p>
219: *
220: * @return the frame URIs of the currently loaded frameset
221: */
222: public Map getFrameUris() {
223:
224: return m_frameUris;
225: }
226:
227: /**
228: * Returns the current gallery type name.<p>
229: *
230: * @return the current gallery type name
231: */
232: public String getGalleryType() {
233:
234: return m_galleryType;
235: }
236:
237: /**
238: * Returns the last saved gallery for the given gallery type id.<p>
239: *
240: * @param galleryTypeId the type id of the gallery
241: * @return the last saved gallery for the given gallery type id
242: */
243: public String getLastUsedGallery(int galleryTypeId) {
244:
245: return (String) m_lastUsedGalleries.get(String
246: .valueOf(galleryTypeId));
247: }
248:
249: /**
250: * Returns the list dialog object.<p>
251: *
252: * Use this mechanism for transfering a html list object between
253: * several page instances of an interactive dialog. This is usually
254: * required when having several lists in a tool or when a list action
255: * another list displays of the "Administration" view.<p>
256: *
257: * @return the dialog object
258: *
259: * @see org.opencms.workplace.list.A_CmsListDialog#getListObject(Class, CmsWorkplaceSettings)
260: */
261: public Object getListObject() {
262:
263: return m_listObject;
264: }
265:
266: /**
267: * Returns the current detail grade of the view.<p>
268: *
269: * @return value of the details.
270: */
271: public String getPermissionDetailView() {
272:
273: return m_permissionDetailView;
274: }
275:
276: /**
277: * Returns the currently selected project of the workplace user.<p>
278: *
279: * @return the currently selected project of the workplace user
280: */
281: public CmsUUID getProject() {
282:
283: return m_project;
284: }
285:
286: /**
287: * Returns the publish list.<p>
288: *
289: * @return the publishList
290: */
291: public CmsPublishList getPublishList() {
292:
293: return m_publishList;
294: }
295:
296: /**
297: * Returns the current site for the user.<p>
298: *
299: * @return the current site for the user
300: */
301: public String getSite() {
302:
303: return m_currentSite;
304: }
305:
306: /**
307: * Returns the new admin view tool User Data.<p>
308: *
309: * @return the tool User Data
310: */
311: public CmsToolUserData getToolUserData() {
312:
313: return m_toolUserData;
314: }
315:
316: /**
317: * Returns the tree resource uri for the specified tree type.<p>
318: *
319: * @param type the type of the tree
320: * @return the tree resource uri for the specified tree type
321: */
322: public String getTreeResource(String type) {
323:
324: String result = (String) m_treeType.get(type);
325: if (result == null) {
326: result = "/";
327: }
328: return result;
329: }
330:
331: /**
332: * Returns the tree site uri for the specified tree type.<p>
333: *
334: * @param type the type of the tree
335: * @return the tree site uri for the specified tree type
336: */
337: public String getTreeSite(String type) {
338:
339: String result = (String) m_treeSite.get(type);
340: return result;
341: }
342:
343: /**
344: * Returns the current workplace user.<p>
345: *
346: * @return the current workplace user
347: */
348: public CmsUser getUser() {
349:
350: return m_user;
351: }
352:
353: /**
354: * Returns the current workplace user settings object.<p>
355: *
356: * @return the current workplace user settings object
357: */
358: public CmsUserSettings getUserSettings() {
359:
360: return m_userSettings;
361: }
362:
363: /**
364: * Returns the view startup page.<p>
365: *
366: * The view startup page can be used to directly load a specific workplace dialog or other workplace resource in the
367: * OpenCms workplace base frameset after the user logs in.<p>
368: *
369: * @return the view startup page
370: */
371: public String getViewStartup() {
372:
373: return m_viewStartup;
374: }
375:
376: /**
377: * Returns the current view Uri selected in the workplace.<p>
378: *
379: * @return the current view Uri selected in the workplace
380: */
381: public String getViewUri() {
382:
383: return m_viewUri;
384: }
385:
386: /**
387: * Checks if the current view is the explorer view.<p>
388: *
389: * @return true if the current view is the explorer view, otherwise false
390: */
391: public boolean isViewExplorer() {
392:
393: return getViewUri().endsWith(
394: CmsWorkplace.FILE_EXPLORER_FILELIST);
395: }
396:
397: /**
398: * Sets the collector object.<p>
399: *
400: * Use this mechanism for transferring a resource collector between
401: * several page instances of an interactive dialog.<p>
402: *
403: * @param collector the dialog object to set
404: */
405: public void setCollector(I_CmsResourceCollector collector) {
406:
407: m_collector = collector;
408: }
409:
410: /**
411: * Sets the dialog object.<p>
412: *
413: * Use this mechanism for transferring a complex object between
414: * several page instances of an interactive dialog. This is usually
415: * required when editing a complex object in a dialog of the "Administration" view.<p>
416: *
417: * @param dialogObject the dialog object to set
418: */
419: public void setDialogObject(Object dialogObject) {
420:
421: m_dialogObject = dialogObject;
422: }
423:
424: /**
425: * Sets the error message to display in the workplace.<p>
426: *
427: * @param errorMessage the error message to display in the workplace
428: */
429: public void setErrorMessage(CmsMessageContainer errorMessage) {
430:
431: m_errorMessage = errorMessage;
432: }
433:
434: /**
435: * Sets the explorer flat url.<p>
436: *
437: * @param value the explorer flat url
438: */
439: public void setExplorerFlaturl(String value) {
440:
441: m_explorerFlaturl = value;
442: }
443:
444: /**
445: * Sets the current explorer mode.<p>
446: *
447: * @param value the current explorer mode
448: */
449: public void setExplorerMode(String value) {
450:
451: m_explorerMode = value;
452: }
453:
454: /**
455: * Sets the currently selected page in the explorer view.<p>
456: *
457: * @param page the currently selected page in the explorer view
458: */
459: public void setExplorerPage(int page) {
460:
461: m_explorerPage = page;
462: }
463:
464: /**
465: * Sets the explorer project filter for the project view.<p>
466: *
467: * @param value the explorer project filter
468: */
469: public void setExplorerProjectFilter(String value) {
470:
471: m_explorerProjectFilter = value;
472: }
473:
474: /**
475: * Sets the explorer project id for the project view.<p>
476: *
477: * @param value the explorer project id
478: */
479: public void setExplorerProjectId(CmsUUID value) {
480:
481: m_explorerProjectId = value;
482: }
483:
484: /**
485: * Sets the current resource to be displayed in the explorer.<p>
486: *
487: * @param value the current resource to be displayed in the explorer
488: */
489: public void setExplorerResource(String value) {
490:
491: if (value == null) {
492: return;
493: }
494: // get the current explorer mode
495: String mode = getExplorerMode();
496: if (mode == null) {
497: mode = CmsExplorer.VIEW_EXPLORER;
498: }
499: if (CmsExplorer.VIEW_EXPLORER.equals(mode)) {
500: // append the current site to the key when in explorer view mode
501: mode += "_" + getSite() + "/";
502: }
503:
504: // set the resource for the given mode
505: if (value.startsWith(CmsResource.VFS_FOLDER_SYSTEM + "/")
506: && (!value.startsWith(m_currentSite))
507: && (!CmsExplorer.VIEW_GALLERY.equals(getExplorerMode()))) {
508: // restrict access to /system/
509: m_explorerResource.put(mode, "/");
510: } else {
511: m_explorerResource.put(mode, value);
512: }
513: }
514:
515: /**
516: * Sets the current gallery type name.<p>
517: *
518: * @param currentGallery the current gallery type name to set
519: */
520: public void setGalleryType(String currentGallery) {
521:
522: m_galleryType = currentGallery;
523: }
524:
525: /**
526: * Saves the last gallery.<p>
527: *
528: * @param galleryTypeId the type id of the gallery as key
529: * @param gallerypath the resourcepath of the gallery
530: */
531: public void setLastUsedGallery(int galleryTypeId, String gallerypath) {
532:
533: m_lastUsedGalleries.put(String.valueOf(galleryTypeId),
534: gallerypath);
535: }
536:
537: /**
538: * Sets the list object.<p>
539: *
540: * Use this mechanism for transfering a html list object between
541: * several page instances of an interactive dialog. This is usually
542: * required when having several lists in a tool or when a list action
543: * another list displays of the "Administration" view.<p>
544: *
545: * @param listObject the list object to set
546: *
547: * @see org.opencms.workplace.list.A_CmsListDialog#setListObject(Class, org.opencms.workplace.list.CmsHtmlList)
548: */
549: public void setListObject(Object listObject) {
550:
551: m_listObject = listObject;
552: }
553:
554: /**
555: * Sets the current detail grade of the view.<p>
556: *
557: * @param value the current details.
558: */
559: public void setPermissionDetailView(String value) {
560:
561: m_permissionDetailView = value;
562: }
563:
564: /**
565: * Sets the currently selected project of the workplace user.<p>
566: *
567: * @param project the currently selected project of thw workplace user
568: */
569: public void setProject(CmsUUID project) {
570:
571: m_project = project;
572: }
573:
574: /**
575: * Sets the publish list.<p>
576: *
577: * @param publishList the publishList to set
578: */
579: public void setPublishList(CmsPublishList publishList) {
580:
581: m_publishList = publishList;
582: }
583:
584: /**
585: * Sets the current site for the user.<p>
586: *
587: * @param value the current site for the user
588: */
589: public void setSite(String value) {
590:
591: if ((value != null) && !value.equals(m_currentSite)) {
592: m_currentSite = value;
593: m_treeType = new HashMap();
594: }
595: }
596:
597: /**
598: * Sets the new admin view tool User Data.<p>
599: *
600: * @param toolUserData the tool User Data to set
601: */
602: public void setToolUserData(CmsToolUserData toolUserData) {
603:
604: m_toolUserData = toolUserData;
605: }
606:
607: /**
608: * Sets the tree resource uri for the specified tree type.<p>
609: *
610: * @param type the type of the tree
611: * @param value the resource uri to set for the type
612: */
613: public void setTreeResource(String type, String value) {
614:
615: if (value == null) {
616: return;
617: }
618: if (value.startsWith(CmsResource.VFS_FOLDER_SYSTEM + "/")
619: && (!value.startsWith(m_currentSite))) {
620: // restrict access to /system/
621: value = "/";
622: }
623: m_treeType.put(type, value);
624: }
625:
626: /**
627: * Sets the tree resource uri for the specified tree type.<p>
628: *
629: * @param type the type of the tree
630: * @param value the resource uri to set for the type
631: */
632: public void setTreeSite(String type, String value) {
633:
634: if (value == null) {
635: return;
636: }
637: m_treeSite.put(type, value);
638: }
639:
640: /**
641: * Sets the current workplace user.<p>
642: *
643: * @param user the current workplace user
644: */
645: public void setUser(CmsUser user) {
646:
647: m_user = user;
648: }
649:
650: /**
651: * Sets the current workplace user settings object.<p>
652: *
653: * @param userSettings the current workplace user settings object
654: */
655: public void setUserSettings(CmsUserSettings userSettings) {
656:
657: m_userSettings = userSettings;
658: }
659:
660: /**
661: * Sets the view startup page.<p>
662: *
663: * The view startup page can be used to directly load a specific workplace dialog or other workplace resource in the
664: * OpenCms workplace base frameset after the user logs in.<p>
665: *
666: * @param viewStartup the view startup page to set
667: */
668: public void setViewStartup(String viewStartup) {
669:
670: m_viewStartup = viewStartup;
671: }
672:
673: /**
674: * Sets the view Uri for the workplace.<p>
675: *
676: * @param string the view Uri for the workplace
677: */
678: public void setViewUri(String string) {
679:
680: m_viewUri = string;
681: }
682: }
|