chemistry-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From f...@apache.org
Subject svn commit: r959306 - in /incubator/chemistry/opencmis-browser-binding/trunk: ./ src/main/java/org/apache/chemistry/opencmis/server/impl/browser/ src/main/java/org/apache/chemistry/opencmis/server/impl/browser/json/ src/main/webapp/
Date Wed, 30 Jun 2010 13:40:38 GMT
Author: fmui
Date: Wed Jun 30 13:40:38 2010
New Revision: 959306

URL: http://svn.apache.org/viewvc?rev=959306&view=rev
Log:
much nicer JSON

Added:
    incubator/chemistry/opencmis-browser-binding/trunk/src/main/java/org/apache/chemistry/opencmis/server/impl/browser/json/
    incubator/chemistry/opencmis-browser-binding/trunk/src/main/java/org/apache/chemistry/opencmis/server/impl/browser/json/JSONConstants.java
  (with props)
    incubator/chemistry/opencmis-browser-binding/trunk/src/main/java/org/apache/chemistry/opencmis/server/impl/browser/json/JSONConverter.java
  (with props)
Removed:
    incubator/chemistry/opencmis-browser-binding/trunk/src/main/java/org/apache/chemistry/opencmis/server/impl/browser/RepositoryInfoList.java
Modified:
    incubator/chemistry/opencmis-browser-binding/trunk/pom.xml
    incubator/chemistry/opencmis-browser-binding/trunk/src/main/java/org/apache/chemistry/opencmis/server/impl/browser/CmisResource.java
    incubator/chemistry/opencmis-browser-binding/trunk/src/main/webapp/demo.jsp

Modified: incubator/chemistry/opencmis-browser-binding/trunk/pom.xml
URL: http://svn.apache.org/viewvc/incubator/chemistry/opencmis-browser-binding/trunk/pom.xml?rev=959306&r1=959305&r2=959306&view=diff
==============================================================================
--- incubator/chemistry/opencmis-browser-binding/trunk/pom.xml (original)
+++ incubator/chemistry/opencmis-browser-binding/trunk/pom.xml Wed Jun 30 13:40:38 2010
@@ -102,9 +102,15 @@
              <version>1.3</version>
         </dependency>
         <dependency>
-            <groupId>com.sun.grizzly</groupId>
-            <artifactId>grizzly-servlet-webserver</artifactId>
-            <version>1.9.18-i</version>
+             <groupId>com.googlecode.json-simple</groupId>
+             <artifactId>json-simple</artifactId>
+             <version>1.1</version>
+        </dependency>
+        <dependency>
+            <groupId>javax.servlet</groupId>
+            <artifactId>servlet-api</artifactId>
+            <version>2.4</version>
+            <scope>provided</scope>
         </dependency>
     </dependencies>
 

Modified: incubator/chemistry/opencmis-browser-binding/trunk/src/main/java/org/apache/chemistry/opencmis/server/impl/browser/CmisResource.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/opencmis-browser-binding/trunk/src/main/java/org/apache/chemistry/opencmis/server/impl/browser/CmisResource.java?rev=959306&r1=959305&r2=959306&view=diff
==============================================================================
--- incubator/chemistry/opencmis-browser-binding/trunk/src/main/java/org/apache/chemistry/opencmis/server/impl/browser/CmisResource.java
(original)
+++ incubator/chemistry/opencmis-browser-binding/trunk/src/main/java/org/apache/chemistry/opencmis/server/impl/browser/CmisResource.java
Wed Jun 30 13:40:38 2010
@@ -31,7 +31,6 @@ import javax.ws.rs.core.Context;
 import javax.ws.rs.core.MediaType;
 import javax.ws.rs.core.Response;
 import javax.xml.bind.JAXBElement;
-import javax.xml.namespace.QName;
 
 import org.apache.chemistry.opencmis.commons.data.ContentStream;
 import org.apache.chemistry.opencmis.commons.data.ObjectData;
@@ -41,10 +40,7 @@ import org.apache.chemistry.opencmis.com
 import org.apache.chemistry.opencmis.commons.definitions.TypeDefinitionList;
 import org.apache.chemistry.opencmis.commons.enums.IncludeRelationships;
 import org.apache.chemistry.opencmis.commons.impl.Converter;
-import org.apache.chemistry.opencmis.commons.impl.JaxBHelper;
 import org.apache.chemistry.opencmis.commons.impl.jaxb.CmisObjectInFolderListType;
