KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > slide > webdav > util > ComputedPropertyProvider


1 /*
2  * $Header: /home/cvs/jakarta-slide/src/webdav/server/org/apache/slide/webdav/util/ComputedPropertyProvider.java,v 1.9.2.1 2004/10/19 13:26:58 unico Exp $
3  * $Revision: 1.9.2.1 $
4  * $Date: 2004/10/19 13:26:58 $
5  *
6  * ====================================================================
7  *
8  * Copyright 1999 The Apache Software Foundation
9  *
10  * Licensed under the Apache License, Version 2.0 (the "License");
11  * you may not use this file except in compliance with the License.
12  * You may obtain a copy of the License at
13  *
14  * http://www.apache.org/licenses/LICENSE-2.0
15  *
16  * Unless required by applicable law or agreed to in writing, software
17  * distributed under the License is distributed on an "AS IS" BASIS,
18  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19  * See the License for the specific language governing permissions and
20  * limitations under the License.
21  *
22  */

23 package org.apache.slide.webdav.util;
24
25 // import list
26
import java.util.ArrayList JavaDoc;
27 import java.util.Iterator JavaDoc;
28 import java.util.List JavaDoc;
29 import java.util.Set JavaDoc;
30
31 import org.apache.slide.common.NamespaceAccessToken;
32 import org.apache.slide.common.PropertyName;
33 import org.apache.slide.common.SlideException;
34 import org.apache.slide.common.SlideToken;
35 import org.apache.slide.content.Content;
36 import org.apache.slide.content.NodeProperty;
37 import org.apache.slide.content.NodeRevisionDescriptor;
38 import org.apache.slide.content.NodeRevisionDescriptors;
39 import org.apache.slide.content.NodeProperty.NamespaceCache;
40 import org.apache.slide.search.PropertyProvider;
41 import org.apache.slide.webdav.WebdavServletConfig;
42 import org.apache.slide.webdav.util.resourcekind.AbstractResourceKind;
43 import org.apache.slide.webdav.util.resourcekind.ResourceKind;
44 import org.jdom.JDOMException;
45
46 /**
47  *
48  *
49  * @version $Revision: 1.9.2.1 $
50  *
51  **/

