. 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:
Kevin Roast
2006-07-24 15:06:00 +00:00
parent e31e027039
commit a3603a071c

View File

@@ -21,6 +21,7 @@ import java.io.UnsupportedEncodingException;
import java.net.URLEncoder; import java.net.URLEncoder;
import java.text.MessageFormat; import java.text.MessageFormat;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@@ -53,6 +54,8 @@ import org.alfresco.service.namespace.QName;
import org.alfresco.service.namespace.RegexQNamePattern; import org.alfresco.service.namespace.RegexQNamePattern;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; 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.ScriptableObject;
import org.mozilla.javascript.Wrapper; import org.mozilla.javascript.Wrapper;
import org.springframework.util.StringUtils; import org.springframework.util.StringUtils;
@@ -888,24 +891,36 @@ public final class Node implements Serializable
// set using a JavaScript Array object // set using a JavaScript Array object
ScriptableObject values = (ScriptableObject)value; ScriptableObject values = (ScriptableObject)value;
// convert JavaScript array of values to a List of Serializable objects if (value instanceof NativeArray)
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 // convert JavaScript array of values to a List of Serializable objects
Object propId = propIds[i]; 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 // we are only interested in keys that indicate a list of values
if (propId instanceof Integer) if (propId instanceof Integer)
{ {
// get the value out for the specified key // get the value out for the specified key
Serializable val = (Serializable)values.get((Integer)propId, values); Serializable val = (Serializable)values.get((Integer)propId, values);
// recursively call this method to convert the value // recursively call this method to convert the value
propValues.add(convertValue(val)); propValues.add(convertValue(val));
} }
}
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;
}
} }
value = (Serializable)propValues;
} }
return value; return value;
} }
@@ -1178,14 +1193,8 @@ public final class Node implements Serializable
{ {
// get the value out for the specified key - make sure it is Serializable // get the value out for the specified key - make sure it is Serializable
Object value = props.get((String)propId, props); Object value = props.get((String)propId, props);
if (value instanceof Wrapper) value = convertValue((Serializable)value);
{ aspectProps.put(createQName((String)propId), (Serializable)value);
value = ((Wrapper)value).unwrap();
}
if (value instanceof Serializable)
{
aspectProps.put(createQName((String)propId), (Serializable)value);
}
} }
} }
} }