001/* 002 * This library is part of OpenCms - 003 * the Open Source Content Management System 004 * 005 * Copyright (c) Alkacon Software GmbH & Co. KG (https://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: https://www.alkacon.com 019 * 020 * For further information about OpenCms, please see the 021 * project website: https://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.gwt.shared; 029 030import com.google.gwt.user.client.rpc.IsSerializable; 031 032/** 033 * Client side lock class.<p> 034 * 035 * @since 8.0.0 036 */ 037public class CmsClientLock implements IsSerializable { 038 039 /** 040 * The available lock types. Replace with {@link org.opencms.lock.CmsLockType} as soon that fulfills the serializable convention. 041 */ 042 public enum LockType { 043 044 /** 045 * A lock that allows the user to edit the resource's structure record, 046 * it's resource record, and its content record.<p> 047 * 048 * This lock is assigned to files that are locked via the context menu. 049 */ 050 EXCLUSIVE(4), 051 052 /** A lock that is inherited from a locked parent folder. */ 053 INHERITED(3), 054 055 /** A lock that indicates that the resource is waiting to be published in the publish queue. */ 056 PUBLISH(7), 057 058 /** 059 * A lock that allows the user to edit the resource's structure record only, 060 * but not it's resource record nor content record.<p> 061 * 062 * This lock is assigned to files if a sibling of the resource record has 063 * already an exclusive lock. 064 */ 065 SHARED_EXCLUSIVE(2), 066 067 /** 068 * A lock that allows the user to edit the resource's structure record only, 069 * but not it's resource record nor content record.<p> 070 * 071 * This lock is assigned to resources that already have a shared exclusive lock, 072 * and then inherit a lock because one if it's parent folders gets locked. 073 */ 074 SHARED_INHERITED(1), 075 076 /** 077 * A temporary exclisive lock that allows the user to edit the resource's structure record, 078 * it's resource record, and its content record.<p> 079 * 080 * This lock is identical to the {@link #EXCLUSIVE} lock, but it is automatically removed after 081 * a user is logged out.<p> 082 */ 083 TEMPORARY(6), 084 085 /** Type of the NULL lock obtained by {@link org.opencms.lock.CmsLock#getNullLock()}. */ 086 SYSTEM_UNLOCKED(8), 087 088 /** Type of the NULL system lock. */ 089 UNLOCKED(0); 090 091 /** The lock mode/type. */ 092 private int m_mode; 093 094 /** 095 * Constructor.<p> 096 * 097 * @param mode the lock mode/type 098 */ 099 LockType(int mode) { 100 101 m_mode = mode; 102 } 103 104 /** 105 * Returns the lock type according to the given mode.<p> 106 * 107 * @param mode the lock mode/type int 108 * 109 * @return the lock type 110 */ 111 public static LockType valueOf(int mode) { 112 113 switch (mode) { 114 case 1: 115 return SHARED_INHERITED; 116 case 2: 117 return SHARED_EXCLUSIVE; 118 case 3: 119 return INHERITED; 120 case 4: 121 return EXCLUSIVE; 122 case 6: 123 return TEMPORARY; 124 case 7: 125 return PUBLISH; 126 case 8: 127 return SYSTEM_UNLOCKED; 128 default: 129 return UNLOCKED; 130 } 131 } 132 133 /** 134 * Return the lock mode/type.<p> 135 * 136 * @return the lock mode/type 137 */ 138 public int getMode() { 139 140 return m_mode; 141 } 142 143 /** 144 * Returns <code>true</code> if this lock is in fact unlocked.<p> 145 * 146 * Only if this is <code>true</code>, the result lock is equal to the <code>NULL</code> lock, 147 * which can be obtained by {@link org.opencms.lock.CmsLock#getNullLock()}.<p> 148 * 149 * @return <code>true</code> if this lock is in fact unlocked 150 */ 151 public boolean isUnlocked() { 152 153 return ((this == UNLOCKED) || (this == SYSTEM_UNLOCKED)); 154 } 155 156 /** 157 * @see java.lang.Object#toString() 158 */ 159 @Override 160 public String toString() { 161 162 switch (m_mode) { 163 case 1: 164 return "shared inherited"; 165 case 2: 166 return "shared exclusive"; 167 case 3: 168 return "inherited"; 169 case 4: 170 return "exclusive"; 171 case 6: 172 return "temporary exclusive"; 173 case 7: 174 return "publish"; 175 case 8: 176 return "system unlocked"; 177 default: 178 return "unlocked"; 179 } 180 } 181 } 182 183 /** Flag to indicate if the current lock is owned by the current user. */ 184 private boolean m_isOwnedByUser; 185 186 /** The lock owner name. */ 187 private String m_lockOwner; 188 189 /** The lock type. */ 190 private LockType m_lockType; 191 192 /** 193 * Default constructor for serialization.<p> 194 */ 195 public CmsClientLock() { 196 197 // nothing to do 198 } 199 200 /** 201 * Returns the lock owner name.<p> 202 * 203 * @return the lock owner name 204 */ 205 public String getLockOwner() { 206 207 return m_lockOwner; 208 } 209 210 /** 211 * Returns the lock type.<p> 212 * 213 * @return the lock type 214 */ 215 public LockType getLockType() { 216 217 return m_lockType; 218 } 219 220 /** 221 * Returns if the current lock is owned by the current user.<p> 222 * 223 * @return if the current lock is owned by the current user 224 */ 225 public boolean isOwnedByUser() { 226 227 return m_isOwnedByUser; 228 } 229 230 /** 231 * Sets the lock owner name.<p> 232 * 233 * @param lockOwner the lock owner name to set 234 */ 235 public void setLockOwner(String lockOwner) { 236 237 m_lockOwner = lockOwner; 238 } 239 240 /** 241 * Sets the lock type.<p> 242 * 243 * @param lockType the lock type to set 244 */ 245 public void setLockType(LockType lockType) { 246 247 m_lockType = lockType; 248 } 249 250 /** 251 * Sets if the current lock is owned by the current user.<p> 252 * 253 * @param isOwnedByUser if the current lock is owned by the current user 254 */ 255 public void setOwnedByUser(boolean isOwnedByUser) { 256 257 m_isOwnedByUser = isOwnedByUser; 258 } 259}