juergen 02/03/14 21:41:28
Modified: src/webdav/server/org/apache/slide/webdav/method
PropFindMethod.java
Log:
Refactored PropfinfMethod to make use of the PropertyRetriever in order to have a
common code-base for all methods dealing with properties (currently ReportMethod,
SearchMethod and PropfindMethod).
(ralf)
Revision Changes Path
1.51 +195 -1257
jakarta-slide/src/webdav/server/org/apache/slide/webdav/method/PropFindMethod.java
Index: PropFindMethod.java
===================================================================
RCS file:
/home/cvs/jakarta-slide/src/webdav/server/org/apache/slide/webdav/method/PropFindMethod.java,v
retrieving revision 1.50
retrieving revision 1.51
diff -u -r1.50 -r1.51
--- PropFindMethod.java 1 Mar 2002 16:46:26 -0000 1.50
+++ PropFindMethod.java 15 Mar 2002 05:41:27 -0000 1.51
@@ -1,7 +1,7 @@
/*
- * $Header:
/home/cvs/jakarta-slide/src/webdav/server/org/apache/slide/webdav/method/PropFindMethod.java,v
1.50 2002/03/01 16:46:26 pnever Exp $
- * $Revision: 1.50 $
- * $Date: 2002/03/01 16:46:26 $
+ * $Header:
/home/cvs/jakarta-slide/src/webdav/server/org/apache/slide/webdav/method/PropFindMethod.java,v
1.51 2002/03/15 05:41:27 juergen Exp $
+ * $Revision: 1.51 $
+ * $Date: 2002/03/15 05:41:27 $
*
* ====================================================================
*
@@ -70,7 +70,6 @@
import javax.servlet.http.*;
import javax.xml.parsers.ParserConfigurationException;
-import org.w3c.dom.*;
import org.xml.sax.SAXException;
import org.apache.util.XMLPrinter;
@@ -86,22 +85,45 @@
import org.apache.slide.security.Security;
import org.apache.slide.webdav.util.VersioningHelper;
import org.apache.slide.webdav.util.WebdavUtils;
+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.webdav.util.PropertyRetriever;
+import org.apache.slide.webdav.util.PropertyRetrieverImpl;
+import org.apache.slide.webdav.util.resourcekind.AbstractResourceKind;
+import org.apache.slide.webdav.util.resourcekind.ResourceKind;
import org.apache.slide.util.Configuration;
+import org.jdom.Element;
+import org.jdom.Document;
+import org.jdom.Namespace;
+import org.jdom.JDOMException;
+
+import org.jdom.input.DOMBuilder;
+import org.jdom.input.SAXBuilder;
+
+import org.jdom.output.XMLOutputter;
+
/**
* PROPFIND method.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Remy Maucherat</a>
*/
-public class PropFindMethod extends WebdavMethod {
+public class PropFindMethod extends WebdavMethod implements DeltavConstants,
AclConstants {
// -------------------------------------------------------------- Constants
/**
- * Root node URI.
+ * String constant for <code>http://</code>.
*/
- protected static final String DIRECTORY = "/";
+ public static final String HTTP_PROTOCOL = "http://";
+
+ /**
+ * String constant for <code>HTTP/1.1</code>.
+ */
+ public static final String HTTP_VERSION = "HTTP/1.1";
+
/**
@@ -128,129 +150,6 @@
protected static final int FIND_PROPERTY_NAMES = 2;
- /**
- * Supported locks property value.
- */
- protected static final String SUPPORTED_LOCK = "<lockentry>"
- + "<lockscope><exclusive/></lockscope>"
- + "<locktype><write/></locktype>"
- + "</lockentry>"
- + "<lockentry>"
- + "<lockscope><shared/></lockscope>"
- + "<locktype><write/></locktype>"
- + "</lockentry>";
-
-
- /**
- * Supported privilege set.
- */
- protected static final String SUPPORTED_PRIVILEGE_SET =
- "supported-privilege-set";
-
-
- /**
- * Supported privileges.
- */
- protected static final String SUPPORTED_PRIVILEGES =
- "<supported-privilege>"
- + "<privilege><all/></privilege>"
- + "<description>Any operation</description>"
- + "<supported-privilege>"
- + "<privilege><read/></privilege>"
- + "<description>Read any object</description>"
- + "</supported-privilege>"
- + "<supported-privilege>"
- + "<privilege><write/></privilege>"
- + "<description>Write any object</description>"
- + "</supported-privilege>"
- + "<supported-privilege>"
- + "<privilege><read-acl/></privilege>"
- + "<description>Read the ACL</description>"
- + "</supported-privilege>"
- + "<supported-privilege>"
- + "<privilege><write-acl/></privilege>"
- + "<description>Write the ACL</description>"
- + "</supported-privilege>"
- + "</supported-privilege>";
-
-
- /**
- * ACL semantics.
- */
- protected static final String SLIDE_ACL_SEMANTICS =
- "<ace-combination><all-grant-before-any-deny/></ace-combination>"
- + "<required-principal><all/></required-principal>";
-
-
- /**
- * Owner.
- */
- protected static final String OWNER =
- "owner";
-
-
- /**
- * Current user privilege set.
- */
- protected static final String CURRENT_USER_PRIVILEGE_SET =
- "current-user-privilege-set";
-
-
- /**
- * Principal collection set.
- */
- protected static final String PRINCIPAL_COLLECTION_SET =
- "principal-collection-set";
-
-
- /**
- * ACL semantics.
- */
- protected static final String ACL_SEMANTICS = "acl-semantics";
-
-
- /**
- * ACL.
- */
- protected static final String ACL = "acl";
-
-
- /**
- * ACE.
- */
- protected static final String ACE = "ace";
-
-
- /**
- * GRANT.
- */
- protected static final String GRANT = "grant";
-
-
- /**
- * DENY.
- */
- protected static final String DENY = "deny";
-
-
- /**
- * PRINCIPAL.
- */
- protected static final String PRINCIPAL = "principal";
-
-
- /**
- * PRIVILEGE.
- */
- protected static final String PRIVILEGE = "privilege";
-
-
- /**
- * INHERITED.
- */
- protected static final String INHERITED = "inherited";
-
-
// ----------------------------------------------------- Instance Variables
@@ -266,22 +165,21 @@
protected int propFindType;
- /**
- * Properties to display
- */
- protected Vector propertyVector;
+ /**
+ ** The SAXBuilder used to create JDOM Documents.
+ **/
+ protected static SAXBuilder saxBuilder = null;
/**
- * Current namespace number used to generate namespace abbreviations.
+ * The list of requested properties.
*/
- protected int namespaceNumber = 0;
-
+ protected RequestedProperties requestedProperties = null;
/**
- * Namespaces list. Keyed by namespace names.
+ * The request content (XML) Document.
*/
- protected HashMap namespaces;
+ protected Document requestContentDocument = null;
// ----------------------------------------------------------- Constructors
@@ -300,8 +198,6 @@
super(token, req, resp, config);
readRequestContent();
- namespaces = new HashMap();
- namespaces.put(SLIDE_NAMESPACE, SLIDE_NAMESPACE_ABBREV);
depth = INFINITY;
propFindType = FIND_ALL_PROP;
}
@@ -315,10 +211,65 @@
*
* @exception WebdavException Bad request
*/
- protected void parseRequest()
- throws WebdavException {
+ protected void parseRequest() throws WebdavException {
+
+ retrieveDepth();
+
+ if (req.getContentLength() == 0) {
+ requestedProperties = new RequestedPropertiesImpl();
+ propFindType = FIND_BY_PROPERTY;
+ }
+ else {
+
+ try {
+ retrieveRequestContent();
+
+ Element element = getRequestContent().getRootElement();
+ if ( (element == null) || !
element.getName().equalsIgnoreCase(E_PROPFIND)) {
+ throw new WebdavException(WebdavStatus.SC_BAD_REQUEST);
+ }
+
+ element = (Element)element.getChildren().get(0);
+ if (element == null) {
+ throw new WebdavException(WebdavStatus.SC_BAD_REQUEST);
+ }
+
+ if (element.getName().equalsIgnoreCase(E_PROPNAME)){
+ propFindType = FIND_PROPERTY_NAMES;
+ }
+ else if ( element.getName().equalsIgnoreCase(E_PROP) ) {
+ requestedProperties = new RequestedPropertiesImpl(element);
+ propFindType = FIND_BY_PROPERTY;
+ }
+ else if ( element.getName().equalsIgnoreCase(E_ALLPROP) ) {
+ requestedProperties = new RequestedPropertiesImpl(element);
+ propFindType = FIND_ALL_PROP;
+ }
+ else {
+ throw new WebdavException(WebdavStatus.SC_BAD_REQUEST);
+ }
+
+ }
+ catch (IOException e){
+ e.printStackTrace();
+ throw new WebdavException(WebdavStatus.SC_INTERNAL_SERVER_ERROR);
+ }
+ catch (SAXException e){
+ e.printStackTrace();
+ throw new WebdavException(WebdavStatus.SC_INTERNAL_SERVER_ERROR);
+ }
+ catch (ParserConfigurationException e){
+ e.printStackTrace();
+ throw new WebdavException(WebdavStatus.SC_INTERNAL_SERVER_ERROR);
+ }
+ }
+ }
+
+ /**
+ * Retrieves the <code>Depth</code> header from the request.
+ */
+ private void retrieveDepth() {
- // parse Depth header
String depthStr = req.getHeader("Depth");
if (depthStr == null) {
depth = INFINITY;
@@ -343,103 +294,32 @@
if (depth > getConfig().getDepthLimit()) {
depth = getConfig().getDepthLimit();
}
-
- if (req.getContentLength() != 0) {
-
- Node propNode = null;
-
- try {
- Document document = parseRequestContent();
-
- // Get the root element of the document
- Element rootElement = document.getDocumentElement();
- NodeList childList = rootElement.getChildNodes();
-
- for (int i=0; i < childList.getLength(); i++) {
- Node currentNode = childList.item(i);
- switch (currentNode.getNodeType()) {
- case Node.TEXT_NODE:
- break;
- case Node.ELEMENT_NODE:
- if (currentNode.getNodeName().endsWith("prop")) {
- propFindType = FIND_BY_PROPERTY;
- propNode = currentNode;
- }
- if (currentNode.getNodeName().endsWith("propname")) {
- propFindType = FIND_PROPERTY_NAMES;
- }
- if (currentNode.getNodeName().endsWith("allprop")) {
- propFindType = FIND_ALL_PROP;
- }
- break;
- }
- }
- } catch (SAXException e) {
- resp.setStatus(WebdavStatus.SC_BAD_REQUEST);
- throw new WebdavException(WebdavStatus.SC_BAD_REQUEST);
- } catch (ParserConfigurationException e) {
- System.err.println(e.getMessage());
- resp.setStatus(WebdavStatus.SC_INTERNAL_SERVER_ERROR);
- throw new WebdavException
- (WebdavStatus.SC_INTERNAL_SERVER_ERROR);
- } catch (IOException e) {
- System.err.println(e.getMessage());
- e.printStackTrace();
- resp.setStatus(WebdavStatus.SC_INTERNAL_SERVER_ERROR);
- throw new WebdavException
- (WebdavStatus.SC_INTERNAL_SERVER_ERROR);
- }
-
- if (propFindType == FIND_BY_PROPERTY) {
- propertyVector = new Vector();
- NodeList childList = propNode.getChildNodes();
-
- for (int i=0; i < childList.getLength(); i++) {
- Node currentNode = childList.item(i);
- switch (currentNode.getNodeType()) {
- case Node.TEXT_NODE:
- break;
- case Node.ELEMENT_NODE:
- Property property = getProperty(currentNode);
- propertyVector.addElement(property);
- break;
- }
- }
-
- }
-
- }
-
}
-
/**
- * Parse the namespace info of a node name.
+ * Returns the request content (XML) Document.
*
- * @param node The DOM node to parse
- * @return The corresponding Property object
+ * @return the request content (XML) Document.
*/
- protected Property getProperty(Node node) {
-
- Property property = new Property();
-
- property.name = node.getLocalName();
- property.namespace = node.getNamespaceURI();
- if (property.namespace != null)
- generateNamespaceAbbreviation(property.namespace);
-
- return property;
-
+ protected Document getRequestContent() {
+ return requestContentDocument;
+ }
+
+ /**
+ * Retrieves the request content (XML) Document.
+ */
+ protected void retrieveRequestContent() throws ParserConfigurationException,
IOException, SAXException{
+ requestContentDocument = new DOMBuilder().build(parseRequestContent());
}
+
/**
* Execute the request.
*
* @exception WebdavException
*/
- protected void executeRequest()
- throws IOException, WebdavException {
+ protected void executeRequest() throws IOException, WebdavException {
resp.setStatus(WebdavStatus.SC_MULTI_STATUS);
@@ -468,16 +348,11 @@
resp.setContentType("text/xml; charset=UTF-8");
// Create multistatus object
- XMLPrinter generatedXML = new XMLPrinter(resp.getWriter());
-
- generatedXML.writeXMLHeader();
- generatedXML.writeElement(null, "multistatus"
- + generateNamespaceDeclarations(),
- XMLPrinter.OPENING);
+ Element multistatusElement = new Element(E_MULTISTATUS,
Namespace.getNamespace(DEFAULT_NAMESPACE));
if (resource != null) {
if (depth == 0) {
- parsePropertiesOfObject(resource, generatedXML);
+ multistatusElement.addContent(getPropertiesOfObject(resource));
} else {
// The stack always contains the object of the current level
Stack stack = new Stack();
@@ -488,11 +363,8 @@
while ((!stack.isEmpty()) && (depth >= 0)) {
- // Send partial response
- generatedXML.sendData();
-
ObjectNode cur = (ObjectNode) stack.pop();
- parsePropertiesOfObject(cur, generatedXML);
+ multistatusElement.addContent(getPropertiesOfObject(cur));
if (depth > 0) {
@@ -521,29 +393,25 @@
}
}
- generatedXML.writeElement(null, "multistatus",
- XMLPrinter.CLOSING);
-
- // Send remaining data
- generatedXML.sendData();
-
+ new XMLOutputter().output(multistatusElement, resp.getWriter());
}
/**
- * Parse properties of an object.
+ * Return the properties of an object as a <code><response></code>.
*
* @param object
- * @param multistatus
+ *
+ * @return the <code><response></code> Element.
+ *
* @exception WebdavException
*/
- protected void parsePropertiesOfObject(ObjectNode object,
- XMLPrinter generatedXML)
+ protected Element getPropertiesOfObject(ObjectNode object)
throws WebdavException {
- generatedXML.writeElement(null, "response", XMLPrinter.OPENING);
+ Element responseElement = new Element(E_RESPONSE,
Namespace.getNamespace(DEFAULT_NAMESPACE));
- String status = new String("HTTP/1.1 " + WebdavStatus.SC_OK + " "
+ String status = new String(HTTP_VERSION + WebdavStatus.SC_OK + " "
+ WebdavStatus.getStatusText
(WebdavStatus.SC_OK));
NodeRevisionDescriptors revisionDescriptors = null;
@@ -552,13 +420,11 @@
boolean isCollection = false;
NodeLock objectLockToken = null;
+ String serverURL = HTTP_PROTOCOL + req.getServerName()+ ":" +
req.getServerPort();
try {
- generatedXML.writeElement(null, "href", XMLPrinter.OPENING);
+ Element hrefElement = new Element(E_HREF,
Namespace.getNamespace(DEFAULT_NAMESPACE));
- // Changed for DeltaV --start--
-// revisionDescriptors =
-// content.retrieve(slideToken, object.getUri());
VersioningHelper vHelp = VersioningHelper.getVersioningHelper(
slideToken, token, req, resp, getConfig() );
String resourcePath = object.getUri();
@@ -568,15 +434,11 @@
content.retrieve(slideToken, resourcePath);
}
else {
- revisionDescriptors =
+ revisionDescriptors =
vHelp.retrieveRevisionDescriptors( resourcePath );
}
- // Changed for DeltaV --end--
try {
- // Changed for DeltaV --start--
-// revisionDescriptor = content.retrieve(slideToken,
-// revisionDescriptors);
if( !Configuration.useVersionControl() ) {
revisionDescriptor = content.retrieve(slideToken,
revisionDescriptors);
@@ -585,41 +447,12 @@
revisionDescriptor = vHelp.retrieveLatestRevisionDescriptor(
resourcePath, revisionDescriptors );
}
- // Changed for DeltaV --end--
isCollection = WebdavUtils.isCollection(revisionDescriptor);
String path = object.getUri();
- // String absoluteUri =
- // req.getRequestURI();
-//
- // System.out.println("getContextPath
"+req.getContextPath());
- // System.out.println("getRequestURI
"+req.getRequestURI());
- // System.out.println("getPathInfo
"+req.getPathInfo());
- // System.out.println("getPathTranslated
"+req.getPathTranslated());
- // System.out.println("getRealPath
"+req.getRealPath("xx"));
- // System.out.println("getRemoteAddr
"+req.getRemoteAddr());
- // System.out.println("getRemoteHost
"+req.getRemoteHost());
- // System.out.println("getServerName
"+req.getServerName());
- // System.out.println("getServletPath
"+req.getServletPath());
-//
- // String relativePath = requestUri;
- // String toAppend = "";
- // if (relativePath.length() <= path.length()) {
- // toAppend =
path.substring(relativePath.length());
- // if ((!absoluteUri.endsWith("/")) &&
- // (!toAppend.startsWith("/"))) {
- // toAppend = "/" + toAppend;
- // }
- // if (toAppend.equals("/")) {
- // toAppend = "";
- // }
- // }
-
- generatedXML.writeText(
- WebdavUtils.encodeURL(req.getContextPath() + path, "UTF-8"));
- // generatedXML.writeText(absoluteUri + toAppend);
+
hrefElement.setText(WebdavUtils.encodeURL(PropertyHelper.getAbsoluteURL(serverURL,
req.getContextPath(), path), "UTF-8"));
} catch (RevisionDescriptorNotFoundException e) {
@@ -636,29 +469,10 @@
String path = object.getUri();
- // String absoluteUri =
- // WebdavUtils.getRelativePath(req, getConfig());
- // String relativePath = requestUri;
- // String toAppend = "";
- // if (relativePath.length() <= path.length()) {
- // toAppend =
path.substring(relativePath.length());
- // if ((!absoluteUri.endsWith("/"))
- // && (!toAppend.startsWith("/"))) {
- // toAppend = "/" + toAppend;
- // }
- // }
-//
-
- generatedXML.writeText(
- WebdavUtils.encodeURL(req.getContextPath() + path, "UTF-8"));
-
- // generatedXML.writeText(
- // WebdavUtils.encodeURL(absoluteUri + toAppend,
"UTF-8"));
- // generatedXML.writeText(absoluteUri + toAppend);
-
+
hrefElement.setText(WebdavUtils.encodeURL(PropertyHelper.getAbsoluteURL(serverURL,
req.getContextPath(), path), "UTF-8"));
}
- generatedXML.writeElement(null, "href", XMLPrinter.CLOSING);
+ responseElement.addContent(hrefElement);
Enumeration lockTokens = lock.enumerateLocks(slideToken,
object.getUri(), true);
@@ -671,986 +485,110 @@
revisionDescriptor = new NodeRevisionDescriptor(0);
}
} catch (Exception e) {
- resp.setStatus(getErrorCode(e)); // no special handling needed
- throw new WebdavException(WebdavStatus.SC_INTERNAL_SERVER_ERROR); //
abort the TA
+ e.printStackTrace();
+ responseElement = getErrorResponse(object.getUri(), getErrorCode(e),
null);
}
Vector propertiesParser = null;
switch (propFindType) {
case FIND_ALL_PROP :
-
- // Show properties / values for current object.
- generatedXML.writeElement(null, "propstat",
- XMLPrinter.OPENING);
- generatedXML.writeElement(null, "prop", XMLPrinter.OPENING);
-
- status = new String("HTTP/1.1 " + WebdavStatus.SC_OK
- + " " + WebdavStatus.getStatusText
- (WebdavStatus.SC_OK));
-
- // Lock information, which is dynamically generated
- if (objectLockToken != null) {
- showLockDiscoveryInfo(objectLockToken, generatedXML);
- }
-
- // Supported locks
- generatedXML.writeElement(null, "supportedlock",
- XMLPrinter.OPENING);
- generatedXML.writeText(SUPPORTED_LOCK);
- generatedXML.writeElement(null, "supportedlock",
- XMLPrinter.CLOSING);
-
- // WebDAV ACL
- if( org.apache.slide.util.Configuration.useIntegratedSecurity() ) {
- showSupportedPrivilegeSet(generatedXML);
- showCurrentUserPrivilegeSet(object, generatedXML);
- showAcl(object, generatedXML);
- showAclSemantics(generatedXML);
- showPrincipalCollectionSet(generatedXML);
- }
-
- { // Owner property
- NodeProperty ownerProperty =
revisionDescriptor.getProperty(OWNER, NodeProperty.DEFAULT_NAMESPACE);
- String ownerHref;
- NamespaceConfig config = token.getNamespaceConfig();
- if ((ownerProperty != null) && (ownerProperty.getValue()!=null)
&&
- (!"".equals(ownerProperty.getValue().toString()))) {
- ownerHref=config.getUsersPath() + "/" +
ownerProperty.getValue().toString();
- }
- else {
- ownerHref=config.getUsersPath() + "/" +
config.getGuestPath();
- }
- generatedXML.writeElement(null, OWNER, XMLPrinter.OPENING);
- generatedXML.writeElement(null, "href", XMLPrinter.OPENING);
- generatedXML.writeText(WebdavUtils.encodeURL(ownerHref));
- generatedXML.writeElement(null, "href", XMLPrinter.CLOSING);
- generatedXML.writeElement(null, OWNER, XMLPrinter.CLOSING);
- }
-
-
- // Other properties
- Enumeration propertyList =
- revisionDescriptor.enumerateProperties();
-
- while (propertyList.hasMoreElements()) {
- NodeProperty currentProperty =
- (NodeProperty) propertyList.nextElement();
- if (currentProperty != null) {
- if ((OWNER.equals(currentProperty.getName())) &&
- (NodeProperty.DEFAULT_NAMESPACE.equals(
- currentProperty.getNamespace()))) {
- // skip owner property
- continue;
- }
- generateNamespaceAbbreviation(
- currentProperty.getNamespace());
-
- writeSingleProperty(generatedXML, currentProperty);
- }
+ case FIND_BY_PROPERTY :
+ try {
+ PropertyRetriever propertyRetriever = new
PropertyRetrieverImpl(token, slideToken);
+ List propstatList=
propertyRetriever.getPropertiesOfObject(requestedProperties, revisionDescriptors,
revisionDescriptor, req.getContextPath(), serverURL, false);
+ Iterator iterator = propstatList.iterator();
+ while (iterator.hasNext()) {
+ responseElement.addContent((Element)iterator.next());
+ }
+ } catch (Exception e) {
+ e.printStackTrace();
+ responseElement = getErrorResponse(object.getUri(),
getErrorCode(e), null);
}
-
- generatedXML.writeElement(null, "prop", XMLPrinter.CLOSING);
- generatedXML.writeProperty(null, "status", status);
- generatedXML.writeElement(null, "propstat",
- XMLPrinter.CLOSING);
-
break;
case FIND_PROPERTY_NAMES :
- // Show properties for current object.
-
status = new String("HTTP/1.1 " + WebdavStatus.SC_OK
+ " " + WebdavStatus.getStatusText
(WebdavStatus.SC_OK));
- generatedXML.writeElement(null, "propstat", XMLPrinter.OPENING);
- generatedXML.writeElement(null, "prop", XMLPrinter.OPENING);
-
- // Lock information
-
- generatedXML.writeElement(null, "lockdiscovery",
- XMLPrinter.NO_CONTENT);
- generatedXML.writeElement(null, "supportedlock",
- XMLPrinter.NO_CONTENT);
-
- // WebDAV ACL
- if( org.apache.slide.util.Configuration.useIntegratedSecurity() ) {
- generatedXML.writeElement(null, "owner", XMLPrinter.NO_CONTENT);
- generatedXML.writeElement(null, "supported-privilege-set",
- XMLPrinter.NO_CONTENT);
- generatedXML.writeElement(null, "current-user-privilege-set",
- XMLPrinter.NO_CONTENT);
- generatedXML.writeElement(null, "acl",
- XMLPrinter.NO_CONTENT);
- generatedXML.writeElement(null, ACL_SEMANTICS,
- XMLPrinter.NO_CONTENT);
- generatedXML.writeElement(null, PRINCIPAL_COLLECTION_SET,
- XMLPrinter.NO_CONTENT);
+ Element propstatElement = new Element(E_PROPSTAT,
Namespace.getNamespace(DEFAULT_NAMESPACE));
+ responseElement.addContent(propstatElement);
+ Element propElement = new Element(E_PROPSTAT,
Namespace.getNamespace(DEFAULT_NAMESPACE));
+ propstatElement.addContent(propElement);
+
+ ResourceKind resourceKind =
AbstractResourceKind.determineResourceKind(revisionDescriptor);
+ String[] filter = null;
+ if ( ! Configuration.useIntegratedSecurity() ) {
+ filter = new String[] {F_ACCESS_CONTROL};
}
+ Set propertySet = resourceKind.getSupportedLiveProperties(null,
filter);
// Then, add this resource's custom properties
- propertyList = revisionDescriptor.enumerateProperties();
-
+ Enumeration propertyList = revisionDescriptor.enumerateProperties();
while (propertyList.hasMoreElements()) {
NodeProperty currentProperty =
(NodeProperty) propertyList.nextElement();
if (currentProperty != null) {
- String namespace = currentProperty.getNamespace();
- generateNamespaceAbbreviation(namespace);
- String namespaceAbbrev =
- (String) namespaces.get(namespace);
- generatedXML.writeElement
- (namespaceAbbrev, namespace,
- currentProperty.getName(),
- XMLPrinter.NO_CONTENT);
+ propertySet.add(currentProperty.getName());
}
}
- generatedXML.writeElement(null, "prop", XMLPrinter.CLOSING);
- generatedXML.writeProperty(null, "status", status);
- generatedXML.writeElement(null, "propstat",
- XMLPrinter.CLOSING);
-
- break;
- case FIND_BY_PROPERTY :
- // Show requested properties value.
-
- propertyList = propertyVector.elements();
-
- generatedXML.writeElement(null, "propstat",
- XMLPrinter.OPENING);
- generatedXML.writeElement(null, "prop", XMLPrinter.OPENING);
-
- status = new String("HTTP/1.1 " + WebdavStatus.SC_OK
- + " " + WebdavStatus.getStatusText
- (WebdavStatus.SC_OK));
-
- Vector propertiesNotFoundVector = new Vector();
-
- while (propertyList.hasMoreElements()) {
- Property property = (Property) propertyList.nextElement();
- String propertyName = property.name;
- String propertyNamespace = property.namespace;
-
- // Lock information, dynamically generated
-
- if ((propertyName.equals("lockdiscovery")) &&
- (propertyNamespace.equals
- (NodeProperty.DEFAULT_NAMESPACE))) {
- // Return list of active locks ...
- if (objectLockToken != null) {
- showLockDiscoveryInfo(objectLockToken, generatedXML);
- }
- } else if ((propertyName.equals("supportedlock")) &&
- (propertyNamespace.equals
- (NodeProperty.DEFAULT_NAMESPACE))) {
- // Supported locks
- generatedXML.writeElement(null, "supportedlock",
- XMLPrinter.OPENING);
- generatedXML.writeText(SUPPORTED_LOCK);
- generatedXML.writeElement(null, "supportedlock",
- XMLPrinter.CLOSING);
- } else if ((propertyName.equals(OWNER)) &&
- (propertyNamespace.equals
- (NodeProperty.DEFAULT_NAMESPACE))) {
- NodeProperty ownerProperty =
revisionDescriptor.getProperty(OWNER, NodeProperty.DEFAULT_NAMESPACE);
- String ownerHref;
- NamespaceConfig config = token.getNamespaceConfig();
- if ((ownerProperty != null) &&
(ownerProperty.getValue()!=null) &&
- (!"".equals(ownerProperty.getValue().toString()))) {
- ownerHref=config.getUsersPath() + "/" +
ownerProperty.getValue().toString();
- }
- else {
- ownerHref=config.getUsersPath() + "/" +
config.getGuestPath();
- }
- generatedXML.writeElement(null, OWNER, XMLPrinter.OPENING);
- generatedXML.writeElement(null, "href", XMLPrinter.OPENING);
- generatedXML.writeText(WebdavUtils.encodeURL(ownerHref));
- generatedXML.writeElement(null, "href", XMLPrinter.CLOSING);
- generatedXML.writeElement(null, OWNER, XMLPrinter.CLOSING);
- } else if ((propertyName.equals(SUPPORTED_PRIVILEGE_SET)) &&
- (propertyNamespace.equals
- (NodeProperty.DEFAULT_NAMESPACE))) {
- // WebDAV ACL
- if(
org.apache.slide.util.Configuration.useIntegratedSecurity() )
- showSupportedPrivilegeSet(generatedXML);
- } else if ((propertyName.equals(CURRENT_USER_PRIVILEGE_SET)) &&
- (propertyNamespace.equals
- (NodeProperty.DEFAULT_NAMESPACE))) {
- if(
org.apache.slide.util.Configuration.useIntegratedSecurity() )
- showCurrentUserPrivilegeSet(object, generatedXML);
- } else if ((propertyName.equals("acl")) &&
- (propertyNamespace.equals
- (NodeProperty.DEFAULT_NAMESPACE))) {
- if(
org.apache.slide.util.Configuration.useIntegratedSecurity() )
- showAcl(object, generatedXML);
- } else if ((propertyName.equals(ACL_SEMANTICS)) &&
- (propertyNamespace.equals
- (NodeProperty.DEFAULT_NAMESPACE))) {
- if(
org.apache.slide.util.Configuration.useIntegratedSecurity() )
- showAclSemantics(generatedXML);
- } else if ((propertyName.equals(PRINCIPAL_COLLECTION_SET)) &&
- (propertyNamespace.equals
- (NodeProperty.DEFAULT_NAMESPACE))) {
- if(
org.apache.slide.util.Configuration.useIntegratedSecurity() )
- showPrincipalCollectionSet(generatedXML);
- } else {
-
- // Search in the custom properties
-
- NodeProperty currentProperty =
- revisionDescriptor.getProperty(propertyName,
- propertyNamespace);
- if (currentProperty != null) {
- writeSingleProperty(generatedXML, currentProperty);
- } else {
- propertiesNotFoundVector.addElement(property);
- }
- }
-
- }
-
- generatedXML.writeElement(null, "prop", XMLPrinter.CLOSING);
- generatedXML.writeProperty(null, "status", status);
- generatedXML.writeElement(null, "propstat",
- XMLPrinter.CLOSING);
-
- Enumeration propertiesNotFoundList =
- propertiesNotFoundVector.elements();
-
- if (propertiesNotFoundList.hasMoreElements()) {
-
- status = new String("HTTP/1.1 " + WebdavStatus.SC_NOT_FOUND
- + " " + WebdavStatus.getStatusText
- (WebdavStatus.SC_NOT_FOUND));
-
- generatedXML.writeElement(null, "propstat",
- XMLPrinter.OPENING);
- generatedXML.writeElement(null, "prop",
- XMLPrinter.OPENING);
-
- while (propertiesNotFoundList.hasMoreElements()) {
- Property propertyNotFound =
- (Property) propertiesNotFoundList.nextElement();
- String name = propertyNotFound.name;
- String namespace = propertyNotFound.namespace;
- String namespaceAbbrev =
- (String) namespaces.get(namespace);
- generatedXML.writeElement
- (namespaceAbbrev, null, name, XMLPrinter.NO_CONTENT);
- }
-
- generatedXML.writeElement(null, "prop",
- XMLPrinter.CLOSING);
- generatedXML.writeProperty(null, "status", status);
- generatedXML.writeElement(null, "propstat",
- XMLPrinter.CLOSING);
-
+ Iterator iterator = propertySet.iterator();
+ while (iterator.hasNext()) {
+ Element propertyElement = new
Element(iterator.next().toString(),
+
Namespace.getNamespace(DEFAULT_NAMESPACE));
+ propElement.addContent(propertyElement);
}
-
+ Element statusElement = new Element(E_STATUS,
Namespace.getNamespace(DEFAULT_NAMESPACE));
+ propElement.addContent(statusElement);
break;
}
- generatedXML.writeElement(null, "response", XMLPrinter.CLOSING);
-
- }
-
-
- // ------------------------------------------------------ Protected Methods
-
-
- /**
- * Write a single property including the value to the XML printer.
- *
- * @param generatedXML the output channel
- * @param currentProperty the property to be written to the output channel
- */
- private void writeSingleProperty(XMLPrinter generatedXML, NodeProperty
currentProperty) {
- if (currentProperty != null) {
- writeSingleProperty(generatedXML,
- currentProperty.getNamespace(),
- currentProperty.getName(),
- currentProperty.getValue());
- }
- }
-
- /**
- * Write a single property including the value to the XML printer.
- *
- * @param generatedXML the output channel
- * @param namespace the property namespace
- * @param propertyName the property Name
- * @param propertyValue the property Value
- */
- private void writeSingleProperty(XMLPrinter generatedXML,
- String namespace,
- String propertyName,
- Object propertyValue) {
- String namespaceAbbrev = (String) namespaces.get(namespace);
- if ((propertyValue == null) ||
- (propertyValue.toString().equals(""))) {
- generatedXML.writeElement
- (namespaceAbbrev, null, propertyName, XMLPrinter.NO_CONTENT);
- } else {
- generatedXML.writeElement
- (namespaceAbbrev, null, propertyName, XMLPrinter.OPENING);
- String currentPropertyString = propertyValue.toString();
- if (propertyName.equals("displayname") &&
- !currentPropertyString.startsWith("<![CDATA[") &&
- (currentPropertyString.indexOf("&") != -1||
- currentPropertyString.indexOf("<") != -1 )) {
- generatedXML.writeData(currentPropertyString);
- } else {
- generatedXML.writeText(currentPropertyString);
- }
- generatedXML.writeElement
- (namespaceAbbrev, null, propertyName, XMLPrinter.CLOSING);
- }
- }
-
-
- /**
- * Generate a namespace abbreviation for the given namespace.
- *
- * @param namespaceName Name of the namespace
- */
- protected void generateNamespaceAbbreviation(String namespaceName) {
-
- if (namespaces.get(namespaceName) != null)
- return;
-
- if (namespaceName.equals(NodeProperty.DEFAULT_NAMESPACE))
- return;
-
- String namespaceAbbrev = "ns" + namespaceNumber++;
- namespaces.put(namespaceName, namespaceAbbrev);
-
+ return responseElement;
}
-
/**
- * Generate namespace declaration attributes.
+ * Returns the appropriate <code><response></code> due to the given
+ * <code>exception</code> to the <code>generatedXML</code>
*
- * @return String namespace attributes
- */
- protected String generateNamespaceDeclarations() {
-
- StringBuffer result = new StringBuffer();
-
- result.append(" xmlns=\"").append(NodeProperty.DEFAULT_NAMESPACE)
- .append("\" ");
-
- Iterator namespaceList = namespaces.keySet().iterator();
- while (namespaceList.hasNext()) {
-
- String namespace = (String) namespaceList.next();
- String abbrev = (String) namespaces.get(namespace);
- result.append("xmlns:").append(abbrev).append("=\"")
- .append(namespace).append("\" ");
-
+ * @param requestUri the URI of the request to display in the
+ * <code><href></code> element.
+ * @param errorCode the HTTP error code.
+ * @param condition the condition that has been violated.
+ */
+ private Element getErrorResponse(String requestUri, int errorCode, String
condition) {
+
+ Element response = new Element(E_RESPONSE,
Namespace.getNamespace(DEFAULT_NAMESPACE));
+
+ Element href = new Element(E_HREF,
Namespace.getNamespace(DEFAULT_NAMESPACE));
+ href.setText(HTTP_PROTOCOL +
+ req.getServerName()+ ":" +
+ req.getServerPort() +
+ req.getContextPath() +
+ requestUri);
+ response.addContent(href);
+ Element propStat = new Element(E_PROPSTAT,
Namespace.getNamespace(DEFAULT_NAMESPACE));
+ response.addContent(propStat);
+
+ Element status = new Element(E_STATUS,
Namespace.getNamespace(DEFAULT_NAMESPACE));
+ status.setText(HTTP_VERSION + " " + errorCode + " " +
WebdavStatus.getStatusText(errorCode));
+ propStat.addContent(status);
+
+ if (condition != null) {
+ Element responseDescriptiont = new Element(E_RESPONSEDESCRIPTION,
Namespace.getNamespace(DEFAULT_NAMESPACE));
+ Element errorElement = new Element(E_ERROR,
Namespace.getNamespace(DEFAULT_NAMESPACE));
+ responseDescriptiont.addContent(errorElement);
+ Element conditionElement = new Element(condition,
Namespace.getNamespace(DEFAULT_NAMESPACE));
+ errorElement.addContent(conditionElement);
+ propStat.addContent(responseDescriptiont);
}
-
- return result.toString();
-
- }
-
-
- /**
- * Show lockdiscovery info.
- *
- * @exception WebdavException Something is wrong with the servlet container
- */
- protected void showLockDiscoveryInfo(NodeLock token,
- XMLPrinter generatedXML)
- throws WebdavException {
-
- generatedXML.writeElement(null, "lockdiscovery", XMLPrinter.OPENING);
-
- generatedXML.writeElement(null, "activelock", XMLPrinter.OPENING);
-
- generatedXML.writeElement(null, "locktype", XMLPrinter.OPENING);
- generatedXML.writeElement(null, "write", XMLPrinter.NO_CONTENT);
- generatedXML.writeElement(null, "locktype", XMLPrinter.CLOSING);
-
- generatedXML.writeElement(null, "lockscope", XMLPrinter.OPENING);
- if (token.isExclusive()) {
- generatedXML.writeElement(null, "exclusive",
- XMLPrinter.NO_CONTENT);
- } else {
- generatedXML.writeElement(null, "shared", XMLPrinter.NO_CONTENT);
- }
- generatedXML.writeElement(null, "lockscope", XMLPrinter.CLOSING);
-
- generatedXML.writeElement(null, "depth", XMLPrinter.OPENING);
- if (token.isInheritable()) {
- generatedXML.writeText("infinity");
- } else {
- generatedXML.writeText("0");
- }
- generatedXML.writeElement(null, "depth", XMLPrinter.CLOSING);
-
- generatedXML.writeElement(null, "owner", XMLPrinter.OPENING);
- /* We need to write this as data (i.e. a CDATA section) because
- * we don't know what the subjectUri (i.e. username) might
- * contain. The webdav RFC leaves us completely free to
- * put whatever we want inside the owner element.
- */
- generatedXML.writeText(getFullPath(token.getSubjectUri()));
-// generatedXML.writeData(token.getSubjectUri());
- generatedXML.writeElement(null, "owner", XMLPrinter.CLOSING);
-
- generatedXML.writeElement(null, "timeout", XMLPrinter.OPENING);
- generatedXML.writeText("Second-"
- + (new Long((token.getExpirationDate().getTime()
- - (new Date()).getTime())/1000))
- .toString());
- generatedXML.writeElement(null, "timeout", XMLPrinter.CLOSING);
-
- generatedXML.writeElement(null, "locktoken", XMLPrinter.OPENING);
- generatedXML.writeElement(null, "href", XMLPrinter.OPENING);
- // Put here the token Id
- boolean isOwner = false;
- try {
- String subjectUri = security.getPrincipal(slideToken).getUri();
- if (token.getSubjectUri().startsWith(subjectUri))
- isOwner = true;
- } catch (Exception e) {
- }
- if (isOwner || slideToken.checkLockToken(token.getLockId())) {
- generatedXML.writeText("opaquelocktoken:" + token.getLockId());
- } else {
- generatedXML.writeText("opaquelocktoken:faketoken");
- }
- generatedXML.writeElement(null, "href", XMLPrinter.CLOSING);
- generatedXML.writeElement(null, "locktoken", XMLPrinter.CLOSING);
-
- generatedXML.writeElement(null, "activelock", XMLPrinter.CLOSING);
-
- generatedXML.writeElement(null, "lockdiscovery", XMLPrinter.CLOSING);
-
- }
-
-
- /**
- * WebDAV ACL DAV:supported-privilege-set property.
- */
- protected void showSupportedPrivilegeSet(XMLPrinter generatedXML)
- throws WebdavException {
-
- generatedXML.writeElement(null, SUPPORTED_PRIVILEGE_SET,
- XMLPrinter.OPENING);
-
- // FIXME : Make the genaration dynamic (although it needs only to be
- // generated once). I suggest waiting for the DAV ACL spec final
- // version before implementing that.
- generatedXML.writeText(SUPPORTED_PRIVILEGES);
-
- generatedXML.writeElement(null, SUPPORTED_PRIVILEGE_SET,
- XMLPrinter.CLOSING);
-
- }
-
-
- /**
- * WebDAV ACL DAV:current-user-privilege-set property.
- */
- protected void showCurrentUserPrivilegeSet
- (ObjectNode object, XMLPrinter generatedXML)
- throws WebdavException {
-
- NamespaceConfig config = token.getNamespaceConfig();
-
- SubjectNode principalNode = null;
-
- try {
- principalNode = (SubjectNode) security.getPrincipal(slideToken);
- } catch (SlideException e) {
- return;
- } catch (ClassCastException e) {
- return;
- }
-
- try {
-
- boolean readObject =
- security.hasPermission(object, principalNode,
- config.getReadObjectAction());
- boolean createObject =
- security.hasPermission(object, principalNode,
- config.getCreateObjectAction());
- boolean removeObject =
- security.hasPermission(object, principalNode,
- config.getRemoveObjectAction());
- boolean grantPermission =
- security.hasPermission(object, principalNode,
- config.getGrantPermissionAction());
- boolean revokePermission =
- security.hasPermission(object, principalNode,
- config.getRevokePermissionAction());
- boolean readPermissions =
- security.hasPermission(object, principalNode,
- config.getReadPermissionsAction());
- boolean lockObject =
- security.hasPermission(object, principalNode,
- config.getLockObjectAction());
- boolean killLock =
- security.hasPermission(object, principalNode,
- config.getKillLockAction());
- boolean readLocks =
- security.hasPermission(object, principalNode,
- config.getReadLocksAction());
- boolean readRevisionMetadata =
- security.hasPermission(object, principalNode,
- config.getReadRevisionMetadataAction());
- boolean createRevisionMetadata = security.hasPermission
- (object, principalNode,
- config.getCreateRevisionMetadataAction());
- boolean modifyRevisionMetadata = security.hasPermission
- (object, principalNode,
- config.getModifyRevisionMetadataAction());
- boolean removeRevisionMetadata = security.hasPermission
- (object, principalNode,
- config.getRemoveRevisionMetadataAction());
- boolean readRevisionContent =
- security.hasPermission(object, principalNode,
- config.getReadRevisionContentAction());
- boolean createRevisionContent = security.hasPermission
- (object, principalNode,
- config.getCreateRevisionContentAction());
- boolean modifyRevisionContent = security.hasPermission
- (object, principalNode,
- config.getModifyRevisionContentAction());
- boolean removeRevisionContent = security.hasPermission
- (object, principalNode,
- config.getRemoveRevisionContentAction());
-
- boolean canRead = readObject && readRevisionMetadata
- && readRevisionContent;
- boolean canWrite = createObject && removeObject && lockObject
- && readLocks && createRevisionMetadata
- && modifyRevisionMetadata && removeRevisionMetadata
- && createRevisionContent && modifyRevisionContent
- && removeRevisionContent;
- boolean canReadAcl = readPermissions;
- boolean canWriteAcl = grantPermission && revokePermission;
- boolean canAll = canRead && canWrite && canReadAcl && canWriteAcl
- && killLock;
-
- generatedXML.writeElement(null, CURRENT_USER_PRIVILEGE_SET,
- XMLPrinter.OPENING);
-
- if (canRead) {
- writePrivilege(generatedXML, "read", null);
- }
- if (canWrite) {
- writePrivilege(generatedXML, "write", null);
- }
- if (canReadAcl) {
- writePrivilege(generatedXML, "read-acl", null);
- }
- if (canWriteAcl) {
- writePrivilege(generatedXML, "write-acl", null);
- }
- if (canAll) {
- writePrivilege(generatedXML, "all", null);
- }
-
- generatedXML.writeElement(null, CURRENT_USER_PRIVILEGE_SET,
- XMLPrinter.CLOSING);
-
- } catch (SlideException e) {
- return;
- }
-
- }
-
-
- /**
- * Write a privilege.
- */
- protected void writePrivilege(XMLPrinter generatedXML, String privilege,
- String namespace) {
- generatedXML.writeElement(null, "privilege", XMLPrinter.OPENING);
- generatedXML.writeElement(namespace, privilege, XMLPrinter.NO_CONTENT);
- generatedXML.writeElement(null, "privilege", XMLPrinter.CLOSING);
- }
-
-
- /**
- * WebDAV ACL DAV:acl property.
- */
- protected void showAcl(ObjectNode object, XMLPrinter generatedXML)
- throws WebdavException {
-
- generatedXML.writeElement(null, ACL, XMLPrinter.OPENING);
-
- NamespaceConfig config = token.getNamespaceConfig();
-
- // check read-acl permission
- Security securityHelper = token.getSecurityHelper();
- try {
- securityHelper.checkCredentials(slideToken, object,
config.getReadPermissionsAction());
- } catch (AccessDeniedException ade) {
- try {
- resp.sendError(WebdavStatus.SC_FORBIDDEN,
- WebdavStatus.getStatusText(WebdavStatus.SC_FORBIDDEN));
- } catch(IOException ex) {}
- throw new WebdavException(WebdavStatus.SC_FORBIDDEN);
- } catch (ServiceAccessException sae) {
- try {
- resp.sendError(WebdavStatus.SC_FORBIDDEN,
- WebdavStatus.getStatusText(WebdavStatus.SC_FORBIDDEN));
- } catch(IOException ex) {}
- throw new WebdavException(WebdavStatus.SC_FORBIDDEN);
- }
-
- // read
- String readObjectUri = config.getReadObjectAction().getUri();
- String readRevisionMetadataUri =
- config.getReadRevisionMetadataAction().getUri();
- String readRevisionContentUri =
- config.getReadRevisionContentAction().getUri();
-
- // write
- String createObjectUri = config.getCreateObjectAction().getUri();
- String removeObjectUri = config.getRemoveObjectAction().getUri();
- String lockObjectUri = config.getLockObjectAction().getUri();
- String readLocksUri = config.getReadLocksAction().getUri();
- String createRevisionMetadataUri =
- config.getCreateRevisionMetadataAction().getUri();
- String modifyRevisionMetadataUri =
- config.getModifyRevisionMetadataAction().getUri();
- String removeRevisionMetadataUri =
- config.getRemoveRevisionMetadataAction().getUri();
- String createRevisionContentUri =
- config.getCreateRevisionContentAction().getUri();
- String modifyRevisionContentUri =
- config.getModifyRevisionContentAction().getUri();
- String removeRevisionContentUri =
- config.getRemoveRevisionContentAction().getUri();
-
- // read-acl
- String readPermissionsUri = config.getReadPermissionsAction().getUri();
-
- // write-acl
- String grantPermissionUri = config.getGrantPermissionAction().getUri();
- String revokePermissionUri =
- config.getRevokePermissionAction().getUri();
-
- ObjectNode current = object;
- boolean inheritedPermissions = false;
- Vector permissions = new Vector();
-
- while (current != null) {
-
- try {
- // put all permissions in a list
- permissions.clear();
- Enumeration aclList = security.enumeratePermissions(slideToken,
current);
- while (aclList.hasMoreElements()) {
-
- NodePermission permission = (NodePermission)
aclList.nextElement();
-
- // if we are processing inheritedPermissions (from parent and
up)
- // then the permission should be inheritable
- if (inheritedPermissions && !permission.isInheritable()) {
- // continue with next permission
- continue;
- }
- permissions.add(permission);
- }
-
- // start combining and writing the permissions
- while (permissions.size()>0) {
-
- NodePermission permission = (NodePermission) permissions.get(0);
- permissions.remove(0);
-
- String principal = permission.getSubjectUri();
- boolean negative = permission.isNegative();
-
- String action = permission.getActionUri();
-
- // read
- boolean isReadObject =
readObjectUri.startsWith(action);
- boolean isReadLocks =
readLocksUri.startsWith(action);
- boolean isReadRevisionMetadata =
readRevisionMetadataUri.startsWith(action);
- boolean isReadRevisionContent =
readRevisionContentUri.startsWith(action);
-
- // write
- boolean isCreateObject =
createObjectUri.startsWith(action);
- boolean isRemoveObject =
removeObjectUri.startsWith(action);
- boolean isLockObject =
lockObjectUri.startsWith(action);
- boolean isCreateRevisionMetadata =
createRevisionMetadataUri.startsWith(action);
- boolean isModifyRevisionMetadata =
modifyRevisionMetadataUri.startsWith(action);
- boolean isRemoveRevisionMetadata =
removeRevisionMetadataUri.startsWith(action);
- boolean isCreateRevisionContent =
createRevisionContentUri.startsWith(action);
- boolean isModifyRevisionContent =
modifyRevisionContentUri.startsWith(action);
- boolean isRemoveRevisionContent =
removeRevisionContentUri.startsWith(action);
-
- //read-acl
- boolean isReadPermissions =
readPermissionsUri.startsWith(action);
-
- // write-acl
- boolean isGrantPermission =
grantPermissionUri.startsWith(action);
- boolean isRevokePermission =
revokePermissionUri.startsWith(action);
-
- // check the other permissions to combine them
- // (if they are for the same principal/negative)
- for (int i=0; i<permissions.size() ; i++)
- {
- NodePermission otherPermission = (NodePermission)
permissions.get(i);
- if (principal.equals(otherPermission.getSubjectUri()) &&
(negative==otherPermission.isNegative()))
- {
- permissions.remove(i);
- i--; // because we removed the current one
-
- action = otherPermission.getActionUri();
-
- // read
- isReadObject |=
readObjectUri.startsWith(action);
- isReadLocks |=
readLocksUri.startsWith(action);
- isReadRevisionMetadata |=
readRevisionMetadataUri.startsWith(action);
- isReadRevisionContent |=
readRevisionContentUri.startsWith(action);
-
- // write
- isCreateObject |=
createObjectUri.startsWith(action);
- isRemoveObject |=
removeObjectUri.startsWith(action);
- isLockObject |=
lockObjectUri.startsWith(action);
- isCreateRevisionMetadata |=
createRevisionMetadataUri.startsWith(action);
- isModifyRevisionMetadata |=
modifyRevisionMetadataUri.startsWith(action);
- isRemoveRevisionMetadata |=
removeRevisionMetadataUri.startsWith(action);
- isCreateRevisionContent |=
createRevisionContentUri.startsWith(action);
- isModifyRevisionContent |=
modifyRevisionContentUri.startsWith(action);
- isRemoveRevisionContent |=
removeRevisionContentUri.startsWith(action);
-
- //read-acl
- isReadPermissions |=
readPermissionsUri.startsWith(action);
-
- // write-acl
- isGrantPermission |=
grantPermissionUri.startsWith(action);
- isRevokePermission |=
revokePermissionUri.startsWith(action);
- }
- }
-
- // WebDAV privileges
- boolean isRead = isReadObject && isReadLocks &&
- isReadRevisionMetadata && isReadRevisionContent;
-
- boolean isWrite = isCreateObject && isRemoveObject &&
isLockObject &&
- isCreateRevisionMetadata && isModifyRevisionMetadata &&
- isRemoveRevisionMetadata &&
- isCreateRevisionContent && isModifyRevisionContent &&
- isRemoveRevisionContent;
-
- boolean isReadAcl = isReadPermissions;
-
- boolean isWriteAcl = isGrantPermission && isRevokePermission;
-
- boolean isAll = isRead && isWrite && isReadAcl && isWriteAcl;
-
-
- // start generating XML
- generatedXML.writeElement(null, ACE, XMLPrinter.OPENING);
-
- writePrincipal(generatedXML, principal);
-
- if (permission.isNegative()) {
- generatedXML.writeElement(null, DENY, XMLPrinter.OPENING);
- } else {
- generatedXML.writeElement(null, GRANT, XMLPrinter.OPENING);
- }
-
- if (isAll) {
- writePrivilege(generatedXML, "all", true);
- } else {
- if (isRead) {
- writePrivilege(generatedXML, "read", true);
- } else {
- if (isReadObject)
- writePrivilege(generatedXML,
- "read-object", false);
- if (isReadLocks)
- writePrivilege(generatedXML,
- "read-locks", false);
- if (isReadRevisionMetadata)
- writePrivilege(generatedXML,
- "read-revision-metadata",
- false);
- if (isReadRevisionContent)
- writePrivilege(generatedXML,
- "read-revision-content", false);
- }
- if (isWrite) {
- writePrivilege(generatedXML, "write", true);
- } else {
- if (isCreateObject)
- writePrivilege(generatedXML,
- "create-object", false);
- if (isRemoveObject)
- writePrivilege(generatedXML,
- "remove-object", false);
- if (isLockObject)
- writePrivilege(generatedXML,
- "lock-object", false);
- if (isCreateRevisionMetadata)
- writePrivilege(generatedXML,
- "create-revision-metadata",
- false);
- if (isModifyRevisionMetadata)
- writePrivilege(generatedXML,
- "modify-revision-metadata",
- false);
- if (isRemoveRevisionMetadata)
- writePrivilege(generatedXML,
- "remove-revision-metadata",
- false);
- if (isCreateRevisionContent)
- writePrivilege(generatedXML,
- "create-revision-content",
- false);
- if (isModifyRevisionContent)
- writePrivilege(generatedXML,
- "modify-revision-content",
- false);
- if (isRemoveRevisionContent)
- writePrivilege(generatedXML,
- "remove-revision-content",
- false);
- }
- if (isReadAcl) {
- writePrivilege(generatedXML, "read-acl", true);
- }
- if (isWriteAcl) {
- writePrivilege(generatedXML, "write-acl", true);
- } else {
- if (isGrantPermission)
- writePrivilege(generatedXML,
- "grant-permission", false);
- if (isRevokePermission)
- writePrivilege(generatedXML,
- "revoke-permission", false);
- }
- }
-
- if (permission.isNegative()) {
- generatedXML.writeElement(null, DENY,
- XMLPrinter.CLOSING);
- } else {
- generatedXML.writeElement(null, GRANT,
- XMLPrinter.CLOSING);
- }
-
- if (inheritedPermissions) {
- generatedXML.writeElement(null, "protected",
- XMLPrinter.NO_CONTENT);
- generatedXML.writeElement(null, INHERITED,
- XMLPrinter.OPENING);
- generatedXML.writeElement(null, "href",
- XMLPrinter.OPENING);
- generatedXML.writeText(getFullPath(current.getUri()));
- generatedXML.writeElement(null, "href",
- XMLPrinter.CLOSING);
- generatedXML.writeElement(null, INHERITED,
- XMLPrinter.CLOSING);
- }
-
- generatedXML.writeElement(null, ACE, XMLPrinter.CLOSING);
- }
-
- } catch (SlideException e) {
- }
-
- inheritedPermissions = true;
-
- try {
- current = structure.getParent(slideToken, current);
- } catch (SlideException e) {
- break;
- }
-
- }
-
- generatedXML.writeElement(null, ACL, XMLPrinter.CLOSING);
-
- }
-
-
- /**
- * Write principal.
- */
- protected void writePrincipal(XMLPrinter generatedXML, String principal) {
- generatedXML.writeElement(null, PRINCIPAL, XMLPrinter.OPENING);
- // FIXME: Apparently, there are or will be some other cases, but it
- // isn't very clear in the spec
- if (principal.equals("~")) {
- generatedXML.writeElement(null, "self", XMLPrinter.NO_CONTENT);
- } else if (principal.equals("nobody")) {
- generatedXML.writeElement(null, "all",
- XMLPrinter.NO_CONTENT);
- } else {
- generatedXML.writeElement(null, "href", XMLPrinter.OPENING);
- generatedXML.writeText(getFullPath(principal));
- generatedXML.writeElement(null, "href", XMLPrinter.CLOSING);
- }
- generatedXML.writeElement(null, PRINCIPAL, XMLPrinter.CLOSING);
- }
-
-
- /**
- * Write grant / deny.
- */
- protected void writePrivilege(XMLPrinter generatedXML, String name,
- boolean standard) {
- generatedXML.writeElement(null, PRIVILEGE, XMLPrinter.OPENING);
- if (standard) {
- generatedXML.writeElement(null, name, XMLPrinter.NO_CONTENT);
- } else {
- generatedXML.writeElement(SLIDE_NAMESPACE_ABBREV, name,
- XMLPrinter.NO_CONTENT);
- }
- generatedXML.writeElement(null, PRIVILEGE, XMLPrinter.CLOSING);
- }
-
-
- /**
- * WebDAV ACL DAV:acl-semantics property.
- */
- protected void showAclSemantics(XMLPrinter generatedXML) {
- generatedXML.writeElement(null, ACL_SEMANTICS, XMLPrinter.OPENING);
- generatedXML.writeText(SLIDE_ACL_SEMANTICS);
- generatedXML.writeElement(null, ACL_SEMANTICS, XMLPrinter.CLOSING);
- }
-
-
- /**
- * WebDAV ACL DAV:principal-collection-set property.
- */
- protected void showPrincipalCollectionSet(XMLPrinter generatedXML) {
- NamespaceConfig config = token.getNamespaceConfig();
- generatedXML.writeElement(null, PRINCIPAL_COLLECTION_SET,
- XMLPrinter.OPENING);
- generatedXML.writeElement(null, "href", XMLPrinter.OPENING);
- generatedXML.writeText(getFullPath(config.getUsersPath()));
- generatedXML.writeElement(null, "href", XMLPrinter.CLOSING);
- generatedXML.writeElement(null, PRINCIPAL_COLLECTION_SET,
- XMLPrinter.CLOSING);
- }
-
-
- // --------------------------------------------------- Property Inner Class
-
-
- protected class Property {
-
- public String name;
- public String value;
- public String namespace;
- public String namespaceAbbrev;
- public int status = WebdavStatus.SC_OK;
-
+ return response;
}
}
+
+
+
+
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>