52 public class ComputedPropertyProvider implements PropertyProvider {
53     
54     /**
55      * The context path of the request, the prefix of all slide uri in the
56      * WebDAV view.
57      */

58    protected String JavaDoc slideContextPath = null;
59     
60     /**
61      * The Content helper to use.
62      */

63     protected Content contentHelper = null;
64     
65     /**
66      * The NamespaceAccessToken to use.
67      */

68     protected NamespaceAccessToken nsaToken= null;
69     
70     /**
71      * The SlideToken to use.
72      */

73     protected SlideToken slideToken= null;
74     
75     /**
76      * The PropertyHelper to use to access the computed properties.
77      */

78     protected PropertyHelper propertyHelper = null;
79     
80     /**
81      * The NodeRevisionDescriptors of the current resource.
82      */

83     protected NodeRevisionDescriptors revisionDescriptors = null;
84     
85     /**
86      * The NodeRevisionDescriptor of the current resource.
87      */

88     protected NodeRevisionDescriptor revisionDescriptor = null;
89     
90     /**
91      * The URI of the last accessed resource.
92      */

93     protected String JavaDoc lastResourceUri = null;
94
95     
96     /**
97      * Creates a ComputedPropertyProvider.
98      *
99      * @param nsaToken the NamespaceAccessToken to use.
100      * @param slideToken the SlideToken to use.
101      * @param slideContextPath the context + servlet path of the request.
102      */

103     public ComputedPropertyProvider(NamespaceAccessToken nsaToken, SlideToken slideToken, String JavaDoc slideContextPath, WebdavServletConfig sConf) {
104        this(nsaToken, slideToken,
105              PropertyHelper.getPropertyHelper(slideToken, nsaToken, sConf),
106              slideContextPath);
107     }
108     /**
109      * @deprecated use {@link #ComputedPropertyProvider(NamespaceAccessToken, SlideToken, String, WebdavServletConfig)}
110      */

111     public ComputedPropertyProvider(NamespaceAccessToken nsaToken, SlideToken slideToken, String JavaDoc contextPath, String JavaDoc servletPath, WebdavServletConfig sConf) {
112         this(nsaToken, slideToken, PropertyHelper.getPropertyHelper(slideToken, nsaToken, sConf), contextPath, servletPath);
113     }
114
115     /**
116      * @deprecated
117      */

118     public ComputedPropertyProvider(NamespaceAccessToken nsaToken, SlideToken slideToken, String JavaDoc contextPath, String JavaDoc servletPath) {
119         this(nsaToken, slideToken, PropertyHelper.getPropertyHelper(slideToken, nsaToken, null), contextPath, servletPath);
120     }
121     
122     /**
123      * Creates a ComputedPropertyProvider.
124      *
125      * @param nsaToken the NamespaceAccessToken to use.
126      * @param slideToken the SlideToken to use.
127      * @param propertyHelper the PropertyHelper to use to access the computed properties.
128      * @param slideContextPath the context + servlet path of the request.
129      */

130     public ComputedPropertyProvider(NamespaceAccessToken nsaToken,
131           SlideToken slideToken, PropertyHelper propertyHelper,
132           String JavaDoc slideContextPath)
133     {
134        this.nsaToken = nsaToken;
135        this.slideToken = slideToken;
136        this.propertyHelper = propertyHelper;
137        this.slideContextPath = slideContextPath;
138        
139        contentHelper = nsaToken.getContentHelper();
140     }
141     
142     /**
143      * @deprecated use {@link #ComputedPropertyProvider(NamespaceAccessToken, SlideToken, PropertyHelper, String)}
144      */

145     public ComputedPropertyProvider(NamespaceAccessToken nsaToken, SlideToken slideToken, PropertyHelper propertyHelper, String JavaDoc contextPath, String JavaDoc servletPath) {
146         
147         this.nsaToken = nsaToken;
148         this.slideToken = slideToken;
149         this.propertyHelper = propertyHelper;
150         //this.contextPath = contextPath;
151
//this.servletPath = servletPath;
152
this.slideContextPath = contextPath + servletPath;
153         
154         contentHelper = nsaToken.getContentHelper();
155     }
156     
157     /**
158      * Returns <code>true</code> if this PropertyProvider can provide the NodeProperty
159      * specified by <code>propertyNamespace</code> and <code>propertyName</code>
160      * for the resource with the given <code>resourceUri</code>.
161      *
162      * @param resourceUri the URI of the resource.
163      * @param propertyName the name of the property.
164      * @param propertyNamespace the namespace of the property.
165      *
166      * @return <code>true</code> if this PropertyProvider can provide the NodeProperty.
167      *
168      * @throws SlideException
169      */

170     public boolean isSupportedProperty(String JavaDoc resourceUri, String JavaDoc propertyName, String JavaDoc propertyNamespace) throws SlideException {
171         
172         updateDescriptors(resourceUri);
173         return getComputedPropertiesNames().contains(propertyName);
174     }
175     
176     /**
177      * Returns the names of the computed properties.
178      *
179      * @return the names of the computed properties.
180      */

181     protected Set JavaDoc getComputedPropertiesNames() {
182         
183         ResourceKind resourceKind =
184             AbstractResourceKind.determineResourceKind(nsaToken,
185                                                        revisionDescriptors,
186                                                        revisionDescriptor);
187         Set JavaDoc computedLivePropertyNames =
188             resourceKind.getSupportedLiveProperties(DeltavConstants.Q_COMPUTED_ONLY);
189         return computedLivePropertyNames;
190     }
191     
192     /**
193      * Returns an Iterator of PropertyName of all properties supported by this
194      * PropertyProvider.
195      *
196      * @param resourceUri the URI of the resource for which to return
197      * the suppored PropertyNames.
198      *
199      * @return an Iterator of PropertyName.
200      *
201      * @throws SlideException
202      */

203     public Iterator JavaDoc getSupportedPropertiesNames(String JavaDoc resourceUri) throws SlideException {
204         
205         updateDescriptors(resourceUri);
206         Set JavaDoc computedLivePropertyNames = getComputedPropertiesNames();
207         List JavaDoc propertiesNamesList = new ArrayList JavaDoc(computedLivePropertyNames.size());
208         Iterator JavaDoc iterator = computedLivePropertyNames.iterator();
209         while (iterator.hasNext()) {
210             propertiesNamesList.add(new PropertyName((String JavaDoc)iterator.next(),
211                                                      NamespaceCache.DEFAULT_URI));
212         }
213         
214         return propertiesNamesList.iterator();
215     }
216     
217     
218     /**
219      * If the property specified by <code>propertyNamespace</code> and
220      * <code>propertyName</code> is {@link #isSupportedProperty supported
221      * by this PropertyProvider}, the NodeProperty of the resource located
222      * at the given <code>resourceUri</code> will be returned. Otherwise
223      * <code>null</code> is returned.
224      *
225      * @param resourceUri the URI of the resource for which to return
226      * the NodeProperty.
227      * @param propertyName the name of the property to return.
228      * @param propertyNamespace the namespace of the property to return.
229      *
230      * @return the requested NodeProperty if it is supported, otherwise
231      * <code>null</code>.
232      *
233      * @throws SlideException
234      */

235     public NodeProperty getProperty(String JavaDoc resourceUri, String JavaDoc propertyName, String JavaDoc propertyNamespace) throws SlideException {
236         
237         updateDescriptors(resourceUri);
238         try {
239             return propertyHelper.getProperty(propertyName, revisionDescriptors, revisionDescriptor, slideContextPath);
240         }
241         catch (JDOMException e) {
242             throw new SlideException("ComputedPropertyProvider.getProperty(): " + e.getMessage());
243         }
244     }
245     
246     /**
247      * Returns an Iterator of all NodeProperties supported by this PropertyProvider.
248      *
249      * @param resourceUri the URI of the resource for which to return
250      * the supported properties.
251      *
252      * @return all NodeProperties supported by this provider.
253      *
254      * @throws SlideException
255      */

256     public Iterator JavaDoc getSupportedProperties(String JavaDoc resourceUri) throws SlideException {
257         
258         updateDescriptors(resourceUri);
259         Set JavaDoc propertyNames = getComputedPropertiesNames();
260         List JavaDoc supportedProperties = new ArrayList JavaDoc(propertyNames.size());
261         Iterator JavaDoc iterator = propertyNames.iterator();
262         while (iterator.hasNext()) {
263             supportedProperties.add(getProperty(resourceUri,
264                                                     (String JavaDoc)iterator.next(),
265                                                 NamespaceCache.DEFAULT_URI));
266         }
267         return supportedProperties.iterator();
268     }
269     
270     /**
271      * Updates the {@link #revisionDescriptors revisionDescriptors} and
272      * {@link #revisionDescriptor revisionDescriptor} if the given
273      * <code>resourceUri</code> is different from the {@link #lastResourceUri
274      * last accessed resource URI}.
275      *
276      * @param resourceUri the URI of the resource to access next.
277      *
278      * @throws SlideException
279      */

280     protected void updateDescriptors(String JavaDoc resourceUri) throws SlideException {
281         if ( (lastResourceUri == null) || ( ! lastResourceUri.equals(resourceUri) ) ) {
282             revisionDescriptors = contentHelper.retrieve(slideToken, resourceUri);
283             revisionDescriptor = contentHelper.retrieve(slideToken, revisionDescriptors);
284             lastResourceUri = resourceUri;
285         }
286     }
287     
288 }
289
290
Popular Tags