1 23 package org.apache.slide.webdav.util; 24 25 import java.util.ArrayList ; 27 import java.util.Iterator ; 28 import java.util.List ; 29 import java.util.Set ; 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 52 public class ComputedPropertyProvider implements PropertyProvider { 53 54 58 protected String slideContextPath = null; 59 60 63 protected Content contentHelper = null; 64 65 68 protected NamespaceAccessToken nsaToken= null; 69 70 73 protected SlideToken slideToken= null; 74 75 78 protected PropertyHelper propertyHelper = null; 79 80 83 protected NodeRevisionDescriptors revisionDescriptors = null; 84 85 88 protected NodeRevisionDescriptor revisionDescriptor = null; 89 90 93 protected String lastResourceUri = null; 94 95 96 103 public ComputedPropertyProvider(NamespaceAccessToken nsaToken, SlideToken slideToken, String slideContextPath, WebdavServletConfig sConf) { 104 this(nsaToken, slideToken, 105 PropertyHelper.getPropertyHelper(slideToken, nsaToken, sConf), 106 slideContextPath); 107 } 108 111 public ComputedPropertyProvider(NamespaceAccessToken nsaToken, SlideToken slideToken, String contextPath, String servletPath, WebdavServletConfig sConf) { 112 this(nsaToken, slideToken, PropertyHelper.getPropertyHelper(slideToken, nsaToken, sConf), contextPath, servletPath); 113 } 114 115 118 public ComputedPropertyProvider(NamespaceAccessToken nsaToken, SlideToken slideToken, String contextPath, String servletPath) { 119 this(nsaToken, slideToken, PropertyHelper.getPropertyHelper(slideToken, nsaToken, null), contextPath, servletPath); 120 } 121 122 130 public ComputedPropertyProvider(NamespaceAccessToken nsaToken, 131 SlideToken slideToken, PropertyHelper propertyHelper, 132 String 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 145 public ComputedPropertyProvider(NamespaceAccessToken nsaToken, SlideToken slideToken, PropertyHelper propertyHelper, String contextPath, String servletPath) { 146 147 this.nsaToken = nsaToken; 148 this.slideToken = slideToken; 149 this.propertyHelper = propertyHelper; 150 this.slideContextPath = contextPath + servletPath; 153 154 contentHelper = nsaToken.getContentHelper(); 155 } 156 157 170 public boolean isSupportedProperty(String resourceUri, String propertyName, String propertyNamespace) throws SlideException { 171 172 updateDescriptors(resourceUri); 173 return getComputedPropertiesNames().contains(propertyName); 174 } 175 176 181 protected Set getComputedPropertiesNames() { 182 183 ResourceKind resourceKind = 184 AbstractResourceKind.determineResourceKind(nsaToken, 185 revisionDescriptors, 186 revisionDescriptor); 187 Set computedLivePropertyNames = 188 resourceKind.getSupportedLiveProperties(DeltavConstants.Q_COMPUTED_ONLY); 189 return computedLivePropertyNames; 190 } 191 192 203 public Iterator getSupportedPropertiesNames(String resourceUri) throws SlideException { 204 205 updateDescriptors(resourceUri); 206 Set computedLivePropertyNames = getComputedPropertiesNames(); 207 List propertiesNamesList = new ArrayList (computedLivePropertyNames.size()); 208 Iterator iterator = computedLivePropertyNames.iterator(); 209 while (iterator.hasNext()) { 210 propertiesNamesList.add(new PropertyName((String )iterator.next(), 211 NamespaceCache.DEFAULT_URI)); 212 } 213 214 return propertiesNamesList.iterator(); 215 } 216 217 218 235 public NodeProperty getProperty(String resourceUri, String propertyName, String 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 256 public Iterator getSupportedProperties(String resourceUri) throws SlideException { 257 258 updateDescriptors(resourceUri); 259 Set propertyNames = getComputedPropertiesNames(); 260 List supportedProperties = new ArrayList (propertyNames.size()); 261 Iterator iterator = propertyNames.iterator(); 262 while (iterator.hasNext()) { 263 supportedProperties.add(getProperty(resourceUri, 264 (String )iterator.next(), 265 NamespaceCache.DEFAULT_URI)); 266 } 267 return supportedProperties.iterator(); 268 } 269 270 280 protected void updateDescriptors(String 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 |