1 23 24 package org.apache.slide.webdav.util; 25 26 import java.util.Enumeration ; 27 import java.util.HashSet ; 28 29 import javax.servlet.http.HttpServletRequest ; 30 import javax.servlet.http.HttpServletResponse ; 31 32 import org.apache.slide.common.NamespaceAccessToken; 33 import org.apache.slide.common.SlideException; 34 import org.apache.slide.common.SlideToken; 35 import org.apache.slide.content.Content; 36 import org.apache.slide.content.NodeProperty; 37 import org.apache.slide.content.NodeRevisionDescriptor; 38 import org.apache.slide.content.NodeRevisionDescriptors; 39 import org.apache.slide.content.RevisionDescriptorNotFoundException; 40 import org.apache.slide.lock.UnlockListener; 41 import org.apache.slide.structure.ObjectNotFoundException; 42 import org.apache.slide.structure.Structure; 43 import org.apache.slide.util.Configuration; 44 import org.apache.slide.webdav.WebdavServletConfig; 45 import org.apache.slide.webdav.util.resourcekind.AbstractResourceKind; 46 import org.apache.slide.webdav.util.resourcekind.CheckedOutVersionControlled; 47 import org.apache.slide.webdav.util.resourcekind.ResourceKind; 48 49 52 public class UnlockListenerImpl implements UnlockListener { 53 SlideToken slideToken; 54 NamespaceAccessToken token; 55 WebdavServletConfig config; 56 HttpServletRequest req; 57 HttpServletResponse resp; 58 int unlockCount = 0; 60 HashSet removedLockNullResources = new HashSet (); 62 63 66 public UnlockListenerImpl( SlideToken slideToken, NamespaceAccessToken token, WebdavServletConfig config, HttpServletRequest req, HttpServletResponse resp ) { 67 this.slideToken = slideToken; 68 this.token = token; 69 this.config = config; 70 this.req = req; 71 this.resp = resp; 72 } 73 74 80 public void beforeUnlock(String uri) throws SlideException { 81 } 82 83 89 public void afterUnlock(String uri) throws SlideException { 90 unlockCount++; 91 92 Content content = token.getContentHelper(); 94 Structure structure = token.getStructureHelper(); 95 NodeRevisionDescriptors revisionDescriptors = 96 content.retrieve(slideToken, uri); 97 NodeRevisionDescriptor revisionDescriptor = 98 content.retrieve(slideToken, revisionDescriptors); 99 ResourceKind resourceKind = AbstractResourceKind.determineResourceKind(token, uri, revisionDescriptor); 100 if( Configuration.useVersionControl() && 101 (resourceKind instanceof CheckedOutVersionControlled) ) { 102 NodeProperty checkinLocktokenProperty = 103 revisionDescriptor.getProperty(DeltavConstants.I_CHECKIN_LOCKTOKEN, 104 NodeProperty.NamespaceCache.SLIDE_URI); 105 if (checkinLocktokenProperty == null) { 106 checkinLocktokenProperty = 109 revisionDescriptor.getProperty(DeltavConstants.I_CHECKIN_LOCKTOKEN); 110 } 111 if ( (checkinLocktokenProperty != null) && (checkinLocktokenProperty.getValue() != null) 112 ) { 114 VersioningHelper versionHelper = VersioningHelper.getVersioningHelper(slideToken, token, req, resp, config); 115 try { 116 versionHelper.checkin(revisionDescriptors, revisionDescriptor, false, false, true); 117 } 118 catch (java.io.IOException e) {} 119 catch (org.jdom.JDOMException e) {} 120 } 121 } 122 123 try { 126 Enumeration locks = token.getLockHelper().enumerateLocks(slideToken, uri); 127 if (!locks.hasMoreElements() && isLockNull(revisionDescriptor)) { 128 this.removedLockNullResources.add(uri); 129 content.remove(slideToken, uri, revisionDescriptor); 130 content.remove(slideToken, revisionDescriptors); 131 structure.remove(slideToken, structure.retrieve(slideToken, uri)); 132 } 133 } catch (ObjectNotFoundException onfe) { 134 } catch (RevisionDescriptorNotFoundException e) { 135 } 139 } 140 141 144 public int getUnlockCount() { 145 return this.unlockCount; 146 } 147 public boolean isRemovedLockResource(String uri) { 148 return this.removedLockNullResources.contains(uri); 149 } 150 151 private boolean isLockNull( NodeRevisionDescriptor nrd ) { 152 return nrd.propertyValueContains(WebdavConstants.P_RESOURCETYPE, 153 WebdavConstants.E_LOCKNULL); 154 } 155 } 156 157 | Popular Tags |