KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > cocoon > components > repository > impl > WebDAVRepositoryVersioningHelper


1 /*
2  * Copyright 1999-2004 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16 package org.apache.cocoon.components.repository.impl;
17
18 import java.io.IOException JavaDoc;
19 import java.util.List JavaDoc;
20
21 import org.apache.avalon.framework.activity.Disposable;
22 import org.apache.avalon.framework.component.Component;
23 import org.apache.avalon.framework.logger.AbstractLogEnabled;
24 import org.apache.avalon.framework.service.ServiceException;
25 import org.apache.avalon.framework.service.ServiceManager;
26 import org.apache.avalon.framework.service.Serviceable;
27 import org.apache.cocoon.components.repository.helpers.CredentialsToken;
28 import org.apache.cocoon.components.repository.helpers.RepositoryVersioningHelper;
29 import org.apache.cocoon.components.webdav.WebDAVUtil;
30 import org.apache.commons.httpclient.HttpException;
31
32 /**
33  * A versioning helper class
34  * intended to be used by flowscripts or corresponding wrapper components.
35  */

36 public class WebDAVRepositoryVersioningHelper extends AbstractLogEnabled
37 implements RepositoryVersioningHelper, Serviceable, Disposable, Component {
38     
39     /* The ServiceManager */
40     private ServiceManager manager;
41
42     /* The repository component */
43     private WebDAVRepository repo;
44
45     /* The credentials to be used against the WebDAV repository */
46     private CredentialsToken credentials;
47
48     /* (non-Javadoc)
49      * @see org.apache.avalon.framework.service.Serviceable#service(org.apache.avalon.framework.service.ServiceManager)
50      */

51     public void service(ServiceManager manager) throws ServiceException {
52         this.manager = manager;
53     }
54
55     /* (non-Javadoc)
56      * @see org.apache.avalon.framework.activity.Disposable#dispose()
57      */

58     public void dispose() {
59         this.manager = null;
60     }
61
62     /**
63      * create a WebDAVRepositoryVersioningHelper
64      *
65      * @param credentials the user credentials to be used against the WebDAV repository.
66      * @param repo a reference to the WebDAVRepository object.
67      */

68     public WebDAVRepositoryVersioningHelper (CredentialsToken credentials, WebDAVRepository repo) {
69         this.credentials = credentials;
70         this.repo = repo;
71     }
72
73     /* (non-Javadoc)
74      * @see org.apache.cocoon.components.repository.helpers.RepositoryVersioningHelper#checkout(java.lang.String)
75      */

76     public boolean checkout(String JavaDoc uri) {
77
78         try {
79             WebDAVUtil.getWebdavResource(this.repo.getAbsoluteURI(uri)).checkoutMethod();
80             return true;
81
82         } catch (HttpException he) {
83             this.getLogger().error("HTTP Error checking out " + uri, he);
84         } catch (IOException JavaDoc ioe) {
85             this.getLogger().error("IO Error checking out " + uri, ioe);
86         }
87
88         return false;
89     }
90
91     /* (non-Javadoc)
92      * @see org.apache.cocoon.components.repository.helpers.RepositoryVersioningHelper#checkin(java.lang.String)
93      */

94     public boolean checkin(String JavaDoc uri) {
95
96         try {
97             WebDAVUtil.getWebdavResource(this.repo.getAbsoluteURI(uri)).checkinMethod();
98             return true;
99
100         } catch (HttpException he) {
101             this.getLogger().error("HTTP Error checking in " + uri, he);
102         } catch (IOException JavaDoc ioe) {
103             this.getLogger().error("IO Error checking in " + uri, ioe);
104         }
105
106         return false;
107     }
108
109     /* (non-Javadoc)
110      * @see org.apache.cocoon.components.repository.helpers.RepositoryVersioningHelper#uncheckout(java.lang.String)
111      */

112     public boolean uncheckout(String JavaDoc uri) {
113
114         try {
115             WebDAVUtil.getWebdavResource(this.repo.getAbsoluteURI(uri)).uncheckoutMethod();
116             return true;
117
118         } catch (HttpException he) {
119             this.getLogger().error("HTTP Error while uncheckout " + uri, he);
120         } catch (IOException JavaDoc ioe) {
121             this.getLogger().error("IO Error while uncheckout " + uri, ioe);
122         }
123
124         return false;
125     }
126
127     /* (non-Javadoc)
128      * @see org.apache.cocoon.components.repository.helpers.RepositoryVersioningHelper#isVersioned(java.lang.String)
129      */

130     public boolean isVersioned(String JavaDoc uri) {
131         //not yet implemented
132
throw new UnsupportedOperationException JavaDoc();
133     }
134
135     /* (non-Javadoc)
136      * @see org.apache.cocoon.components.repository.helpers.RepositoryVersioningHelper#setVersioned(java.lang.String, boolean)
137      */

138     public boolean setVersioned(final String JavaDoc uri, final boolean versioned) {
139
140         try {
141             if(!versioned) {
142                 return false;
143
144             } else {
145                 return WebDAVUtil.getWebdavResource(this.repo.getAbsoluteURI(uri))
146                                                     .versionControlMethod(this.repo.getAbsoluteURI(uri));
147             }
148
149         } catch (HttpException he) {
150             this.getLogger().error("HTTP Error while versioncontrol " + uri, he);
151         } catch (IOException JavaDoc ioe) {
152             this.getLogger().error("IO Error while versioncontrol " + uri, ioe);
153         }
154         
155         return false;
156     }
157
158     /* (non-Javadoc)
159      * @see org.apache.cocoon.components.repository.helpers.RepositoryVersioningHelper#getVersions(java.lang.String)
160      */

161     public List JavaDoc getVersions(String JavaDoc uri) {
162         //not yet implemented
163
throw new UnsupportedOperationException JavaDoc();
164     }
165
166 }
Popular Tags