jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bae...@apache.org
Subject svn commit: r1468174 - in /jackrabbit/branches/2.4: ./ jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/server/remoting/davex/JsonWriter.java jackrabbit-spi2dav/src/main/java/org/apache/jackrabbit/spi2davex/RepositoryServiceImpl.java
Date Mon, 15 Apr 2013 18:29:33 GMT
Author: baedke
Date: Mon Apr 15 18:29:32 2013
New Revision: 1468174

URL: http://svn.apache.org/r1468174
Log:
JCR-3551: DavEx cannot handle Double.NaN properties. The DavEx server now sendsNaN and Infinity
as type-hinted strings and spi2devex sends them as parts.

Modified:
    jackrabbit/branches/2.4/   (props changed)
    jackrabbit/branches/2.4/jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/server/remoting/davex/JsonWriter.java
    jackrabbit/branches/2.4/jackrabbit-spi2dav/src/main/java/org/apache/jackrabbit/spi2davex/RepositoryServiceImpl.java

Propchange: jackrabbit/branches/2.4/
------------------------------------------------------------------------------
  Merged /jackrabbit/trunk:r1467363

Modified: jackrabbit/branches/2.4/jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/server/remoting/davex/JsonWriter.java
URL: http://svn.apache.org/viewvc/jackrabbit/branches/2.4/jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/server/remoting/davex/JsonWriter.java?rev=1468174&r1=1468173&r2=1468174&view=diff
==============================================================================
--- jackrabbit/branches/2.4/jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/server/remoting/davex/JsonWriter.java
(original)
+++ jackrabbit/branches/2.4/jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/server/remoting/davex/JsonWriter.java
Mon Apr 15 18:29:32 2013
@@ -16,6 +16,9 @@
  */
 package org.apache.jackrabbit.server.remoting.davex;
 
+import java.io.IOException;
+import java.io.Writer;
+import java.util.Collection;
 import javax.jcr.Node;
 import javax.jcr.NodeIterator;
 import javax.jcr.Property;
@@ -23,9 +26,6 @@ import javax.jcr.PropertyIterator;
 import javax.jcr.PropertyType;
 import javax.jcr.RepositoryException;
 import javax.jcr.Value;
-import java.io.Writer;
-import java.io.IOException;
-import java.util.Collection;
 
 import org.apache.jackrabbit.JcrConstants;
 import org.apache.jackrabbit.commons.json.JsonUtil;
@@ -188,11 +188,11 @@ class JsonWriter {
             }
         } else {
             boolean isMultiple = p.isMultiple();
-            if (requiresTypeInfo(type) || (isMultiple && p.getValues().length ==
0)) {
+            if (requiresTypeInfo(p) || (isMultiple && p.getValues().length == 0))
{
                 /* special property types that have no correspondence in JSON
                    are transported as String. the type is transported with an
                    extra key-value pair, the key having a leading ':' the value
-                   reflects the type. 
+                   reflects the type.
                    the same applies for multivalued properties consisting of an
                    empty array -> property type guessing would not be possible.
                  */
@@ -208,8 +208,8 @@ class JsonWriter {
         }
     }
 
-    private static boolean requiresTypeInfo(int type) {
-        switch (type) {
+    private static boolean requiresTypeInfo(Property p) throws RepositoryException {
+        switch (p.getType()) {
             case PropertyType.NAME:
             case PropertyType.PATH:
             case PropertyType.REFERENCE:
@@ -218,6 +218,22 @@ class JsonWriter {
             case PropertyType.URI:
             case PropertyType.DECIMAL:
                 return true;
+            case PropertyType.DOUBLE:
+                /* Double.NaN, Double.POSITIVE_INFINITY and Double.NEGATIVE_INFINITY
+                   are not defined in JSON, so they have to be serialized as type-hinted
strings.
+                 */
+                if (p.isMultiple()) {
+                    for (Value val : p.getValues()) {
+                        double doubleValue = val.getDouble();
+                        if (Double.isInfinite(doubleValue) || Double.isNaN(doubleValue))
{
+                            return true;
+                        }
+                    }
+                    return false;
+                } else {
+                    double doubleValue = p.getDouble();
+                    return Double.isInfinite(doubleValue) || Double.isNaN(doubleValue);
+                }
             default:
                 // any other property type
                 return false;
@@ -290,9 +306,16 @@ class JsonWriter {
 
             case PropertyType.BOOLEAN:
             case PropertyType.LONG:
-            case PropertyType.DOUBLE:
                 writer.write(v.getString());
                 break;
+            case PropertyType.DOUBLE:
+                double d = v.getDouble();
+                String str = v.getString();
+                if (Double.isNaN(d) || Double.isInfinite(d)) {
+                    str = JsonUtil.getJsonString(str);
+                }
+                writer.write(str);
+                break;
 
             default:
                 writer.write(JsonUtil.getJsonString(v.getString()));

Modified: jackrabbit/branches/2.4/jackrabbit-spi2dav/src/main/java/org/apache/jackrabbit/spi2davex/RepositoryServiceImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/branches/2.4/jackrabbit-spi2dav/src/main/java/org/apache/jackrabbit/spi2davex/RepositoryServiceImpl.java?rev=1468174&r1=1468173&r2=1468174&view=diff
==============================================================================
--- jackrabbit/branches/2.4/jackrabbit-spi2dav/src/main/java/org/apache/jackrabbit/spi2davex/RepositoryServiceImpl.java
(original)
+++ jackrabbit/branches/2.4/jackrabbit-spi2dav/src/main/java/org/apache/jackrabbit/spi2davex/RepositoryServiceImpl.java
Mon Apr 15 18:29:32 2013
@@ -16,6 +16,18 @@
  */
 package org.apache.jackrabbit.spi2davex;
 
+import java.io.IOException;
+import java.io.StringWriter;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import javax.jcr.Credentials;
+import javax.jcr.ItemNotFoundException;
+import javax.jcr.PropertyType;
+import javax.jcr.RepositoryException;
+
 import org.apache.commons.httpclient.HttpClient;
 import org.apache.commons.httpclient.HttpException;
 import org.apache.commons.httpclient.HttpMethod;
@@ -66,18 +78,6 @@ import org.apache.jackrabbit.webdav.prop
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-import javax.jcr.Credentials;
-import javax.jcr.ItemNotFoundException;
-import javax.jcr.PropertyType;
-import javax.jcr.RepositoryException;
-import java.io.IOException;
-import java.io.StringWriter;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-
 /**
  * <code>RepositoryServiceImpl</code>...
  */
@@ -934,9 +934,15 @@ public class RepositoryServiceImpl exten
                     str = value.getString();
                     break;
                 case PropertyType.DOUBLE:
-                    str = value.getString();
-                    if (str.indexOf('.') == -1) {
-                        str += ".0";
+                    double d = value.getDouble();
+                    if (Double.isNaN(d) || Double.isInfinite(d)) {
+                    // JSON cannot specifically handle this property type...
+                        str = null;
+                    } else {
+                        str = value.getString();
+                        if (str.indexOf('.') == -1) {
+                            str += ".0";
+                        }
                     }
                     break;
                 default:



Mime
View raw message