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.db; 029 030import org.opencms.file.CmsResource; 031 032import java.io.Serializable; 033 034/** 035 * Enumeration class for the different resource states.<p> 036 * 037 * @since 6.5.3 038 */ 039public class CmsResourceState implements Serializable { 040 041 /** Indicates if a resource has been changed in the offline version when compared to the online version. */ 042 public static final CmsResourceState STATE_CHANGED = new CmsResourceState(1, 'C'); 043 044 /** Indicates if a resource has been deleted in the offline version when compared to the online version. */ 045 public static final CmsResourceState STATE_DELETED = new CmsResourceState(3, 'D'); 046 047 /** 048 * Special state value that indicates the current state must be kept on a resource, 049 * this value must never be written to the database. 050 */ 051 public static final CmsResourceState STATE_KEEP = new CmsResourceState(99, '_'); 052 053 /** Indicates if a resource is new in the offline version when compared to the online version. */ 054 public static final CmsResourceState STATE_NEW = new CmsResourceState(2, 'N'); 055 056 /** Indicates if a resource is unchanged in the offline version when compared to the online version. */ 057 public static final CmsResourceState STATE_UNCHANGED = new CmsResourceState(0, 'U'); 058 059 /** serializable version id. */ 060 private static final long serialVersionUID = -2704354453252295414L; 061 062 /** The state abbreviation character. */ 063 private char m_abbrev; 064 065 /** The integer state representation. */ 066 private int m_state; 067 068 /** 069 * Default constructor for serialization.<p> 070 * 071 * @deprecated Don't use this constructor! 072 * It is only used to transfer the resource state via RPC call. 073 */ 074 @Deprecated 075 protected CmsResourceState() { 076 077 // noop 078 } 079 080 /** 081 * protected constructor.<p> 082 * 083 * @param state an integer representing the state 084 * @param abbrev an abbreviation character 085 */ 086 protected CmsResourceState(int state, char abbrev) { 087 088 m_state = state; 089 m_abbrev = abbrev; 090 } 091 092 /** 093 * Returns the resource state object from the resource state integer.<p> 094 * 095 * @param state the resource state integer 096 * 097 * @return the resource state object 098 */ 099 public static CmsResourceState valueOf(int state) { 100 101 switch (state) { 102 case 0: 103 return CmsResource.STATE_UNCHANGED; 104 case 1: 105 return CmsResource.STATE_CHANGED; 106 case 2: 107 return CmsResource.STATE_NEW; 108 case 3: 109 return CmsResource.STATE_DELETED; 110 case 99: 111 default: 112 return CmsResource.STATE_KEEP; 113 } 114 } 115 116 /** 117 * @see java.lang.Object#equals(java.lang.Object) 118 */ 119 @Override 120 public boolean equals(Object obj) { 121 122 return (obj instanceof CmsResourceState) && (((CmsResourceState)obj).m_state == m_state); 123 } 124 125 /** 126 * Returns resource state abbreviation.<p> 127 * 128 * @return resource state abbreviation 129 */ 130 public char getAbbreviation() { 131 132 return m_abbrev; 133 } 134 135 /** 136 * Returns the resource state integer for this resource state object.<p> 137 * 138 * @return the resource state integer for this resource state object 139 */ 140 public int getState() { 141 142 return m_state; 143 } 144 145 /** 146 * @see java.lang.Object#hashCode() 147 */ 148 @Override 149 public int hashCode() { 150 151 return Integer.valueOf(m_state).hashCode(); 152 } 153 154 /** 155 * Returns if this is {@link CmsResource#STATE_CHANGED}.<p> 156 * 157 * @return if this is {@link CmsResource#STATE_CHANGED} 158 */ 159 public boolean isChanged() { 160 161 return (equals(CmsResource.STATE_CHANGED)); 162 } 163 164 /** 165 * Returns if this is {@link CmsResource#STATE_DELETED}.<p> 166 * 167 * @return if this is {@link CmsResource#STATE_DELETED} 168 */ 169 public boolean isDeleted() { 170 171 return (equals(CmsResource.STATE_DELETED)); 172 } 173 174 /** 175 * Returns if this is {@link CmsResource#STATE_KEEP}.<p> 176 * 177 * @return if this is {@link CmsResource#STATE_KEEP} 178 */ 179 public boolean isKeep() { 180 181 return (equals(CmsResource.STATE_KEEP)); 182 } 183 184 /** 185 * Returns if this is {@link CmsResource#STATE_NEW}.<p> 186 * 187 * @return if this is {@link CmsResource#STATE_NEW} 188 */ 189 public boolean isNew() { 190 191 return (equals(CmsResource.STATE_NEW)); 192 } 193 194 /** 195 * Returns if this is {@link CmsResource#STATE_UNCHANGED}.<p> 196 * 197 * @return if this is {@link CmsResource#STATE_UNCHANGED} 198 */ 199 public boolean isUnchanged() { 200 201 return (equals(CmsResource.STATE_UNCHANGED)); 202 } 203 204 /** 205 * @see java.lang.Object#toString() 206 */ 207 @Override 208 public String toString() { 209 210 return String.valueOf(getState()); 211 } 212}