1 23 24 package org.apache.slide.webdav.method.report; 25 26 import java.io.IOException ; 27 import java.util.Iterator ; 28 import java.util.List ; 29 30 import org.apache.slide.common.NamespaceAccessToken; 31 import org.apache.slide.common.RequestedProperties; 32 import org.apache.slide.common.ServiceAccessException; 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.NodeRevisionNumber; 37 import org.apache.slide.content.NodeProperty.NamespaceCache; 38 import org.apache.slide.search.Search; 39 import org.apache.slide.security.Security; 40 import org.apache.slide.structure.Structure; 41 import org.apache.slide.webdav.WebdavServletConfig; 42 import org.apache.slide.webdav.util.AclConstants; 43 import org.apache.slide.webdav.util.DeltavConstants; 44 import org.apache.slide.webdav.util.PreconditionViolationException; 45 import org.apache.slide.webdav.util.PropertyRetriever; 46 import org.apache.slide.webdav.util.PropertyRetrieverImpl; 47 import org.apache.slide.webdav.util.WebdavStatus; 48 import org.apache.slide.webdav.util.WebdavUtils; 49 import org.jdom.Element; 50 import org.jdom.Namespace; 51 52 53 57 public abstract class AbstractReport implements DeltavConstants, AclConstants { 58 59 protected static final Namespace DNSP = NamespaceCache.DEFAULT_NAMESPACE; 60 protected static final String HTTP_VERSION = "HTTP/1.1"; 61 62 protected SlideToken slideToken; 63 protected NamespaceAccessToken token; 64 protected WebdavServletConfig config; 65 protected String slideContextPath; 66 protected Structure structure; 67 protected Content content; 68 protected Security security; 69 protected Search search; 70 protected PropertyRetriever retriever; 71 72 82 public AbstractReport(SlideToken slideToken, NamespaceAccessToken token, WebdavServletConfig config, String slideContextPath) { 83 this.slideToken = slideToken; 84 this.token = token; 85 this.config = config; 86 this.slideContextPath = slideContextPath; 87 this.structure = token.getStructureHelper(); 88 this.content = token.getContentHelper(); 89 this.security = token.getSecurityHelper(); 90 this.search = token.getSearchHelper(); 91 this.retriever = new PropertyRetrieverImpl(token, slideToken, config); 92 } 93 94 102 public abstract void init(String resourcePath, Element reportElm) throws PreconditionViolationException; 103 104 115 public abstract void execute(String resourcePath, Element multistatusElm, int depth) throws SlideException, IOException ; 116 117 124 public void checkPreconditions(String resourcePath, int depth) throws PreconditionViolationException, ServiceAccessException { 125 } 127 128 protected Element getResponseElement(SlideToken slideToken, String resourcePath, NodeRevisionNumber revisionNumber, RequestedProperties requestedProperties) { 129 130 Element responseElm = new Element(E_RESPONSE, DNSP); 131 Element hrefElm = new Element(E_HREF, DNSP); 132 133 String absUri = WebdavUtils.getAbsolutePath (resourcePath, slideContextPath, config); 134 hrefElm.setText (absUri); 135 responseElm.addContent(hrefElm); 136 137 try { 138 List propstatList = retriever.getPropertiesOfObject(requestedProperties, 139 resourcePath, 140 revisionNumber, 141 slideContextPath, 142 true); 143 Iterator iterator = propstatList.iterator(); 144 while (iterator.hasNext()) { 145 responseElm.addContent((Element)iterator.next()); 146 } 147 } 148 catch (Exception e) { 149 responseElm = getErrorResponse(resourcePath, WebdavUtils.getErrorCode(e), null); 150 } 151 return responseElm; 152 } 153 154 protected Element getErrorResponse(String resourcePath, int statusCode, String condition) { 155 156 Element responseElm = new Element(E_RESPONSE, DNSP); 157 158 Element hrefElm = new Element(E_HREF, DNSP); 159 hrefElm.setText(WebdavUtils.getAbsolutePath (resourcePath, slideContextPath, config)); 160 responseElm.addContent(hrefElm); 161 Element propStatElm = new Element(E_PROPSTAT, DNSP); 162 responseElm.addContent(propStatElm); 163 164 Element statusElm = new Element(E_STATUS, DNSP); 165 statusElm.setText(HTTP_VERSION+" "+statusCode+" "+WebdavStatus.getStatusText(statusCode)); 166 propStatElm.addContent(statusElm); 167 168 if (condition != null) { 169 Element responseDescriptiont = new Element(E_RESPONSEDESCRIPTION, DNSP); 170 Element errorElm = new Element(E_ERROR, DNSP); 171 responseDescriptiont.addContent(errorElm); 172 Element conditionElm = new Element(condition, DNSP); 173 errorElm.addContent(conditionElm); 174 propStatElm.addContent(responseDescriptiont); 175 } 176 return responseElm; 177 } 178 } 179 180 | Popular Tags |