chemistry-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From f...@apache.org
Subject svn commit: r1043539 - in /incubator/chemistry/opencmis-browser-binding/trunk/src/main: java/org/apache/chemistry/opencmis/server/impl/browser/ java/org/apache/chemistry/opencmis/server/impl/browser/json/ webapp/
Date Wed, 08 Dec 2010 17:37:44 GMT
Author: fmui
Date: Wed Dec  8 17:37:44 2010
New Revision: 1043539

URL: http://svn.apache.org/viewvc?rev=1043539&view=rev
Log:
a step towards the browser binding schema

Added:
    incubator/chemistry/opencmis-browser-binding/trunk/src/main/java/org/apache/chemistry/opencmis/server/impl/browser/json/JSONConverterTypeCache.java
  (with props)
Modified:
    incubator/chemistry/opencmis-browser-binding/trunk/src/main/java/org/apache/chemistry/opencmis/server/impl/browser/BrowserBindingUtils.java
    incubator/chemistry/opencmis-browser-binding/trunk/src/main/java/org/apache/chemistry/opencmis/server/impl/browser/NavigationService.java
    incubator/chemistry/opencmis-browser-binding/trunk/src/main/java/org/apache/chemistry/opencmis/server/impl/browser/ObjectService.java
    incubator/chemistry/opencmis-browser-binding/trunk/src/main/java/org/apache/chemistry/opencmis/server/impl/browser/json/JSONConstants.java
    incubator/chemistry/opencmis-browser-binding/trunk/src/main/java/org/apache/chemistry/opencmis/server/impl/browser/json/JSONConverter.java
    incubator/chemistry/opencmis-browser-binding/trunk/src/main/webapp/demo.html

