[dna-commits] DNA SVN: r1199 - trunk/extensions/dna-web-jcr-rest/src/main/java/org/jboss/dna/web/jcr/rest.

dna-commits at lists.jboss.org dna-commits at lists.jboss.org
Wed Sep 9 20:02:49 EDT 2009


Author: rhauch
Date: 2009-09-09 20:02:49 -0400 (Wed, 09 Sep 2009)
New Revision: 1199

Modified:
   trunk/extensions/dna-web-jcr-rest/src/main/java/org/jboss/dna/web/jcr/rest/JcrResources.java
Log:
DNA-513 REST server does not correctly encode binary values

Changed the JcrResources class to have the '/base64/' string in a constant.

Modified: trunk/extensions/dna-web-jcr-rest/src/main/java/org/jboss/dna/web/jcr/rest/JcrResources.java
===================================================================
--- trunk/extensions/dna-web-jcr-rest/src/main/java/org/jboss/dna/web/jcr/rest/JcrResources.java	2009-09-10 00:02:26 UTC (rev 1198)
+++ trunk/extensions/dna-web-jcr-rest/src/main/java/org/jboss/dna/web/jcr/rest/JcrResources.java	2009-09-10 00:02:49 UTC (rev 1199)
@@ -157,6 +157,8 @@
 @Path( "/" )
 public class JcrResources {
 
+    private static final String BASE64_ENCODING_SUFFIX = "/base64/";
+
     private static final UrlEncoder URL_ENCODER = new UrlEncoder();
 
     private static final String PROPERTIES_HOLDER = "properties";
@@ -352,7 +354,7 @@
             valueObject = encoded ? jsonEncodedStringFor(value) : value.getString();
         }
         String propertyName = property.getName();
-        if (encoded) propertyName = propertyName + "/base64/";
+        if (encoded) propertyName = propertyName + BASE64_ENCODING_SUFFIX;
         JSONObject jsonProperty = new JSONObject();
         jsonProperty.put(propertyName, valueObject);
         return jsonProperty;
@@ -414,7 +416,7 @@
                         break;
                     }
                 }
-                if (encoded) propName = propName + "/base64/";
+                if (encoded) propName = propName + BASE64_ENCODING_SUFFIX;
                 JSONArray array = new JSONArray();
                 for (int i = 0; i < values.length; i++) {
                     array.put(encoded ? jsonEncodedStringFor(values[i]) : values[i].getString());
@@ -424,7 +426,7 @@
             } else {
                 Value value = prop.getValue();
                 encoded = value.getType() == PropertyType.BINARY;
-                if (encoded) propName = propName + "/base64/";
+                if (encoded) propName = propName + BASE64_ENCODING_SUFFIX;
                 properties.put(propName, encoded ? jsonEncodedStringFor(value) : value.getString());
             }
 
@@ -605,9 +607,9 @@
                                     String propName,
                                     Object value ) throws RepositoryException, JSONException {
         // Are the property values encoded ?
-        boolean encoded = propName.endsWith("/base64/");
+        boolean encoded = propName.endsWith(BASE64_ENCODING_SUFFIX);
         if (encoded) {
-            int newLength = propName.length() - "/base64/".length();
+            int newLength = propName.length() - BASE64_ENCODING_SUFFIX.length();
             propName = newLength > 0 ? propName.substring(0, newLength) : "";
         }
 
@@ -767,7 +769,7 @@
             Property property = (Property)item;
             String propertyName = property.getName();
             JSONObject jsonProperty = new JSONObject(requestContent);
-            String jsonPropertyName = jsonProperty.has(propertyName) ? propertyName : propertyName + "/base64/";
+            String jsonPropertyName = jsonProperty.has(propertyName) ? propertyName : propertyName + BASE64_ENCODING_SUFFIX;
             node = property.getParent();
             setPropertyOnNode(node, jsonPropertyName, jsonProperty.get(jsonPropertyName));
         }



More information about the dna-commits mailing list