| 1 23 24 package org.apache.slide.webdav.util; 25 26 import java.util.Enumeration; 27 import java.util.HashSet; 28 import java.util.Iterator; 29 import java.util.Set; 30 31 import org.apache.slide.common.PropertyName; 32 import org.apache.slide.common.SlideException; 33 import org.apache.slide.content.NodeProperty; 34 import org.apache.slide.content.NodeRevisionDescriptor; 35 import org.apache.slide.content.NodeRevisionDescriptors; 36 import org.apache.slide.search.PropertyProvider; 37 import org.apache.slide.search.RequestedResource; 38 39 48 public class ResourceWithProvidedProperties implements RequestedResource { 49 50 53 protected NodeRevisionDescriptors revisionDescriptors = null; 54 55 58 protected NodeRevisionDescriptor revisionDescriptor = null; 59 60 63 protected PropertyProvider propertyProvider = null; 64 65 75 public ResourceWithProvidedProperties(NodeRevisionDescriptors revisionDescriptors, 76 NodeRevisionDescriptor revisionDescriptor, 77 PropertyProvider propertyProvider) { 78 79 this.revisionDescriptors = revisionDescriptors; 80 this.revisionDescriptor = revisionDescriptor; 81 this.propertyProvider = propertyProvider; 82 } 83 84 89 public String getUri() { 90 return revisionDescriptors.getOriginalUri(); 91 } 92 93 102 public NodeProperty getProperty(PropertyName propertyName) throws SlideException { 103 return getProperty(propertyName.getName(), propertyName.getNamespace()); 104 } 105 106 118 public NodeProperty getProperty(String name, String namespace) throws SlideException { 119 120 if ( (propertyProvider != null) && 121 propertyProvider.isSupportedProperty(getUri(), name, namespace) ) { 122 return propertyProvider.getProperty(getUri(), name, namespace); 123 } 124 else { 125 return revisionDescriptor.getProperty(name, namespace); 126 } 127 } 128 129 136 public Iterator getAllPropertiesNames() throws SlideException { 137 138 Set propertyNamesList = new HashSet(); 139 Enumeration enum = revisionDescriptor.enumerateProperties(); 140 NodeProperty property = null; 141 if (enum != null) { 142 while (enum.hasMoreElements()) { 143 property = (NodeProperty)enum.nextElement(); 144 propertyNamesList.add(new PropertyName(property.getName(), 145 property.getNamespace())); 146 } 147 } 148 149 if (propertyProvider != null) { 150 Iterator iterator = propertyProvider.getSupportedPropertiesNames(getUri()); 151 while (iterator.hasNext()) { 152 propertyNamesList.add(iterator.next()); 153 } 154 } 155 156 return propertyNamesList.iterator(); 157 } 158 159 166 public Iterator getAllProperties() throws SlideException { 167 168 Set propertyList = new HashSet(); 169 Enumeration enum = revisionDescriptor.enumerateProperties(); 170 if (enum != null) { 171 while (enum.hasMoreElements()) { 172 propertyList.add(enum.nextElement()); 173 } 174 } 175 176 if (propertyProvider != null) { 177 Iterator iterator = propertyProvider.getSupportedProperties(getUri()); 178 while (iterator.hasNext()) { 179 propertyList.add(iterator.next()); 180 } 181 } 182 183 return propertyList.iterator(); 184 } 185 186 } 187 188 | Popular Tags |