[exo-jcr-commits] exo-jcr SVN: r2793 - in jcr/branches/1.12.x/exo.jcr.component.webdav/src: test/java/org/exoplatform/services/jcr/webdav/command and 1 other directory.

do-not-reply at jboss.org do-not-reply at jboss.org
Thu Jul 15 09:28:42 EDT 2010


Author: dkatayev
Date: 2010-07-15 09:28:41 -0400 (Thu, 15 Jul 2010)
New Revision: 2793

Modified:
   jcr/branches/1.12.x/exo.jcr.component.webdav/src/main/java/org/exoplatform/services/jcr/webdav/xml/PropertyWriteUtil.java
   jcr/branches/1.12.x/exo.jcr.component.webdav/src/test/java/org/exoplatform/services/jcr/webdav/command/TestPropFind.java
Log:
EXOJCR-857 Only special characters in displayname property are decoded.


Modified: jcr/branches/1.12.x/exo.jcr.component.webdav/src/main/java/org/exoplatform/services/jcr/webdav/xml/PropertyWriteUtil.java
===================================================================
--- jcr/branches/1.12.x/exo.jcr.component.webdav/src/main/java/org/exoplatform/services/jcr/webdav/xml/PropertyWriteUtil.java	2010-07-15 09:23:57 UTC (rev 2792)
+++ jcr/branches/1.12.x/exo.jcr.component.webdav/src/main/java/org/exoplatform/services/jcr/webdav/xml/PropertyWriteUtil.java	2010-07-15 13:28:41 UTC (rev 2793)
@@ -26,6 +26,8 @@
 import java.util.Iterator;
 import java.util.Map;
 import java.util.Set;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
 
 import javax.xml.stream.XMLStreamException;
 import javax.xml.stream.XMLStreamWriter;
@@ -133,15 +135,21 @@
          }
 
          writeAttributes(xmlStreamWriter, prop);
-
-         try
+         
+         if (prop.getName().getLocalPart().equals("displayname") && containsEncodedChar(prop.getValue()))
          {
-            xmlStreamWriter.writeCharacters(URLDecoder.decode(prop.getValue(), "UTF-8"));
+            try
+            {
+               xmlStreamWriter.writeCharacters(URLDecoder.decode(prop.getValue(), "UTF-8"));
+            }
+            catch (UnsupportedEncodingException e)
+            {
+               e.printStackTrace();
+            }
+         } else {
+            xmlStreamWriter.writeCharacters(prop.getValue());
          }
-         catch (UnsupportedEncodingException e)
-         {
-            e.printStackTrace();
-         }
+         
          xmlStreamWriter.writeEndElement();
       }
    }
@@ -165,5 +173,17 @@
          xmlStreamWriter.writeAttribute(attrName, attrValue);
       }
    }
+   
+   /**
+    * Checks if string contains encoded characters like %2f.
+    * @param str string to check.
+    * @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);
+      return matcher.find();
+      
+   }
 
 }

Modified: jcr/branches/1.12.x/exo.jcr.component.webdav/src/test/java/org/exoplatform/services/jcr/webdav/command/TestPropFind.java
===================================================================
--- jcr/branches/1.12.x/exo.jcr.component.webdav/src/test/java/org/exoplatform/services/jcr/webdav/command/TestPropFind.java	2010-07-15 09:23:57 UTC (rev 2792)
+++ jcr/branches/1.12.x/exo.jcr.component.webdav/src/test/java/org/exoplatform/services/jcr/webdav/command/TestPropFind.java	2010-07-15 13:28:41 UTC (rev 2793)
@@ -154,6 +154,30 @@
       assertTrue(find.contains(authorProp));
       assertTrue(find.contains(author));
    }
+ 
+   
+   
+   
+   
+   public void testPropWithPercent() throws Exception
+   {
+      String content = TestUtils.getFileContent();
+      String file = TestUtils.getFileName();
+      TestUtils.addContent(session, file, new ByteArrayInputStream(content.getBytes()), nt_webdave_file, "");
+      String authorValue = "bla % bla";
+      TestUtils.addNodeProperty(session, file, authorProp, authorValue);
+      ContainerResponse responseFind =
+         service(WebDAVMethods.PROPFIND, getPathWS() + file, "", null, allPropsXML.getBytes());
+      assertEquals(HTTPStatus.MULTISTATUS, responseFind.getStatus());
+      ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
+      PropFindResponseEntity entity = (PropFindResponseEntity)responseFind.getEntity();
+      entity.write(outputStream);
+      String find = outputStream.toString();
+      assertTrue(find.contains("D:getlastmodified"));
+      assertTrue(find.contains(authorProp));
+      assertTrue(find.contains(authorValue));
+   }
+   
 
    @Override
    protected String getRepositoryName()



More information about the exo-jcr-commits mailing list