You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by fm...@apache.org on 2009/02/10 13:18:20 UTC

svn commit: r742950 - /incubator/sling/trunk/scripting/javascript/src/main/java/org/apache/sling/scripting/javascript/wrapper/ScriptableNode.java

Author: fmeschbe
Date: Tue Feb 10 12:18:08 2009
New Revision: 742950

URL: http://svn.apache.org/viewvc?rev=742950&view=rev
Log:
SLING-534 Apply patch to better support multi-value properties

Modified:
    incubator/sling/trunk/scripting/javascript/src/main/java/org/apache/sling/scripting/javascript/wrapper/ScriptableNode.java

Modified: incubator/sling/trunk/scripting/javascript/src/main/java/org/apache/sling/scripting/javascript/wrapper/ScriptableNode.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/scripting/javascript/src/main/java/org/apache/sling/scripting/javascript/wrapper/ScriptableNode.java?rev=742950&r1=742949&r2=742950&view=diff
==============================================================================
--- incubator/sling/trunk/scripting/javascript/src/main/java/org/apache/sling/scripting/javascript/wrapper/ScriptableNode.java (original)
+++ incubator/sling/trunk/scripting/javascript/src/main/java/org/apache/sling/scripting/javascript/wrapper/ScriptableNode.java Tue Feb 10 12:18:08 2009
@@ -317,32 +317,29 @@
         }
 
         // Add all matching properties to result
+        boolean isMulti = false;
         try {
             PropertyIterator it = node.getProperties(name);
             while (it.hasNext()) {
                 Property prop = it.nextProperty();
-                int type = prop.getType();
                 if (prop.getDefinition().isMultiple()) {
+                    isMulti = true;
                     Value[] values = prop.getValues();
-                    for (int i=0;i<values.length;i++) {
+                    for (int i = 0; i < values.length; i++) {
                         items.add(wrap(values[i]));
                     }
                 } else {
-                    if (type==PropertyType.REFERENCE) {
-                        items.add(ScriptRuntime.toObject(this, prop.getNode()));
-                    } else {
-                        items.add(wrap(prop.getValue()));
-                    }
+                    items.add(wrap(prop.getValue()));
                 }
             }
         } catch (RepositoryException e) {
-            log.debug("RepositoryException while collecting Node properties",e);
+            log.debug("RepositoryException while collecting Node properties", e);
         }
 
         if (items.size()==0) {
             return getNative(name, start);
             
-        } else if (items.size()==1) {
+        } else if (items.size()==1 && !isMulti) {
             return items.iterator().next();
             
         } else {
@@ -355,7 +352,17 @@
     /** Wrap JCR Values in a simple way */
     private Scriptable wrap(Value value) throws ValueFormatException,
             IllegalStateException, RepositoryException {
-        return ScriptRuntime.toObject(this, JcrResourceUtil.toJavaObject(value));
+
+        Object javaObject;
+        if (value.getType() == PropertyType.REFERENCE) {
+            String nodeUuid = value.getString();
+            javaObject = node.getSession().getNodeByUUID(nodeUuid);
+
+        } else {
+            javaObject = JcrResourceUtil.toJavaObject(value);
+        }
+
+        return ScriptRuntime.toObject(this, javaObject);
     }
 
     @Override