001/* 002 * This library is part of OpenCms - 003 * the Open Source Content Management System 004 * 005 * Copyright (C) Alkacon Software (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.acacia.shared; 029 030import java.util.List; 031import java.util.Map; 032 033import com.google.gwt.user.client.rpc.IsSerializable; 034 035/** 036 * Contains all information defining a content entity type.<p> 037 */ 038public class CmsContentDefinition implements IsSerializable { 039 040 /** The name of the native renderer. */ 041 public static final String NATIVE_RENDERER = "native"; 042 043 /** The member name for the form rendering function. */ 044 public static final String FUNCTION_RENDER_FORM = "renderForm"; 045 046 /** The member name for the inline rendering function. */ 047 public static final String FUNCTION_RENDER_INLINE = "renderInline"; 048 049 /** The parameter name for the initialization function. */ 050 public static final String PARAM_INIT_CALL = "init"; 051 052 /** The attribute configurations. */ 053 private Map<String, CmsAttributeConfiguration> m_configurations; 054 055 /** The locale specific entities. */ 056 private Map<String, CmsEntity> m_entities; 057 058 /** The entity. */ 059 private String m_entityId; 060 061 /** Indicates if optional fields should be grouped together. */ 062 private boolean m_groupOptionalFields; 063 064 /** The content locale. */ 065 private String m_locale; 066 067 /** The tab information beans. */ 068 private List<CmsTabInfo> m_tabInfos; 069 070 /** The types defining the entity. */ 071 private Map<String, CmsType> m_types; 072 073 /** 074 * Constructor.<p> 075 * 076 * @param entityId the entity id 077 * @param entities the locale specific entities 078 * @param configurations the attribute configurations 079 * @param types the types 080 * @param tabInfos the tab information beans 081 * @param groupOptionalFields <code>true</code> if optional fields should be grouped together 082 * @param locale the content locale 083 */ 084 public CmsContentDefinition( 085 String entityId, 086 Map<String, CmsEntity> entities, 087 Map<String, CmsAttributeConfiguration> configurations, 088 Map<String, CmsType> types, 089 List<CmsTabInfo> tabInfos, 090 boolean groupOptionalFields, 091 String locale) { 092 093 m_entityId = entityId; 094 m_entities = entities; 095 m_configurations = configurations; 096 m_types = types; 097 m_tabInfos = tabInfos; 098 m_groupOptionalFields = groupOptionalFields; 099 m_locale = locale; 100 } 101 102 /** 103 * Constructor. Used for serialization only.<p> 104 */ 105 protected CmsContentDefinition() { 106 107 // nothing to do 108 } 109 110 /** 111 * Extracts the attribute index from the given attribute name where the index is appended to the name like 'attributename[1]'.<p> 112 * 113 * @param attributeName the attribute name 114 * 115 * @return the extracted index 116 */ 117 public static int extractIndex(String attributeName) { 118 119 int index = 0; 120 // check if the value index is appended to the attribute name 121 if (hasIndex(attributeName)) { 122 try { 123 String temp = attributeName.substring(attributeName.lastIndexOf("[") + 1, attributeName.length() - 1); 124 125 index = Integer.parseInt(temp); 126 } catch (NumberFormatException e) { 127 // ignore 128 } 129 } 130 return index; 131 } 132 133 /** 134 * Checks if the given XPATH component has an index.<p> 135 * 136 * @param pathComponent the path component 137 * 138 * @return true if the argument contains an index 139 */ 140 public static boolean hasIndex(String pathComponent) { 141 142 return pathComponent.endsWith("]") && pathComponent.contains("["); 143 } 144 145 /** 146 * Removes an attribute index suffix from the given attribute name.<p> 147 * 148 * @param attributeName the attribute name 149 * 150 * @return the attribute name 151 */ 152 public static String removeIndex(String attributeName) { 153 154 if (hasIndex(attributeName)) { 155 attributeName = attributeName.substring(0, attributeName.lastIndexOf("[")); 156 } 157 return attributeName; 158 } 159 160 /** 161 * Returns the attribute configurations.<p> 162 * 163 * @return the attribute configurations 164 */ 165 public Map<String, CmsAttributeConfiguration> getConfigurations() { 166 167 return m_configurations; 168 } 169 170 /** 171 * Returns the locale specific entities of the content.<p> 172 * 173 * @return the locale specific entities of the content 174 */ 175 public Map<String, CmsEntity> getEntities() { 176 177 return m_entities; 178 } 179 180 /** 181 * Returns the entity.<p> 182 * 183 * @return the entity 184 */ 185 public CmsEntity getEntity() { 186 187 return m_entities.get(m_entityId); 188 } 189 190 /** 191 * Returns the entity id.<p> 192 * 193 * @return the entity id 194 */ 195 public String getEntityId() { 196 197 return m_entityId; 198 } 199 200 /** 201 * Returns the entity type name.<p> 202 * 203 * @return the entity type name 204 */ 205 public String getEntityTypeName() { 206 207 return getEntity().getTypeName(); 208 } 209 210 /** 211 * Returns the locale.<p> 212 * 213 * @return the locale 214 */ 215 public String getLocale() { 216 217 return m_locale; 218 } 219 220 /** 221 * Returns the tab information beans.<p> 222 * 223 * @return the tab information beans 224 */ 225 public List<CmsTabInfo> getTabInfos() { 226 227 return m_tabInfos; 228 } 229 230 /** 231 * Returns the types.<p> 232 * 233 * @return the types 234 */ 235 public Map<String, CmsType> getTypes() { 236 237 return m_types; 238 } 239 240 /** 241 * Returns if optional fields should be grouped together.<p> 242 * 243 * @return <code>true</code> if optional fields should be grouped together 244 */ 245 public boolean isGroupOptionalFields() { 246 247 return m_groupOptionalFields; 248 } 249}