org.opencms.acacia.shared.CmsContentDefinition Maven / Gradle / Ivy
Show all versions of opencms-gwt Show documentation
/*
* This library is part of OpenCms -
* the Open Source Content Management System
*
* Copyright (C) Alkacon Software (http://www.alkacon.com)
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* For further information about Alkacon Software, please see the
* company website: http://www.alkacon.com
*
* For further information about OpenCms, please see the
* project website: http://www.opencms.org
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
package org.opencms.acacia.shared;
import java.util.List;
import java.util.Map;
import com.google.gwt.user.client.rpc.IsSerializable;
/**
* Contains all information defining a content entity type.
*/
public class CmsContentDefinition implements IsSerializable {
/** The name of the native renderer. */
public static final String NATIVE_RENDERER = "native";
/** The member name for the form rendering function. */
public static final String FUNCTION_RENDER_FORM = "renderForm";
/** The member name for the inline rendering function. */
public static final String FUNCTION_RENDER_INLINE = "renderInline";
/** The parameter name for the initialization function. */
public static final String PARAM_INIT_CALL = "init";
/** The attribute configurations. */
private Map m_configurations;
/** The locale specific entities. */
private Map m_entities;
/** The entity. */
private String m_entityId;
/** Indicates if optional fields should be grouped together. */
private boolean m_groupOptionalFields;
/** The content locale. */
private String m_locale;
/** The tab information beans. */
private List m_tabInfos;
/** The types defining the entity. */
private Map m_types;
/**
* Constructor.
*
* @param entityId the entity id
* @param entities the locale specific entities
* @param configurations the attribute configurations
* @param types the types
* @param tabInfos the tab information beans
* @param groupOptionalFields true
if optional fields should be grouped together
* @param locale the content locale
*/
public CmsContentDefinition(
String entityId,
Map entities,
Map configurations,
Map types,
List tabInfos,
boolean groupOptionalFields,
String locale) {
m_entityId = entityId;
m_entities = entities;
m_configurations = configurations;
m_types = types;
m_tabInfos = tabInfos;
m_groupOptionalFields = groupOptionalFields;
m_locale = locale;
}
/**
* Constructor. Used for serialization only.
*/
protected CmsContentDefinition() {
// nothing to do
}
/**
* Extracts the attribute index from the given attribute name where the index is appended to the name like 'attributename[1]'.
*
* @param attributeName the attribute name
*
* @return the extracted index
*/
public static int extractIndex(String attributeName) {
int index = 0;
// check if the value index is appended to the attribute name
if (hasIndex(attributeName)) {
try {
String temp = attributeName.substring(attributeName.lastIndexOf("[") + 1, attributeName.length() - 1);
index = Integer.parseInt(temp);
} catch (NumberFormatException e) {
// ignore
}
}
return index;
}
/**
* Checks if the given XPATH component has an index.
*
* @param pathComponent the path component
*
* @return true if the argument contains an index
*/
public static boolean hasIndex(String pathComponent) {
return pathComponent.endsWith("]") && pathComponent.contains("[");
}
/**
* Removes an attribute index suffix from the given attribute name.
*
* @param attributeName the attribute name
*
* @return the attribute name
*/
public static String removeIndex(String attributeName) {
if (hasIndex(attributeName)) {
attributeName = attributeName.substring(0, attributeName.lastIndexOf("["));
}
return attributeName;
}
/**
* Returns the attribute configurations.
*
* @return the attribute configurations
*/
public Map getConfigurations() {
return m_configurations;
}
/**
* Returns the locale specific entities of the content.
*
* @return the locale specific entities of the content
*/
public Map getEntities() {
return m_entities;
}
/**
* Returns the entity.
*
* @return the entity
*/
public CmsEntity getEntity() {
return m_entities.get(m_entityId);
}
/**
* Returns the entity id.
*
* @return the entity id
*/
public String getEntityId() {
return m_entityId;
}
/**
* Returns the entity type name.
*
* @return the entity type name
*/
public String getEntityTypeName() {
return getEntity().getTypeName();
}
/**
* Returns the locale.
*
* @return the locale
*/
public String getLocale() {
return m_locale;
}
/**
* Returns the tab information beans.
*
* @return the tab information beans
*/
public List getTabInfos() {
return m_tabInfos;
}
/**
* Returns the types.
*
* @return the types
*/
public Map getTypes() {
return m_types;
}
/**
* Returns if optional fields should be grouped together.
*
* @return true
if optional fields should be grouped together
*/
public boolean isGroupOptionalFields() {
return m_groupOptionalFields;
}
}