1 23 package org.apache.slide.webdav.method; 24 25 import java.io.IOException ; 26 import java.util.Iterator ; 27 28 import org.apache.slide.common.NamespaceAccessToken; 29 import org.apache.slide.common.ServiceAccessException; 30 import org.apache.slide.event.EventDispatcher; 31 import org.apache.slide.webdav.WebdavException; 32 import org.apache.slide.webdav.WebdavServletConfig; 33 import org.apache.slide.webdav.event.WebdavEvent; 34 import org.apache.slide.webdav.util.DeltavConstants; 35 import org.apache.slide.webdav.util.PreconditionViolationException; 36 import org.apache.slide.webdav.util.VersioningHelper; 37 import org.apache.slide.webdav.util.WebdavStatus; 38 import org.apache.slide.webdav.util.WebdavUtils; 39 import org.jdom.Element; 40 import org.jdom.JDOMException; 41 42 46 public class CheckinMethod extends AbstractWebdavMethod implements DeltavConstants, WriteMethod { 47 48 49 private String resourcePath; 50 51 52 private boolean forkOk = false; 53 private boolean keepCheckedOut = false; 54 55 56 58 59 65 public CheckinMethod(NamespaceAccessToken token, 66 WebdavServletConfig config) { 67 super(token, config); 68 } 69 70 75 protected void parseRequest() throws WebdavException { 76 77 resourcePath = requestUri; 78 if (resourcePath == null) { 79 resourcePath = "/"; 80 } 81 82 83 if( req.getContentLength() > 0 ) { 84 try{ 86 Iterator i = parseRequestContent(E_CHECKIN).getChildren().iterator(); 87 while( i.hasNext() ) { 88 Element e = (Element)i.next(); 89 if( e.getName().equals(E_FORK_OK) ) 90 forkOk = true; 91 if( e.getName().equals(E_KEEP_CHECKED_OUT) ) { 92 keepCheckedOut = true; 93 } 94 } 95 } 96 catch (IOException e){ 97 int statusCode = WebdavStatus.SC_INTERNAL_SERVER_ERROR; 98 sendError( statusCode, e ); 99 throw new WebdavException( statusCode ); 100 } 101 catch (JDOMException e){ 102 int statusCode = WebdavStatus.SC_BAD_REQUEST; 103 sendError( statusCode, e ); 104 throw new WebdavException( statusCode ); 105 } 106 } 107 } 108 109 115 protected void executeRequest() throws WebdavException, IOException { 116 String locationValue = null; 117 118 slideToken.setForceStoreEnlistment(true); 120 121 try { 123 if (isLockNull(resourcePath)) { 124 int statusCode = WebdavStatus.SC_NOT_FOUND; 125 sendError( statusCode, "lock-null resource", new Object []{resourcePath} ); 126 throw new WebdavException( statusCode ); 127 } 128 } 129 catch (ServiceAccessException e) { 130 int statusCode = getErrorCode( e ); 131 sendError( statusCode, e ); 132 throw new WebdavException( statusCode ); 133 } 134 135 try { 136 VersioningHelper vh = VersioningHelper.getVersioningHelper( 137 slideToken, token, req, resp, getConfig() ); 138 139 if ( WebdavEvent.CHECKIN.isEnabled() ) EventDispatcher.getInstance().fireVetoableEvent(WebdavEvent.CHECKIN, new WebdavEvent(this)); 140 141 locationValue = vh.checkin( resourcePath , forkOk, keepCheckedOut, false); 142 } 143 catch (PreconditionViolationException e) { 144 sendPreconditionViolation(e); 145 throw e; 146 } 147 catch (Exception e) { 148 int statusCode = getErrorCode( e ); 149 sendError( statusCode, e ); 150 throw new WebdavException( statusCode ); 151 } 152 finally { 153 resp.setHeader(H_CACHE_CONTROL, NO_CACHE); 154 if( locationValue != null && locationValue.length() > 0 ) { 155 locationValue = getFullPath( locationValue ); 156 resp.setHeader( H_LOCATION, WebdavUtils.encodeURL(locationValue, "utf-8") ); 158 } 159 } 160 } 161 } 162 163 164 | Popular Tags |