1 23 24 package org.apache.slide.webdav.method.report; 25 26 import java.io.IOException ; 27 import java.util.ArrayList ; 28 import java.util.Enumeration ; 29 import java.util.Iterator ; 30 import java.util.List ; 31 32 import org.apache.slide.common.NamespaceAccessToken; 33 import org.apache.slide.common.PropertyParseException; 34 import org.apache.slide.common.RequestedProperties; 35 import org.apache.slide.common.RequestedPropertiesImpl; 36 import org.apache.slide.common.SlideException; 37 import org.apache.slide.common.SlideToken; 38 import org.apache.slide.content.NodeRevisionDescriptor; 39 import org.apache.slide.content.NodeRevisionDescriptors; 40 import org.apache.slide.structure.ObjectNode; 41 import org.apache.slide.webdav.WebdavServletConfig; 42 import org.apache.slide.webdav.util.DeltavConstants; 43 import org.apache.slide.webdav.util.PreconditionViolationException; 44 import org.apache.slide.webdav.util.WebdavUtils; 45 import org.jdom.Element; 46 import org.jdom.Namespace; 47 48 49 53 public class ExpandPropertyReport extends AbstractReport implements DeltavConstants { 54 55 private static final String PROPERTY_LIST = "propertylist"; 56 57 private List propertyElmList; 58 59 68 public ExpandPropertyReport(SlideToken slideToken, NamespaceAccessToken token, WebdavServletConfig config, String slideContextPath) { 69 super(slideToken, token, config, slideContextPath); 70 } 71 72 80 public void init(String resourcePath, Element expandPropertyElm) throws PreconditionViolationException { 81 this.propertyElmList = expandPropertyElm.getChildren(E_PROPERTY, DNSP); 82 } 83 84 94 public void execute(String resourcePath, Element multistatusElm, int depth) throws SlideException, IOException { 95 if (depth < 0) { 96 return; 97 } 98 writeReport( resourcePath, multistatusElm, propertyElmList ); 99 ObjectNode onode = structure.retrieve( slideToken, resourcePath ); 100 Enumeration childrenEnum = structure.getChildren( slideToken, onode ); 101 while( childrenEnum.hasMoreElements() ) { 102 ObjectNode cnode = (ObjectNode)childrenEnum.nextElement(); 103 execute(cnode.getUri(), multistatusElm, depth-1); 104 } 105 } 106 107 private void writeReport(String resourcePath, Element multistatusElm, List propertyElmList) { 108 109 try { 110 NodeRevisionDescriptors nrds = content.retrieve(slideToken, resourcePath); 111 NodeRevisionDescriptor nrd = content.retrieve(slideToken, nrds); 112 113 Element response = getResponseElement(slideToken, 114 resourcePath, 115 nrd.getRevisionNumber(), 116 createRequestedProperties(propertyElmList)); 117 118 multistatusElm.addContent(response); 119 120 Iterator iterator = propertyElmList.iterator(); 122 while (iterator.hasNext()) { 123 Element propertyElement = (Element)iterator.next(); 124 List childPropertyList = propertyElement.getChildren(); 125 if (childPropertyList.size() > 0) { 126 try { 127 Namespace propertyNamespace = DNSP; 128 String propertyNamespaceStr = propertyElement.getAttributeValue("namespace"); 129 if( propertyNamespaceStr != null ) 130 propertyNamespace = Namespace.getNamespace(propertyNamespaceStr); 131 List hrefElements = response. 132 getChild(E_PROPSTAT, DNSP). 133 getChild(E_PROP, DNSP). 134 getChild(propertyElement.getAttribute("name").getValue(), propertyNamespace). 135 getChildren(E_HREF, DNSP); 136 Iterator hrefs = new ArrayList (hrefElements).iterator(); 137 while( hrefs.hasNext() ) { 138 Element hrefElement = (Element)hrefs.next(); 139 if (hrefElement.getText() != null) { 140 writeReport( 142 WebdavUtils.getSlidePath(hrefElement.getTextTrim(), 143 slideContextPath), 144 (Element)hrefElement.getParent(), 145 childPropertyList); 146 hrefElement.getParent().removeContent(hrefElement); 147 } 148 } 149 } 150 catch (NullPointerException e) { 151 } 153 } 154 } 155 } 156 catch (Exception e) { 157 multistatusElm.addContent(getErrorResponse(resourcePath, WebdavUtils.getErrorCode(e), null)); 158 } 159 } 160 161 private RequestedProperties createRequestedProperties(List propertyElements) throws PropertyParseException { 162 163 Element propertyListElement = new Element(PROPERTY_LIST); 164 Iterator iterator = propertyElements.iterator(); 165 while (iterator.hasNext()) { 166 propertyListElement.addContent((Element)((Element)iterator.next()).clone()); 167 } 168 return new RequestedPropertiesImpl(propertyListElement); 169 } 170 } 171 172 | Popular Tags |