org.opencms.ade.sitemap.shared.CmsSitemapChange Maven / Gradle / Ivy
Show all versions of opencms-test Show documentation
/*
* This library is part of OpenCms -
* the Open Source Content Management System
*
* Copyright (c) Alkacon Software GmbH & Co. KG (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.ade.sitemap.shared;
import org.opencms.ade.detailpage.CmsDetailPageInfo;
import org.opencms.file.CmsResource;
import org.opencms.gwt.shared.property.CmsClientProperty;
import org.opencms.gwt.shared.property.CmsPropertyModification;
import org.opencms.util.CmsUUID;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import com.google.gwt.user.client.rpc.IsSerializable;
/**
* Bean containing sitemap entry change information.
*
* @since 8.0.0
*/
public class CmsSitemapChange implements IsSerializable, Comparable {
/** The change types. */
public enum ChangeType {
/** Making a detail page the default. */
bumpDetailPage, /** The clip-board only change. */
clipboardOnly, /** The create/new change. */
create, /** The delete resource change. */
delete, /** The modify change. */
modify, /** The remove from navigation change. */
remove, /** The undelete resource change. */
undelete
}
/** The change type. */
private ChangeType m_changeType;
/** The changed clip-board data. */
private CmsSitemapClipboardData m_clipBoardData;
/** The folder type to use when a subsitemap should be created, else null. */
private String m_createSitemapFolderType;
/** The default file id. */
private CmsUUID m_defaultFileId;
/** The default file's properties. */
private Map m_defaultFileInternalProperties = new HashMap();
/** Detail page info's to change. */
private List m_detailPageInfos;
/** The entry id. */
private CmsUUID m_entryId;
/** Indicates if the entry to change is a leaf type entry. */
private boolean m_isLeafType;
/** The entry name. */
private String m_name;
/** The new entry copy resource structure id. */
private CmsUUID m_newCopyResourceId;
/** The new entry resource type id. */
private int m_newResourceTypeId;
/** The changed entry's own properties. */
private Map m_ownInternalProperties = new HashMap();
/** An additional parameter which may contain additional information for creating a new resource. */
private String m_parameter;
/** The entry parent id. */
private CmsUUID m_parentId;
/** The entry position.*/
private int m_position = -1;
/** The list of property modifications. */
private List m_propertyModifications = new ArrayList();
/** The entry site path. */
private String m_sitePath;
/** The updated entry. */
private CmsClientSitemapEntry m_updatedEntry;
/**
* Constructor needed for serialization.
*/
public CmsSitemapChange() {
// nothing to do
}
/**
* Constructor.
*
* @param entryId entry id
* @param sitePath the entry site-path
* @param changeType the change type
*/
public CmsSitemapChange(CmsUUID entryId, String sitePath, ChangeType changeType) {
m_entryId = entryId;
m_sitePath = sitePath;
m_changeType = changeType;
}
/**
* Adds the given change data to this change object.
*
* @param data the change data to add
*/
public void addChangeData(CmsSitemapChange data) {
if (data == null) {
return;
}
if (!m_entryId.equals(data.m_entryId)) {
throw new UnsupportedOperationException("Can't add data for a different entry id.");
}
m_sitePath = data.m_sitePath;
if (data.hasChangedName()) {
m_name = data.m_name;
}
if (data.hasChangedPosition()) {
m_position = data.m_position;
}
if (data.hasChangedProperties()) {
m_propertyModifications.addAll(data.m_propertyModifications);
}
if (data.hasNewParent()) {
m_parentId = data.m_parentId;
}
if (data.getClipBoardData() != null) {
m_clipBoardData = data.getClipBoardData();
}
if ((data.m_changeType == ChangeType.delete)
|| ((data.m_changeType == ChangeType.remove) && (m_changeType != ChangeType.delete))
|| (m_changeType == ChangeType.clipboardOnly)) {
m_changeType = data.m_changeType;
}
}
/**
* Adds a property change for a changed title.
*
* @param title the changed title
*/
public void addChangeTitle(String title) {
CmsPropertyModification propChange = new CmsPropertyModification(
m_entryId,
CmsClientProperty.PROPERTY_NAVTEXT,
title,
true);
m_propertyModifications.add(propChange);
m_ownInternalProperties.put("NavText", new CmsClientProperty("NavText", title, null));
}
/**
* Will compare the parent site path and the position of the entry to change.
*
* @see java.lang.Comparable#compareTo(java.lang.Object)
*/
public int compareTo(CmsSitemapChange arg0) {
if (m_entryId.equals(arg0.m_entryId)) {
return 0;
}
int result = CmsResource.getParentFolder(m_sitePath).compareTo(CmsResource.getParentFolder(arg0.m_sitePath));
if (result == 0) {
result = m_position - arg0.m_position;
if (result == 0) {
// two different entries should never have the same parent and the same name, so this compare should be sufficient
result = m_name.compareTo(arg0.m_name);
}
}
return result;
}
/**
* Two sitemap change objects are considered equal, if the entry id's are equal.
*
* @see java.lang.Object#equals(java.lang.Object)
*/
@Override
public boolean equals(Object obj) {
if (obj instanceof CmsSitemapChange) {
return m_entryId.equals(((CmsSitemapChange)obj).m_entryId);
}
return false;
}
/**
* Returns the change type.
*
* @return the change type
*/
public ChangeType getChangeType() {
return m_changeType;
}
/**
* Returns the clip-board data.
*
* @return the clip-board data
*/
public CmsSitemapClipboardData getClipBoardData() {
return m_clipBoardData;
}
/**
* Returns an additional parameter for creating new resources.
*
* @return an additional parameter which may contain information needed to create new resources
*/
public String getCreateParameter() {
return m_parameter;
}
/**
* Gets the folder type to use if a subsitemap should be created, else null.
*
* @return a resource type name
*/
public String getCreateSitemapFolderType() {
return m_createSitemapFolderType;
}
/**
* Gets the default file id.
*
* @return the default file id
*/
public CmsUUID getDefaultFileId() {
return m_defaultFileId;
}
/**
* Returns the change'S properties for the default file.
*
* @return the properties for the default file
*/
public Map getDefaultFileProperties() {
return m_defaultFileInternalProperties;
}
/**
* Returns the detail page info's.
*
* @return the detail page info's
*/
public List getDetailPageInfos() {
return m_detailPageInfos;
}
/**
* Returns the entry id.
*
* @return the entry id
*/
public CmsUUID getEntryId() {
return m_entryId;
}
/**
* Returns the entry name.
*
* @return the entry name
*/
public String getName() {
return m_name;
}
/**
* Returns the new entry copy resource structure id.
*
* @return the new entry copy resource structure id
*/
public CmsUUID getNewCopyResourceId() {
return m_newCopyResourceId;
}
/**
* Returns the new entry resource type id.
*
* @return the new entry resource type id
*/
public int getNewResourceTypeId() {
return m_newResourceTypeId;
}
/**
* Returns the properties for the entry itself.
*
* @return the properties for the entry itself
*/
public Map getOwnInternalProperties() {
return m_ownInternalProperties;
}
/**
* Returns the change's properties for the entry itself.
*
* @return the change's properties for the entry itself
*/
public Map getOwnProperties() {
return m_ownInternalProperties;
}
/**
* Returns the entry parent id.
*
* @return the entry parent id
*/
public CmsUUID getParentId() {
return m_parentId;
}
/**
* Returns the entry position.
*
* @return the entry position
*/
public int getPosition() {
return m_position;
}
/**
* Gets the list of property changes.
*
* @return the list of property changes
*/
public List getPropertyChanges() {
return m_propertyModifications;
}
/**
* Returns the site-path.
*
* @return the site-path
*/
public String getSitePath() {
return m_sitePath;
}
/**
* Returns the updated entry.
*
* @return the updated entry
*/
public CmsClientSitemapEntry getUpdatedEntry() {
return m_updatedEntry;
}
/**
* Returns if the entry name has changed.
*
* @return true
if the entry name has changed
*/
public boolean hasChangedName() {
return m_name != null;
}
/**
* Returns if the position has changed.
*
* @return true
if the position has changed
*/
public boolean hasChangedPosition() {
return m_position >= 0;
}
/**
* Returns if there are changed properties.
*
* @return true
if there are changed properties
*/
public boolean hasChangedProperties() {
return (m_propertyModifications != null) && (m_propertyModifications.size() > 0);
}
/**
* Returns if detail page info's have changed.
*
* @return true
if detail page info's have changed
*/
public boolean hasDetailPageInfos() {
return m_detailPageInfos != null;
}
/**
* @see java.lang.Object#hashCode()
*/
@Override
public int hashCode() {
return m_entryId.hashCode();
}
/**
* Returns if this change sets a new parent.
*
* @return true
if the entry gets a new parent
*/
public boolean hasNewParent() {
return m_parentId != null;
}
/**
* Returns if this is a deleting change.
*
* @return the is delete flag
*/
public boolean isDelete() {
return ChangeType.delete == m_changeType;
}
/**
* Returns if the entry to change is a leaf type entry.
*
* @return true
if the entry to change is a leaf type entry
*/
public boolean isLeafType() {
return m_isLeafType;
}
/**
* Returns if this is a creating new change.
*
* @return the is new flag
*/
public boolean isNew() {
return ChangeType.create == m_changeType;
}
/**
* Returns if this is a remove from navigation change.
*
* @return the is new flag
*/
public boolean isRemove() {
return ChangeType.remove == m_changeType;
}
/**
* Sets the clip-board data.
*
* @param clipBoardData the clip-board data to set
*/
public void setClipBoardData(CmsSitemapClipboardData clipBoardData) {
m_clipBoardData = clipBoardData;
}
/**
* Sets additional info needed for creating new resources.
*
* @param parameter the additional resource creation information
*/
public void setCreateParameter(String parameter) {
m_parameter = parameter;
}
/**
* Sets the folder type name to use for creating a subsitemap.
*
* @param folderType a resource type name
*/
public void setCreateSitemapFolderType(String folderType) {
m_createSitemapFolderType = folderType;
}
/**
* Sets the default file id.
*
* @param id the default file id
*/
public void setDefaultFileId(CmsUUID id) {
m_defaultFileId = id;
}
/**
* Sets the properties for the default file.
*
* @param props the properties for the default file
*/
public void setDefaultFileInternalProperties(Map props) {
m_defaultFileInternalProperties = props;
}
/**
* Sets the detail page info's.
*
* @param detailPageInfos the detail page info's to set
*/
public void setDetailPageInfos(List detailPageInfos) {
m_detailPageInfos = detailPageInfos;
}
/**
* Sets the entry id.
*
* @param entryId the entry id to set
*/
public void setEntryId(CmsUUID entryId) {
m_entryId = entryId;
}
/**
* Sets if the entry to change is a leaf type entry.
*
* @param isLeafEntry true
if the entry to change is a leaf type entry
*/
public void setLeafType(boolean isLeafEntry) {
m_isLeafType = isLeafEntry;
}
/**
* Sets the entry name.
*
* @param name the entry name to set
*/
public void setName(String name) {
m_name = name;
}
/**
* Sets the new entry copy resource structure id.
*
* @param newCopyResourceId the new entry copy resource structure id to set
*/
public void setNewCopyResourceId(CmsUUID newCopyResourceId) {
m_newCopyResourceId = newCopyResourceId;
}
/**
* Sets the new entry resource type id.
*
* @param newResourceTypeId the new entry resource type id to set
*/
public void setNewResourceTypeId(int newResourceTypeId) {
m_newResourceTypeId = newResourceTypeId;
}
/**
* Sets the changed properties of the entry itself.
*
* @param props the entry's changed properties
*/
public void setOwnInternalProperties(Map props) {
m_ownInternalProperties = props;
}
/**
* Sets the entry parent id.
*
* @param parentId the entry parent id to set
*/
public void setParentId(CmsUUID parentId) {
m_parentId = parentId;
}
/**
* Sets the entry position.
*
* @param position the entry position to set
*/
public void setPosition(int position) {
m_position = position;
}
/**
* Sets the list of property changes.
*
* @param propertyChanges the property changes
*/
public void setPropertyChanges(List propertyChanges) {
m_propertyModifications = propertyChanges;
}
/**
* Sets the site path.
*
* @param sitePath the site path to set
*/
public void setSitePath(String sitePath) {
m_sitePath = sitePath;
}
/**
* Sets the title.
*
* @param title the title
*/
public void setTitle(String title) {
addChangeTitle(title);
}
/**
* Sets the updated entry.
*
* @param updatedEntry the updated entry to set
*/
public void setUpdatedEntry(CmsClientSitemapEntry updatedEntry) {
m_updatedEntry = updatedEntry;
}
}