mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-07-24 17:32:48 +00:00
. Fix JavaScript engine to correctly handle JavaScript native Date() objects as Alfresco property values
git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@3388 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -21,6 +21,7 @@ import java.io.UnsupportedEncodingException;
|
||||
import java.net.URLEncoder;
|
||||
import java.text.MessageFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
@@ -53,6 +54,8 @@ import org.alfresco.service.namespace.QName;
|
||||
import org.alfresco.service.namespace.RegexQNamePattern;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.mozilla.javascript.Context;
|
||||
import org.mozilla.javascript.NativeArray;
|
||||
import org.mozilla.javascript.ScriptableObject;
|
||||
import org.mozilla.javascript.Wrapper;
|
||||
import org.springframework.util.StringUtils;
|
||||
@@ -888,6 +891,8 @@ public final class Node implements Serializable
|
||||
// set using a JavaScript Array object
|
||||
ScriptableObject values = (ScriptableObject)value;
|
||||
|
||||
if (value instanceof NativeArray)
|
||||
{
|
||||
// convert JavaScript array of values to a List of Serializable objects
|
||||
Object[] propIds = values.getIds();
|
||||
List<Serializable> propValues = new ArrayList<Serializable>(propIds.length);
|
||||
@@ -907,6 +912,16 @@ public final class Node implements Serializable
|
||||
}
|
||||
value = (Serializable)propValues;
|
||||
}
|
||||
else
|
||||
{
|
||||
// TODO: add code here to use the dictionary and convert to correct value type
|
||||
Object javaObj = Context.jsToJava(value, Date.class);
|
||||
if (javaObj instanceof Date)
|
||||
{
|
||||
value = (Date)javaObj;
|
||||
}
|
||||
}
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
@@ -1178,17 +1193,11 @@ public final class Node implements Serializable
|
||||
{
|
||||
// get the value out for the specified key - make sure it is Serializable
|
||||
Object value = props.get((String)propId, props);
|
||||
if (value instanceof Wrapper)
|
||||
{
|
||||
value = ((Wrapper)value).unwrap();
|
||||
}
|
||||
if (value instanceof Serializable)
|
||||
{
|
||||
value = convertValue((Serializable)value);
|
||||
aspectProps.put(createQName((String)propId), (Serializable)value);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
QName aspectQName = createQName(type);
|
||||
this.nodeService.addAspect(this.nodeRef, aspectQName, aspectProps);
|
||||
|
||||
|
Reference in New Issue
Block a user