Author: dkuleshov
Date: 2010-10-22 11:03:50 -0400 (Fri, 22 Oct 2010)
New Revision: 3340
Modified:
jcr/trunk/exo.jcr.component.webdav/src/main/java/org/exoplatform/services/jcr/webdav/command/PropFindCommand.java
jcr/trunk/exo.jcr.component.webdav/src/main/java/org/exoplatform/services/jcr/webdav/command/propfind/PropFindRequestEntity.java
jcr/trunk/exo.jcr.component.webdav/src/main/java/org/exoplatform/services/jcr/webdav/util/PropertyConstants.java
jcr/trunk/exo.jcr.component.webdav/src/main/java/org/exoplatform/services/jcr/webdav/xml/PropertyWriteUtil.java
jcr/trunk/exo.jcr.component.webdav/src/main/java/org/exoplatform/services/jcr/webdav/xml/PropstatGroupedRepresentation.java
jcr/trunk/exo.jcr.component.webdav/src/test/java/org/exoplatform/services/jcr/webdav/command/TestPropFind.java
Log:
EXOJCR-1013: fixed PROPFIND with allprop and include elements, now response contains
properties from include element
Modified:
jcr/trunk/exo.jcr.component.webdav/src/main/java/org/exoplatform/services/jcr/webdav/command/PropFindCommand.java
===================================================================
---
jcr/trunk/exo.jcr.component.webdav/src/main/java/org/exoplatform/services/jcr/webdav/command/PropFindCommand.java 2010-10-22
14:48:36 UTC (rev 3339)
+++
jcr/trunk/exo.jcr.component.webdav/src/main/java/org/exoplatform/services/jcr/webdav/command/PropFindCommand.java 2010-10-22
15:03:50 UTC (rev 3340)
@@ -28,6 +28,7 @@
import org.exoplatform.services.jcr.webdav.resource.ResourceUtil;
import org.exoplatform.services.jcr.webdav.resource.VersionedCollectionResource;
import org.exoplatform.services.jcr.webdav.resource.VersionedFileResource;
+import org.exoplatform.services.jcr.webdav.util.PropertyConstants;
import org.exoplatform.services.jcr.webdav.util.TextUtil;
import org.exoplatform.services.jcr.webdav.xml.WebDavNamespaceContext;
import org.exoplatform.services.log.ExoLogger;
@@ -144,6 +145,10 @@
{
response = new PropFindResponseEntity(depth, resource, null, false);
}
+ else if (request.getType().equalsIgnoreCase("include"))
+ {
+ response = new PropFindResponseEntity(depth, resource, propertyNames(body),
false);
+ }
else if (request.getType().equalsIgnoreCase("propname"))
{
response = new PropFindResponseEntity(depth, resource, null, true);
@@ -171,8 +176,17 @@
{
HashSet<QName> names = new HashSet<QName>();
- HierarchicalProperty propBody = body.getChild(0);
+ HierarchicalProperty propBody =
body.getChild(PropertyConstants.DAV_ALLPROP_INCLUDE);
+ if (propBody != null)
+ {
+ names.add(PropertyConstants.DAV_ALLPROP_INCLUDE);
+ }
+ else
+ {
+ propBody = body.getChild(0);
+ }
+
List<HierarchicalProperty> properties = propBody.getChildren();
Iterator<HierarchicalProperty> propIter = properties.iterator();
while (propIter.hasNext())
Modified:
jcr/trunk/exo.jcr.component.webdav/src/main/java/org/exoplatform/services/jcr/webdav/command/propfind/PropFindRequestEntity.java
===================================================================
---
jcr/trunk/exo.jcr.component.webdav/src/main/java/org/exoplatform/services/jcr/webdav/command/propfind/PropFindRequestEntity.java 2010-10-22
14:48:36 UTC (rev 3339)
+++
jcr/trunk/exo.jcr.component.webdav/src/main/java/org/exoplatform/services/jcr/webdav/command/propfind/PropFindRequestEntity.java 2010-10-22
15:03:50 UTC (rev 3340)
@@ -19,6 +19,7 @@
package org.exoplatform.services.jcr.webdav.command.propfind;
import org.exoplatform.common.util.HierarchicalProperty;
+import org.exoplatform.services.jcr.webdav.util.PropertyConstants;
import javax.xml.namespace.QName;
@@ -60,6 +61,11 @@
return "allprop";
}
+ if (input.getChild(PropertyConstants.DAV_ALLPROP_INCLUDE) != null)
+ {
+ return "include";
+ }
+
QName name = input.getChild(0).getName();
if (name.getNamespaceURI().equals("DAV:"))
return name.getLocalPart();
Modified:
jcr/trunk/exo.jcr.component.webdav/src/main/java/org/exoplatform/services/jcr/webdav/util/PropertyConstants.java
===================================================================
---
jcr/trunk/exo.jcr.component.webdav/src/main/java/org/exoplatform/services/jcr/webdav/util/PropertyConstants.java 2010-10-22
14:48:36 UTC (rev 3339)
+++
jcr/trunk/exo.jcr.component.webdav/src/main/java/org/exoplatform/services/jcr/webdav/util/PropertyConstants.java 2010-10-22
15:03:50 UTC (rev 3340)
@@ -207,6 +207,20 @@
QName IS_READ_ONLY = new QName("DAV:", "isreadonly");
/**
+ * dav:include element for dav:allprop of PROPFIND method
+ * See <a
href='http://www.webdav.org/specs/rfc4918.html#METHOD_PROPFIND'&g... Extensions
for Web Distributed Authoring
+ * and Versioning (WebDAV)</a> for more information..
+ */
+ QName DAV_ALLPROP_INCLUDE = new QName("DAV:", "include");
+
+ /**
+ * dav:allprop element for dav:allprop of PROPFIND method
+ * See <a
href='http://www.webdav.org/specs/rfc4918.html#METHOD_PROPFIND'&g... Extensions
for Web Distributed Authoring
+ * and Versioning (WebDAV)</a> for more information..
+ */
+ QName DAV_ALLPROP = new QName("DAV:", "allprop");
+
+ /**
* Creation date pattern.
*/
String CREATION_PATTERN = "yyyy-MM-dd'T'HH:mm:ss'Z'";
Modified:
jcr/trunk/exo.jcr.component.webdav/src/main/java/org/exoplatform/services/jcr/webdav/xml/PropertyWriteUtil.java
===================================================================
---
jcr/trunk/exo.jcr.component.webdav/src/main/java/org/exoplatform/services/jcr/webdav/xml/PropertyWriteUtil.java 2010-10-22
14:48:36 UTC (rev 3339)
+++
jcr/trunk/exo.jcr.component.webdav/src/main/java/org/exoplatform/services/jcr/webdav/xml/PropertyWriteUtil.java 2010-10-22
15:03:50 UTC (rev 3340)
@@ -41,6 +41,7 @@
public class PropertyWriteUtil
{
+ private final static Pattern ESCAPE_PATTERN =
Pattern.compile("%[0-9a-fA-F]{2}");
/**
* Writes the statuses of properties into XML.
@@ -180,8 +181,7 @@
* @return <code>true</code> if string contains encoded characters,
otherwise returns <code>false</code>
*/
private static boolean containsEncodedChar(String str){
- Pattern p = Pattern.compile("%[0-9a-fA-F]{2}");
- Matcher matcher = p.matcher(str);
+ Matcher matcher = ESCAPE_PATTERN.matcher(str);
return matcher.find();
}
Modified:
jcr/trunk/exo.jcr.component.webdav/src/main/java/org/exoplatform/services/jcr/webdav/xml/PropstatGroupedRepresentation.java
===================================================================
---
jcr/trunk/exo.jcr.component.webdav/src/main/java/org/exoplatform/services/jcr/webdav/xml/PropstatGroupedRepresentation.java 2010-10-22
14:48:36 UTC (rev 3339)
+++
jcr/trunk/exo.jcr.component.webdav/src/main/java/org/exoplatform/services/jcr/webdav/xml/PropstatGroupedRepresentation.java 2010-10-22
15:03:50 UTC (rev 3340)
@@ -131,7 +131,11 @@
}
else
{
-
+ if (propNames.contains(PropertyConstants.DAV_ALLPROP_INCLUDE))
+ {
+ propStats.put(statname, resource.getProperties(namesOnly));
+ propNames.remove(PropertyConstants.DAV_ALLPROP_INCLUDE);
+ }
for (QName propName : propNames)
{
HierarchicalProperty prop = new HierarchicalProperty(propName);
Modified:
jcr/trunk/exo.jcr.component.webdav/src/test/java/org/exoplatform/services/jcr/webdav/command/TestPropFind.java
===================================================================
---
jcr/trunk/exo.jcr.component.webdav/src/test/java/org/exoplatform/services/jcr/webdav/command/TestPropFind.java 2010-10-22
14:48:36 UTC (rev 3339)
+++
jcr/trunk/exo.jcr.component.webdav/src/test/java/org/exoplatform/services/jcr/webdav/command/TestPropFind.java 2010-10-22
15:03:50 UTC (rev 3340)
@@ -62,6 +62,9 @@
private String allPropsXML =
"<?xml version=\"1.0\" encoding=\"utf-8\"
?><D:propfind
xmlns:D=\"DAV:\"><D:allprop/></D:propfind>";
+ private String allPropsWithInclusionXML = "<?xml version=\"1.0\"
encoding=\"utf-8\" ?><D:propfind xmlns:D=\"DAV:\">"
+ +
"<D:allprop/><D:include><D:lockdiscovery/><D:supported-method-set/></D:include></D:propfind>";
+
public void setUp() throws Exception
{
super.setUp();
@@ -155,6 +158,34 @@
assertTrue(find.contains(author));
}
+ public void testAllPropsWithInclusion() throws Exception
+ {
+
+ String content = TestUtils.getFileContent();
+ String file = TestUtils.getFileName();
+ Node node =
+ TestUtils.addContent(session, file, new
ByteArrayInputStream(content.getBytes()), nt_webdave_file, "");
+
+ node.addMixin("mix:lockable");
+ node.save();
+ node.lock(true, false);
+ node.getPath();
+ node.getName();
+
+ MultivaluedMap<String, String> headers = new MultivaluedMapImpl();
+ headers.add(HttpHeaders.CONTENT_TYPE, "text/xml");
+ ContainerResponse responseFind =
+ service(WebDAVMethods.PROPFIND, getPathWS() + file, "", null,
allPropsWithInclusionXML.getBytes());
+ assertEquals(HTTPStatus.MULTISTATUS, responseFind.getStatus());
+ ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
+ PropFindResponseEntity entity = (PropFindResponseEntity)responseFind.getEntity();
+ entity.write(outputStream);
+ String find = outputStream.toString();
+ System.out.println("\n" + find);
+ assertTrue(find.contains("D:lockdiscovery"));
+ assertTrue(find.contains("D:supported-method-set"));
+
+ }
public void testPropfindWrongDataFormat() throws Exception
{