1 28 29 package com.opencms.defaults; 30 31 import org.opencms.file.CmsObject; 32 import org.opencms.file.CmsUser; 33 import org.opencms.main.CmsException; 34 import org.opencms.security.CmsPermissionSet; 35 import org.opencms.util.CmsUUID; 36 37 import com.opencms.defaults.master.CmsPlausibilizationException; 38 import com.opencms.template.I_CmsContent; 39 40 import java.lang.reflect.Method ; 41 import java.util.Vector ; 42 43 52 public abstract class A_CmsContentDefinition implements I_CmsContent { 53 54 57 private CmsUUID m_userId; 58 59 62 private String m_group; 63 64 67 private int m_accessFlags; 68 69 77 public static Vector applyFilter(CmsObject cms, CmsFilterMethod filterMethod) throws Exception { 78 79 return applyFilter(cms, filterMethod, null); 80 } 81 82 91 public static Vector applyFilter(CmsObject cms, CmsFilterMethod filterMethod, String userParameter) 92 throws Exception { 93 94 Method method = filterMethod.getFilterMethod(); 95 Object [] defaultParams = filterMethod.getDefaultParameter(); 96 Vector allParameters = new Vector (); 97 Object [] allParametersArray; 98 Class [] paramTypes = method.getParameterTypes(); 99 100 if ((paramTypes.length > 0) && (paramTypes[0] == CmsObject.class)) { 101 allParameters.addElement(cms); 102 } 103 104 for (int i = 0; i < defaultParams.length; i++) { 105 allParameters.addElement(defaultParams[i]); 106 } 107 108 if (filterMethod.hasUserParameter()) { 109 allParameters.addElement(userParameter); 110 } 111 112 allParametersArray = new Object [allParameters.size()]; 113 allParameters.copyInto(allParametersArray); 114 return (Vector )method.invoke(null, allParametersArray); 115 } 116 117 123 public void check(boolean finalcheck) throws CmsPlausibilizationException { 124 125 } 127 128 136 public abstract void delete(CmsObject cms) throws Exception ; 137 138 145 public static Vector getFieldMethods(CmsObject cms) { 146 147 return new Vector (); 148 } 149 150 157 public static Vector getFieldNames(CmsObject cms) { 158 159 return new Vector (); 160 } 161 162 169 public static Vector getFilterMethods(CmsObject cms) { 170 171 return new Vector (); 172 } 173 174 181 public CmsUUID getLockstate() { 182 183 return CmsUUID.getNullUUID(); 184 } 185 186 192 public abstract String getUniqueId(CmsObject cms); 193 194 200 public String getUrl() { 201 202 return null; 203 } 204 205 210 public static boolean isLockable() { 211 212 return false; 213 } 214 215 222 public void setLockstate(CmsUUID lockedByUserId) { 223 224 } 225 226 233 public abstract void write(CmsObject cms) throws Exception ; 234 235 239 public boolean isReadable() { 240 241 return true; 242 } 243 244 248 public boolean isWriteable() { 249 250 return true; 251 } 252 253 258 public void setOwner(CmsUUID userId) { 259 260 m_userId = userId; 261 } 262 263 267 public CmsUUID getOwner() { 268 269 return m_userId; 270 } 271 272 276 public void setGroup(String group) { 277 278 m_group = group; 279 } 280 281 285 public String getGroup() { 286 287 return m_group; 288 } 289 290 294 public void setAccessFlags(int accessFlags) { 295 296 m_accessFlags = accessFlags; 297 } 298 299 303 public int getAccessFlags() { 304 305 return m_accessFlags; 306 } 307 308 315 protected boolean hasReadAccess(CmsObject cms) throws CmsException { 316 317 CmsUser currentUser = cms.getRequestContext().currentUser(); 318 319 if (!accessOther(com.opencms.core.I_CmsConstants.C_ACCESS_PUBLIC_READ) 320 && !accessOwner(cms, currentUser, CmsPermissionSet.PERMISSION_READ) 321 && !accessGroup(cms, currentUser, com.opencms.core.I_CmsConstants.C_ACCESS_GROUP_READ)) { 322 return false; 323 } 324 return true; 325 } 326 327 334 public boolean hasWriteAccess(CmsObject cms) throws CmsException { 335 336 CmsUser currentUser = cms.getRequestContext().currentUser(); 337 339 if (isLockable() && (!getLockstate().equals(currentUser.getId()))) { 340 return false; 342 } 343 344 if (!(accessOther(com.opencms.core.I_CmsConstants.C_ACCESS_PUBLIC_WRITE) 346 || accessOwner(cms, currentUser, CmsPermissionSet.PERMISSION_WRITE) || accessGroup( 347 cms, 348 currentUser, 349 com.opencms.core.I_CmsConstants.C_ACCESS_GROUP_WRITE))) { 350 return false; 352 } 353 return true; 354 } 355 356 366 protected boolean accessOwner(CmsObject cms, CmsUser currentUser, int flags) throws CmsException { 367 368 if (currentUser.getId().equals(getOwner())) { 370 if ((getAccessFlags() & flags) == flags) { 371 return true; 372 } 373 } 374 375 return false; 377 } 378 379 389 protected boolean accessGroup(CmsObject cms, CmsUser currentUser, int flags) throws CmsException { 390 391 if (cms.userInGroup(currentUser.getName(), getGroup())) { 393 if ((getAccessFlags() & flags) == flags) { 394 return true; 395 } 396 } 397 398 return false; 400 } 401 402 409 protected boolean accessOther(int flags) throws CmsException { 410 411 return ((getAccessFlags() & flags) == flags); 412 } 413 414 420 public static boolean isExtendedList() { 421 422 return false; 423 } 424 425 430 public boolean isTimedContent() { 431 432 return false; 433 } 434 }
| Popular Tags
|