001: /*
002: * File : $Source: /usr/local/cvs/opencms/src/org/opencms/db/CmsResourceState.java,v $
003: * Date : $Date: 2008-02-27 12:05:43 $
004: * Version: $Revision: 1.4 $
005: *
006: * This library is part of OpenCms -
007: * the Open Source Content Management System
008: *
009: * Copyright (c) 2002 - 2008 Alkacon Software GmbH (http://www.alkacon.com)
010: *
011: * This library is free software; you can redistribute it and/or
012: * modify it under the terms of the GNU Lesser General Public
013: * License as published by the Free Software Foundation; either
014: * version 2.1 of the License, or (at your option) any later version.
015: *
016: * This library is distributed in the hope that it will be useful,
017: * but WITHOUT ANY WARRANTY; without even the implied warranty of
018: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
019: * Lesser General Public License for more details.
020: *
021: * For further information about Alkacon Software GmbH, please see the
022: * company website: http://www.alkacon.com
023: *
024: * For further information about OpenCms, please see the
025: * project website: http://www.opencms.org
026: *
027: * You should have received a copy of the GNU Lesser General Public
028: * License along with this library; if not, write to the Free Software
029: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
030: */
031:
032: package org.opencms.db;
033:
034: import org.opencms.file.CmsResource;
035:
036: import java.io.Serializable;
037:
038: /**
039: * Enumeration class for the different resource states.<p>
040: *
041: * @author Michael Moossen
042: *
043: * @version $Revision: 1.4 $
044: *
045: * @since 6.5.3
046: */
047: public class CmsResourceState implements Serializable {
048:
049: /** serializable version id. */
050: private static final long serialVersionUID = -2704354453252295414L;
051:
052: /** Indicates if a resource has been changed in the offline version when compared to the online version. */
053: public static final CmsResourceState STATE_CHANGED = new CmsResourceState(
054: 1, 'C');
055:
056: /** Indicates if a resource has been deleted in the offline version when compared to the online version. */
057: public static final CmsResourceState STATE_DELETED = new CmsResourceState(
058: 3, 'D');
059:
060: /**
061: * Special state value that indicates the current state must be kept on a resource,
062: * this value must never be written to the database.
063: */
064: public static final CmsResourceState STATE_KEEP = new CmsResourceState(
065: 99, '_');
066:
067: /** Indicates if a resource is new in the offline version when compared to the online version. */
068: public static final CmsResourceState STATE_NEW = new CmsResourceState(
069: 2, 'N');
070:
071: /** Indicates if a resource is unchanged in the offline version when compared to the online version. */
072: public static final CmsResourceState STATE_UNCHANGED = new CmsResourceState(
073: 0, 'U');
074:
075: /** The state abbreviation character. */
076: private char m_abbrev;
077:
078: /** The integer state representation. */
079: private int m_state;
080:
081: /**
082: * protected constructor.<p>
083: *
084: * @param state an integer representing the state
085: * @param abbrev an abbreviation character
086: */
087: protected CmsResourceState(int state, char abbrev) {
088:
089: m_state = state;
090: m_abbrev = abbrev;
091: }
092:
093: /**
094: * Returns the resource state object from the resource state integer.<p>
095: *
096: * @param state the resource state integer
097: *
098: * @return the resource state object
099: */
100: public static CmsResourceState valueOf(int state) {
101:
102: switch (state) {
103: case 0:
104: return CmsResource.STATE_UNCHANGED;
105: case 1:
106: return CmsResource.STATE_CHANGED;
107: case 2:
108: return CmsResource.STATE_NEW;
109: case 3:
110: return CmsResource.STATE_DELETED;
111: case 99:
112: default:
113: return CmsResource.STATE_KEEP;
114: }
115: }
116:
117: /**
118: * Returns resource state abbreviation.<p>
119: *
120: * @return resource state abbreviation
121: */
122: public char getAbbreviation() {
123:
124: return m_abbrev;
125: }
126:
127: /**
128: * Returns the resource state integer for this resource state object.<p>
129: *
130: * @return the resource state integer for this resource state object
131: */
132: public int getState() {
133:
134: return m_state;
135: }
136:
137: /**
138: * Returns if this is {@link CmsResource#STATE_CHANGED}.<p>
139: *
140: * @return if this is {@link CmsResource#STATE_CHANGED}
141: */
142: public boolean isChanged() {
143:
144: return (this == CmsResource.STATE_CHANGED);
145: }
146:
147: /**
148: * Returns if this is {@link CmsResource#STATE_DELETED}.<p>
149: *
150: * @return if this is {@link CmsResource#STATE_DELETED}
151: */
152: public boolean isDeleted() {
153:
154: return (this == CmsResource.STATE_DELETED);
155: }
156:
157: /**
158: * Returns if this is {@link CmsResource#STATE_KEEP}.<p>
159: *
160: * @return if this is {@link CmsResource#STATE_KEEP}
161: */
162: public boolean isKeep() {
163:
164: return (this == CmsResource.STATE_KEEP);
165: }
166:
167: /**
168: * Returns if this is {@link CmsResource#STATE_NEW}.<p>
169: *
170: * @return if this is {@link CmsResource#STATE_NEW}
171: */
172: public boolean isNew() {
173:
174: return (this == CmsResource.STATE_NEW);
175: }
176:
177: /**
178: * Returns if this is {@link CmsResource#STATE_UNCHANGED}.<p>
179: *
180: * @return if this is {@link CmsResource#STATE_UNCHANGED}
181: */
182: public boolean isUnchanged() {
183:
184: return (this == CmsResource.STATE_UNCHANGED);
185: }
186:
187: /**
188: * @see java.lang.Object#toString()
189: */
190: public String toString() {
191:
192: return String.valueOf(getState());
193: }
194: }
|