You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by ju...@apache.org on 2010/02/09 02:29:20 UTC

svn commit: r907872 - in /sling/trunk/bundles/jcr/contentloader/src: main/java/org/apache/sling/jcr/contentloader/internal/ main/java/org/apache/sling/jcr/contentloader/internal/readers/ test/java/org/apache/sling/jcr/contentloader/internal/

Author: justin
Date: Tue Feb  9 01:29:19 2010
New Revision: 907872

URL: http://svn.apache.org/viewvc?rev=907872&view=rev
Log:
SLING-1359 - updating contentloader bundle to use Undefined instead of String as the default property type

Modified:
    sling/trunk/bundles/jcr/contentloader/src/main/java/org/apache/sling/jcr/contentloader/internal/DefaultContentCreator.java
    sling/trunk/bundles/jcr/contentloader/src/main/java/org/apache/sling/jcr/contentloader/internal/readers/JsonReader.java
    sling/trunk/bundles/jcr/contentloader/src/test/java/org/apache/sling/jcr/contentloader/internal/JsonReaderTest.java

Modified: sling/trunk/bundles/jcr/contentloader/src/main/java/org/apache/sling/jcr/contentloader/internal/DefaultContentCreator.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/jcr/contentloader/src/main/java/org/apache/sling/jcr/contentloader/internal/DefaultContentCreator.java?rev=907872&r1=907871&r2=907872&view=diff
==============================================================================
--- sling/trunk/bundles/jcr/contentloader/src/main/java/org/apache/sling/jcr/contentloader/internal/DefaultContentCreator.java (original)
+++ sling/trunk/bundles/jcr/contentloader/src/main/java/org/apache/sling/jcr/contentloader/internal/DefaultContentCreator.java Tue Feb  9 01:29:19 2010
@@ -333,7 +333,11 @@
               node.setProperty(name, value, propertyType);
             }
         } else {
-            node.setProperty(name, value, propertyType);
+            if (propertyType == PropertyType.UNDEFINED) {
+                node.setProperty(name, value);
+            } else {
+                node.setProperty(name, value, propertyType);
+            }
         }
     }
 

Modified: sling/trunk/bundles/jcr/contentloader/src/main/java/org/apache/sling/jcr/contentloader/internal/readers/JsonReader.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/jcr/contentloader/src/main/java/org/apache/sling/jcr/contentloader/internal/readers/JsonReader.java?rev=907872&r1=907871&r2=907872&view=diff
==============================================================================
--- sling/trunk/bundles/jcr/contentloader/src/main/java/org/apache/sling/jcr/contentloader/internal/readers/JsonReader.java (original)
+++ sling/trunk/bundles/jcr/contentloader/src/main/java/org/apache/sling/jcr/contentloader/internal/readers/JsonReader.java Tue Feb  9 01:29:19 2010
@@ -42,39 +42,39 @@
  * The <code>JsonReader</code> Parses a Json document on content load and creates the
  * corresponding node structure with properties. Will not update protected nodes and
  * properties like rep:Policy and children.
- * 
+ *
  * <pre>
  * Nodes, Properties and in fact complete subtrees may be described in JSON files
  * using the following skeleton structure (see http://www.json.org for information
  * on the syntax of JSON) :
