Merge V4.1-BUG-FIX (4.1.1) to HEAD

38283: Merge V3.4-BUG-FIX (3.4.11) to V4.1-BUG-FIX (4.1.1)
      38281: ALF-14340 CLONE: Alfresco crashes when viewing doclib / previewing - PDF with CMap
         - Fix rotate build failure on 4.1.1 and HEAD
           Disable 'ANY' (wild carded) transforms where one of the other intermediate transforms
           supports the transform.
   38276: Fixed ALF-12524 "Check in/out to Google Docs actions are available for original document"
   - Updated comments for gdocs checkin evaluator
   - Added new doclib evaluators: evaluator.doclib.action.notWorkingCopy, evaluator.doclib.action.checkedOutAspect & evaluator.doclib.action.notCheckedOutAspect
   - Made sure evaluator.doclib.action.googleDocsCheckOut use notWorkingCopy & notCheckedOutAspect
   - Made sure both "google doc checkin" action's js function works for both working copy & original on Document Details page
   38275: ALF-14784: Multi-valued Properties Not Serialized to JSON Correctly
      - Moved serialization of individual properties to JSON to separate method which is called recursively for lists

git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@38285 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Alan Davis
2012-06-25 13:22:01 +00:00
parent b44664bccc
commit 7e1568020d
2 changed files with 82 additions and 36 deletions

View File

@@ -5,6 +5,7 @@ package org.alfresco.repo.jscript.app;
import java.io.Serializable;
import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
@@ -261,6 +262,57 @@ public class JSONConversionComponent
return userPermissionJSON;
}
/**
* Handles the work of converting values to JSON.
*
* @param nodeRef
* @param propertyName
* @param key
* @param value
* @return the JSON value
*/
@SuppressWarnings({ "unchecked", "rawtypes" })
protected Object propertyToJSON(NodeRef nodeRef, QName propertyName, String key, Serializable value)
{
if (value != null)
{
// Has a decorator has been registered for this property?
if (propertyDecorators.containsKey(propertyName) == true)
{
JSONAware jsonAware = propertyDecorators.get(propertyName).decorate(propertyName, nodeRef, value);
if (jsonAware != null)
{
return jsonAware;
}
}
else
{
// Built-in data type processing
if (value instanceof Date)
{
JSONObject dateObj = new JSONObject();
dateObj.put("value", JSONObject.escape(value.toString()));
dateObj.put("iso8601", JSONObject.escape(ISO8601DateFormat.format((Date)value)));
return dateObj;
}
else if (value instanceof List)
{
// Convert the List to a JSON list by recursively calling propertyToJSON
List jsonList = new ArrayList(((List) value).size());
for (Object listItem : (List) value) {
jsonList.add(propertyToJSON(nodeRef, propertyName, key, (Serializable) listItem));
}
return jsonList;
}
else
{
return value.toString();
}
}
}
return null;
}
/**
*
* @param nodeRef
@@ -280,42 +332,8 @@ public class JSONConversionComponent
{
String key = nameToString(propertyName, useShortQNames);
Serializable value = properties.get(propertyName);
if (value != null)
{
// Has a decorator has been registered for this property?
if (propertyDecorators.containsKey(propertyName) == true)
{
JSONAware jsonAware = propertyDecorators.get(propertyName).decorate(propertyName, nodeRef, value);
if (jsonAware != null)
{
propertiesJSON.put(key, jsonAware);
}
}
else
{
// Built-in data type processing
if (value instanceof Date)
{
JSONObject dateObj = new JSONObject();
dateObj.put("value", JSONObject.escape(value.toString()));
dateObj.put("iso8601", JSONObject.escape(ISO8601DateFormat.format((Date)value)));
propertiesJSON.put(key, dateObj);
}
else if (value instanceof List)
{
propertiesJSON.put(key, value);
}
else
{
propertiesJSON.put(key, value.toString());
}
}
}
else
{
propertiesJSON.put(key, null);
}
propertiesJSON.put(key, propertyToJSON(nodeRef, propertyName, key, value));
}
catch (NamespaceException ne)
{