chemistry-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From f...@apache.org
Subject svn commit: r1301758 [1/2] - in /chemistry/opencmis/trunk: chemistry-opencmis-client/chemistry-opencmis-client-bindings/src/main/java/org/apache/chemistry/opencmis/client/bindings/spi/browser/ chemistry-opencmis-commons/chemistry-opencmis-commons-impl/...
Date Fri, 16 Mar 2012 21:02:28 GMT
Author: fmui
Date: Fri Mar 16 21:02:27 2012
New Revision: 1301758

URL: http://svn.apache.org/viewvc?rev=1301758&view=rev
Log:
- Moved JSON library source code into OpenCMIS and modified the code to prevent data loss (BigInteger and BigDecimal)
- Several JSON code optimizations

Added:
    chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-impl/src/main/java/org/apache/chemistry/opencmis/commons/impl/json/
    chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-impl/src/main/java/org/apache/chemistry/opencmis/commons/impl/json/JSONArray.java   (with props)
    chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-impl/src/main/java/org/apache/chemistry/opencmis/commons/impl/json/JSONAware.java   (with props)
    chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-impl/src/main/java/org/apache/chemistry/opencmis/commons/impl/json/JSONObject.java   (with props)
    chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-impl/src/main/java/org/apache/chemistry/opencmis/commons/impl/json/JSONStreamAware.java   (with props)
    chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-impl/src/main/java/org/apache/chemistry/opencmis/commons/impl/json/JSONValue.java   (with props)
    chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-impl/src/main/java/org/apache/chemistry/opencmis/commons/impl/json/parser/
    chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-impl/src/main/java/org/apache/chemistry/opencmis/commons/impl/json/parser/ContainerFactory.java   (with props)
    chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-impl/src/main/java/org/apache/chemistry/opencmis/commons/impl/json/parser/ContentHandler.java   (with props)
    chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-impl/src/main/java/org/apache/chemistry/opencmis/commons/impl/json/parser/JSONParseException.java   (with props)
    chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-impl/src/main/java/org/apache/chemistry/opencmis/commons/impl/json/parser/JSONParser.java   (with props)
    chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-impl/src/main/java/org/apache/chemistry/opencmis/commons/impl/json/parser/Yylex.java   (with props)
    chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-impl/src/main/java/org/apache/chemistry/opencmis/commons/impl/json/parser/Yytoken.java   (with props)
Modified:
    chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-bindings/src/main/java/org/apache/chemistry/opencmis/client/bindings/spi/browser/AbstractBrowserBindingService.java
    chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-impl/pom.xml
    chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-impl/src/main/java/org/apache/chemistry/opencmis/commons/impl/JSONConverter.java
    chemistry/opencmis/trunk/chemistry-opencmis-dist/src/main/resources/NOTICE
    chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/impl/browser/AclService.java
    chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/impl/browser/BrowserBindingUtils.java
    chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/impl/browser/CmisBrowserBindingServlet.java
    chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/impl/browser/DiscoveryService.java
    chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/impl/browser/MultiFilingService.java
    chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/impl/browser/NavigationService.java
    chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/impl/browser/ObjectService.java
    chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/impl/browser/PolicyService.java
    chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/impl/browser/RelationshipService.java
    chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/impl/browser/RepositoryService.java
    chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/impl/browser/VersioningService.java
    chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/shared/Dispatcher.java

Modified: chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-bindings/src/main/java/org/apache/chemistry/opencmis/client/bindings/spi/browser/AbstractBrowserBindingService.java
URL: http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-bindings/src/main/java/org/apache/chemistry/opencmis/client/bindings/spi/browser/AbstractBrowserBindingService.java?rev=1301758&r1=1301757&r2=1301758&view=diff
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-bindings/src/main/java/org/apache/chemistry/opencmis/client/bindings/spi/browser/AbstractBrowserBindingService.java (original)
+++ chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-bindings/src/main/java/org/apache/chemistry/opencmis/client/bindings/spi/browser/AbstractBrowserBindingService.java Fri Mar 16 21:02:27 2012
@@ -53,9 +53,9 @@ import org.apache.chemistry.opencmis.com
 import org.apache.chemistry.opencmis.commons.impl.JSONConverter;
 import org.apache.chemistry.opencmis.commons.impl.UrlBuilder;
 import org.apache.chemistry.opencmis.commons.impl.dataobjects.RepositoryInfoBrowserBindingImpl;
-import org.json.simple.JSONObject;
-import org.json.simple.parser.ContainerFactory;
-import org.json.simple.parser.JSONParser;
+import org.apache.chemistry.opencmis.commons.impl.json.JSONObject;
+import org.apache.chemistry.opencmis.commons.impl.json.parser.ContainerFactory;
+import org.apache.chemistry.opencmis.commons.impl.json.parser.JSONParser;
 
 /**
  * Base class for all Browser Binding client services.
@@ -63,14 +63,12 @@ import org.json.simple.parser.JSONParser
 public abstract class AbstractBrowserBindingService implements LinkAccess {
 
     protected static final ContainerFactory SIMPLE_CONTAINER_FACTORY = new ContainerFactory() {
-        @SuppressWarnings("rawtypes")
-        public Map createObjectContainer() {
-            return new LinkedHashMap();
+        public Map<String, Object> createObjectContainer() {
+            return new LinkedHashMap<String, Object>();
         }
 
-        @SuppressWarnings("rawtypes")
-        public List creatArrayContainer() {
-            return new ArrayList();
+        public List<Object> creatArrayContainer() {
+            return new ArrayList<Object>();
         }
     };
 

Modified: chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-impl/pom.xml
URL: http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-impl/pom.xml?rev=1301758&r1=1301757&r2=1301758&view=diff
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-impl/pom.xml (original)
+++ chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-impl/pom.xml Fri Mar 16 21:02:27 2012
@@ -43,11 +43,6 @@
             <version>2.1.7</version>
             <scope>compile</scope>
         </dependency>
-        <dependency>
-             <groupId>com.googlecode.json-simple</groupId>
-             <artifactId>json-simple</artifactId>
-             <version>1.1</version>
-        </dependency>
     </dependencies>
 
     <build>

Modified: chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-impl/src/main/java/org/apache/chemistry/opencmis/commons/impl/JSONConverter.java
URL: http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-impl/src/main/java/org/apache/chemistry/opencmis/commons/impl/JSONConverter.java?rev=1301758&r1=1301757&r2=1301758&view=diff
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-impl/src/main/java/org/apache/chemistry/opencmis/commons/impl/JSONConverter.java (original)
+++ chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-impl/src/main/java/org/apache/chemistry/opencmis/commons/impl/JSONConverter.java Fri Mar 16 21:02:27 2012
@@ -143,8 +143,8 @@ import org.apache.chemistry.opencmis.com
 import org.apache.chemistry.opencmis.commons.impl.dataobjects.RepositoryInfoBrowserBindingImpl;
 import org.apache.chemistry.opencmis.commons.impl.dataobjects.TypeDefinitionContainerImpl;
 import org.apache.chemistry.opencmis.commons.impl.dataobjects.TypeDefinitionListImpl;
-import org.json.simple.JSONArray;
-import org.json.simple.JSONObject;
+import org.apache.chemistry.opencmis.commons.impl.json.JSONArray;
+import org.apache.chemistry.opencmis.commons.impl.json.JSONObject;
 
 /**
  * OpenCMIS objects to JSON converter.
@@ -160,7 +160,6 @@ public class JSONConverter {
     /**
      * Converts a repository info object.
      */
