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.ade.detailpage; 029 030import org.opencms.util.CmsUUID; 031import org.opencms.xml.containerpage.CmsXmlDynamicFunctionHandler; 032 033import java.io.Serializable; 034 035/** 036 * Data bean containing the information for a detail page.<p> 037 * 038 * @since 8.0.0 039 */ 040public class CmsDetailPageInfo implements Serializable { 041 042 /** The prefix for dynamic function detail page types. */ 043 public static final String FUNCTION_PREFIX = "function@"; 044 045 /** ID for serialization. */ 046 private static final long serialVersionUID = 7714334294682534900L; 047 048 /** The resource icon style classes. */ 049 private String m_iconClasses; 050 051 /** The id of the detail page. */ 052 private CmsUUID m_id; 053 054 /** Flag used to distinguish inherited detail pages from ones defined in the current sitemap config. */ 055 private boolean m_inherited; 056 057 /** The resource type which the detail page should display. */ 058 private String m_type; 059 060 /** The original URI of the detail page (for debugging purposes only). */ 061 private String m_uri; 062 063 /** 064 * Creates a new detail page info bean.<p> 065 * 066 * @param id the id of the detail page 067 * @param uri the original URI of the page 068 * @param type the resource type for which the detail page is used 069 * @param iconClasses the resource icon style classes 070 */ 071 public CmsDetailPageInfo(CmsUUID id, String uri, String type, String iconClasses) { 072 073 m_id = id; 074 m_type = type; 075 m_uri = uri; 076 m_iconClasses = iconClasses; 077 } 078 079 /** 080 * Empty default constructor for serialization.<p> 081 */ 082 protected CmsDetailPageInfo() { 083 084 // for serialization 085 } 086 087 /** 088 * Removes the prefix for dynamic functions from a detail page type name.<p> 089 * 090 * @param name the detail page type name 091 * 092 * @return the detail page type name withotu the function prefix 093 */ 094 public static String removeFunctionPrefix(String name) { 095 096 return name.replaceFirst("^" + FUNCTION_PREFIX, ""); 097 } 098 099 /** 100 * Creates a copy of this entry, but sets the 'inherited' flag to true in the copy.<p> 101 * 102 * @return the copy of this entry 103 */ 104 public CmsDetailPageInfo copyAsInherited() { 105 106 CmsDetailPageInfo result = new CmsDetailPageInfo(m_id, m_uri, m_type, m_iconClasses); 107 result.m_inherited = true; 108 return result; 109 } 110 111 /** 112 * @see java.lang.Object#equals(java.lang.Object) 113 */ 114 @Override 115 public boolean equals(Object obj) { 116 117 boolean result = false; 118 if (obj instanceof CmsDetailPageInfo) { 119 CmsDetailPageInfo info = (CmsDetailPageInfo)obj; 120 result = toString().equals(info.toString()); 121 } 122 return result; 123 } 124 125 /** 126 * Gets the type name to display to the user.<p> 127 * 128 * @return the type name to display 129 */ 130 public String getDisplayType() { 131 132 return m_type != null ? removeFunctionPrefix(m_type) : ""; 133 } 134 135 /** 136 * Returns the resource icon style classes.<p> 137 * 138 * @return the resource icon style classes 139 **/ 140 public String getIconClasses() { 141 142 return m_iconClasses; 143 } 144 145 /** 146 * Returns the resource type name for the icon to display.<p> 147 * 148 * @return the icon resource type 149 */ 150 public String getIconType() { 151 152 if (m_type.startsWith(FUNCTION_PREFIX)) { 153 return CmsXmlDynamicFunctionHandler.TYPE_FUNCTION; 154 } else { 155 return m_type; 156 } 157 } 158 159 /** 160 * Returns the id of the detail page.<p> 161 * 162 * @return the id of the detail page 163 */ 164 public CmsUUID getId() { 165 166 return m_id; 167 } 168 169 /** 170 * Returns the type for which the detail page is used.<p> 171 * 172 * @return the type for which the detail page is used 173 */ 174 public String getType() { 175 176 return m_type; 177 } 178 179 /** 180 * The original URI for the detail page.<p> 181 * 182 * @return the original URI for the detail page 183 */ 184 public String getUri() { 185 186 return m_uri; 187 } 188 189 /** 190 * @see java.lang.Object#hashCode() 191 */ 192 @Override 193 public int hashCode() { 194 195 return toString().hashCode(); 196 } 197 198 /** 199 * Returns true if the detail page entry is inherited from a parent sitemap.<p> 200 * 201 * @return true if the detail page entry is inherited from a parent sitemap 202 */ 203 public boolean isInherited() { 204 205 return m_inherited; 206 } 207 208 /** 209 * @see java.lang.Object#toString() 210 */ 211 @Override 212 public String toString() { 213 214 return "" + m_type + ":" + m_id + m_uri; 215 } 216}