From 530eb70aaf3eccde3c0b7416ee05604a54f6ef44 Mon Sep 17 00:00:00 2001 From: Kevin Roast Date: Mon, 12 Jun 2006 14:26:18 +0000 Subject: [PATCH] fix for AR-654 - saving multi value properties on JavaScript node object git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@3078 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261 --- .../java/org/alfresco/repo/jscript/Node.java | 71 +++++++++++++++++-- 1 file changed, 64 insertions(+), 7 deletions(-) diff --git a/source/java/org/alfresco/repo/jscript/Node.java b/source/java/org/alfresco/repo/jscript/Node.java index deb7b1db9d..2b36dedd14 100644 --- a/source/java/org/alfresco/repo/jscript/Node.java +++ b/source/java/org/alfresco/repo/jscript/Node.java @@ -20,6 +20,7 @@ import java.io.Serializable; import java.io.UnsupportedEncodingException; import java.net.URLEncoder; import java.text.MessageFormat; +import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -51,7 +52,6 @@ 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.NativeArray; import org.mozilla.javascript.ScriptableObject; import org.mozilla.javascript.Wrapper; import org.springframework.util.StringUtils; @@ -87,7 +87,6 @@ public final class Node implements Serializable private NodeRef nodeRef; private String name; private QName type; - private String path; private String id; private Set aspects = null; private ScriptableQNameMap properties = null; @@ -101,6 +100,7 @@ public final class Node implements Serializable private TemplateImageResolver imageResolver = null; private Node parent = null; private ChildAssociationRef primaryParentAssoc = null; + // NOTE: see the reset() method when adding new cached members! // ------------------------------------------------------------------------------ @@ -321,7 +321,7 @@ public final class Node implements Serializable for (AssociationRef ref : refs) { String qname = ref.getTypeQName().toString(); - Node[] nodes = (Node[])assocs.get(qname); + Node[] nodes = (Node[])this.assocs.get(qname); if (nodes == null) { // first access for the list for this qname @@ -333,7 +333,7 @@ public final class Node implements Serializable System.arraycopy(nodes, 0, newNodes, 0, nodes.length); nodes = newNodes; } - nodes[nodes.length] = new Node(ref.getTargetRef(), this.services, this.imageResolver); + nodes[nodes.length - 1] = new Node(ref.getTargetRef(), this.services, this.imageResolver); this.assocs.put(ref.getTypeQName().toString(), nodes); } @@ -801,6 +801,37 @@ public final class Node implements Serializable // 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 propValues = new ArrayList(propIds.length); + for (int i=0; i