001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017: package org.apache.cocoon.components.repository.impl;
018:
019: import java.io.IOException;
020: import java.util.List;
021:
022: import org.apache.avalon.framework.activity.Disposable;
023: import org.apache.avalon.framework.component.Component;
024: import org.apache.avalon.framework.logger.AbstractLogEnabled;
025: import org.apache.avalon.framework.service.ServiceException;
026: import org.apache.avalon.framework.service.ServiceManager;
027: import org.apache.avalon.framework.service.Serviceable;
028: import org.apache.cocoon.components.repository.helpers.CredentialsToken;
029: import org.apache.cocoon.components.repository.helpers.RepositoryVersioningHelper;
030: import org.apache.cocoon.components.webdav.WebDAVUtil;
031: import org.apache.commons.httpclient.HttpException;
032:
033: /**
034: * A versioning helper class
035: * intended to be used by flowscripts or corresponding wrapper components.
036: */
037: public class WebDAVRepositoryVersioningHelper extends
038: AbstractLogEnabled implements RepositoryVersioningHelper,
039: Serviceable, Disposable, Component {
040:
041: /* The ServiceManager */
042: private ServiceManager manager;
043:
044: /* The repository component */
045: private WebDAVRepository repo;
046:
047: /* The credentials to be used against the WebDAV repository */
048: private CredentialsToken credentials;
049:
050: /* (non-Javadoc)
051: * @see org.apache.avalon.framework.service.Serviceable#service(org.apache.avalon.framework.service.ServiceManager)
052: */
053: public void service(ServiceManager manager) throws ServiceException {
054: this .manager = manager;
055: }
056:
057: /* (non-Javadoc)
058: * @see org.apache.avalon.framework.activity.Disposable#dispose()
059: */
060: public void dispose() {
061: this .manager = null;
062: }
063:
064: /**
065: * create a WebDAVRepositoryVersioningHelper
066: *
067: * @param credentials the user credentials to be used against the WebDAV repository.
068: * @param repo a reference to the WebDAVRepository object.
069: */
070: public WebDAVRepositoryVersioningHelper(
071: CredentialsToken credentials, WebDAVRepository repo) {
072: this .credentials = credentials;
073: this .repo = repo;
074: }
075:
076: /* (non-Javadoc)
077: * @see org.apache.cocoon.components.repository.helpers.RepositoryVersioningHelper#checkout(java.lang.String)
078: */
079: public boolean checkout(String uri) {
080:
081: try {
082: WebDAVUtil.getWebdavResource(this .repo.getAbsoluteURI(uri))
083: .checkoutMethod();
084: return true;
085:
086: } catch (HttpException he) {
087: this .getLogger()
088: .error("HTTP Error checking out " + uri, he);
089: } catch (IOException ioe) {
090: this .getLogger().error("IO Error checking out " + uri, ioe);
091: }
092:
093: return false;
094: }
095:
096: /* (non-Javadoc)
097: * @see org.apache.cocoon.components.repository.helpers.RepositoryVersioningHelper#checkin(java.lang.String)
098: */
099: public boolean checkin(String uri) {
100:
101: try {
102: WebDAVUtil.getWebdavResource(this .repo.getAbsoluteURI(uri))
103: .checkinMethod();
104: return true;
105:
106: } catch (HttpException he) {
107: this .getLogger().error("HTTP Error checking in " + uri, he);
108: } catch (IOException ioe) {
109: this .getLogger().error("IO Error checking in " + uri, ioe);
110: }
111:
112: return false;
113: }
114:
115: /* (non-Javadoc)
116: * @see org.apache.cocoon.components.repository.helpers.RepositoryVersioningHelper#uncheckout(java.lang.String)
117: */
118: public boolean uncheckout(String uri) {
119:
120: try {
121: WebDAVUtil.getWebdavResource(this .repo.getAbsoluteURI(uri))
122: .uncheckoutMethod();
123: return true;
124:
125: } catch (HttpException he) {
126: this .getLogger().error(
127: "HTTP Error while uncheckout " + uri, he);
128: } catch (IOException ioe) {
129: this .getLogger().error("IO Error while uncheckout " + uri,
130: ioe);
131: }
132:
133: return false;
134: }
135:
136: /* (non-Javadoc)
137: * @see org.apache.cocoon.components.repository.helpers.RepositoryVersioningHelper#isVersioned(java.lang.String)
138: */
139: public boolean isVersioned(String uri) {
140: //not yet implemented
141: throw new UnsupportedOperationException();
142: }
143:
144: /* (non-Javadoc)
145: * @see org.apache.cocoon.components.repository.helpers.RepositoryVersioningHelper#setVersioned(java.lang.String, boolean)
146: */
147: public boolean setVersioned(final String uri,
148: final boolean versioned) {
149:
150: try {
151: if (!versioned) {
152: return false;
153:
154: } else {
155: return WebDAVUtil.getWebdavResource(
156: this .repo.getAbsoluteURI(uri))
157: .versionControlMethod(
158: this .repo.getAbsoluteURI(uri));
159: }
160:
161: } catch (HttpException he) {
162: this .getLogger().error(
163: "HTTP Error while versioncontrol " + uri, he);
164: } catch (IOException ioe) {
165: this .getLogger().error(
166: "IO Error while versioncontrol " + uri, ioe);
167: }
168:
169: return false;
170: }
171:
172: /* (non-Javadoc)
173: * @see org.apache.cocoon.components.repository.helpers.RepositoryVersioningHelper#getVersions(java.lang.String)
174: */
175: public List getVersions(String uri) {
176: //not yet implemented
177: throw new UnsupportedOperationException();
178: }
179:
180: }
|