1 39 40 package org.apache.slide.webdav.method.report; 41 42 import org.apache.slide.common.*; 43 import org.apache.slide.webdav.WebdavServletConfig; 44 import org.apache.slide.webdav.util.AclConstants; 45 import org.apache.slide.webdav.util.PreconditionViolationException; 46 import org.apache.slide.webdav.util.ViolatedPrecondition; 47 import org.apache.slide.webdav.util.WebdavStatus; 48 import org.apache.slide.webdav.util.resourcekind.PrincipalImpl; 49 import org.jdom.Element; 50 51 import java.io.IOException ; 52 import java.util.Iterator ; 53 54 55 59 public class PrincipalSearchPropertySetReport extends AbstractReport implements AclConstants { 60 61 70 public PrincipalSearchPropertySetReport(SlideToken slideToken, NamespaceAccessToken token, WebdavServletConfig config, String slideContextPath) { 71 super(slideToken, token, config, slideContextPath); 72 } 73 74 82 public void init(String resourcePath, Element principalSearchPropertySetElm) throws PreconditionViolationException { 83 if (principalSearchPropertySetElm.getChildren().size() > 0) { 84 throw new PreconditionViolationException( 85 new ViolatedPrecondition("empty-principal-search-property-set-element", 86 WebdavStatus.SC_BAD_REQUEST, 87 "DAV:principal-search-property-set element must be empty"), 88 resourcePath 89 ); 90 } 91 } 92 93 103 public void execute(String resourcePath, Element principalSearchPropertySetElm, int depth) throws SlideException, IOException { 104 Iterator props = retriever.getAllPropertyNames(PrincipalImpl.getInstance()) 105 .getRequestedProperties(); 106 while (props.hasNext()) { 107 RequestedProperty p = (RequestedProperty)props.next(); 108 Element principalSearchPropertyElm = new Element(E_PRINCIPAL_SEARCH_PROPERTY, DNSP); 109 Element propElm = new Element("prop", DNSP); 110 principalSearchPropertyElm.addContent(propElm); 111 propElm.addContent(new Element(p.getName(), p.getNamespace())); 112 Element descriptionElm = new Element("description", DNSP); 113 principalSearchPropertyElm.addContent(descriptionElm); 114 descriptionElm.setText(p.getName()); 115 principalSearchPropertySetElm.addContent(principalSearchPropertyElm); 116 } 117 } 118 119 126 public void checkPreconditions(String resourcePath, int depth) throws PreconditionViolationException, ServiceAccessException { 127 if (depth != 0) { 128 throw new PreconditionViolationException( 129 new ViolatedPrecondition("depth-must-be-zero", 130 WebdavStatus.SC_BAD_REQUEST, 131 "This report is only defined for depth=0."), 132 resourcePath 133 ); 134 } 135 UriPath resourcepath = new UriPath(resourcePath); 136 NamespaceConfig namespaceConfig = token.getNamespaceConfig(); 137 UriPath userspath = namespaceConfig.getUsersPath() != null 138 ? new UriPath(namespaceConfig.getUsersPath()) 139 : null; 140 UriPath groupspath = namespaceConfig.getGroupsPath() != null 141 ? new UriPath(namespaceConfig.getGroupsPath()) 142 : null; 143 UriPath rolespath = namespaceConfig.getRolesPath() != null 144 ? new UriPath(namespaceConfig.getRolesPath()) 145 : null; 146 if (!resourcepath.equals(userspath) && 147 !resourcepath.equals(groupspath) && 148 !resourcepath.equals(rolespath)) { 149 throw new PreconditionViolationException( 150 new ViolatedPrecondition("valid-request-uri", 151 WebdavStatus.SC_BAD_REQUEST, 152 "This report is only defined for one of the collections identified in the value of the DAV:principal-collection-set property."), 153 resourcePath 154 ); 155 } 156 } 157 } 158 | Popular Tags |