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.namespace.NamespaceType; 26 import org.openharmonise.dav.server.managers.HarmonisePropertiesManager; 27 import org.openharmonise.dav.server.utils.*; 28 import org.openharmonise.rm.DataAccessException; 29 import org.openharmonise.rm.factory.*; 30 import org.openharmonise.rm.resources.*; 31 import org.openharmonise.rm.resources.metadata.properties.PropertyGroup; 32 import org.openharmonise.rm.resources.metadata.properties.ranges.*; 33 import org.w3c.dom.*; 34 35 import com.ibm.webdav.*; 36 37 46 public class DAVPropertyRange extends DAVRange { 47 48 51 public DAVPropertyRange(AbstractDataStoreInterface dsi) { 52 super(dsi, new ProfileRange()); 53 } 54 55 59 public DAVPropertyRange(AbstractDataStoreInterface dsi, Range range) { 60 super(dsi, range); 61 } 62 63 67 public DAVPropertyRange(AbstractDataStoreInterface dsi, Element davPropEl) 68 throws WebDAVException { 69 super(dsi, new ProfileRange(), davPropEl); 70 71 } 72 73 74 77 protected void addRangeDetails(Element rangeEl, Range range, Document doc) 78 throws WebDAVException { 79 Element resourceTypeEl = 80 doc.createElementNS( 81 NamespaceType.DAV.getURI(), 82 HarmonisePropertiesManager.TAG_RESOURCETYPE); 83 resourceTypeEl.setPrefix(NamespaceType.DAV.getPrefix()); 84 85 Element propResEl = 86 doc.createElementNS( 87 NamespaceType.DAV.getURI(), 88 HarmonisePropertiesManager.TAG_PROPERTY_RESOURCE); 89 propResEl.setPrefix(NamespaceType.DAV.getPrefix()); 90 resourceTypeEl.appendChild(propResEl); 91 rangeEl.appendChild(resourceTypeEl); 92 93 List allowedPropGroups = 94 ((ProfileRange) m_range).getAllowedPropertyParents(); 95 96 Iterator iter = allowedPropGroups.iterator(); 97 try { 98 while (iter.hasNext()) { 99 String sPath = (String ) iter.next(); 100 if (sPath != null) { 101 AbstractParentObject parent = 102 ( 103 AbstractParentObject) HarmoniseObjectFactory 104 .instantiateHarmoniseObject( 105 m_dsi, 106 PropertyGroup.class.getName(), 107 sPath); 108 String sDAVPath = HarmoniseNameResolver.getDAVPath(parent); 109 if(sDAVPath != null) { 110 Element hrefEl = 111 doc.createElementNS( 112 NamespaceType.DAV.getURI(), 113 HarmonisePropertiesManager.TAG_HREF); 114 hrefEl.setPrefix(NamespaceType.DAV.getPrefix()); 115 hrefEl.appendChild(doc.createTextNode(sDAVPath)); 116 rangeEl.appendChild(hrefEl); 117 } 118 119 } 120 } 121 122 } catch (HarmoniseFactoryException e) { 123 throw new WebDAVException( 124 WebDAVStatus.SC_INTERNAL_SERVER_ERROR, 125 e.getLocalizedMessage()); 126 } catch (NameResolverException e) { 127 throw new WebDAVException( 128 WebDAVStatus.SC_INTERNAL_SERVER_ERROR, 129 e.getLocalizedMessage()); 130 } 131 132 } 133 134 135 138 public void populate(Element propEl) throws WebDAVException { 139 try { 140 NodeList hrefNodes = 142 propEl.getElementsByTagNameNS( 143 NamespaceType.DAV.getURI(), 144 HarmonisePropertiesManager.TAG_HREF); 145 146 List ohPaths = new ArrayList(); 147 AbstractParentObject parent = null; 148 149 String sParentClassName = null; 150 for (int i = 0; i < hrefNodes.getLength(); i++) { 151 Element hrefEl = (Element) hrefNodes.item(i); 152 153 String hrefVal = hrefEl.getChildNodes().item(0).getNodeValue(); 154 155 if (hrefVal != null && hrefVal.length() > 0) { 156 AbstractChildObject child = 157 HarmoniseNameResolver.getObjectFromURL(m_dsi, hrefVal); 158 159 if ((child instanceof PropertyGroup) == false) { 160 throw new WebDAVException( 161 WebDAVStatus.SC_BAD_REQUEST, 162 "Invalid path - " + hrefVal); 163 } 164 165 ohPaths.add(child.getFullPath()); 166 parent = (AbstractParentObject) child; 167 168 if (sParentClassName != null 170 && parent.getClass().getName().equals(sParentClassName) 171 == false) { 172 throw new WebDAVException( 173 WebDAVStatus.SC_BAD_REQUEST, 174 "Invalid set of paths"); 175 } 176 177 sParentClassName = parent.getClass().getName(); 178 } 179 180 } 181 182 ((ProfileRange) m_range).setAllowedPropertyParents(ohPaths); 183 } catch (DataAccessException e) { 184 throw new WebDAVException( 185 WebDAVStatus.SC_INTERNAL_SERVER_ERROR, 186 e.getLocalizedMessage()); 187 } catch (NameResolverException e) { 188 throw new WebDAVException( 189 WebDAVStatus.SC_INTERNAL_SERVER_ERROR, 190 e.getLocalizedMessage()); 191 } 192 193 } 194 195 } 196 | Popular Tags |