001/* 002 * This library is part of OpenCms - 003 * the Open Source Content Management System 004 * 005 * Copyright (c) Alkacon Software GmbH & Co. KG (http://www.alkacon.com) 006 * 007 * This library is free software; you can redistribute it and/or 008 * modify it under the terms of the GNU Lesser General Public 009 * License as published by the Free Software Foundation; either 010 * version 2.1 of the License, or (at your option) any later version. 011 * 012 * This library is distributed in the hope that it will be useful, 013 * but WITHOUT ANY WARRANTY; without even the implied warranty of 014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 015 * Lesser General Public License for more details. 016 * 017 * For further information about Alkacon Software, please see the 018 * company website: http://www.alkacon.com 019 * 020 * For further information about OpenCms, please see the 021 * project website: http://www.opencms.org 022 * 023 * You should have received a copy of the GNU Lesser General Public 024 * License along with this library; if not, write to the Free Software 025 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 026 */ 027 028package org.opencms.configuration.preferences; 029 030import org.opencms.file.CmsObject; 031import org.opencms.main.CmsLog; 032import org.opencms.main.OpenCms; 033import org.opencms.security.CmsRole; 034import org.opencms.ui.apps.I_CmsWorkplaceAppConfiguration; 035import org.opencms.xml.content.CmsXmlContentProperty; 036 037import java.util.ArrayList; 038import java.util.List; 039import java.util.Locale; 040 041import org.apache.commons.logging.Log; 042 043/** 044 * Preference for the start site.<p> 045 */ 046public class CmsStartViewPreference extends CmsBuiltinPreference { 047 048 /** Logger instance for this class. */ 049 private static final Log LOG = CmsLog.getLog(CmsStartViewPreference.class); 050 051 /** The nice name. */ 052 private static final String NICE_NAME = "%(key." 053 + org.opencms.workplace.commons.Messages.GUI_PREF_STARTUP_VIEW_0 054 + ")"; 055 056 /** 057 * Creates a new instance.<p> 058 * 059 * @param name the preference name 060 */ 061 public CmsStartViewPreference(String name) { 062 063 super(name); 064 } 065 066 /** 067 * Gets the select options for the view selector.<p> 068 * 069 * @param cms the CMS context 070 * @param value the current value 071 * @return the select options 072 */ 073 public static SelectOptions getViewSelectOptions(CmsObject cms, String value) { 074 075 Locale locale = OpenCms.getWorkplaceManager().getWorkplaceLocale(cms); 076 077 List<String> options = new ArrayList<String>(); 078 List<String> values = new ArrayList<String>(); 079 int selectedIndex = 0; 080 081 List<I_CmsWorkplaceAppConfiguration> apps = OpenCms.getWorkplaceAppManager().getDefaultQuickLaunchConfigurations(); 082 083 for (I_CmsWorkplaceAppConfiguration app : apps) { 084 if (OpenCms.getRoleManager().hasRole( 085 cms, 086 cms.getRequestContext().getCurrentUser().getName(), 087 app.getRequiredRole())) { 088 values.add(app.getId()); 089 options.add(app.getName(locale)); 090 } 091 } 092 093 SelectOptions optionBean = new SelectOptions(options, values, selectedIndex); 094 return optionBean; 095 } 096 097 /** 098 * @see org.opencms.configuration.preferences.CmsBuiltinPreference#getPropertyDefinition(org.opencms.file.CmsObject) 099 */ 100 @Override 101 public CmsXmlContentProperty getPropertyDefinition() { 102 103 CmsXmlContentProperty prop = new CmsXmlContentProperty( 104 getName(), //name 105 "string", //type 106 null, //widget 107 null, //widgetconfig 108 null, //regex 109 null, //ruletype 110 null, //default 111 NICE_NAME, //nicename 112 null, //description 113 null, //error 114 null//preferfolder 115 ); 116 return prop; 117 } 118 119 /** 120 * @see org.opencms.configuration.preferences.CmsBuiltinPreference#getPropertyDefinition(org.opencms.file.CmsObject) 121 */ 122 @Override 123 public CmsXmlContentProperty getPropertyDefinition(CmsObject cms) { 124 125 String options = getViewSelectOptions(cms, null).toClientSelectWidgetConfiguration(); 126 CmsXmlContentProperty prop = new CmsXmlContentProperty( 127 getName(), //name 128 "string", //type 129 "select_notnull", //widget 130 options, //widgetconfig 131 null, //regex 132 null, //ruletype 133 null, //default 134 NICE_NAME, //nicename 135 null, //description 136 null, //error 137 null//preferfolder 138 ); 139 return prop; 140 } 141 142 /** 143 * @see org.opencms.configuration.preferences.A_CmsPreference#isDisabled(org.opencms.file.CmsObject) 144 */ 145 @Override 146 public boolean isDisabled(CmsObject cms) { 147 148 return !OpenCms.getRoleManager().hasRole(cms, CmsRole.WORKPLACE_USER); 149 } 150 151}