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.configuration.CmsDefaultUserSettings; 031import org.opencms.file.CmsObject; 032import org.opencms.xml.content.CmsXmlContentProperty; 033 034import org.dom4j.Element; 035 036/** 037 * Wrapper used for built-in preferene which have also been configured in opencms-workplace.xml.<p> 038 */ 039public class CmsWrapperPreference implements I_CmsPreference { 040 041 /** The configured preference data. */ 042 private CmsPreferenceData m_prefData; 043 044 /** The preference being wrapped. */ 045 private I_CmsPreference m_wrappedPreference; 046 047 /** 048 * Creates a new instance.<p> 049 * 050 * @param prefData the configured preference data 051 * 052 * @param wrappedPref the preference being wrapped 053 */ 054 public CmsWrapperPreference(CmsPreferenceData prefData, I_CmsPreference wrappedPref) { 055 056 m_prefData = prefData; 057 m_wrappedPreference = wrappedPref; 058 } 059 060 /** 061 * @see org.opencms.configuration.preferences.I_CmsPreference#createConfigurationItem() 062 */ 063 public Element createConfigurationItem() { 064 065 Element elem = m_wrappedPreference.createConfigurationItem(); 066 CmsUserDefinedPreference.fillAttributes(m_prefData, elem); 067 return elem; 068 } 069 070 /** 071 * @see org.opencms.configuration.preferences.I_CmsPreference#getDefaultValue() 072 */ 073 public String getDefaultValue() { 074 075 return firstNotNull(m_prefData.getDefaultValue(), m_wrappedPreference.getDefaultValue()); 076 } 077 078 /** 079 * @see org.opencms.configuration.preferences.I_CmsPreference#getName() 080 */ 081 public String getName() { 082 083 return m_wrappedPreference.getName(); 084 } 085 086 /** 087 * @see org.opencms.configuration.preferences.I_CmsPreference#getPropertyDefinition(org.opencms.file.CmsObject) 088 */ 089 @Override 090 public CmsXmlContentProperty getPropertyDefinition(CmsObject cms) { 091 092 CmsXmlContentProperty configProp = m_prefData.getPropertyDefinition(); 093 CmsXmlContentProperty wrappedProp = m_wrappedPreference.getPropertyDefinition(cms); 094 095 CmsXmlContentProperty prop = new CmsXmlContentProperty( 096 getName(), //name 097 "string", //type 098 firstNotNull(configProp.getConfiguredWidget(), wrappedProp.getConfiguredWidget()), //widget 099 firstNotNull(configProp.getWidgetConfiguration(), wrappedProp.getWidgetConfiguration()), //widgetconfig 100 firstNotNull(configProp.getRuleRegex(), wrappedProp.getRuleRegex()), //regex 101 firstNotNull(configProp.getRuleType(), wrappedProp.getRuleType()), //ruletype 102 firstNotNull(configProp.getDefault(), wrappedProp.getDefault()), 103 firstNotNull(configProp.getNiceName(), wrappedProp.getNiceName()), //nicename 104 firstNotNull(configProp.getDescription(), wrappedProp.getDescription()), //description 105 firstNotNull(configProp.getError(), wrappedProp.getError()), //error 106 null//preferfolder 107 ); 108 109 return prop; 110 } 111 112 /** 113 * @see org.opencms.configuration.preferences.I_CmsPreference#getTab() 114 */ 115 public String getTab() { 116 117 return firstNotNull(m_prefData.getTab(), m_wrappedPreference.getTab()); 118 } 119 120 /** 121 * @see org.opencms.configuration.preferences.I_CmsPreference#getValue(org.opencms.configuration.CmsDefaultUserSettings) 122 */ 123 public String getValue(CmsDefaultUserSettings userSettings) { 124 125 return m_wrappedPreference.getValue(userSettings); 126 } 127 128 /** 129 * @see org.opencms.configuration.preferences.I_CmsPreference#isDisabled(CmsObject) 130 */ 131 public boolean isDisabled(CmsObject cms) { 132 133 return m_wrappedPreference.isDisabled(cms); 134 } 135 136 /** 137 * @see org.opencms.configuration.preferences.I_CmsPreference#setValue(org.opencms.configuration.CmsDefaultUserSettings, java.lang.String) 138 */ 139 public void setValue(CmsDefaultUserSettings settings, String value) { 140 141 m_wrappedPreference.setValue(settings, value); 142 } 143 144 /** 145 * Returns the first non-null value.<p> 146 * 147 * @param a a value 148 * @param b another value 149 * 150 * @return the first non-null value 151 */ 152 String firstNotNull(String a, String b) { 153 154 return a != null ? a : b; 155 } 156 157}