1 16 package org.apache.cocoon.components.repository.impl; 17 18 import java.io.IOException ; 19 20 import org.apache.avalon.framework.activity.Disposable; 21 import org.apache.avalon.framework.component.Component; 22 import org.apache.avalon.framework.logger.AbstractLogEnabled; 23 import org.apache.avalon.framework.service.ServiceException; 24 import org.apache.avalon.framework.service.ServiceManager; 25 import org.apache.avalon.framework.service.Serviceable; 26 import org.apache.cocoon.components.repository.helpers.CredentialsToken; 27 import org.apache.cocoon.components.repository.helpers.RepositoryTransactionHelper; 28 import org.apache.cocoon.components.webdav.WebDAVUtil; 29 import org.apache.commons.httpclient.HttpException; 30 31 35 public class WebDAVRepositoryTransactionHelper extends AbstractLogEnabled 36 implements RepositoryTransactionHelper, Serviceable, Disposable, Component { 37 38 39 private ServiceManager manager; 40 41 42 private WebDAVRepository repo; 43 44 45 private CredentialsToken credentials; 46 47 50 public void service(ServiceManager manager) throws ServiceException { 51 this.manager = manager; 52 } 53 54 57 public void dispose() { 58 this.manager = null; 59 } 60 61 67 public WebDAVRepositoryTransactionHelper(CredentialsToken credentials, WebDAVRepository repo) { 68 this.credentials = credentials; 69 this.repo = repo; 70 } 71 72 75 public boolean beginTran() { 76 throw new UnsupportedOperationException (); 78 } 79 80 83 public boolean commitTran() { 84 throw new UnsupportedOperationException (); 86 } 87 88 91 public boolean rollbackTran() { 92 throw new UnsupportedOperationException (); 94 } 95 96 99 public boolean lock(String uri) { 100 101 try { 102 return WebDAVUtil.getWebdavResource(this.repo.getAbsoluteURI(uri)).lockMethod(); 103 104 } catch (HttpException he) { 105 this.getLogger().error("HTTP Error locking " + uri, he); 106 } catch (IOException ioe) { 107 this.getLogger().error("IO Error locking " + uri, ioe); 108 } 109 110 return false; 111 } 112 113 116 public boolean lock(String uri, int timeout) { 117 118 try { 119 return WebDAVUtil.getWebdavResource(this.repo.getAbsoluteURI(uri)) 120 .lockMethod(this.credentials.getPrincipal().getName(), timeout); 121 122 } catch (HttpException he) { 123 this.getLogger().error("HTTP Error locking " + uri, he); 124 } catch (IOException ioe) { 125 this.getLogger().error("IO Error locking " + uri, ioe); 126 } 127 128 return false; 129 } 130 131 134 public boolean unlock(String uri) { 135 136 try { 137 return WebDAVUtil.getWebdavResource(this.repo.getAbsoluteURI(uri)).unlockMethod(); 138 139 } catch (HttpException he) { 140 this.getLogger().error("HTTP Error unlocking " + uri, he); 141 } catch (IOException ioe) { 142 this.getLogger().error("IO Error unlocking " + uri, ioe); 143 } 144 145 return false; 146 } 147 148 151 public boolean supportsTransactions() { 152 return false; 154 } 155 156 159 public boolean supportsLocking() { 160 return true; 161 } 162 163 } | Popular Tags |