KickJava   Java API By Example, From Geeks To Geeks.

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


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 import java.util.Map JavaDoc;
21 import java.util.Properties JavaDoc;
22 import java.util.Set JavaDoc;
23
24 import javax.xml.transform.OutputKeys JavaDoc;
25
26 import org.apache.avalon.framework.activity.Disposable;
27 import org.apache.avalon.framework.component.Component;
28 import org.apache.avalon.framework.logger.AbstractLogEnabled;
29 import org.apache.avalon.framework.service.ServiceException;
30 import org.apache.avalon.framework.service.ServiceManager;
31 import org.apache.avalon.framework.service.Serviceable;
32 import org.apache.cocoon.ProcessingException;
33 import org.apache.cocoon.components.repository.helpers.CredentialsToken;
34 import org.apache.cocoon.components.repository.helpers.RepositoryPropertyHelper;
35 import org.apache.cocoon.components.source.helpers.SourceProperty;
36 import org.apache.cocoon.components.webdav.WebDAVUtil;
37 import org.apache.cocoon.xml.XMLUtils;
38 import org.apache.commons.httpclient.HttpException;
39 import org.w3c.dom.Node JavaDoc;
40
41 /**
42  * A property helper class for the WebDAV repository
43  * intended to be used by flowscripts or corresponding wrapper components.
44  */

45 public class WebDAVRepositoryPropertyHelper extends AbstractLogEnabled
46 implements RepositoryPropertyHelper, Serviceable, Disposable, Component {
47     
48     /* The ServiceManager */
49     private ServiceManager manager;
50
51     /* The repository component */
52     private WebDAVRepository repo;
53
54     /* The credentials to be used against the WebDAV repository */
55     private CredentialsToken credentials;
56
57     /* (non-Javadoc)
58      * @see org.apache.avalon.framework.service.Serviceable#service(org.apache.avalon.framework.service.ServiceManager)
59      */

60     public void service(ServiceManager manager) throws ServiceException {
61         this.manager = manager;
62     }
63
64     /* (non-Javadoc)
65      * @see org.apache.avalon.framework.activity.Disposable#dispose()
66      */

67     public void dispose() {
68         this.manager = null;
69     }
70
71     /**
72      * create a WebDAVRepositoryPropertyHelper
73      *
74      * @param credentials the user credentials to be used against the WebDAV repository.
75      * @param repo a reference to the WebDAVRepository object.
76      */

77     public WebDAVRepositoryPropertyHelper (CredentialsToken credentials, WebDAVRepository repo) {
78         this.credentials = credentials;
79         this.repo = repo;
80     }
81
82     /* (non-Javadoc)
83      * @see org.apache.cocoon.components.repository.helpers.RepositoryPropertyHelper#getProperty(java.lang.String, java.lang.String, java.lang.String)
84      */

85     public SourceProperty getProperty(String JavaDoc uri, String JavaDoc name, String JavaDoc namespace) {
86
87         try {
88             return WebDAVUtil.getProperty(this.repo.getAbsoluteURI(uri), name, namespace);
89
90         } catch (HttpException he) {
91             this.getLogger().error("HTTP Error getting property " + namespace + ":" + name + " for " + uri, he);
92
93         } catch (IOException JavaDoc ioe) {
94             this.getLogger().error("IO Error getting property " + namespace + ":" + name + " for " + uri, ioe);
95         }
96
97         return null;
98     }
99
100     /* (non-Javadoc)
101      * @see org.apache.cocoon.components.repository.helpers.RepositoryPropertyHelper#getProperties(java.lang.String, java.util.Set)
102      */

103     public Map JavaDoc getProperties(String JavaDoc uri, Set JavaDoc propNames) {
104
105         try {
106             return WebDAVUtil.getProperties(this.repo.getAbsoluteURI(uri), propNames);
107
108         } catch (HttpException he) {
109             this.getLogger().error("HTTP Error getting properties for " + uri, he);
110
111         } catch (IOException JavaDoc ioe) {
112             this.getLogger().error("IO Error getting properties for " + uri, ioe);
113         }
114
115         return null;
116     }
117
118     /* (non-Javadoc)
119      * @see org.apache.cocoon.components.repository.helpers.RepositoryPropertyHelper#getAllProperties(java.lang.String)
120      */

121     public List JavaDoc getAllProperties(String JavaDoc uri) {
122
123         try {
124             return WebDAVUtil.getAllProperties(this.repo.getAbsoluteURI(uri));
125
126         } catch (HttpException he) {
127             this.getLogger().error("HTTP Error getting properties for " + uri, he);
128
129         } catch (IOException JavaDoc ioe) {
130             this.getLogger().error("IO Error getting properties for " + uri, ioe);
131         }
132
133         return null;
134     }
135
136     /* (non-Javadoc)
137      * @see org.apache.cocoon.components.repository.helpers.RepositoryPropertyHelper#setProperty(java.lang.String, java.lang.String, java.lang.String, java.lang.String)
138      */

139     public boolean setProperty(String JavaDoc uri, String JavaDoc name, String JavaDoc namespace, String JavaDoc value) {
140
141         try {
142             WebDAVUtil.setProperty(this.repo.getAbsoluteURI(uri), name, namespace, value);
143             return true;
144
145         } catch (HttpException he) {
146             this.getLogger().error("HTTP Error setting property " + namespace + ":" + name + " for " + uri, he);
147         } catch (IOException JavaDoc ioe) {
148             this.getLogger().error("IO Error setting property " + namespace + ":" + name + " for " + uri, ioe);
149         }
150
151         return false;
152     }
153
154     /* (non-Javadoc)
155      * @see org.apache.cocoon.components.repository.helpers.RepositoryPropertyHelper#setProperty(java.lang.String, java.lang.String, java.lang.String, org.w3c.dom.Node)
156      */

157     public boolean setProperty(String JavaDoc uri, String JavaDoc name, String JavaDoc namespace, Node JavaDoc value) {
158
159         try {
160             Properties JavaDoc format = new Properties JavaDoc();
161             format.put(OutputKeys.METHOD, "xml");
162             format.put(OutputKeys.OMIT_XML_DECLARATION, "yes");
163             return this.setProperty(uri, name, namespace, XMLUtils.serializeNode(value, format));
164
165         } catch (ProcessingException pe) {
166             this.getLogger().error("Error serializing node " + value, pe);
167         }
168
169         return false;
170     }
171
172     /* (non-Javadoc)
173      * @see org.apache.cocoon.components.repository.helpers.RepositoryPropertyHelper#setProperties(java.lang.String, java.util.Map)
174      */

175     public boolean setProperties(final String JavaDoc uri, final Map JavaDoc properties) {
176
177         try {
178             WebDAVUtil.setProperties(this.repo.getAbsoluteURI(uri), properties);
179             return true;
180
181         } catch (HttpException he) {
182             this.getLogger().error("HTTP Error setting properties for " + uri, he);
183         } catch (IOException JavaDoc ioe) {
184             this.getLogger().error("IO Error setting properties for " + uri, ioe);
185         }
186
187         return false;
188     }
189
190 }
Popular Tags