1 23 24 package org.apache.slide.webdav.method; 25 26 import java.io.IOException ; 27 import java.util.Iterator ; 28 29 import org.apache.slide.common.Domain; 30 import org.apache.slide.common.NamespaceAccessToken; 31 import org.apache.slide.common.ServiceAccessException; 32 import org.apache.slide.event.EventDispatcher; 33 import org.apache.slide.macro.ForbiddenException; 34 import org.apache.slide.webdav.WebdavException; 35 import org.apache.slide.webdav.WebdavServletConfig; 36 import org.apache.slide.webdav.event.WebdavEvent; 37 import org.apache.slide.webdav.util.DeltavConstants; 38 import org.apache.slide.webdav.util.PreconditionViolationException; 39 import org.apache.slide.webdav.util.UriHandler; 40 import org.apache.slide.webdav.util.VersioningHelper; 41 import org.apache.slide.webdav.util.WebdavStatus; 42 import org.jdom.Element; 43 import org.jdom.JDOMException; 44 48 public class VersionControlMethod extends AbstractWebdavMethod 49 implements DeltavConstants, WriteMethod { 50 51 54 private String resourcePath; 55 56 60 private String existingVersionPath; 61 62 63 65 66 72 public VersionControlMethod(NamespaceAccessToken token, 73 WebdavServletConfig config) { 74 super(token, config); 75 } 76 77 82 protected void parseRequest() throws WebdavException { 83 85 resourcePath = requestUri; 86 if (resourcePath == null) { 87 resourcePath = "/"; 88 } 89 90 if( req.getContentLength() > 0 ) { 91 try{ 92 Element ve = null; 93 Iterator i = parseRequestContent(E_VERSION_CONTROL).getChildren().iterator(); 94 while( i.hasNext() ) { 95 Element e = (Element)i.next(); 96 if( e.getName().equals(E_VERSION) ) { 97 ve = e; 99 try { 101 Element hre = (Element)ve.getChildren().get(0); 102 if( hre == null || !hre.getName().equals(E_HREF) ) 103 throw new Exception (); 104 existingVersionPath = getSlidePath( hre.getText() ); 105 } 106 catch( Exception x ) { 107 Domain.warn( E_VERSION+" element must contain "+E_HREF+" element" ); 108 throw new JDOMException("<"+E_VERSION+"> element must contain <"+E_HREF+"> element" ); 109 } 110 break; 111 } 112 } 113 } 114 catch (JDOMException e){ 115 int statusCode = WebdavStatus.SC_BAD_REQUEST; 116 sendError( statusCode, e ); 117 throw new WebdavException( statusCode ); 118 } 119 catch( IOException e ){ 120 int statusCode = WebdavStatus.SC_INTERNAL_SERVER_ERROR; 121 sendError( statusCode, e ); 122 throw new WebdavException( statusCode ); 123 } 124 } 125 } 126 127 132 protected void executeRequest() throws WebdavException, IOException { 133 134 slideToken.setForceStoreEnlistment(true); 136 137 try { 139 if (isLockNull(resourcePath)) { 140 int statusCode = WebdavStatus.SC_NOT_FOUND; 141 sendError( statusCode, "lock-null resource", new Object []{resourcePath} ); 142 throw new WebdavException( statusCode ); 143 } 144 } 145 catch (ServiceAccessException e) { 146 int statusCode = getErrorCode((Exception )e); 147 sendError( statusCode, e ); 148 throw new WebdavException( statusCode ); 149 } 150 151 try { 152 UriHandler rUh = UriHandler.getUriHandler( resourcePath ); 153 if (isExcludedForVersionControl(resourcePath)) { 154 throw new ForbiddenException( 155 resourcePath, 156 new Exception ("The resource path has been excluded from version-control") ); 157 } 158 if ( WebdavEvent.VERSION_CONTROL.isEnabled() ) EventDispatcher.getInstance().fireVetoableEvent(WebdavEvent.VERSION_CONTROL, new WebdavEvent(this)); 159 160 VersioningHelper vh = VersioningHelper.getVersioningHelper( 161 slideToken, token, req, resp, getConfig() ); 162 if( existingVersionPath == null ) 163 vh.versionControl( resourcePath ); 164 else 165 vh.versionControl( resourcePath, existingVersionPath ); 166 } 167 catch (PreconditionViolationException e) { 168 sendPreconditionViolation(e); 169 throw e; 170 } 171 catch (Exception e) { 172 int statusCode = getErrorCode( e ); 173 sendError( statusCode, e ); 174 throw new WebdavException( statusCode ); 175 } 176 } 177 } 178 179 180 181 | Popular Tags |