001: /*
002: * File : $Source: /usr/local/cvs/opencms/src/org/opencms/workplace/explorer/CmsExplorerTypeSettings.java,v $
003: * Date : $Date: 2008-02-27 12:05:21 $
004: * Version: $Revision: 1.20 $
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.explorer;
033:
034: import org.opencms.file.CmsObject;
035: import org.opencms.file.CmsResource;
036: import org.opencms.i18n.CmsMessages;
037: import org.opencms.main.CmsLog;
038: import org.opencms.main.OpenCms;
039: import org.opencms.security.CmsPermissionSet;
040: import org.opencms.util.CmsStringUtil;
041: import org.opencms.workplace.CmsWorkplaceManager;
042:
043: import java.util.ArrayList;
044: import java.util.List;
045:
046: import org.apache.commons.logging.Log;
047:
048: /**
049: * Holds all information to build the explorer context menu of a resource type
050: * and information for the new resource dialog.<p>
051: *
052: * Objects of this type are sorted by their order value which specifies the order
053: * in the new resource dialog.<p>
054: *
055: * @author Andreas Zahner
056: *
057: * @version $Revision: 1.20 $
058: *
059: * @since 6.0.0
060: */
061: public class CmsExplorerTypeSettings implements Comparable {
062:
063: /** The default order start value for context menu entries. */
064: public static final int ORDER_VALUE_DEFAULT_START = 100000;
065:
066: /** The default order value for context menu separator entries without order attribute. */
067: public static final String ORDER_VALUE_SEPARATOR_DEFAULT = "999999";
068:
069: /** The log object for this class. */
070: private static final Log LOG = CmsLog
071: .getLog(CmsExplorerTypeSettings.class);
072:
073: private CmsExplorerTypeAccess m_access;
074:
075: /** Flag for showing that this is an additional resource type which defined in a module. */
076: private boolean m_addititionalModuleExplorerType;
077: private boolean m_autoSetNavigation;
078: private boolean m_autoSetTitle;
079: private CmsExplorerContextMenu m_contextMenu;
080: private List m_contextMenuEntries;
081: private String m_descriptionImage;
082: private boolean m_hasEditOptions;
083: private String m_icon;
084: private String m_info;
085: private String m_key;
086: private String m_name;
087:
088: /** Optional class name for a new resource handler. */
089: private String m_newResourceHandlerClassName;
090: private Integer m_newResourceOrder;
091: private String m_newResourcePage;
092: private String m_newResourceUri;
093: private List m_properties;
094: private boolean m_propertiesEnabled;
095: private String m_reference;
096: private boolean m_showNavigation;
097:
098: private String m_titleKey;
099:
100: /**
101: * Default constructor.<p>
102: */
103: public CmsExplorerTypeSettings() {
104:
105: m_access = new CmsExplorerTypeAccess();
106: m_properties = new ArrayList();
107: m_contextMenuEntries = new ArrayList();
108: m_contextMenu = new CmsExplorerContextMenu();
109: m_hasEditOptions = false;
110: m_propertiesEnabled = false;
111: m_showNavigation = false;
112: m_addititionalModuleExplorerType = false;
113: m_newResourceOrder = new Integer(0);
114: }
115:
116: /**
117: * Adds a menu entry to the list of context menu items.<p>
118: *
119: * @param item the entry item to add to the list
120: */
121: public void addContextMenuEntry(CmsExplorerContextMenuItem item) {
122:
123: item.setType(CmsExplorerContextMenuItem.TYPE_ENTRY);
124: m_contextMenuEntries.add(item);
125: if (LOG.isDebugEnabled()) {
126: LOG.debug(Messages.get().getBundle().key(
127: Messages.LOG_ADD_MENU_ENTRY_2, item.getKey(),
128: item.getUri()));
129: }
130: }
131:
132: /**
133: * Adds a menu separator to the list of context menu items.<p>
134: *
135: * @param item the separator item to add to the list
136: */
137: public void addContextMenuSeparator(CmsExplorerContextMenuItem item) {
138:
139: item.setType(CmsExplorerContextMenuItem.TYPE_SEPARATOR);
140: m_contextMenuEntries.add(item);
141: if (LOG.isDebugEnabled()) {
142: LOG.debug(Messages.get().getBundle().key(
143: Messages.LOG_ADD_MENU_SEPARATOR_1, item.getType()));
144: }
145: }
146:
147: /**
148: * Adds a property definition name to the list of editable properties.<p>
149: *
150: * @param propertyName the name of the property definition to add
151: * @return true if the property definition was added properly
152: */
153: public boolean addProperty(String propertyName) {
154:
155: if (CmsStringUtil.isNotEmptyOrWhitespaceOnly(propertyName)) {
156: if (LOG.isDebugEnabled()) {
157: LOG.debug(Messages.get().getBundle().key(
158: Messages.LOG_ADD_PROP_1, propertyName));
159: }
160: return m_properties.add(propertyName);
161: } else {
162: return false;
163: }
164: }
165:
166: /**
167: * @see java.lang.Comparable#compareTo(java.lang.Object)
168: */
169: public int compareTo(Object obj) {
170:
171: if (obj == this ) {
172: return 0;
173: }
174: if (obj instanceof CmsExplorerTypeSettings) {
175: CmsExplorerTypeSettings other = (CmsExplorerTypeSettings) obj;
176: String myPage = getNewResourcePage();
177: String otherPage = other.getNewResourcePage();
178: if (CmsStringUtil.isEmptyOrWhitespaceOnly(myPage)) {
179: myPage = "";
180: }
181: if (CmsStringUtil.isEmptyOrWhitespaceOnly(otherPage)) {
182: otherPage = "";
183: }
184: int result = myPage.compareTo(otherPage);
185: if (result == 0) {
186: result = m_newResourceOrder
187: .compareTo(other.m_newResourceOrder);
188: }
189: return result;
190: }
191: return 0;
192: }
193:
194: /**
195: * Adds all context menu entries to the context menu object.<p>
196: *
197: * This method has to be called when all context menu entries have been
198: * added to the list of entries.<p>
199: */
200: public void createContextMenu() {
201:
202: m_contextMenu.addEntries(getContextMenuEntries());
203: if (LOG.isDebugEnabled()) {
204: LOG.debug(Messages.get().getBundle().key(
205: Messages.LOG_CREATE_CONTEXT_MENU_1, getName()));
206: }
207: }
208:
209: /**
210: * @see java.lang.Object#equals(java.lang.Object)
211: */
212: public boolean equals(Object o) {
213:
214: if (!(o instanceof CmsExplorerTypeSettings)) {
215: return false;
216: }
217: CmsExplorerTypeSettings other = (CmsExplorerTypeSettings) o;
218: return getName().equals(other.getName());
219: }
220:
221: /**
222: * Gets the access object of the type settings.<p>
223: *
224: * @return access object of the type settings
225: */
226: public CmsExplorerTypeAccess getAccess() {
227:
228: if (m_access.isEmpty()) {
229: CmsWorkplaceManager workplaceManager = OpenCms
230: .getWorkplaceManager();
231: if (workplaceManager != null) {
232: m_access = workplaceManager.getDefaultAccess();
233: }
234: }
235: return m_access;
236: }
237:
238: /**
239: * Returns the context menu.<p>
240: * @return the context menu
241: */
242: public CmsExplorerContextMenu getContextMenu() {
243:
244: if ((m_reference != null) && (m_contextMenu.isEmpty())) {
245: m_contextMenu = (CmsExplorerContextMenu) OpenCms
246: .getWorkplaceManager().getExplorerTypeSetting(
247: m_reference).getContextMenu().clone();
248: }
249: return m_contextMenu;
250: }
251:
252: /**
253: * Returns the list of context menu entries of the explorer type setting.<p>
254: *
255: * @return the list of context menu entries of the explorer type setting
256: */
257: public List getContextMenuEntries() {
258:
259: return m_contextMenuEntries;
260: }
261:
262: /**
263: * Returns the descriptionImage.<p>
264: *
265: * @return the descriptionImage
266: */
267: public String getDescriptionImage() {
268:
269: return m_descriptionImage;
270: }
271:
272: /**
273: * Returns the icon path and file name of the explorer type setting.<p>
274: *
275: * @return the icon path and file name of the explorer type setting
276: */
277: public String getIcon() {
278:
279: return m_icon;
280: }
281:
282: /**
283: * Returns the info.<p>
284: *
285: * @return the info
286: */
287: public String getInfo() {
288:
289: return m_info;
290: }
291:
292: /**
293: * Builds the Javascript to create the context menu.<p>
294: *
295: * @param settings the explorer type settings for which the context menu is created
296: * @param resTypeId the id of the resource type which uses the context menu
297: * @param messages the messages to generate the context menu with (should be the workplace messages)
298: *
299: * @return the JavaScript output to create the context menu
300: */
301: public String getJSEntries(CmsExplorerTypeSettings settings,
302: int resTypeId, CmsMessages messages) {
303:
304: // entries not yet in Map, so generate them
305: StringBuffer result = new StringBuffer(4096);
306:
307: // create the JS for the resource object
308: result.append("\nvi.resource[").append(resTypeId).append(
309: "]=new res(\"").append(settings.getName()).append(
310: "\", ");
311: result.append("\"");
312: result.append(messages.key(settings.getKey()));
313: result.append("\", vi.skinPath + \"filetypes/");
314: result.append(settings.getIcon());
315: result.append("\", \"");
316: result.append(settings.getNewResourceUri());
317: result.append("\", true);\n");
318:
319: return result.toString();
320: }
321:
322: /**
323: * Returns the key name of the explorer type setting.<p>
324: *
325: * @return the key name of the explorer type setting
326: */
327: public String getKey() {
328:
329: return m_key;
330: }
331:
332: /**
333: * Returns the name of the explorer type setting.<p>
334: *
335: * @return the name of the explorer type setting
336: */
337: public String getName() {
338:
339: return m_name;
340: }
341:
342: /**
343: * Returns the class name of the new resource handler used to create new resources of a specified resource type.<p>
344: *
345: * @return the class name of the new resource handler
346: */
347: public String getNewResourceHandlerClassName() {
348:
349: return m_newResourceHandlerClassName;
350: }
351:
352: /**
353: * Returns the order for the new resource dialog of the explorer type setting.<p>
354: *
355: * @return the order for the new resource dialog of the explorer type setting
356: */
357: public String getNewResourceOrder() {
358:
359: return String.valueOf(m_newResourceOrder);
360: }
361:
362: /**
363: * Returns the page.<p>
364: *
365: * @return the page
366: */
367: public String getNewResourcePage() {
368:
369: return m_newResourcePage;
370: }
371:
372: /**
373: * Returns the URI for the new resource dialog of the explorer type setting.<p>
374: *
375: * @return the URI for the new resource dialog of the explorer type setting
376: */
377: public String getNewResourceUri() {
378:
379: return m_newResourceUri;
380: }
381:
382: /**
383: * Returns the list of properties of the explorer type setting.<p>
384: * @return the list of properties of the explorer type setting
385: */
386: public List getProperties() {
387:
388: return m_properties;
389: }
390:
391: /**
392: * Returns the reference of the explorer type setting.<p>
393: *
394: * @return the reference of the explorer type setting
395: */
396: public String getReference() {
397:
398: return m_reference;
399: }
400:
401: /**
402: * Returns the titleKey.<p>
403: *
404: * @return the titleKey
405: */
406: public String getTitleKey() {
407:
408: return m_titleKey;
409: }
410:
411: /**
412: * Returns true if this explorer type entry has explicit edit options set.<p>
413: *
414: * @return true if this explorer type entry has explicit edit options set
415: */
416: public boolean hasEditOptions() {
417:
418: return m_hasEditOptions;
419: }
420:
421: /**
422: * @see java.lang.Object#hashCode()
423: */
424: public int hashCode() {
425:
426: return getName().hashCode();
427: }
428:
429: /**
430: * Indicates that this is an additional explorer type which is defined in a module.<p>
431: *
432: * @return true or false
433: */
434: public boolean isAddititionalModuleExplorerType() {
435:
436: return m_addititionalModuleExplorerType;
437: }
438:
439: /**
440: * Returns true if navigation properties should automatically be added on resource creation.<p>
441: *
442: * @return true if navigation properties should automatically be added on resource creation, otherwise false
443: */
444: public boolean isAutoSetNavigation() {
445:
446: return m_autoSetNavigation;
447: }
448:
449: /**
450: * Returns true if the title property should automatically be added on resource creation.<p>
451: *
452: * @return true if the title property should automatically be added on resource creation, otherwise false
453: */
454: public boolean isAutoSetTitle() {
455:
456: return m_autoSetTitle;
457: }
458:
459: /**
460: * Checks if the current user has write permissions on the given resource.<p>
461: *
462: * @param cms the current cms context
463: * @param resource the resource to check
464: *
465: * @return <code>true</code> if the current user has write permissions on the given resource
466: */
467: public boolean isEditable(CmsObject cms, CmsResource resource) {
468:
469: // determine if this resource type is editable for the current user
470: CmsPermissionSet permissions = getAccess().getPermissions(cms,
471: resource);
472: return permissions.requiresWritePermission();
473: }
474:
475: /**
476: * Returns if this explorer type setting uses a special properties dialog.<p>
477: *
478: * @return true, if this explorer type setting uses a special properties dialog
479: */
480: public boolean isPropertiesEnabled() {
481:
482: return m_propertiesEnabled;
483: }
484:
485: /**
486: * Returns if this explorer type setting displays the navigation properties in the special properties dialog.<p>
487: *
488: * @return true, if this explorer type setting displays the navigation properties in the special properties dialog
489: */
490: public boolean isShowNavigation() {
491:
492: return m_showNavigation;
493: }
494:
495: /**
496: * Sets the access object of the type settings.<p>
497: *
498: * @param access access object
499: */
500: public void setAccess(CmsExplorerTypeAccess access) {
501:
502: m_access = access;
503: }
504:
505: /**
506: * Sets the additional explorer type flag.<p>
507: *
508: * @param addititionalModuleExplorerType true or false
509: */
510: public void setAddititionalModuleExplorerType(
511: boolean addititionalModuleExplorerType) {
512:
513: m_addititionalModuleExplorerType = addititionalModuleExplorerType;
514: }
515:
516: /**
517: * Sets if navigation properties should automatically be added on resource creation.<p>
518: *
519: * @param autoSetNavigation true if properties should be added, otherwise false
520: */
521: public void setAutoSetNavigation(String autoSetNavigation) {
522:
523: m_autoSetNavigation = Boolean.valueOf(autoSetNavigation)
524: .booleanValue();
525: if (LOG.isDebugEnabled()) {
526: LOG.debug(Messages.get().getBundle().key(
527: Messages.LOG_SET_AUTO_NAV_1, autoSetNavigation));
528: }
529: }
530:
531: /**
532: * Sets if the title property should automatically be added on resource creation.<p>
533: *
534: * @param autoSetTitle true if title should be added, otherwise false
535: */
536: public void setAutoSetTitle(String autoSetTitle) {
537:
538: m_autoSetTitle = Boolean.valueOf(autoSetTitle).booleanValue();
539: if (LOG.isDebugEnabled()) {
540: LOG.debug(Messages.get().getBundle().key(
541: Messages.LOG_SET_AUTO_TITLE_1, autoSetTitle));
542: }
543: }
544:
545: /**
546: * Sets the list of context menu entries of the explorer type setting.<p>
547: *
548: * @param entries the list of context menu entries of the explorer type setting
549: */
550: public void setContextMenuEntries(List entries) {
551:
552: m_contextMenuEntries = entries;
553: }
554:
555: /**
556: * Sets the descriptionImage.<p>
557: *
558: * @param descriptionImage the descriptionImage to set
559: */
560: public void setDescriptionImage(String descriptionImage) {
561:
562: m_descriptionImage = descriptionImage;
563: if (LOG.isDebugEnabled()) {
564: LOG.debug(Messages.get().getBundle().key(
565: Messages.LOG_SET_NEW_RESOURCE_DESCRIPTION_IMAGE_1,
566: descriptionImage));
567: }
568: }
569:
570: /**
571: * Sets the flag if this explorer type entry has explicit edit options set.<p>
572: *
573: * This is determined by the presence of the <editoptions> node in the Cms workplace configuration.<p>
574: */
575: public void setEditOptions() {
576:
577: m_hasEditOptions = true;
578: }
579:
580: /**
581: * Sets the icon path and file name of the explorer type setting.<p>
582: *
583: * @param icon the icon path and file name of the explorer type setting
584: */
585: public void setIcon(String icon) {
586:
587: m_icon = icon;
588: if (LOG.isDebugEnabled()) {
589: LOG.debug(Messages.get().getBundle().key(
590: Messages.LOG_SET_ICON_1, icon));
591: }
592: }
593:
594: /**
595: * Sets the info.<p>
596: *
597: * @param info the info to set
598: */
599: public void setInfo(String info) {
600:
601: m_info = info;
602: if (LOG.isDebugEnabled()) {
603: LOG.debug(Messages.get().getBundle().key(
604: Messages.LOG_SET_INFO_1, info));
605: }
606: }
607:
608: /**
609: * Sets the key name of the explorer type setting.<p>
610: *
611: * @param key the key name of the explorer type setting
612: */
613: public void setKey(String key) {
614:
615: m_key = key;
616: if (LOG.isDebugEnabled()) {
617: LOG.debug(Messages.get().getBundle().key(
618: Messages.LOG_SET_KEY_1, key));
619: }
620: }
621:
622: /**
623: * Sets the name of the explorer type setting.<p>
624: *
625: * @param name the name of the explorer type setting
626: */
627: public void setName(String name) {
628:
629: m_name = name;
630: if (LOG.isDebugEnabled()) {
631: LOG.debug(Messages.get().getBundle().key(
632: Messages.LOG_SET_NAME_1, name));
633: }
634: }
635:
636: /**
637: * Sets the class name of the new resource handler used to create new resources of a specified resource type.<p>
638: *
639: * @param newResourceHandlerClassName the class name of the new resource handler
640: */
641: public void setNewResourceHandlerClassName(
642: String newResourceHandlerClassName) {
643:
644: m_newResourceHandlerClassName = newResourceHandlerClassName;
645: }
646:
647: /**
648: * Sets the order for the new resource dialog of the explorer type setting.<p>
649: *
650: * @param newResourceOrder the order for the new resource dialog of the explorer type setting
651: */
652: public void setNewResourceOrder(String newResourceOrder) {
653:
654: try {
655: m_newResourceOrder = Integer.valueOf(newResourceOrder);
656: if (LOG.isDebugEnabled()) {
657: LOG.debug(Messages.get().getBundle().key(
658: Messages.LOG_SET_NEW_RESOURCE_ORDER_1,
659: newResourceOrder));
660: }
661: } catch (Exception e) {
662: // can usually be ignored
663: if (LOG.isInfoEnabled()) {
664: LOG.info(e);
665: }
666: m_newResourceOrder = new Integer(0);
667: }
668: }
669:
670: /**
671: * Sets the page.<p>
672: *
673: * @param page the page to set
674: */
675: public void setNewResourcePage(String page) {
676:
677: m_newResourcePage = page;
678: }
679:
680: /**
681: * Sets the URI for the new resource dialog of the explorer type setting.<p>
682: *
683: * @param newResourceUri the URI for the new resource dialog of the explorer type setting
684: */
685: public void setNewResourceUri(String newResourceUri) {
686:
687: m_newResourceUri = newResourceUri;
688: if (LOG.isDebugEnabled()) {
689: LOG.debug(Messages.get().getBundle()
690: .key(Messages.LOG_SET_NEW_RESOURCE_URI_1,
691: newResourceUri));
692: }
693: }
694:
695: /**
696: * Sets the list of properties of the explorer type setting.<p>
697: *
698: * @param properties the list of properties of the explorer type setting
699: */
700: public void setProperties(List properties) {
701:
702: m_properties = properties;
703: }
704:
705: /**
706: * Sets if this explorer type setting uses a special properties dialog.<p>
707: *
708: * @param enabled true, if this explorer type setting uses a special properties dialog
709: */
710: public void setPropertiesEnabled(boolean enabled) {
711:
712: m_propertiesEnabled = enabled;
713: }
714:
715: /**
716: * Sets the default settings for the property display dialog.<p>
717: *
718: * @param enabled true, if this explorer type setting uses a special properties dialog
719: * @param showNavigation true, if this explorer type setting displays the navigation properties in the special properties dialog
720: */
721: public void setPropertyDefaults(String enabled,
722: String showNavigation) {
723:
724: setPropertiesEnabled(Boolean.valueOf(enabled).booleanValue());
725: setShowNavigation(Boolean.valueOf(showNavigation)
726: .booleanValue());
727: if (LOG.isDebugEnabled()) {
728: LOG.debug(Messages.get().getBundle().key(
729: Messages.LOG_SET_PROP_DEFAULTS_2, enabled,
730: showNavigation));
731: }
732: }
733:
734: /**
735: * Sets the reference of the explorer type setting.<p>
736: *
737: * @param reference the reference of the explorer type setting
738: */
739: public void setReference(String reference) {
740:
741: m_reference = reference;
742: if (LOG.isDebugEnabled()) {
743: LOG.debug(Messages.get().getBundle().key(
744: Messages.LOG_SET_REFERENCE_1, m_reference));
745: }
746: }
747:
748: /**
749: * Sets if this explorer type setting displays the navigation properties in the special properties dialog.<p>
750: *
751: * @param navigation true, if this explorer type setting displays the navigation properties in the special properties dialog
752: */
753: public void setShowNavigation(boolean navigation) {
754:
755: m_showNavigation = navigation;
756: }
757:
758: /**
759: * Sets the titleKey.<p>
760: *
761: * @param titleKey the titleKey to set
762: */
763: public void setTitleKey(String titleKey) {
764:
765: m_titleKey = titleKey;
766: if (LOG.isDebugEnabled()) {
767: LOG.debug(Messages.get().getBundle().key(
768: Messages.LOG_SET_TITLE_KEY_1, titleKey));
769: }
770: }
771:
772: /**
773: * Sets the basic attributes of the type settings.<p>
774: *
775: * @param name the name of the type setting
776: * @param key the key name of the explorer type setting
777: * @param icon the icon path and file name of the explorer type setting
778: */
779: public void setTypeAttributes(String name, String key, String icon) {
780:
781: setName(name);
782: setKey(key);
783: setIcon(icon);
784: }
785:
786: /**
787: * Sets the basic attributes of the type settings.<p>
788: *
789: * @param name the name of the type setting
790: * @param key the key name of the explorer type setting
791: * @param icon the icon path and file name of the explorer type setting
792: * @param reference the reference of the explorer type setting
793: */
794: public void setTypeAttributes(String name, String key, String icon,
795: String reference) {
796:
797: setName(name);
798: setKey(key);
799: setIcon(icon);
800: setReference(reference);
801: }
802:
803: }
|