- * 
+ *
  * # the name of the node is taken from the name of the file without the .json ext.
  *   {
- *   
+ *
  *     # optional primary node type, default &quot;nt:unstructured&quot;
  *     &quot;jcr:primaryType&quot;:&quot;sling:ScriptedComponent&quot;,
  *     # optional mixin node types as array
  *     &quot;jcr:mixinTypes&quot;: [ ],
- *     
- *       
+ *
+ *
  *       # &quot;properties&quot; are added as key value pairs, the name of the key being the name
- *       # of the property. The value is either the string property value, array for 
- *       # multi-values or an object whose value[s] property denotes the property 
+ *       # of the property. The value is either the string property value, array for
+ *       # multi-values or an object whose value[s] property denotes the property
  *       # value(s) and whose type property denotes the property type
  *       &quot;sling:contentClass&quot;: &quot;com.day.sling.jcr.test.Test&quot;,
  *       &quot;sampleMulti&quot;: [ &quot;v1&quot;, &quot;v2&quot; ],
  *       &quot;sampleStruct&quot;: 1,
  *       &quot;sampleStructMulti&quot;: [ 1, 2, 3 ],
- *       
+ *
  *       # reference properties start with jcr:reference
  *       &quot;jcr:reference:sampleReference&quot;: &quot;/test/content&quot;,
- *       
+ *
  *       # path propertie start with jcr:path
  *       &quot;jcr:path:sampleReference&quot;: &quot;/test/path&quot;,
- *         
- *       # nested nodes are added as nested maps. 
+ *
+ *       # nested nodes are added as nested maps.
  *     &quot;sling:scripts&quot;:  {
- *               
+ *
  *         &quot;jcr:primaryType&quot;: &quot;sling:ScriptList&quot;,
  *         &quot;script1&quot; :{
  *             &quot;primaryNodeType&quot;: &quot;sling:Script&quot;,
@@ -84,7 +84,7 @@
  *         }
  *     }
  *   }
- * 
+ *
  * </pre>
  */
 public class JsonReader implements ContentReader {
@@ -104,7 +104,7 @@
         ignoredNames.add("jcr:checkedOut");
         ignoredNames.add("jcr:created");
     }
-    
+
     private static final Set<String> ignoredPrincipalPropertyNames = new HashSet<String>();
     static {
     	ignoredPrincipalPropertyNames.add("name");
@@ -239,7 +239,7 @@
         }
 
         // fall back to default
-        return PropertyType.STRING;
+        return PropertyType.UNDEFINED;
     }
 
     protected String getName(String name) {
@@ -278,8 +278,8 @@
 
         return new String(bos.toByteArray(), encoding);
     }
-    
-    
+
+
     /**
      * Create or update one or more user and/or groups
      *	<code>
@@ -313,7 +313,7 @@
     		}
     	}
     }
-    
+
     /**
      * Create or update a user or group
      */
@@ -349,11 +349,11 @@
     		contentCreator.createUser(name, password, extraProps);
     	}
     }
-    
+
     /**
      * Create or update one or more access control entries for the current
      * node.
-     * 
+     *
      *  <code>
      *  {
      *   "security:acl" : [
@@ -372,8 +372,8 @@
      *      		"jcr:read",
      *      		"jcr:write"
      *     		]
-     *     	}   
-     *   ]   
+     *     	}
+     *   ]
      *  }
      *  </code>
      */
@@ -395,14 +395,14 @@
     		}
     	}
     }
-   
+
     /**
      * Create or update an access control entry
      */
     protected void createAce(JSONObject ace, ContentCreator contentCreator)
     throws JSONException, RepositoryException {
 		String principalID = ace.getString("principal");
-		
+
 		String [] grantedPrivileges = null;
 		JSONArray granted = ace.optJSONArray("granted");
 		if (granted != null) {
@@ -420,9 +420,9 @@
 				deniedPrivileges[a] = denied.getString(a);
 			}
 		}
-		
+
 		//do the work.
 		contentCreator.createAce(principalID, grantedPrivileges, deniedPrivileges);
-    }   
-   
+    }
+
 }

