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 GmbH & Co. KG, 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.xml.content; 029 030import org.opencms.util.CmsStringUtil; 031 032/** 033 * Represents a configured tab to be used in the XML content editor for better usability.<p> 034 */ 035public class CmsXmlContentTab { 036 037 /** Indicates if the first level of left labels should be shown in the editor. */ 038 private boolean m_collapsed; 039 040 /** The name for the tab ID, generated from the start name. */ 041 private String m_idName; 042 043 /** The XML element name where this tab starts. */ 044 private String m_startName; 045 046 /** Description of this tab. */ 047 private String m_description; 048 049 /** The name to display on the tab. */ 050 private String m_tabName; 051 052 /** 053 * Constructor with the start element name.<p> 054 * 055 * The tab name is equal to the element name and the first level should not be shown in the editor.<p> 056 * 057 * @param startName the XML element name where this tab starts 058 */ 059 public CmsXmlContentTab(String startName) { 060 061 this(startName, true, startName, null); 062 } 063 064 /** 065 * Constructor with all possible tab parameter settings.<p> 066 * 067 * @param startName XML element name where this tab starts 068 * @param collapsed indicates if the first level of left labels should be shown in the editor 069 * @param tabName the name to display on the tab 070 * @param description the tab description HTML 071 */ 072 public CmsXmlContentTab(String startName, boolean collapsed, String tabName, String description) { 073 074 m_startName = startName; 075 m_collapsed = collapsed; 076 m_tabName = tabName; 077 m_description = description; 078 } 079 080 /** 081 * @see java.lang.Object#equals(java.lang.Object) 082 */ 083 @Override 084 public boolean equals(Object obj) { 085 086 if (obj == this) { 087 return true; 088 } 089 if (obj instanceof CmsXmlContentTab) { 090 return ((CmsXmlContentTab)obj).getStartName().equals(getStartName()); 091 } 092 return false; 093 } 094 095 /** 096 * Gets the tab description HTML.<p> 097 * 098 * @return the tab description HTML 099 */ 100 public String getDescription() { 101 102 return m_description; 103 } 104 105 /** 106 * Returns the name for the tab ID, generated from the start name.<p> 107 * 108 * @return the name for the tab ID, generated from the start name 109 */ 110 public String getIdName() { 111 112 if (m_idName == null) { 113 m_idName = getStartName(); 114 // remove special characters causing problems in ID attributes 115 m_idName = CmsStringUtil.substitute(m_idName, ".", "-"); 116 m_idName = CmsStringUtil.substitute(m_idName, ":", "-"); 117 m_idName = CmsStringUtil.substitute(m_idName, "_", "-"); 118 119 } 120 return m_idName; 121 } 122 123 /** 124 * Returns the XML element name where this tab starts.<p> 125 * 126 * @return the XML element name where this tab starts 127 */ 128 public String getStartName() { 129 130 return m_startName; 131 } 132 133 /** 134 * Returns the name to display on the tab.<p> 135 * 136 * @return the name to display on the tab 137 */ 138 public String getTabName() { 139 140 return m_tabName; 141 } 142 143 /** 144 * @see java.lang.Object#hashCode() 145 */ 146 @Override 147 public int hashCode() { 148 149 return getStartName().hashCode(); 150 } 151 152 /** 153 * Indicates if the first level of left labels should be shown in the editor.<p> 154 * 155 * @return <code>true</code> if the first level of left labels should NOT be shown in the editor 156 */ 157 public boolean isCollapsed() { 158 159 return m_collapsed; 160 } 161 162}