You are viewing a plain text version of this content. The canonical link for it is here.
Posted to slide-dev@jakarta.apache.org by ju...@apache.org on 2002/05/15 08:43:43 UTC
cvs commit: jakarta-slide/src/webdav/server/org/apache/slide/webdav/util PropertyRetrieverImpl.java
juergen 02/05/14 23:43:43
Modified: src/webdav/server/org/apache/slide/webdav/util
PropertyRetrieverImpl.java
Log:
Now always use JDOM instead of XMLPrinter to generate response.
All computations of properties has been moved to PropertyHelper.
(ralf)
Revision Changes Path
1.14 +186 -1083 jakarta-slide/src/webdav/server/org/apache/slide/webdav/util/PropertyRetrieverImpl.java
Index: PropertyRetrieverImpl.java
===================================================================
RCS file: /home/cvs/jakarta-slide/src/webdav/server/org/apache/slide/webdav/util/PropertyRetrieverImpl.java,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -r1.13 -r1.14
--- PropertyRetrieverImpl.java 30 Apr 2002 12:39:40 -0000 1.13
+++ PropertyRetrieverImpl.java 15 May 2002 06:43:43 -0000 1.14
@@ -1,7 +1,7 @@
/*
- * $Header: /home/cvs/jakarta-slide/src/webdav/server/org/apache/slide/webdav/util/PropertyRetrieverImpl.java,v 1.13 2002/04/30 12:39:40 pnever Exp $
- * $Revision: 1.13 $
- * $Date: 2002/04/30 12:39:40 $
+ * $Header: /home/cvs/jakarta-slide/src/webdav/server/org/apache/slide/webdav/util/PropertyRetrieverImpl.java,v 1.14 2002/05/15 06:43:43 juergen Exp $
+ * $Revision: 1.14 $
+ * $Date: 2002/05/15 06:43:43 $
*
* ====================================================================
*
@@ -118,12 +118,15 @@
import java.util.Date;
import java.util.Set;
import java.util.List;
+import java.util.ListIterator;
import java.util.ArrayList;
import java.util.Collections;
import org.jdom.Document;
import org.jdom.Element;
import org.jdom.JDOMException;
+import org.jdom.Namespace;
+import org.jdom.CDATA;
import org.jdom.input.SAXBuilder;
@@ -135,59 +138,12 @@
* providing property information (<code>PropFindMethod</code>,
* <code>ReportMethod</code>) should use this class.
*
- * @version $Revision: 1.13 $
+ * @version $Revision: 1.14 $
*
* @author <a href="mailto:ralf.stuckert@softwareag.com">Ralf Stuckert</a>
*/
-public class PropertyRetrieverImpl implements PropertyRetriever, WebdavConstants, DeltavConstants, AclConstants {
+public class PropertyRetrieverImpl extends AbstractWebdavHelper implements PropertyRetriever, WebdavConstants, DeltavConstants, AclConstants {
- protected static final String SUPPORTED_PRIVILEGE_SET =
- "supported-privilege-set";
-
-
- protected static final String OWNER =
- "owner";
-
- protected static final String CURRENT_USER_PRIVILEGE_SET =
- "current-user-privilege-set";
-
- protected static final String PRINCIPAL_COLLECTION_SET =
- "principal-collection-set";
-
- protected static final String ACL_SEMANTICS = "acl-semantics";
-
- protected static final String ACL = "acl";
-
- protected static final String ACE = "ace";
-
- protected static final String GRANT = "grant";
-
- protected static final String DENY = "deny";
-
- protected static final String PRINCIPAL = "principal";
-
- protected static final String PRIVILEGE = "privilege";
-
- protected static final String INHERITED = "inherited";
-
- /**
- ** The SAXBuilder used to create JDOM Documents.
- **/
- protected static SAXBuilder saxBuilder = null;
-
-
- private static final String START_TAG = "<root>";
- private static final String END_TAG = "</root>";
-
- /**
- * The NamespaceAccessToken used to access the helpers.
- */
- protected NamespaceAccessToken token = null;
-
- /**
- * The SlideToken used to retrieve the NodeRevisionDescriptor(s).
- */
- protected SlideToken slideToken = null;
/**
* The Content helper.
@@ -210,37 +166,12 @@
protected Structure structure = null;
/**
- * Maps the namespaces against its abbreviation.
- */
- protected HashMap namespacesMap;
-
- /**
- * The number used to identify the generated namespaces.
- */
- protected int namespaceNumber = 0;
-
- /**
* The PropertyHelper used to access the (computed) properties.
*/
protected PropertyHelper propertyHelper = null;
/**
- * Returns the SAXBuilder used to create JDOM Documents in method
- * {@link #getJDOMDocumentFromXMLPrinter getJDOMDocumentFromXMLPrinter}.
- *
- * @return the SAXBuilder used to create JDOM Documents.
- */
- protected SAXBuilder getSAXBuilder() {
- if (saxBuilder == null) {
- saxBuilder = new SAXBuilder();
- }
- return saxBuilder;
- }
-
-
-
- /**
* Creates a PropertyRetriever from the given parameters.
*
* @param token the NamespaceAccessToken used to access the helpers.
@@ -248,17 +179,12 @@
*/
public PropertyRetrieverImpl(NamespaceAccessToken token, SlideToken slideToken) {
- this.token = token;
- this.slideToken = slideToken;
+ super(slideToken, token);
this.structure = token.getStructureHelper();
this.content = token.getContentHelper();
this.security = token.getSecurityHelper();
this.lock = token.getLockHelper();
- namespacesMap = new HashMap();
- namespacesMap.put(WebdavMethod.SLIDE_NAMESPACE, WebdavMethod.SLIDE_NAMESPACE_ABBREV);
- namespacesMap.put(DEFAULT_NAMESPACE, null);
-
propertyHelper = new PropertyHelper(slideToken, token);
}
@@ -271,38 +197,6 @@
return propertyHelper;
}
- /**
- * Converts the XML written into the <code>XMLPrinter</code> to a
- * list of JDOM Elements.
- *
- * @param xmlPrinter the XMLPrinter which contains the XML as a String.
- *
- * @return the list of Elements that represents the XML written into the
- * given <code>XMLPrinter</code>
- *
- * @throws JDOMException if the transforming the String into a
- * JDOM Document fails.
- */
- protected List getElementListFromXMLPrinter(XMLPrinter xmlPrinter) throws JDOMException, IOException {
-
- String xmlString = xmlPrinter.toString();
- StringBuffer buffer = new StringBuffer(START_TAG.length() + xmlString.length() + END_TAG.length());
- buffer.append(START_TAG);
- buffer.append(xmlString);
- buffer.append(END_TAG);
- Document document = getSAXBuilder().build(new StringReader(buffer.toString()));
-
- List children = document.getRootElement().getChildren();
- List clonedChildren = new ArrayList(children.size());
- Iterator iterator = children.iterator();
- while (iterator.hasNext()) {
- clonedChildren.add(((Element)iterator.next()).clone());
- }
-
- return clonedChildren;
- }
-
-
/**
* Returns the requested properties of the last revision of the resource
@@ -334,11 +228,11 @@
try {
revisionDescriptors =
- content.retrieve(slideToken, uri);
+ content.retrieve(sToken, uri);
try {
- revisionDescriptor = content.retrieve(slideToken,
+ revisionDescriptor = content.retrieve(sToken,
revisionDescriptors);
isCollection = WebdavUtils.isCollection(revisionDescriptor);
@@ -394,8 +288,8 @@
*/
public List getPropertiesOfObject(RequestedProperties requestedProperties, String uri, NodeRevisionNumber revisionNumber, String contextPath, String serverURL, boolean allpropSupportsDeltaV) throws SlideException, JDOMException {
- NodeRevisionDescriptors revisionDescriptors = content.retrieve(slideToken, uri);
- NodeRevisionDescriptor revisionDescriptor = content.retrieve(slideToken,
+ NodeRevisionDescriptors revisionDescriptors = content.retrieve(sToken, uri);
+ NodeRevisionDescriptor revisionDescriptor = content.retrieve(sToken,
revisionDescriptors,
revisionNumber);
return getPropertiesOfObject(requestedProperties, revisionDescriptors, revisionDescriptor, contextPath, serverURL, allpropSupportsDeltaV);
@@ -425,40 +319,7 @@
*/
public List getPropertiesOfObject(RequestedProperties requestedProperties, NodeRevisionDescriptors revisionDescriptors, NodeRevisionDescriptor revisionDescriptor, String contextPath, String serverURL, boolean allpropSupportsDeltaV) throws SlideException, JDOMException {
- XMLPrinter xmlPrinter = new XMLPrinter();
- writePropertiesOfObject(requestedProperties, revisionDescriptors, revisionDescriptor, contextPath, serverURL, allpropSupportsDeltaV, xmlPrinter);
- try {
- return getElementListFromXMLPrinter(xmlPrinter);
- }
- catch( IOException x ) {
- x.printStackTrace();
- return Collections.EMPTY_LIST;
- }
- }
-
-
-
- /**
- * Writes the requested properties of the resource identified by the given
- * <code>uri</code> and <code>revisionNumber</code> as an XML text (starting
- * with the generatedXML.writeElement(null, DEFAULT_NAMESPACE</code>) into the given <code>XMLPrinter</code>.
- *
- * @param requestedProperties the requested properties.
- * @param revisionDescriptors the NodeRevisionDescriptors of the resource.
- * @param revisionDescriptor the NodeRevisionDescriptor of the resource.
- * @param contextPath the context path of the uri. The concatenation of
- * <code>serverURL</code>/<code>contextPath</code>
- * /<code>uri</code> gives the absolute URL of the resource.
- * @param serverURL the URL of the server (e.g. <code>http://www.abc.com</code>).
- * @param allpropSupportsDeltaV indicates if the <code>DeltaV</code> specific
- * properties should be included in case
- * all properties are requested.
- * @param generatedXML the XMLPrinter to write the output to.
- *
- * @throws SlideException
- * @throws JDOMException
- */
- public void writePropertiesOfObject(RequestedProperties requestedProperties, NodeRevisionDescriptors revisionDescriptors, NodeRevisionDescriptor revisionDescriptor, String contextPath, String serverURL, boolean allpropSupportsDeltaV, XMLPrinter generatedXML) throws SlideException, JDOMException {
+ List elementList = new ArrayList();
String status = new String("HTTP/1.1 " + WebdavStatus.SC_OK + " "
+ WebdavStatus.getStatusText
@@ -470,7 +331,7 @@
// try {
isCollection = WebdavUtils.isCollection(revisionDescriptor);
- Enumeration lockTokens = lock.enumerateLocks(slideToken, revisionDescriptors.getUri(), true);
+ Enumeration lockTokens = lock.enumerateLocks(sToken, revisionDescriptors.getUri(), true);
if (lockTokens.hasMoreElements()) {
objectLockToken = (NodeLock) lockTokens.nextElement();
}
@@ -484,7 +345,7 @@
ObjectNode object = null;
// try {
- object = structure.retrieve(slideToken, revisionDescriptors.getUri());
+ object = structure.retrieve(sToken, revisionDescriptors.getUri());
// }
// catch (SlideException e) {
// throw new WebdavException(WebdavStatus.SC_NOT_FOUND);
@@ -494,9 +355,11 @@
if (requestedProperties.isAllProp()) {
// Show properties / values for current object.
- generatedXML.writeElement(null, DEFAULT_NAMESPACE, "propstat",
- XMLPrinter.OPENING);
- generatedXML.writeElement(null, DEFAULT_NAMESPACE, "prop", XMLPrinter.OPENING);
+ Element propstat = new Element(E_PROPSTAT, davNamespace);
+ elementList.add(propstat);
+ Element prop = new Element(E_PROP, davNamespace);
+ propstat.addContent(prop);
+ Element propertyElement = null;
status = new String("HTTP/1.1 " + WebdavStatus.SC_OK
+ " " + WebdavStatus.getStatusText
@@ -504,46 +367,34 @@
// Lock information, which is dynamically generated
if (objectLockToken != null) {
- showLockDiscoveryInfo(objectLockToken, contextPath, generatedXML);
+ propertyElement = getComputedProperty(P_LOCKDISCOVERY, revisionDescriptors, revisionDescriptor, contextPath, serverURL, propertyHelper);
+ if (propertyElement != null) {prop.addContent(propertyElement);}
}
// Supported locks
- generatedXML.writeElement(null, DEFAULT_NAMESPACE, "supportedlock",
- XMLPrinter.OPENING);
- writeSupportedLock(generatedXML);
- generatedXML.writeElement(null, DEFAULT_NAMESPACE, "supportedlock",
- XMLPrinter.CLOSING);
+ propertyElement = getComputedProperty(P_SUPPORTEDLOCK, revisionDescriptors, revisionDescriptor, contextPath, serverURL, propertyHelper);
+ if (propertyElement != null) {prop.addContent(propertyElement);}
// WebDAV ACL
if( org.apache.slide.util.Configuration.useIntegratedSecurity() ) {
- showSupportedPrivilegeSet(generatedXML);
- showCurrentUserPrivilegeSet(object, generatedXML);
+ propertyElement = getComputedProperty(P_SUPPORTED_PRIVILEGE_SET, revisionDescriptors, revisionDescriptor, contextPath, serverURL, propertyHelper);
+ if (propertyElement != null) {prop.addContent(propertyElement);}
+ propertyElement = getComputedProperty(P_CURRENT_USER_PRIVILEGE_SET, revisionDescriptors, revisionDescriptor, contextPath, serverURL, propertyHelper);
+ if (propertyElement != null) {prop.addContent(propertyElement);}
try {
- showAcl(object, contextPath, generatedXML);
+ propertyElement = getComputedProperty(P_ACL, revisionDescriptors, revisionDescriptor, contextPath, serverURL, propertyHelper);
+ if (propertyElement != null) {prop.addContent(propertyElement);}
} catch (AccessDeniedException ade) {
} catch (ServiceAccessException sae){
}
- showAclSemantics(generatedXML);
- showPrincipalCollectionSet(contextPath, generatedXML);
+ propertyElement = getComputedProperty(P_ACL_SEMANTICS, revisionDescriptors, revisionDescriptor, contextPath, serverURL, propertyHelper);
+ if (propertyElement != null) {prop.addContent(propertyElement);}
+ propertyElement = getComputedProperty(P_PRINCIPAL_COLLECTION_SET, revisionDescriptors, revisionDescriptor, contextPath, serverURL, propertyHelper);
+ if (propertyElement != null) {prop.addContent(propertyElement);}
}
- { // 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, DEFAULT_NAMESPACE, OWNER, XMLPrinter.OPENING);
- generatedXML.writeElement(null, DEFAULT_NAMESPACE, "href", XMLPrinter.OPENING);
- generatedXML.writeText(WebdavUtils.encodeURL(ownerHref));
- generatedXML.writeElement(null, DEFAULT_NAMESPACE, "href", XMLPrinter.CLOSING);
- generatedXML.writeElement(null, DEFAULT_NAMESPACE, OWNER, XMLPrinter.CLOSING);
- }
+ propertyElement = getComputedProperty(P_OWNER, revisionDescriptors, revisionDescriptor, contextPath, serverURL, propertyHelper);
+ if (propertyElement != null) {prop.addContent(propertyElement);}
// Other properties
@@ -554,7 +405,7 @@
NodeProperty currentProperty =
(NodeProperty) propertyList.nextElement();
if (currentProperty != null) {
- if ((OWNER.equals(currentProperty.getName())) &&
+ if ((P_OWNER.equals(currentProperty.getName())) &&
(NodeProperty.DEFAULT_NAMESPACE.equals(
currentProperty.getNamespace()))) {
// skip owner property
@@ -565,34 +416,34 @@
// skip DeltaV properties
continue;
}
- generateNamespaceAbbreviation(
- currentProperty.getNamespace());
- writeSingleProperty(generatedXML, currentProperty, contextPath, serverURL);
+ propertyElement = getPropertyElement(currentProperty, contextPath, serverURL);
+ if (propertyElement != null) {prop.addContent(propertyElement);}
}
}
// DeltaV computed properties
if (allpropSupportsDeltaV) {
- writeAllComputedDeltaVProperties(revisionDescriptors, revisionDescriptor, contextPath, serverURL, propertyHelper, generatedXML);
+ List deltavPropertyList = getAllComputedDeltaVProperties(revisionDescriptors, revisionDescriptor, contextPath, serverURL, propertyHelper);
+ Iterator iterator = deltavPropertyList.iterator();
+ while (iterator.hasNext()) {
+ prop.addContent((Element)iterator.next());
+ }
}
- generatedXML.writeElement(null, DEFAULT_NAMESPACE, "prop", XMLPrinter.CLOSING);
- generatedXML.writeProperty(null, DEFAULT_NAMESPACE, "status", status);
- generatedXML.writeElement(null, DEFAULT_NAMESPACE, "propstat",
- XMLPrinter.CLOSING);
-
}
else {
// Show requested properties value.
- ResourceKind resourceKind = AbstractResourceKind.determineResourceKind(token, revisionDescriptors, revisionDescriptor);
+ ResourceKind resourceKind = AbstractResourceKind.determineResourceKind(nsaToken, revisionDescriptors, revisionDescriptor);
Iterator propertyIterator = requestedProperties.getRequestedProperties();
- generatedXML.writeElement(null, DEFAULT_NAMESPACE, "propstat",
- XMLPrinter.OPENING);
- generatedXML.writeElement(null, DEFAULT_NAMESPACE, "prop", XMLPrinter.OPENING);
+ Element propstat = new Element(E_PROPSTAT, davNamespace);
+ elementList.add(propstat);
+ Element prop = new Element(E_PROP, davNamespace);
+ propstat.addContent(prop);
+ Element propertyElement = null;
status = new String("HTTP/1.1 " + WebdavStatus.SC_OK
+ " " + WebdavStatus.getStatusText
@@ -604,71 +455,67 @@
RequestedProperty property = (RequestedProperty)propertyIterator.next();
// Lock information, dynamically generated
- if ((property.getName().equals("lockdiscovery")) &&
+ if ((property.getName().equals(P_LOCKDISCOVERY)) &&
(property.getNamespace().equals
(NodeProperty.DEFAULT_NAMESPACE))) {
// Return list of active locks ...
if (objectLockToken != null) {
- showLockDiscoveryInfo(objectLockToken, contextPath, generatedXML);
+ propertyElement = getComputedProperty(P_LOCKDISCOVERY, revisionDescriptors, revisionDescriptor, contextPath, serverURL, propertyHelper);
+ if (propertyElement != null) {prop.addContent(propertyElement);}
}
- } else if ((property.getName().equals("supportedlock")) &&
+ } else if ((property.getName().equals(P_SUPPORTEDLOCK)) &&
(property.getNamespace().equals
(NodeProperty.DEFAULT_NAMESPACE))) {
// Supported locks
- generatedXML.writeElement(null, DEFAULT_NAMESPACE, "supportedlock",
- XMLPrinter.OPENING);
- writeSupportedLock(generatedXML);
- generatedXML.writeElement(null, DEFAULT_NAMESPACE, "supportedlock",
- XMLPrinter.CLOSING);
- } else if ((property.getName().equals(OWNER)) &&
+ propertyElement = getComputedProperty(P_SUPPORTEDLOCK, revisionDescriptors, revisionDescriptor, contextPath, serverURL, propertyHelper);
+ if (propertyElement != null) {prop.addContent(propertyElement);}
+ } else if ((property.getName().equals(P_OWNER)) &&
(property.getNamespace().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, DEFAULT_NAMESPACE, OWNER, XMLPrinter.OPENING);
- generatedXML.writeElement(null, DEFAULT_NAMESPACE, "href", XMLPrinter.OPENING);
- generatedXML.writeText(WebdavUtils.encodeURL(ownerHref));
- generatedXML.writeElement(null, DEFAULT_NAMESPACE, "href", XMLPrinter.CLOSING);
- generatedXML.writeElement(null, DEFAULT_NAMESPACE, OWNER, XMLPrinter.CLOSING);
- } else if ((property.getName().equals(SUPPORTED_PRIVILEGE_SET)) &&
+ propertyElement = getComputedProperty(P_OWNER, revisionDescriptors, revisionDescriptor, contextPath, serverURL, propertyHelper);
+ if (propertyElement != null) {prop.addContent(propertyElement);}
+ } else if ((property.getName().equals(P_SUPPORTED_PRIVILEGE_SET)) &&
(property.getNamespace().equals
(NodeProperty.DEFAULT_NAMESPACE))) {
// WebDAV ACL
- if( org.apache.slide.util.Configuration.useIntegratedSecurity() )
- showSupportedPrivilegeSet(generatedXML);
- } else if ((property.getName().equals(CURRENT_USER_PRIVILEGE_SET)) &&
+ if( org.apache.slide.util.Configuration.useIntegratedSecurity() ) {
+ propertyElement = getComputedProperty(P_SUPPORTED_PRIVILEGE_SET, revisionDescriptors, revisionDescriptor, contextPath, serverURL, propertyHelper);
+ if (propertyElement != null) {prop.addContent(propertyElement);}
+ }
+ } else if ((property.getName().equals(P_CURRENT_USER_PRIVILEGE_SET)) &&
(property.getNamespace().equals
(NodeProperty.DEFAULT_NAMESPACE))) {
- if( org.apache.slide.util.Configuration.useIntegratedSecurity() )
- showCurrentUserPrivilegeSet(object, generatedXML);
- } else if ((property.getName().equals("acl")) &&
+ if( org.apache.slide.util.Configuration.useIntegratedSecurity() ) {
+ propertyElement = getComputedProperty(P_CURRENT_USER_PRIVILEGE_SET, revisionDescriptors, revisionDescriptor, contextPath, serverURL, propertyHelper);
+ if (propertyElement != null) {prop.addContent(propertyElement);}
+ }
+ } else if ((property.getName().equals(P_ACL)) &&
(property.getNamespace().equals
(NodeProperty.DEFAULT_NAMESPACE))) {
- if( org.apache.slide.util.Configuration.useIntegratedSecurity() )
- showAcl(object, contextPath, generatedXML);
- } else if ((property.getName().equals(ACL_SEMANTICS)) &&
+ if( org.apache.slide.util.Configuration.useIntegratedSecurity() ) {
+ propertyElement = getComputedProperty(P_ACL, revisionDescriptors, revisionDescriptor, contextPath, serverURL, propertyHelper);
+ if (propertyElement != null) {prop.addContent(propertyElement);}
+ }
+ } else if ((property.getName().equals(P_ACL_SEMANTICS)) &&
(property.getNamespace().equals
(NodeProperty.DEFAULT_NAMESPACE))) {
- if( org.apache.slide.util.Configuration.useIntegratedSecurity() )
- showAclSemantics(generatedXML);
- } else if ((property.getName().equals(PRINCIPAL_COLLECTION_SET)) &&
+ if( org.apache.slide.util.Configuration.useIntegratedSecurity() ) {
+ propertyElement = getComputedProperty(P_ACL_SEMANTICS, revisionDescriptors, revisionDescriptor, contextPath, serverURL, propertyHelper);
+ if (propertyElement != null) {prop.addContent(propertyElement);}
+ }
+ } else if ((property.getName().equals(P_PRINCIPAL_COLLECTION_SET)) &&
(property.getNamespace().equals
(NodeProperty.DEFAULT_NAMESPACE))) {
- if( org.apache.slide.util.Configuration.useIntegratedSecurity() )
- showPrincipalCollectionSet(contextPath, generatedXML);
+ if( org.apache.slide.util.Configuration.useIntegratedSecurity() ) {
+ propertyElement = getComputedProperty(P_PRINCIPAL_COLLECTION_SET, revisionDescriptors, revisionDescriptor, contextPath, serverURL, propertyHelper);
+ if (propertyElement != null) {prop.addContent(propertyElement);}
+ }
}
// now the computed (DeltaV) properties
else if (resourceKind.getSupportedLiveProperties(Q_COMPUTED_ONLY).contains(property.getName())) {
- writeComputedProperty(property.getName(), revisionDescriptors, revisionDescriptor, contextPath, serverURL, propertyHelper, generatedXML);
+ propertyElement = getComputedProperty(property.getName(), revisionDescriptors, revisionDescriptor, contextPath, serverURL, propertyHelper);
+ if (propertyElement != null) {prop.addContent(propertyElement);}
}
else {
@@ -680,884 +527,127 @@
property.getNamespace());
if (currentProperty != null) {
- writeSingleProperty(generatedXML, currentProperty, contextPath, serverURL);
+ propertyElement = getPropertyElement(currentProperty, contextPath, serverURL);
+ if (propertyElement != null) {prop.addContent(propertyElement);}
} else {
propertiesNotFoundVector.addElement(property);
}
}
}
- generatedXML.writeElement(null, DEFAULT_NAMESPACE, "prop", XMLPrinter.CLOSING);
- generatedXML.writeProperty(null, DEFAULT_NAMESPACE, "status", status);
- generatedXML.writeElement(null, DEFAULT_NAMESPACE, "propstat",
- XMLPrinter.CLOSING);
+ Element statusElement = new Element(E_STATUS, davNamespace);
+ statusElement.setText(status);
+ propstat.addContent(statusElement);
- Enumeration propertiesNotFoundList =
+ Enumeration propertiesNotFoundEnum =
propertiesNotFoundVector.elements();
- if (propertiesNotFoundList.hasMoreElements()) {
+ if (propertiesNotFoundEnum.hasMoreElements()) {
+
+ propstat = new Element(E_PROPSTAT, davNamespace);
+ elementList.add(propstat);
+ prop = new Element(E_PROP, davNamespace);
+ propstat.addContent(prop);
status = new String("HTTP/1.1 " + WebdavStatus.SC_NOT_FOUND
+ " " + WebdavStatus.getStatusText
(WebdavStatus.SC_NOT_FOUND));
- generatedXML.writeElement(null, DEFAULT_NAMESPACE, "propstat",
- XMLPrinter.OPENING);
- generatedXML.writeElement(null, DEFAULT_NAMESPACE, "prop",
- XMLPrinter.OPENING);
- while (propertiesNotFoundList.hasMoreElements()) {
+ while (propertiesNotFoundEnum.hasMoreElements()) {
RequestedProperty propertyNotFound =
- (RequestedProperty) propertiesNotFoundList.nextElement();
- String namespaceAbbrev =
- (String) namespacesMap.get(propertyNotFound.getNamespace());
- generatedXML.writeElement
- (namespaceAbbrev, null, propertyNotFound.getName(), XMLPrinter.NO_CONTENT);
+ (RequestedProperty) propertiesNotFoundEnum.nextElement();
+ propertyElement = getPropertyElement(propertyNotFound.getNamespace(),
+ propertyNotFound.getName(),
+ null,
+ contextPath,
+ serverURL);
+ if (propertyElement != null) {prop.addContent(propertyElement);}
}
- generatedXML.writeElement(null, DEFAULT_NAMESPACE, "prop",
- XMLPrinter.CLOSING);
- generatedXML.writeProperty(null, DEFAULT_NAMESPACE, "status", status);
- generatedXML.writeElement(null, DEFAULT_NAMESPACE, "propstat",
- XMLPrinter.CLOSING);
-
+ statusElement = new Element(E_STATUS, davNamespace);
+ statusElement.setText(status);
+ propstat.addContent(statusElement);
}
}
-
+ return elementList;
}
/**
- * Write a single property including the value to the XML printer.
+ * Returns the JDOM Element for the given <code>property</code>.
*
- * @param generatedXML the output channel
- * @param currentProperty the property to be written to the output channel
+ * @param property the property for which to return the Element.
* @param contextPath the context path of the uri. The concatenation of
* <code>serverURL</code>/<code>contextPath</code>
* /<code>uri</code> gives the absolute URL of the resource.
* @param serverURL the URL of the server (e.g. <code>http://www.abc.com</code>).
+ *
+ * @return the JDOM Element for the given <code>property</code>.
*/
- private void writeSingleProperty(XMLPrinter generatedXML, NodeProperty currentProperty, String contextPath, String serverURL) {
- if (currentProperty != null) {
- writeSingleProperty(generatedXML,
- currentProperty.getNamespace(),
- currentProperty.getName(),
- currentProperty.getValue(),
+ private Element getPropertyElement(NodeProperty property, String contextPath, String serverURL) {
+ if (property != null) {
+ return getPropertyElement(property.getNamespace(),
+ property.getName(),
+ property.getValue(),
contextPath,
serverURL);
}
+ return null;
}
/**
- * Write a single property including the value to the XML printer.
+ * Returns the JDOM Element for the given <code>property</code>.
*
- * @param generatedXML the output channel
- * @param namespace the property namespace
- * @param propertyName the property Name
- * @param propertyValue the property Value
+ * @param namespaceString the property namespace.
+ * @param propertyName the property Name.
+ * @param propertyValue the property Value.
* @param contextPath the context path of the uri. The concatenation of
* <code>serverURL</code>/<code>contextPath</code>
* /<code>uri</code> gives the absolute URL of the resource.
* @param serverURL the URL of the server (e.g. <code>http://www.abc.com</code>).
+ *
+ * @return the JDOM Element for the given <code>property</code>.
*/
- private void writeSingleProperty(XMLPrinter generatedXML,
- String namespace,
+ private Element getPropertyElement(String namespaceString,
String propertyName,
Object propertyValue,
String contextPath,
String serverURL) {
- if ((propertyValue == null) ||
- (propertyValue.toString().equals(""))) {
- generatedXML.writeElement
- (null, namespace, propertyName, XMLPrinter.NO_CONTENT);
- } else {
- generatedXML.writeElement
- (null, namespace, 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(convertHrefValueToAbsoluteURL(currentPropertyString, contextPath, serverURL));
- }
- generatedXML.writeElement
- (null, namespace, propertyName, XMLPrinter.CLOSING);
- }
+ Element property = null;
+ Namespace namespace = davNamespace;
+ if ( (namespaceString != null) && !namespaceString.equals(davNamespace.getURI())) {
+ namespace = Namespace.getNamespace(namespaceString);
}
-
- /**
- * Generate a namespace abbreviation for the given namespace.
- *
- * @param namespaceName Name of the namespace
- */
- protected void generateNamespaceAbbreviation(String namespaceName) {
-
- if (namespacesMap.get(namespaceName) != null)
- return;
-
- if (namespaceName.equals(NodeProperty.DEFAULT_NAMESPACE))
- return;
-
- String namespaceAbbrev = "ns" + namespaceNumber++;
- namespacesMap.put(namespaceName, namespaceAbbrev);
-
- }
-
-
- /**
- * Generate namespace declaration attributes.
- *
- * @return String namespace attributes
- */
- protected String generateNamespaceDeclarations() {
-
- StringBuffer result = new StringBuffer();
-
- result.append(" xmlns=\"").append(NodeProperty.DEFAULT_NAMESPACE)
- .append("\" ");
-
- Iterator namespaceList = namespacesMap.keySet().iterator();
- while (namespaceList.hasNext()) {
-
- String namespace = (String) namespaceList.next();
- String abbrev = (String) namespacesMap.get(namespace);
- result.append("xmlns:").append(abbrev).append("=\"")
- .append(namespace).append("\" ");
-
- }
-
- return result.toString();
-
- }
-
-
- /**
- * Show lockdiscovery info.
- *
- * @exception WebdavException Something is wrong with the servlet container
- */
- protected void showLockDiscoveryInfo(NodeLock token,
- String contextPath,
- XMLPrinter generatedXML)
- {
-
- generatedXML.writeElement(null, DEFAULT_NAMESPACE, "lockdiscovery", XMLPrinter.OPENING);
-
- generatedXML.writeElement(null, DEFAULT_NAMESPACE, "activelock", XMLPrinter.OPENING);
-
- generatedXML.writeElement(null, DEFAULT_NAMESPACE, "locktype", XMLPrinter.OPENING);
- generatedXML.writeElement(null, DEFAULT_NAMESPACE, "write", XMLPrinter.NO_CONTENT);
- generatedXML.writeElement(null, DEFAULT_NAMESPACE, "locktype", XMLPrinter.CLOSING);
-
- generatedXML.writeElement(null, DEFAULT_NAMESPACE, "lockscope", XMLPrinter.OPENING);
- if (token.isExclusive()) {
- generatedXML.writeElement(null, DEFAULT_NAMESPACE, "exclusive",
- XMLPrinter.NO_CONTENT);
- } else {
- generatedXML.writeElement(null, DEFAULT_NAMESPACE, "shared", XMLPrinter.NO_CONTENT);
- }
- generatedXML.writeElement(null, DEFAULT_NAMESPACE, "lockscope", XMLPrinter.CLOSING);
-
- generatedXML.writeElement(null, DEFAULT_NAMESPACE, "depth", XMLPrinter.OPENING);
- if (token.isInheritable()) {
- generatedXML.writeText("infinity");
- } else {
- generatedXML.writeText("0");
- }
- generatedXML.writeElement(null, DEFAULT_NAMESPACE, "depth", XMLPrinter.CLOSING);
-
- generatedXML.writeElement(null, DEFAULT_NAMESPACE, "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(contextPath, token.getSubjectUri()));
- // generatedXML.writeData(token.getSubjectUri());
- generatedXML.writeElement(null, DEFAULT_NAMESPACE, "owner", XMLPrinter.CLOSING);
-
- generatedXML.writeElement(null, DEFAULT_NAMESPACE, "timeout", XMLPrinter.OPENING);
- generatedXML.writeText("Second-"
- + (new Long((token.getExpirationDate().getTime()
- - (new Date()).getTime())/1000))
- .toString());
- generatedXML.writeElement(null, DEFAULT_NAMESPACE, "timeout", XMLPrinter.CLOSING);
-
- generatedXML.writeElement(null, DEFAULT_NAMESPACE, "locktoken", XMLPrinter.OPENING);
- generatedXML.writeElement(null, DEFAULT_NAMESPACE, "href", XMLPrinter.OPENING);
- // Put here the token Id
- boolean isOwner = false;
+ property = new Element(propertyName, namespace);
+ if ( (propertyValue != null) && (propertyValue.toString().length() > 0)) {
+ if (propertyValue.toString().startsWith("<")) {
try {
- String subjectUri = security.getPrincipal(slideToken).getUri();
- if (token.getSubjectUri().startsWith(subjectUri))
- isOwner = true;
- } catch (Exception e) {
+ XMLValue xmlValue = new XMLValue(propertyValue.toString(), namespace);
+ convertHrefValueToAbsoluteURL(xmlValue, contextPath, serverURL);
+ Iterator iterator = xmlValue.iterator();
+ while (iterator.hasNext()) {
+ property.addContent((Element)iterator.next());
}
- if (isOwner || slideToken.checkLockToken(token.getLockId())) {
- generatedXML.writeText("opaquelocktoken:" + token.getLockId());
- } else {
- generatedXML.writeText("opaquelocktoken:faketoken");
}
- generatedXML.writeElement(null, DEFAULT_NAMESPACE, "href", XMLPrinter.CLOSING);
- generatedXML.writeElement(null, DEFAULT_NAMESPACE, "locktoken", XMLPrinter.CLOSING);
-
- generatedXML.writeElement(null, DEFAULT_NAMESPACE, "activelock", XMLPrinter.CLOSING);
-
- generatedXML.writeElement(null, DEFAULT_NAMESPACE, "lockdiscovery", XMLPrinter.CLOSING);
-
+ catch (JDOMException e) {
+ property.setText(propertyValue.toString());
}
-
-
- /**
- * WebDAV ACL DAV:supported-privilege-set property.
- */
- protected void showSupportedPrivilegeSet(XMLPrinter generatedXML) {
-
- generatedXML.writeElement(null, DEFAULT_NAMESPACE, 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.
- writeSupportedPrivileges(generatedXML);
- generatedXML.writeElement(null, DEFAULT_NAMESPACE, SUPPORTED_PRIVILEGE_SET,
- XMLPrinter.CLOSING);
-
}
-
-
- /**
- * WebDAV ACL DAV:current-user-privilege-set property.
- */
- protected void showCurrentUserPrivilegeSet
- (ObjectNode object, XMLPrinter generatedXML) {
-
- NamespaceConfig config = token.getNamespaceConfig();
-
- SubjectNode principalNode = null;
-
- try {
- principalNode = (SubjectNode) security.getPrincipal(slideToken);
- } catch (SlideException e) {
- return;
- } catch (ClassCastException e) {
- return;
+ else if (P_DISPLAYNAME.equals(propertyName)) {
+ property.addContent(new CDATA(propertyValue.toString()));
}
-
- 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, DEFAULT_NAMESPACE, CURRENT_USER_PRIVILEGE_SET,
- XMLPrinter.OPENING);
-
- if (canRead) {
- writePrivilege(generatedXML, "read", null);
+ else {
+ property.setText(propertyValue.toString());
}
- 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, DEFAULT_NAMESPACE, 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, DEFAULT_NAMESPACE, "privilege", XMLPrinter.OPENING);
- generatedXML.writeElement(namespace, privilege, XMLPrinter.NO_CONTENT);
- generatedXML.writeElement(null, DEFAULT_NAMESPACE, "privilege", XMLPrinter.CLOSING);
- }
-
-
- /**
- * WebDAV ACL DAV:acl property.
- */
- protected void showAcl(ObjectNode object, String contextPath, XMLPrinter generatedXML) throws AccessDeniedException, ServiceAccessException {
-
- NamespaceConfig config = token.getNamespaceConfig();
-
- // check read-acl permission
- Security securityHelper = token.getSecurityHelper();
-
- securityHelper.checkCredentials(slideToken, object, config.getReadPermissionsAction());
-
- generatedXML.writeElement(null, DEFAULT_NAMESPACE, ACL, XMLPrinter.OPENING);
- // 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, DEFAULT_NAMESPACE, ACE, XMLPrinter.OPENING);
-
- writePrincipal(contextPath, generatedXML, principal);
-
- if (permission.isNegative()) {
- generatedXML.writeElement(null, DEFAULT_NAMESPACE, DENY, XMLPrinter.OPENING);
- } else {
- generatedXML.writeElement(null, DEFAULT_NAMESPACE, 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, DEFAULT_NAMESPACE, DENY,
- XMLPrinter.CLOSING);
- } else {
- generatedXML.writeElement(null, DEFAULT_NAMESPACE, GRANT,
- XMLPrinter.CLOSING);
- }
-
- if (inheritedPermissions) {
- generatedXML.writeElement(null, DEFAULT_NAMESPACE, "protected",
- XMLPrinter.NO_CONTENT);
- generatedXML.writeElement(null, DEFAULT_NAMESPACE, INHERITED,
- XMLPrinter.OPENING);
- generatedXML.writeElement(null, DEFAULT_NAMESPACE, "href",
- XMLPrinter.OPENING);
- generatedXML.writeText(getFullPath(contextPath, current.getUri()));
- generatedXML.writeElement(null, DEFAULT_NAMESPACE, "href",
- XMLPrinter.CLOSING);
- generatedXML.writeElement(null, DEFAULT_NAMESPACE, INHERITED,
- XMLPrinter.CLOSING);
- }
-
- generatedXML.writeElement(null, DEFAULT_NAMESPACE, ACE, XMLPrinter.CLOSING);
- }
-
- } catch (SlideException e) {
- }
-
- inheritedPermissions = true;
-
- try {
- current = structure.getParent(slideToken, current);
- } catch (SlideException e) {
- break;
- }
-
- }
-
- generatedXML.writeElement(null, DEFAULT_NAMESPACE, ACL, XMLPrinter.CLOSING);
-
- }
-
-
- /**
- * Write principal.
- */
- protected void writePrincipal(String contextPath, XMLPrinter generatedXML, String principal) {
- generatedXML.writeElement(null, DEFAULT_NAMESPACE, 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, DEFAULT_NAMESPACE, "self", XMLPrinter.NO_CONTENT);
- } else if (principal.equals("nobody")) {
- generatedXML.writeElement(null, DEFAULT_NAMESPACE, "all",
- XMLPrinter.NO_CONTENT);
- } else {
- generatedXML.writeElement(null, DEFAULT_NAMESPACE, "href", XMLPrinter.OPENING);
- generatedXML.writeText(getFullPath(contextPath, principal));
- generatedXML.writeElement(null, DEFAULT_NAMESPACE, "href", XMLPrinter.CLOSING);
- }
- generatedXML.writeElement(null, DEFAULT_NAMESPACE, PRINCIPAL, XMLPrinter.CLOSING);
- }
-
-
- /**
- * Write grant / deny.
- */
- protected void writePrivilege(XMLPrinter generatedXML, String name,
- boolean standard) {
- generatedXML.writeElement(null, DEFAULT_NAMESPACE, PRIVILEGE, XMLPrinter.OPENING);
- if (standard) {
- generatedXML.writeElement(null, DEFAULT_NAMESPACE, name, XMLPrinter.NO_CONTENT);
- } else {
- generatedXML.writeElement(WebdavMethod.SLIDE_NAMESPACE_ABBREV, name,
- XMLPrinter.NO_CONTENT);
}
- generatedXML.writeElement(null, DEFAULT_NAMESPACE, PRIVILEGE, XMLPrinter.CLOSING);
- }
-
-
- /**
- * WebDAV ACL DAV:acl-semantics property.
- */
- protected void showAclSemantics(XMLPrinter generatedXML) {
- generatedXML.writeElement(null, DEFAULT_NAMESPACE, ACL_SEMANTICS, XMLPrinter.OPENING);
- writeSlideAclSemantics(generatedXML);
- generatedXML.writeElement(null, DEFAULT_NAMESPACE, ACL_SEMANTICS, XMLPrinter.CLOSING);
+ return property;
}
- /**
- * WebDAV ACL DAV:principal-collection-set property.
- */
- protected void showPrincipalCollectionSet(String contextPath, XMLPrinter generatedXML) {
- NamespaceConfig config = token.getNamespaceConfig();
- generatedXML.writeElement(null, DEFAULT_NAMESPACE, PRINCIPAL_COLLECTION_SET,
- XMLPrinter.OPENING);
- generatedXML.writeElement(null, DEFAULT_NAMESPACE, "href", XMLPrinter.OPENING);
-
- generatedXML.writeText(getFullPath(contextPath, config.getUsersPath()));
- generatedXML.writeElement(null, DEFAULT_NAMESPACE, "href", XMLPrinter.CLOSING);
- generatedXML.writeElement(null, DEFAULT_NAMESPACE, PRINCIPAL_COLLECTION_SET,
- XMLPrinter.CLOSING);
- }
-
/**
- * Return an absolute URL (absolute in the HTTP sense) based on a Slide
- * path.
- */
- public String getFullPath(String contextPath, String path) {
-
- if (path.startsWith("/"))
- return WebdavUtils.encodeURL(contextPath + path);
- else
- return WebdavUtils.encodeURL(contextPath + "/" + path);
- }
-
-
- /**
- * Get return status based on exception type.
- */
- protected int getErrorCode(Throwable ex) {
- if ( !(ex instanceof SlideException) ) {
- return WebdavStatus.SC_INTERNAL_SERVER_ERROR;
- } else {
- return getErrorCode((SlideException)ex);
- }
- }
-
-
- /**
- * Get return status based on exception type.
- */
- protected int getErrorCode(SlideException ex) {
- try {
- throw ex;
- } catch(ObjectNotFoundException e) {
- return WebdavStatus.SC_NOT_FOUND;
- } catch(ConflictException e) {
- return WebdavStatus.SC_CONFLICT;
- } catch(ForbiddenException e) {
- return WebdavStatus.SC_FORBIDDEN;
- } catch(AccessDeniedException e) {
- return WebdavStatus.SC_FORBIDDEN;
- } catch(ObjectAlreadyExistsException e) {
- return WebdavStatus.SC_PRECONDITION_FAILED;
- } catch(ServiceAccessException e) {
- return getErrorCode((ServiceAccessException)ex);
- } catch(ObjectLockedException e) {
- return WebdavStatus.SC_LOCKED;
- } catch(SlideException e) {
- return WebdavStatus.SC_INTERNAL_SERVER_ERROR;
- }
- }
-
-
-
- /**
- * Get return status based on exception type.
- */
- protected int getErrorCode(ServiceAccessException ex) {
- Throwable cause = ex.getCauseException();
- if (cause == null || !(cause instanceof SlideException) ) {
- return WebdavStatus.SC_INTERNAL_SERVER_ERROR; // this is the default}
- } else {
- return getErrorCode((SlideException)cause);
- }
- }
-
- /**
- * Writes the <code><lockentry></code> to the given
- * xmlPrinter.
- *
- * @param generatedXML the XMLPrinter to write to.
- */
- protected void writeSupportedLock(XMLPrinter generatedXML) {
-
- generatedXML.writeElement(null, DEFAULT_NAMESPACE, E_LOCKENTRY, XMLPrinter.OPENING);
- generatedXML.writeElement(null, DEFAULT_NAMESPACE, E_LOCKSCOPE, XMLPrinter.OPENING);
- generatedXML.writeElement(null, DEFAULT_NAMESPACE, E_EXCLUSIVE, XMLPrinter.NO_CONTENT);
- generatedXML.writeElement(null, DEFAULT_NAMESPACE, E_LOCKSCOPE, XMLPrinter.CLOSING);
- generatedXML.writeElement(null, DEFAULT_NAMESPACE, E_LOCKTYPE, XMLPrinter.OPENING);
- generatedXML.writeElement(null, DEFAULT_NAMESPACE, E_WRITE, XMLPrinter.NO_CONTENT);
- generatedXML.writeElement(null, DEFAULT_NAMESPACE, E_LOCKTYPE, XMLPrinter.CLOSING);
- generatedXML.writeElement(null, DEFAULT_NAMESPACE, E_LOCKENTRY, XMLPrinter.CLOSING);
-
- generatedXML.writeElement(null, DEFAULT_NAMESPACE, E_LOCKENTRY, XMLPrinter.OPENING);
- generatedXML.writeElement(null, DEFAULT_NAMESPACE, E_LOCKSCOPE, XMLPrinter.OPENING);
- generatedXML.writeElement(null, DEFAULT_NAMESPACE, E_SHARED, XMLPrinter.NO_CONTENT);
- generatedXML.writeElement(null, DEFAULT_NAMESPACE, E_LOCKSCOPE, XMLPrinter.CLOSING);
- generatedXML.writeElement(null, DEFAULT_NAMESPACE, E_LOCKTYPE, XMLPrinter.OPENING);
- generatedXML.writeElement(null, DEFAULT_NAMESPACE, E_WRITE, XMLPrinter.NO_CONTENT);
- generatedXML.writeElement(null, DEFAULT_NAMESPACE, E_LOCKTYPE, XMLPrinter.CLOSING);
- generatedXML.writeElement(null, DEFAULT_NAMESPACE, E_LOCKENTRY, XMLPrinter.CLOSING);
-
- }
-
- /**
- * Writes the <code><supported-privilege></code> to the given
- * xmlPrinter.
- *
- * @param generatedXML the XMLPrinter to write to.
- */
- protected void writeSupportedPrivileges(XMLPrinter generatedXML) {
-
- generatedXML.writeElement(null, DEFAULT_NAMESPACE, "supported-privilege", XMLPrinter.OPENING);
- generatedXML.writeElement(null, DEFAULT_NAMESPACE, "privilege", XMLPrinter.OPENING);
- generatedXML.writeElement(null, DEFAULT_NAMESPACE, "all", XMLPrinter.NO_CONTENT);
- generatedXML.writeElement(null, DEFAULT_NAMESPACE, "privilege", XMLPrinter.CLOSING);
- generatedXML.writeElement(null, DEFAULT_NAMESPACE, "description", XMLPrinter.OPENING);
- generatedXML.writeText("Any operation");
- generatedXML.writeElement(null, DEFAULT_NAMESPACE, "description", XMLPrinter.CLOSING);
- generatedXML.writeElement(null, DEFAULT_NAMESPACE, "privilege", XMLPrinter.OPENING);
- generatedXML.writeElement(null, DEFAULT_NAMESPACE, "read", XMLPrinter.NO_CONTENT);
- generatedXML.writeElement(null, DEFAULT_NAMESPACE, "privilege", XMLPrinter.CLOSING);
- generatedXML.writeElement(null, DEFAULT_NAMESPACE, "description", XMLPrinter.OPENING);
- generatedXML.writeText("Read any object");
- generatedXML.writeElement(null, DEFAULT_NAMESPACE, "description", XMLPrinter.CLOSING);
- generatedXML.writeElement(null, DEFAULT_NAMESPACE, "supported-privilege", XMLPrinter.CLOSING);
-
- generatedXML.writeElement(null, DEFAULT_NAMESPACE, "supported-privilege", XMLPrinter.OPENING);
- generatedXML.writeElement(null, DEFAULT_NAMESPACE, "privilege", XMLPrinter.OPENING);
- generatedXML.writeElement(null, DEFAULT_NAMESPACE, "write", XMLPrinter.NO_CONTENT);
- generatedXML.writeElement(null, DEFAULT_NAMESPACE, "privilege", XMLPrinter.CLOSING);
- generatedXML.writeElement(null, DEFAULT_NAMESPACE, "description", XMLPrinter.OPENING);
- generatedXML.writeText("Write any object");
- generatedXML.writeElement(null, DEFAULT_NAMESPACE, "description", XMLPrinter.CLOSING);
- generatedXML.writeElement(null, DEFAULT_NAMESPACE, "privilege", XMLPrinter.OPENING);
- generatedXML.writeElement(null, DEFAULT_NAMESPACE, "read-acl", XMLPrinter.NO_CONTENT);
- generatedXML.writeElement(null, DEFAULT_NAMESPACE, "privilege", XMLPrinter.CLOSING);
- generatedXML.writeElement(null, DEFAULT_NAMESPACE, "description", XMLPrinter.OPENING);
- generatedXML.writeText("Read the ACL");
- generatedXML.writeElement(null, DEFAULT_NAMESPACE, "description", XMLPrinter.CLOSING);
- generatedXML.writeElement(null, DEFAULT_NAMESPACE, "supported-privilege", XMLPrinter.CLOSING);
-
- generatedXML.writeElement(null, DEFAULT_NAMESPACE, "supported-privilege", XMLPrinter.OPENING);
- generatedXML.writeElement(null, DEFAULT_NAMESPACE, "privilege", XMLPrinter.OPENING);
- generatedXML.writeElement(null, DEFAULT_NAMESPACE, "write-acl", XMLPrinter.NO_CONTENT);
- generatedXML.writeElement(null, DEFAULT_NAMESPACE, "privilege", XMLPrinter.CLOSING);
- generatedXML.writeElement(null, DEFAULT_NAMESPACE, "description", XMLPrinter.OPENING);
- generatedXML.writeText("Write the ACL");
- generatedXML.writeElement(null, DEFAULT_NAMESPACE, "description", XMLPrinter.CLOSING);
- generatedXML.writeElement(null, DEFAULT_NAMESPACE, "supported-privilege", XMLPrinter.CLOSING);
- }
-
- /**
- * Writes the <code><supported-privilege></code> to the given
- * xmlPrinter.
- *
- * @param generatedXML the XMLPrinter to write to.
- */
- protected void writeSlideAclSemantics(XMLPrinter generatedXML) {
-
- generatedXML.writeElement(null, DEFAULT_NAMESPACE, "ace-combination", XMLPrinter.OPENING);
- generatedXML.writeElement(null, DEFAULT_NAMESPACE, "all-grant-before-any-deny", XMLPrinter.NO_CONTENT);
- generatedXML.writeElement(null, DEFAULT_NAMESPACE, "ace-combination", XMLPrinter.CLOSING);
- generatedXML.writeElement(null, DEFAULT_NAMESPACE, "required-principal", XMLPrinter.OPENING);
- generatedXML.writeElement(null, DEFAULT_NAMESPACE, "all", XMLPrinter.NO_CONTENT);
- generatedXML.writeElement(null, DEFAULT_NAMESPACE, "required-principal", XMLPrinter.CLOSING);
- }
-
- /**
- * Writes the specified computed property to the given XMLPrinter.
+ * Returns the specified computed property as a JDOM Element.
*
* @param propertyName
* @param revisionDescriptors
@@ -1567,23 +657,38 @@
* /<code>uri</code> gives the absolute URL of the resource.
* @param serverURL the URL of the server (e.g. <code>http://www.abc.com</code>).
* @param propertyHelper
- * @param generatedXML
+ *
+ * @return the specified computed property as a JDOM Element.
*
* @throws SlideException
* @throws JDOMException
*/
- protected void writeComputedProperty(String propertyName, NodeRevisionDescriptors revisionDescriptors, NodeRevisionDescriptor revisionDescriptor, String contextPath, String serverURL, PropertyHelper propertyHelper, XMLPrinter generatedXML) throws SlideException, JDOMException {
+ protected Element getComputedProperty(String propertyName, NodeRevisionDescriptors revisionDescriptors, NodeRevisionDescriptor revisionDescriptor, String contextPath, String serverURL, PropertyHelper propertyHelper) throws SlideException, JDOMException {
+ Element propertyElement = null;
NodeProperty property = propertyHelper.getProperty(propertyName, revisionDescriptors, revisionDescriptor, contextPath, serverURL);
if (property != null) {
- generatedXML.writeElement(null, DEFAULT_NAMESPACE, propertyName, XMLPrinter.OPENING);
- generatedXML.writeText(property.getValue().toString());
- generatedXML.writeElement(null, DEFAULT_NAMESPACE, propertyName, XMLPrinter.CLOSING);
+ Namespace namespace = davNamespace;
+ if ( (property.getNamespace() != null) &&
+ ! property.getNamespace().equals(davNamespace.getURI()) ) {
+ namespace = Namespace.getNamespace(property.getNamespace());
+ }
+ propertyElement = new Element(propertyName, namespace);
+ if (property.getValue() instanceof XMLValue) {
+ Iterator iterator = ((XMLValue)property.getValue()).iterator();
+ while (iterator.hasNext()) {
+ propertyElement.addContent((Element)iterator.next());
+ }
}
+ else if (property.getValue() != null) {
+ propertyElement.setText(property.getValue().toString());
+ }
+ }
+ return propertyElement;
}
/**
- * Writes all computed DeltaV properties to the given XMLPrinter.
+ * Returns all computed DeltaV properties as a List of JDOM Elements.
*
* @param revisionDescriptors
* @param revisionDescriptor
@@ -1592,40 +697,43 @@
* /<code>uri</code> gives the absolute URL of the resource.
* @param serverURL the URL of the server (e.g. <code>http://www.abc.com</code>).
* @param propertyHelper
- * @param generatedXML
+ *
+ * @return all computed DeltaV properties as a List of JDOM Elements.
*
* @throws SlideException
* @throws JDOMException
*/
- protected void writeAllComputedDeltaVProperties(NodeRevisionDescriptors revisionDescriptors, NodeRevisionDescriptor revisionDescriptor, String contextPath, String serverURL, PropertyHelper propertyHelper, XMLPrinter generatedXML) throws SlideException, JDOMException {
+ protected List getAllComputedDeltaVProperties(NodeRevisionDescriptors revisionDescriptors, NodeRevisionDescriptor revisionDescriptor, String contextPath, String serverURL, PropertyHelper propertyHelper) throws SlideException, JDOMException {
- ResourceKind resourceKind = AbstractResourceKind.determineResourceKind(token, revisionDescriptors, revisionDescriptor);
+ List propertyList = new ArrayList();
+
+ ResourceKind resourceKind = AbstractResourceKind.determineResourceKind(nsaToken, revisionDescriptors, revisionDescriptor);
Set computedLivePropertyNames = resourceKind.getSupportedLiveProperties(Q_COMPUTED_ONLY, new String[] {F_ACCESS_CONTROL, F_LOCKING, F_UPDATE});
Iterator iterator = computedLivePropertyNames.iterator();
+ String propertyName = null;
while (iterator.hasNext()) {
- writeComputedProperty((String)iterator.next(), revisionDescriptors, revisionDescriptor, contextPath, serverURL, propertyHelper, generatedXML);
+ propertyName = (String)iterator.next();
+ if (DeltavConstants.DELTAV_PROPERTY_LIST.contains(propertyName)) {
+ propertyList.add(getComputedProperty(propertyName, revisionDescriptors, revisionDescriptor, contextPath, serverURL, propertyHelper));
+ }
}
+ return propertyList;
}
/**
- * If the given <code>value</code> is a <code><href></code> value
+ * If the given <code>xmlValue</code> contains <code><href></code> elements,
* the relative URI is converted to an absolute one.
*
- * @param value the value to convert in case it is a <code><href></code>
- * value.
+ * @param xmlValue the XMLValue that might contain <code><href></code>
+ * values to convert.
* @param contextPath the context path of the uri. The concatenation of
* <code>serverURL</code>/<code>contextPath</code>
* /<code>uri</code> gives the absolute URL of the resource.
* @param serverURL the URL of the server (e.g. <code>http://www.abc.com</code>).
- *
- * @return the converted value.
*/
- protected static String convertHrefValueToAbsoluteURL(String value, String contextPath, String serverURL) {
+ protected static void convertHrefValueToAbsoluteURL(XMLValue xmlValue, String contextPath, String serverURL) {
- String convertedValue = value;
- if ( (value != null) && (value.startsWith("<"+E_HREF)) ) {
- try {
- XMLValue xmlValue = new XMLValue(value);
+ if (xmlValue != null) {
Iterator iterator = xmlValue.iterator();
Element element = null;
while (iterator.hasNext()) {
@@ -1634,14 +742,9 @@
element.setText(PropertyHelper.getAbsoluteURL(serverURL, contextPath, element.getText()));
}
}
- convertedValue = xmlValue.toString();
- }
- catch (JDOMException e) {
}
}
- return convertedValue;
- }
}
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>