Modified: incubator/chemistry/opencmis-browser-binding/trunk/src/main/java/org/apache/chemistry/opencmis/server/impl/browser/BrowserBindingUtils.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/opencmis-browser-binding/trunk/src/main/java/org/apache/chemistry/opencmis/server/impl/browser/BrowserBindingUtils.java?rev=1043539&r1=1043538&r2=1043539&view=diff
==============================================================================
--- incubator/chemistry/opencmis-browser-binding/trunk/src/main/java/org/apache/chemistry/opencmis/server/impl/browser/BrowserBindingUtils.java
(original)
+++ incubator/chemistry/opencmis-browser-binding/trunk/src/main/java/org/apache/chemistry/opencmis/server/impl/browser/BrowserBindingUtils.java
Wed Dec  8 17:37:44 2010
@@ -57,6 +57,7 @@ public class BrowserBindingUtils {
     public static final String FIELD_OBJECT_ID = "objectId";
 
     public static final String CONTEXT_OBJECT_ID = "org.apache.chemistry.openmis.browserbinding.objectId";
+    public static final String CONTEXT_OBJECT_TYPE_ID = "org.apache.chemistry.openmis.browserbinding.objectTypeId";
     public static final String CONTEXT_BASETYPE_ID = "org.apache.chemistry.openmis.browserbinding.basetypeId";
 
     public enum CallUrl {
@@ -125,6 +126,8 @@ public class BrowserBindingUtils {
 
         if (context instanceof CallContextImpl) {
             ((CallContextImpl) context).put(CONTEXT_OBJECT_ID, object.getId());
+            ((CallContextImpl) context).put(CONTEXT_OBJECT_TYPE_ID,
+                    getProperty(object, PropertyIds.OBJECT_TYPE_ID, String.class));
             ((CallContextImpl) context).put(CONTEXT_BASETYPE_ID,
                     getProperty(object, PropertyIds.BASE_TYPE_ID, String.class));
         }

Modified: incubator/chemistry/opencmis-browser-binding/trunk/src/main/java/org/apache/chemistry/opencmis/server/impl/browser/NavigationService.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/opencmis-browser-binding/trunk/src/main/java/org/apache/chemistry/opencmis/server/impl/browser/NavigationService.java?rev=1043539&r1=1043538&r2=1043539&view=diff
==============================================================================
--- incubator/chemistry/opencmis-browser-binding/trunk/src/main/java/org/apache/chemistry/opencmis/server/impl/browser/NavigationService.java
(original)
+++ incubator/chemistry/opencmis-browser-binding/trunk/src/main/java/org/apache/chemistry/opencmis/server/impl/browser/NavigationService.java
Wed Dec  8 17:37:44 2010
@@ -35,6 +35,7 @@ import org.apache.chemistry.opencmis.com
 import org.apache.chemistry.opencmis.commons.server.CallContext;
 import org.apache.chemistry.opencmis.commons.server.CmisService;
 import org.apache.chemistry.opencmis.server.impl.browser.json.JSONConverter;
+import org.apache.chemistry.opencmis.server.impl.browser.json.JSONConverterTypeCache;
 import org.json.simple.JSONObject;
 
 public final class NavigationService {
@@ -65,7 +66,8 @@ public final class NavigationService {
             throw new CmisRuntimeException("Children are null!");
         }
 
-        JSONObject jsonChildren = JSONConverter.convert(children);
+        JSONConverterTypeCache typeCache = new JSONConverterTypeCache(repositoryId, service);
+        JSONObject jsonChildren = JSONConverter.convert(children, typeCache);
 
         BrowserBindingUtils.writeJSON(jsonChildren, request, response);
     }

Modified: incubator/chemistry/opencmis-browser-binding/trunk/src/main/java/org/apache/chemistry/opencmis/server/impl/browser/ObjectService.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/opencmis-browser-binding/trunk/src/main/java/org/apache/chemistry/opencmis/server/impl/browser/ObjectService.java?rev=1043539&r1=1043538&r2=1043539&view=diff
==============================================================================
--- incubator/chemistry/opencmis-browser-binding/trunk/src/main/java/org/apache/chemistry/opencmis/server/impl/browser/ObjectService.java
(original)
+++ incubator/chemistry/opencmis-browser-binding/trunk/src/main/java/org/apache/chemistry/opencmis/server/impl/browser/ObjectService.java
Wed Dec  8 17:37:44 2010
@@ -40,6 +40,7 @@ import org.apache.chemistry.opencmis.com
 import org.apache.chemistry.opencmis.commons.server.CallContext;
 import org.apache.chemistry.opencmis.commons.server.CmisService;
 import org.apache.chemistry.opencmis.server.impl.browser.json.JSONConverter;
+import org.apache.chemistry.opencmis.server.impl.browser.json.JSONConverterTypeCache;
 import org.json.simple.JSONObject;
 
 public final class ObjectService {
@@ -78,7 +79,8 @@ public final class ObjectService {
             throw new CmisRuntimeException("Object is null!");
         }
 
-        JSONObject jsonObject = JSONConverter.convert(object);
+        JSONConverterTypeCache typeCache = new JSONConverterTypeCache(repositoryId, service);
+        JSONObject jsonObject = JSONConverter.convert(object, typeCache);
 
         BrowserBindingUtils.writeJSON(jsonObject, request, response);
     }

Modified: 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=1043539&r1=1043538&r2=1043539&view=diff
==============================================================================
--- incubator/chemistry/opencmis-browser-binding/trunk/src/main/java/org/apache/chemistry/opencmis/server/impl/browser/json/JSONConstants.java
(original)
+++ incubator/chemistry/opencmis-browser-binding/trunk/src/main/java/org/apache/chemistry/opencmis/server/impl/browser/json/JSONConstants.java
Wed Dec  8 17:37:44 2010
@@ -83,9 +83,10 @@ public class JSONConstants {
     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_VALUE = "value";
     public final static String JSON_PROPERTY_DATATYPE = "type";
-
+    public final static String JSON_PROPERTY_CARDINALITY = "cardinality";
+    
     public final static String JSON_CHANGE_EVENT_TYPE = "changeType";
     public final static String JSON_CHANGE_EVENT_TIME = "changeTime";
 

Modified: 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=1043539&r1=1043538&r2=1043539&view=diff
==============================================================================
--- incubator/chemistry/opencmis-browser-binding/trunk/src/main/java/org/apache/chemistry/opencmis/server/impl/browser/json/JSONConverter.java
(original)
+++ incubator/chemistry/opencmis-browser-binding/trunk/src/main/java/org/apache/chemistry/opencmis/server/impl/browser/json/JSONConverter.java
Wed Dec  8 17:37:44 2010
@@ -43,8 +43,11 @@ import org.apache.chemistry.opencmis.com
 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.definitions.PropertyDefinition;
+import org.apache.chemistry.opencmis.commons.definitions.TypeDefinition;
 import org.apache.chemistry.opencmis.commons.enums.Action;
 import org.apache.chemistry.opencmis.commons.enums.BaseTypeId;
+import org.apache.chemistry.opencmis.commons.enums.Cardinality;
 import org.apache.chemistry.opencmis.commons.enums.PropertyType;
 import org.apache.chemistry.opencmis.commons.impl.UrlBuilder;
 import org.apache.chemistry.opencmis.server.impl.browser.BrowserBindingUtils;
@@ -197,7 +200,7 @@ public class JSONConverter extends JSONC
      * Converts an object.
      */
     @SuppressWarnings("unchecked")
-    public static JSONObject convert(ObjectData object) {
+    public static JSONObject convert(ObjectData object, JSONConverterTypeCache typeCache)
{
         if (object == null) {
             return null;
         }
@@ -208,20 +211,10 @@ public class JSONConverter extends JSONC
         if (object.getProperties() != null) {
             JSONObject properties = new JSONObject();
 
-            for (PropertyData<?> prop : object.getProperties().getPropertyList()) {
-                if (prop.getValues() == null) {
-                    properties.put(prop.getId(), null);
-                } else if (prop.getValues().size() == 1) {
-                    properties.put(prop.getId(), getJSONValue(prop.getValues().get(0)));
-                } else {
-                    JSONArray values = new JSONArray();
-
-                    for (Object value : prop.getValues()) {
-                        values.add(getJSONValue(value));
-                    }
-
-                    properties.put(prop.getId(), values);
-                }
+            for (PropertyData<?> property : object.getProperties().getPropertyList())
{
+                TypeDefinition type = typeCache.getTypeDefinitionForObject(object.getId());
+                properties
+                        .put(property.getId(), convert(property, type.getPropertyDefinitions().get(property.getId())));
             }
 
             result.put(JSON_OBJECT_PROPERTIES, properties);
@@ -237,7 +230,7 @@ public class JSONConverter extends JSONC
             JSONArray relationships = new JSONArray();
 
             for (ObjectData relationship : object.getRelationships()) {
-                relationships.add(convert(relationship));
+                relationships.add(convert(relationship, typeCache));
             }
 
             result.put(JSON_OBJECT_RELATIONSHIP, relationships);
@@ -286,6 +279,41 @@ public class JSONConverter extends JSONC
     }
 
     /**
+     * Converts a property.
+     */
+    @SuppressWarnings("unchecked")
+    public static JSONObject convert(PropertyData<?> property, PropertyDefinition<?>
propDef) {
+        if (property == null) {
+            return null;
+        }
+
+        JSONObject result = new JSONObject();
+
+        result.put(JSON_PROPERTY_ID, property.getId());
+        result.put(JSON_PROPERTY_LOCAL_NAME, property.getLocalName());
+        result.put(JSON_PROPERTY_DISPLAY_NAME, property.getDisplayName());
+        result.put(JSON_PROPERTY_QUERY_NAME, property.getQueryName());
+        result.put(JSON_PROPERTY_DATATYPE, propDef.getPropertyType().value());
+        result.put(JSON_PROPERTY_CARDINALITY, propDef.getCardinality().value());
+
+        if ((property.getValues() == null) || (property.getValues().size() == 0)) {
+            result.put(JSON_PROPERTY_VALUE, null);
+        } else if (propDef.getCardinality() == Cardinality.SINGLE) {
+            result.put(JSON_PROPERTY_VALUE, getJSONValue(property.getValues().get(0)));
+        } else {
+            JSONArray values = new JSONArray();
+
+            for (Object value : property.getValues()) {
+                values.add(getJSONValue(value));
+            }
+
+            result.put(JSON_PROPERTY_VALUE, values);
+        }
+
+        return result;
+    }
+
+    /**
      * Converts allowable actions.
      */
     @SuppressWarnings("unchecked")
@@ -364,12 +392,12 @@ public class JSONConverter extends JSONC
      * Converts an object in a folder list.
      */
     @SuppressWarnings("unchecked")
-    public static JSONObject convert(ObjectInFolderData objectInFolder) {
+    public static JSONObject convert(ObjectInFolderData objectInFolder, JSONConverterTypeCache
typeCache) {
         if ((objectInFolder == null) || (objectInFolder.getObject() == null)) {
             return null;
         }
 
-        JSONObject result = convert(objectInFolder.getObject());
+        JSONObject result = convert(objectInFolder.getObject(), typeCache);
         result.put(JSON_OBJECT_PATH_SEGMENT, objectInFolder.getPathSegment());
 
         return result;
@@ -379,7 +407,7 @@ public class JSONConverter extends JSONC
      * Converts a folder list.
      */
     @SuppressWarnings("unchecked")
-    public static JSONObject convert(ObjectInFolderList objectInFolderList) {
+    public static JSONObject convert(ObjectInFolderList objectInFolderList, JSONConverterTypeCache
typeCache) {
         if (objectInFolderList == null) {
             return null;
         }
@@ -390,7 +418,7 @@ public class JSONConverter extends JSONC
             JSONObject objects = new JSONObject();
 
             for (ObjectInFolderData object : objectInFolderList.getObjects()) {
-                objects.put(object.getObject().getId(), convert(object));
+                objects.put(object.getObject().getId(), convert(object, typeCache));
             }
 
             result.put(JSON_OBJECTINFOLDERLIST_OBJECTS, objects);

Added: incubator/chemistry/opencmis-browser-binding/trunk/src/main/java/org/apache/chemistry/opencmis/server/impl/browser/json/JSONConverterTypeCache.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/opencmis-browser-binding/trunk/src/main/java/org/apache/chemistry/opencmis/server/impl/browser/json/JSONConverterTypeCache.java?rev=1043539&view=auto
==============================================================================
--- incubator/chemistry/opencmis-browser-binding/trunk/src/main/java/org/apache/chemistry/opencmis/server/impl/browser/json/JSONConverterTypeCache.java
(added)
+++ incubator/chemistry/opencmis-browser-binding/trunk/src/main/java/org/apache/chemistry/opencmis/server/impl/browser/json/JSONConverterTypeCache.java
Wed Dec  8 17:37:44 2010
@@ -0,0 +1,53 @@
+/*
+ * 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.HashMap;
+import java.util.Map;
+
+import org.apache.chemistry.opencmis.commons.definitions.TypeDefinition;
+import org.apache.chemistry.opencmis.commons.server.CmisService;
+import org.apache.chemistry.opencmis.commons.server.ObjectInfo;
+
+public class JSONConverterTypeCache {
+
+    private String repositoryId;
+    private CmisService service;
+    private Map<String, TypeDefinition> typeDefinitions;
+
+    public JSONConverterTypeCache(String repositoryId, CmisService service) {
+        this.repositoryId = repositoryId;
+        this.service = service;
+        typeDefinitions = new HashMap<String, TypeDefinition>();
+    }
+
+    public TypeDefinition getTypeDefinition(String typeId) {
+        TypeDefinition type = typeDefinitions.get(typeId);
+        if (type == null) {
+            type = service.getTypeDefinition(repositoryId, typeId, null);
+        }
+
+        return type;
+    }
+
+    public TypeDefinition getTypeDefinitionForObject(String objectId) {
+        ObjectInfo info = service.getObjectInfo(objectId, objectId);
+        return getTypeDefinition(info.getTypeId());
+    }
+}

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

Modified: incubator/chemistry/opencmis-browser-binding/trunk/src/main/webapp/demo.html
URL: http://svn.apache.org/viewvc/incubator/chemistry/opencmis-browser-binding/trunk/src/main/webapp/demo.html?rev=1043539&r1=1043538&r2=1043539&view=diff
==============================================================================
--- incubator/chemistry/opencmis-browser-binding/trunk/src/main/webapp/demo.html (original)
+++ incubator/chemistry/opencmis-browser-binding/trunk/src/main/webapp/demo.html Wed Dec 
8 17:37:44 2010
@@ -3,19 +3,21 @@
 <head>
 <title>OpenCMIS Browser Binding Demo</title>
 <style type="text/css">
-  body {
-    font-family:Arial,sans-serif;
-    font-size:11pt;
-  }
-  .box {
-    border-width:1px;
-    border-style:solid;
-    width:100%;
-    padding:3px;
-  }
-  td {
-    padding:5px;
-  }
+body {
+	font-family: Arial, sans-serif;
+	font-size: 11pt;
+}
+
+.box {
+	border-width: 1px;
+	border-style: solid;
+	width: 100%;
+	padding: 3px;
+}
+
+td {
+	padding: 5px;
+}
 </style>
 <script type="text/javascript">
 var rootFolderUrl;
@@ -52,8 +54,8 @@ function printRepositoryInfos(infos) {
 }
 
 function printObject(obj) {
-    var id = obj.properties["cmis:objectId"];
-    var name = obj.properties["cmis:name"];
+    var id = obj.properties["cmis:objectId"].value;
+    var name = obj.properties["cmis:name"].value;
 
     var s = '<h2>Object "' + name + '" (' + id + ')</h2>';
 
@@ -61,10 +63,19 @@ function printObject(obj) {
     s = s + '<table>';
 	
     for(propertyId in obj.properties) {
-        var propertyValue = obj.properties[propertyId];
-        s = s + '<tr><td>' + propertyId + '</td><td>' + propertyValue
+ '</td></tr>';
+        var property = obj.properties[propertyId];
+        s = s + '<tr><td>' + propertyId + '</td>';
+        s = s + '<td>' + property.displayName + '</td>';
+        s = s + '<td>' + property.type + '</td>';
+        s = s + '<td>' + property.cardinality + '</td>';
+
+        if(property.type == 'datetime') {
+            s = s + '<td>' + (new Date(property.value)) + '</td></tr>';
+        } else {
+            s = s + '<td>' + property.value + '</td></tr>';
+        }
     }
-
+    
     s = s + '</table>';
     
     document.getElementById('objectInfo').innerHTML = s;
@@ -81,18 +92,18 @@ function printChildren(children) {
     for(var id in children.objects) {
         var object = children.objects[id];
 
-        var name = object.properties["cmis:name"];
-        var type = object.properties["cmis:objectTypeId"];
+        var name = object.properties["cmis:name"].value;
+        var type = object.properties["cmis:objectTypeId"].value;
         var mimetype = "";
         var size = "";
-        var createdBy = object.properties["cmis:createdBy"];
-        var creationDate = new Date(object.properties["cmis:creationDate"]);
-        var id = object.properties["cmis:objectId"];
+        var createdBy = object.properties["cmis:createdBy"].value;
+        var creationDate = new Date(object.properties["cmis:creationDate"].value);
+        var id = object.properties["cmis:objectId"].value;
         var link = "";
 
-        if(object.properties["cmis:baseTypeId"] == "cmis:document") {
-            size = object.properties["cmis:contentStreamLength"];
-            mimetype = object.properties["cmis:contentStreamMimeType"];
+        if(object.properties["cmis:baseTypeId"].value == "cmis:document") {
+            size = object.properties["cmis:contentStreamLength"].value;
+            mimetype = object.properties["cmis:contentStreamMimeType"].value;
             link = encodeURI(rootFolderUrl + '?objectId=' + id + '&selector=content');
         }
 
@@ -117,19 +128,14 @@ function printChildren(children) {
 </head>
 <body>
 <h1>OpenCMIS Browser Binding - Demo</h1>
-<br/>
-<div id="repositoryInfo" class="box">
-repositoryInfo
-</div>
-<br/>
-<div id="objectInfo" class="box">
-objectInfo
-</div>
-<br/>
-<div id="folderInfo" class="box">
-folderInfo
-</div>
+<br />
+<div id="repositoryInfo" class="box">repositoryInfo</div>
+<br />
+<div id="objectInfo" class="box">objectInfo</div>
+<br />
+<div id="folderInfo" class="box">folderInfo</div>
 
-<script type="text/javascript" src="browser?clientToken=printRepositoryInfos"></script>
+<script type="text/javascript"
+	src="browser?clientToken=printRepositoryInfos"></script>
 </body>
 </html>
\ No newline at end of file



Mime
View raw message