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.jsp.util; 029 030import org.opencms.file.CmsObject; 031import org.opencms.util.CmsStringUtil; 032 033/** 034 * Element setting access wrapper.<p> 035 */ 036public class CmsJspElementSettingValueWrapper extends A_CmsJspValueWrapper { 037 038 /** Flag indicating the setting has been configured. */ 039 private boolean m_exists; 040 041 /** Calculated hash code. */ 042 private int m_hashCode; 043 044 /** The wrapped setting value, which always is a String. */ 045 private String m_value; 046 047 /** 048 * Constructor.<p> 049 * 050 * @param cms the CMS context 051 * @param value the wrapped value 052 * @param exists flag indicating the setting has been configured 053 */ 054 CmsJspElementSettingValueWrapper(CmsObject cms, String value, boolean exists) { 055 056 m_cms = cms; 057 m_value = value; 058 m_exists = exists; 059 } 060 061 /** 062 * Returns if the setting has been configured.<p> 063 * 064 * @return <code>true</code> if the setting has been configured 065 */ 066 @Override 067 public boolean getExists() { 068 069 return m_exists; 070 } 071 072 /** 073 * Returns if the setting value is null or empty.<p> 074 * 075 * @return <code>true</code> if the setting value is null or empty 076 */ 077 @Override 078 public boolean getIsEmpty() { 079 080 return !m_exists || CmsStringUtil.isEmpty(m_value); 081 } 082 083 /** 084 * Returns if the setting value is null or white space only.<p> 085 * 086 * @return <code>true</code> if the setting value is null or white space only 087 */ 088 @Override 089 public boolean getIsEmptyOrWhitespaceOnly() { 090 091 return !m_exists || CmsStringUtil.isEmptyOrWhitespaceOnly(m_value); 092 } 093 094 /** 095 * @see org.opencms.jsp.util.A_CmsJspValueWrapper#getObjectValue() 096 */ 097 @Override 098 public Object getObjectValue() { 099 100 return m_value; 101 } 102 103 /** 104 * Returns the raw value.<p> 105 * 106 * This may return <code>null</code>. 107 * 108 * @return the value 109 * 110 * @deprecated use {@link #getObjectValue()} instead 111 */ 112 @Deprecated 113 public String getValue() { 114 115 return m_value; 116 } 117 118 /** 119 * The hash code is based in the String value of the element setting.<p> 120 * 121 * @see org.opencms.jsp.util.A_CmsJspValueWrapper#hashCode() 122 */ 123 @Override 124 public int hashCode() { 125 126 if (m_value == null) { 127 return 0; 128 } 129 if (m_hashCode == 0) { 130 m_hashCode = m_value.hashCode(); 131 } 132 return m_hashCode; 133 } 134 135 /** 136 * Returns the string value.<p> 137 * 138 * This will always be at least an empty String <code>""</code>, never <code>null</code>. 139 * 140 * @return the string value 141 */ 142 @Override 143 public String toString() { 144 145 return m_value != null ? m_value : ""; 146 } 147}