-import org.apache.chemistry.opencmis.commons.impl.jaxb.CmisObjectType;
-import org.apache.chemistry.opencmis.commons.impl.jaxb.CmisRepositoryInfoType;
 import org.apache.chemistry.opencmis.commons.impl.jaxb.CmisTypeDefinitionListType;
 import org.apache.chemistry.opencmis.commons.impl.jaxb.CmisTypeDefinitionType;
 import org.apache.chemistry.opencmis.commons.impl.server.AbstractServiceFactory;
@@ -54,6 +50,8 @@ import org.apache.chemistry.opencmis.ser
 import org.apache.chemistry.opencmis.server.impl.CmisRepositoryContextListener;
 import org.apache.chemistry.opencmis.server.impl.atompub.BasicAuthCallContextHandler;
 import org.apache.chemistry.opencmis.server.impl.atompub.CallContextHandler;
+import org.apache.chemistry.opencmis.server.impl.browser.json.JSONConverter;
+import org.json.simple.JSONArray;
 
 @Path("/")
 public class CmisResource {
@@ -75,20 +73,20 @@ public class CmisResource {
     @GET
     @Path("/repositories")
     @Produces(MediaType.APPLICATION_JSON)
-    public JAXBElement<RepositoryInfoList> getRepositories() {
+    @SuppressWarnings("unchecked")
+    public String getRepositories() {
         CmisService service = null;
 
         try {
-            service = getService(null);
+            JSONArray result = new JSONArray();
 
-            RepositoryInfoList result = new RepositoryInfoList();
+            service = getService(null);
 
             for (RepositoryInfo ri : service.getRepositoryInfos(null)) {
-                result.getRepositoryInfos().add(Converter.convert(ri));
+                result.add(JSONConverter.convert(ri));
             }
 
-            return new JAXBElement<RepositoryInfoList>(new QName("repositoryInfoList"),
RepositoryInfoList.class,
-                    result);
+            return result.toJSONString();
         } finally {
             if (service != null) {
                 service.close();
@@ -99,7 +97,7 @@ public class CmisResource {
     @GET
     @Path("/repository/{repositoryId}")
     @Produces(MediaType.APPLICATION_JSON)
-    public JAXBElement<CmisRepositoryInfoType> getRepository(@PathParam("repositoryId")
String repositoryId) {
+    public String getRepository(@PathParam("repositoryId") String repositoryId) {
         CmisService service = null;
 
         try {
@@ -107,7 +105,7 @@ public class CmisResource {
 
             RepositoryInfo ri = service.getRepositoryInfo(repositoryId, null);
 
-            return JaxBHelper.CMIS_EXTRA_OBJECT_FACTORY.createRepositoryInfo(Converter.convert(ri));
+            return JSONConverter.convert(ri).toJSONString();
         } finally {
             if (service != null) {
                 service.close();
@@ -159,17 +157,16 @@ public class CmisResource {
     @GET
     @Path("/object/{repositoryId}")
     @Produces(MediaType.APPLICATION_JSON)
-    public JAXBElement<CmisObjectType> getObject(@PathParam("repositoryId") String
repositoryId,
-            @QueryParam("id") String objectId) {
+    public String getObject(@PathParam("repositoryId") String repositoryId, @QueryParam("id")
String objectId) {
         CmisService service = null;
 
         try {
             service = getService(repositoryId);
 
-            ObjectData object = service.getObject(repositoryId, objectId, null, true, IncludeRelationships.NONE,
null,
-                    false, false, null);
+            ObjectData object = service.getObject(repositoryId, objectId, null, true, IncludeRelationships.BOTH,
null,
+                    true, true, null);
 
-            return JaxBHelper.CMIS_EXTRA_OBJECT_FACTORY.createObject(Converter.convert(object));
+            return JSONConverter.convert(object).toJSONString();
         } finally {
             if (service != null) {
                 service.close();

Added: incubator/chemistry/opencmis-browser-binding/trunk/src/main/java/org/apache/chemistry/opencmis/server/impl/browser/json/JSONConstants.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/opencmis-browser-binding/trunk/src/main/java/org/apache/chemistry/opencmis/server/impl/browser/json/JSONConstants.java?rev=959306&view=auto
==============================================================================
--- incubator/chemistry/opencmis-browser-binding/trunk/src/main/java/org/apache/chemistry/opencmis/server/impl/browser/json/JSONConstants.java
(added)
+++ incubator/chemistry/opencmis-browser-binding/trunk/src/main/java/org/apache/chemistry/opencmis/server/impl/browser/json/JSONConstants.java
Wed Jun 30 13:40:38 2010
@@ -0,0 +1,100 @@
+/*
+ * 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.server.impl.browser.json;
+
+
+public class JSONConstants {
+
+    public final static String JSON_REPINFO_ID = "repositoryId";
+    public final static String JSON_REPINFO_NAME = "repositoryName";
+    public final static String JSON_REPINFO_DESCRIPTION = "repositoryDescription";
+    public final static String JSON_REPINFO_VENDOR = "vendorName";
+    public final static String JSON_REPINFO_PRODUCT = "productName";
+    public final static String JSON_REPINFO_PRODUCT_VERSION = "productVersion";
+    public final static String JSON_REPINFO_ROOT_FOLDER_ID = "rootFolderId";
+    public final static String JSON_REPINFO_CAPABILITIES = "capabilities";
+    public final static String JSON_REPINFO_ACL_CAPABILITIES = "aclCapabilities";
+    public final static String JSON_REPINFO_CHANGE_LOCK_TOKEN = "latestChangeLogToken";
+    public final static String JSON_REPINFO_CMIS_VERSION_SUPPORTED = "cmisVersionSupported";
+    public final static String JSON_REPINFO_THIN_CLIENT_URI = "thinClientURI";
+    public final static String JSON_REPINFO_CHANGES_INCOMPLETE = "changesIncomplete";
+    public final static String JSON_REPINFO_CHANGES_ON_TYPE = "changesOnType";
+    public final static String JSON_REPINFO_PRINCIPAL_ID_ANONYMOUS = "principalIdAnonymous";
+    public final static String JSON_REPINFO_PRINCIPAL_ID_ANYONE = "principalIdAnyone";
+
+    public final static String JSON_CAP_CONTENT_STREAM_UPDATES = "contentStreamUpdates";
+    public final static String JSON_CAP_CHANGES = "changes";
+    public final static String JSON_CAP_RENDITIONS = "renditions";
+    public final static String JSON_CAP_GET_DESCENDANTS = "getDescendants";
+    public final static String JSON_CAP_GET_FOLDER_TREE = "getFolderTree";
+    public final static String JSON_CAP_MULTIFILING = "multifiling";
+    public final static String JSON_CAP_UNFILING = "unfiling";
+    public final static String JSON_CAP_VERSION_SPECIFIC_FILING = "versionSpecificFiling";
+    public final static String JSON_CAP_PWC_SEARCHABLE = "pwcSearchable";
+    public final static String JSON_CAP_PWC_UPDATABLE = "pwcUpdatable";
+    public final static String JSON_CAP_ALL_VERSIONS_SEARCHABLE = "allVersionsSearchable";
+    public final static String JSON_CAP_QUERY = "query";
+    public final static String JSON_CAP_JOIN = "join";
+    public final static String JSON_CAP_ACL = "acl";
+
+    public final static String JSON_ACLCAP_SUPPORTED_PERMISSIONS = "supportedPermissions";
+    public final static String JSON_ACLCAP_ACL_PROPAGATION = "aclPropagation";
+    public final static String JSON_ACLCAP_PERMISSIONS = "permissions";
+    public final static String JSON_ACLCAP_PERMISSION_MAPPING = "permissionMapping";
+
+    public final static String JSON_ACLCAP_PERMISSION_ID = "id";
+    public final static String JSON_ACLCAP_PERMISSION_DESCRIPTION = "description";
+
+    public final static String JSON_ACLCAP_MAPPING_KEY = "key";
+    public final static String JSON_ACLCAP_MAPPING_PERMISSIONS = "permissions";
+
+    public final static String JSON_OBJECT_PROPERTIES = "properties";
+    public final static String JSON_OBJECT_ALLOWABLE_ACTIONS = "allowableActions";
+    public final static String JSON_OBJECT_RELATIONSHIP = "relationship";
+    public final static String JSON_OBJECT_CHANGE_EVENT_INFO = "changeEventInfo";
+    public final static String JSON_OBJECT_ACL = "acl";
+    public final static String JSON_OBJECT_EXACT_ACL = "exactACL";
+    public final static String JSON_OBJECT_POLICY_IDS = "policyIds";
+    public final static String JSON_OBJECT_RENDITION = "rendition";
+
+    public final static String JSON_PROPERTY_ID = "id";
+    public final static String JSON_PROPERTY_LOCAL_NAME = "localName";
+    public final static String JSON_PROPERTY_DISPLAY_NAME = "displayName";
+    public final static String JSON_PROPERTY_QUERY_NAME = "queryName";
+    public final static String JSON_PROPERTY_VALUES = "values";
+    public final static String JSON_PROPERTY_DATATYPE = "type";
+
+    public final static String JSON_CHANGE_EVENT_TYPE = "changeType";
+    public final static String JSON_CHANGE_EVENT_TIME = "changeTime";
+
+    public final static String JSON_ACL_ACES = "aces";
+    public final static String JSON_ACL_IS_EXACT = "isExact";
+
+    public final static String JSON_ACE_PRINCIPAL = "princialId";
+    public final static String JSON_ACE_PERMISSIONS = "permissions";
+
+    public final static String JSON_RENDITION_STREAM_ID = "streamId";
+    public final static String JSON_RENDITION_MIMETYPE = "mimetype";
+    public final static String JSON_RENDITION_LENGTH = "length";
+    public final static String JSON_RENDITION_KIND = "kind";
+    public final static String JSON_RENDITION_TITLE = "title";
+    public final static String JSON_RENDITION_HEIGHT = "height";
+    public final static String JSON_RENDITION_WIDTH = "width";
+    public final static String JSON_RENDITION_DOCUMENT_ID = "renditionDocumentId";
+}

Propchange: incubator/chemistry/opencmis-browser-binding/trunk/src/main/java/org/apache/chemistry/opencmis/server/impl/browser/json/JSONConstants.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/chemistry/opencmis-browser-binding/trunk/src/main/java/org/apache/chemistry/opencmis/server/impl/browser/json/JSONConverter.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/opencmis-browser-binding/trunk/src/main/java/org/apache/chemistry/opencmis/server/impl/browser/json/JSONConverter.java?rev=959306&view=auto
==============================================================================
--- incubator/chemistry/opencmis-browser-binding/trunk/src/main/java/org/apache/chemistry/opencmis/server/impl/browser/json/JSONConverter.java
(added)
+++ incubator/chemistry/opencmis-browser-binding/trunk/src/main/java/org/apache/chemistry/opencmis/server/impl/browser/json/JSONConverter.java
Wed Jun 30 13:40:38 2010
@@ -0,0 +1,393 @@
+/*
+ * 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.server.impl.browser.json;
+
+import java.util.GregorianCalendar;
+import java.util.Set;
+
+import org.apache.chemistry.opencmis.commons.data.Ace;
+import org.apache.chemistry.opencmis.commons.data.Acl;
+import org.apache.chemistry.opencmis.commons.data.AclCapabilities;
+import org.apache.chemistry.opencmis.commons.data.AllowableActions;
+import org.apache.chemistry.opencmis.commons.data.ChangeEventInfo;
+import org.apache.chemistry.opencmis.commons.data.ObjectData;
+import org.apache.chemistry.opencmis.commons.data.PermissionMapping;
+import org.apache.chemistry.opencmis.commons.data.PropertyBoolean;
+import org.apache.chemistry.opencmis.commons.data.PropertyData;
+import org.apache.chemistry.opencmis.commons.data.PropertyDateTime;
+import org.apache.chemistry.opencmis.commons.data.PropertyDecimal;
+import org.apache.chemistry.opencmis.commons.data.PropertyHtml;
+import org.apache.chemistry.opencmis.commons.data.PropertyId;
+import org.apache.chemistry.opencmis.commons.data.PropertyInteger;
+import org.apache.chemistry.opencmis.commons.data.PropertyString;
+import org.apache.chemistry.opencmis.commons.data.PropertyUri;
+import org.apache.chemistry.opencmis.commons.data.RenditionData;
+import org.apache.chemistry.opencmis.commons.data.RepositoryCapabilities;
+import org.apache.chemistry.opencmis.commons.data.RepositoryInfo;
+import org.apache.chemistry.opencmis.commons.definitions.PermissionDefinition;
+import org.apache.chemistry.opencmis.commons.enums.Action;
+import org.apache.chemistry.opencmis.commons.enums.BaseTypeId;
+import org.apache.chemistry.opencmis.commons.enums.PropertyType;
+import org.json.simple.JSONArray;
+import org.json.simple.JSONObject;
+
+public class JSONConverter extends JSONConstants {
+
+    /**
+     * Private constructor.
+     */
+    private JSONConverter() {
+    }
+
+    /**
+     * Converts a repository info object.
+     */
+    @SuppressWarnings("unchecked")
+    public static JSONObject convert(RepositoryInfo repositoryInfo) {
+        if (repositoryInfo == null) {
+            return null;
+        }
+
+        JSONObject result = new JSONObject();
+
+        result.put(JSON_REPINFO_ID, repositoryInfo.getId());
+        result.put(JSON_REPINFO_NAME, repositoryInfo.getName());
+        result.put(JSON_REPINFO_DESCRIPTION, repositoryInfo.getDescription());
+        result.put(JSON_REPINFO_VENDOR, repositoryInfo.getVendorName());
+        result.put(JSON_REPINFO_PRODUCT, repositoryInfo.getProductName());
+        result.put(JSON_REPINFO_PRODUCT_VERSION, repositoryInfo.getProductVersion());
+        result.put(JSON_REPINFO_ROOT_FOLDER_ID, repositoryInfo.getRootFolderId());
+        result.put(JSON_REPINFO_CAPABILITIES, convert(repositoryInfo.getCapabilities()));
+        result.put(JSON_REPINFO_ACL_CAPABILITIES, convert(repositoryInfo.getAclCapabilities()));
+        result.put(JSON_REPINFO_CHANGE_LOCK_TOKEN, repositoryInfo.getLatestChangeLogToken());
+        result.put(JSON_REPINFO_CMIS_VERSION_SUPPORTED, repositoryInfo.getCmisVersionSupported());
+        result.put(JSON_REPINFO_THIN_CLIENT_URI, repositoryInfo.getThinClientUri());
+        result.put(JSON_REPINFO_CHANGES_INCOMPLETE, repositoryInfo.getChangesIncomplete());
+
+        if (repositoryInfo.getChangesOnType() != null) {
+            JSONArray changesOnType = new JSONArray();
+
+            for (BaseTypeId type : repositoryInfo.getChangesOnType()) {
+                changesOnType.add(getJSONStringValue(type));
+            }
+
+            result.put(JSON_REPINFO_CHANGES_ON_TYPE, changesOnType);
+        }
+
+        result.put(JSON_REPINFO_PRINCIPAL_ID_ANONYMOUS, repositoryInfo.getPrincipalIdAnonymous());
+        result.put(JSON_REPINFO_PRINCIPAL_ID_ANYONE, repositoryInfo.getPrincipalIdAnyone());
+
+        return result;
+    }
+
+    /**
+     * Converts a capabilities object.
+     */
+    @SuppressWarnings("unchecked")
+    public static JSONObject convert(RepositoryCapabilities capabilities) {
+        if (capabilities == null) {
+            return null;
+        }
+
+        JSONObject result = new JSONObject();
+
+        result.put(JSON_CAP_CONTENT_STREAM_UPDATES,
+                getJSONStringValue(capabilities.getContentStreamUpdatesCapability()));
+        result.put(JSON_CAP_CHANGES, getJSONStringValue(capabilities.getChangesCapability()));
+        result.put(JSON_CAP_RENDITIONS, getJSONStringValue(capabilities.getRenditionsCapability()));
+        result.put(JSON_CAP_GET_DESCENDANTS, capabilities.isGetDescendantsSupported());
+        result.put(JSON_CAP_GET_FOLDER_TREE, capabilities.isGetFolderTreeSupported());
+        result.put(JSON_CAP_MULTIFILING, capabilities.isMultifilingSupported());
+        result.put(JSON_CAP_UNFILING, capabilities.isUnfilingSupported());
+        result.put(JSON_CAP_VERSION_SPECIFIC_FILING, capabilities.isVersionSpecificFilingSupported());
+        result.put(JSON_CAP_PWC_SEARCHABLE, capabilities.isPwcSearchableSupported());
+        result.put(JSON_CAP_PWC_UPDATABLE, capabilities.isPwcUpdatableSupported());
+        result.put(JSON_CAP_ALL_VERSIONS_SEARCHABLE, capabilities.isAllVersionsSearchableSupported());
+        result.put(JSON_CAP_QUERY, getJSONStringValue(capabilities.getQueryCapability()));
+        result.put(JSON_CAP_JOIN, getJSONStringValue(capabilities.getJoinCapability()));
+        result.put(JSON_CAP_ACL, getJSONStringValue(capabilities.getAclCapability()));
+
+        return result;
+    }
+
+    /**
+     * Converts an ACL capabilities object.
+     */
+    @SuppressWarnings("unchecked")
+    public static JSONObject convert(AclCapabilities capabilities) {
+        if (capabilities == null) {
+            return null;
+        }
+
+        JSONObject result = new JSONObject();
+
+        result.put(JSON_ACLCAP_SUPPORTED_PERMISSIONS, getJSONStringValue(capabilities.getSupportedPermissions()));
+        result.put(JSON_ACLCAP_ACL_PROPAGATION, getJSONStringValue(capabilities.getAclPropagation()));
+
+        // permissions
+        if (capabilities.getPermissions() != null) {
+            JSONArray permissions = new JSONArray();
+
+            for (PermissionDefinition permDef : capabilities.getPermissions()) {
+                JSONObject permission = new JSONObject();
+                permission.put(JSON_ACLCAP_PERMISSION_ID, permDef.getId());
+                permission.put(JSON_ACLCAP_PERMISSION_DESCRIPTION, permDef.getDescription());
+
+                permissions.add(permission);
+            }
+
+            result.put(JSON_ACLCAP_PERMISSIONS, permissions);
+        }
+
+        // permission mapping
+
+        if (capabilities.getPermissionMapping() != null) {
+            JSONArray permissionMapping = new JSONArray();
+
+            for (PermissionMapping permMap : capabilities.getPermissionMapping().values())
{
+                JSONArray mappingPermissions = new JSONArray();
+                if (permMap.getPermissions() != null) {
+                    for (String p : permMap.getPermissions()) {
+                        mappingPermissions.add(p);
+                    }
+                }
+
+                JSONObject mapping = new JSONObject();
+                mapping.put(JSON_ACLCAP_MAPPING_KEY, permMap.getKey());
+                mapping.put(JSON_ACLCAP_MAPPING_PERMISSIONS, mappingPermissions);
+
+                permissionMapping.add(mapping);
+            }
+
+            result.put(JSON_ACLCAP_PERMISSION_MAPPING, permissionMapping);
+        }
+
+        return result;
+    }
+
+    /**
+     * Converts an object.
+     */
+    @SuppressWarnings("unchecked")
+    public static JSONObject convert(ObjectData object) {
+        if (object == null) {
+            return null;
+        }
+
+        JSONObject result = new JSONObject();
+
+        // properties
+        if (object.getProperties() != null) {
+            JSONObject properties = new JSONObject();
+
+            for (PropertyData<?> prop : object.getProperties().getPropertyList()) {
+                JSONArray propertyValues = new JSONArray();
+                if (prop.getValues() != null) {
+                    for (Object value : prop.getValues()) {
+                        propertyValues.add(getJSONValue(value));
+                    }
+                }
+
+                JSONObject propertyObject = new JSONObject();
+                propertyObject.put(JSON_PROPERTY_ID, prop.getId());
+                propertyObject.put(JSON_PROPERTY_LOCAL_NAME, prop.getLocalName());
+                propertyObject.put(JSON_PROPERTY_DISPLAY_NAME, prop.getDisplayName());
+                propertyObject.put(JSON_PROPERTY_QUERY_NAME, prop.getQueryName());
+                propertyObject.put(JSON_PROPERTY_VALUES, propertyValues);
+                propertyObject.put(JSON_PROPERTY_DATATYPE, getJSONPropertyDataType(prop));
+
+                properties.put(prop.getId(), propertyObject);
+            }
+
+            result.put(JSON_OBJECT_PROPERTIES, properties);
+        }
+
+        // allowable actions
+        if (object.getAllowableActions() != null) {
+            result.put(JSON_OBJECT_ALLOWABLE_ACTIONS, convert(object.getAllowableActions()));
+        }
+
+        // relationships
+        if (object.getRelationships() != null) {
+            JSONArray relationships = new JSONArray();
+
+            for (ObjectData relationship : object.getRelationships()) {
+                relationships.add(convert(relationship));
+            }
+
+            result.put(JSON_OBJECT_RELATIONSHIP, relationships);
+        }
+
+        // change event info
+        if (object.getChangeEventInfo() != null) {
+            JSONObject changeEventInfo = new JSONObject();
+
+            ChangeEventInfo cei = object.getChangeEventInfo();
+            changeEventInfo.put(JSON_CHANGE_EVENT_TYPE, getJSONStringValue(cei.getChangeType()));
+            changeEventInfo.put(JSON_CHANGE_EVENT_TIME, getJSONValue(cei.getChangeTime()));
+
+            result.put(JSON_OBJECT_CHANGE_EVENT_INFO, changeEventInfo);
+        }
+
+        // ACL
+        if ((object.getAcl() != null) && (object.getAcl().getAces() != null)) {
+            result.put(JSON_OBJECT_ACL, convert(object.getAcl()));
+            result.put(JSON_OBJECT_EXACT_ACL, object.isExactAcl());
+        }
+
+        // policy ids
+        if ((object.getPolicyIds() != null) && (object.getPolicyIds().getPolicyIds()
!= null)) {
+            JSONArray policyIds = new JSONArray();
+
+            for (String pi : object.getPolicyIds().getPolicyIds()) {
+                policyIds.add(pi);
+            }
+
+            result.put(JSON_OBJECT_POLICY_IDS, policyIds);
+        }
+
+        // renditions
+        if (object.getRenditions() != null) {
+            JSONArray renditions = new JSONArray();
+
+            for (RenditionData rendition : object.getRenditions()) {
+                renditions.add(convert(rendition));
+            }
+
+            result.put(JSON_OBJECT_RENDITION, renditions);
+        }
+
+        return result;
+    }
+
+    /**
+     * Converts allowable actions.
+     */
+    @SuppressWarnings("unchecked")
+    public static JSONObject convert(AllowableActions allowableActions) {
+        if (allowableActions == null) {
+            return null;
+        }
+
+        JSONObject result = new JSONObject();
+
+        Set<Action> actionSet = allowableActions.getAllowableActions();
+        for (Action action : Action.values()) {
+            result.put(action.value(), actionSet.contains(action));
+        }
+
+        return result;
+    }
+
+    /**
+     * Converts an ACL.
+     */
+    @SuppressWarnings("unchecked")
+    public static JSONObject convert(Acl acl) {
+        if ((acl == null) || (acl.getAces() == null)) {
+            return null;
+        }
+
+        JSONArray aceObjects = new JSONArray();
+
+        for (Ace ace : acl.getAces()) {
+            JSONArray permissions = new JSONArray();
+            if (ace.getPermissions() != null) {
+                for (String p : ace.getPermissions()) {
+                    permissions.add(p);
+                }
+            }
+
+            JSONObject aceObject = new JSONObject();
+            aceObject.put(JSON_ACE_PRINCIPAL, ace.getPrincipalId());
+            aceObject.put(JSON_ACE_PERMISSIONS, permissions);
+
+            aceObjects.add(aceObject);
+        }
+
+        JSONObject result = new JSONObject();
+        result.put(JSON_ACL_ACES, aceObjects);
+        result.put(JSON_ACL_IS_EXACT, acl.isExact());
+
+        return result;
+    }
+
+    /**
+     * Converts a rendition.
+     */
+    @SuppressWarnings("unchecked")
+    public static JSONObject convert(RenditionData rendition) {
+        if (rendition == null) {
+            return null;
+        }
+
+        JSONObject result = new JSONObject();
+
+        result.put(JSON_RENDITION_STREAM_ID, rendition.getStreamId());
+        result.put(JSON_RENDITION_MIMETYPE, rendition.getMimeType());
+        result.put(JSON_RENDITION_LENGTH, rendition.getBigLength());
+        result.put(JSON_RENDITION_KIND, rendition.getKind());
+        result.put(JSON_RENDITION_TITLE, rendition.getTitle());
+        result.put(JSON_RENDITION_HEIGHT, rendition.getBigHeight());
+        result.put(JSON_RENDITION_WIDTH, rendition.getBigWidth());
+        result.put(JSON_RENDITION_DOCUMENT_ID, rendition.getRenditionDocumentId());
+
+        return result;
+    }
+
+    // -----------------------------------------------------------------
+
+    public static String getJSONStringValue(Object obj) {
+        if (obj == null) {
+            return null;
+        }
+
+        return obj.toString();
+    }
+
+    public static Object getJSONValue(Object value) {
+        if (value instanceof GregorianCalendar) {
+            return ((GregorianCalendar) value).getTimeInMillis();
+        }
+
+        return value;
+    }
+
+    public static String getJSONPropertyDataType(PropertyData<?> property) {
+        if (property instanceof PropertyBoolean) {
+            return PropertyType.BOOLEAN.value();
+        } else if (property instanceof PropertyId) {
+            return PropertyType.ID.value();
+        } else if (property instanceof PropertyInteger) {
+            return PropertyType.INTEGER.value();
+        } else if (property instanceof PropertyDateTime) {
+            return PropertyType.DATETIME.value();
+        } else if (property instanceof PropertyDecimal) {
+            return PropertyType.DECIMAL.value();
+        } else if (property instanceof PropertyHtml) {
+            return PropertyType.HTML.value();
+        } else if (property instanceof PropertyString) {
+            return PropertyType.STRING.value();
+        } else if (property instanceof PropertyUri) {
+            return PropertyType.URI.value();
+        }
+
+        return null;
+    }
+}

Propchange: incubator/chemistry/opencmis-browser-binding/trunk/src/main/java/org/apache/chemistry/opencmis/server/impl/browser/json/JSONConverter.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: incubator/chemistry/opencmis-browser-binding/trunk/src/main/webapp/demo.jsp
URL: http://svn.apache.org/viewvc/incubator/chemistry/opencmis-browser-binding/trunk/src/main/webapp/demo.jsp?rev=959306&r1=959305&r2=959306&view=diff
==============================================================================
--- incubator/chemistry/opencmis-browser-binding/trunk/src/main/webapp/demo.jsp (original)
+++ incubator/chemistry/opencmis-browser-binding/trunk/src/main/webapp/demo.jsp Wed Jun 30
13:40:38 2010
@@ -18,10 +18,10 @@
 <script type="text/javascript">
 $(document).ready(function(){
   $.getJSON('<%=request.getContextPath()%>/browser/repositories', 
-    function(data) {
-      var ri = data.repositoryInfos;
+    function(riData) {
+      var ri = riData[0];
       $('#repositoryInfo').html(
-        '<h2>Repsository ' + ri.repositoryName + ' (' + ri.repositoryId + ')</h2>'
+
+        '<h2>Repsository "' + ri.repositoryName + '" (' + ri.repositoryId + ')</h2>'
+
         '<table>' +
         '<tr><td>Id:</td><td>' + ri.repositoryId + '</td></tr>'
+
         '<tr><td>Name:</td><td>' + ri.repositoryName + '</td></tr>'
+
@@ -29,6 +29,45 @@ $(document).ready(function(){
         '<tr><td>Product:</td><td>' + ri.vendorName + ' ' + ri.productName
+ ' ' + ri.productVersion + '</td></tr>' +
         '<tr><td>Root folder id:</td><td>' + ri.rootFolderId + '</td></tr>'
+
         '</table>');
+
+      $.getJSON(encodeURI('<%=request.getContextPath()%>/browser/object/' + ri.repositoryId
+ '?id=' + ri.rootFolderId), 
+        function(objData) {
+          var id = objData.properties["cmis:objectId"].values[0];
+          var name = objData.properties["cmis:name"].values[0];
+          
+          var s = '<h2>Object "' + name + '" (' + id + ')</h2>';
+
+          s = s + '<h3>Properties</h3>';
+          s = s + '<table>';
+          
+          var propertyId;
+          for(propertyId in objData.properties) {
+              var property = objData.properties[propertyId];
+              s = s + '<tr><td>' + property.id +  '</td><td><td>'
+ property.type +  '</td><td>';
+
+              for(var i in property.values) {
+                  var value = property.values[i];
+                  if(property.type == 'datetime') {
+                      value = new Date(value);
+                  }
+                  
+                  s = s + value + '<br/>';
+              }
+               
+               s = s + '</td></tr>';
+          }          
+          
+          s = s + '</table>';
+
+          s = s + '<h3>(Some) Allowable Actions</h3>';
+          s = s + '<table>';
+          s = s + '<tr><td>Can get properties:</td><td>' + objData.allowableActions.canGetProperties
+ '</td></tr>';
+          s = s + '<tr><td>Can get children:</td><td>' + objData.allowableActions.canGetChildren
+ '</td></tr>';
+          s = s + '<tr><td>Can get content stream:</td><td>' + objData.allowableActions.canGetContentStream
+ '</td></tr>';
+          s = s + '</table>';
+          
+    	  $('#objectInfo').html(s);
+        });
    });
 });     
 </script>
@@ -39,5 +78,9 @@ $(document).ready(function(){
 <div id="repositoryInfo" class="box">
 RepositoryInfo
 </div>
+<br/>
+<div id="objectInfo" class="box">
+objectInfo
+</div>
 </body>
 </html>
\ No newline at end of file



Mime
View raw message