You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by cz...@apache.org on 2013/03/20 09:50:18 UTC

svn commit: r1458689 - /sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/helper/jcr/JcrResourceProvider.java

Author: cziegeler
Date: Wed Mar 20 08:50:18 2013
New Revision: 1458689

URL: http://svn.apache.org/r1458689
Log:
SLING-2782 :  Try to use sling:resourceType as a node type for node creation 

Modified:
    sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/helper/jcr/JcrResourceProvider.java

Modified: sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/helper/jcr/JcrResourceProvider.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/helper/jcr/JcrResourceProvider.java?rev=1458689&r1=1458688&r2=1458689&view=diff
==============================================================================
--- sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/helper/jcr/JcrResourceProvider.java (original)
+++ sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/helper/jcr/JcrResourceProvider.java Wed Mar 20 08:50:18 2013
@@ -51,6 +51,7 @@ import org.apache.sling.api.resource.Res
 import org.apache.sling.api.resource.ResourceResolverFactory;
 import org.apache.sling.api.resource.ValueMap;
 import org.apache.sling.api.wrappers.ValueMapDecorator;
+import org.apache.sling.jcr.resource.JcrResourceConstants;
 import org.apache.sling.jcr.resource.JcrResourceUtil;
 import org.apache.sling.jcr.resource.internal.JcrModifiableValueMap;
 import org.apache.sling.jcr.resource.internal.NodeUtil;
@@ -388,7 +389,30 @@ public class JcrResourceProvider
     throws PersistenceException {
         // check for node type
         final Object nodeObj = (properties != null ? properties.get(NodeUtil.NODE_TYPE) : null);
-        final String nodeType = (nodeObj != null ? nodeObj.toString() : null);
+        // check for sling:resourcetype
+        final String nodeType;
+        if ( nodeObj != null ) {
+            nodeType = nodeObj.toString();
+        } else {
+            final Object rtObj =  (properties != null ? properties.get(JcrResourceConstants.SLING_RESOURCE_TYPE_PROPERTY) : null);
+            boolean isNodeType = false;
+            if ( rtObj != null ) {
+                final String resourceType = rtObj.toString();
+                if ( resourceType.indexOf(':') != -1 && resourceType.indexOf('/') == -1 ) {
+                    try {
+                        this.session.getWorkspace().getNodeTypeManager().getNodeType(resourceType);
+                        isNodeType = true;
+                    } catch (final RepositoryException ignore) {
+                        // we expect this, if this isn't a valid node type, therefore ignoring
+                    }
+                }
+            }
+            if ( isNodeType ) {
+                nodeType = rtObj.toString();
+            } else {
+                nodeType = null;
+            }
+        }
         try {
             final int lastPos = path.lastIndexOf('/');
             final Node parent;