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, 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.webdav; 029 030import org.opencms.file.CmsResource; 031import org.opencms.file.CmsVfsResourceNotFoundException; 032import org.opencms.main.CmsException; 033import org.opencms.main.CmsLog; 034import org.opencms.repository.CmsPropertyName; 035import org.opencms.repository.I_CmsRepositoryItem; 036import org.opencms.repository.I_CmsRepositorySession; 037import org.opencms.security.CmsPermissionViolationException; 038import org.opencms.util.CmsFileUtil; 039import org.opencms.util.CmsStringUtil; 040 041import java.io.IOException; 042import java.io.InputStream; 043import java.io.OutputStream; 044import java.util.ArrayList; 045import java.util.Arrays; 046import java.util.Date; 047import java.util.HashMap; 048import java.util.List; 049import java.util.Map; 050import java.util.Optional; 051import java.util.TreeSet; 052import java.util.stream.Collectors; 053 054import javax.servlet.http.HttpServletResponse; 055 056import org.apache.commons.logging.Log; 057import org.apache.jackrabbit.webdav.DavCompliance; 058import org.apache.jackrabbit.webdav.DavException; 059import org.apache.jackrabbit.webdav.DavMethods; 060import org.apache.jackrabbit.webdav.DavResource; 061import org.apache.jackrabbit.webdav.DavResourceFactory; 062import org.apache.jackrabbit.webdav.DavResourceIterator; 063import org.apache.jackrabbit.webdav.DavResourceIteratorImpl; 064import org.apache.jackrabbit.webdav.DavResourceLocator; 065import org.apache.jackrabbit.webdav.DavServletResponse; 066import org.apache.jackrabbit.webdav.DavSession; 067import org.apache.jackrabbit.webdav.MultiStatusResponse; 068import org.apache.jackrabbit.webdav.io.InputContext; 069import org.apache.jackrabbit.webdav.io.OutputContext; 070import org.apache.jackrabbit.webdav.lock.ActiveLock; 071import org.apache.jackrabbit.webdav.lock.LockInfo; 072import org.apache.jackrabbit.webdav.lock.LockManager; 073import org.apache.jackrabbit.webdav.lock.Scope; 074import org.apache.jackrabbit.webdav.lock.Type; 075import org.apache.jackrabbit.webdav.property.DavProperty; 076import org.apache.jackrabbit.webdav.property.DavPropertyName; 077import org.apache.jackrabbit.webdav.property.DavPropertySet; 078import org.apache.jackrabbit.webdav.property.DefaultDavProperty; 079import org.apache.jackrabbit.webdav.property.PropEntry; 080import org.apache.jackrabbit.webdav.property.ResourceType; 081import org.apache.jackrabbit.webdav.xml.Namespace; 082 083/** 084 * Represents a resource in the WebDav repository (may not actually correspond to an actual OpenCms resource, since 085 * DavResource are also created for the target locations for move/copy operations, before any of the moving / copying happens. 086 */ 087public class CmsDavResource implements DavResource { 088 089 /** Logger instance for this class. **/ 090 private static final Log LOG = CmsLog.getLog(CmsDavResource.class); 091 092 /** The resource factory that produced this resource. */ 093 private CmsDavResourceFactory m_factory; 094 095 /** The resource locator for this resource. */ 096 private DavResourceLocator m_locator; 097 098 /** The Webdav session object. */ 099 private CmsDavSession m_session; 100 101 /** Lazily initialized repository item - null means not initialized, Optional.empty means tried to load resource, but it was not found. */ 102 private Optional<I_CmsRepositoryItem> m_item; 103 104 /** The lock manager. */ 105 private LockManager m_lockManager; 106 107 /** 108 * Creates a new instance. 109 * 110 * @param loc the locator for this resource 111 * @param factory the factory that produced this resource 112 * @param session the Webdav session 113 * @param lockManager the lock manager 114 */ 115 public CmsDavResource( 116 DavResourceLocator loc, 117 CmsDavResourceFactory factory, 118 CmsDavSession session, 119 LockManager lockManager) { 120 121 m_factory = factory; 122 m_locator = loc; 123 m_session = session; 124 m_lockManager = lockManager; 125 } 126 127 /** 128 * @see org.apache.jackrabbit.webdav.DavResource#addLockManager(org.apache.jackrabbit.webdav.lock.LockManager) 129 */ 130 public void addLockManager(LockManager lockmgr) { 131 132 m_lockManager = lockmgr; 133 } 134 135 /** 136 * @see org.apache.jackrabbit.webdav.DavResource#addMember(org.apache.jackrabbit.webdav.DavResource, org.apache.jackrabbit.webdav.io.InputContext) 137 */ 138 public void addMember(DavResource dres, InputContext inputContext) throws DavException { 139 140 I_CmsRepositorySession session = getRepositorySession(); 141 String childPath = ((CmsDavResource)dres).getCmsPath(); 142 String method = ((CmsDavInputContext)inputContext).getMethod(); 143 InputStream stream = inputContext.getInputStream(); 144 if (method.equals(DavMethods.METHOD_MKCOL) && (stream != null)) { 145 throw new DavException(HttpServletResponse.SC_UNSUPPORTED_MEDIA_TYPE); 146 } 147 if (dres.exists() && isLocked(dres)) { 148 throw new DavException(DavServletResponse.SC_LOCKED); 149 } 150 try { 151 if (stream != null) { 152 session.save(childPath, stream, true); 153 } else { 154 session.create(childPath); 155 } 156 } catch (CmsException e) { 157 LOG.error(e.getLocalizedMessage(), e); 158 throw new DavException(CmsDavUtil.getStatusForException(e), e); 159 } catch (Exception e) { 160 throw new DavException(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); 161 } 162 163 } 164 165 /** 166 * @see org.apache.jackrabbit.webdav.DavResource#alterProperties(java.util.List) 167 */ 168 public MultiStatusResponse alterProperties(List<? extends PropEntry> changeList) throws DavException { 169 170 if (exists() && isLocked(this)) { 171 throw new DavException(DavServletResponse.SC_LOCKED); 172 } 173 174 MultiStatusResponse res = new MultiStatusResponse(getHref(), null); 175 Map<CmsPropertyName, String> propMap = new HashMap<>(); 176 for (PropEntry entry : changeList) { 177 if (entry instanceof DefaultDavProperty<?>) { 178 DefaultDavProperty<String> prop = (DefaultDavProperty<String>)entry; 179 CmsPropertyName cmsPropName = new CmsPropertyName( 180 prop.getName().getNamespace().getURI(), 181 prop.getName().getName()); 182 propMap.put(cmsPropName, prop.getValue()); 183 } else if (entry instanceof DavPropertyName) { 184 CmsPropertyName cmsPropName = new CmsPropertyName( 185 ((DavPropertyName)entry).getNamespace().getURI(), 186 ((DavPropertyName)entry).getName()); 187 propMap.put(cmsPropName, ""); 188 189 } 190 } 191 int status = HttpServletResponse.SC_OK; 192 try { 193 getRepositorySession().updateProperties(getCmsPath(), propMap); 194 } catch (CmsException e) { 195 LOG.warn(e.getLocalizedMessage(), e); 196 if (e instanceof CmsPermissionViolationException) { 197 status = HttpServletResponse.SC_FORBIDDEN; 198 } 199 } 200 for (PropEntry entry : changeList) { 201 if (entry instanceof DavPropertyName) { 202 res.add((DavPropertyName)entry, status); 203 } else if (entry instanceof DefaultDavProperty<?>) { 204 res.add((DavProperty)entry, status); 205 } else { 206 res.add((DavPropertyName)entry, HttpServletResponse.SC_FORBIDDEN); 207 } 208 } 209 return res; 210 } 211 212 /** 213 * @see org.apache.jackrabbit.webdav.DavResource#copy(org.apache.jackrabbit.webdav.DavResource, boolean) 214 */ 215 public void copy(DavResource dres, boolean shallow) throws DavException { 216 217 CmsDavResource other = (CmsDavResource)dres; 218 boolean targetParentExists = false; 219 try { 220 targetParentExists = dres.getCollection().exists(); 221 } catch (Exception e) { 222 LOG.warn(e.getLocalizedMessage(), e); 223 } 224 if (!targetParentExists) { 225 throw new DavException(HttpServletResponse.SC_CONFLICT); 226 } 227 228 try { 229 getRepositorySession().copy(getCmsPath(), other.getCmsPath(), true, shallow); 230 } catch (CmsException e) { 231 LOG.error(e.getLocalizedMessage(), e); 232 throw new DavException(CmsDavUtil.getStatusForException(e)); 233 } 234 } 235 236 /** 237 * Deletes the resource. 238 * 239 * @throws DavException if an error occurs 240 */ 241 public void delete() throws DavException { 242 243 if (!exists()) { 244 throw new DavException(HttpServletResponse.SC_NOT_FOUND); 245 } 246 try { 247 getRepositorySession().delete(getCmsPath()); 248 } catch (CmsException e) { 249 LOG.error(e.getLocalizedMessage(), e); 250 throw new DavException(CmsDavUtil.getStatusForException(e), e); 251 } 252 253 } 254 255 /** 256 * @see org.apache.jackrabbit.webdav.DavResource#exists() 257 */ 258 public boolean exists() { 259 260 return getItem() != null; 261 262 } 263 264 /** 265 * @see org.apache.jackrabbit.webdav.DavResource#getCollection() 266 */ 267 public DavResource getCollection() { 268 269 DavResourceLocator locator = m_locator.getFactory().createResourceLocator( 270 m_locator.getPrefix(), 271 m_locator.getWorkspacePath(), 272 CmsResource.getParentFolder(m_locator.getResourcePath())); 273 try { 274 return m_factory.createResource(locator, m_session); 275 } catch (DavException e) { 276 return null; 277 278 } 279 } 280 281 /** 282 * @see org.apache.jackrabbit.webdav.DavResource#getComplianceClass() 283 */ 284 public String getComplianceClass() { 285 286 return DavCompliance.concatComplianceClasses(new String[] {DavCompliance._1_, DavCompliance._2_}); 287 } 288 289 /** 290 * @see org.apache.jackrabbit.webdav.DavResource#getDisplayName() 291 */ 292 public String getDisplayName() { 293 294 String result = CmsResource.getName(getCmsPath()); 295 result = result.replace("/", ""); 296 return result; 297 } 298 299 /** 300 * @see org.apache.jackrabbit.webdav.DavResource#getFactory() 301 */ 302 public DavResourceFactory getFactory() { 303 304 return m_factory; 305 } 306 307 /** 308 * @see org.apache.jackrabbit.webdav.DavResource#getHref() 309 */ 310 public String getHref() { 311 312 String href = m_locator.getHref(true); 313 String result = CmsFileUtil.removeTrailingSeparator(href); 314 return result; 315 } 316 317 /** 318 * @see org.apache.jackrabbit.webdav.DavResource#getLocator() 319 */ 320 public DavResourceLocator getLocator() { 321 322 return m_locator; 323 } 324 325 /** 326 * @see org.apache.jackrabbit.webdav.DavResource#getLock(org.apache.jackrabbit.webdav.lock.Type, org.apache.jackrabbit.webdav.lock.Scope) 327 */ 328 public ActiveLock getLock(Type type, Scope scope) { 329 330 return m_lockManager.getLock(type, scope, this); 331 } 332 333 /** 334 * @see org.apache.jackrabbit.webdav.DavResource#getLocks() 335 */ 336 public ActiveLock[] getLocks() { 337 338 ActiveLock writeLock = getLock(Type.WRITE, Scope.EXCLUSIVE); 339 return (writeLock != null) ? new ActiveLock[] {writeLock} : new ActiveLock[0]; 340 } 341 342 /** 343 * @see org.apache.jackrabbit.webdav.DavResource#getMembers() 344 */ 345 public DavResourceIterator getMembers() { 346 347 I_CmsRepositorySession session = getRepositorySession(); 348 try { 349 List<I_CmsRepositoryItem> children = session.list(getCmsPath()); 350 List<DavResource> childDavRes = children.stream().map(child -> { 351 String childPath = CmsStringUtil.joinPaths(m_locator.getWorkspacePath(), child.getName()); 352 DavResourceLocator childLocator = m_locator.getFactory().createResourceLocator( 353 m_locator.getPrefix(), 354 m_locator.getWorkspacePath(), 355 childPath); 356 return new CmsDavResource(childLocator, m_factory, m_session, m_lockManager); 357 }).filter(child -> { 358 boolean exists = child.exists(); 359 if (!exists) { 360 // one case where this happens is when the child resource has a name that would be 361 // modified by the configured file translation rules. 362 LOG.warn( 363 "Invalid child resource: " 364 + child.getLocator().getPrefix() 365 + ":" 366 + child.getLocator().getResourcePath()); 367 } 368 return exists; 369 }).collect(Collectors.toList()); 370 return new DavResourceIteratorImpl(childDavRes); 371 } catch (Exception e) { 372 LOG.error(e.getLocalizedMessage(), e); 373 return null; 374 } 375 376 } 377 378 /** 379 * @see org.apache.jackrabbit.webdav.DavResource#getModificationTime() 380 */ 381 public long getModificationTime() { 382 383 I_CmsRepositoryItem item = getItem(); 384 return item.getLastModifiedDate(); 385 } 386 387 /** 388 * @see org.apache.jackrabbit.webdav.DavResource#getProperties() 389 */ 390 public DavPropertySet getProperties() { 391 392 DavPropertySet result = new DavPropertySet(); 393 ResourceType typeProp = new ResourceType( 394 isCollection() ? ResourceType.COLLECTION : ResourceType.DEFAULT_RESOURCE); 395 result.add(typeProp); 396 result.add( 397 new DefaultDavProperty<String>( 398 DavPropertyName.GETLASTMODIFIED, 399 CmsDavUtil.DATE_FORMAT.format(new Date(getItem().getLastModifiedDate())))); 400 result.add(new DefaultDavProperty<String>(DavPropertyName.DISPLAYNAME, "" + getItem().getName())); 401 if (!isCollection()) { 402 result.add( 403 new DefaultDavProperty<String>(DavPropertyName.GETCONTENTLENGTH, "" + getItem().getContentLength())); 404 405 result.add(new DefaultDavProperty<String>(DavPropertyName.GETETAG, getETag())); 406 407 } 408 try { 409 Map<CmsPropertyName, String> cmsProps = getRepositorySession().getProperties(getCmsPath()); 410 for (Map.Entry<CmsPropertyName, String> entry : cmsProps.entrySet()) { 411 CmsPropertyName propName = entry.getKey(); 412 DavPropertyName name = DavPropertyName.create( 413 propName.getName(), 414 Namespace.getNamespace(propName.getNamespace())); 415 result.add(new DefaultDavProperty<String>(name, entry.getValue())); 416 } 417 } catch (Exception e) { 418 LOG.error(e.getLocalizedMessage(), e); 419 } 420 return result; 421 } 422 423 /** 424 * @see org.apache.jackrabbit.webdav.DavResource#getProperty(org.apache.jackrabbit.webdav.property.DavPropertyName) 425 */ 426 public DavProperty<?> getProperty(DavPropertyName name) { 427 428 return getProperties().get(name); 429 } 430 431 /** 432 * @see org.apache.jackrabbit.webdav.DavResource#getPropertyNames() 433 */ 434 public DavPropertyName[] getPropertyNames() { 435 436 return getProperties().getPropertyNames(); 437 } 438 439 /** 440 * @see org.apache.jackrabbit.webdav.DavResource#getResourcePath() 441 */ 442 public String getResourcePath() { 443 444 return m_locator.getResourcePath(); 445 } 446 447 /** 448 * @see org.apache.jackrabbit.webdav.DavResource#getSession() 449 */ 450 public DavSession getSession() { 451 452 return m_session; 453 } 454 455 /** 456 * @see org.apache.jackrabbit.webdav.DavResource#getSupportedMethods() 457 */ 458 public String getSupportedMethods() { 459 460 TreeSet<String> methods = new TreeSet<>(); 461 I_CmsRepositoryItem item = getItem(); 462 if (item == null) { 463 methods.addAll(Arrays.asList(DavMethods.METHOD_OPTIONS, DavMethods.METHOD_PUT, DavMethods.METHOD_MKCOL)); 464 methods.add(DavMethods.METHOD_LOCK); 465 } else { 466 methods.addAll( 467 Arrays.asList( 468 DavMethods.METHOD_OPTIONS, 469 DavMethods.METHOD_HEAD, 470 DavMethods.METHOD_POST, 471 DavMethods.METHOD_DELETE)); 472 methods.add(DavMethods.METHOD_PROPFIND); 473 methods.add(DavMethods.METHOD_PROPPATCH); 474 475 Arrays.asList(DavMethods.METHOD_COPY, DavMethods.METHOD_MOVE); 476 if (!item.isCollection()) { 477 methods.add(DavMethods.METHOD_PUT); 478 } 479 480 } 481 return CmsStringUtil.listAsString(new ArrayList<>(methods), ", "); 482 } 483 484 /** 485 * @see org.apache.jackrabbit.webdav.DavResource#hasLock(org.apache.jackrabbit.webdav.lock.Type, org.apache.jackrabbit.webdav.lock.Scope) 486 */ 487 public boolean hasLock(Type type, Scope scope) { 488 489 return m_lockManager.getLock(type, scope, this) != null; 490 } 491 492 /** 493 * @see org.apache.jackrabbit.webdav.DavResource#isCollection() 494 */ 495 public boolean isCollection() { 496 497 I_CmsRepositoryItem item = getItem(); 498 return (item != null) && item.isCollection(); 499 } 500 501 /** 502 * @see org.apache.jackrabbit.webdav.DavResource#isLockable(org.apache.jackrabbit.webdav.lock.Type, org.apache.jackrabbit.webdav.lock.Scope) 503 */ 504 public boolean isLockable(Type type, Scope scope) { 505 506 // TODO Auto-generated method stub 507 return false; 508 } 509 510 /** 511 * @see org.apache.jackrabbit.webdav.DavResource#lock(org.apache.jackrabbit.webdav.lock.LockInfo) 512 */ 513 public ActiveLock lock(LockInfo reqLockInfo) throws DavException { 514 515 return m_lockManager.createLock(reqLockInfo, this); 516 } 517 518 /** 519 * @see org.apache.jackrabbit.webdav.DavResource#move(org.apache.jackrabbit.webdav.DavResource) 520 */ 521 public void move(DavResource destination) throws DavException { 522 523 CmsDavResource other = (CmsDavResource)destination; 524 if (isLocked(this)) { 525 throw new DavException(DavServletResponse.SC_LOCKED); 526 } 527 528 try { 529 getRepositorySession().move(getCmsPath(), other.getCmsPath(), true); 530 } catch (CmsException e) { 531 LOG.error(e.getLocalizedMessage(), e); 532 throw new DavException(CmsDavUtil.getStatusForException(e)); 533 } 534 535 } 536 537 /** 538 * @see org.apache.jackrabbit.webdav.DavResource#refreshLock(org.apache.jackrabbit.webdav.lock.LockInfo, java.lang.String) 539 */ 540 public ActiveLock refreshLock(LockInfo reqLockInfo, String lockToken) throws DavException { 541 542 return m_lockManager.refreshLock(reqLockInfo, lockToken, this); 543 } 544 545 /** 546 * @see org.apache.jackrabbit.webdav.DavResource#removeMember(org.apache.jackrabbit.webdav.DavResource) 547 */ 548 public void removeMember(DavResource member) throws DavException { 549 550 if (isLocked(this) || isLocked(member)) { 551 throw new DavException(DavServletResponse.SC_LOCKED); 552 } 553 ((CmsDavResource)member).delete(); 554 } 555 556 /** 557 * @see org.apache.jackrabbit.webdav.DavResource#removeProperty(org.apache.jackrabbit.webdav.property.DavPropertyName) 558 */ 559 public void removeProperty(DavPropertyName propertyName) throws DavException { 560 561 if (exists() && isLocked(this)) { 562 throw new DavException(DavServletResponse.SC_LOCKED); 563 } 564 565 I_CmsRepositorySession session = getRepositorySession(); 566 Map<CmsPropertyName, String> props = new HashMap<>(); 567 CmsPropertyName key = new CmsPropertyName(propertyName.getNamespace().getURI(), propertyName.getName()); 568 props.put(key, ""); 569 try { 570 session.updateProperties(getCmsPath(), props); 571 } catch (CmsException e) { 572 LOG.error(e.getLocalizedMessage(), e); 573 throw new DavException(500); 574 } 575 } 576 577 /** 578 * @see org.apache.jackrabbit.webdav.DavResource#setProperty(org.apache.jackrabbit.webdav.property.DavProperty) 579 */ 580 public void setProperty(DavProperty<?> property) throws DavException { 581 582 if (exists() && isLocked(this)) { 583 throw new DavException(DavServletResponse.SC_LOCKED); 584 } 585 586 if (!(property instanceof DefaultDavProperty)) { 587 throw new DavException(HttpServletResponse.SC_FORBIDDEN); 588 } 589 I_CmsRepositorySession session = getRepositorySession(); 590 Map<CmsPropertyName, String> props = new HashMap<>(); 591 DavPropertyName propertyName = property.getName(); 592 String newValue = ((DefaultDavProperty<String>)property).getValue(); 593 if (newValue == null) { 594 newValue = ""; 595 } 596 CmsPropertyName key = new CmsPropertyName(propertyName.getNamespace().getURI(), propertyName.getName()); 597 props.put(key, newValue); 598 try { 599 session.updateProperties(getCmsPath(), props); 600 } catch (CmsException e) { 601 LOG.error(e.getLocalizedMessage(), e); 602 throw new DavException(500); 603 } 604 605 } 606 607 /** 608 * @see org.apache.jackrabbit.webdav.DavResource#spool(org.apache.jackrabbit.webdav.io.OutputContext) 609 */ 610 public void spool(OutputContext outputContext) throws IOException { 611 612 I_CmsRepositoryItem item = getItem(); 613 outputContext.setContentType(item.getMimeType()); 614 outputContext.setContentLength(item.getContentLength()); 615 outputContext.setModificationTime(item.getLastModifiedDate()); 616 outputContext.setETag(getETag()); 617 OutputStream out = outputContext.getOutputStream(); 618 if (out != null) { 619 out.write(item.getContent()); 620 } 621 622 } 623 624 /** 625 * @see org.apache.jackrabbit.webdav.DavResource#unlock(java.lang.String) 626 */ 627 public void unlock(String lockToken) throws DavException { 628 629 m_lockManager.releaseLock(lockToken, this); 630 } 631 632 /** 633 * Gets the OpenCms path corresponding to this resource's locator. 634 * 635 * @return the OpenCms path 636 */ 637 private String getCmsPath() { 638 639 String path = m_locator.getResourcePath(); 640 String workspace = m_locator.getWorkspacePath(); 641 Optional<String> remainingPath = CmsStringUtil.removePrefixPath(workspace, path); 642 return remainingPath.orElse(null); 643 644 } 645 646 /** 647 * Computes the ETag for the item (the item must be not null). 648 * 649 * @return the ETag for the repository item 650 */ 651 private String getETag() { 652 653 return "\"" + getItem().getContentLength() + "-" + getItem().getLastModifiedDate() + "\""; 654 } 655 656 /** 657 * Tries to load the appropriate repository item for this resource. 658 * 659 * @return the repository item, or null if none was found 660 */ 661 private I_CmsRepositoryItem getItem() { 662 663 if (m_item == null) { 664 try { 665 I_CmsRepositoryItem item = getRepositorySession().getItem(getCmsPath()); 666 m_item = Optional.of(item); 667 668 } catch (Exception e) { 669 if (!(e instanceof CmsVfsResourceNotFoundException)) { 670 LOG.error(e.getLocalizedMessage(), e); 671 } else { 672 LOG.info(e.getLocalizedMessage(), e); 673 } 674 m_item = Optional.empty(); 675 676 } 677 } 678 return m_item.orElse(null); 679 680 } 681 682 /** 683 * Gets the OpenCms repository session for which this resource was created. 684 * 685 * @return the OpenCms repository session 686 */ 687 private I_CmsRepositorySession getRepositorySession() { 688 689 return m_session.getRepositorySession(); 690 } 691 692 /** 693 * Return true if this resource cannot be modified due to a write lock 694 * that is not owned by the current session. 695 * 696 * @param res the resource to check 697 * 698 * @return true if this resource cannot be modified due to a write lock 699 */ 700 private boolean isLocked(DavResource res) { 701 702 ActiveLock lock = res.getLock(Type.WRITE, Scope.EXCLUSIVE); 703 if (lock == null) { 704 return false; 705 } else { 706 for (String sLockToken : m_session.getLockTokens()) { 707 if (sLockToken.equals(lock.getToken())) { 708 return false; 709 } 710 } 711 return true; 712 } 713 } 714 715}