Modified: sling/trunk/bundles/jcr/contentloader/src/test/java/org/apache/sling/jcr/contentloader/internal/JsonReaderTest.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/jcr/contentloader/src/test/java/org/apache/sling/jcr/contentloader/internal/JsonReaderTest.java?rev=907872&r1=907871&r2=907872&view=diff
==============================================================================
--- sling/trunk/bundles/jcr/contentloader/src/test/java/org/apache/sling/jcr/contentloader/internal/JsonReaderTest.java (original)
+++ sling/trunk/bundles/jcr/contentloader/src/test/java/org/apache/sling/jcr/contentloader/internal/JsonReaderTest.java Tue Feb  9 01:29:19 2010
@@ -127,7 +127,7 @@
 
         this.mockery.checking(new Expectations() {{
             allowing(creator).createNode(null, null, null); inSequence(mySequence);
-            allowing(creator).createProperty("property", PropertyType.STRING, ""); inSequence(mySequence);
+            allowing(creator).createProperty("property", PropertyType.UNDEFINED, ""); inSequence(mySequence);
             allowing(creator).finishNode(); inSequence(mySequence);
         }});
         this.parse(json);
@@ -138,7 +138,7 @@
 
         this.mockery.checking(new Expectations() {{
             allowing(creator).createNode(null, null, null); inSequence(mySequence);
-            allowing(creator).createProperty("p1", PropertyType.STRING, "v1"); inSequence(mySequence);
+            allowing(creator).createProperty("p1", PropertyType.UNDEFINED, "v1"); inSequence(mySequence);
             allowing(creator).finishNode(); inSequence(mySequence);
         }});
         this.parse(json);
@@ -160,8 +160,8 @@
 
         this.mockery.checking(new Expectations() {{
             allowing(creator).createNode(null, null, null); inSequence(mySequence);
-            allowing(creator).createProperty("p1", PropertyType.STRING, "v1"); inSequence(mySequence);
-            allowing(creator).createProperty("p2", PropertyType.STRING, "v2"); inSequence(mySequence);
+            allowing(creator).createProperty("p1", PropertyType.UNDEFINED, "v1"); inSequence(mySequence);
+            allowing(creator).createProperty("p2", PropertyType.UNDEFINED, "v2"); inSequence(mySequence);
             allowing(creator).finishNode(); inSequence(mySequence);
         }});
         this.parse(json);
@@ -172,7 +172,7 @@
 
         this.mockery.checking(new Expectations() {{
             allowing(creator).createNode(null, null, null); inSequence(mySequence);
-            allowing(creator).createProperty("p1", PropertyType.STRING, new String[] {"v1"}); inSequence(mySequence);
+            allowing(creator).createProperty("p1", PropertyType.UNDEFINED, new String[] {"v1"}); inSequence(mySequence);
             allowing(creator).finishNode(); inSequence(mySequence);
         }});
         this.parse(json);
@@ -253,14 +253,14 @@
         this.mockery.checking(new Expectations() {{
             allowing(creator).createNode(null, null, null); inSequence(mySequence);
             allowing(creator).createNode("c1", null, null); inSequence(mySequence);
-            allowing(creator).createProperty("c1p1", PropertyType.STRING, "v1");
+            allowing(creator).createProperty("c1p1", PropertyType.UNDEFINED, "v1");
             allowing(creator).finishNode(); inSequence(mySequence);
             allowing(creator).finishNode(); inSequence(mySequence);
         }});
         this.parse(json);
     }
-    
-    
+
+
     @org.junit.Test public void testCreateAcl() throws Exception {
     	String json = " { " +
     			"\"security:acl\" : [ " +
@@ -279,10 +279,10 @@
     			"    \"denied\" : [\"jcr:write\"]" +
     			"  }" +
     			"]" +
-    			"}";	
+    			"}";
         this.mockery.checking(new Expectations() {{
         	allowing(creator).createNode(null, null, null); inSequence(mySequence);
-            
+
             allowing(creator).createAce("username1",new String[]{"jcr:read","jcr:write"},new String[]{}); inSequence(mySequence);
             allowing(creator).createAce("groupname1",new String[]{"jcr:read","jcr:write"},null); inSequence(mySequence);
             allowing(creator).createAce("groupname2",new String[]{"jcr:read"},new String[]{"jcr:write"}); inSequence(mySequence);