-    @SuppressWarnings("unchecked")
     public static JSONObject convert(RepositoryInfo repositoryInfo, String repositoryUrl, String rootUrl) {
         if (repositoryInfo == null) {
             return null;
@@ -204,7 +203,6 @@ public class JSONConverter {
     /**
      * Converts a capabilities object.
      */
-    @SuppressWarnings("unchecked")
     public static JSONObject convert(RepositoryCapabilities capabilities) {
         if (capabilities == null) {
             return null;
@@ -236,7 +234,6 @@ public class JSONConverter {
     /**
      * Converts an ACL capabilities object.
      */
-    @SuppressWarnings("unchecked")
     public static JSONObject convert(AclCapabilities capabilities) {
         if (capabilities == null) {
             return null;
@@ -823,7 +820,6 @@ public class JSONConverter {
     /**
      * Converts an object.
      */
-    @SuppressWarnings("unchecked")
     public static JSONObject convert(ObjectData object, TypeCache typeCache, boolean isQueryResult) {
         if (object == null) {
             return null;
@@ -903,7 +899,6 @@ public class JSONConverter {
     /**
      * Converts a bag of properties.
      */
-    @SuppressWarnings("unchecked")
     public static JSONObject convert(Properties properties, String objectId, TypeCache typeCache, boolean isQueryResult) {
         if (properties == null) {
             return null;
@@ -933,7 +928,6 @@ public class JSONConverter {
     /**
      * Converts a property.
      */
-    @SuppressWarnings("unchecked")
     public static JSONObject convert(PropertyData<?> property, PropertyDefinition<?> propDef) {
         if (property == null) {
             return null;
@@ -987,7 +981,6 @@ public class JSONConverter {
     /**
      * Converts allowable actions.
      */
-    @SuppressWarnings("unchecked")
     public static JSONObject convert(AllowableActions allowableActions) {
         if (allowableActions == null) {
             return null;
@@ -1008,7 +1001,6 @@ public class JSONConverter {
     /**
      * Converts an ACL.
      */
-    @SuppressWarnings("unchecked")
     public static JSONObject convert(Acl acl) {
         if ((acl == null) || (acl.getAces() == null)) {
             return null;
@@ -1046,7 +1038,6 @@ public class JSONConverter {
     /**
      * Converts a rendition.
      */
-    @SuppressWarnings("unchecked")
     public static JSONObject convert(RenditionData rendition) {
         if (rendition == null) {
             return null;
@@ -1071,7 +1062,6 @@ public class JSONConverter {
     /**
      * Converts a query object list.
      */
-    @SuppressWarnings("unchecked")
     public static JSONObject convert(ObjectList list, TypeCache typeCache, boolean isQueryResult) {
         if (list == null) {
             return null;
@@ -1106,7 +1096,6 @@ public class JSONConverter {
     /**
      * Converts an object in a folder list.
      */
-    @SuppressWarnings("unchecked")
     public static JSONObject convert(ObjectInFolderData objectInFolder, TypeCache typeCache) {
         if ((objectInFolder == null) || (objectInFolder.getObject() == null)) {
             return null;
@@ -1124,7 +1113,6 @@ public class JSONConverter {
     /**
      * Converts a folder list.
      */
-    @SuppressWarnings("unchecked")
     public static JSONObject convert(ObjectInFolderList objectInFolderList, TypeCache typeCache) {
         if (objectInFolderList == null) {
             return null;
@@ -1153,7 +1141,6 @@ public class JSONConverter {
     /**
      * Converts a folder container.
      */
-    @SuppressWarnings("unchecked")
     public static JSONObject convert(ObjectInFolderContainer container, TypeCache typeCache) {
         if (container == null) {
             return null;
@@ -1179,7 +1166,6 @@ public class JSONConverter {
     /**
      * Converts an object parent.
      */
-    @SuppressWarnings("unchecked")
     public static JSONObject convert(ObjectParentData parent, TypeCache typeCache) {
         if ((parent == null) || (parent.getObject() == null)) {
             return null;
@@ -1199,7 +1185,6 @@ public class JSONConverter {
     /**
      * Converts a type definition.
      */
-    @SuppressWarnings("unchecked")
     public static JSONObject convert(TypeDefinition type) {
         if (type == null) {
             return null;
@@ -1253,7 +1238,6 @@ public class JSONConverter {
     /**
      * Converts a property type definition.
      */
-    @SuppressWarnings("unchecked")
     public static JSONObject convert(PropertyDefinition<?> propertyDefinition) {
         if (propertyDefinition == null) {
             return null;
@@ -1336,7 +1320,6 @@ public class JSONConverter {
     /**
      * Converts choices.
      */
-    @SuppressWarnings("unchecked")
     private static <T> JSONArray convertChoices(List<Choice<T>> choices, Cardinality cardinality) {
         if (choices == null) {
             return null;
@@ -1374,7 +1357,6 @@ public class JSONConverter {
     /**
      * Converts a type definition list.
      */
-    @SuppressWarnings("unchecked")
     public static JSONObject convert(TypeDefinitionList list) {
         if (list == null) {
             return null;
@@ -1434,7 +1416,6 @@ public class JSONConverter {
     /**
      * Converts a type definition container.
      */
-    @SuppressWarnings("unchecked")
     public static JSONObject convert(TypeDefinitionContainer container) {
         if (container == null) {
             return null;
@@ -1755,8 +1736,8 @@ public class JSONConverter {
                         if (values != null) {
                             propertyValues = new ArrayList<BigInteger>();
                             for (Object obj : values) {
-                                if (obj instanceof Number) {
-                                    propertyValues.add(BigInteger.valueOf(((Number) obj).longValue()));
+                                if (obj instanceof BigInteger) {
+                                    propertyValues.add((BigInteger) obj);
                                 } else {
                                     throw new CmisRuntimeException("Invalid property value: " + obj);
                                 }
@@ -1772,10 +1753,8 @@ public class JSONConverter {
                         if (values != null) {
                             propertyValues = new ArrayList<BigDecimal>();
                             for (Object obj : values) {
-                                if (obj instanceof Double) {
-                                    propertyValues.add(BigDecimal.valueOf((Double) obj));
-                                } else if (obj instanceof Number) {
-                                    propertyValues.add(BigDecimal.valueOf(((Number) obj).longValue()));
+                                if (obj instanceof BigDecimal) {
+                                    propertyValues.add((BigDecimal) obj);
                                 } else {
                                     throw new CmisRuntimeException("Invalid property value: " + obj);
                                 }
@@ -2063,7 +2042,6 @@ public class JSONConverter {
     /**
      * Converts FailedToDelete ids.
      */
-    @SuppressWarnings("unchecked")
     public static JSONObject convert(FailedToDeleteData ftd) {
         if (ftd == null) {
             return null;
@@ -2115,7 +2093,6 @@ public class JSONConverter {
 
     // -----------------------------------------------------------------
 
-    @SuppressWarnings("unchecked")
     public static void convertExtension(ExtensionsData source, JSONObject target) {
         if (source == null || source.getExtensions() == null) {
             return;
@@ -2130,7 +2107,6 @@ public class JSONConverter {
         }
     }
 
-    @SuppressWarnings("unchecked")
     private static JSONObject convertExtensionList(List<CmisExtensionElement> extensionList) {
         if (extensionList == null) {
             return null;
@@ -2270,15 +2246,13 @@ public class JSONConverter {
             }
             throw new CmisRuntimeException("Invalid Boolean value!");
         case INTEGER:
-            if (value instanceof Number) {
-                return BigInteger.valueOf(((Number) value).longValue());
+            if (value instanceof BigInteger) {
+                return (BigInteger) value;
             }
             throw new CmisRuntimeException("Invalid Integer value!");
         case DECIMAL:
-            if (value instanceof Double) {
-                return BigDecimal.valueOf((Double) value);
-            } else if (value instanceof Number) {
-                return BigDecimal.valueOf(((Number) value).longValue());
+            if (value instanceof BigDecimal) {
+                return (BigDecimal) value;
             }
             throw new CmisRuntimeException("Invalid Decimal value!");
         case DATETIME:
@@ -2293,7 +2267,6 @@ public class JSONConverter {
         throw new CmisRuntimeException("Unkown property type!");
     }
 
-    @SuppressWarnings("unchecked")
     public static JSONArray getJSONArrayFromList(List<?> list) {
         if (list == null) {
             return null;
@@ -2327,7 +2300,6 @@ public class JSONConverter {
         return null;
     }
 
-    @SuppressWarnings("unchecked")
     public static void setIfNotNull(String name, Object obj, JSONObject json) {
         if (obj != null) {
             json.put(name, obj);
@@ -2362,12 +2334,12 @@ public class JSONConverter {
                 + (o instanceof List ? "JSON object" : o.getClass().getSimpleName()) + ": " + o.toString());
     }
 
-    public static String getString(@SuppressWarnings("rawtypes") Map json, String key) {
+    public static String getString(Map<String, Object> json, String key) {
         Object obj = json.get(key);
         return obj == null ? null : obj.toString();
     }
 
-    public static Boolean getBoolean(@SuppressWarnings("rawtypes") Map json, String key) {
+    public static Boolean getBoolean(Map<String, Object> json, String key) {
         Object obj = json.get(key);
 
         if (obj instanceof Boolean) {
@@ -2377,29 +2349,27 @@ public class JSONConverter {
         return null;
     }
 
-    public static BigInteger getInteger(@SuppressWarnings("rawtypes") Map json, String key) {
+    public static BigInteger getInteger(Map<String, Object> json, String key) {
         Object obj = json.get(key);
 
-        if (obj instanceof Number) {
-            return BigInteger.valueOf(((Number) obj).longValue());
+        if (obj instanceof BigInteger) {
+            return (BigInteger) obj;
         }
 
         return null;
     }
 
-    public static BigDecimal getDecimal(@SuppressWarnings("rawtypes") Map json, String key) {
+    public static BigDecimal getDecimal(Map<String, Object> json, String key) {
         Object obj = json.get(key);
 
-        if (obj instanceof Double) {
-            return BigDecimal.valueOf((Double) obj);
-        } else if (obj instanceof Number) {
-            return BigDecimal.valueOf(((Number) obj).longValue());
+        if (obj instanceof BigDecimal) {
+            return (BigDecimal) obj;
         }
 
         return null;
     }
 
-    public static GregorianCalendar getDateTime(@SuppressWarnings("rawtypes") Map json, String key) {
+    public static GregorianCalendar getDateTime(Map<String, Object> json, String key) {
         Object obj = json.get(key);
 
         if (obj instanceof Number) {
@@ -2412,7 +2382,7 @@ public class JSONConverter {
     }
 
     @SuppressWarnings("unchecked")
-    public static <T extends Enum<T>> T getEnum(@SuppressWarnings("rawtypes") Map json, String key, Class<T> clazz) {
+    public static <T extends Enum<T>> T getEnum(Map<String, Object> json, String key, Class<T> clazz) {
         String value = getString(json, key);
         if (value == null) {
             return null;

Added: chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-impl/src/main/java/org/apache/chemistry/opencmis/commons/impl/json/JSONArray.java
URL: http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-impl/src/main/java/org/apache/chemistry/opencmis/commons/impl/json/JSONArray.java?rev=1301758&view=auto
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-impl/src/main/java/org/apache/chemistry/opencmis/commons/impl/json/JSONArray.java (added)
+++ chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-impl/src/main/java/org/apache/chemistry/opencmis/commons/impl/json/JSONArray.java Fri Mar 16 21:02:27 2012
@@ -0,0 +1,120 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.chemistry.opencmis.commons.impl.json;
+
+import java.io.IOException;
+import java.io.Writer;
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * A JSON array. JSONObject supports java.util.List interface.
+ * 
+ * (Taken from JSON.simple <http://code.google.com/p/json-simple/> and modified
+ * for OpenCMIS.)
+ * 
+ * @author FangYidong<fangyidong@yahoo.com.cn>
+ */
+public class JSONArray extends ArrayList<Object> implements List<Object>, JSONAware, JSONStreamAware {
+    private static final long serialVersionUID = 3957988303675231981L;
+
+    /**
+     * Encode a list into JSON text and write it to out. If this list is also a
+     * JSONStreamAware or a JSONAware, JSONStreamAware and JSONAware specific
+     * behaviours will be ignored at this top level.
+     * 
+     * @see org.json.simple.JSONValue#writeJSONString(Object, Writer)
+     * 
+     * @param list
+     * @param out
+     */
+    public static void writeJSONString(List<Object> list, Writer out) throws IOException {
+        if (list == null) {
+            out.write("null");
+            return;
+        }
+
+        boolean first = true;
+
+        out.write('[');
+        for (Object value : list) {
+            if (first) {
+                first = false;
+            } else {
+                out.write(',');
+            }
+
+            if (value == null) {
+                out.write("null");
+                continue;
+            }
+
+            JSONValue.writeJSONString(value, out);
+        }
+        out.write(']');
+    }
+
+    public void writeJSONString(Writer out) throws IOException {
+        writeJSONString(this, out);
+    }
+
+    /**
+     * Convert a list to JSON text. The result is a JSON array. If this list is
+     * also a JSONAware, JSONAware specific behaviours will be omitted at this
+     * top level.
+     * 
+     * @see org.json.simple.JSONValue#toJSONString(Object)
+     * 
+     * @param list
+     * @return JSON text, or "null" if list is null.
+     */
+    public static String toJSONString(List<Object> list) {
+        if (list == null) {
+            return "null";
+        }
+
+        boolean first = true;
+        StringBuilder sb = new StringBuilder();
+
+        sb.append('[');
+        for (Object value : list) {
+            if (first) {
+                first = false;
+            } else {
+                sb.append(',');
+            }
+
+            if (value == null) {
+                sb.append("null");
+                continue;
+            }
+            sb.append(JSONValue.toJSONString(value));
+        }
+        sb.append(']');
+        return sb.toString();
+    }
+
+    public String toJSONString() {
+        return toJSONString(this);
+    }
+
+    public String toString() {
+        return toJSONString();
+    }
+}

Propchange: chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-impl/src/main/java/org/apache/chemistry/opencmis/commons/impl/json/JSONArray.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-impl/src/main/java/org/apache/chemistry/opencmis/commons/impl/json/JSONAware.java
URL: http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-impl/src/main/java/org/apache/chemistry/opencmis/commons/impl/json/JSONAware.java?rev=1301758&view=auto
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-impl/src/main/java/org/apache/chemistry/opencmis/commons/impl/json/JSONAware.java (added)
+++ chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-impl/src/main/java/org/apache/chemistry/opencmis/commons/impl/json/JSONAware.java Fri Mar 16 21:02:27 2012
@@ -0,0 +1,35 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.chemistry.opencmis.commons.impl.json;
+
+/**
+ * Beans that support customized output of JSON text shall implement this
+ * interface.
+ * 
+ * (Taken from JSON.simple <http://code.google.com/p/json-simple/> and modified
+ * for OpenCMIS.)
+ * 
+ * @author FangYidong<fangyidong@yahoo.com.cn>
+ */
+public interface JSONAware {
+    /**
+     * @return JSON text
+     */
+    String toJSONString();
+}

Propchange: chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-impl/src/main/java/org/apache/chemistry/opencmis/commons/impl/json/JSONAware.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-impl/src/main/java/org/apache/chemistry/opencmis/commons/impl/json/JSONObject.java
URL: http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-impl/src/main/java/org/apache/chemistry/opencmis/commons/impl/json/JSONObject.java?rev=1301758&view=auto
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-impl/src/main/java/org/apache/chemistry/opencmis/commons/impl/json/JSONObject.java (added)
+++ chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-impl/src/main/java/org/apache/chemistry/opencmis/commons/impl/json/JSONObject.java Fri Mar 16 21:02:27 2012
@@ -0,0 +1,152 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.chemistry.opencmis.commons.impl.json;
+
+import java.io.IOException;
+import java.io.Writer;
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * A JSON object. Key value pairs are unordered. JSONObject supports
+ * java.util.Map interface.
+ * 
+ * (Taken from JSON.simple <http://code.google.com/p/json-simple/> and modified
+ * for OpenCMIS.)
+ * 
+ * @author FangYidong<fangyidong@yahoo.com.cn>
+ */
+public class JSONObject extends HashMap<String, Object> implements Map<String, Object>, JSONAware, JSONStreamAware {
+    private static final long serialVersionUID = -503443796854799292L;
+
+    /**
+     * Encode a map into JSON text and write it to out. If this map is also a
+     * JSONAware or JSONStreamAware, JSONAware or JSONStreamAware specific
+     * behaviours will be ignored at this top level.
+     * 
+     * @see org.json.simple.JSONValue#writeJSONString(Object, Writer)
+     * 
+     * @param map
+     * @param out
+     */
+    public static void writeJSONString(Map<String, Object> map, Writer out) throws IOException {
+        if (map == null) {
+            out.write("null");
+            return;
+        }
+
+        boolean first = true;
+
+        out.write('{');
+        for (Map.Entry<String, Object> entry : map.entrySet()) {
+            if (first) {
+                first = false;
+            } else {
+                out.write(',');
+            }
+
+            out.write('\"');
+            out.write(escape(entry.getKey()));
+            out.write('\"');
+            out.write(':');
+            JSONValue.writeJSONString(entry.getValue(), out);
+        }
+        out.write('}');
+    }
+
+    public void writeJSONString(Writer out) throws IOException {
+        writeJSONString(this, out);
+    }
+
+    /**
+     * Convert a map to JSON text. The result is a JSON object. If this map is
+     * also a JSONAware, JSONAware specific behaviours will be omitted at this
+     * top level.
+     * 
+     * @see org.json.simple.JSONValue#toJSONString(Object)
+     * 
+     * @param map
+     * @return JSON text, or "null" if map is null.
+     */
+    public static String toJSONString(Map<String, Object> map) {
+        if (map == null) {
+            return "null";
+        }
+
+        StringBuilder sb = new StringBuilder();
+        boolean first = true;
+
+        sb.append('{');
+        for (Map.Entry<String, Object> entry : map.entrySet()) {
+            if (first) {
+                first = false;
+            } else {
+                sb.append(',');
+            }
+
+            toJSONString(entry.getKey(), entry.getValue(), sb);
+        }
+        sb.append('}');
+
+        return sb.toString();
+    }
+
+    public String toJSONString() {
+        return toJSONString(this);
+    }
+
+    private static String toJSONString(String key, Object value, StringBuilder sb) {
+        sb.append('\"');
+        if (key == null) {
+            sb.append("null");
+        } else {
+            JSONValue.escape(key, sb);
+        }
+
+        sb.append('\"').append(':');
+
+        sb.append(JSONValue.toJSONString(value));
+
+        return sb.toString();
+    }
+
+    public String toString() {
+        return toJSONString();
+    }
+
+    public static String toString(String key, Object value) {
+        StringBuilder sb = new StringBuilder();
+        toJSONString(key, value, sb);
+        return sb.toString();
+    }
+
+    /**
+     * Escape quotes, \, /, \r, \n, \b, \f, \t and other control characters
+     * (U+0000 through U+001F). It's the same as JSONValue.escape() only for
+     * compatibility here.
+     * 
+     * @see JSONValue#escape(String)
+     * 
+     * @param s
+     * @return
+     */
+    public static String escape(String s) {
+        return JSONValue.escape(s);
+    }
+}

Propchange: chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-impl/src/main/java/org/apache/chemistry/opencmis/commons/impl/json/JSONObject.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-impl/src/main/java/org/apache/chemistry/opencmis/commons/impl/json/JSONStreamAware.java
URL: http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-impl/src/main/java/org/apache/chemistry/opencmis/commons/impl/json/JSONStreamAware.java?rev=1301758&view=auto
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-impl/src/main/java/org/apache/chemistry/opencmis/commons/impl/json/JSONStreamAware.java (added)
+++ chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-impl/src/main/java/org/apache/chemistry/opencmis/commons/impl/json/JSONStreamAware.java Fri Mar 16 21:02:27 2012
@@ -0,0 +1,38 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.chemistry.opencmis.commons.impl.json;
+
+import java.io.IOException;
+import java.io.Writer;
+
+/**
+ * Beans that support customized output of JSON text to a writer shall implement
+ * this interface.
+ * 
+ * (Taken from JSON.simple <http://code.google.com/p/json-simple/> and modified
+ * for OpenCMIS.)
+ * 
+ * @author FangYidong<fangyidong@yahoo.com.cn>
+ */
+public interface JSONStreamAware {
+    /**
+     * write JSON string to out.
+     */
+    void writeJSONString(Writer out) throws IOException;
+}

Propchange: chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-impl/src/main/java/org/apache/chemistry/opencmis/commons/impl/json/JSONStreamAware.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-impl/src/main/java/org/apache/chemistry/opencmis/commons/impl/json/JSONValue.java
URL: http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-impl/src/main/java/org/apache/chemistry/opencmis/commons/impl/json/JSONValue.java?rev=1301758&view=auto
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-impl/src/main/java/org/apache/chemistry/opencmis/commons/impl/json/JSONValue.java (added)
+++ chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-impl/src/main/java/org/apache/chemistry/opencmis/commons/impl/json/JSONValue.java Fri Mar 16 21:02:27 2012
@@ -0,0 +1,312 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.chemistry.opencmis.commons.impl.json;
+
+import java.io.IOException;
+import java.io.Reader;
+import java.io.StringReader;
+import java.io.Writer;
+import java.math.BigDecimal;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.chemistry.opencmis.commons.impl.json.parser.JSONParser;
+import org.apache.chemistry.opencmis.commons.impl.json.parser.JSONParseException;
+
+/**
+ * (Taken from JSON.simple <http://code.google.com/p/json-simple/> and modified
+ * for OpenCMIS.)
+ * 
+ * @author FangYidong<fangyidong@yahoo.com.cn>
+ */
+public class JSONValue {
+    /**
+     * Parse JSON text into java object from the input source. Please use
+     * parseWithException() if you don't want to ignore the exception.
+     * 
+     * @see org.json.simple.parser.JSONParser#parse(Reader)
+     * @see #parseWithException(Reader)
+     * 
+     * @param in
+     * @return Instance of the following: org.json.simple.JSONObject,
+     *         org.json.simple.JSONArray, java.lang.String, java.lang.Number,
+     *         java.lang.Boolean, null
+     * 
+     */
+    public static Object parse(Reader in) {
+        try {
+            JSONParser parser = new JSONParser();
+            return parser.parse(in);
+        } catch (Exception e) {
+            return null;
+        }
+    }
+
+    public static Object parse(String s) {
+        StringReader in = new StringReader(s);
+        return parse(in);
+    }
+
+    /**
+     * Parse JSON text into java object from the input source.
+     * 
+     * @see org.json.simple.parser.JSONParser
+     * 
+     * @param in
+     * @return Instance of the following: org.json.simple.JSONObject,
+     *         org.json.simple.JSONArray, java.lang.String, java.lang.Number,
+     *         java.lang.Boolean, null
+     * 
+     * @throws IOException
+     * @throws JSONParseException
+     */
+    public static Object parseWithException(Reader in) throws IOException, JSONParseException {
+        JSONParser parser = new JSONParser();
+        return parser.parse(in);
+    }
+
+    public static Object parseWithException(String s) throws JSONParseException {
+        JSONParser parser = new JSONParser();
+        return parser.parse(s);
+    }
+
+    /**
+     * Encode an object into JSON text and write it to out.
+     * <p>
+     * If this object is a Map or a List, and it's also a JSONStreamAware or a
+     * JSONAware, JSONStreamAware or JSONAware will be considered firstly.
+     * <p>
+     * DO NOT call this method from writeJSONString(Writer) of a class that
+     * implements both JSONStreamAware and (Map or List) with "this" as the
+     * first parameter, use JSONObject.writeJSONString(Map, Writer) or
+     * JSONArray.writeJSONString(List, Writer) instead.
+     * 
+     * @see org.json.simple.JSONObject#writeJSONString(Map, Writer)
+     * @see org.json.simple.JSONArray#writeJSONString(List, Writer)
+     * 
+     * @param value
+     * @param writer
+     */
+    @SuppressWarnings("unchecked")
+    public static void writeJSONString(Object value, Writer out) throws IOException {
+        if (value == null) {
+            out.write("null");
+            return;
+        }
+
+        if (value instanceof String) {
+            out.write('\"');
+            out.write(escape((String) value));
+            out.write('\"');
+            return;
+        }
+
+        if (value instanceof Double) {
+            if (((Double) value).isInfinite() || ((Double) value).isNaN()) {
+                out.write("null");
+            } else {
+                out.write(value.toString());
+            }
+            return;
+        }
+
+        if (value instanceof Float) {
+            if (((Float) value).isInfinite() || ((Float) value).isNaN()) {
+                out.write("null");
+            } else {
+                out.write(value.toString());
+            }
+            return;
+        }
+
+        if (value instanceof BigDecimal) {
+            out.write(((BigDecimal) value).toPlainString());
+            return;
+        }
+
+        if (value instanceof Number) {
+            out.write(value.toString());
+            return;
+        }
+
+        if (value instanceof Boolean) {
+            out.write(value.toString());
+            return;
+        }
+
+        if (value instanceof JSONStreamAware) {
+            ((JSONStreamAware) value).writeJSONString(out);
+            return;
+        }
+
+        if (value instanceof JSONAware) {
+            out.write(((JSONAware) value).toJSONString());
+            return;
+        }
+
+        if (value instanceof Map) {
+            JSONObject.writeJSONString((Map<String, Object>) value, out);
+            return;
+        }
+
+        if (value instanceof List) {
+            JSONArray.writeJSONString((List<Object>) value, out);
+            return;
+        }
+
+        out.write(value.toString());
+    }
+
+    /**
+     * Convert an object to JSON text.
+     * <p>
+     * If this object is a Map or a List, and it's also a JSONAware, JSONAware
+     * will be considered firstly.
+     * <p>
+     * DO NOT call this method from toJSONString() of a class that implements
+     * both JSONAware and Map or List with "this" as the parameter, use
+     * JSONObject.toJSONString(Map) or JSONArray.toJSONString(List) instead.
+     * 
+     * @see org.json.simple.JSONObject#toJSONString(Map)
+     * @see org.json.simple.JSONArray#toJSONString(List)
+     * 
+     * @param value
+     * @return JSON text, or "null" if value is null or it's an NaN or an INF
+     *         number.
+     */
+    @SuppressWarnings("unchecked")
+    public static String toJSONString(Object value) {
+        if (value == null) {
+            return "null";
+        }
+
+        if (value instanceof String) {
+            return "\"" + escape((String) value) + "\"";
+        }
+
+        if (value instanceof Double) {
+            if (((Double) value).isInfinite() || ((Double) value).isNaN()) {
+                return "null";
+            } else {
+                return value.toString();
+            }
+        }
+
+        if (value instanceof Float) {
+            if (((Float) value).isInfinite() || ((Float) value).isNaN()) {
+                return "null";
+            } else {
+                return value.toString();
+            }
+        }
+
+        if (value instanceof BigDecimal) {
+            return ((BigDecimal) value).toPlainString();
+        }
+
+        if (value instanceof Number) {
+            return value.toString();
+        }
+
+        if (value instanceof Boolean) {
+            return value.toString();
+        }
+
+        if (value instanceof JSONAware) {
+            return ((JSONAware) value).toJSONString();
+        }
+
+        if (value instanceof Map) {
+            return JSONObject.toJSONString((Map<String, Object>) value);
+        }
+
+        if (value instanceof List) {
+            return JSONArray.toJSONString((List<Object>) value);
+        }
+
+        return value.toString();
+    }
+
+    /**
+     * Escape quotes, \, /, \r, \n, \b, \f, \t and other control characters
+     * (U+0000 through U+001F).
+     * 
+     * @param s
+     * @return
+     */
+    public static String escape(String s) {
+        if (s == null) {
+            return null;
+        }
+
+        StringBuilder sb = new StringBuilder();
+        escape(s, sb);
+        return sb.toString();
+    }
+
+    /**
+     * @param s
+     *            - Must not be null.
+     * @param sb
+     */
+    static void escape(String s, StringBuilder sb) {
+        for (int i = 0; i < s.length(); i++) {
+            char ch = s.charAt(i);
+            switch (ch) {
+            case '"':
+                sb.append("\\\"");
+                break;
+            case '\\':
+                sb.append("\\\\");
+                break;
+            case '\b':
+                sb.append("\\b");
+                break;
+            case '\f':
+                sb.append("\\f");
+                break;
+            case '\n':
+                sb.append("\\n");
+                break;
+            case '\r':
+                sb.append("\\r");
+                break;
+            case '\t':
+                sb.append("\\t");
+                break;
+            case '/':
+                sb.append("\\/");
+                break;
+            default:
+                // Reference: http://www.unicode.org/versions/Unicode5.1.0/
+                if ((ch >= '\u0000' && ch <= '\u001F') || (ch >= '\u007F' && ch <= '\u009F')
+                        || (ch >= '\u2000' && ch <= '\u20FF')) {
+                    String ss = Integer.toHexString(ch);
+                    sb.append("\\u");
+                    for (int k = 0; k < 4 - ss.length(); k++) {
+                        sb.append('0');
+                    }
+                    sb.append(ss.toUpperCase());
+                } else {
+                    sb.append(ch);
+                }
+            }
+        }// for
+    }
+}

Propchange: chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-impl/src/main/java/org/apache/chemistry/opencmis/commons/impl/json/JSONValue.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-impl/src/main/java/org/apache/chemistry/opencmis/commons/impl/json/parser/ContainerFactory.java
URL: http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-impl/src/main/java/org/apache/chemistry/opencmis/commons/impl/json/parser/ContainerFactory.java?rev=1301758&view=auto
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-impl/src/main/java/org/apache/chemistry/opencmis/commons/impl/json/parser/ContainerFactory.java (added)
+++ chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-impl/src/main/java/org/apache/chemistry/opencmis/commons/impl/json/parser/ContainerFactory.java Fri Mar 16 21:02:27 2012
@@ -0,0 +1,46 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.chemistry.opencmis.commons.impl.json.parser;
+
+import java.util.List;
+import java.util.Map;
+
+/**
+ * Container factory for creating containers for JSON object and JSON array.
+ * 
+ * (Taken from JSON.simple <http://code.google.com/p/json-simple/> and modified
+ * for OpenCMIS.)
+ * 
+ * @see JSONParser#parse(java.io.Reader, ContainerFactory)
+ * 
+ * @author FangYidong<fangyidong@yahoo.com.cn>
+ */
+public interface ContainerFactory {
+    /**
+     * @return A Map instance to store JSON object, or null if you want to use
+     *         JSONObject.
+     */
+    Map<String, Object> createObjectContainer();
+
+    /**
+     * @return A List instance to store JSON array, or null if you want to use
+     *         JSONArray.
+     */
+    List<Object> creatArrayContainer();
+}

Propchange: chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-impl/src/main/java/org/apache/chemistry/opencmis/commons/impl/json/parser/ContainerFactory.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-impl/src/main/java/org/apache/chemistry/opencmis/commons/impl/json/parser/ContentHandler.java
URL: http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-impl/src/main/java/org/apache/chemistry/opencmis/commons/impl/json/parser/ContentHandler.java?rev=1301758&view=auto
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-impl/src/main/java/org/apache/chemistry/opencmis/commons/impl/json/parser/ContentHandler.java (added)
+++ chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-impl/src/main/java/org/apache/chemistry/opencmis/commons/impl/json/parser/ContentHandler.java Fri Mar 16 21:02:27 2012
@@ -0,0 +1,129 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.chemistry.opencmis.commons.impl.json.parser;
+
+import java.io.IOException;
+
+/**
+ * A simplified and stoppable SAX-like content handler for stream processing of
+ * JSON text.
+ * 
+ * (Taken from JSON.simple <http://code.google.com/p/json-simple/> and modified
+ * for OpenCMIS.)
+ * 
+ * @see org.xml.sax.ContentHandler
+ * @see JSONParser#parse(java.io.Reader, ContentHandler, boolean)
+ * 
+ * @author FangYidong<fangyidong@yahoo.com.cn>
+ */
+public interface ContentHandler {
+    /**
+     * Receive notification of the beginning of JSON processing. The parser will
+     * invoke this method only once.
+     * 
+     * @throws JSONParseException
+     *             - JSONParser will stop and throw the same exception to the
+     *             caller when receiving this exception.
+     */
+    void startJSON() throws JSONParseException, IOException;
+
+    /**
+     * Receive notification of the end of JSON processing.
+     * 
+     * @throws JSONParseException
+     */
+    void endJSON() throws JSONParseException, IOException;
+
+    /**
+     * Receive notification of the beginning of a JSON object.
+     * 
+     * @return false if the handler wants to stop parsing after return.
+     * @throws JSONParseException
+     *             - JSONParser will stop and throw the same exception to the
+     *             caller when receiving this exception.
+     * @see #endJSON
+     */
+    boolean startObject() throws JSONParseException, IOException;
+
+    /**
+     * Receive notification of the end of a JSON object.
+     * 
+     * @return false if the handler wants to stop parsing after return.
+     * @throws JSONParseException
+     * 
+     * @see #startObject
+     */
+    boolean endObject() throws JSONParseException, IOException;
+
+    /**
+     * Receive notification of the beginning of a JSON object entry.
+     * 
+     * @param key
+     *            - Key of a JSON object entry.
+     * 
+     * @return false if the handler wants to stop parsing after return.
+     * @throws JSONParseException
+     * 
+     * @see #endObjectEntry
+     */
+    boolean startObjectEntry(String key) throws JSONParseException, IOException;
+
+    /**
+     * Receive notification of the end of the value of previous object entry.
+     * 
+     * @return false if the handler wants to stop parsing after return.
+     * @throws JSONParseException
+     * 
+     * @see #startObjectEntry
+     */
+    boolean endObjectEntry() throws JSONParseException, IOException;
+
+    /**
+     * Receive notification of the beginning of a JSON array.
+     * 
+     * @return false if the handler wants to stop parsing after return.
+     * @throws JSONParseException
+     * 
+     * @see #endArray
+     */
+    boolean startArray() throws JSONParseException, IOException;
+
+    /**
+     * Receive notification of the end of a JSON array.
+     * 
+     * @return false if the handler wants to stop parsing after return.
+     * @throws JSONParseException
+     * 
+     * @see #startArray
+     */
+    boolean endArray() throws JSONParseException, IOException;
+
+    /**
+     * Receive notification of the JSON primitive values: java.lang.String,
+     * java.lang.Number, java.lang.Boolean null
+     * 
+     * @param value
+     *            - Instance of the following: java.lang.String,
+     *            java.lang.Number, java.lang.Boolean null
+     * 
+     * @return false if the handler wants to stop parsing after return.
+     * @throws JSONParseException
+     */
+    boolean primitive(Object value) throws JSONParseException, IOException;
+}

Propchange: chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-impl/src/main/java/org/apache/chemistry/opencmis/commons/impl/json/parser/ContentHandler.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-impl/src/main/java/org/apache/chemistry/opencmis/commons/impl/json/parser/JSONParseException.java
URL: http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-impl/src/main/java/org/apache/chemistry/opencmis/commons/impl/json/parser/JSONParseException.java?rev=1301758&view=auto
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-impl/src/main/java/org/apache/chemistry/opencmis/commons/impl/json/parser/JSONParseException.java (added)
+++ chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-impl/src/main/java/org/apache/chemistry/opencmis/commons/impl/json/parser/JSONParseException.java Fri Mar 16 21:02:27 2012
@@ -0,0 +1,113 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.chemistry.opencmis.commons.impl.json.parser;
+
+/**
+ * ParseException explains why and where the error occurs in source JSON text.
+ * 
+ * (Taken from JSON.simple <http://code.google.com/p/json-simple/> and modified
+ * for OpenCMIS.)
+ * 
+ * @author FangYidong<fangyidong@yahoo.com.cn>
+ */
+public class JSONParseException extends Exception {
+    private static final long serialVersionUID = -7880698968187728548L;
+
+    public static final int ERROR_UNEXPECTED_CHAR = 0;
+    public static final int ERROR_UNEXPECTED_TOKEN = 1;
+    public static final int ERROR_UNEXPECTED_EXCEPTION = 2;
+
+    private int errorType;
+    private Object unexpectedObject;
+    private int position;
+
+    public JSONParseException(int errorType) {
+        this(-1, errorType, null);
+    }
+
+    public JSONParseException(int errorType, Object unexpectedObject) {
+        this(-1, errorType, unexpectedObject);
+    }
+
+    public JSONParseException(int position, int errorType, Object unexpectedObject) {
+        this.position = position;
+        this.errorType = errorType;
+        this.unexpectedObject = unexpectedObject;
+    }
+
+    public int getErrorType() {
+        return errorType;
+    }
+
+    public void setErrorType(int errorType) {
+        this.errorType = errorType;
+    }
+
+    /**
+     * @see org.json.simple.parser.JSONParser#getPosition()
+     * 
+     * @return The character position (starting with 0) of the input where the
+     *         error occurs.
+     */
+    public int getPosition() {
+        return position;
+    }
+
+    public void setPosition(int position) {
+        this.position = position;
+    }
+
+    /**
+     * @see org.json.simple.parser.Yytoken
+     * 
+     * @return One of the following base on the value of errorType:
+     *         ERROR_UNEXPECTED_CHAR java.lang.Character ERROR_UNEXPECTED_TOKEN
+     *         org.json.simple.parser.Yytoken ERROR_UNEXPECTED_EXCEPTION
+     *         java.lang.Exception
+     */
+    public Object getUnexpectedObject() {
+        return unexpectedObject;
+    }
+
+    public void setUnexpectedObject(Object unexpectedObject) {
+        this.unexpectedObject = unexpectedObject;
+    }
+
+    public String toString() {
+        StringBuilder sb = new StringBuilder();
+
+        switch (errorType) {
+        case ERROR_UNEXPECTED_CHAR:
+            sb.append("Unexpected character (").append(unexpectedObject).append(") at position ").append(position)
+                    .append(".");
+            break;
+        case ERROR_UNEXPECTED_TOKEN:
+            sb.append("Unexpected token ").append(unexpectedObject).append(" at position ").append(position)
+                    .append(".");
+            break;
+        case ERROR_UNEXPECTED_EXCEPTION:
+            sb.append("Unexpected exception at position ").append(position).append(": ").append(unexpectedObject);
+            break;
+        default:
+            sb.append("Unkown error at position ").append(position).append(".");
+            break;
+        }
+        return sb.toString();
+    }
+}

Propchange: chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-impl/src/main/java/org/apache/chemistry/opencmis/commons/impl/json/parser/JSONParseException.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-impl/src/main/java/org/apache/chemistry/opencmis/commons/impl/json/parser/JSONParser.java
URL: http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-impl/src/main/java/org/apache/chemistry/opencmis/commons/impl/json/parser/JSONParser.java?rev=1301758&view=auto
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-impl/src/main/java/org/apache/chemistry/opencmis/commons/impl/json/parser/JSONParser.java (added)
+++ chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-impl/src/main/java/org/apache/chemistry/opencmis/commons/impl/json/parser/JSONParser.java Fri Mar 16 21:02:27 2012
@@ -0,0 +1,547 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.chemistry.opencmis.commons.impl.json.parser;
+
+import java.io.IOException;
+import java.io.Reader;
+import java.io.StringReader;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.chemistry.opencmis.commons.impl.json.JSONArray;
+import org.apache.chemistry.opencmis.commons.impl.json.JSONObject;
+
+/**
+ * Parser for JSON text. Please note that JSONParser is NOT thread-safe.
+ * 
+ * (Taken from JSON.simple <http://code.google.com/p/json-simple/> and modified
+ * for OpenCMIS.)
+ * 
+ * @author FangYidong<fangyidong@yahoo.com.cn>
+ */
+public class JSONParser {
+    public static final int S_INIT = 0;
+    public static final int S_IN_FINISHED_VALUE = 1;// string,number,boolean,null,object,array
+    public static final int S_IN_OBJECT = 2;
+    public static final int S_IN_ARRAY = 3;
+    public static final int S_PASSED_PAIR_KEY = 4;
+    public static final int S_IN_PAIR_VALUE = 5;
+    public static final int S_END = 6;
+    public static final int S_IN_ERROR = -1;
+
+    private LinkedList<Integer> handlerStatusStack;
+    private Yylex lexer = new Yylex((Reader) null);
+    private Yytoken token = null;
+    private int status = S_INIT;
+
+    private int peekStatus(LinkedList<Integer> statusStack) {
+        if (statusStack.size() == 0) {
+            return -1;
+        }
+
+        return statusStack.getFirst();
+    }
+
+    /**
+     * Reset the parser to the initial state without resetting the underlying
+     * reader.
+     * 
+     */
+    public void reset() {
+        token = null;
+        status = S_INIT;
+        handlerStatusStack = null;
+    }
+
+    /**
+     * Reset the parser to the initial state with a new character reader.
+     * 
+     * @param in
+     *            - The new character reader.
+     * @throws IOException
+     * @throws JSONParseException
+     */
+    public void reset(Reader in) {
+        lexer.yyreset(in);
+        reset();
+    }
+
+    /**
+     * @return The position of the beginning of the current token.
+     */
+    public int getPosition() {
+        return lexer.getPosition();
+    }
+
+    public Object parse(String s) throws JSONParseException {
+        return parse(s, (ContainerFactory) null);
+    }
+
+    public Object parse(String s, ContainerFactory containerFactory) throws JSONParseException {
+        StringReader in = new StringReader(s);
+        try {
+            return parse(in, containerFactory);
+        } catch (IOException ie) {
+            /*
+             * Actually it will never happen.
+             */
+            throw new JSONParseException(-1, JSONParseException.ERROR_UNEXPECTED_EXCEPTION, ie);
+        }
+    }
+
+    public Object parse(Reader in) throws IOException, JSONParseException {
+        return parse(in, (ContainerFactory) null);
+    }
+
+    /**
+     * Parse JSON text into java object from the input source.
+     * 
+     * @param in
+     * @param containerFactory
+     *            - Use this factory to createyour own JSON object and JSON
+     *            array containers.
+     * @return Instance of the following: org.json.simple.JSONObject,
+     *         org.json.simple.JSONArray, java.lang.String, java.lang.Number,
+     *         java.lang.Boolean, null
+     * 
+     * @throws IOException
+     * @throws JSONParseException
+     */
+    @SuppressWarnings("unchecked")
+    public Object parse(Reader in, ContainerFactory containerFactory) throws IOException, JSONParseException {
+        reset(in);
+        LinkedList<Integer> statusStack = new LinkedList<Integer>();
+        LinkedList<Object> valueStack = new LinkedList<Object>();
+
+        try {
+            do {
+                nextToken();
+                switch (status) {
+                case S_INIT:
+                    switch (token.type) {
+                    case Yytoken.TYPE_VALUE:
+                        status = S_IN_FINISHED_VALUE;
+                        statusStack.addFirst(new Integer(status));
+                        valueStack.addFirst(token.value);
+                        break;
+                    case Yytoken.TYPE_LEFT_BRACE:
+                        status = S_IN_OBJECT;
+                        statusStack.addFirst(new Integer(status));
+                        valueStack.addFirst(createObjectContainer(containerFactory));
+                        break;
+                    case Yytoken.TYPE_LEFT_SQUARE:
+                        status = S_IN_ARRAY;
+                        statusStack.addFirst(new Integer(status));
+                        valueStack.addFirst(createArrayContainer(containerFactory));
+                        break;
+                    default:
+                        status = S_IN_ERROR;
+                    }// inner switch
+                    break;
+
+                case S_IN_FINISHED_VALUE:
+                    if (token.type == Yytoken.TYPE_EOF)
+                        return valueStack.removeFirst();
+                    else
+                        throw new JSONParseException(getPosition(), JSONParseException.ERROR_UNEXPECTED_TOKEN, token);
+
+                case S_IN_OBJECT:
+                    switch (token.type) {
+                    case Yytoken.TYPE_COMMA:
+                        break;
+                    case Yytoken.TYPE_VALUE:
+                        if (token.value instanceof String) {
+                            String key = (String) token.value;
+                            valueStack.addFirst(key);
+                            status = S_PASSED_PAIR_KEY;
+                            statusStack.addFirst(new Integer(status));
+                        } else {
+                            status = S_IN_ERROR;
+                        }
+                        break;
+                    case Yytoken.TYPE_RIGHT_BRACE:
+                        if (valueStack.size() > 1) {
+                            statusStack.removeFirst();
+                            valueStack.removeFirst();
+                            status = peekStatus(statusStack);
+                        } else {
+                            status = S_IN_FINISHED_VALUE;
+                        }
+                        break;
+                    default:
+                        status = S_IN_ERROR;
+                        break;
+                    }// inner switch
+                    break;
+
+                case S_PASSED_PAIR_KEY:
+                    switch (token.type) {
+                    case Yytoken.TYPE_COLON:
+                        break;
+                    case Yytoken.TYPE_VALUE:
+                        statusStack.removeFirst();
+                        String key = (String) valueStack.removeFirst();
+                        Map<String, Object> parent = (Map<String, Object>) valueStack.getFirst();
+                        parent.put(key, token.value);
+                        status = peekStatus(statusStack);
+                        break;
+                    case Yytoken.TYPE_LEFT_SQUARE:
+                        statusStack.removeFirst();
+                        key = (String) valueStack.removeFirst();
+                        parent = (Map<String, Object>) valueStack.getFirst();
+                        List<Object> newArray = createArrayContainer(containerFactory);
+                        parent.put(key, newArray);
+                        status = S_IN_ARRAY;
+                        statusStack.addFirst(new Integer(status));
+                        valueStack.addFirst(newArray);
+                        break;
+                    case Yytoken.TYPE_LEFT_BRACE:
+                        statusStack.removeFirst();
+                        key = (String) valueStack.removeFirst();
+                        parent = (Map<String, Object>) valueStack.getFirst();
+                        Map<String, Object> newObject = createObjectContainer(containerFactory);
+                        parent.put(key, newObject);
+                        status = S_IN_OBJECT;
+                        statusStack.addFirst(new Integer(status));
+                        valueStack.addFirst(newObject);
+                        break;
+                    default:
+                        status = S_IN_ERROR;
+                    }
+                    break;
+
+                case S_IN_ARRAY:
+                    switch (token.type) {
+                    case Yytoken.TYPE_COMMA:
+                        break;
+                    case Yytoken.TYPE_VALUE:
+                        List<Object> val = (List<Object>) valueStack.getFirst();
+                        val.add(token.value);
+                        break;
+                    case Yytoken.TYPE_RIGHT_SQUARE:
+                        if (valueStack.size() > 1) {
+                            statusStack.removeFirst();
+                            valueStack.removeFirst();
+                            status = peekStatus(statusStack);
+                        } else {
+                            status = S_IN_FINISHED_VALUE;
+                        }
+                        break;
+                    case Yytoken.TYPE_LEFT_BRACE:
+                        val = (List<Object>) valueStack.getFirst();
+                        Map<String, Object> newObject = createObjectContainer(containerFactory);
+                        val.add(newObject);
+                        status = S_IN_OBJECT;
+                        statusStack.addFirst(new Integer(status));
+                        valueStack.addFirst(newObject);
+                        break;
+                    case Yytoken.TYPE_LEFT_SQUARE:
+                        val = (List<Object>) valueStack.getFirst();
+                        List<Object> newArray = createArrayContainer(containerFactory);
+                        val.add(newArray);
+                        status = S_IN_ARRAY;
+                        statusStack.addFirst(new Integer(status));
+                        valueStack.addFirst(newArray);
+                        break;
+                    default:
+                        status = S_IN_ERROR;
+                    }// inner switch
+                    break;
+                case S_IN_ERROR:
+                    throw new JSONParseException(getPosition(), JSONParseException.ERROR_UNEXPECTED_TOKEN, token);
+                }// switch
+                if (status == S_IN_ERROR) {
+                    throw new JSONParseException(getPosition(), JSONParseException.ERROR_UNEXPECTED_TOKEN, token);
+                }
+            } while (token.type != Yytoken.TYPE_EOF);
+        } catch (IOException ie) {
+            throw ie;
+        }
+
+        throw new JSONParseException(getPosition(), JSONParseException.ERROR_UNEXPECTED_TOKEN, token);
+    }
+
+    private void nextToken() throws JSONParseException, IOException {
+        token = lexer.yylex();
+        if (token == null)
+            token = new Yytoken(Yytoken.TYPE_EOF, null);
+    }
+
+    private Map<String, Object> createObjectContainer(ContainerFactory containerFactory) {
+        if (containerFactory == null) {
+            return new JSONObject();
+        }
+
+        Map<String, Object> m = containerFactory.createObjectContainer();
+
+        if (m == null) {
+            return new JSONObject();
+        }
+
+        return m;
+    }
+
+    private List<Object> createArrayContainer(ContainerFactory containerFactory) {
+        if (containerFactory == null) {
+            return new JSONArray();
+        }
+
+        List<Object> l = containerFactory.creatArrayContainer();
+
+        if (l == null) {
+            return new JSONArray();
+        }
+
+        return l;
+    }
+
+    public void parse(String s, ContentHandler contentHandler) throws JSONParseException {
+        parse(s, contentHandler, false);
+    }
+
+    public void parse(String s, ContentHandler contentHandler, boolean isResume) throws JSONParseException {
+        StringReader in = new StringReader(s);
+        try {
+            parse(in, contentHandler, isResume);
+        } catch (IOException ie) {
+            /*
+             * Actually it will never happen.
+             */
+            throw new JSONParseException(-1, JSONParseException.ERROR_UNEXPECTED_EXCEPTION, ie);
+        }
+    }
+
+    public void parse(Reader in, ContentHandler contentHandler) throws IOException, JSONParseException {
+        parse(in, contentHandler, false);
+    }
+
+    /**
+     * Stream processing of JSON text.
+     * 
+     * @see ContentHandler
+     * 
+     * @param in
+     * @param contentHandler
+     * @param isResume
+     *            - Indicates if it continues previous parsing operation. If set
+     *            to true, resume parsing the old stream, and parameter 'in'
+     *            will be ignored. If this method is called for the first time
+     *            in this instance, isResume will be ignored.
+     * 
+     * @throws IOException
+     * @throws JSONParseException
+     */
+    public void parse(Reader in, ContentHandler contentHandler, boolean isResume) throws IOException, JSONParseException {
+        if (!isResume) {
+            reset(in);
+            handlerStatusStack = new LinkedList<Integer>();
+        } else {
+            if (handlerStatusStack == null) {
+                isResume = false;
+                reset(in);
+                handlerStatusStack = new LinkedList<Integer>();
+            }
+        }
+
+        LinkedList<Integer> statusStack = handlerStatusStack;
+
+        try {
+            do {
+                switch (status) {
+                case S_INIT:
+                    contentHandler.startJSON();
+                    nextToken();
+                    switch (token.type) {
+                    case Yytoken.TYPE_VALUE:
+                        status = S_IN_FINISHED_VALUE;
+                        statusStack.addFirst(new Integer(status));
+                        if (!contentHandler.primitive(token.value))
+                            return;
+                        break;
+                    case Yytoken.TYPE_LEFT_BRACE:
+                        status = S_IN_OBJECT;
+                        statusStack.addFirst(new Integer(status));
+                        if (!contentHandler.startObject())
+                            return;
+                        break;
+                    case Yytoken.TYPE_LEFT_SQUARE:
+                        status = S_IN_ARRAY;
+                        statusStack.addFirst(new Integer(status));
+                        if (!contentHandler.startArray())
+                            return;
+                        break;
+                    default:
+                        status = S_IN_ERROR;
+                    }// inner switch
+                    break;
+
+                case S_IN_FINISHED_VALUE:
+                    nextToken();
+                    if (token.type == Yytoken.TYPE_EOF) {
+                        contentHandler.endJSON();
+                        status = S_END;
+                        return;
+                    } else {
+                        status = S_IN_ERROR;
+                        throw new JSONParseException(getPosition(), JSONParseException.ERROR_UNEXPECTED_TOKEN, token);
+                    }
+
+                case S_IN_OBJECT:
+                    nextToken();
+                    switch (token.type) {
+                    case Yytoken.TYPE_COMMA:
+                        break;
+                    case Yytoken.TYPE_VALUE:
+                        if (token.value instanceof String) {
+                            String key = (String) token.value;
+                            status = S_PASSED_PAIR_KEY;
+                            statusStack.addFirst(new Integer(status));
+                            if (!contentHandler.startObjectEntry(key))
+                                return;
+                        } else {
+                            status = S_IN_ERROR;
+                        }
+                        break;
+                    case Yytoken.TYPE_RIGHT_BRACE:
+                        if (statusStack.size() > 1) {
+                            statusStack.removeFirst();
+                            status = peekStatus(statusStack);
+                        } else {
+                            status = S_IN_FINISHED_VALUE;
+                        }
+                        if (!contentHandler.endObject())
+                            return;
+                        break;
+                    default:
+                        status = S_IN_ERROR;
+                        break;
+                    }// inner switch
+                    break;
+
+                case S_PASSED_PAIR_KEY:
+                    nextToken();
+                    switch (token.type) {
+                    case Yytoken.TYPE_COLON:
+                        break;
+                    case Yytoken.TYPE_VALUE:
+                        statusStack.removeFirst();
+                        status = peekStatus(statusStack);
+                        if (!contentHandler.primitive(token.value))
+                            return;
+                        if (!contentHandler.endObjectEntry())
+                            return;
+                        break;
+                    case Yytoken.TYPE_LEFT_SQUARE:
+                        statusStack.removeFirst();
+                        statusStack.addFirst(new Integer(S_IN_PAIR_VALUE));
+                        status = S_IN_ARRAY;
+                        statusStack.addFirst(new Integer(status));
+                        if (!contentHandler.startArray())
+                            return;
+                        break;
+                    case Yytoken.TYPE_LEFT_BRACE:
+                        statusStack.removeFirst();
+                        statusStack.addFirst(new Integer(S_IN_PAIR_VALUE));
+                        status = S_IN_OBJECT;
+                        statusStack.addFirst(new Integer(status));
+                        if (!contentHandler.startObject())
+                            return;
+                        break;
+                    default:
+                        status = S_IN_ERROR;
+                    }
+                    break;
+
+                case S_IN_PAIR_VALUE:
+                    /*
+                     * S_IN_PAIR_VALUE is just a marker to indicate the end of
+                     * an object entry, it doesn't proccess any token, therefore
+                     * delay consuming token until next round.
+                     */
+                    statusStack.removeFirst();
+                    status = peekStatus(statusStack);
+                    if (!contentHandler.endObjectEntry())
+                        return;
+                    break;
+
+                case S_IN_ARRAY:
+                    nextToken();
+                    switch (token.type) {
+                    case Yytoken.TYPE_COMMA:
+                        break;
+                    case Yytoken.TYPE_VALUE:
+                        if (!contentHandler.primitive(token.value))
+                            return;
+                        break;
+                    case Yytoken.TYPE_RIGHT_SQUARE:
+                        if (statusStack.size() > 1) {
+                            statusStack.removeFirst();
+                            status = peekStatus(statusStack);
+                        } else {
+                            status = S_IN_FINISHED_VALUE;
+                        }
+                        if (!contentHandler.endArray())
+                            return;
+                        break;
+                    case Yytoken.TYPE_LEFT_BRACE:
+                        status = S_IN_OBJECT;
+                        statusStack.addFirst(new Integer(status));
+                        if (!contentHandler.startObject())
+                            return;
+                        break;
+                    case Yytoken.TYPE_LEFT_SQUARE:
+                        status = S_IN_ARRAY;
+                        statusStack.addFirst(new Integer(status));
+                        if (!contentHandler.startArray())
+                            return;
+                        break;
+                    default:
+                        status = S_IN_ERROR;
+                    }// inner switch
+                    break;
+
+                case S_END:
+                    return;
+
+                case S_IN_ERROR:
+                    throw new JSONParseException(getPosition(), JSONParseException.ERROR_UNEXPECTED_TOKEN, token);
+                }// switch
+                if (status == S_IN_ERROR) {
+                    throw new JSONParseException(getPosition(), JSONParseException.ERROR_UNEXPECTED_TOKEN, token);
+                }
+            } while (token.type != Yytoken.TYPE_EOF);
+        } catch (IOException ie) {
+            status = S_IN_ERROR;
+            throw ie;
+        } catch (JSONParseException pe) {
+            status = S_IN_ERROR;
+            throw pe;
+        } catch (RuntimeException re) {
+            status = S_IN_ERROR;
+            throw re;
+        } catch (Error e) {
+            status = S_IN_ERROR;
+            throw e;
+        }
+
+        status = S_IN_ERROR;
+        throw new JSONParseException(getPosition(), JSONParseException.ERROR_UNEXPECTED_TOKEN, token);
+    }
+}

Propchange: chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-impl/src/main/java/org/apache/chemistry/opencmis/commons/impl/json/parser/JSONParser.java
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message