| 1 19 20 package org.openharmonise.dav.server.property.ranges; 21 22 import java.util.*; 23 24 import org.openharmonise.commons.dsi.AbstractDataStoreInterface; 25 import org.openharmonise.commons.xml.XMLUtils; 26 import org.openharmonise.commons.xml.namespace.NamespaceType; 27 import org.openharmonise.dav.server.managers.HarmonisePropertiesManager; 28 import org.openharmonise.dav.server.utils.*; 29 import org.openharmonise.rm.DataAccessException; 30 import org.openharmonise.rm.factory.*; 31 import org.openharmonise.rm.resources.*; 32 import org.openharmonise.rm.resources.content.*; 33 import org.openharmonise.rm.resources.metadata.properties.Property; 34 import org.openharmonise.rm.resources.metadata.properties.ranges.*; 35 import org.openharmonise.rm.resources.metadata.values.Value; 36 import org.w3c.dom.*; 37 import org.w3c.dom.Document ; 38 39 import com.ibm.webdav.*; 40 41 48 public class DAVResourceRange extends DAVRange { 49 50 53 public DAVResourceRange(AbstractDataStoreInterface dsi) { 54 super(dsi, new AbsoluteChildObjectRange()); 55 56 } 57 58 62 public DAVResourceRange(AbstractDataStoreInterface dsi, Range range) { 63 super(dsi, range); 64 } 65 66 70 public DAVResourceRange(AbstractDataStoreInterface dsi, Element davPropEl) 71 throws WebDAVException { 72 super(dsi, new AbsoluteChildObjectRange(), davPropEl); 73 } 74 75 79 public DAVResourceRange(AbstractDataStoreInterface dsi,Range range, Element davPropEl) 80 throws WebDAVException { 81 super(dsi, range, davPropEl); 82 } 83 84 92 protected void addRangeDetails(Element rangeEl, Range range, Document doc) 93 throws WebDAVException { 94 95 try { 96 97 Element resourceTypeEl = 98 doc.createElementNS( 99 NamespaceType.DAV.getURI(), 100 HarmonisePropertiesManager.TAG_RESOURCETYPE); 101 resourceTypeEl.setPrefix(NamespaceType.DAV.getPrefix()); 102 103 String sRangeObj = ((ChildObjectRange)range).getChildObjectValueClassName((AbstractChildObject)null); 104 String sResourceType = 105 HarmoniseNameResolver.getResourceTypeFromClass(sRangeObj); 106 107 Element valEl = 108 doc.createElementNS(NamespaceType.DAV.getURI(), sResourceType); 109 valEl.setPrefix(NamespaceType.DAV.getPrefix()); 110 resourceTypeEl.appendChild(valEl); 111 rangeEl.appendChild(resourceTypeEl); 112 113 Class clss = Class.forName(sRangeObj); 114 115 AbstractChildObject child = 116 (AbstractChildObject) clss.newInstance(); 117 118 String sParentClass = child.getParentObjectClassName(); 119 120 List allowedParents = ((AbsoluteChildObjectRange) range).getAllowedParents(); 121 122 Iterator iter = allowedParents.iterator(); 123 124 while (iter.hasNext()) { 125 String sPath = (String ) iter.next(); 126 127 AbstractParentObject parent = 128 ( 129 AbstractParentObject) HarmoniseObjectFactory 130 .instantiateHarmoniseObject( 131 m_dsi, 132 sParentClass, 133 sPath); 134 135 if (parent != null) { 136 String sDAVPath = HarmoniseNameResolver.getDAVPath(parent); 137 Element hrefEl = 138 doc.createElementNS( 139 NamespaceType.DAV.getURI(), 140 HarmonisePropertiesManager.TAG_HREF); 141 hrefEl.setPrefix(NamespaceType.DAV.getPrefix()); 142 hrefEl.appendChild(doc.createTextNode(sDAVPath)); 143 rangeEl.appendChild(hrefEl); 144 } 145 } 146 147 } catch (DataAccessException e) { 148 throw new WebDAVException( 149 WebDAVStatus.SC_INTERNAL_SERVER_ERROR, 150 e.getLocalizedMessage()); 151 } catch (HarmoniseFactoryException e) { 152 throw new WebDAVException( 153 WebDAVStatus.SC_INTERNAL_SERVER_ERROR, 154 e.getLocalizedMessage()); 155 } catch (NameResolverException e) { 156 throw new WebDAVException( 157 WebDAVStatus.SC_INTERNAL_SERVER_ERROR, 158 e.getLocalizedMessage()); 159 } catch (ClassNotFoundException e) { 160 throw new WebDAVException( 161 WebDAVStatus.SC_INTERNAL_SERVER_ERROR, 162 e.getLocalizedMessage()); 163 } catch (InstantiationException e) { 164 throw new WebDAVException( 165 WebDAVStatus.SC_INTERNAL_SERVER_ERROR, 166 e.getLocalizedMessage()); 167 } catch (IllegalAccessException e) { 168 throw new WebDAVException( 169 WebDAVStatus.SC_INTERNAL_SERVER_ERROR, 170 e.getLocalizedMessage()); 171 } 172 } 173 174 175 178 public void populate(Element propEl) throws WebDAVException { 179 try { 180 String sResourceType = null; 182 183 Element resourceEl = XMLUtils.getFirstNamedChild(propEl, HarmonisePropertiesManager.TAG_RESOURCETYPE); 184 185 if(resourceEl != null) { 186 Element resourceTypeEl = XMLUtils.getFirstElementChild(resourceEl); 187 sResourceType = resourceTypeEl.getLocalName(); 188 } 189 190 NodeList hrefNodes = 192 propEl.getElementsByTagNameNS( 193 NamespaceType.DAV.getURI(), 194 HarmonisePropertiesManager.TAG_HREF); 195 196 List ohPaths = new ArrayList(); 197 AbstractParentObject parent = null; 198 199 String sParentClassName = null; 200 for (int i = 0; i < hrefNodes.getLength(); i++) { 201 Element hrefEl = (Element) hrefNodes.item(i); 202 203 String hrefVal = hrefEl.getChildNodes().item(0).getNodeValue(); 204 205 if(hrefVal != null && hrefVal.length() > 0) { 206 AbstractChildObject child = 207 HarmoniseNameResolver.getObjectFromURL(m_dsi, hrefVal); 208 209 ohPaths.add(child.getFullPath()); 210 parent = (AbstractParentObject) child; 211 212 if(sParentClassName != null && parent.getClass().getName().equals(sParentClassName) == false) { 214 throw new WebDAVException(WebDAVStatus.SC_BAD_REQUEST, "Invalid set of paths"); 215 } 216 217 sParentClassName = parent.getClass().getName(); 218 } 219 220 } 221 222 ((AbsoluteChildObjectRange)m_range).setAllowedParents(ohPaths); 223 String sClassname = null; 224 if(ohPaths.size()>0) { 226 if(sResourceType.equals(HarmonisePropertiesManager.TAG_COLLECTION)) { 227 sClassname = parent.getClass().getName(); 228 } else if(sResourceType.equals(TAG_VALUE)) { 229 sClassname = Value.class.getName(); 230 } else if(sResourceType.equals(HarmonisePropertiesManager.TAG_PROPERTY_RESOURCE) == true) { 231 sClassname = Property.class.getName(); 232 } else { 233 List childClassTypes = parent.getChildClassNames(); 234 String parentName = parent.getClass().getName(); 235 Iterator iter = childClassTypes.iterator(); 236 237 while (iter.hasNext() && sClassname == null) { 238 String sTmpClass = (String ) iter.next(); 239 if(sTmpClass.equals(parentName) == false) { 240 241 if(childClassTypes.size() == 2) { 242 sClassname = sTmpClass; 243 } else { 244 if(parentName.equals(Section.class.getName()) == true) { 247 if(parent.getFullPath().startsWith(HarmoniseNameResolver.ASSETS_PATH)) { 248 sClassname = Asset.class.getName(); 249 } else { 250 sClassname = org.openharmonise.rm.resources.content.Document.class.getName(); 251 } 252 } 253 } 254 255 } 256 } 257 258 } 259 } else { 260 sClassname = HarmoniseNameResolver.getClassFromResourceTypeDesc(sResourceType, null); 261 } 262 263 264 ((AbsoluteChildObjectRange)m_range).setObjectRestriction(sClassname); 265 266 267 } catch (DataAccessException e) { 268 throw new WebDAVException(WebDAVStatus.SC_INTERNAL_SERVER_ERROR,e.getLocalizedMessage()); 269 } catch (NameResolverException e) { 270 throw new WebDAVException(WebDAVStatus.SC_INTERNAL_SERVER_ERROR,e.getLocalizedMessage()); 271 } 272 273 274 } 275 276 } 277 | Popular Tags |