sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From romb...@apache.org
Subject [sling-org-apache-sling-jcr-contentloader] 19/28: SLING-1172 Allow uploading JSON files to create content structures Fixed the import case where no name is provided
Date Tue, 07 Nov 2017 09:47:59 GMT
This is an automated email from the ASF dual-hosted git repository.

rombert pushed a commit to annotated tag org.apache.sling.jcr.contentloader-2.1.0
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-jcr-contentloader.git

commit a4686f9d156da1022f3210e1ff811a1da9e07e28
Author: Eric Norman <enorman@apache.org>
AuthorDate: Fri Jul 2 23:18:18 2010 +0000

    SLING-1172 Allow uploading JSON files to create content structures
    Fixed the import case where no name is provided
    
    git-svn-id: https://svn.apache.org/repos/asf/sling/trunk/bundles/jcr/contentloader@960134
13f79535-47bb-0310-9956-ffa450edef68
---
 .../sling/jcr/contentloader/internal/DefaultContentCreator.java      | 3 ++-
 .../sling/jcr/contentloader/internal/DefaultContentImporter.java     | 5 ++++-
 .../apache/sling/jcr/contentloader/internal/readers/JsonReader.java  | 4 +---
 3 files changed, 7 insertions(+), 5 deletions(-)

diff --git a/src/main/java/org/apache/sling/jcr/contentloader/internal/DefaultContentCreator.java
b/src/main/java/org/apache/sling/jcr/contentloader/internal/DefaultContentCreator.java
index 3c5565d..57af6c1 100644
--- a/src/main/java/org/apache/sling/jcr/contentloader/internal/DefaultContentCreator.java
+++ b/src/main/java/org/apache/sling/jcr/contentloader/internal/DefaultContentCreator.java
@@ -239,6 +239,7 @@ public class DefaultContentCreator implements ContentCreator {
                            String[] mixinNodeTypes)
     throws RepositoryException {
         final Node parentNode = this.parentNodeStack.peek();
+        boolean isParentImport = (name == null && isParentNodeImport);
         if ( name == null ) {
             if ( this.parentNodeStack.size() > 1 ) {
                 throw new RepositoryException("Node needs to have a name.");
@@ -247,7 +248,7 @@ public class DefaultContentCreator implements ContentCreator {
         }
 
         // if we are in parent node import mode, we don't create the root top level node!
-        if ( !isParentNodeImport || this.parentNodeStack.size() > 1 ) {
+        if ( !isParentImport || this.parentNodeStack.size() > 1 ) {
             // if node already exists but should be overwritten, delete it
             if (!this.ignoreOverwriteFlag && this.configuration.isOverwrite() &&
parentNode.hasNode(name)) {
                 parentNode.getNode(name).remove();
diff --git a/src/main/java/org/apache/sling/jcr/contentloader/internal/DefaultContentImporter.java
b/src/main/java/org/apache/sling/jcr/contentloader/internal/DefaultContentImporter.java
index c974fd7..b1c14e9 100644
--- a/src/main/java/org/apache/sling/jcr/contentloader/internal/DefaultContentImporter.java
+++ b/src/main/java/org/apache/sling/jcr/contentloader/internal/DefaultContentImporter.java
@@ -120,7 +120,10 @@ public class DefaultContentImporter extends BaseImportLoader implements
JcrConte
     private String toPlainName(DefaultContentCreator contentCreator, String name) {
         final String providerExt = contentCreator.getImportProviderExtension(name);
         if (providerExt != null) {
-            return name.substring(0, name.length() - providerExt.length());
+        	if (name.length() == providerExt.length()) {
+        		return null; //no name is provided
+        	}
+        	return name.substring(0, name.length() - providerExt.length());
         }
         return name;
     }
diff --git a/src/main/java/org/apache/sling/jcr/contentloader/internal/readers/JsonReader.java
b/src/main/java/org/apache/sling/jcr/contentloader/internal/readers/JsonReader.java
index 01696e0..2a8e599 100644
--- a/src/main/java/org/apache/sling/jcr/contentloader/internal/readers/JsonReader.java
+++ b/src/main/java/org/apache/sling/jcr/contentloader/internal/readers/JsonReader.java
@@ -105,7 +105,6 @@ public class JsonReader implements ContentReader {
         ignoredNames.add("jcr:successors");
         ignoredNames.add("jcr:checkedOut");
         ignoredNames.add("jcr:created");
-        ignoredNames.add(":name");
     }
 
     private static final Set<String> ignoredPrincipalPropertyNames = new HashSet<String>();
@@ -157,8 +156,7 @@ public class JsonReader implements ContentReader {
             }
 
             JSONObject json = new JSONObject(jsonString);
-            String optionalName = json.optString(":name", null);
-            this.createNode(optionalName, json, contentCreator);
+            this.createNode(null, json, contentCreator);
         } catch (JSONException je) {
             throw (IOException) new IOException(je.getMessage()).initCause(je);
         }

-- 
To stop receiving notification emails like this one, please contact
"commits@sling.apache.org" <commits@sling.apache.org>.

Mime
View raw message