juergen 02/03/17 23:29:58
Modified: src/webdav/server/org/apache/slide/webdav/method
ReportMethod.java
Log:
added acl-principal-props Report (Eckehard)
Revision Changes Path
1.8 +192 -7
jakarta-slide/src/webdav/server/org/apache/slide/webdav/method/ReportMethod.java
Index: ReportMethod.java
===================================================================
RCS file:
/home/cvs/jakarta-slide/src/webdav/server/org/apache/slide/webdav/method/ReportMethod.java,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- ReportMethod.java 13 Mar 2002 09:28:46 -0000 1.7
+++ ReportMethod.java 18 Mar 2002 07:29:58 -0000 1.8
@@ -1,7 +1,7 @@
/*
- * $Header:
/home/cvs/jakarta-slide/src/webdav/server/org/apache/slide/webdav/method/ReportMethod.java,v
1.7 2002/03/13 09:28:46 juergen Exp $
- * $Revision: 1.7 $
- * $Date: 2002/03/13 09:28:46 $
+ * $Header:
/home/cvs/jakarta-slide/src/webdav/server/org/apache/slide/webdav/method/ReportMethod.java,v
1.8 2002/03/18 07:29:58 juergen Exp $
+ * $Revision: 1.8 $
+ * $Date: 2002/03/18 07:29:58 $
*
* ====================================================================
*
@@ -76,6 +76,7 @@
import java.util.Iterator;
import java.util.StringTokenizer;
import java.util.NoSuchElementException;
+import java.util.HashSet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
@@ -98,6 +99,8 @@
import org.apache.slide.webdav.WebdavException;
import org.apache.slide.webdav.WebdavServletConfig;
import org.apache.slide.webdav.util.DeltavConstants;
+import org.apache.slide.webdav.util.AclConstants;
+import org.apache.slide.webdav.util.PropertyHelper;
import org.apache.slide.structure.ObjectNode;
import org.apache.slide.structure.LinkedObjectNotFoundException;
@@ -122,7 +125,7 @@
import org.apache.slide.search.BadQueryException;
import org.apache.slide.util.Configuration;
-
+import org.apache.slide.webdav.util.VersioningHelper;
import org.apache.slide.webdav.util.PropertyRetriever;
import org.apache.slide.webdav.util.PropertyRetrieverImpl;
import org.apache.slide.webdav.util.UriHandler;
@@ -142,11 +145,11 @@
/**
* An implementation of the DeltaV <code>REPORT</code> method.
*
- * @version $Revision: 1.7 $
+ * @version $Revision: 1.8 $
*
* @author <a href="mailto:[EMAIL PROTECTED]">Ralf Stuckert</a>
*/
-public class ReportMethod extends WebdavMethod implements DeltavConstants {
+public class ReportMethod extends WebdavMethod implements DeltavConstants,
AclConstants {
/**
* String constant for <code>text/xml</code>.
@@ -173,7 +176,20 @@
*/
public static final String PROPERTY_LIST = "propertylist";
+ /**
+ * String constant for <code>property</code>.
+ */
+ public static final String PROPERTY = "property";
+ /**
+ * String constant for <code>prop</code>.
+ */
+ public static final String PROP_ELEMENT = "prop";
+
+ /**
+ * String constant for <code>name</code>.
+ */
+ public static final String PARAM_NAME = "name";
/**
** The SAXBuilder used to create JDOM Documents.
@@ -213,6 +229,11 @@
*/
protected Element expandPropertyElement = null;
+ /**
+ * The list of requested properties for the <code>acl-principal</code> report.
+ */
+ protected RequestedProperties requestedAclPrincipalProperties = null;
+
@@ -248,7 +269,10 @@
try{
retrieveRequestContent();
- Element element = getRequestContent().getRootElement();
+ // check if Report request contains a content
+ Document content = getRequestContent();
+ Element element = content.getRootElement();
+
if (element == null) {
throw new WebdavException(WebdavStatus.SC_BAD_REQUEST);
}
@@ -261,6 +285,10 @@
requestedReport = R_EXPAND_PROPERTY;
parseExpandPropertyRequest(element);
}
+ else if (element.getName().equalsIgnoreCase(R_ACL_PRINCIPAL_PROPS)){
+ requestedReport = R_ACL_PRINCIPAL_PROPS;
+ parseACLPrincipalRequest(element);
+ }
// TODO
// locate-by-history report
else{
@@ -304,6 +332,31 @@
}
/**
+ * Parses the <code><acl-principal></code> request.
+ *
+ * @param aclPrincipalElement the <code><acl-principal></code>
+ * Element.
+ *
+ * @throws WebdavException if parsing fails for any reason.
+ */
+ protected void parseACLPrincipalRequest(Element aclPrincipalElement) throws
WebdavException {
+
+ List childrenList = aclPrincipalElement.getChildren();
+ if (childrenList.size() == 0) {
+ throw new WebdavException(WebdavStatus.SC_BAD_REQUEST);
+ }
+
+ Element element = (Element)childrenList.get(0);
+
+ if ( E_ALLPROP.equals(element.getName()) ||
E_PROP.equals(element.getName()) ) {
+ requestedAclPrincipalProperties = new RequestedPropertiesImpl(element);
+ }
+ else {
+ throw new WebdavException(WebdavStatus.SC_BAD_REQUEST);
+ }
+ }
+
+ /**
* Parses the <code><expand-property></code> request.
*
* @param expandPropertyElement the <code><expand-property></code>
@@ -339,6 +392,9 @@
else if (R_EXPAND_PROPERTY.equals(requestedReport)) {
executeExpandPropertyReport(requestUri, multistatusElement,
getDepth());
}
+ else if (R_ACL_PRINCIPAL_PROPS.equals(requestedReport)) {
+ executeAclPrincipalReport(requestUri, multistatusElement,
getDepth());
+ }
new XMLOutputter().output(multistatusElement,
getResponse().getWriter());
}
@@ -569,6 +625,135 @@
protected void executeExpandPropertyReport(String requestUri, Element
parentElement, int depth) throws WebdavException, ObjectLockedException,
RevisionDescriptorNotFoundException, ServiceAccessException,
LinkedObjectNotFoundException, AccessDeniedException, ObjectNotFoundException,
JDOMException {
List requestedPropertyElementList =
expandPropertyElement.getChildren(E_PROPERTY,
Namespace.getNamespace(DEFAULT_NAMESPACE));
writeExpandPropertyReport(requestUri, parentElement,
requestedPropertyElementList);
+ }
+
+ /**
+ * Executes a requested <code>acl-principal</code> report.
+ *
+ * @param requestUri the URI of the requested resource.
+ * @param parentElement the parent Element to append the
+ * <response></code> to.
+ *
+ * @throws WebdavException
+ * @throws ObjectLockedException
+ * @throws RevisionDescriptorNotFoundException
+ * @throws ServiceAccessException
+ * @throws LinkedObjectNotFoundException
+ * @throws AccessDeniedException
+ * @throws ObjectNotFoundException
+ * @throws JDOMException
+ */
+ protected void executeAclPrincipalReport(String requestUri, Element
parentElement, int depth) throws WebdavException, ObjectLockedException,
RevisionDescriptorNotFoundException, ServiceAccessException,
LinkedObjectNotFoundException, AccessDeniedException, ObjectNotFoundException,
JDOMException {
+ NodeRevisionDescriptors revisionDescriptors = null;
+ NodeRevisionDescriptor revisionDescriptor = null;
+ NodeRevisionNumber revisionNumber = null;
+ PropertyRetrieverImpl retriever = new PropertyRetrieverImpl(token,
slideToken);
+ String serverURL = HTTP_PROTOCOL + req.getServerName()+ ":" +
req.getServerPort();
+ List propstatList = null;
+ Element aclprops = null;
+ Element aclpropstat = null;
+ Element acl = null;
+ List aces = null;
+ HashSet principals = new HashSet();
+
+ // get acl
+
+ // create virtuel ACL property object
+ Element aclproperty = new Element(PROPERTY,DEFAULT_NAMESPACE);
+ aclproperty.addAttribute(PARAM_NAME,P_ACL);
+ Element prop = new Element(PROP_ELEMENT,DEFAULT_NAMESPACE);
+ prop.addContent(aclproperty);
+ RequestedPropertiesImpl reqProperties = new RequestedPropertiesImpl(prop);
+
+ // get NodeRevisionDescriptor
+ try {
+ VersioningHelper vHelp = VersioningHelper.getVersioningHelper(
+ slideToken, token, req, resp, getRequestContent(), getConfig() );
+
+ if( !Configuration.useVersionControl() ) {
+ revisionDescriptors =
+ content.retrieve(slideToken, resourcePath);
+ }
+ else {
+ revisionDescriptors =
vHelp.retrieveRevisionDescriptors(resourcePath);
+ }
+
+ try {
+ if( !Configuration.useVersionControl() ) {
+ revisionDescriptor = content.retrieve(slideToken,
revisionDescriptors);
+ }
+ else {
+ revisionDescriptor =
vHelp.retrieveLatestRevisionDescriptor(resourcePath, revisionDescriptors);
+ }
+
+ } catch (RevisionDescriptorNotFoundException e) {
+
+ // The object doesn't have any revision, we create a dummy
+ // NodeRevisionDescriptor object
+ revisionDescriptor = new NodeRevisionDescriptor(0);
+
+ String resourceName = requestUri;
+ int lastSlash = resourceName.lastIndexOf('/');
+ if (lastSlash != -1)
+ resourceName = resourceName.substring(lastSlash + 1);
+ revisionDescriptor.setName(resourceName);
+ }
+ } catch (AccessDeniedException e) {
+ if (revisionDescriptor == null) {
+ revisionDescriptor = new NodeRevisionDescriptor(0);
+ }
+ } catch (Exception e) {
+ resp.setStatus(WebdavStatus.SC_INTERNAL_SERVER_ERROR);
+ throw new WebdavException
+ (WebdavStatus.SC_INTERNAL_SERVER_ERROR);
+ }
+
+ // get the ACL of the current resource
+ try {
+ propstatList = retriever.getPropertiesOfObject(reqProperties,
revisionDescriptors, revisionDescriptor, req.getContextPath(), serverURL, true);
+ }catch (SlideException e) {
+ resp.setStatus(getErrorCode(e));
+ throw new WebdavException
+ (getErrorCode(e));
+ }
+ if (propstatList.size() != 1) {
+ resp.setStatus(WebdavStatus.SC_INTERNAL_SERVER_ERROR);
+ throw new WebdavException
+ (WebdavStatus.SC_INTERNAL_SERVER_ERROR);
+ }
+
+ Iterator iterator = propstatList.iterator();
+ aclpropstat = ((Element)iterator.next());
+ aclprops = aclpropstat.getChild(PROP_ELEMENT,
Namespace.getNamespace(DEFAULT_NAMESPACE));
+
+ if (aclprops != null) {
+ acl = aclprops.getChild(P_ACL,
Namespace.getNamespace(DEFAULT_NAMESPACE));
+ } else return;
+
+ if (aclprops != null) {
+ acl = aclprops.getChild(P_ACL,
Namespace.getNamespace(DEFAULT_NAMESPACE));
+ } else return;
+
+ aces = acl.getChildren(P_ACE, Namespace.getNamespace(DEFAULT_NAMESPACE));
+
+ // get Principals
+ Iterator aceIter = aces.iterator();
+ Element current = null;
+
+ while (aceIter.hasNext()) {
+ current = ((Element) aceIter.next()).getChild(K_PRINCIPAL,
Namespace.getNamespace(DEFAULT_NAMESPACE)).getChild("href",
Namespace.getNamespace(DEFAULT_NAMESPACE));
+ if (current != null){
+ principals.add(current.getText());
+ }
+ }
+
+ // get principal properties and write responce
+ Iterator principalIter = principals.iterator();
+ while (principalIter.hasNext()) {
+ String principalUrl =
((String)principalIter.next()).substring(token.getNamespaceConfig().toString().length()+1);
+ Element response = getResponseElement(principalUrl,
revisionDescriptors, revisionNumber, slideToken, principalUrl,
requestedAclPrincipalProperties);
+ parentElement.addContent((Element) response);
+ }
}
/**
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>