gcasper 2004/04/02 06:53:35
Added:
src/blocks/webdav/java/org/apache/cocoon/components/repository/impl
WebDAVRepositoryPropertyHelper.java
WebDAVRepository.java
WebDAVRepositoryVersioningHelper.java
WebDAVRepositoryTransactionHelper.java
Log:
repository component for WebDAV
Revision Changes Path
1.1
cocoon-2.1/src/blocks/webdav/java/org/apache/cocoon/components/repository/impl/WebDAVRepositoryPropertyHelper.java
Index: WebDAVRepositoryPropertyHelper.java
===================================================================
/*
* Copyright 1999-2004 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.cocoon.components.repository.impl;
import java.io.IOException;
import java.util.List;
import java.util.Map;
import java.util.Properties;
import java.util.Set;
import javax.xml.transform.OutputKeys;
import org.apache.avalon.framework.activity.Disposable;
import org.apache.avalon.framework.component.Component;
import org.apache.avalon.framework.logger.AbstractLogEnabled;
import org.apache.avalon.framework.service.ServiceException;
import org.apache.avalon.framework.service.ServiceManager;
import org.apache.avalon.framework.service.Serviceable;
import org.apache.cocoon.ProcessingException;
import org.apache.cocoon.components.repository.helpers.CredentialsToken;
import
org.apache.cocoon.components.repository.helpers.RepositoryPropertyHelper;
import org.apache.cocoon.components.source.helpers.SourceProperty;
import org.apache.cocoon.components.webdav.WebDAVUtil;
import org.apache.cocoon.xml.XMLUtils;
import org.apache.commons.httpclient.HttpException;
import org.w3c.dom.Node;
/**
* A property helper class for the WebDAV repository
* intended to be used by flowscripts or corresponding wrapper components.
*/
public class WebDAVRepositoryPropertyHelper extends AbstractLogEnabled
implements RepositoryPropertyHelper, Serviceable, Disposable, Component {
/* The ServiceManager */
private ServiceManager manager;
/* The repository component */
private WebDAVRepository repo;
/* The credentials to be used against the WebDAV repository */
private CredentialsToken credentials;
/* (non-Javadoc)
* @see
org.apache.avalon.framework.service.Serviceable#service(org.apache.avalon.framework.service.ServiceManager)
*/
public void service(ServiceManager manager) throws ServiceException {
this.manager = manager;
}
/* (non-Javadoc)
* @see org.apache.avalon.framework.activity.Disposable#dispose()
*/
public void dispose() {
this.manager = null;
}
/**
* create a WebDAVRepositoryPropertyHelper
*
* @param credentials the user credentials to be used against the WebDAV
repository.
* @param repo a reference to the WebDAVRepository object.
*/
public WebDAVRepositoryPropertyHelper (CredentialsToken credentials,
WebDAVRepository repo) {
this.credentials = credentials;
this.repo = repo;
}
/* (non-Javadoc)
* @see
org.apache.cocoon.components.repository.helpers.RepositoryPropertyHelper#getProperty(java.lang.String,
java.lang.String, java.lang.String)
*/
public SourceProperty getProperty(String uri, String name, String
namespace) {
try {
return WebDAVUtil.getProperty(this.repo.getAbsoluteURI(uri),
name, namespace);
} catch (HttpException he) {
this.getLogger().error("HTTP Error getting property " + namespace
+ ":" + name + " for " + uri, he);
} catch (IOException ioe) {
this.getLogger().error("IO Error getting property " + namespace +
":" + name + " for " + uri, ioe);
}
return null;
}
/* (non-Javadoc)
* @see
org.apache.cocoon.components.repository.helpers.RepositoryPropertyHelper#getProperties(java.lang.String,
java.util.Set)
*/
public Map getProperties(String uri, Set propNames) {
try {
return WebDAVUtil.getProperties(this.repo.getAbsoluteURI(uri),
propNames);
} catch (HttpException he) {
this.getLogger().error("HTTP Error getting properties for " +
uri, he);
} catch (IOException ioe) {
this.getLogger().error("IO Error getting properties for " + uri,
ioe);
}
return null;
}
/* (non-Javadoc)
* @see
org.apache.cocoon.components.repository.helpers.RepositoryPropertyHelper#getAllProperties(java.lang.String)
*/
public List getAllProperties(String uri) {
try {
return WebDAVUtil.getAllProperties(this.repo.getAbsoluteURI(uri));
} catch (HttpException he) {
this.getLogger().error("HTTP Error getting properties for " +
uri, he);
} catch (IOException ioe) {
this.getLogger().error("IO Error getting properties for " + uri,
ioe);
}
return null;
}
/* (non-Javadoc)
* @see
org.apache.cocoon.components.repository.helpers.RepositoryPropertyHelper#setProperty(java.lang.String,
java.lang.String, java.lang.String, java.lang.String)
*/
public boolean setProperty(String uri, String name, String namespace,
String value) {
try {
WebDAVUtil.setProperty(this.repo.getAbsoluteURI(uri), name,
namespace, value);
return true;
} catch (HttpException he) {
this.getLogger().error("HTTP Error setting property " + namespace
+ ":" + name + " for " + uri, he);
} catch (IOException ioe) {
this.getLogger().error("IO Error setting property " + namespace +
":" + name + " for " + uri, ioe);
}
return false;
}
/* (non-Javadoc)
* @see
org.apache.cocoon.components.repository.helpers.RepositoryPropertyHelper#setProperty(java.lang.String,
java.lang.String, java.lang.String, org.w3c.dom.Node)
*/
public boolean setProperty(String uri, String name, String namespace,
Node value) {
try {
Properties format = new Properties();
format.put(OutputKeys.METHOD, "xml");
format.put(OutputKeys.OMIT_XML_DECLARATION, "yes");
return this.setProperty(uri, name, namespace,
XMLUtils.serializeNode(value, format));
} catch (ProcessingException pe) {
this.getLogger().error("Error serializing node " + value, pe);
}
return false;
}
/* (non-Javadoc)
* @see
org.apache.cocoon.components.repository.helpers.RepositoryPropertyHelper#setProperties(java.lang.String,
java.util.Map)
*/
public boolean setProperties(String uri, Map properties) {
try {
WebDAVUtil.setProperties(uri, properties);
return true;
} catch (HttpException he) {
this.getLogger().error("HTTP Error setting properties for " +
uri, he);
} catch (IOException ioe) {
this.getLogger().error("IO Error setting properties for " + uri,
ioe);
}
return false;
}
}
1.1
cocoon-2.1/src/blocks/webdav/java/org/apache/cocoon/components/repository/impl/WebDAVRepository.java
Index: WebDAVRepository.java
===================================================================
/*
* Copyright 1999-2004 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.cocoon.components.repository.impl;
import java.io.BufferedInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.MalformedURLException;
import java.util.Properties;
import javax.xml.transform.OutputKeys;
import org.apache.avalon.excalibur.io.IOUtil;
import org.apache.avalon.framework.activity.Disposable;
import org.apache.avalon.framework.activity.Initializable;
import org.apache.avalon.framework.component.Component;
import org.apache.avalon.framework.configuration.Configurable;
import org.apache.avalon.framework.configuration.Configuration;
import org.apache.avalon.framework.configuration.ConfigurationException;
import org.apache.avalon.framework.logger.AbstractLogEnabled;
import org.apache.avalon.framework.service.ServiceException;
import org.apache.avalon.framework.service.ServiceManager;
import org.apache.avalon.framework.service.Serviceable;
import org.apache.cocoon.ProcessingException;
import org.apache.cocoon.components.LifecycleHelper;
import org.apache.cocoon.components.repository.Repository;
import org.apache.cocoon.components.repository.helpers.CredentialsToken;
import
org.apache.cocoon.components.repository.helpers.RepositoryTransactionHelper;
import
org.apache.cocoon.components.repository.helpers.RepositoryPropertyHelper;
import
org.apache.cocoon.components.repository.helpers.RepositoryVersioningHelper;
import org.apache.cocoon.components.webdav.WebDAVUtil;
import org.apache.cocoon.xml.XMLUtils;
import org.apache.commons.httpclient.HttpException;
import org.apache.excalibur.source.Source;
import org.apache.excalibur.xml.dom.DOMParser;
import org.apache.webdav.lib.WebdavResource;
import org.w3c.dom.Document;
import org.w3c.dom.Node;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
/**
* A repository implementation for WebDAV.
*/
public class WebDAVRepository extends AbstractLogEnabled
implements Repository, Serviceable, Configurable, Initializable, Disposable,
Component {
/** The name of the repository location configuration element */
public static final String REPO_BASE_CONF = "repo-base";
/* The ServiceManager */
private ServiceManager manager;
/* The RepositoryPropertyHelper */
private WebDAVRepositoryPropertyHelper propertyHelper;
/* The RepositoryTransactionHelper */
private WebDAVRepositoryTransactionHelper transactionHelper;
/* The RepositoryVersioningHelper */
private WebDAVRepositoryVersioningHelper versioningHelper;
/* The location of the repository */
private String repoBaseUrl;
/* The credentials to be used against the WebDAV repository */
private CredentialsToken credentials;
/* (non-Javadoc)
* @see
org.apache.avalon.framework.service.Serviceable#service(org.apache.avalon.framework.service.ServiceManager)
*/
public void service(ServiceManager manager) throws ServiceException {
this.manager = manager;
}
/* (non-Javadoc)
* @see
org.apache.avalon.framework.configuration.Configurable#configure(org.apache.avalon.framework.configuration.Configuration)
*/
public void configure(Configuration configuration) throws
ConfigurationException {
this.repoBaseUrl = configuration.getChild(REPO_BASE_CONF).getValue();
if (this.getLogger().isDebugEnabled()) {
this.getLogger().debug("configuring repository location " +
this.repoBaseUrl);
}
}
/* (non-Javadoc)
* @see org.apache.avalon.framework.activity.Initializable#initialize()
*/
public void initialize() throws Exception {
this.propertyHelper = new
WebDAVRepositoryPropertyHelper(this.credentials, this);
this.transactionHelper = new
WebDAVRepositoryTransactionHelper(this.credentials, this);
this.versioningHelper = new
WebDAVRepositoryVersioningHelper(this.credentials, this);
LifecycleHelper lh = new LifecycleHelper(this.getLogger(),
null,
this.manager,
null,
null);
lh.setupComponent(this.propertyHelper, true);
lh.setupComponent(this.transactionHelper, true);
lh.setupComponent(this.versioningHelper, true);
}
/* (non-Javadoc)
* @see org.apache.avalon.framework.activity.Disposable#dispose()
*/
public void dispose() {
this.manager = null;
this.propertyHelper.dispose();
this.transactionHelper.dispose();
this.versioningHelper.dispose();
this.propertyHelper = null;
this.transactionHelper = null;
this.versioningHelper = null;
}
/* (non-Javadoc)
* @see
org.apache.cocoon.components.repository.Repository#getContentString(java.lang.String)
*/
public String getContentString(String uri) throws ProcessingException {
try {
return IOUtil.toString(this.getContentStream(uri));
} catch (IOException ioe) {
throw new ProcessingException ("Error loading resource: " +
this.repoBaseUrl + uri, ioe);
}
}
/* (non-Javadoc)
* @see
org.apache.cocoon.components.repository.Repository#getContentStream(java.lang.String)
*/
public InputStream getContentStream(String uri) throws
ProcessingException {
if (this.getLogger().isDebugEnabled()) {
this.getLogger().debug("getting content of: " + uri);
}
try {
WebdavResource resource =
WebDAVUtil.getWebdavResource(this.getAbsoluteURI(uri));
if (!resource.exists()) {
throw new HttpException(uri + " does not exist");
}
return new BufferedInputStream(resource.getMethodData());
} catch (MalformedURLException mue) {
throw new ProcessingException ("Bad URL for resource: " +
this.repoBaseUrl + uri, mue);
} catch (IOException ioe) {
throw new ProcessingException ("Error loading resource: " +
this.repoBaseUrl + uri, ioe);
}
}
/* (non-Javadoc)
* @see
org.apache.cocoon.components.repository.Repository#getContentDOM(java.lang.String)
*/
public Document getContentDOM(String uri) throws ProcessingException {
DOMParser parser = null;
try {
parser = (DOMParser)this.manager.lookup( DOMParser.ROLE);
return parser.parseDocument(new
InputSource(this.getContentStream(uri)));
} catch (SAXException se) {
throw new ProcessingException ("Error parsing: " +
this.repoBaseUrl + uri, se);
} catch (IOException ioe) {
throw new ProcessingException ("Error getting: " +
this.repoBaseUrl + uri, ioe);
} catch (ServiceException se) {
throw new ProcessingException ("Error getting DOMParser", se);
} finally {
this.manager.release(parser);
}
}
/* (non-Javadoc)
* @see
org.apache.cocoon.components.repository.Repository#saveContent(java.lang.String,
java.lang.String)
*/
public boolean saveContent(String uri, String content) {
if (this.getLogger().isDebugEnabled()) {
this.getLogger().debug("save content to " + uri);
}
try {
return
WebDAVUtil.getWebdavResource(this.getAbsoluteURI(uri)).putMethod(content);
} catch (HttpException he) {
this.getLogger().error("Error saving: " + this.repoBaseUrl + uri,
he);
} catch (IOException ioe) {
this.getLogger().error("Error saving: " + this.repoBaseUrl + uri,
ioe);
}
return false;
}
/* (non-Javadoc)
* @see
org.apache.cocoon.components.repository.Repository#saveContent(java.lang.String,
org.w3c.dom.Node)
*/
public boolean saveContent(String uri, Node node) {
try {
Properties format = new Properties();
format.put(OutputKeys.METHOD, "xml");
format.put(OutputKeys.OMIT_XML_DECLARATION, "yes");
return this.saveContent(uri, XMLUtils.serializeNode(node, format));
} catch (ProcessingException pe) {
this.getLogger().error("Error saving dom to: " + this.repoBaseUrl
+ uri, pe);
}
return false;
}
/* (non-Javadoc)
* @see
org.apache.cocoon.components.repository.Repository#saveContent(java.lang.String,
org.apache.excalibur.source.Source)
*/
public boolean saveContent(String uri, Source source) {
try {
return this.saveContent(uri,
IOUtil.toString(source.getInputStream()));
} catch (IOException ioe) {
this.getLogger().error("Error saving source: " + source.getURI() +
" to "+ this.repoBaseUrl + uri,
ioe);
}
return false;
}
/* (non-Javadoc)
* @see
org.apache.cocoon.components.repository.Repository#exists(java.lang.String)
*/
public boolean exists(String uri) {
if (this.getLogger().isDebugEnabled()) {
this.getLogger().debug("checking existance of " + uri);
}
try {
return
WebDAVUtil.getWebdavResource(this.getAbsoluteURI(uri)).exists();
} catch (HttpException he) {
this.getLogger().error("HTTP Error occurred while checking for
existance of: " + uri, he);
} catch (IOException ioe) {
this.getLogger().error("IO Error occurred while checking for
existance of: " + uri, ioe);
}
return false;
}
/* (non-Javadoc)
* @see
org.apache.cocoon.components.repository.Repository#copy(java.lang.String,
java.lang.String, boolean)
*/
public boolean copy(String uri, String dest, boolean recurse, boolean
overwrite) {
try {
WebDAVUtil.copyResource(this.getAbsoluteURI(uri),
this.getAbsoluteURI(dest), recurse, overwrite);
return true;
} catch (HttpException he) {
this.getLogger().error("HTTP Error copying: " + this.repoBaseUrl
+ uri, he);
} catch (IOException ioe) {
this.getLogger().error("IO Error copying: " + this.repoBaseUrl +
uri, ioe);
}
return false;
}
/* (non-Javadoc)
* @see
org.apache.cocoon.components.repository.Repository#move(java.lang.String,
java.lang.String, boolean)
*/
public boolean move(String uri, String dest, boolean recurse, boolean
overwrite) {
try {
WebDAVUtil.moveResource(this.getAbsoluteURI(uri),
this.getAbsoluteURI(dest), recurse, overwrite);
return true;
} catch (HttpException he) {
this.getLogger().error("HTTP Error moving: " + this.repoBaseUrl +
uri, he);
} catch (IOException ioe) {
this.getLogger().error("IO Error moving: " + this.repoBaseUrl +
uri, ioe);
}
return false;
}
/* (non-Javadoc)
* @see
org.apache.cocoon.components.repository.Repository#remove(java.lang.String)
*/
public boolean remove(String uri) {
try {
WebDAVUtil.getWebdavResource(this.getAbsoluteURI(uri)).deleteMethod();
return true;
} catch (HttpException he) {
this.getLogger().error("HTTP Error removing: " + this.repoBaseUrl
+ uri, he);
} catch (IOException ioe) {
this.getLogger().error("IO Error removing: " + this.repoBaseUrl +
uri, ioe);
}
return false;
}
/* (non-Javadoc)
* @see
org.apache.cocoon.components.repository.Repository#makeCollection(java.lang.String,
boolean)
*/
public boolean makeCollection(String uri, boolean recursive) {
try {
if (uri.endsWith("/")) uri = uri.substring(0, uri.length()-1);
if (recursive) {
WebDAVUtil.makePath(this.getAbsoluteURI(uri));
return true;
} else {
String parent = uri.substring(0, uri.lastIndexOf("/"));
String collection = uri.substring(uri.lastIndexOf("/")+1);
WebDAVUtil.makeCollection(this.getAbsoluteURI(parent),
collection);
return true;
}
} catch (HttpException he) {
this.getLogger().error("HTTP Error making collection: " +
this.repoBaseUrl + uri, he);
} catch (IOException ioe) {
this.getLogger().error("IO Error making collection: " +
this.repoBaseUrl + uri, ioe);
}
return false;
}
/**
* get a WebDAV property helper
*
* @return a WebDAV property helper.
*/
public RepositoryPropertyHelper getPropertyHelper() {
return this.propertyHelper;
}
/**
* get a WebDAV transaction helper
*
* @return a WebDAV transaction helper.
*/
public RepositoryTransactionHelper getTransactionHelper() {
return this.transactionHelper;
}
/**
* get a WebDAV versioning helper
*
* @return a WebDAV versioning helper.
*/
public RepositoryVersioningHelper getVersioningHelper() {
return this.versioningHelper;
}
/**
* get the absolute URI of a given path
*
* @param uri the uri to get a versioning helper for.
* @return the absolute URI.
*/
public String getAbsoluteURI(String uri) {
return "http://"+this.credentials.getPrincipal().getName()
+":"+this.credentials.getCredentials()
+"@"+this.repoBaseUrl + uri;
}
/* (non-Javadoc)
* @see
org.apache.cocoon.components.repository.Repository#getCredentials()
*/
public CredentialsToken getCredentials() {
return this.credentials;
}
/* (non-Javadoc)
* @see
org.apache.cocoon.components.repository.Repository#setCredentials(org.apache.cocoon.components.repository.helpers.CredentialsToken)
*/
public void setCredentials(CredentialsToken credentials) {
this.credentials = credentials;
}
}
1.1
cocoon-2.1/src/blocks/webdav/java/org/apache/cocoon/components/repository/impl/WebDAVRepositoryVersioningHelper.java
Index: WebDAVRepositoryVersioningHelper.java
===================================================================
/*
* Copyright 1999-2004 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.cocoon.components.repository.impl;
import java.io.IOException;
import java.util.List;
import org.apache.avalon.framework.activity.Disposable;
import org.apache.avalon.framework.component.Component;
import org.apache.avalon.framework.logger.AbstractLogEnabled;
import org.apache.avalon.framework.service.ServiceException;
import org.apache.avalon.framework.service.ServiceManager;
import org.apache.avalon.framework.service.Serviceable;
import org.apache.cocoon.components.repository.helpers.CredentialsToken;
import
org.apache.cocoon.components.repository.helpers.RepositoryVersioningHelper;
import org.apache.cocoon.components.webdav.WebDAVUtil;
import org.apache.commons.httpclient.HttpException;
/**
* A versioning helper class
* intended to be used by flowscripts or corresponding wrapper components.
*/
public class WebDAVRepositoryVersioningHelper extends AbstractLogEnabled
implements RepositoryVersioningHelper, Serviceable, Disposable, Component {
/* The ServiceManager */
private ServiceManager manager;
/* The repository component */
private WebDAVRepository repo;
/* The credentials to be used against the WebDAV repository */
private CredentialsToken credentials;
/* (non-Javadoc)
* @see
org.apache.avalon.framework.service.Serviceable#service(org.apache.avalon.framework.service.ServiceManager)
*/
public void service(ServiceManager manager) throws ServiceException {
this.manager = manager;
}
/* (non-Javadoc)
* @see org.apache.avalon.framework.activity.Disposable#dispose()
*/
public void dispose() {
this.manager = null;
}
/**
* create a WebDAVRepositoryVersioningHelper
*
* @param credentials the user credentials to be used against the WebDAV
repository.
* @param repo a reference to the WebDAVRepository object.
*/
public WebDAVRepositoryVersioningHelper (CredentialsToken credentials,
WebDAVRepository repo) {
this.credentials = credentials;
this.repo = repo;
}
/* (non-Javadoc)
* @see
org.apache.cocoon.components.repository.helpers.RepositoryVersioningHelper#checkout(java.lang.String)
*/
public boolean checkout(String uri) {
try {
WebDAVUtil.getWebdavResource(this.repo.getAbsoluteURI(uri)).checkoutMethod();
return true;
} catch (HttpException he) {
this.getLogger().error("HTTP Error checking out " + uri, he);
} catch (IOException ioe) {
this.getLogger().error("IO Error checking out " + uri, ioe);
}
return false;
}
/* (non-Javadoc)
* @see
org.apache.cocoon.components.repository.helpers.RepositoryVersioningHelper#checkin(java.lang.String)
*/
public boolean checkin(String uri) {
try {
WebDAVUtil.getWebdavResource(this.repo.getAbsoluteURI(uri)).checkinMethod();
return true;
} catch (HttpException he) {
this.getLogger().error("HTTP Error checking in " + uri, he);
} catch (IOException ioe) {
this.getLogger().error("IO Error checking in " + uri, ioe);
}
return false;
}
/* (non-Javadoc)
* @see
org.apache.cocoon.components.repository.helpers.RepositoryVersioningHelper#uncheckout(java.lang.String)
*/
public boolean uncheckout(String uri) {
try {
WebDAVUtil.getWebdavResource(this.repo.getAbsoluteURI(uri)).uncheckoutMethod();
return true;
} catch (HttpException he) {
this.getLogger().error("HTTP Error while uncheckout " + uri, he);
} catch (IOException ioe) {
this.getLogger().error("IO Error while uncheckout " + uri, ioe);
}
return false;
}
/* (non-Javadoc)
* @see
org.apache.cocoon.components.repository.helpers.RepositoryVersioningHelper#isVersioned(java.lang.String)
*/
public boolean isVersioned(String uri) {
//not yet implemented
throw new UnsupportedOperationException();
}
/* (non-Javadoc)
* @see
org.apache.cocoon.components.repository.helpers.RepositoryVersioningHelper#setVersioned(java.lang.String,
boolean)
*/
public boolean setVersioned(String uri, boolean versioned) {
//not yet implemented
throw new UnsupportedOperationException();
}
/* (non-Javadoc)
* @see
org.apache.cocoon.components.repository.helpers.RepositoryVersioningHelper#getVersions(java.lang.String)
*/
public List getVersions(String uri) {
//not yet implemented
throw new UnsupportedOperationException();
}
}
1.1
cocoon-2.1/src/blocks/webdav/java/org/apache/cocoon/components/repository/impl/WebDAVRepositoryTransactionHelper.java
Index: WebDAVRepositoryTransactionHelper.java
===================================================================
/*
* Copyright 1999-2004 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.cocoon.components.repository.impl;
import java.io.IOException;
import org.apache.avalon.framework.activity.Disposable;
import org.apache.avalon.framework.component.Component;
import org.apache.avalon.framework.logger.AbstractLogEnabled;
import org.apache.avalon.framework.service.ServiceException;
import org.apache.avalon.framework.service.ServiceManager;
import org.apache.avalon.framework.service.Serviceable;
import org.apache.cocoon.components.repository.helpers.CredentialsToken;
import
org.apache.cocoon.components.repository.helpers.RepositoryTransactionHelper;
import org.apache.cocoon.components.webdav.WebDAVUtil;
import org.apache.commons.httpclient.HttpException;
/**
* A transaction an locking helper class
* intended to be used by flowscripts or corresponding wrapper components.
*/
public class WebDAVRepositoryTransactionHelper extends AbstractLogEnabled
implements RepositoryTransactionHelper, Serviceable, Disposable, Component {
/* The ServiceManager */
private ServiceManager manager;
/* The repository component */
private WebDAVRepository repo;
/* The credentials to be used against the WebDAV repository */
private CredentialsToken credentials;
/* (non-Javadoc)
* @see
org.apache.avalon.framework.service.Serviceable#service(org.apache.avalon.framework.service.ServiceManager)
*/
public void service(ServiceManager manager) throws ServiceException {
this.manager = manager;
}
/* (non-Javadoc)
* @see org.apache.avalon.framework.activity.Disposable#dispose()
*/
public void dispose() {
this.manager = null;
}
/**
* create a WebDAVRepositoryTransactionHelper
*
* @param credentials the user credentials to be used against the WebDAV
repository.
* @param repo a reference to the WebDAVRepository object.
*/
public WebDAVRepositoryTransactionHelper(CredentialsToken credentials,
WebDAVRepository repo) {
this.credentials = credentials;
this.repo = repo;
}
/* (non-Javadoc)
* @see
org.apache.cocoon.components.repository.helpers.RepositoryTransactionHelper#beginTran()
*/
public boolean beginTran() {
//may be implemented via DeltaV activities?
throw new UnsupportedOperationException();
}
/* (non-Javadoc)
* @see
org.apache.cocoon.components.repository.helpers.RepositoryTransactionHelper#commitTran()
*/
public boolean commitTran() {
//may be implemented via DeltaV activities?
throw new UnsupportedOperationException();
}
/* (non-Javadoc)
* @see
org.apache.cocoon.components.repository.helpers.RepositoryTransactionHelper#rollbackTran()
*/
public boolean rollbackTran() {
//may be implemented via DeltaV activities?
throw new UnsupportedOperationException();
}
/* (non-Javadoc)
* @see
org.apache.cocoon.components.repository.helpers.RepositoryTransactionHelper#lock(java.lang.String)
*/
public boolean lock(String uri) {
try {
WebDAVUtil.getWebdavResource(this.repo.getAbsoluteURI(uri)).lockMethod();
return true;
} catch (HttpException he) {
this.getLogger().error("HTTP Error locking " + uri, he);
} catch (IOException ioe) {
this.getLogger().error("IO Error locking " + uri, ioe);
}
return false;
}
/* (non-Javadoc)
* @see
org.apache.cocoon.components.repository.helpers.RepositoryTransactionHelper#lock(java.lang.String,
int)
*/
public boolean lock(String uri, int timeout) {
try {
WebDAVUtil.getWebdavResource(this.repo.getAbsoluteURI(uri))
.lockMethod(this.credentials.getPrincipal().getName(),
timeout);
return true;
} catch (HttpException he) {
this.getLogger().error("HTTP Error locking " + uri, he);
} catch (IOException ioe) {
this.getLogger().error("IO Error locking " + uri, ioe);
}
return false;
}
/* (non-Javadoc)
* @see
org.apache.cocoon.components.repository.helpers.RepositoryTransactionHelper#unlock(java.lang.String)
*/
public boolean unlock(String uri) {
try {
WebDAVUtil.getWebdavResource(this.repo.getAbsoluteURI(uri)).unlockMethod();
return true;
} catch (HttpException he) {
this.getLogger().error("HTTP Error unlocking " + uri, he);
} catch (IOException ioe) {
this.getLogger().error("IO Error unlocking " + uri, ioe);
}
return false;
}
/* (non-Javadoc)
* @see
org.apache.cocoon.components.repository.helpers.RepositoryTransactionHelper#supportsTransactions()
*/
public boolean supportsTransactions() {
//may be implemeted via DeltaV activities? --> make configurable
return false;
}
/* (non-Javadoc)
* @see
org.apache.cocoon.components.repository.helpers.RepositoryTransactionHelper#supportsLocking()
*/
public boolean supportsLocking() {
return true;
}
}