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.file; 029 030import org.opencms.db.CmsDbEntryNotFoundException; 031import org.opencms.db.CmsPublishedResource; 032import org.opencms.db.CmsResourceState; 033import org.opencms.db.CmsSecurityManager; 034import org.opencms.db.log.CmsLogEntry; 035import org.opencms.db.log.CmsLogFilter; 036import org.opencms.db.urlname.CmsUrlNameMappingEntry; 037import org.opencms.db.urlname.CmsUrlNameMappingFilter; 038import org.opencms.file.CmsResource.CmsResourceDeleteMode; 039import org.opencms.file.history.CmsHistoryPrincipal; 040import org.opencms.file.history.CmsHistoryProject; 041import org.opencms.file.history.I_CmsHistoryResource; 042import org.opencms.file.types.I_CmsResourceType; 043import org.opencms.i18n.CmsLocaleGroupService; 044import org.opencms.lock.CmsLock; 045import org.opencms.lock.CmsLockFilter; 046import org.opencms.lock.CmsLockType; 047import org.opencms.main.CmsException; 048import org.opencms.main.CmsIllegalArgumentException; 049import org.opencms.main.I_CmsEventListener; 050import org.opencms.main.OpenCms; 051import org.opencms.relations.CmsRelation; 052import org.opencms.relations.CmsRelationFilter; 053import org.opencms.relations.CmsRelationType; 054import org.opencms.report.I_CmsReport; 055import org.opencms.security.CmsAccessControlEntry; 056import org.opencms.security.CmsAccessControlList; 057import org.opencms.security.CmsOrganizationalUnit; 058import org.opencms.security.CmsPermissionSet; 059import org.opencms.security.CmsPrincipal; 060import org.opencms.security.CmsRole; 061import org.opencms.security.CmsRoleViolationException; 062import org.opencms.security.CmsSecurityException; 063import org.opencms.security.I_CmsPermissionHandler; 064import org.opencms.security.I_CmsPrincipal; 065import org.opencms.util.CmsPair; 066import org.opencms.util.CmsStringUtil; 067import org.opencms.util.CmsUUID; 068import org.opencms.xml.content.CmsNumberSuffixNameSequence; 069 070import java.util.ArrayList; 071import java.util.Collections; 072import java.util.Iterator; 073import java.util.List; 074import java.util.Locale; 075import java.util.Map; 076import java.util.Set; 077 078/** 079 * This pivotal class provides all authorized access to the OpenCms VFS resources.<p> 080 * 081 * It encapsulates user identification and permissions. 082 * Think of it as an initialized "shell" to access the OpenCms VFS. 083 * Every call to a method here will be checked for user permissions 084 * according to the <code>{@link org.opencms.file.CmsRequestContext}</code> this CmsObject instance was created with.<p> 085 * 086 * From a JSP page running in OpenCms, use <code>{@link org.opencms.jsp.CmsJspBean#getCmsObject()}</code> to gain 087 * access to the current users CmsObject. Usually this is done with a <code>{@link org.opencms.jsp.CmsJspActionElement}</code>.<p> 088 * 089 * To generate a new instance of this class in your application, use 090 * <code>{@link org.opencms.main.OpenCms#initCmsObject(String)}</code>. The argument String should be 091 * the name of the guest user, usually "Guest" and more formally obtained by <code>{@link org.opencms.db.CmsDefaultUsers#getUserGuest()}</code>. 092 * This will give you an initialized context with guest user permissions. 093 * Then use <code>{@link CmsObject#loginUser(String, String)}</code> to log in the user you want. 094 * Obviously you need the password for the new user. 095 * You should never try to create an instance of this class using the constructor, 096 * this is reserved for internal operation only.<p> 097 * 098 * @since 6.0.0 099 */ 100public final class CmsObject { 101 102 /** The request context. */ 103 protected CmsRequestContext m_context; 104 105 /** The security manager to access the cms. */ 106 protected CmsSecurityManager m_securityManager; 107 108 /** 109 * Connects an OpenCms user context to a running database.<p> 110 * 111 * <b>Please note:</b> This constructor is internal to OpenCms and not for public use. 112 * If you want to create a new instance of a <code>{@link CmsObject}</code> in your application, 113 * use <code>{@link org.opencms.main.OpenCms#initCmsObject(String)}</code>.<p> 114 * 115 * @param securityManager the security manager 116 * @param context the request context that contains the user authentication 117 */ 118 public CmsObject(CmsSecurityManager securityManager, CmsRequestContext context) { 119 120 init(securityManager, context); 121 } 122 123 /** 124 * Adds a new relation to the given resource.<p> 125 * 126 * @param resource the source resource 127 * @param target the target resource 128 * @param type the type of the relation 129 * 130 * @throws CmsException if something goes wrong 131 */ 132 public void addRelationToResource(CmsResource resource, CmsResource target, String type) throws CmsException { 133 134 createRelation(resource, target, type, false); 135 } 136 137 /** 138 * Adds a new relation to the given resource.<p> 139 * 140 * @param resourceName the name of the source resource 141 * @param targetPath the path of the target resource 142 * @param type the type of the relation 143 * 144 * @throws CmsException if something goes wrong 145 */ 146 public void addRelationToResource(String resourceName, String targetPath, String type) throws CmsException { 147 148 createRelation(resourceName, targetPath, type, false); 149 } 150 151 /** 152 * Convenience method to add the site root from the current user's 153 * request context to the given resource name.<p> 154 * 155 * @param resourcename the resource name 156 * 157 * @return the resource name with the site root added 158 * 159 * @see CmsRequestContext#addSiteRoot(String) 160 */ 161 public String addSiteRoot(String resourcename) { 162 163 return m_context.addSiteRoot(resourcename); 164 } 165 166 /** 167 * Adds a user to a group.<p> 168 * 169 * @param username the name of the user that is to be added to the group 170 * @param groupname the name of the group 171 * 172 * @throws CmsException if something goes wrong 173 */ 174 public void addUserToGroup(String username, String groupname) throws CmsException { 175 176 m_securityManager.addUserToGroup(m_context, username, groupname, false); 177 } 178 179 /** 180 * This method works just like {@link CmsObject#adjustLinks(String, String)}, but you can specify multiple source 181 * files, and the target folder is interpreted as the folder into which the source files have been copied.<p> 182 * 183 * @param sourceFiles the list of source files 184 * @param targetParentFolder the folder into which the source files have been copied 185 * 186 * @throws CmsException if something goes wrong 187 */ 188 public void adjustLinks(List<String> sourceFiles, String targetParentFolder) throws CmsException { 189 190 CmsObject cms = OpenCms.initCmsObject(this); 191 cms.getRequestContext().setSiteRoot(""); 192 List<String> rootSourceFiles = new ArrayList<String>(); 193 for (String sourceFile : sourceFiles) { 194 rootSourceFiles.add(addSiteRoot(sourceFile)); 195 } 196 String rootTargetParentFolder = addSiteRoot(targetParentFolder); 197 198 CmsLinkRewriter rewriter = new CmsLinkRewriter(cms, rootSourceFiles, rootTargetParentFolder); 199 rewriter.rewriteLinks(); 200 } 201 202 /** 203 * This method works just like {@link CmsObject#adjustLinks(String, String)}, but instead of specifying 204 * a single source and target folder, you can specify multiple sources and the corresponding targets in 205 * a map of strings. 206 * 207 * @param sourceTargetMap a map with the source files as keys and the corresponding targets as values 208 * @param targetParentFolder the folder into which the source files have been copied 209 * 210 * @throws CmsException if something goes wrong 211 */ 212 public void adjustLinks(Map<String, String> sourceTargetMap, String targetParentFolder) throws CmsException { 213 214 CmsObject cms = OpenCms.initCmsObject(this); 215 cms.getRequestContext().setSiteRoot(""); 216 List<CmsPair<String, String>> sourcesAndTargets = new ArrayList<CmsPair<String, String>>(); 217 for (Map.Entry<String, String> entry : sourceTargetMap.entrySet()) { 218 String rootSource = addSiteRoot(entry.getKey()); 219 String rootTarget = addSiteRoot(entry.getValue()); 220 sourcesAndTargets.add(CmsPair.create(rootSource, rootTarget)); 221 } 222 String rootTargetParentFolder = addSiteRoot(targetParentFolder); 223 CmsLinkRewriter rewriter = new CmsLinkRewriter(cms, rootTargetParentFolder, sourcesAndTargets); 224 rewriter.rewriteLinks(); 225 } 226 227 /** 228 * Adjusts all links in the target folder that point to the source folder 229 * so that they are kept "relative" in the target folder where possible. 230 * 231 * If a link is found from the target folder to the source folder, 232 * then the target folder is checked if a target of the same name 233 * is found also "relative" inside the target Folder, and if so, 234 * the link is changed to that "relative" target. This is mainly used to keep 235 * relative links inside a copied folder structure intact. 236 * 237 * Example: Image we have folder /folderA/ that contains files 238 * /folderA/x1 and /folderA/y1. x1 has a link to y1 and y1 to x1. 239 * Now someone copies /folderA/ to /folderB/. So we end up with 240 * /folderB/x2 and /folderB/y2. Because of the link mechanism in OpenCms, 241 * x2 will have a link to y1 and y2 to x1. By using this method, 242 * the links from x2 to y1 will be replaced by a link x2 to y2, 243 * and y2 to x1 with y2 to x2. 244 * 245 * Link replacement works for links in XML files as well as relation only 246 * type links. 247 * 248 * @param sourceFolder the source folder 249 * @param targetFolder the target folder 250 * 251 * @throws CmsException if something goes wrong 252 */ 253 public void adjustLinks(String sourceFolder, String targetFolder) throws CmsException { 254 255 String rootSourceFolder = addSiteRoot(sourceFolder); 256 String rootTargetFolder = addSiteRoot(targetFolder); 257 String siteRoot = getRequestContext().getSiteRoot(); 258 getRequestContext().setSiteRoot(""); 259 try { 260 CmsLinkRewriter linkRewriter = new CmsLinkRewriter(this, rootSourceFolder, rootTargetFolder); 261 linkRewriter.rewriteLinks(); 262 } finally { 263 getRequestContext().setSiteRoot(siteRoot); 264 } 265 } 266 267 /** 268 * Changes the access control for a given resource and a given principal(user/group).<p> 269 * 270 * @param resourceName name of the resource 271 * @param principalType the type of the principal (currently group or user): 272 * <ul> 273 * <li><code>{@link I_CmsPrincipal#PRINCIPAL_USER}</code></li> 274 * <li><code>{@link I_CmsPrincipal#PRINCIPAL_GROUP}</code></li> 275 * </ul> 276 * @param principalName name of the principal 277 * @param allowedPermissions bit set of allowed permissions 278 * @param deniedPermissions bit set of denied permissions 279 * @param flags additional flags of the access control entry 280 * 281 * @throws CmsException if something goes wrong 282 */ 283 public void chacc( 284 String resourceName, 285 String principalType, 286 String principalName, 287 int allowedPermissions, 288 int deniedPermissions, 289 int flags) 290 throws CmsException { 291 292 CmsResource res = readResource(resourceName, CmsResourceFilter.ALL); 293 294 CmsAccessControlEntry acEntry = null; 295 try { 296 I_CmsPrincipal principal = CmsPrincipal.readPrincipal(this, principalType, principalName); 297 acEntry = new CmsAccessControlEntry( 298 res.getResourceId(), 299 principal.getId(), 300 allowedPermissions, 301 deniedPermissions, 302 flags); 303 acEntry.setFlagsForPrincipal(principal); 304 } catch (CmsDbEntryNotFoundException e) { 305 // check for special ids 306 if (principalName.equalsIgnoreCase(CmsAccessControlEntry.PRINCIPAL_ALL_OTHERS_NAME)) { 307 acEntry = new CmsAccessControlEntry( 308 res.getResourceId(), 309 CmsAccessControlEntry.PRINCIPAL_ALL_OTHERS_ID, 310 allowedPermissions, 311 deniedPermissions, 312 flags); 313 acEntry.setFlags(CmsAccessControlEntry.ACCESS_FLAGS_ALLOTHERS); 314 } else if (principalName.equalsIgnoreCase(CmsAccessControlEntry.PRINCIPAL_OVERWRITE_ALL_NAME)) { 315 acEntry = new CmsAccessControlEntry( 316 res.getResourceId(), 317 CmsAccessControlEntry.PRINCIPAL_OVERWRITE_ALL_ID, 318 allowedPermissions, 319 deniedPermissions, 320 flags); 321 acEntry.setFlags(CmsAccessControlEntry.ACCESS_FLAGS_OVERWRITE_ALL); 322 } else if (principalType.equalsIgnoreCase(CmsRole.PRINCIPAL_ROLE)) { 323 // only vfs managers can set role based permissions 324 m_securityManager.checkRoleForResource(m_context, CmsRole.VFS_MANAGER, res); 325 // check for role 326 CmsRole role = CmsRole.valueOfRoleName(principalName); 327 // role based permissions can only be set in the system folder 328 if (role == null) { 329 throw e; 330 } 331 acEntry = new CmsAccessControlEntry( 332 res.getResourceId(), 333 role.getId(), 334 allowedPermissions, 335 deniedPermissions, 336 flags); 337 acEntry.setFlags(CmsAccessControlEntry.ACCESS_FLAGS_ROLE); 338 } else { 339 throw e; 340 } 341 } 342 343 m_securityManager.writeAccessControlEntry(m_context, res, acEntry); 344 } 345 346 /** 347 * Changes the access control for a given resource and a given principal(user/group).<p> 348 * 349 * @param resourceName name of the resource 350 * @param principalType the type of the principal (group or user): 351 * <ul> 352 * <li><code>{@link I_CmsPrincipal#PRINCIPAL_USER}</code></li> 353 * <li><code>{@link I_CmsPrincipal#PRINCIPAL_GROUP}</code></li> 354 * </ul> 355 * @param principalName name of the principal 356 * @param permissionString the permissions in the format ((+|-)(r|w|v|c|i|o))* 357 * 358 * @throws CmsException if something goes wrong 359 */ 360 public void chacc(String resourceName, String principalType, String principalName, String permissionString) 361 throws CmsException { 362 363 CmsResource res = readResource(resourceName, CmsResourceFilter.ALL); 364 365 CmsAccessControlEntry acEntry = null; 366 try { 367 I_CmsPrincipal principal = CmsPrincipal.readPrincipal(this, principalType, principalName); 368 acEntry = new CmsAccessControlEntry(res.getResourceId(), principal.getId(), permissionString); 369 acEntry.setFlagsForPrincipal(principal); 370 } catch (CmsDbEntryNotFoundException e) { 371 // check for special ids 372 if (principalName.equalsIgnoreCase(CmsAccessControlEntry.PRINCIPAL_ALL_OTHERS_NAME)) { 373 acEntry = new CmsAccessControlEntry( 374 res.getResourceId(), 375 CmsAccessControlEntry.PRINCIPAL_ALL_OTHERS_ID, 376 permissionString); 377 acEntry.setFlags(CmsAccessControlEntry.ACCESS_FLAGS_ALLOTHERS); 378 } else if (principalName.equalsIgnoreCase(CmsAccessControlEntry.PRINCIPAL_OVERWRITE_ALL_NAME)) { 379 acEntry = new CmsAccessControlEntry( 380 res.getResourceId(), 381 CmsAccessControlEntry.PRINCIPAL_OVERWRITE_ALL_ID, 382 permissionString); 383 acEntry.setFlags(CmsAccessControlEntry.ACCESS_FLAGS_OVERWRITE_ALL); 384 } else if (principalType.equalsIgnoreCase(CmsRole.PRINCIPAL_ROLE)) { 385 // only vfs managers can set role based permissions 386 m_securityManager.checkRoleForResource(m_context, CmsRole.VFS_MANAGER, res); 387 // check for role 388 CmsRole role = CmsRole.valueOfRoleName(principalName); 389 // role based permissions can only be set in the system folder 390 if (role == null) { 391 throw e; 392 } 393 acEntry = new CmsAccessControlEntry(res.getResourceId(), role.getId(), permissionString); 394 acEntry.setFlags(CmsAccessControlEntry.ACCESS_FLAGS_ROLE); 395 } else { 396 throw e; 397 } 398 } 399 400 m_securityManager.writeAccessControlEntry(m_context, res, acEntry); 401 } 402 403 /** 404 * Changes the lock of a resource to the current user, 405 * that is "steals" the lock from another user.<p> 406 * 407 * This is the "steal lock" operation.<p> 408 * 409 * @param resource the resource to change the lock 410 * 411 * @throws CmsException if something goes wrong 412 */ 413 public void changeLock(CmsResource resource) throws CmsException { 414 415 getResourceType(resource).changeLock(this, m_securityManager, resource); 416 } 417 418 /** 419 * Changes the lock of a resource to the current user, 420 * that is "steals" the lock from another user.<p> 421 * 422 * This is the "steal lock" operation.<p> 423 * 424 * @param resourcename the name of the resource to change the lock with complete path 425 * 426 * @throws CmsException if something goes wrong 427 */ 428 public void changeLock(String resourcename) throws CmsException { 429 430 CmsResource resource = readResource(resourcename, CmsResourceFilter.ALL); 431 changeLock(resource); 432 } 433 434 /** 435 * Returns a list with all sub resources of a given folder that have set the given property, 436 * matching the current property's value with the given old value and replacing it by a given new value.<p> 437 * 438 * @param resourcename the name of the resource to change the property value 439 * @param property the name of the property to change the value 440 * @param oldValue the old value of the property, can be a regular expression 441 * @param newValue the new value of the property 442 * @param recursive if true, change recursively all property values on sub-resources (only for folders) 443 * 444 * @return a list with the <code>{@link CmsResource}</code>'s where the property value has been changed 445 * 446 * @throws CmsException if operation was not successful 447 */ 448 public List<CmsResource> changeResourcesInFolderWithProperty( 449 String resourcename, 450 String property, 451 String oldValue, 452 String newValue, 453 boolean recursive) 454 throws CmsException { 455 456 CmsResource resource = readResource(resourcename, CmsResourceFilter.IGNORE_EXPIRATION); 457 return m_securityManager.changeResourcesInFolderWithProperty( 458 m_context, 459 resource, 460 property, 461 oldValue, 462 newValue, 463 recursive); 464 } 465 466 /** 467 * Changes the resource flags of a resource.<p> 468 * 469 * The resource flags are used to indicate various "special" conditions 470 * for a resource. Most notably, the "internal only" setting which signals 471 * that a resource can not be directly requested with it's URL.<p> 472 * 473 * @param resourcename the name of the resource to change the flags for (full current site relative path) 474 * @param flags the new flags for this resource 475 * 476 * @throws CmsException if something goes wrong 477 */ 478 public void chflags(String resourcename, int flags) throws CmsException { 479 480 CmsResource resource = readResource(resourcename, CmsResourceFilter.IGNORE_EXPIRATION); 481 getResourceType(resource).chflags(this, m_securityManager, resource, flags); 482 } 483 484 /** 485 * Changes the resource type of a resource.<p> 486 * 487 * OpenCms handles resources according to the resource type, 488 * not the file suffix. This is e.g. why a JSP in OpenCms can have the 489 * suffix ".html" instead of ".jsp" only. Changing the resource type 490 * makes sense e.g. if you want to make a plain text file a JSP resource, 491 * or a binary file an image, etc.<p> 492 * 493 * @param resourcename the name of the resource to change the type for (full current site relative path) 494 * @param type the new resource type for this resource 495 * 496 * @throws CmsException if something goes wrong 497 */ 498 public void chtype(String resourcename, I_CmsResourceType type) throws CmsException { 499 500 CmsResource resource = readResource(resourcename, CmsResourceFilter.IGNORE_EXPIRATION); 501 getResourceType(resource).chtype(this, m_securityManager, resource, type); 502 } 503 504 /** 505 * Changes the resource type of a resource.<p> 506 * 507 * OpenCms handles resources according to the resource type, 508 * not the file suffix. This is e.g. why a JSP in OpenCms can have the 509 * suffix ".html" instead of ".jsp" only. Changing the resource type 510 * makes sense e.g. if you want to make a plain text file a JSP resource, 511 * or a binary file an image, etc.<p> 512 * 513 * @param resourcename the name of the resource to change the type for (full current site relative path) 514 * @param type the new resource type for this resource 515 * 516 * @throws CmsException if something goes wrong 517 * 518 * @deprecated 519 * Use {@link #chtype(String, I_CmsResourceType)} instead. 520 * Resource types should always be referenced either by its type class (preferred) or by type name. 521 * Use of int based resource type references will be discontinued in a future OpenCms release. 522 */ 523 @Deprecated 524 public void chtype(String resourcename, int type) throws CmsException { 525 526 chtype(resourcename, getResourceType(type)); 527 } 528 529 /** 530 * Copies a resource.<p> 531 * 532 * The copied resource will always be locked to the current user 533 * after the copy operation.<p> 534 * 535 * Siblings will be treated according to the 536 * <code>{@link org.opencms.file.CmsResource#COPY_PRESERVE_SIBLING}</code> mode.<p> 537 * 538 * @param source the name of the resource to copy (full current site relative path) 539 * @param destination the name of the copy destination (full current site relative path) 540 * 541 * @throws CmsException if something goes wrong 542 * @throws CmsIllegalArgumentException if the <code>destination</code> argument is null or of length 0 543 * 544 * @see #copyResource(String, String, CmsResource.CmsResourceCopyMode) 545 */ 546 public void copyResource(String source, String destination) throws CmsException, CmsIllegalArgumentException { 547 548 copyResource(source, destination, CmsResource.COPY_PRESERVE_SIBLING); 549 } 550 551 /** 552 * Copies a resource.<p> 553 * 554 * The copied resource will always be locked to the current user 555 * after the copy operation.<p> 556 * 557 * The <code>siblingMode</code> parameter controls how to handle siblings 558 * during the copy operation.<br> 559 * Possible values for this parameter are: <br> 560 * <ul> 561 * <li><code>{@link CmsResource#COPY_AS_NEW}</code></li> 562 * <li><code>{@link CmsResource#COPY_AS_SIBLING}</code></li> 563 * <li><code>{@link CmsResource#COPY_PRESERVE_SIBLING}</code></li> 564 * </ul><p> 565 * 566 * @param source the name of the resource to copy (full current site relative path) 567 * @param destination the name of the copy destination (full current site relative path) 568 * @param siblingMode indicates how to handle siblings during copy 569 * 570 * @throws CmsException if something goes wrong 571 * @throws CmsIllegalArgumentException if the <code>destination</code> argument is null or of length 0 572 */ 573 public void copyResource(String source, String destination, CmsResource.CmsResourceCopyMode siblingMode) 574 throws CmsException, CmsIllegalArgumentException { 575 576 CmsResource resource = readResource(source, CmsResourceFilter.IGNORE_EXPIRATION); 577 getResourceType(resource).copyResource(this, m_securityManager, resource, destination, siblingMode); 578 } 579 580 /** 581 * Copies a resource to the current project of the user.<p> 582 * 583 * This is used to extend the current users project with the 584 * specified resource, in case that the resource is not yet part of the project. 585 * The resource is not really copied like in a regular copy operation, 586 * it is in fact only "enabled" in the current users project.<p> 587 * 588 * @param resource the resource to copy to the current project 589 * 590 * @throws CmsException if something goes wrong 591 */ 592 public void copyResourceToProject(CmsResource resource) throws CmsException { 593 594 getResourceType(resource).copyResourceToProject(this, m_securityManager, resource); 595 } 596 597 /** 598 * Copies a resource to the current project of the user.<p> 599 * 600 * This is used to extend the current users project with the 601 * specified resource, in case that the resource is not yet part of the project. 602 * The resource is not really copied like in a regular copy operation, 603 * it is in fact only "enabled" in the current users project.<p> 604 * 605 * @param resourcename the name of the resource to copy to the current project (full current site relative path) 606 * 607 * @throws CmsException if something goes wrong 608 */ 609 public void copyResourceToProject(String resourcename) throws CmsException { 610 611 CmsResource resource = readResource(resourcename, CmsResourceFilter.ALL); 612 copyResourceToProject(resource); 613 } 614 615 /** 616 * Counts the locked resources in a project.<p> 617 * 618 * @param id the id of the project 619 * 620 * @return the number of locked resources in this project 621 * 622 * @throws CmsException if operation was not successful 623 */ 624 public int countLockedResources(CmsUUID id) throws CmsException { 625 626 return m_securityManager.countLockedResources(m_context, id); 627 } 628 629 /** 630 * Copies access control entries of a given resource to another resource.<p> 631 * 632 * Already existing access control entries of the destination resource are removed.<p> 633 * 634 * @param sourceName the name of the resource of which the access control entries are copied 635 * @param destName the name of the resource to which the access control entries are applied 636 * 637 * @throws CmsException if something goes wrong 638 */ 639 public void cpacc(String sourceName, String destName) throws CmsException { 640 641 CmsResource source = readResource(sourceName); 642 CmsResource dest = readResource(destName); 643 m_securityManager.copyAccessControlEntries(m_context, source, dest); 644 } 645 646 /** 647 * Creates a new user group.<p> 648 * 649 * @param groupFqn the name of the new group 650 * @param description the description of the new group 651 * @param flags the flags for the new group 652 * @param parent the parent group (or <code>null</code>) 653 * 654 * @return a <code>{@link CmsGroup}</code> object representing the newly created group 655 * 656 * @throws CmsException if operation was not successful 657 */ 658 public CmsGroup createGroup(String groupFqn, String description, int flags, String parent) throws CmsException { 659 660 return m_securityManager.createGroup(m_context, groupFqn, description, flags, parent); 661 } 662 663 /** 664 * Creates a new project.<p> 665 * 666 * @param name the name of the project to create 667 * @param description the description for the new project 668 * @param groupname the name of the project user group 669 * @param managergroupname the name of the project manager group 670 * 671 * @return the created project 672 * 673 * @throws CmsException if something goes wrong 674 */ 675 public CmsProject createProject(String name, String description, String groupname, String managergroupname) 676 throws CmsException { 677 678 return m_securityManager.createProject( 679 m_context, 680 name, 681 description, 682 groupname, 683 managergroupname, 684 CmsProject.PROJECT_TYPE_NORMAL); 685 } 686 687 /** 688 * Creates a new project.<p> 689 * 690 * @param name the name of the project to create 691 * @param description the description for the new project 692 * @param groupname the name of the project user group 693 * @param managergroupname the name of the project manager group 694 * @param projecttype the type of the project (normal or temporary) 695 * 696 * @return the created project 697 * 698 * @throws CmsException if operation was not successful 699 */ 700 public CmsProject createProject( 701 String name, 702 String description, 703 String groupname, 704 String managergroupname, 705 CmsProject.CmsProjectType projecttype) 706 throws CmsException { 707 708 return m_securityManager.createProject(m_context, name, description, groupname, managergroupname, projecttype); 709 } 710 711 /** 712 * Creates a property definition.<p> 713 * 714 * Property definitions are valid for all resource types.<p> 715 * 716 * @param name the name of the property definition to create 717 * 718 * @return the created property definition 719 * 720 * @throws CmsException if something goes wrong 721 */ 722 public CmsPropertyDefinition createPropertyDefinition(String name) throws CmsException { 723 724 return (m_securityManager.createPropertyDefinition(m_context, name)); 725 } 726 727 /** 728 * Creates a resource with the given properties and content. 729 * Will throw an exception, if a resource with the given name already exists.<p> 730 * 731 * @param sitePath the site path for the resource 732 * @param resource the resource object to be imported 733 * @param content the content of the resource 734 * @param properties the properties of the resource 735 * 736 * @return the imported resource 737 * 738 * @throws CmsException if something goes wrong 739 */ 740 public CmsResource createResource( 741 String sitePath, 742 CmsResource resource, 743 byte[] content, 744 List<CmsProperty> properties) 745 throws CmsException { 746 747 resource.setUserLastModified(getRequestContext().getCurrentUser().getId()); 748 resource.setDateLastModified(System.currentTimeMillis()); 749 // ensure resource record is updated 750 resource.setState(CmsResource.STATE_NEW); 751 return m_securityManager.createResource( 752 m_context, 753 m_context.addSiteRoot(sitePath), 754 resource, 755 content, 756 properties); 757 } 758 759 /** 760 * Creates a new resource of the given resource type with 761 * empty content and no properties.<p> 762 * 763 * @param resourcename the name of the resource to create (full current site relative path) 764 * @param type the type of the resource to create 765 * 766 * @return the created resource 767 * 768 * @throws CmsException if something goes wrong 769 * @throws CmsIllegalArgumentException if the given <code>resourcename</code> is null or of length 0 770 * 771 * @see #createResource(String, int, byte[], List) 772 */ 773 public CmsResource createResource(String resourcename, I_CmsResourceType type) 774 throws CmsException, CmsIllegalArgumentException { 775 776 return createResource(resourcename, type, new byte[0], new ArrayList<CmsProperty>(0)); 777 } 778 779 /** 780 * Creates a new resource of the given resource type 781 * with the provided content and properties.<p> 782 * 783 * @param resourcename the name of the resource to create (full current site relative path) 784 * @param type the type of the resource to create 785 * @param content the contents for the new resource 786 * @param properties the properties for the new resource 787 * 788 * @return the created resource 789 * 790 * @throws CmsException if something goes wrong 791 * @throws CmsIllegalArgumentException if the <code>resourcename</code> argument is null or of length 0 792 */ 793 public CmsResource createResource( 794 String resourcename, 795 I_CmsResourceType type, 796 byte[] content, 797 List<CmsProperty> properties) 798 throws CmsException, CmsIllegalArgumentException { 799 800 return type.createResource(this, m_securityManager, resourcename, content, properties); 801 } 802 803 /** 804 * Creates a new resource of the given resource type with 805 * empty content and no properties.<p> 806 * 807 * @param resourcename the name of the resource to create (full current site relative path) 808 * @param type the type of the resource to create 809 * 810 * @return the created resource 811 * 812 * @throws CmsException if something goes wrong 813 * @throws CmsIllegalArgumentException if the given <code>resourcename</code> is null or of length 0 814 * 815 * @see #createResource(String, int, byte[], List) 816 * 817 * @deprecated 818 * Use {@link #createResource(String, I_CmsResourceType)} instead. 819 * Resource types should always be referenced either by its type class (preferred) or by type name. 820 * Use of int based resource type references will be discontinued in a future OpenCms release. 821 */ 822 @Deprecated 823 public CmsResource createResource(String resourcename, int type) throws CmsException, CmsIllegalArgumentException { 824 825 return createResource(resourcename, getResourceType(type), new byte[0], new ArrayList<CmsProperty>(0)); 826 } 827 828 /** 829 * Creates a new resource of the given resource type 830 * with the provided content and properties.<p> 831 * 832 * @param resourcename the name of the resource to create (full current site relative path) 833 * @param type the type of the resource to create 834 * @param content the contents for the new resource 835 * @param properties the properties for the new resource 836 * 837 * @return the created resource 838 * 839 * @throws CmsException if something goes wrong 840 * @throws CmsIllegalArgumentException if the <code>resourcename</code> argument is null or of length 0 841 * 842 * @deprecated 843 * Use {@link #createResource(String, I_CmsResourceType, byte[], List)} instead. 844 * Resource types should always be referenced either by its type class (preferred) or by type name. 845 * Use of int based resource type references will be discontinued in a future OpenCms release. 846 */ 847 @Deprecated 848 public CmsResource createResource(String resourcename, int type, byte[] content, List<CmsProperty> properties) 849 throws CmsException, CmsIllegalArgumentException { 850 851 return createResource(resourcename, getResourceType(type), content, properties); 852 } 853 854 /** 855 * Creates a new sibling of the source resource.<p> 856 * 857 * @param source the name of the resource to create a sibling for with complete path 858 * @param destination the name of the sibling to create with complete path 859 * @param properties the individual properties for the new sibling 860 * 861 * @return the new created sibling 862 * 863 * @throws CmsException if something goes wrong 864 */ 865 public CmsResource createSibling(String source, String destination, List<CmsProperty> properties) 866 throws CmsException { 867 868 CmsResource resource = readResource(source, CmsResourceFilter.IGNORE_EXPIRATION); 869 return getResourceType(resource).createSibling(this, m_securityManager, resource, destination, properties); 870 } 871 872 /** 873 * Creates the project for the temporary workplace files.<p> 874 * 875 * @return the created project for the temporary workplace files 876 * 877 * @throws CmsException if something goes wrong 878 */ 879 public CmsProject createTempfileProject() throws CmsException { 880 881 return m_securityManager.createTempfileProject(m_context); 882 } 883 884 /** 885 * Creates a new user.<p> 886 * 887 * @param userFqn the name for the new user 888 * @param password the password for the new user 889 * @param description the description for the new user 890 * @param additionalInfos the additional infos for the user 891 * 892 * @return the created user 893 * 894 * @throws CmsException if something goes wrong 895 */ 896 public CmsUser createUser(String userFqn, String password, String description, Map<String, Object> additionalInfos) 897 throws CmsException { 898 899 return m_securityManager.createUser(m_context, userFqn, password, description, additionalInfos); 900 } 901 902 /** 903 * Deletes all published resource entries.<p> 904 * 905 * @param linkType the type of resource deleted (0= non-parameter, 1=parameter) 906 * 907 * @throws CmsException if something goes wrong 908 */ 909 public void deleteAllStaticExportPublishedResources(int linkType) throws CmsException { 910 911 m_securityManager.deleteAllStaticExportPublishedResources(m_context, linkType); 912 } 913 914 /** 915 * Deletes a group, where all permissions, users and children of the group 916 * are transfered to a replacement group.<p> 917 * 918 * @param groupId the id of the group to be deleted 919 * @param replacementId the id of the group to be transfered, can be <code>null</code> 920 * 921 * @throws CmsException if operation was not successful 922 */ 923 public void deleteGroup(CmsUUID groupId, CmsUUID replacementId) throws CmsException { 924 925 m_securityManager.deleteGroup(m_context, groupId, replacementId); 926 } 927 928 /** 929 * Deletes a user group.<p> 930 * 931 * Only groups that contain no subgroups can be deleted.<p> 932 * 933 * @param group the name of the group 934 * 935 * @throws CmsException if operation was not successful 936 */ 937 public void deleteGroup(String group) throws CmsException { 938 939 m_securityManager.deleteGroup(m_context, group); 940 } 941 942 /** 943 * Deletes the versions from the history tables, keeping the given number of versions per resource.<p> 944 * 945 * @param versionsToKeep number of versions to keep, is ignored if negative 946 * @param versionsDeleted number of versions to keep for deleted resources, is ignored if negative 947 * @param timeDeleted deleted resources older than this will also be deleted, is ignored if negative 948 * @param report the report for output logging 949 * 950 * @throws CmsException if operation was not successful 951 */ 952 public void deleteHistoricalVersions(int versionsToKeep, int versionsDeleted, long timeDeleted, I_CmsReport report) 953 throws CmsException { 954 955 m_securityManager.deleteHistoricalVersions(m_context, versionsToKeep, versionsDeleted, timeDeleted, report); 956 } 957 958 /** 959 * Deletes the log entries matching the given filter.<p> 960 * 961 * @param filter the filter to use for deleting the log entries 962 * 963 * @throws CmsException if something goes wrong 964 * 965 * @see CmsSecurityManager#deleteLogEntries(CmsRequestContext, CmsLogFilter) 966 * @see #getLogEntries(CmsLogFilter) 967 */ 968 public void deleteLogEntries(CmsLogFilter filter) throws CmsException { 969 970 m_securityManager.deleteLogEntries(m_context, filter); 971 } 972 973 /** 974 * Deletes a project.<p> 975 * 976 * All resources inside the project have to be be reset to their online state.<p> 977 * 978 * @param id the id of the project to delete 979 * 980 * @throws CmsException if operation was not successful 981 */ 982 public void deleteProject(CmsUUID id) throws CmsException { 983 984 m_securityManager.deleteProject(m_context, id); 985 } 986 987 /** 988 * Deletes a property definition.<p> 989 * 990 * @param name the name of the property definition to delete 991 * 992 * @throws CmsException if something goes wrong 993 */ 994 public void deletePropertyDefinition(String name) throws CmsException { 995 996 m_securityManager.deletePropertyDefinition(m_context, name); 997 } 998 999 /** 1000 * Deletes the relations to a given resource.<p> 1001 * 1002 * @param resource the resource to delete the relations from 1003 * @param filter the filter to use for deleting the relations 1004 * 1005 * @throws CmsException if something goes wrong 1006 */ 1007 public void deleteRelationsFromResource(CmsResource resource, CmsRelationFilter filter) throws CmsException { 1008 1009 m_securityManager.deleteRelationsForResource(m_context, resource, filter); 1010 } 1011 1012 /** 1013 * Deletes the relations to a given resource.<p> 1014 * 1015 * @param resourceName the resource to delete the relations from 1016 * @param filter the filter to use for deleting the relations 1017 * 1018 * @throws CmsException if something goes wrong 1019 */ 1020 public void deleteRelationsFromResource(String resourceName, CmsRelationFilter filter) throws CmsException { 1021 1022 CmsResource resource = readResource(resourceName, CmsResourceFilter.ALL); 1023 m_securityManager.deleteRelationsForResource(m_context, resource, filter); 1024 } 1025 1026 /** 1027 * Deletes a resource.<p> 1028 * 1029 * The <code>siblingMode</code> parameter controls how to handle siblings 1030 * during the delete operation.<br> 1031 * Possible values for this parameter are: <br> 1032 * <ul> 1033 * <li><code>{@link CmsResource#DELETE_REMOVE_SIBLINGS}</code></li> 1034 * <li><code>{@link CmsResource#DELETE_PRESERVE_SIBLINGS}</code></li> 1035 * </ul><p> 1036 * 1037 * @param res the resource to delete 1038 * @param deletePreserveSiblings indicates how to handle siblings of the deleted resource 1039 * 1040 * @throws CmsException if something goes wrong 1041 */ 1042 public void deleteResource(CmsResource res, CmsResourceDeleteMode deletePreserveSiblings) throws CmsException { 1043 1044 getResourceType(res).deleteResource(this, m_securityManager, res, deletePreserveSiblings); 1045 } 1046 1047 /** 1048 * Deletes a resource given its name.<p> 1049 * 1050 * The <code>siblingMode</code> parameter controls how to handle siblings 1051 * during the delete operation.<br> 1052 * Possible values for this parameter are: <br> 1053 * <ul> 1054 * <li><code>{@link CmsResource#DELETE_REMOVE_SIBLINGS}</code></li> 1055 * <li><code>{@link CmsResource#DELETE_PRESERVE_SIBLINGS}</code></li> 1056 * </ul><p> 1057 * 1058 * @param resourcename the name of the resource to delete (full current site relative path) 1059 * @param siblingMode indicates how to handle siblings of the deleted resource 1060 * 1061 * @throws CmsException if something goes wrong 1062 */ 1063 public void deleteResource(String resourcename, CmsResource.CmsResourceDeleteMode siblingMode) throws CmsException { 1064 1065 // throw the exception if resource name is an empty string 1066 if (CmsStringUtil.isEmptyOrWhitespaceOnly(resourcename)) { 1067 throw new CmsVfsResourceNotFoundException( 1068 Messages.get().container(Messages.ERR_DELETE_RESOURCE_1, resourcename)); 1069 } 1070 1071 CmsResource resource = readResource(resourcename, CmsResourceFilter.IGNORE_EXPIRATION); 1072 getResourceType(resource).deleteResource(this, m_securityManager, resource, siblingMode); 1073 } 1074 1075 /** 1076 * Deletes a published resource entry.<p> 1077 * 1078 * @param resourceName The name of the resource to be deleted in the static export 1079 * @param linkType the type of resource deleted (0= non-parameter, 1=parameter) 1080 * @param linkParameter the parameters of the resource 1081 * 1082 * @throws CmsException if something goes wrong 1083 */ 1084 public void deleteStaticExportPublishedResource(String resourceName, int linkType, String linkParameter) 1085 throws CmsException { 1086 1087 m_securityManager.deleteStaticExportPublishedResource(m_context, resourceName, linkType, linkParameter); 1088 } 1089 1090 /** 1091 * Deletes a user.<p> 1092 * 1093 * @param userId the id of the user to be deleted 1094 * 1095 * @throws CmsException if operation was not successful 1096 */ 1097 public void deleteUser(CmsUUID userId) throws CmsException { 1098 1099 m_securityManager.deleteUser(m_context, userId); 1100 } 1101 1102 /** 1103 * Deletes a user, where all permissions and resources attributes of the user 1104 * were transfered to a replacement user.<p> 1105 * 1106 * @param userId the id of the user to be deleted 1107 * @param replacementId the id of the user to be transfered, can be <code>null</code> 1108 * 1109 * @throws CmsException if operation was not successful 1110 */ 1111 public void deleteUser(CmsUUID userId, CmsUUID replacementId) throws CmsException { 1112 1113 m_securityManager.deleteUser(m_context, userId, replacementId); 1114 } 1115 1116 /** 1117 * Deletes a user.<p> 1118 * 1119 * @param username the name of the user to be deleted 1120 * 1121 * @throws CmsException if operation was not successful 1122 */ 1123 public void deleteUser(String username) throws CmsException { 1124 1125 m_securityManager.deleteUser(m_context, username); 1126 } 1127 1128 /** 1129 * Checks the availability of a resource in the VFS, 1130 * using the <code>{@link CmsResourceFilter#DEFAULT}</code> filter.<p> 1131 * 1132 * A resource may be of type <code>{@link CmsFile}</code> or 1133 * <code>{@link CmsFolder}</code>.<p> 1134 * 1135 * This method also takes into account the user permissions, so if 1136 * the given resource exists, but the current user has not the required 1137 * permissions, then this method will return <code>false</code>.<p> 1138 * 1139 * @param structureId the structure id of the resource to check 1140 * 1141 * @return <code>true</code> if the resource is available 1142 * 1143 * @see #readResource(CmsUUID) 1144 * @see #existsResource(CmsUUID, CmsResourceFilter) 1145 */ 1146 public boolean existsResource(CmsUUID structureId) { 1147 1148 return existsResource(structureId, CmsResourceFilter.DEFAULT); 1149 } 1150 1151 /** 1152 * Checks the availability of a resource in the VFS, 1153 * using the <code>{@link CmsResourceFilter#DEFAULT}</code> filter.<p> 1154 * 1155 * A resource may be of type <code>{@link CmsFile}</code> or 1156 * <code>{@link CmsFolder}</code>.<p> 1157 * 1158 * The specified filter controls what kind of resources should be "found" 1159 * during the read operation. This will depend on the application. For example, 1160 * using <code>{@link CmsResourceFilter#DEFAULT}</code> will only return currently 1161 * "valid" resources, while using <code>{@link CmsResourceFilter#IGNORE_EXPIRATION}</code> 1162 * will ignore the date release / date expired information of the resource.<p> 1163 * 1164 * This method also takes into account the user permissions, so if 1165 * the given resource exists, but the current user has not the required 1166 * permissions, then this method will return <code>false</code>.<p> 1167 * 1168 * @param structureId the structure id of the resource to check 1169 * @param filter the resource filter to use while checking 1170 * 1171 * @return <code>true</code> if the resource is available 1172 * 1173 * @see #readResource(CmsUUID) 1174 * @see #readResource(CmsUUID, CmsResourceFilter) 1175 */ 1176 public boolean existsResource(CmsUUID structureId, CmsResourceFilter filter) { 1177 1178 return m_securityManager.existsResource(m_context, structureId, filter); 1179 } 1180 1181 /** 1182 * Checks the availability of a resource in the VFS, 1183 * using the <code>{@link CmsResourceFilter#DEFAULT}</code> filter.<p> 1184 * 1185 * A resource may be of type <code>{@link CmsFile}</code> or 1186 * <code>{@link CmsFolder}</code>.<p> 1187 * 1188 * This method also takes into account the user permissions, so if 1189 * the given resource exists, but the current user has not the required 1190 * permissions, then this method will return <code>false</code>.<p> 1191 * 1192 * @param resourcename the name of the resource to check (full current site relative path) 1193 * 1194 * @return <code>true</code> if the resource is available 1195 * 1196 * @see #readResource(String) 1197 * @see #existsResource(String, CmsResourceFilter) 1198 */ 1199 public boolean existsResource(String resourcename) { 1200 1201 return existsResource(resourcename, CmsResourceFilter.DEFAULT); 1202 } 1203 1204 /** 1205 * Checks the availability of a resource in the VFS, 1206 * using the provided filter.<p> 1207 * 1208 * A resource may be of type <code>{@link CmsFile}</code> or 1209 * <code>{@link CmsFolder}</code>.<p> 1210 * 1211 * The specified filter controls what kind of resources should be "found" 1212 * during the read operation. This will depend on the application. For example, 1213 * using <code>{@link CmsResourceFilter#DEFAULT}</code> will only return currently 1214 * "valid" resources, while using <code>{@link CmsResourceFilter#IGNORE_EXPIRATION}</code> 1215 * will ignore the date release / date expired information of the resource.<p> 1216 * 1217 * This method also takes into account the user permissions, so if 1218 * the given resource exists, but the current user has not the required 1219 * permissions, then this method will return <code>false</code>.<p> 1220 * 1221 * @param resourcename the name of the resource to check (full current site relative path) 1222 * @param filter the resource filter to use while checking 1223 * 1224 * @return <code>true</code> if the resource is available 1225 * 1226 * @see #readResource(String) 1227 * @see #readResource(String, CmsResourceFilter) 1228 */ 1229 public boolean existsResource(String resourcename, CmsResourceFilter filter) { 1230 1231 return m_securityManager.existsResource(m_context, addSiteRoot(resourcename), filter); 1232 } 1233 1234 /** 1235 * Returns the list of access control entries of a resource given its name.<p> 1236 * 1237 * @param resourceName the name of the resource 1238 * 1239 * @return a list of <code>{@link CmsAccessControlEntry}</code> objects 1240 * 1241 * @throws CmsException if something goes wrong 1242 */ 1243 public List<CmsAccessControlEntry> getAccessControlEntries(String resourceName) throws CmsException { 1244 1245 return getAccessControlEntries(resourceName, true); 1246 } 1247 1248 /** 1249 * Returns the list of access control entries of a resource given its name.<p> 1250 * 1251 * @param resourceName the name of the resource 1252 * @param getInherited <code>true</code>, if inherited access control entries should be returned, too 1253 * 1254 * @return a list of <code>{@link CmsAccessControlEntry}</code> objects defining all permissions for the given resource 1255 * 1256 * @throws CmsException if something goes wrong 1257 */ 1258 public List<CmsAccessControlEntry> getAccessControlEntries(String resourceName, boolean getInherited) 1259 throws CmsException { 1260 1261 CmsResource res = readResource(resourceName, CmsResourceFilter.ALL); 1262 return m_securityManager.getAccessControlEntries(m_context, res, getInherited); 1263 } 1264 1265 /** 1266 * Returns the access control list (summarized access control entries) of a given resource.<p> 1267 * 1268 * @param resourceName the name of the resource 1269 * 1270 * @return the access control list of the resource 1271 * 1272 * @throws CmsException if something goes wrong 1273 */ 1274 public CmsAccessControlList getAccessControlList(String resourceName) throws CmsException { 1275 1276 return getAccessControlList(resourceName, false); 1277 } 1278 1279 /** 1280 * Returns the access control list (summarized access control entries) of a given resource.<p> 1281 * 1282 * If <code>inheritedOnly</code> is set, only inherited access control entries are returned.<p> 1283 * 1284 * @param resourceName the name of the resource 1285 * @param inheritedOnly if set, the non-inherited entries are skipped 1286 * 1287 * @return the access control list of the resource 1288 * 1289 * @throws CmsException if something goes wrong 1290 */ 1291 public CmsAccessControlList getAccessControlList(String resourceName, boolean inheritedOnly) throws CmsException { 1292 1293 CmsResource res = readResource(resourceName, CmsResourceFilter.ALL); 1294 return m_securityManager.getAccessControlList(m_context, res, inheritedOnly); 1295 } 1296 1297 /** 1298 * Gets all access control entries for the current project.<p> 1299 * 1300 * @return the list of all access control entries 1301 * 1302 * @throws CmsException if something goes wrong 1303 */ 1304 public List<CmsAccessControlEntry> getAllAccessControlEntries() throws CmsException { 1305 1306 return m_securityManager.getAllAccessControlEntries(m_context); 1307 } 1308 1309 /** 1310 * Returns a list with all projects from history.<p> 1311 * 1312 * @return list of <code>{@link CmsHistoryProject}</code> objects 1313 * with all projects from history 1314 * 1315 * @throws CmsException if operation was not successful 1316 */ 1317 public List<CmsHistoryProject> getAllHistoricalProjects() throws CmsException { 1318 1319 return m_securityManager.getAllHistoricalProjects(m_context); 1320 } 1321 1322 /** 1323 * Gets all URL names for a given structure id.<p> 1324 * 1325 * @param id the structure id 1326 * @return the list of all URL names for that structure id 1327 * 1328 * @throws CmsException if something goes wrong 1329 */ 1330 public List<String> getAllUrlNames(CmsUUID id) throws CmsException { 1331 1332 return m_securityManager.readAllUrlNameMappingEntries(m_context, id); 1333 } 1334 1335 /** 1336 * Returns a list of child resources to the given resource that can not be locked by the current user.<p> 1337 * 1338 * @param resource the resource 1339 * 1340 * @return a list of child resources to the given resource that can not be locked by the current user 1341 * 1342 * @throws CmsException if something goes wrong reading the resources 1343 */ 1344 public List<CmsResource> getBlockingLockedResources(CmsResource resource) throws CmsException { 1345 1346 if (resource.isFolder()) { 1347 CmsLockFilter blockingFilter = CmsLockFilter.FILTER_ALL; 1348 blockingFilter = blockingFilter.filterNotLockableByUser(getRequestContext().getCurrentUser()); 1349 return getLockedResources(resource, blockingFilter); 1350 } 1351 return Collections.<CmsResource> emptyList(); 1352 } 1353 1354 /** 1355 * Returns a list of child resources to the given resource that can not be locked by the current user.<p> 1356 * 1357 * @param resourceName the resource site path 1358 * 1359 * @return a list of child resources to the given resource that can not be locked by the current user 1360 * 1361 * @throws CmsException if something goes wrong reading the resources 1362 */ 1363 public List<CmsResource> getBlockingLockedResources(String resourceName) throws CmsException { 1364 1365 CmsResource resource = readResource(resourceName); 1366 return getBlockingLockedResources(resource); 1367 } 1368 1369 /** 1370 * Returns all child groups of a group.<p> 1371 * 1372 * @param groupname the name of the group 1373 * @param includeSubChildren if set also returns all sub-child groups of the given group 1374 * 1375 * @return a list of all child <code>{@link CmsGroup}</code> objects or <code>null</code> 1376 * 1377 * @throws CmsException if operation was not successful 1378 */ 1379 public List<CmsGroup> getChildren(String groupname, boolean includeSubChildren) throws CmsException { 1380 1381 return m_securityManager.getChildren(m_context, groupname, includeSubChildren); 1382 } 1383 1384 /** 1385 * Returns the detail name of a resource.<p> 1386 * 1387 * The detail view URI of a content element consists of its detail page URI and the detail name returned by this 1388 * method.<p> 1389 * 1390 * @param res the resource for which the detail name should be retrieved 1391 * @param locale the locale for the detail name 1392 * @param defaultLocales the default locales for the detail name 1393 * 1394 * @return the detail name 1395 * @throws CmsException if something goes wrong 1396 */ 1397 public String getDetailName(CmsResource res, Locale locale, List<Locale> defaultLocales) throws CmsException { 1398 1399 String urlName = readBestUrlName(res.getStructureId(), locale, defaultLocales); 1400 if (urlName == null) { 1401 urlName = res.getStructureId().toString(); 1402 } 1403 return urlName; 1404 } 1405 1406 /** 1407 * Returns all file resources contained in a folder.<p> 1408 * 1409 * The result is filtered according to the rules of 1410 * the <code>{@link CmsResourceFilter#DEFAULT}</code> filter.<p> 1411 * 1412 * @param resourcename the full current site relative path of the resource to return the child resources for 1413 * 1414 * @return a list of all child files as <code>{@link CmsResource}</code> objects 1415 * 1416 * @throws CmsException if something goes wrong 1417 * 1418 * @see #getFilesInFolder(String, CmsResourceFilter) 1419 */ 1420 public List<CmsResource> getFilesInFolder(String resourcename) throws CmsException { 1421 1422 return getFilesInFolder(resourcename, CmsResourceFilter.DEFAULT); 1423 } 1424 1425 /** 1426 * Returns all file resources contained in a folder.<p> 1427 * 1428 * With the <code>{@link CmsResourceFilter}</code> provided as parameter 1429 * you can control if you want to include deleted, invisible or 1430 * time-invalid resources in the result.<p> 1431 * 1432 * @param resourcename the full path of the resource to return the child resources for 1433 * @param filter the resource filter to use 1434 * 1435 * @return a list of all child file as <code>{@link CmsResource}</code> objects 1436 * 1437 * @throws CmsException if something goes wrong 1438 */ 1439 public List<CmsResource> getFilesInFolder(String resourcename, CmsResourceFilter filter) throws CmsException { 1440 1441 CmsResource resource = readResource(resourcename, CmsResourceFilter.ALL); 1442 return m_securityManager.readChildResources(m_context, resource, filter, false, true); 1443 } 1444 1445 /** 1446 * Returns all the groups the given user belongs to.<p> 1447 * 1448 * @param username the name of the user 1449 * @param directGroupsOnly if set only the direct assigned groups will be returned, if not also indirect roles 1450 * 1451 * @return a list of <code>{@link CmsGroup}</code> objects 1452 * 1453 * @throws CmsException if operation was not successful 1454 */ 1455 public List<CmsGroup> getGroupsOfUser(String username, boolean directGroupsOnly) throws CmsException { 1456 1457 return getGroupsOfUser(username, directGroupsOnly, true); 1458 } 1459 1460 /** 1461 * Returns all the groups the given user belongs to.<p> 1462 * 1463 * @param username the name of the user 1464 * @param directGroupsOnly if set only the direct assigned groups will be returned, if not also indirect roles 1465 * @param includeOtherOus if to include groups of other organizational units 1466 * 1467 * @return a list of <code>{@link CmsGroup}</code> objects 1468 * 1469 * @throws CmsException if operation was not successful 1470 */ 1471 public List<CmsGroup> getGroupsOfUser(String username, boolean directGroupsOnly, boolean includeOtherOus) 1472 throws CmsException { 1473 1474 return getGroupsOfUser(username, directGroupsOnly, includeOtherOus, m_context.getRemoteAddress()); 1475 } 1476 1477 /** 1478 * Returns the groups of a user filtered by the specified IP address.<p> 1479 * 1480 * @param username the name of the user 1481 * @param directGroupsOnly if set only the direct assigned groups will be returned, if not also indirect roles 1482 * @param remoteAddress the IP address to filter the groups in the result list 1483 * @param includeOtherOus if to include groups of other organizational units 1484 * 1485 * @return a list of <code>{@link CmsGroup}</code> objects filtered by the specified IP address 1486 * 1487 * @throws CmsException if operation was not successful 1488 */ 1489 public List<CmsGroup> getGroupsOfUser( 1490 String username, 1491 boolean directGroupsOnly, 1492 boolean includeOtherOus, 1493 String remoteAddress) 1494 throws CmsException { 1495 1496 return m_securityManager.getGroupsOfUser( 1497 m_context, 1498 username, 1499 (includeOtherOus ? "" : CmsOrganizationalUnit.getParentFqn(username)), 1500 includeOtherOus, 1501 false, 1502 directGroupsOnly, 1503 remoteAddress); 1504 } 1505 1506 /** 1507 * Creates a new locale group service.<p> 1508 * 1509 * @return a locale group service instance 1510 */ 1511 public CmsLocaleGroupService getLocaleGroupService() { 1512 1513 return new CmsLocaleGroupService(this); 1514 } 1515 1516 /** 1517 * Returns the edition lock state for a specified resource.<p> 1518 * 1519 * If the resource is waiting to be publish you might get a lock of type {@link CmsLockType#PUBLISH}.<p> 1520 * 1521 * @param resource the resource to return the edition lock state for 1522 * 1523 * @return the edition lock state for the specified resource 1524 * 1525 * @throws CmsException if something goes wrong 1526 */ 1527 public CmsLock getLock(CmsResource resource) throws CmsException { 1528 1529 return m_securityManager.getLock(m_context, resource); 1530 } 1531 1532 /** 1533 * Returns the lock state for a specified resource name.<p> 1534 * 1535 * If the resource is waiting to be publish you might get a lock of type {@link CmsLockType#PUBLISH}.<p> 1536 * 1537 * @param resourcename the name if the resource to get the lock state for (full current site relative path) 1538 * 1539 * @return the lock state for the specified resource 1540 * 1541 * @throws CmsException if something goes wrong 1542 */ 1543 public CmsLock getLock(String resourcename) throws CmsException { 1544 1545 CmsResource resource = readResource(resourcename, CmsResourceFilter.ALL); 1546 return getLock(resource); 1547 } 1548 1549 /** 1550 * Returns all locked resources within a folder or matches the lock of the given resource.<p> 1551 * 1552 * @param resource the resource to check 1553 * @param filter the lock filter 1554 * 1555 * @return a list of locked resources 1556 * 1557 * @throws CmsException if operation was not successful 1558 */ 1559 public List<CmsResource> getLockedResources(CmsResource resource, CmsLockFilter filter) throws CmsException { 1560 1561 return m_securityManager.getLockedResourcesObjects(m_context, resource, filter); 1562 } 1563 1564 /** 1565 * Returns all locked resources within a folder or matches the lock of the given resource.<p> 1566 * 1567 * @param resourceName the name of the resource to check 1568 * @param filter the lock filter 1569 * 1570 * @return a list of locked resource paths (relative to current site) 1571 * 1572 * @throws CmsException if operation was not successful 1573 */ 1574 public List<String> getLockedResources(String resourceName, CmsLockFilter filter) throws CmsException { 1575 1576 CmsResource resource = readResource(resourceName, CmsResourceFilter.ALL); 1577 return m_securityManager.getLockedResources(m_context, resource, filter); 1578 } 1579 1580 /** 1581 * Returns all locked resources within a folder or matches the lock of the given resource, but uses a cache for resource lookup.<p> 1582 * 1583 * @param resource the resource to check 1584 * @param filter the lock filter 1585 * @param cache the cache to use for resource lookups 1586 * 1587 * @return a list of locked resources 1588 * 1589 * @throws CmsException if operation was not successful 1590 */ 1591 public List<CmsResource> getLockedResourcesWithCache( 1592 CmsResource resource, 1593 CmsLockFilter filter, 1594 Map<String, CmsResource> cache) 1595 throws CmsException { 1596 1597 return m_securityManager.getLockedResourcesObjectsWithCache(m_context, resource, filter, cache); 1598 } 1599 1600 /** 1601 * Returns all log entries matching the given filter.<p> 1602 * 1603 * @param filter the filter to match the relation 1604 * 1605 * @return a list containing all log entries matching the given filter 1606 * 1607 * @throws CmsException if something goes wrong 1608 * 1609 * @see CmsSecurityManager#getLogEntries(CmsRequestContext, CmsLogFilter) 1610 * @see #deleteLogEntries(CmsLogFilter) 1611 */ 1612 public List<CmsLogEntry> getLogEntries(CmsLogFilter filter) throws CmsException { 1613 1614 return m_securityManager.getLogEntries(m_context, filter); 1615 } 1616 1617 /** 1618 * Returns the name a resource would have if it were moved to the 1619 * "lost and found" folder. <p> 1620 * 1621 * In general, it is the same name as the given resource has, the only exception is 1622 * if a resource in the "lost and found" folder with the same name already exists. 1623 * In such case, a counter is added to the resource name.<p> 1624 * 1625 * @param resourcename the name of the resource to get the "lost and found" name for (full current site relative path) 1626 * 1627 * @return the tentative name of the resource inside the "lost and found" folder 1628 * 1629 * @throws CmsException if something goes wrong 1630 * 1631 * @see #moveToLostAndFound(String) 1632 */ 1633 public String getLostAndFoundName(String resourcename) throws CmsException { 1634 1635 CmsResource resource = readResource(resourcename, CmsResourceFilter.ALL); 1636 return m_securityManager.moveToLostAndFound(m_context, resource, true); 1637 } 1638 1639 /** 1640 * Returns the parent group of a group.<p> 1641 * 1642 * @param groupname the name of the group 1643 * 1644 * @return group the parent group or <code>null</code> 1645 * 1646 * @throws CmsException if operation was not successful 1647 */ 1648 public CmsGroup getParent(String groupname) throws CmsException { 1649 1650 return m_securityManager.getParent(m_context, groupname); 1651 } 1652 1653 /** 1654 * Returns the set of permissions of the current user for a given resource.<p> 1655 * 1656 * @param resourceName the name of the resource 1657 * 1658 * @return the bit set of the permissions of the current user 1659 * 1660 * @throws CmsException if something goes wrong 1661 */ 1662 public CmsPermissionSet getPermissions(String resourceName) throws CmsException { 1663 1664 return getPermissions(resourceName, m_context.getCurrentUser().getName()); 1665 } 1666 1667 /** 1668 * Returns the set of permissions of a given user for a given resource.<p> 1669 * 1670 * @param resourceName the name of the resource 1671 * @param userName the name of the user 1672 * 1673 * @return the current permissions on this resource 1674 * 1675 * @throws CmsException if something goes wrong 1676 */ 1677 public CmsPermissionSet getPermissions(String resourceName, String userName) throws CmsException { 1678 1679 // reading permissions is allowed even if the resource is marked as deleted 1680 CmsResource resource = readResource(resourceName, CmsResourceFilter.ALL); 1681 CmsUser user = readUser(userName); 1682 return m_securityManager.getPermissions(m_context, resource, user); 1683 } 1684 1685 /** 1686 * Returns all relations for the given resource matching the given filter.<p> 1687 * 1688 * You should have view/read permissions on the given resource.<p> 1689 * 1690 * You may become source and/or target paths to resource you do not have view/read permissions on.<p> 1691 * 1692 * @param resource the resource to retrieve the relations for 1693 * @param filter the filter to match the relation 1694 * 1695 * @return a List containing all {@link org.opencms.relations.CmsRelation} 1696 * objects for the given resource matching the given filter 1697 * 1698 * @throws CmsException if something goes wrong 1699 * 1700 * @see CmsSecurityManager#getRelationsForResource(CmsRequestContext, CmsResource, CmsRelationFilter) 1701 */ 1702 public List<CmsRelation> getRelationsForResource(CmsResource resource, CmsRelationFilter filter) 1703 throws CmsException { 1704 1705 return m_securityManager.getRelationsForResource(m_context, resource, filter); 1706 } 1707 1708 /** 1709 * Returns all relations for the given resource matching the given filter.<p> 1710 * 1711 * You should have view/read permissions on the given resource.<p> 1712 * 1713 * You may become source and/or target paths to resource you do not have view/read permissions on.<p> 1714 * 1715 * @param resourceName the name of the resource to retrieve the relations for 1716 * @param filter the filter to match the relation 1717 * 1718 * @return a List containing all {@link org.opencms.relations.CmsRelation} 1719 * objects for the given resource matching the given filter 1720 * 1721 * @throws CmsException if something goes wrong 1722 * 1723 * @see CmsSecurityManager#getRelationsForResource(CmsRequestContext, CmsResource, CmsRelationFilter) 1724 */ 1725 public List<CmsRelation> getRelationsForResource(String resourceName, CmsRelationFilter filter) 1726 throws CmsException { 1727 1728 return getRelationsForResource(readResource(resourceName, CmsResourceFilter.ALL), filter); 1729 } 1730 1731 /** 1732 * Returns the current users request context.<p> 1733 * 1734 * This request context is used to authenticate the user for all 1735 * OpenCms operations. It also contains the request runtime settings, e.g. 1736 * about the current site this request was made on.<p> 1737 * 1738 * @return the current users request context 1739 */ 1740 public CmsRequestContext getRequestContext() { 1741 1742 return m_context; 1743 } 1744 1745 /** 1746 * Returns all resources associated to a given principal via an ACE with the given permissions.<p> 1747 * 1748 * If the <code>includeAttr</code> flag is set it returns also all resources associated to 1749 * a given principal through some of following attributes.<p> 1750 * 1751 * <ul> 1752 * <li>User Created</li> 1753 * <li>User Last Modified</li> 1754 * </ul><p> 1755 * 1756 * @param principalId the id of the principal 1757 * @param permissions a set of permissions to match, can be <code>null</code> for all ACEs 1758 * @param includeAttr a flag to include resources associated by attributes 1759 * 1760 * @return a set of <code>{@link CmsResource}</code> objects 1761 * 1762 * @throws CmsException if something goes wrong 1763 */ 1764 public Set<CmsResource> getResourcesForPrincipal( 1765 CmsUUID principalId, 1766 CmsPermissionSet permissions, 1767 boolean includeAttr) 1768 throws CmsException { 1769 1770 return m_securityManager.getResourcesForPrincipal(getRequestContext(), principalId, permissions, includeAttr); 1771 } 1772 1773 /** 1774 * Returns all child resources of a resource, that is the resources 1775 * contained in a folder.<p> 1776 * 1777 * With the <code>{@link CmsResourceFilter}</code> provided as parameter 1778 * you can control if you want to include deleted, invisible or 1779 * time-invalid resources in the result.<p> 1780 * 1781 * This method is mainly used by the workplace explorer.<p> 1782 * 1783 * @param resourcename the full current site relative path of the resource to return the child resources for 1784 * @param filter the resource filter to use 1785 * 1786 * @return a list of all child <code>{@link CmsResource}</code>s 1787 * 1788 * @throws CmsException if something goes wrong 1789 */ 1790 public List<CmsResource> getResourcesInFolder(String resourcename, CmsResourceFilter filter) throws CmsException { 1791 1792 CmsResource resource = readResource(resourcename, CmsResourceFilter.ALL); 1793 return m_securityManager.readChildResources(m_context, resource, filter, true, true); 1794 } 1795 1796 /** 1797 * Adjusts the absolute resource root path for the current site.<p> 1798 * 1799 * The full root path of a resource is always available using 1800 * <code>{@link CmsResource#getRootPath()}</code>. From this name this method cuts 1801 * of the current site root using 1802 * <code>{@link CmsRequestContext#removeSiteRoot(String)}</code>.<p> 1803 * 1804 * If the resource root path does not start with the current site root, 1805 * it is left untouched.<p> 1806 * 1807 * @param resource the resource to get the adjusted site root path for 1808 * 1809 * @return the absolute resource path adjusted for the current site 1810 * 1811 * @see CmsRequestContext#removeSiteRoot(String) 1812 * @see CmsRequestContext#getSitePath(CmsResource) 1813 * @see CmsResource#getRootPath() 1814 */ 1815 public String getSitePath(CmsResource resource) { 1816 1817 return m_context.getSitePath(resource); 1818 } 1819 1820 /** 1821 * Returns all folder resources contained in a folder.<p> 1822 * 1823 * The result is filtered according to the rules of 1824 * the <code>{@link CmsResourceFilter#DEFAULT}</code> filter.<p> 1825 * 1826 * @param resourcename the full current site relative path of the resource to return the child resources for. 1827 * 1828 * @return a list of all child file as <code>{@link CmsResource}</code> objects 1829 * 1830 * @throws CmsException if something goes wrong 1831 * 1832 * @see #getSubFolders(String, CmsResourceFilter) 1833 */ 1834 public List<CmsResource> getSubFolders(String resourcename) throws CmsException { 1835 1836 return getSubFolders(resourcename, CmsResourceFilter.DEFAULT); 1837 } 1838 1839 /** 1840 * Returns all folder resources contained in a folder.<p> 1841 * 1842 * With the <code>{@link CmsResourceFilter}</code> provided as parameter 1843 * you can control if you want to include deleted, invisible or 1844 * time-invalid resources in the result.<p> 1845 * 1846 * @param resourcename the full current site relative path of the resource to return the child resources for. 1847 * 1848 * @return a list of all child folder <code>{@link CmsResource}</code>s 1849 * @param filter the resource filter to use 1850 * 1851 * @throws CmsException if something goes wrong 1852 */ 1853 public List<CmsResource> getSubFolders(String resourcename, CmsResourceFilter filter) throws CmsException { 1854 1855 CmsResource resource = readResource(resourcename, CmsResourceFilter.ALL); 1856 return m_securityManager.readChildResources(m_context, resource, filter, true, false); 1857 } 1858 1859 /** 1860 * Returns the newest URL names for the given structure id for each locale.<p> 1861 * 1862 * @param id the structure id 1863 * @return the list of URL names for each locale 1864 * 1865 * @throws CmsException if something goes wrong 1866 */ 1867 public List<String> getUrlNamesForAllLocales(CmsUUID id) throws CmsException { 1868 1869 return m_securityManager.readUrlNamesForAllLocales(m_context, id); 1870 } 1871 1872 /** 1873 * Returns all direct users of a given group.<p> 1874 * 1875 * Users that are "indirectly" in the group are not returned in the result.<p> 1876 * 1877 * @param groupname the name of the group to get all users for 1878 * 1879 * @return all <code>{@link CmsUser}</code> objects in the group 1880 * 1881 * @throws CmsException if operation was not successful 1882 */ 1883 public List<CmsUser> getUsersOfGroup(String groupname) throws CmsException { 1884 1885 return getUsersOfGroup(groupname, true); 1886 } 1887 1888 /** 1889 * Returns all direct users of a given group.<p> 1890 * 1891 * Users that are "indirectly" in the group are not returned in the result.<p> 1892 * 1893 * @param groupname the name of the group to get all users for 1894 * @param includeOtherOus if the result should include users of other ous 1895 * 1896 * @return all <code>{@link CmsUser}</code> objects in the group 1897 * 1898 * @throws CmsException if operation was not successful 1899 */ 1900 public List<CmsUser> getUsersOfGroup(String groupname, boolean includeOtherOus) throws CmsException { 1901 1902 return m_securityManager.getUsersOfGroup(m_context, groupname, includeOtherOus, true, false); 1903 } 1904 1905 /** 1906 * Checks if the current user has required permissions to access a given resource.<p> 1907 * 1908 * @param resource the resource to check the permissions for 1909 * @param requiredPermissions the set of permissions to check for 1910 * 1911 * @return <code>true</code> if the required permissions are satisfied 1912 * 1913 * @throws CmsException if something goes wrong 1914 */ 1915 public boolean hasPermissions(CmsResource resource, CmsPermissionSet requiredPermissions) throws CmsException { 1916 1917 return m_securityManager.hasPermissions( 1918 m_context, 1919 resource, 1920 requiredPermissions, 1921 true, 1922 CmsResourceFilter.ALL).isAllowed(); 1923 } 1924 1925 /** 1926 * Checks if the current user has required permissions to access a given resource.<p> 1927 * 1928 * @param resource the resource to check the permissions for 1929 * @param requiredPermissions the set of permissions to check for 1930 * @param checkLock if <code>true</code> the lock status of the resource is checked for write operations 1931 * and the resource needs be locked by the current user so that the test is passed, 1932 * if <code>false</code> the lock is not checked at all 1933 * @param filter the resource filter to use 1934 * 1935 * @return <code>true</code> if the required permissions are satisfied 1936 * 1937 * @throws CmsException if something goes wrong 1938 */ 1939 public boolean hasPermissions( 1940 CmsResource resource, 1941 CmsPermissionSet requiredPermissions, 1942 boolean checkLock, 1943 CmsResourceFilter filter) 1944 throws CmsException { 1945 1946 return I_CmsPermissionHandler.PERM_ALLOWED == m_securityManager.hasPermissions( 1947 m_context, 1948 resource, 1949 requiredPermissions, 1950 checkLock, 1951 filter); 1952 } 1953 1954 /** 1955 * Writes a list of access control entries as new access control entries of a given resource.<p> 1956 * 1957 * Already existing access control entries of this resource are removed before.<p> 1958 * 1959 * @param resource the resource to attach the control entries to 1960 * @param acEntries a list of <code>{@link CmsAccessControlEntry}</code> objects 1961 * 1962 * @throws CmsException if something goes wrong 1963 */ 1964 public void importAccessControlEntries(CmsResource resource, List<CmsAccessControlEntry> acEntries) 1965 throws CmsException { 1966 1967 m_securityManager.importAccessControlEntries(m_context, resource, acEntries); 1968 } 1969 1970 /** 1971 * Imports a new relation to the given resource.<p> 1972 * 1973 * @param resourceName the name of the source resource 1974 * @param targetPath the path of the target resource 1975 * @param relationType the type of the relation 1976 * 1977 * @throws CmsException if something goes wrong 1978 */ 1979 public void importRelation(String resourceName, String targetPath, String relationType) throws CmsException { 1980 1981 createRelation(resourceName, targetPath, relationType, true); 1982 } 1983 1984 /** 1985 * Imports a resource to the OpenCms VFS.<p> 1986 * 1987 * If a resource already exists in the VFS (i.e. has the same name and 1988 * same id) it is replaced by the imported resource.<p> 1989 * 1990 * If a resource with the same name but a different id exists, 1991 * the imported resource is (usually) moved to the "lost and found" folder.<p> 1992 * 1993 * @param resourcename the name for the resource after import (full current site relative path) 1994 * @param resource the resource object to be imported 1995 * @param content the content of the resource 1996 * @param properties the properties of the resource 1997 * 1998 * @return the imported resource 1999 * 2000 * @throws CmsException if something goes wrong 2001 * 2002 * @see CmsObject#moveToLostAndFound(String) 2003 */ 2004 public CmsResource importResource( 2005 String resourcename, 2006 CmsResource resource, 2007 byte[] content, 2008 List<CmsProperty> properties) 2009 throws CmsException { 2010 2011 return getResourceType( 2012 resource).importResource(this, m_securityManager, resourcename, resource, content, properties); 2013 } 2014 2015 /** 2016 * Creates a new user by import.<p> 2017 * 2018 * @param id the id of the user 2019 * @param name the new name for the user 2020 * @param password the new password for the user 2021 * @param firstname the first name of the user 2022 * @param lastname the last name of the user 2023 * @param email the email of the user 2024 * @param flags the flags for a user (for example <code>{@link I_CmsPrincipal#FLAG_ENABLED}</code>) 2025 * @param dateCreated the creation date 2026 * @param additionalInfos the additional user infos 2027 * 2028 * @return the imported user 2029 * 2030 * @throws CmsException if something goes wrong 2031 */ 2032 public CmsUser importUser( 2033 String id, 2034 String name, 2035 String password, 2036 String firstname, 2037 String lastname, 2038 String email, 2039 int flags, 2040 long dateCreated, 2041 Map<String, Object> additionalInfos) 2042 throws CmsException { 2043 2044 return m_securityManager.importUser( 2045 m_context, 2046 id, 2047 name, 2048 password, 2049 firstname, 2050 lastname, 2051 email, 2052 flags, 2053 dateCreated, 2054 additionalInfos); 2055 } 2056 2057 /** 2058 * Increments a counter and returns its old value.<p> 2059 * 2060 * @param name the name of the counter 2061 * 2062 * @return the value of the counter before incrementing 2063 * 2064 * @throws CmsException if something goes wrong 2065 */ 2066 public int incrementCounter(String name) throws CmsException { 2067 2068 return m_securityManager.incrementCounter(m_context, name); 2069 } 2070 2071 /** 2072 * Checks if the specified resource is inside the current project.<p> 2073 * 2074 * The project "view" is determined by a set of path prefixes. 2075 * If the resource starts with any one of this prefixes, it is considered to 2076 * be "inside" the project.<p> 2077 * 2078 * @param resourcename the specified resource name (full current site relative path) 2079 * 2080 * @return <code>true</code>, if the specified resource is inside the current project 2081 */ 2082 public boolean isInsideCurrentProject(String resourcename) { 2083 2084 return m_securityManager.isInsideCurrentProject(m_context, addSiteRoot(resourcename)); 2085 } 2086 2087 /** 2088 * Checks if the current user has management access to the current project.<p> 2089 * 2090 * @return <code>true</code>, if the user has management access to the current project 2091 */ 2092 2093 public boolean isManagerOfProject() { 2094 2095 return m_securityManager.isManagerOfProject(m_context); 2096 } 2097 2098 /** 2099 * Locks a resource.<p> 2100 * 2101 * This will be an exclusive, persistent lock that is removed only if the user unlocks it.<p> 2102 * 2103 * @param resource the resource to lock 2104 * 2105 * @throws CmsException if something goes wrong 2106 */ 2107 public void lockResource(CmsResource resource) throws CmsException { 2108 2109 getResourceType(resource).lockResource(this, m_securityManager, resource, CmsLockType.EXCLUSIVE); 2110 } 2111 2112 /** 2113 * Locks a resource.<p> 2114 * 2115 * This will be an exclusive, persistent lock that is removed only if the user unlocks it.<p> 2116 * 2117 * @param resourcename the name of the resource to lock (full current site relative path) 2118 * 2119 * @throws CmsException if something goes wrong 2120 */ 2121 public void lockResource(String resourcename) throws CmsException { 2122 2123 lockResource(resourcename, CmsLockType.EXCLUSIVE); 2124 } 2125 2126 /** 2127 * Locks a resource temporary.<p> 2128 * 2129 * This will be an exclusive, temporary lock valid only for the current users session. 2130 * Usually this should not be used directly, this method is intended for the OpenCms workplace only.<p> 2131 * 2132 * @param resource the resource to lock 2133 * 2134 * @throws CmsException if something goes wrong 2135 * 2136 * @see CmsObject#lockResource(String) 2137 */ 2138 public void lockResourceTemporary(CmsResource resource) throws CmsException { 2139 2140 getResourceType(resource).lockResource(this, m_securityManager, resource, CmsLockType.TEMPORARY); 2141 } 2142 2143 /** 2144 * Locks a resource temporary.<p> 2145 * 2146 * This will be an exclusive, temporary lock valid only for the current users session. 2147 * Usually this should not be used directly, this method is intended for the OpenCms workplace only.<p> 2148 * 2149 * @param resourcename the name of the resource to lock (full current site relative path) 2150 * 2151 * @throws CmsException if something goes wrong 2152 * 2153 * @see CmsObject#lockResource(String) 2154 */ 2155 public void lockResourceTemporary(String resourcename) throws CmsException { 2156 2157 lockResource(resourcename, CmsLockType.TEMPORARY); 2158 } 2159 2160 /** 2161 * Logs a user into the Cms, if the password is correct.<p> 2162 * 2163 * @param username the name of the user 2164 * @param password the password of the user 2165 * 2166 * @return the name of the logged in user 2167 * 2168 * @throws CmsException if the login was not successful 2169 */ 2170 public String loginUser(String username, String password) throws CmsException { 2171 2172 return loginUser(username, password, m_context.getRemoteAddress()); 2173 } 2174 2175 /** 2176 * Logs a user with a given ip address into the Cms, if the password is correct.<p> 2177 * 2178 * @param username the name of the user 2179 * @param password the password of the user 2180 * @param remoteAddress the ip address 2181 * 2182 * @return the name of the logged in user 2183 * 2184 * @throws CmsException if the login was not successful 2185 */ 2186 public String loginUser(String username, String password, String remoteAddress) throws CmsException { 2187 2188 // login the user 2189 CmsUser newUser = m_securityManager.loginUser(m_context, username, password, remoteAddress); 2190 // set the project back to the "Online" project 2191 CmsProject newProject = m_securityManager.readProject(CmsProject.ONLINE_PROJECT_ID); 2192 // switch the cms context to the new user and project 2193 m_context.switchUser(newUser, newProject, newUser.getOuFqn()); 2194 // init this CmsObject with the new user 2195 init(m_securityManager, m_context); 2196 // fire a login event 2197 fireEvent(I_CmsEventListener.EVENT_LOGIN_USER, newUser); 2198 // return the users login name 2199 return newUser.getName(); 2200 } 2201 2202 /** 2203 * Lookups and reads the user or group with the given UUID.<p> 2204 * 2205 * @param principalId the uuid of a user or group 2206 * 2207 * @return the user or group with the given UUID 2208 */ 2209 public I_CmsPrincipal lookupPrincipal(CmsUUID principalId) { 2210 2211 return m_securityManager.lookupPrincipal(m_context, principalId); 2212 } 2213 2214 /** 2215 * Lookups and reads the user or group with the given name.<p> 2216 * 2217 * @param principalName the name of the user or group 2218 * 2219 * @return the user or group with the given name 2220 */ 2221 public I_CmsPrincipal lookupPrincipal(String principalName) { 2222 2223 return m_securityManager.lookupPrincipal(m_context, principalName); 2224 } 2225 2226 /** 2227 * Moves a resource to the given destination.<p> 2228 * 2229 * A move operation in OpenCms is always a copy (as sibling) followed by a delete, 2230 * this is a result of the online/offline structure of the 2231 * OpenCms VFS. This way you can see the deleted files/folders in the offline 2232 * project, and you will be unable to undelete them.<p> 2233 * 2234 * @param source the name of the resource to move (full current site relative path) 2235 * @param destination the destination resource name (full current site relative path) 2236 * 2237 * @throws CmsException if something goes wrong 2238 * 2239 * @see #renameResource(String, String) 2240 */ 2241 public void moveResource(String source, String destination) throws CmsException { 2242 2243 CmsResource resource = readResource(source, CmsResourceFilter.IGNORE_EXPIRATION); 2244 getResourceType(resource).moveResource(this, m_securityManager, resource, destination); 2245 } 2246 2247 /** 2248 * Moves a resource to the "lost and found" folder.<p> 2249 * 2250 * The "lost and found" folder is a special system folder. 2251 * 2252 * This operation is used e.g. during import of resources 2253 * when a resource with the same name but a different resource ID 2254 * already exists in the VFS. In this case, the imported resource is 2255 * moved to the "lost and found" folder.<p> 2256 * 2257 * @param resourcename the name of the resource to move to "lost and found" (full current site relative path) 2258 * 2259 * @return the name of the resource inside the "lost and found" folder 2260 * 2261 * @throws CmsException if something goes wrong 2262 * 2263 * @see #getLostAndFoundName(String) 2264 */ 2265 public String moveToLostAndFound(String resourcename) throws CmsException { 2266 2267 CmsResource resource = readResource(resourcename, CmsResourceFilter.ALL); 2268 return m_securityManager.moveToLostAndFound(m_context, resource, false); 2269 } 2270 2271 /** 2272 * Reads all available versions for a given resource.<p> 2273 * 2274 * @param resource the resource for which to read the versions 2275 * @return the list of historical versions of the resource 2276 * 2277 * @throws CmsException if something goes wrong 2278 */ 2279 public List<I_CmsHistoryResource> readAllAvailableVersions(CmsResource resource) throws CmsException { 2280 2281 return m_securityManager.readAllAvailableVersions(m_context, resource); 2282 } 2283 2284 /** 2285 * Reads all historical versions of a resource.<br> 2286 * 2287 * The reading excludes the file content, if the resource is a file.<p> 2288 * 2289 * @param resourceName the name of the resource to be read 2290 * 2291 * @return a list of historical resources, as <code>{@link I_CmsHistoryResource}</code> objects 2292 * 2293 * @throws CmsException if operation was not successful 2294 */ 2295 public List<I_CmsHistoryResource> readAllAvailableVersions(String resourceName) throws CmsException { 2296 2297 CmsResource resource = readResource(resourceName, CmsResourceFilter.ALL); 2298 return m_securityManager.readAllAvailableVersions(m_context, resource); 2299 } 2300 2301 /** 2302 * Reads all property definitions.<p> 2303 * 2304 * @return a list with the <code>{@link CmsPropertyDefinition}</code> objects (may be empty) 2305 * 2306 * @throws CmsException if something goes wrong 2307 */ 2308 public List<CmsPropertyDefinition> readAllPropertyDefinitions() throws CmsException { 2309 2310 return m_securityManager.readAllPropertyDefinitions(m_context); 2311 } 2312 2313 /** 2314 * Returns the first ancestor folder matching the filter criteria.<p> 2315 * 2316 * If no folder matching the filter criteria is found, null is returned.<p> 2317 * 2318 * @param resourcename the name of the resource to start (full current site relative path) 2319 * @param filter the resource filter to match while reading the ancestors 2320 * 2321 * @return the first ancestor folder matching the filter criteria or null if no folder was found 2322 * 2323 * @throws CmsException if something goes wrong 2324 */ 2325 public CmsFolder readAncestor(String resourcename, CmsResourceFilter filter) throws CmsException { 2326 2327 CmsResource resource = readResource(resourcename, CmsResourceFilter.ALL); 2328 return m_securityManager.readAncestor(m_context, resource, filter); 2329 } 2330 2331 /** 2332 * Returns the first ancestor folder matching the resource type.<p> 2333 * 2334 * If no folder with the requested resource type is found, null is returned.<p> 2335 * 2336 * @param resourcename the name of the resource to start (full current site relative path) 2337 * @param type the resource type of the folder to match 2338 * 2339 * @return the first ancestor folder matching the filter criteria or null if no folder was found 2340 * 2341 * @throws CmsException if something goes wrong 2342 */ 2343 @SuppressWarnings("deprecation") 2344 public CmsFolder readAncestor(String resourcename, int type) throws CmsException { 2345 2346 return readAncestor(resourcename, CmsResourceFilter.requireType(type)); 2347 } 2348 2349 /** 2350 * Reads the newest URL name which is mapped to the given structure id.<p> 2351 * 2352 * If the structure id is not mapped to any name, null will be returned.<p> 2353 * 2354 * @param id the structure id for which the newest mapped name should be returned 2355 * @param locale the locale for which the URL name should be selected if possible 2356 * @param defaultLocales the default locales which should be used if the locale is not available 2357 * @return an URL name or null 2358 * @throws CmsException if something goes wrong 2359 */ 2360 public String readBestUrlName(CmsUUID id, Locale locale, List<Locale> defaultLocales) throws CmsException { 2361 2362 return m_securityManager.readBestUrlName(m_context, id, locale, defaultLocales); 2363 } 2364 2365 /** 2366 * Returns the default resource for the given folder.<p> 2367 * <ol> 2368 * <li>the {@link CmsPropertyDefinition#PROPERTY_DEFAULT_FILE} is checked, and 2369 * <li>if still no file could be found, the configured default files in the 2370 * <code>opencms-vfs.xml</code> configuration are iterated until a match is 2371 * found, and 2372 * <li>if still no file could be found, <code>null</code> is returned 2373 * </ol> 2374 * 2375 * @param folderResource the folder 2376 * @param resourceFilter the resource filter 2377 * 2378 * @return the default file for the given folder 2379 * 2380 * @throws CmsSecurityException if the user has no permissions to read the resulting file 2381 */ 2382 public CmsResource readDefaultFile(CmsResource folderResource, CmsResourceFilter resourceFilter) 2383 throws CmsSecurityException { 2384 2385 return m_securityManager.readDefaultFile(m_context, folderResource, resourceFilter); 2386 } 2387 2388 /** 2389 * Returns the default resource for the given folder.<p> 2390 * 2391 * If the given resource name or id identifies a file, then this file is returned.<p> 2392 * 2393 * Otherwise, in case of a folder:<br> 2394 * <ol> 2395 * <li>the {@link CmsPropertyDefinition#PROPERTY_DEFAULT_FILE} is checked, and 2396 * <li>if still no file could be found, the configured default files in the 2397 * <code>opencms-vfs.xml</code> configuration are iterated until a match is 2398 * found, and 2399 * <li>if still no file could be found, <code>null</code> is returned 2400 * </ol> 2401 * 2402 * @param resourceNameOrID the name or id of the folder to read the default file for 2403 * 2404 * @return the default file for the given folder 2405 * 2406 * @throws CmsException if something goes wrong 2407 * @throws CmsSecurityException if the user has no permissions to read the resulting file 2408 */ 2409 public CmsResource readDefaultFile(String resourceNameOrID) throws CmsException, CmsSecurityException { 2410 2411 return readDefaultFile(resourceNameOrID, CmsResourceFilter.DEFAULT); 2412 } 2413 2414 /** 2415 * Returns the default resource for the given folder.<p> 2416 * 2417 * If the given resource name or id identifies a file, then this file is returned.<p> 2418 * 2419 * Otherwise, in case of a folder:<br> 2420 * <ol> 2421 * <li>the {@link CmsPropertyDefinition#PROPERTY_DEFAULT_FILE} is checked, and 2422 * <li>if still no file could be found, the configured default files in the 2423 * <code>opencms-vfs.xml</code> configuration are iterated until a match is 2424 * found, and 2425 * <li>if still no file could be found, <code>null</code> is returned 2426 * </ol> 2427 * 2428 * @param resourceNameOrID the name or id of the folder to read the default file for# 2429 * @param filter the resource filter to use for reading the resources 2430 * 2431 * @return the default file for the given folder 2432 * 2433 * @throws CmsException if something goes wrong 2434 * @throws CmsSecurityException if the user has no permissions to read the resulting file 2435 */ 2436 public CmsResource readDefaultFile(String resourceNameOrID, CmsResourceFilter filter) 2437 throws CmsException, CmsSecurityException { 2438 2439 CmsResource resource; 2440 if (CmsUUID.isValidUUID(resourceNameOrID)) { 2441 resource = readResource(new CmsUUID(resourceNameOrID), filter); 2442 } else { 2443 resource = readResource(resourceNameOrID, filter); 2444 } 2445 return m_securityManager.readDefaultFile(m_context, resource, filter); 2446 } 2447 2448 /** 2449 * Reads all deleted (historical) resources below the given path, 2450 * including the full tree below the path, if required.<p> 2451 * 2452 * The result list may include resources with the same name of 2453 * resources (with different id's).<p> 2454 * 2455 * Use in conjunction with the {@link #restoreDeletedResource(CmsUUID)} 2456 * method.<p> 2457 * 2458 * @param resourcename the parent path to read the resources from 2459 * @param readTree <code>true</code> to read all sub resources 2460 * 2461 * @return a list of <code>{@link I_CmsHistoryResource}</code> objects 2462 * 2463 * @throws CmsException if something goes wrong 2464 * 2465 * @see #readResource(CmsUUID, int) 2466 * @see #readResources(String, CmsResourceFilter, boolean) 2467 */ 2468 public List<I_CmsHistoryResource> readDeletedResources(String resourcename, boolean readTree) throws CmsException { 2469 2470 CmsResource resource = readResource(resourcename, CmsResourceFilter.ALL); 2471 return m_securityManager.readDeletedResources(m_context, resource, readTree); 2472 } 2473 2474 /** 2475 * Reads a file resource (including it's binary content) from the VFS, 2476 * for the given resource (this may also be an historical version of the resource).<p> 2477 * 2478 * In case the input {@link CmsResource} object already is a {@link CmsFile} with contents 2479 * available, it is casted to a file and returned unchanged. Otherwise the file is read 2480 * from the VFS.<p> 2481 * 2482 * In case you do not need the file content, 2483 * use <code>{@link #readResource(String)}</code> or 2484 * <code>{@link #readResource(String, CmsResourceFilter)}</code> instead.<p> 2485 * 2486 * No resource filter is applied when reading the resource, since we already have 2487 * a full resource instance and assume we just want the content for that instance. 2488 * In case you need to apply a filter, use {@link #readFile(String, CmsResourceFilter)} instead.<p> 2489 * 2490 * @param resource the resource to read 2491 * 2492 * @return the file resource that was read 2493 * 2494 * @throws CmsException if the file resource could not be read for any reason 2495 * 2496 * @see #readFile(String) 2497 * @see #readFile(String, CmsResourceFilter) 2498 */ 2499 public CmsFile readFile(CmsResource resource) throws CmsException { 2500 2501 // test if we already have a file 2502 if (resource instanceof CmsFile) { 2503 // resource is already a file 2504 CmsFile file = (CmsFile)resource; 2505 if ((file.getContents() != null) && (file.getContents().length > 0)) { 2506 // file has the contents already available 2507 return file; 2508 } 2509 } 2510 2511 return m_securityManager.readFile(m_context, resource); 2512 } 2513 2514 /** 2515 * Reads a file resource (including it's binary content) from the VFS, 2516 * using the <code>{@link CmsResourceFilter#DEFAULT}</code> filter.<p> 2517 * 2518 * In case you do not need the file content, 2519 * use <code>{@link #readResource(String)}</code> instead.<p> 2520 * 2521 * @param resourcename the name of the resource to read (full current site relative path) 2522 * 2523 * @return the file resource that was read 2524 * 2525 * @throws CmsException if the file resource could not be read for any reason 2526 * 2527 * @see #readFile(String, CmsResourceFilter) 2528 * @see #readFile(CmsResource) 2529 * @see #readResource(String) 2530 */ 2531 public CmsFile readFile(String resourcename) throws CmsException { 2532 2533 return readFile(resourcename, CmsResourceFilter.DEFAULT); 2534 } 2535 2536 /** 2537 * Reads a file resource (including it's binary content) from the VFS, 2538 * using the specified resource filter.<p> 2539 * 2540 * In case you do not need the file content, 2541 * use <code>{@link #readResource(String, CmsResourceFilter)}</code> instead.<p> 2542 * 2543 * The specified filter controls what kind of resources should be "found" 2544 * during the read operation. This will depend on the application. For example, 2545 * using <code>{@link CmsResourceFilter#DEFAULT}</code> will only return currently 2546 * "valid" resources, while using <code>{@link CmsResourceFilter#IGNORE_EXPIRATION}</code> 2547 * will ignore the date release / date expired information of the resource.<p> 2548 * 2549 * @param resourcename the name of the resource to read (full current site relative path) 2550 * @param filter the resource filter to use while reading 2551 * 2552 * @return the file resource that was read 2553 * 2554 * @throws CmsException if the file resource could not be read for any reason 2555 * 2556 * @see #readFile(String) 2557 * @see #readFile(CmsResource) 2558 * @see #readResource(String, CmsResourceFilter) 2559 */ 2560 public CmsFile readFile(String resourcename, CmsResourceFilter filter) throws CmsException { 2561 2562 CmsResource resource = readResource(resourcename, filter); 2563 return readFile(resource); 2564 } 2565 2566 /** 2567 * Reads a folder resource from the VFS, 2568 * using the <code>{@link CmsResourceFilter#DEFAULT}</code> filter.<p> 2569 * 2570 * @param resourcename the name of the folder resource to read (full current site relative path) 2571 * 2572 * @return the folder resource that was read 2573 * 2574 * @throws CmsException if the resource could not be read for any reason 2575 * 2576 * @see #readResource(String, CmsResourceFilter) 2577 * @see #readFolder(String, CmsResourceFilter) 2578 */ 2579 public CmsFolder readFolder(String resourcename) throws CmsException { 2580 2581 return readFolder(resourcename, CmsResourceFilter.DEFAULT); 2582 } 2583 2584 /** 2585 * Reads a folder resource from the VFS, 2586 * using the specified resource filter.<p> 2587 * 2588 * The specified filter controls what kind of resources should be "found" 2589 * during the read operation. This will depend on the application. For example, 2590 * using <code>{@link CmsResourceFilter#DEFAULT}</code> will only return currently 2591 * "valid" resources, while using <code>{@link CmsResourceFilter#IGNORE_EXPIRATION}</code> 2592 * will ignore the date release / date expired information of the resource.<p> 2593 * 2594 * @param resourcename the name of the folder resource to read (full current site relative path) 2595 * @param filter the resource filter to use while reading 2596 * 2597 * @return the folder resource that was read 2598 * 2599 * @throws CmsException if the resource could not be read for any reason 2600 * 2601 * @see #readResource(String, CmsResourceFilter) 2602 */ 2603 public CmsFolder readFolder(String resourcename, CmsResourceFilter filter) throws CmsException { 2604 2605 return m_securityManager.readFolder(m_context, addSiteRoot(resourcename), filter); 2606 } 2607 2608 /** 2609 * Reads the group of a project.<p> 2610 * 2611 * @param project the project to read the group from 2612 * 2613 * @return the group of the given project 2614 */ 2615 public CmsGroup readGroup(CmsProject project) { 2616 2617 return m_securityManager.readGroup(m_context, project); 2618 } 2619 2620 /** 2621 * Reads a group based on its id.<p> 2622 * 2623 * @param groupId the id of the group to be read 2624 * 2625 * @return the group that has the provided id 2626 * 2627 * @throws CmsException if something goes wrong 2628 * 2629 * @see #readHistoryPrincipal(CmsUUID) for retrieving deleted groups 2630 */ 2631 public CmsGroup readGroup(CmsUUID groupId) throws CmsException { 2632 2633 return m_securityManager.readGroup(m_context, groupId); 2634 } 2635 2636 /** 2637 * Reads a group based on its name.<p> 2638 * 2639 * @param groupName the name of the group to be read 2640 * 2641 * @return the group that has the provided name 2642 * 2643 * @throws CmsException if something goes wrong 2644 */ 2645 public CmsGroup readGroup(String groupName) throws CmsException { 2646 2647 return m_securityManager.readGroup(m_context, groupName); 2648 } 2649 2650 /** 2651 * Reads a principal (an user or group) from the historical archive based on its ID.<p> 2652 * 2653 * @param principalId the id of the principal to read 2654 * 2655 * @return the historical principal entry with the given id 2656 * 2657 * @throws CmsException if something goes wrong, ie. {@link org.opencms.db.CmsDbEntryNotFoundException} 2658 * 2659 * @see #readUser(CmsUUID) 2660 * @see #readGroup(CmsUUID) 2661 */ 2662 public CmsHistoryPrincipal readHistoryPrincipal(CmsUUID principalId) throws CmsException { 2663 2664 return m_securityManager.readHistoricalPrincipal(m_context, principalId); 2665 } 2666 2667 /** 2668 * Returns the latest historical project entry with the given id.<p> 2669 * 2670 * @param projectId the project id 2671 * 2672 * @return the requested historical project entry 2673 * 2674 * @throws CmsException if operation was not successful 2675 */ 2676 public CmsHistoryProject readHistoryProject(CmsUUID projectId) throws CmsException { 2677 2678 return (m_securityManager.readHistoryProject(m_context, projectId)); 2679 } 2680 2681 /** 2682 * Returns a historical project entry.<p> 2683 * 2684 * @param publishTag publish tag of the project 2685 * 2686 * @return the requested historical project entry 2687 * 2688 * @throws CmsException if operation was not successful 2689 */ 2690 public CmsHistoryProject readHistoryProject(int publishTag) throws CmsException { 2691 2692 return (m_securityManager.readHistoryProject(m_context, publishTag)); 2693 } 2694 2695 /** 2696 * Reads the list of all <code>{@link CmsProperty}</code> objects that belong to the given historical resource version.<p> 2697 * 2698 * @param resource the historical resource version to read the properties for 2699 * 2700 * @return the list of <code>{@link CmsProperty}</code> objects 2701 * 2702 * @throws CmsException if something goes wrong 2703 */ 2704 public List<CmsProperty> readHistoryPropertyObjects(I_CmsHistoryResource resource) throws CmsException { 2705 2706 return m_securityManager.readHistoryPropertyObjects(m_context, resource); 2707 } 2708 2709 /** 2710 * This method retrieves the structure id which is mapped to a given URL name.<p> 2711 * 2712 * If there is no structure id mapped to the given name, null will be returned.<p> 2713 * 2714 * However if the parameter is a string which represents a valid uuid, it will be directly returned as a {@link CmsUUID} instance.<p> 2715 * 2716 * @param name the url name 2717 * @return the id which is mapped to the URL name 2718 * 2719 * @throws CmsException if something goes wrong 2720 */ 2721 public CmsUUID readIdForUrlName(String name) throws CmsException { 2722 2723 if (CmsUUID.isValidUUID(name)) { 2724 return new CmsUUID(name); 2725 } 2726 return m_securityManager.readIdForUrlName(m_context, name); 2727 } 2728 2729 /** 2730 * Returns the project manager group of a project.<p> 2731 * 2732 * @param project the project 2733 * 2734 * @return the manager group of the project 2735 */ 2736 public CmsGroup readManagerGroup(CmsProject project) { 2737 2738 return m_securityManager.readManagerGroup(m_context, project); 2739 } 2740 2741 /** 2742 * Reads the owner of a project.<p> 2743 * 2744 * @param project the project to read the owner from 2745 * 2746 * @return the owner of the project 2747 * 2748 * @throws CmsException if something goes wrong 2749 */ 2750 public CmsUser readOwner(CmsProject project) throws CmsException { 2751 2752 return m_securityManager.readOwner(m_context, project); 2753 } 2754 2755 /** 2756 * Returns the parent folder to the given structure id.<p> 2757 * 2758 * @param structureId the child structure id 2759 * 2760 * @return the parent folder <code>{@link CmsResource}</code> 2761 * 2762 * @throws CmsException if something goes wrong 2763 */ 2764 public CmsResource readParentFolder(CmsUUID structureId) throws CmsException { 2765 2766 return m_securityManager.readParentFolder(m_context, structureId); 2767 } 2768 2769 /** 2770 * Builds a list of resources for a given path.<p> 2771 * 2772 * @param resource the resource to read the path for 2773 * @param filter a filter object (only "includeDeleted" information is used!) 2774 * 2775 * @return list of <code>{@link CmsResource}</code>s 2776 * 2777 * @throws CmsException if something goes wrong 2778 */ 2779 public List<CmsResource> readPath(CmsResource resource, CmsResourceFilter filter) throws CmsException { 2780 2781 return m_securityManager.readPath(m_context, resource.getRootPath(), filter); 2782 } 2783 2784 /** 2785 * Builds a list of resources for a given path.<p> 2786 * 2787 * @param path the requested path 2788 * @param filter a filter object (only "includeDeleted" information is used!) 2789 * 2790 * @return list of <code>{@link CmsResource}</code>s 2791 * 2792 * @throws CmsException if something goes wrong 2793 */ 2794 public List<CmsResource> readPath(String path, CmsResourceFilter filter) throws CmsException { 2795 2796 return m_securityManager.readPath(m_context, addSiteRoot(path), filter); 2797 } 2798 2799 /** 2800 * Reads the project with the given id.<p> 2801 * 2802 * @param id the id of the project 2803 * 2804 * @return the project with the given id 2805 * 2806 * @throws CmsException if operation was not successful 2807 */ 2808 public CmsProject readProject(CmsUUID id) throws CmsException { 2809 2810 return m_securityManager.readProject(id); 2811 } 2812 2813 /** 2814 * Reads the project with the given name.<p> 2815 * 2816 * @param name the name of the project 2817 * 2818 * @return the project with the given name 2819 * 2820 * @throws CmsException if operation was not successful 2821 */ 2822 public CmsProject readProject(String name) throws CmsException { 2823 2824 return m_securityManager.readProject(name); 2825 } 2826 2827 /** 2828 * Returns the list of all resource names that define the "view" of the given project.<p> 2829 * 2830 * @param project the project to get the project resources for 2831 * 2832 * @return the list of all resource names (root paths), as <code>{@link String}</code> 2833 * objects that define the "view" of the given project 2834 * 2835 * @throws CmsException if something goes wrong 2836 */ 2837 public List<String> readProjectResources(CmsProject project) throws CmsException { 2838 2839 return m_securityManager.readProjectResources(m_context, project); 2840 } 2841 2842 /** 2843 * Reads all resources of a project that match a given state from the VFS.<p> 2844 * 2845 * Possible values for the <code>state</code> parameter are:<br> 2846 * <ul> 2847 * <li><code>{@link CmsResource#STATE_CHANGED}</code>: Read all "changed" resources in the project</li> 2848 * <li><code>{@link CmsResource#STATE_NEW}</code>: Read all "new" resources in the project</li> 2849 * <li><code>{@link CmsResource#STATE_DELETED}</code>: Read all "deleted" resources in the project</li> 2850 * <li><code>{@link CmsResource#STATE_KEEP}</code>: Read all resources either "changed", "new" or "deleted" in the project</li> 2851 * </ul><p> 2852 * 2853 * @param projectId the id of the project to read the file resources for 2854 * @param state the resource state to match 2855 * 2856 * @return all <code>{@link CmsResource}</code>s of a project that match a given criteria from the VFS 2857 * 2858 * @throws CmsException if something goes wrong 2859 */ 2860 public List<CmsResource> readProjectView(CmsUUID projectId, CmsResourceState state) throws CmsException { 2861 2862 return m_securityManager.readProjectView(m_context, projectId, state); 2863 } 2864 2865 /** 2866 * Reads a property definition.<p> 2867 * 2868 * If no property definition with the given name is found, 2869 * <code>null</code> is returned.<p> 2870 * 2871 * @param name the name of the property definition to read 2872 * 2873 * @return the property definition that was read 2874 * 2875 * @throws CmsException a CmsDbEntryNotFoundException is thrown if the property definition does not exist 2876 */ 2877 public CmsPropertyDefinition readPropertyDefinition(String name) throws CmsException { 2878 2879 return (m_securityManager.readPropertyDefinition(m_context, name)); 2880 } 2881 2882 /** 2883 * Reads a property object from a resource specified by a property name.<p> 2884 * 2885 * Returns <code>{@link CmsProperty#getNullProperty()}</code> if the property is not found.<p> 2886 * 2887 * This method is more efficient then using <code>{@link CmsObject#readPropertyObject(String, String, boolean)}</code> 2888 * if you already have an instance of the resource to look up the property from.<p> 2889 * 2890 * @param resource the resource where the property is attached to 2891 * @param property the property name 2892 * @param search if true, the property is searched on all parent folders of the resource, 2893 * if it's not found attached directly to the resource 2894 * 2895 * @return the required property, or <code>{@link CmsProperty#getNullProperty()}</code> if the property was not found 2896 * 2897 * @throws CmsException if something goes wrong 2898 */ 2899 public CmsProperty readPropertyObject(CmsResource resource, String property, boolean search) throws CmsException { 2900 2901 return m_securityManager.readPropertyObject(m_context, resource, property, search); 2902 } 2903 2904 /** 2905 * Reads the locale specific version of a property object from a resource specified by a property name.<p> 2906 * 2907 * Returns <code>{@link CmsProperty#getNullProperty()}</code> if the property is not found.<p> 2908 * 2909 * This method is more efficient then using <code>{@link CmsObject#readPropertyObject(String, String, boolean)}</code> 2910 * if you already have an instance of the resource to look up the property from.<p> 2911 * 2912 * @param resource the resource where the property is attached to 2913 * @param property the property name 2914 * @param search if true, the property is searched on all parent folders of the resource, 2915 * if it's not found attached directly to the resource 2916 * @param locale the locale for which the property should be read. 2917 * 2918 * @return the required property, or <code>{@link CmsProperty#getNullProperty()}</code> if the property was not found 2919 * 2920 * @throws CmsException if something goes wrong 2921 */ 2922 public CmsProperty readPropertyObject(CmsResource resource, String property, boolean search, Locale locale) 2923 throws CmsException { 2924 2925 return m_securityManager.readPropertyObject(m_context, resource, property, search, locale); 2926 } 2927 2928 /** 2929 * Reads a property object from a resource specified by a property name.<p> 2930 * 2931 * Returns <code>{@link CmsProperty#getNullProperty()}</code> if the property is not found.<p> 2932 * 2933 * @param resourcePath the name of resource where the property is attached to 2934 * @param property the property name 2935 * @param search if true, the property is searched on all parent folders of the resource, 2936 * if it's not found attached directly to the resource 2937 * 2938 * @return the required property, or <code>{@link CmsProperty#getNullProperty()}</code> if the property was not found 2939 * 2940 * @throws CmsException if something goes wrong 2941 */ 2942 public CmsProperty readPropertyObject(String resourcePath, String property, boolean search) throws CmsException { 2943 2944 CmsResource resource = readResource(resourcePath, CmsResourceFilter.ALL); 2945 return m_securityManager.readPropertyObject(m_context, resource, property, search); 2946 } 2947 2948 /** 2949 * Reads the locale specific version of a property object from a resource specified by a property name.<p> 2950 * 2951 * Returns <code>{@link CmsProperty#getNullProperty()}</code> if the property is not found.<p> 2952 * 2953 * @param resourcePath the name of resource where the property is attached to 2954 * @param property the property name 2955 * @param search if true, the property is searched on all parent folders of the resource, 2956 * if it's not found attached directly to the resource 2957 * @param locale the locale for which the property should be read. 2958 * 2959 * @return the required property, or <code>{@link CmsProperty#getNullProperty()}</code> if the property was not found 2960 * 2961 * @throws CmsException if something goes wrong 2962 */ 2963 public CmsProperty readPropertyObject(String resourcePath, String property, boolean search, Locale locale) 2964 throws CmsException { 2965 2966 CmsResource resource = readResource(resourcePath, CmsResourceFilter.ALL); 2967 return m_securityManager.readPropertyObject(m_context, resource, property, search, locale); 2968 } 2969 2970 /** 2971 * Reads all property objects from a resource.<p> 2972 * 2973 * Returns an empty list if no properties are found.<p> 2974 * 2975 * This method is more efficient then using <code>{@link CmsObject#readPropertyObjects(String, boolean)}</code> 2976 * if you already have an instance of the resource to look up the property from.<p> 2977 * 2978 * If the <code>search</code> parameter is <code>true</code>, the properties of all 2979 * parent folders of the resource are also read. The results are merged with the 2980 * properties directly attached to the resource. While merging, a property 2981 * on a parent folder that has already been found will be ignored. 2982 * So e.g. if a resource has a property "Title" attached, and it's parent folder 2983 * has the same property attached but with a different value, the result list will 2984 * contain only the property with the value from the resource, not form the parent folder(s).<p> 2985 * 2986 * @param resource the resource where the property is mapped to 2987 * @param search if <code>true</code>, the properties of all parent folders of the resource 2988 * are merged with the resource properties. 2989 * 2990 * @return a list of <code>{@link CmsProperty}</code> objects 2991 * 2992 * @throws CmsException if something goes wrong 2993 */ 2994 public List<CmsProperty> readPropertyObjects(CmsResource resource, boolean search) throws CmsException { 2995 2996 return m_securityManager.readPropertyObjects(m_context, resource, search); 2997 } 2998 2999 /** 3000 * Reads all property objects from a resource.<p> 3001 * 3002 * Returns an empty list if no properties are found.<p> 3003 * 3004 * All properties in the result List will be in frozen (read only) state, so you can't change the values.<p> 3005 * 3006 * If the <code>search</code> parameter is <code>true</code>, the properties of all 3007 * parent folders of the resource are also read. The results are merged with the 3008 * properties directly attached to the resource. While merging, a property 3009 * on a parent folder that has already been found will be ignored. 3010 * So e.g. if a resource has a property "Title" attached, and it's parent folder 3011 * has the same property attached but with a different value, the result list will 3012 * contain only the property with the value from the resource, not form the parent folder(s).<p> 3013 * 3014 * @param resourcePath the name of resource where the property is mapped to 3015 * @param search if <code>true</code>, the properties of all parent folders of the resource 3016 * are merged with the resource properties. 3017 * 3018 * @return a list of <code>{@link CmsProperty}</code> objects 3019 * 3020 * @throws CmsException if something goes wrong 3021 */ 3022 public List<CmsProperty> readPropertyObjects(String resourcePath, boolean search) throws CmsException { 3023 3024 CmsResource resource = readResource(resourcePath, CmsResourceFilter.ALL); 3025 return m_securityManager.readPropertyObjects(m_context, resource, search); 3026 } 3027 3028 /** 3029 * Reads the resources that were published in a publish task for a given publish history ID.<p> 3030 * 3031 * @param publishHistoryId unique ID to identify each publish task in the publish history 3032 * 3033 * @return a list of <code>{@link org.opencms.db.CmsPublishedResource}</code> objects 3034 * 3035 * @throws CmsException if something goes wrong 3036 */ 3037 public List<CmsPublishedResource> readPublishedResources(CmsUUID publishHistoryId) throws CmsException { 3038 3039 return m_securityManager.readPublishedResources(m_context, publishHistoryId); 3040 } 3041 3042 /** 3043 * Returns all relations matching the given filter.<p> 3044 * 3045 * @param filter the filter to match the relation 3046 * 3047 * @return all relations matching the given filter 3048 * 3049 * @throws CmsException if something goes wrong 3050 * 3051 * @see CmsSecurityManager#getRelationsForResource(CmsRequestContext, CmsResource, CmsRelationFilter) 3052 * @see #getRelationsForResource(CmsResource, CmsRelationFilter) 3053 */ 3054 public List<CmsRelation> readRelations(CmsRelationFilter filter) throws CmsException { 3055 3056 return m_securityManager.getRelationsForResource(m_context, null, filter); 3057 } 3058 3059 /** 3060 * Reads a resource from the VFS, 3061 * using the <code>{@link CmsResourceFilter#DEFAULT}</code> filter.<p> 3062 * 3063 * A resource may be of type <code>{@link CmsFile}</code> or 3064 * <code>{@link CmsFolder}</code>. In case of 3065 * a file, the resource will not contain the binary file content. Since reading 3066 * the binary content is a cost-expensive database operation, it's recommended 3067 * to work with resources if possible, and only read the file content when absolutely 3068 * required. To "upgrade" a resource to a file, 3069 * use <code>{@link #readFile(CmsResource)}</code>.<p> 3070 * 3071 * @param structureID the structure ID of the resource to read 3072 * 3073 * @return the resource that was read 3074 * 3075 * @throws CmsException if the resource could not be read for any reason 3076 * 3077 * @see #readFile(String) 3078 * @see #readResource(CmsUUID, CmsResourceFilter) 3079 */ 3080 public CmsResource readResource(CmsUUID structureID) throws CmsException { 3081 3082 return readResource(structureID, CmsResourceFilter.DEFAULT); 3083 } 3084 3085 /** 3086 * Reads a resource from the VFS, 3087 * using the specified resource filter.<p> 3088 * 3089 * A resource may be of type <code>{@link CmsFile}</code> or 3090 * <code>{@link CmsFolder}</code>. In case of 3091 * a file, the resource will not contain the binary file content. Since reading 3092 * the binary content is a cost-expensive database operation, it's recommended 3093 * to work with resources if possible, and only read the file content when absolutely 3094 * required. To "upgrade" a resource to a file, 3095 * use <code>{@link #readFile(CmsResource)}</code>.<p> 3096 * 3097 * The specified filter controls what kind of resources should be "found" 3098 * during the read operation. This will depend on the application. For example, 3099 * using <code>{@link CmsResourceFilter#DEFAULT}</code> will only return currently 3100 * "valid" resources, while using <code>{@link CmsResourceFilter#IGNORE_EXPIRATION}</code> 3101 * will ignore the date release / date expired information of the resource.<p> 3102 * 3103 * @param structureID the structure ID of the resource to read 3104 * @param filter the resource filter to use while reading 3105 * 3106 * @return the resource that was read 3107 * 3108 * @throws CmsException if the resource could not be read for any reason 3109 * 3110 * @see #readFile(String, CmsResourceFilter) 3111 * @see #readFolder(String, CmsResourceFilter) 3112 */ 3113 public CmsResource readResource(CmsUUID structureID, CmsResourceFilter filter) throws CmsException { 3114 3115 return m_securityManager.readResource(m_context, structureID, filter); 3116 } 3117 3118 /** 3119 * Reads the historical resource with the given version for the resource given 3120 * the given structure id.<p> 3121 * 3122 * A resource may be of type <code>{@link CmsFile}</code> or 3123 * <code>{@link CmsFolder}</code>. In case of a file, the resource will not 3124 * contain the binary file content. Since reading the binary content is a 3125 * cost-expensive database operation, it's recommended to work with resources 3126 * if possible, and only read the file content when absolutely required. To 3127 * "upgrade" a resource to a file, use 3128 * <code>{@link #readFile(CmsResource)}</code>.<p> 3129 * 3130 * Please note that historical versions are just generated during publishing, 3131 * so the first version with version number 1 is generated during publishing 3132 * of a new resource (exception is a new sibling, that may also contain some 3133 * relevant versions of already published siblings) and the last version 3134 * available is the version of the current online resource.<p> 3135 * 3136 * @param structureID the structure ID of the resource to read 3137 * @param version the version number you want to retrieve 3138 * 3139 * @return the resource that was read 3140 * 3141 * @throws CmsException if the resource could not be read for any reason 3142 * @throws CmsVfsResourceNotFoundException if the version does not exists 3143 * 3144 * @see #restoreResourceVersion(CmsUUID, int) 3145 */ 3146 public I_CmsHistoryResource readResource(CmsUUID structureID, int version) 3147 throws CmsException, CmsVfsResourceNotFoundException { 3148 3149 CmsResource resource = readResource(structureID, CmsResourceFilter.ALL); 3150 return m_securityManager.readResource(m_context, resource, version); 3151 } 3152 3153 /** 3154 * Reads a resource from the VFS, 3155 * using the <code>{@link CmsResourceFilter#DEFAULT}</code> filter.<p> 3156 * 3157 * A resource may be of type <code>{@link CmsFile}</code> or 3158 * <code>{@link CmsFolder}</code>. In case of 3159 * a file, the resource will not contain the binary file content. Since reading 3160 * the binary content is a cost-expensive database operation, it's recommended 3161 * to work with resources if possible, and only read the file content when absolutely 3162 * required. To "upgrade" a resource to a file, 3163 * use <code>{@link #readFile(CmsResource)}</code>.<p> 3164 * 3165 * @param resourcename the name of the resource to read (full current site relative path) 3166 * 3167 * @return the resource that was read 3168 * 3169 * @throws CmsException if the resource could not be read for any reason 3170 * 3171 * @see #readFile(String) 3172 * @see #readResource(String, CmsResourceFilter) 3173 */ 3174 public CmsResource readResource(String resourcename) throws CmsException { 3175 3176 return readResource(resourcename, CmsResourceFilter.DEFAULT); 3177 } 3178 3179 /** 3180 * Reads a resource from the VFS, 3181 * using the specified resource filter.<p> 3182 * 3183 * A resource may be of type <code>{@link CmsFile}</code> or 3184 * <code>{@link CmsFolder}</code>. In case of 3185 * a file, the resource will not contain the binary file content. Since reading 3186 * the binary content is a cost-expensive database operation, it's recommended 3187 * to work with resources if possible, and only read the file content when absolutely 3188 * required. To "upgrade" a resource to a file, 3189 * use <code>{@link #readFile(CmsResource)}</code>.<p> 3190 * 3191 * The specified filter controls what kind of resources should be "found" 3192 * during the read operation. This will depend on the application. For example, 3193 * using <code>{@link CmsResourceFilter#DEFAULT}</code> will only return currently 3194 * "valid" resources, while using <code>{@link CmsResourceFilter#IGNORE_EXPIRATION}</code> 3195 * will ignore the date release / date expired information of the resource.<p> 3196 * 3197 * @param resourcename the name of the resource to read (full current site relative path) 3198 * @param filter the resource filter to use while reading 3199 * 3200 * @return the resource that was read 3201 * 3202 * @throws CmsException if the resource could not be read for any reason 3203 * 3204 * @see #readFile(String, CmsResourceFilter) 3205 * @see #readFolder(String, CmsResourceFilter) 3206 */ 3207 public CmsResource readResource(String resourcename, CmsResourceFilter filter) throws CmsException { 3208 3209 return m_securityManager.readResource(m_context, addSiteRoot(resourcename), filter); 3210 } 3211 3212 /** 3213 * Reads all resources below the given resource matching the filter criteria, 3214 * including the full tree below the path only in case the <code>readTree</code> 3215 * parameter is <code>true</code>.<p> 3216 * 3217 * @param resource the parent resource 3218 * @param filter the filter 3219 * @param readTree <code>true</code> to read all sub resources 3220 * 3221 * @return a list of <code>{@link CmsResource}</code> objects matching the filter criteria 3222 * 3223 * @throws CmsException if something goes wrong 3224 */ 3225 public List<CmsResource> readResources(CmsResource resource, CmsResourceFilter filter, boolean readTree) 3226 throws CmsException { 3227 3228 if (readTree) { 3229 return m_securityManager.readResources(m_context, resource, filter, readTree); 3230 } else { 3231 return m_securityManager.readChildResources(m_context, resource, filter, true, true); 3232 } 3233 } 3234 3235 /** 3236 * Reads all resources below the given path matching the filter criteria, 3237 * including the full tree below the path.<p> 3238 * 3239 * @param resourcename the parent path to read the resources from 3240 * @param filter the filter 3241 * 3242 * @return a list of <code>{@link CmsResource}</code> objects matching the filter criteria 3243 * 3244 * @throws CmsException if something goes wrong 3245 * 3246 * @see #readResources(String, CmsResourceFilter, boolean) 3247 */ 3248 public List<CmsResource> readResources(String resourcename, CmsResourceFilter filter) throws CmsException { 3249 3250 return readResources(resourcename, filter, true); 3251 } 3252 3253 /** 3254 * Reads all resources below the given path matching the filter criteria, 3255 * including the full tree below the path only in case the <code>readTree</code> 3256 * parameter is <code>true</code>.<p> 3257 * 3258 * @param resourcename the parent path to read the resources from 3259 * @param filter the filter 3260 * @param readTree <code>true</code> to read all sub resources 3261 * 3262 * @return a list of <code>{@link CmsResource}</code> objects matching the filter criteria 3263 * 3264 * @throws CmsException if something goes wrong 3265 */ 3266 public List<CmsResource> readResources(String resourcename, CmsResourceFilter filter, boolean readTree) 3267 throws CmsException { 3268 3269 CmsResource resource = readResource(resourcename, CmsResourceFilter.ALL); 3270 return m_securityManager.readResources(m_context, resource, filter, readTree); 3271 } 3272 3273 /** 3274 * Reads all resources that have a value set for the specified property.<p> 3275 * 3276 * Both individual and shared properties of a resource are checked.<p> 3277 * 3278 * Will use the {@link CmsResourceFilter#ALL} resource filter.<p> 3279 * 3280 * @param propertyDefinition the name of the property to check for 3281 * 3282 * @return a list of all <code>{@link CmsResource}</code> objects 3283 * that have a value set for the specified property. 3284 * 3285 * @throws CmsException if something goes wrong 3286 */ 3287 public List<CmsResource> readResourcesWithProperty(String propertyDefinition) throws CmsException { 3288 3289 return readResourcesWithProperty("/", propertyDefinition); 3290 } 3291 3292 /** 3293 * Reads all resources that have a value set for the specified property in the given path.<p> 3294 * 3295 * Both individual and shared properties of a resource are checked.<p> 3296 * 3297 * Will use the {@link CmsResourceFilter#ALL} resource filter.<p> 3298 * 3299 * @param path the folder to get the resources with the property from 3300 * @param propertyDefinition the name of the property to check for 3301 * 3302 * @return all <code>{@link CmsResource}</code> objects 3303 * that have a value set for the specified property in the given path. 3304 * 3305 * @throws CmsException if something goes wrong 3306 */ 3307 public List<CmsResource> readResourcesWithProperty(String path, String propertyDefinition) throws CmsException { 3308 3309 return readResourcesWithProperty(path, propertyDefinition, null); 3310 } 3311 3312 /** 3313 * Reads all resources that have a value (containing the specified value) set 3314 * for the specified property in the given path.<p> 3315 * 3316 * Both individual and shared properties of a resource are checked.<p> 3317 * 3318 * If the <code>value</code> parameter is <code>null</code>, all resources having the 3319 * given property set are returned.<p> 3320 * 3321 * Will use the {@link CmsResourceFilter#ALL} resource filter.<p> 3322 * 3323 * @param path the folder to get the resources with the property from 3324 * @param propertyDefinition the name of the property to check for 3325 * @param value the string to search in the value of the property 3326 * 3327 * @return all <code>{@link CmsResource}</code> objects 3328 * that have a value set for the specified property in the given path. 3329 * 3330 * @throws CmsException if something goes wrong 3331 */ 3332 public List<CmsResource> readResourcesWithProperty(String path, String propertyDefinition, String value) 3333 throws CmsException { 3334 3335 CmsResource resource = readResource(path, CmsResourceFilter.IGNORE_EXPIRATION); 3336 return m_securityManager.readResourcesWithProperty( 3337 m_context, 3338 resource, 3339 propertyDefinition, 3340 value, 3341 CmsResourceFilter.ALL); 3342 } 3343 3344 /** 3345 * Reads all resources that have a value (containing the specified value) set 3346 * for the specified property in the given path.<p> 3347 * 3348 * Both individual and shared properties of a resource are checked.<p> 3349 * 3350 * If the <code>value</code> parameter is <code>null</code>, all resources having the 3351 * given property set are returned.<p> 3352 * 3353 * Will use the given resource filter.<p> 3354 * 3355 * @param path the folder to get the resources with the property from 3356 * @param propertyDefinition the name of the property to check for 3357 * @param value the string to search in the value of the property 3358 * @param filter the resource filter to apply to the result set 3359 * 3360 * @return all <code>{@link CmsResource}</code> objects 3361 * that have a value set for the specified property in the given path. 3362 * 3363 * @throws CmsException if something goes wrong 3364 */ 3365 public List<CmsResource> readResourcesWithProperty( 3366 String path, 3367 String propertyDefinition, 3368 String value, 3369 CmsResourceFilter filter) 3370 throws CmsException { 3371 3372 CmsResource resource = readResource(path, CmsResourceFilter.IGNORE_EXPIRATION); 3373 return m_securityManager.readResourcesWithProperty(m_context, resource, propertyDefinition, value, filter); 3374 } 3375 3376 /** 3377 * Returns a set of principals that are responsible for a specific resource.<p> 3378 * 3379 * @param resource the resource to get the responsible principals from 3380 * 3381 * @return the set of principals that are responsible for a specific resource 3382 * 3383 * @throws CmsException if something goes wrong 3384 */ 3385 public Set<I_CmsPrincipal> readResponsiblePrincipals(CmsResource resource) throws CmsException { 3386 3387 return m_securityManager.readResponsiblePrincipals(m_context, resource); 3388 } 3389 3390 /** 3391 * Returns a set of users that are responsible for a specific resource.<p> 3392 * 3393 * @param resource the resource to get the responsible users from 3394 * 3395 * @return the set of users that are responsible for a specific resource 3396 * 3397 * @throws CmsException if something goes wrong 3398 */ 3399 public Set<CmsUser> readResponsibleUsers(CmsResource resource) throws CmsException { 3400 3401 return m_securityManager.readResponsibleUsers(m_context, resource); 3402 } 3403 3404 /** 3405 * Returns a list of all siblings of the specified resource, 3406 * the specified resource being always part of the result set.<p> 3407 * 3408 * @param resource the resource 3409 * @param filter a resource filter 3410 * 3411 * @return a list of <code>{@link CmsResource}</code>s that 3412 * are siblings to the specified resource, 3413 * including the specified resource itself. 3414 * 3415 * @throws CmsException if something goes wrong 3416 */ 3417 public List<CmsResource> readSiblings(CmsResource resource, CmsResourceFilter filter) throws CmsException { 3418 3419 return m_securityManager.readSiblings(m_context, resource, filter); 3420 } 3421 3422 /** 3423 * Returns a list of all siblings of the specified resource, 3424 * the specified resource being always part of the result set.<p> 3425 * 3426 * @param resourcename the name of the specified resource 3427 * @param filter a resource filter 3428 * 3429 * @return a list of <code>{@link CmsResource}</code>s that 3430 * are siblings to the specified resource, 3431 * including the specified resource itself. 3432 * 3433 * @throws CmsException if something goes wrong 3434 */ 3435 public List<CmsResource> readSiblings(String resourcename, CmsResourceFilter filter) throws CmsException { 3436 3437 CmsResource resource = readResource(resourcename, filter); 3438 return readSiblings(resource, filter); 3439 } 3440 3441 /** 3442 * Reads all resources with the given resource id.<p> 3443 * 3444 * @param resourceId the resource id for which we want the siblings 3445 * @param filter the resource filter used to read the resources 3446 * @return the siblings which share the given resource id 3447 * 3448 * @throws CmsException if something goes wrong 3449 */ 3450 public List<CmsResource> readSiblingsForResourceId(CmsUUID resourceId, CmsResourceFilter filter) 3451 throws CmsException { 3452 3453 CmsResource pseudoResource = new CmsResource( 3454 null, 3455 resourceId, 3456 null, 3457 0, 3458 false, 3459 0, 3460 null, 3461 null, 3462 0, 3463 null, 3464 0, 3465 null, 3466 0, 3467 0, 3468 0, 3469 0, 3470 0, 3471 0); 3472 return readSiblings(pseudoResource, filter); 3473 } 3474 3475 /** 3476 * Returns the parameters of a resource in the list of all published template resources.<p> 3477 * 3478 * @param rfsName the rfs name of the resource 3479 * 3480 * @return the parameter string of the requested resource 3481 * 3482 * @throws CmsException if something goes wrong 3483 */ 3484 public String readStaticExportPublishedResourceParameters(String rfsName) throws CmsException { 3485 3486 return m_securityManager.readStaticExportPublishedResourceParameters(m_context, rfsName); 3487 } 3488 3489 /** 3490 * Returns a list of all template resources which must be processed during a static export.<p> 3491 * 3492 * @param parameterResources flag for reading resources with parameters (1) or without (0) 3493 * 3494 * @param timestamp a time stamp for reading the data from the db 3495 * 3496 * @return a list of template resources as <code>{@link String}</code> objects 3497 * 3498 * @throws CmsException if something goes wrong 3499 */ 3500 public List<String> readStaticExportResources(int parameterResources, long timestamp) throws CmsException { 3501 3502 return m_securityManager.readStaticExportResources(m_context, parameterResources, timestamp); 3503 } 3504 3505 /** 3506 * Reads the URL name mappings matching a given filter.<p> 3507 * 3508 * @param filter the filter to match 3509 * @return the URL name mappings matching the filter 3510 * 3511 * @throws CmsException if something goes wrong 3512 */ 3513 public List<CmsUrlNameMappingEntry> readUrlNameMappings(CmsUrlNameMappingFilter filter) throws CmsException { 3514 3515 return m_securityManager.readUrlNameMappings(m_context, filter); 3516 } 3517 3518 /** 3519 * Reads the URL names for all locales.<p> 3520 * 3521 * @param structureId the id of resource for which the URL names should be read 3522 * @return returns the URL names for the resource 3523 * 3524 * @throws CmsException if something goes wrong 3525 */ 3526 public List<String> readUrlNamesForAllLocales(CmsUUID structureId) throws CmsException { 3527 3528 List<String> detailNames = m_securityManager.readUrlNamesForAllLocales(m_context, structureId); 3529 if (detailNames.isEmpty()) { 3530 List<String> result = new ArrayList<String>(); 3531 result.add(structureId.toString()); 3532 return result; 3533 } 3534 return detailNames; 3535 } 3536 3537 /** 3538 * Reads a user based on its id.<p> 3539 * 3540 * @param userId the id of the user to be read 3541 * 3542 * @return the user with the given id 3543 * 3544 * @throws CmsException if something goes wrong 3545 * 3546 * @see #readHistoryPrincipal(CmsUUID) for retrieving data of deleted users 3547 */ 3548 public CmsUser readUser(CmsUUID userId) throws CmsException { 3549 3550 return m_securityManager.readUser(m_context, userId); 3551 } 3552 3553 /** 3554 * Reads a user based on its name.<p> 3555 * 3556 * @param username the name of the user to be read 3557 * 3558 * @return the user with the given name 3559 * 3560 * @throws CmsException if something goes wrong 3561 */ 3562 public CmsUser readUser(String username) throws CmsException { 3563 3564 return m_securityManager.readUser(m_context, username); 3565 } 3566 3567 /** 3568 * Returns a user, if the password is correct.<p> 3569 * 3570 * If the user/pwd pair is not valid a <code>{@link CmsException}</code> is thrown.<p> 3571 * 3572 * @param username the name of the user to be returned 3573 * @param password the password of the user to be returned 3574 * 3575 * @return the validated user 3576 * 3577 * @throws CmsException if operation was not successful 3578 */ 3579 public CmsUser readUser(String username, String password) throws CmsException { 3580 3581 return m_securityManager.readUser(m_context, username, password); 3582 } 3583 3584 /** 3585 * Removes a resource from the current project of the user.<p> 3586 * 3587 * This is used to reduce the current users project with the 3588 * specified resource, in case that the resource is already part of the project. 3589 * The resource is not really removed like in a regular copy operation, 3590 * it is in fact only "disabled" in the current users project.<p> 3591 * 3592 * @param resourcename the name of the resource to remove to the current project (full current site relative path) 3593 * 3594 * @throws CmsException if something goes wrong 3595 */ 3596 public void removeResourceFromProject(String resourcename) throws CmsException { 3597 3598 // TODO: this should be also possible if the resource has been deleted 3599 CmsResource resource = readResource(resourcename, CmsResourceFilter.ALL); 3600 getResourceType(resource).removeResourceFromProject(this, m_securityManager, resource); 3601 } 3602 3603 /** 3604 * Removes a user from a group.<p> 3605 * 3606 * @param username the name of the user that is to be removed from the group 3607 * @param groupname the name of the group 3608 * 3609 * @throws CmsException if operation was not successful 3610 */ 3611 public void removeUserFromGroup(String username, String groupname) throws CmsException { 3612 3613 m_securityManager.removeUserFromGroup(m_context, username, groupname, false); 3614 } 3615 3616 /** 3617 * Renames a resource to the given destination name, 3618 * this is identical to a <code>move</code> operation.<p> 3619 * 3620 * @param source the name of the resource to rename (full current site relative path) 3621 * @param destination the new resource name (full path) 3622 * 3623 * @throws CmsException if something goes wrong 3624 * 3625 * @see #moveResource(String, String) 3626 */ 3627 public void renameResource(String source, String destination) throws CmsException { 3628 3629 moveResource(source, destination); 3630 } 3631 3632 /** 3633 * Replaces the content, type and properties of a resource.<p> 3634 * 3635 * @param resourcename the name of the resource to replace (full current site relative path) 3636 * @param type the new type of the resource 3637 * @param content the new content of the resource 3638 * @param properties the new properties of the resource 3639 * 3640 * @throws CmsException if something goes wrong 3641 */ 3642 public void replaceResource( 3643 String resourcename, 3644 I_CmsResourceType type, 3645 byte[] content, 3646 List<CmsProperty> properties) 3647 throws CmsException { 3648 3649 CmsResource resource = readResource(resourcename, CmsResourceFilter.IGNORE_EXPIRATION); 3650 getResourceType(resource).replaceResource(this, m_securityManager, resource, type, content, properties); 3651 } 3652 3653 /** 3654 * Replaces the content, type and properties of a resource.<p> 3655 * 3656 * @param resourcename the name of the resource to replace (full current site relative path) 3657 * @param type the new type of the resource 3658 * @param content the new content of the resource 3659 * @param properties the new properties of the resource 3660 * 3661 * @throws CmsException if something goes wrong 3662 * 3663 * @deprecated 3664 * Use {@link #replaceResource(String, I_CmsResourceType, byte[], List)} instead. 3665 * Resource types should always be referenced either by its type class (preferred) or by type name. 3666 * Use of int based resource type references will be discontinued in a future OpenCms release. 3667 */ 3668 @Deprecated 3669 public void replaceResource(String resourcename, int type, byte[] content, List<CmsProperty> properties) 3670 throws CmsException { 3671 3672 replaceResource(resourcename, getResourceType(type), content, properties); 3673 } 3674 3675 /** 3676 * Restores a deleted resource identified by its structure id from the historical archive.<p> 3677 * 3678 * These ids can be obtained from the {@link #readDeletedResources(String, boolean)} method.<p> 3679 * 3680 * @param structureId the structure id of the resource to restore 3681 * 3682 * @throws CmsException if something goes wrong 3683 */ 3684 public void restoreDeletedResource(CmsUUID structureId) throws CmsException { 3685 3686 m_securityManager.restoreDeletedResource(m_context, structureId); 3687 } 3688 3689 /** 3690 * Restores a resource in the current project with a version from the historical archive.<p> 3691 * 3692 * @param structureId the structure id of the resource to restore from the archive 3693 * @param version the desired version of the resource to be restored 3694 * 3695 * @throws CmsException if something goes wrong 3696 * 3697 * @see #readResource(CmsUUID, int) 3698 */ 3699 public void restoreResourceVersion(CmsUUID structureId, int version) throws CmsException { 3700 3701 CmsResource resource = readResource(structureId, CmsResourceFilter.IGNORE_EXPIRATION); 3702 getResourceType(resource).restoreResource(this, m_securityManager, resource, version); 3703 } 3704 3705 /** 3706 * Removes an access control entry of a given principal from a given resource.<p> 3707 * 3708 * @param resourceName name of the resource 3709 * @param principalType the type of the principal (currently group or user) 3710 * @param principalName the name of the principal 3711 * 3712 * @throws CmsException if something goes wrong 3713 */ 3714 public void rmacc(String resourceName, String principalType, String principalName) throws CmsException { 3715 3716 CmsResource res = readResource(resourceName, CmsResourceFilter.ALL); 3717 3718 if (CmsUUID.isValidUUID(principalName)) { 3719 // principal name is in fact a UUID, probably the user was already deleted 3720 m_securityManager.removeAccessControlEntry(m_context, res, new CmsUUID(principalName)); 3721 } else if (CmsAccessControlEntry.PRINCIPAL_ALL_OTHERS_NAME.equals(principalName)) { 3722 m_securityManager.removeAccessControlEntry(m_context, res, CmsAccessControlEntry.PRINCIPAL_ALL_OTHERS_ID); 3723 } else if (CmsAccessControlEntry.PRINCIPAL_OVERWRITE_ALL_NAME.equals(principalName)) { 3724 m_securityManager.removeAccessControlEntry( 3725 m_context, 3726 res, 3727 CmsAccessControlEntry.PRINCIPAL_OVERWRITE_ALL_ID); 3728 } else { 3729 try { 3730 // principal name not a UUID, assume this is a normal group or user name 3731 I_CmsPrincipal principal = CmsPrincipal.readPrincipal(this, principalType, principalName); 3732 m_securityManager.removeAccessControlEntry(m_context, res, principal.getId()); 3733 } catch (CmsDbEntryNotFoundException e) { 3734 // role case 3735 CmsRole role = CmsRole.valueOfRoleName(principalName); 3736 if (role == null) { 3737 throw e; 3738 } 3739 m_securityManager.removeAccessControlEntry(m_context, res, role.getId()); 3740 } 3741 } 3742 } 3743 3744 /** 3745 * Changes the "expire" date of a resource.<p> 3746 * 3747 * @param resource the resource to change 3748 * @param dateExpired the new expire date of the changed resource 3749 * @param recursive if this operation is to be applied recursively to all resources in a folder 3750 * 3751 * @throws CmsException if something goes wrong 3752 */ 3753 public void setDateExpired(CmsResource resource, long dateExpired, boolean recursive) throws CmsException { 3754 3755 getResourceType(resource).setDateExpired(this, m_securityManager, resource, dateExpired, recursive); 3756 } 3757 3758 /** 3759 * Changes the "expire" date of a resource.<p> 3760 * 3761 * @param resourcename the name of the resource to change (full current site relative path) 3762 * @param dateExpired the new expire date of the changed resource 3763 * @param recursive if this operation is to be applied recursively to all resources in a folder 3764 * 3765 * @throws CmsException if something goes wrong 3766 */ 3767 public void setDateExpired(String resourcename, long dateExpired, boolean recursive) throws CmsException { 3768 3769 CmsResource resource = readResource(resourcename, CmsResourceFilter.IGNORE_EXPIRATION); 3770 setDateExpired(resource, dateExpired, recursive); 3771 } 3772 3773 /** 3774 * Changes the "last modified" time stamp of a resource.<p> 3775 * 3776 * @param resourcename the name of the resource to change (full current site relative path) 3777 * @param dateLastModified time stamp the new time stamp of the changed resource 3778 * @param recursive if this operation is to be applied recursively to all resources in a folder 3779 * 3780 * @throws CmsException if something goes wrong 3781 */ 3782 public void setDateLastModified(String resourcename, long dateLastModified, boolean recursive) throws CmsException { 3783 3784 CmsResource resource = readResource(resourcename, CmsResourceFilter.IGNORE_EXPIRATION); 3785 getResourceType(resource).setDateLastModified(this, m_securityManager, resource, dateLastModified, recursive); 3786 } 3787 3788 /** 3789 * Changes the "release" date of a resource.<p> 3790 * 3791 * @param resource the resource to change 3792 * @param dateReleased the new release date of the changed resource 3793 * @param recursive if this operation is to be applied recursively to all resources in a folder 3794 * 3795 * @throws CmsException if something goes wrong 3796 */ 3797 public void setDateReleased(CmsResource resource, long dateReleased, boolean recursive) throws CmsException { 3798 3799 getResourceType(resource).setDateReleased(this, m_securityManager, resource, dateReleased, recursive); 3800 } 3801 3802 /** 3803 * Changes the "release" date of a resource.<p> 3804 * 3805 * @param resourcename the name of the resource to change (full current site relative path) 3806 * @param dateReleased the new release date of the changed resource 3807 * @param recursive if this operation is to be applied recursively to all resources in a folder 3808 * 3809 * @throws CmsException if something goes wrong 3810 */ 3811 public void setDateReleased(String resourcename, long dateReleased, boolean recursive) throws CmsException { 3812 3813 CmsResource resource = readResource(resourcename, CmsResourceFilter.IGNORE_EXPIRATION); 3814 setDateReleased(resource, dateReleased, recursive); 3815 } 3816 3817 /** 3818 * Sets a new parent-group for an already existing group.<p> 3819 * 3820 * @param groupName the name of the group that should be updated 3821 * @param parentGroupName the name of the parent group to set, 3822 * or <code>null</code> if the parent 3823 * group should be deleted. 3824 * 3825 * @throws CmsException if operation was not successful 3826 */ 3827 public void setParentGroup(String groupName, String parentGroupName) throws CmsException { 3828 3829 m_securityManager.setParentGroup(m_context, groupName, parentGroupName); 3830 } 3831 3832 /** 3833 * Sets the password for a user.<p> 3834 * 3835 * @param username the name of the user 3836 * @param newPassword the new password 3837 * 3838 * @throws CmsException if operation was not successful 3839 */ 3840 public void setPassword(String username, String newPassword) throws CmsException { 3841 3842 m_securityManager.setPassword(m_context, username, newPassword); 3843 } 3844 3845 /** 3846 * Sets the password for a specified user.<p> 3847 * 3848 * @param username the name of the user 3849 * @param oldPassword the old password 3850 * @param newPassword the new password 3851 * 3852 * @throws CmsException if the user data could not be read from the database 3853 */ 3854 public void setPassword(String username, String oldPassword, String newPassword) throws CmsException { 3855 3856 m_securityManager.resetPassword(m_context, username, oldPassword, newPassword); 3857 } 3858 3859 /** 3860 * Undeletes a resource.<p> 3861 * 3862 * Only resources that have already been published once can be undeleted, 3863 * if a "new" resource is deleted it can not be undeleted.<p> 3864 * 3865 * @param resourcename the name of the resource to undelete 3866 * @param recursive if this operation is to be applied recursively to all resources in a folder 3867 * 3868 * @throws CmsException if something goes wrong 3869 * 3870 * @see CmsObject#undoChanges(String, CmsResource.CmsResourceUndoMode) 3871 */ 3872 public void undeleteResource(String resourcename, boolean recursive) throws CmsException { 3873 3874 CmsResource resource = readResource(resourcename, CmsResourceFilter.ALL); 3875 getResourceType(resource).undelete(this, m_securityManager, resource, recursive); 3876 } 3877 3878 /** 3879 * Undoes all changes to a resource by restoring the version from the 3880 * online project to the current offline project.<p> 3881 * 3882 * @param resourcename the name of the resource to undo the changes for 3883 * @param mode the undo mode, one of the <code>{@link CmsResource.CmsResourceUndoMode}#UNDO_XXX</code> constants 3884 * 3885 * @throws CmsException if something goes wrong 3886 * 3887 * @see CmsResource#UNDO_CONTENT 3888 * @see CmsResource#UNDO_CONTENT_RECURSIVE 3889 * @see CmsResource#UNDO_MOVE_CONTENT 3890 * @see CmsResource#UNDO_MOVE_CONTENT_RECURSIVE 3891 */ 3892 public void undoChanges(String resourcename, CmsResource.CmsResourceUndoMode mode) throws CmsException { 3893 3894 CmsResource resource = readResource(resourcename, CmsResourceFilter.ALL); 3895 getResourceType(resource).undoChanges(this, m_securityManager, resource, mode); 3896 } 3897 3898 /** 3899 * Unlocks all resources of a project. 3900 * 3901 * @param id the id of the project to be unlocked 3902 * 3903 * @throws CmsException if operation was not successful 3904 */ 3905 public void unlockProject(CmsUUID id) throws CmsException { 3906 3907 m_securityManager.unlockProject(m_context, id); 3908 } 3909 3910 /** 3911 * Unlocks a resource.<p> 3912 * 3913 * @param resource the resource to unlock 3914 * 3915 * @throws CmsException if something goes wrong 3916 */ 3917 public void unlockResource(CmsResource resource) throws CmsException { 3918 3919 getResourceType(resource).unlockResource(this, m_securityManager, resource); 3920 } 3921 3922 /** 3923 * Unlocks a resource.<p> 3924 * 3925 * @param resourcename the name of the resource to unlock (full current site relative path) 3926 * 3927 * @throws CmsException if something goes wrong 3928 */ 3929 public void unlockResource(String resourcename) throws CmsException { 3930 3931 CmsResource resource = readResource(resourcename, CmsResourceFilter.ALL); 3932 getResourceType(resource).unlockResource(this, m_securityManager, resource); 3933 } 3934 3935 /** 3936 * Updates the last login date on the given user to the current time.<p> 3937 * 3938 * @param user the user to be updated 3939 * 3940 * @throws CmsRoleViolationException if the current user does not own the rule {@link CmsRole#ACCOUNT_MANAGER} for the current project 3941 * @throws CmsException if operation was not successful 3942 */ 3943 public void updateLastLoginDate(CmsUser user) throws CmsRoleViolationException, CmsException { 3944 3945 m_securityManager.updateLastLoginDate(m_context, user); 3946 } 3947 3948 /** 3949 * Tests if a user is member of the given group.<p> 3950 * 3951 * @param username the name of the user to test 3952 * @param groupname the name of the group to test 3953 * 3954 * @return <code>true</code>, if the user is in the group; or <code>false</code> otherwise 3955 * 3956 * @throws CmsException if operation was not successful 3957 */ 3958 public boolean userInGroup(String username, String groupname) throws CmsException { 3959 3960 return (m_securityManager.userInGroup(m_context, username, groupname)); 3961 } 3962 3963 /** 3964 * This method checks if a new password follows the rules for 3965 * new passwords, which are defined by a Class implementing the 3966 * <code>{@link org.opencms.security.I_CmsPasswordHandler}</code> 3967 * interface and configured in the opencms.properties file.<p> 3968 * 3969 * If this method throws no exception the password is valid.<p> 3970 * 3971 * @param password the new password that has to be checked 3972 * 3973 * @throws CmsSecurityException if the password is not valid 3974 */ 3975 public void validatePassword(String password) throws CmsSecurityException { 3976 3977 m_securityManager.validatePassword(password); 3978 } 3979 3980 /** 3981 * Writes a resource to the OpenCms VFS, including it's content.<p> 3982 * 3983 * Applies only to resources of type <code>{@link CmsFile}</code> 3984 * i.e. resources that have a binary content attached.<p> 3985 * 3986 * Certain resource types might apply content validation or transformation rules 3987 * before the resource is actually written to the VFS. The returned result 3988 * might therefore be a modified version from the provided original.<p> 3989 * 3990 * @param resource the resource to write 3991 * 3992 * @return the written resource (may have been modified) 3993 * 3994 * @throws CmsException if something goes wrong 3995 */ 3996 public CmsFile writeFile(CmsFile resource) throws CmsException { 3997 3998 return getResourceType(resource).writeFile(this, m_securityManager, resource); 3999 } 4000 4001 /** 4002 * Writes an already existing group.<p> 4003 * 4004 * The group has to be a valid OpenCms group.<br> 4005 * 4006 * The group will be completely overridden by the given data.<p> 4007 * 4008 * @param group the group that should be written 4009 * 4010 * @throws CmsException if operation was not successful 4011 */ 4012 public void writeGroup(CmsGroup group) throws CmsException { 4013 4014 m_securityManager.writeGroup(m_context, group); 4015 } 4016 4017 /** 4018 * Creates a historical entry of the current project.<p> 4019 * 4020 * @param publishTag the correlative publish tag 4021 * @param publishDate the date of publishing 4022 4023 * @throws CmsException if operation was not successful 4024 */ 4025 public void writeHistoryProject(int publishTag, long publishDate) throws CmsException { 4026 4027 m_securityManager.writeHistoryProject(m_context, publishTag, publishDate); 4028 } 4029 4030 /** 4031 * Writes an already existing project.<p> 4032 * 4033 * The project id has to be a valid OpenCms project id.<br> 4034 * 4035 * The project with the given id will be completely overridden 4036 * by the given data.<p> 4037 * 4038 * @param project the project that should be written 4039 * 4040 * @throws CmsException if operation was not successful 4041 */ 4042 public void writeProject(CmsProject project) throws CmsException { 4043 4044 m_securityManager.writeProject(m_context, project); 4045 } 4046 4047 /** 4048 * Writes the 'projectlastmodified' field of a resource record.<p> 4049 * 4050 * @param resource the resource which should be modified 4051 * @param project the project whose id should be written into the resource record 4052 * 4053 * @throws CmsException if something goes wrong 4054 */ 4055 public void writeProjectLastModified(CmsResource resource, CmsProject project) throws CmsException { 4056 4057 m_securityManager.writeResourceProjectLastModified(getRequestContext(), resource, project); 4058 } 4059 4060 /** 4061 * Writes a property for a specified resource.<p> 4062 * 4063 * @param resourcename the name of resource with complete path 4064 * @param property the property to write 4065 * 4066 * @throws CmsException if something goes wrong 4067 */ 4068 public void writePropertyObject(String resourcename, CmsProperty property) throws CmsException { 4069 4070 CmsResource resource = readResource(resourcename, CmsResourceFilter.IGNORE_EXPIRATION); 4071 getResourceType(resource).writePropertyObject(this, m_securityManager, resource, property); 4072 } 4073 4074 /** 4075 * Writes a list of properties for a specified resource.<p> 4076 * 4077 * Code calling this method has to ensure that the no properties 4078 * <code>a, b</code> are contained in the specified list so that <code>a.equals(b)</code>, 4079 * otherwise an exception is thrown.<p> 4080 * 4081 * @param res the resource 4082 * @param properties the list of properties to write 4083 * 4084 * @throws CmsException if something goes wrong 4085 */ 4086 public void writePropertyObjects(CmsResource res, List<CmsProperty> properties) throws CmsException { 4087 4088 getResourceType(res).writePropertyObjects(this, m_securityManager, res, properties); 4089 } 4090 4091 /** 4092 * Writes a list of properties for a specified resource.<p> 4093 * 4094 * Code calling this method has to ensure that the no properties 4095 * <code>a, b</code> are contained in the specified list so that <code>a.equals(b)</code>, 4096 * otherwise an exception is thrown.<p> 4097 * 4098 * @param resourcename the name of resource with complete path 4099 * @param properties the list of properties to write 4100 * 4101 * @throws CmsException if something goes wrong 4102 */ 4103 public void writePropertyObjects(String resourcename, List<CmsProperty> properties) throws CmsException { 4104 4105 CmsResource resource = readResource(resourcename, CmsResourceFilter.IGNORE_EXPIRATION); 4106 getResourceType(resource).writePropertyObjects(this, m_securityManager, resource, properties); 4107 } 4108 4109 /** 4110 * Writes a resource.<p> 4111 * 4112 * @param resource the file to write 4113 * 4114 * @throws CmsException if resource type is set to folder, or 4115 * if the user has not the rights to write the file header. 4116 */ 4117 public void writeResource(CmsResource resource) throws CmsException { 4118 4119 m_securityManager.writeResource(m_context, resource); 4120 } 4121 4122 /** 4123 * Writes a published resource entry.<p> 4124 * 4125 * This is done during static export.<p> 4126 * 4127 * @param resourceName The name of the resource to be added to the static export 4128 * @param linkType the type of resource exported (0= non-parameter, 1=parameter) 4129 * @param linkParameter the parameters added to the resource 4130 * @param timestamp a time stamp for writing the data into the db 4131 * 4132 * @throws CmsException if something goes wrong 4133 */ 4134 public void writeStaticExportPublishedResource( 4135 String resourceName, 4136 int linkType, 4137 String linkParameter, 4138 long timestamp) 4139 throws CmsException { 4140 4141 m_securityManager.writeStaticExportPublishedResource( 4142 m_context, 4143 resourceName, 4144 linkType, 4145 linkParameter, 4146 timestamp); 4147 } 4148 4149 /** 4150 * Writes a new URL name mapping for a given resource.<p> 4151 * 4152 * The first name from the given name sequence which is not already mapped to another resource will be used 4153 * for the URL name mapping.<p> 4154 * 4155 * @param nameSeq an iterator for generating names for the mapping 4156 * @param structureId the structure id to which the name should be mapped 4157 * @param locale the locale of the mapping 4158 * @param replaceOnPublish if the mapping should replace previous mappings when published 4159 * 4160 * @return the name which was actually mapped to the structure id 4161 * 4162 * @throws CmsException if something goes wrong 4163 */ 4164 public String writeUrlNameMapping( 4165 Iterator<String> nameSeq, 4166 CmsUUID structureId, 4167 String locale, 4168 boolean replaceOnPublish) 4169 throws CmsException { 4170 4171 return m_securityManager.writeUrlNameMapping(m_context, nameSeq, structureId, locale, replaceOnPublish); 4172 } 4173 4174 /** 4175 * Writes a new URL name mapping for a given resource.<p> 4176 * 4177 * This method uses {@link CmsNumberSuffixNameSequence} to generate a sequence of name candidates 4178 * from the given base name.<p> 4179 * 4180 * @param name the base name for the mapping 4181 * @param structureId the structure id to which the name should be mapped 4182 * @param locale the locale of the mapping 4183 * @param replaceOnPublish mappings for which this is set will replace older mappings on publish 4184 * 4185 * @return the URL name that was actually used for the mapping 4186 * 4187 * @throws CmsException if something goes wrong 4188 */ 4189 public String writeUrlNameMapping(String name, CmsUUID structureId, String locale, boolean replaceOnPublish) 4190 throws CmsException { 4191 4192 return writeUrlNameMapping(new CmsNumberSuffixNameSequence(name), structureId, locale, replaceOnPublish); 4193 } 4194 4195 /** 4196 * Updates the user information. <p> 4197 * 4198 * The user id has to be a valid OpenCms user id.<br> 4199 * 4200 * The user with the given id will be completely overriden 4201 * by the given data.<p> 4202 * 4203 * @param user the user to be written 4204 * 4205 * @throws CmsException if operation was not successful 4206 */ 4207 public void writeUser(CmsUser user) throws CmsException { 4208 4209 m_securityManager.writeUser(m_context, user); 4210 } 4211 4212 /** 4213 * Adds a new relation to the given resource.<p> 4214 * 4215 * @param resource the source resource 4216 * @param target the target resource 4217 * @param relationType the type of the relation 4218 * @param importCase if importing relations 4219 * 4220 * @throws CmsException if something goes wrong 4221 */ 4222 private void createRelation(CmsResource resource, CmsResource target, String relationType, boolean importCase) 4223 throws CmsException { 4224 4225 CmsRelationType type = CmsRelationType.valueOf(relationType); 4226 m_securityManager.addRelationToResource(m_context, resource, target, type, importCase); 4227 } 4228 4229 /** 4230 * Adds a new relation to the given resource.<p> 4231 * 4232 * @param resourceName the name of the source resource 4233 * @param targetPath the path of the target resource 4234 * @param relationType the type of the relation 4235 * @param importCase if importing relations 4236 * 4237 * @throws CmsException if something goes wrong 4238 */ 4239 private void createRelation(String resourceName, String targetPath, String relationType, boolean importCase) 4240 throws CmsException { 4241 4242 CmsResource resource = readResource(resourceName, CmsResourceFilter.IGNORE_EXPIRATION); 4243 CmsResource target = readResource(targetPath, CmsResourceFilter.IGNORE_EXPIRATION); 4244 createRelation(resource, target, relationType, importCase); 4245 } 4246 4247 /** 4248 * Notify all event listeners that a particular event has occurred.<p> 4249 * 4250 * The event will be given to all registered <code>{@link I_CmsEventListener}</code>s.<p> 4251 * 4252 * @param type the type of the event 4253 * @param data a data object that contains data used by the event listeners 4254 * 4255 * @see OpenCms#addCmsEventListener(I_CmsEventListener) 4256 * @see OpenCms#addCmsEventListener(I_CmsEventListener, int[]) 4257 */ 4258 private void fireEvent(int type, Object data) { 4259 4260 OpenCms.fireCmsEvent(type, Collections.singletonMap("data", data)); 4261 } 4262 4263 /** 4264 * Convenience method to get the initialized resource type instance for the given resource, 4265 * with a fall back to special "unknown" resource types in case the resource type is not configured.<p> 4266 * 4267 * @param resource the resource to get the type for 4268 * 4269 * @return the initialized resource type instance for the given resource 4270 * 4271 * @see org.opencms.loader.CmsResourceManager#getResourceType(int) 4272 */ 4273 private I_CmsResourceType getResourceType(CmsResource resource) { 4274 4275 return OpenCms.getResourceManager().getResourceType(resource); 4276 } 4277 4278 /** 4279 * Convenience method to return the initialized resource type 4280 * instance for the given id.<p> 4281 * 4282 * @param resourceType the id of the resource type to get 4283 * 4284 * @return the initialized resource type instance for the given id 4285 * 4286 * @throws CmsException if something goes wrong 4287 * 4288 * @see org.opencms.loader.CmsResourceManager#getResourceType(int) 4289 */ 4290 private I_CmsResourceType getResourceType(int resourceType) throws CmsException { 4291 4292 return OpenCms.getResourceManager().getResourceType(resourceType); 4293 } 4294 4295 /** 4296 * Initializes this <code>{@link CmsObject}</code> with the provided user context and database connection.<p> 4297 * 4298 * @param securityManager the security manager 4299 * @param context the request context that contains the user authentication 4300 */ 4301 private void init(CmsSecurityManager securityManager, CmsRequestContext context) { 4302 4303 m_securityManager = securityManager; 4304 m_context = context; 4305 } 4306 4307 /** 4308 * Locks a resource.<p> 4309 * 4310 * The <code>type</code> parameter controls what kind of lock is used.<br> 4311 * Possible values for this parameter are: <br> 4312 * <ul> 4313 * <li><code>{@link org.opencms.lock.CmsLockType#EXCLUSIVE}</code></li> 4314 * <li><code>{@link org.opencms.lock.CmsLockType#TEMPORARY}</code></li> 4315 * </ul><p> 4316 * 4317 * @param resourcename the name of the resource to lock (full current site relative path) 4318 * @param type type of the lock 4319 * 4320 * @throws CmsException if something goes wrong 4321 */ 4322 private void lockResource(String resourcename, CmsLockType type) throws CmsException { 4323 4324 // throw the exception if resource name is an empty string 4325 if (CmsStringUtil.isEmptyOrWhitespaceOnly(resourcename)) { 4326 throw new CmsVfsResourceNotFoundException( 4327 Messages.get().container(Messages.ERR_LOCK_RESOURCE_1, resourcename)); 4328 } 4329 CmsResource resource = readResource(resourcename, CmsResourceFilter.ALL); 4330 getResourceType(resource).lockResource(this, m_securityManager, resource, type); 4331 } 4332 4333}