Merged V1.3 to HEAD (3068:3083, 3084:3086)

svn merge svn://www.alfresco.org:3691/alfresco/BRANCHES/V1.3@3068 svn://www.alfresco.org:3691/alfresco/BRANCHES/V1.3@3083 .
   svn merge svn://www.alfresco.org:3691/alfresco/BRANCHES/V1.3@3084 svn://www.alfresco.org:3691/alfresco/BRANCHES/V1.3@3086 .


git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@3342 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Derek Hulley
2006-07-18 15:42:28 +00:00
parent dbffd532f7
commit 6564a5011e
3 changed files with 125 additions and 46 deletions

View File

@@ -847,56 +847,68 @@ public final class Node implements Serializable
for (String key : this.properties.keySet())
{
Serializable value = (Serializable)this.properties.get(key);
if (value instanceof Node)
{
// convert back to NodeRef
value = ((Node)value).getNodeRef();
}
else if (value instanceof ScriptContentData)
{
// convert back to ContentData
value = ((ScriptContentData)value).contentData;
}
else if (value instanceof Wrapper)
{
// unwrap a Java object from a JavaScript wrapper
value = (Serializable)((Wrapper)value).unwrap();
}
else if (value instanceof ScriptableObject)
{
// a scriptable object will probably indicate a multi-value property
// set using a JavaScript Array object
ScriptableObject values = (ScriptableObject)value;
// convert JavaScript array of values to a List of Serializable objects
Object[] propIds = values.getIds();
List<Serializable> propValues = new ArrayList<Serializable>(propIds.length);
for (int i=0; i<propIds.length; i++)
{
// work on each key in turn
Object propId = propIds[i];
// we are only interested in keys that indicate a list of values
if (propId instanceof Integer)
{
// get the value out for the specified key - make sure it is Serializable
Object val = values.get((Integer)propId, values);
if (val instanceof Wrapper)
{
val = ((Wrapper)val).unwrap();
}
if (val instanceof Serializable)
{
propValues.add((Serializable)val);
}
}
}
value = (Serializable)propValues;
}
// perform the conversion from script wrapper object to repo serializable values
value = convertValue(value);
props.put(createQName(key), value);
}
this.nodeService.setProperties(this.nodeRef, props);
}
/**
* Convert an object from any script wrapper value to a valid repository serializable value.
* This includes converting JavaScript Array objects to Lists of valid objects.
*
* @param value Value to convert from script wrapper object to repo serializable value
*
* @return valid repo value
*/
private static Serializable convertValue(Serializable value)
{
if (value instanceof Node)
{
// convert back to NodeRef
value = ((Node)value).getNodeRef();
}
else if (value instanceof ScriptContentData)
{
// convert back to ContentData
value = ((ScriptContentData)value).contentData;
}
else if (value instanceof Wrapper)
{
// unwrap a Java object from a JavaScript wrapper
// recursively call this method to convert the unwrapped value
value = convertValue((Serializable)((Wrapper)value).unwrap());
}
else if (value instanceof ScriptableObject)
{
// a scriptable object will probably indicate a multi-value property
// set using a JavaScript Array object
ScriptableObject values = (ScriptableObject)value;
// convert JavaScript array of values to a List of Serializable objects
Object[] propIds = values.getIds();
List<Serializable> propValues = new ArrayList<Serializable>(propIds.length);
for (int i=0; i<propIds.length; i++)
{
// work on each key in turn
Object propId = propIds[i];
// we are only interested in keys that indicate a list of values
if (propId instanceof Integer)
{
// get the value out for the specified key
Serializable val = (Serializable)values.get((Integer)propId, values);
// recursively call this method to convert the value
propValues.add(convertValue(val));
}
}
value = (Serializable)propValues;
}
return value;
}
/**
* Create a new File (cm:content) node as a child of this node.