You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by ss...@apache.org on 2019/08/01 15:34:46 UTC

[sling-org-apache-sling-testing-sling-mock] branch master updated: SLING-8610 sling-mock: Update to Content Parser 2.0.0

This is an automated email from the ASF dual-hosted git repository.

sseifert pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-testing-sling-mock.git


The following commit(s) were added to refs/heads/master by this push:
     new b8f61ce  SLING-8610 sling-mock: Update to Content Parser 2.0.0
b8f61ce is described below

commit b8f61ce97e60bb3efb13004106409da6cdf5d4c4
Author: sseifert <ss...@pro-vision.de>
AuthorDate: Thu Aug 1 17:33:42 2019 +0200

    SLING-8610 sling-mock: Update to Content Parser 2.0.0
---
 core/pom.xml                                       | 10 ++++++--
 .../testing/mock/sling/loader/ContentLoader.java   | 28 +++++++++++-----------
 .../mock/sling/loader/LoaderContentHandler.java    |  2 +-
 3 files changed, 23 insertions(+), 17 deletions(-)

diff --git a/core/pom.xml b/core/pom.xml
index 57359b3..4fbc48c 100644
--- a/core/pom.xml
+++ b/core/pom.xml
@@ -134,8 +134,14 @@
         </dependency>
         <dependency>
             <groupId>org.apache.sling</groupId>
-            <artifactId>org.apache.sling.jcr.contentparser</artifactId>
-            <version>1.2.6</version>
+            <artifactId>org.apache.sling.contentparser.api</artifactId>
+            <version>2.0.0</version>
+            <scope>compile</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.sling</groupId>
+            <artifactId>org.apache.sling.contentparser.json</artifactId>
+            <version>2.0.0</version>
             <scope>compile</scope>
         </dependency>
         <dependency>
diff --git a/core/src/main/java/org/apache/sling/testing/mock/sling/loader/ContentLoader.java b/core/src/main/java/org/apache/sling/testing/mock/sling/loader/ContentLoader.java
index 856a0a5..8f4c403 100644
--- a/core/src/main/java/org/apache/sling/testing/mock/sling/loader/ContentLoader.java
+++ b/core/src/main/java/org/apache/sling/testing/mock/sling/loader/ContentLoader.java
@@ -32,12 +32,11 @@ import org.apache.sling.api.resource.Resource;
 import org.apache.sling.api.resource.ResourceResolver;
 import org.apache.sling.api.resource.ResourceUtil;
 import org.apache.sling.commons.mime.MimeTypeService;
-import org.apache.sling.jcr.contentparser.ContentParser;
-import org.apache.sling.jcr.contentparser.ContentParserFactory;
-import org.apache.sling.jcr.contentparser.ContentType;
-import org.apache.sling.jcr.contentparser.JsonParserFeature;
-import org.apache.sling.jcr.contentparser.ParseException;
-import org.apache.sling.jcr.contentparser.ParserOptions;
+import org.apache.sling.contentparser.api.ContentParser;
+import org.apache.sling.contentparser.api.ParserOptions;
+import org.apache.sling.contentparser.json.JSONParserFeature;
+import org.apache.sling.contentparser.json.JSONParserOptions;
+import org.apache.sling.contentparser.json.internal.JSONContentParser;
 import org.apache.sling.testing.mock.sling.ResourceResolverType;
 import org.jetbrains.annotations.NotNull;
 import org.jetbrains.annotations.Nullable;
@@ -84,6 +83,7 @@ public final class ContentLoader {
     private final boolean autoCommit;
     private final Set<String> ignoredNames;
     private final ContentParser jsonParser;
+    private final ParserOptions jsonParserOptions;
 
     /**
      * @param resourceResolver Resource resolver
@@ -121,11 +121,13 @@ public final class ContentLoader {
         this.bundleContext = bundleContext;
         this.autoCommit = autoCommit;
         this.ignoredNames = getIgnoredNamesForResourceResolverType(resourceResolverType);
-        this.jsonParser = ContentParserFactory.create(ContentType.JSON, new ParserOptions()
-                .detectCalendarValues(true)
-                .ignorePropertyNames(this.ignoredNames)
-                .ignoreResourceNames(this.ignoredNames)
-                .jsonParserFeatures(EnumSet.of(JsonParserFeature.COMMENTS, JsonParserFeature.QUOTE_TICK)));
+        this.jsonParserOptions = new JSONParserOptions()
+            .withFeatures(EnumSet.of(JSONParserFeature.COMMENTS, JSONParserFeature.QUOTE_TICK))
+            .detectCalendarValues(true)
+            .ignorePropertyNames(this.ignoredNames)
+            .ignoreResourceNames(this.ignoredNames);
+        // JSONContentParser is an OSGi service - for sake of simplicity in this mock environment instantiate it directly
+        this.jsonParser = new JSONContentParser();
     }
     
     private final Set<String> getIgnoredNamesForResourceResolverType(ResourceResolverType resourceResolverType) {
@@ -220,13 +222,11 @@ public final class ContentLoader {
             }
 
             LoaderContentHandler contentHandler = new LoaderContentHandler(destPath, resourceResolver);
-            jsonParser.parse(contentHandler, inputStream);
+            jsonParser.parse(contentHandler, inputStream, jsonParserOptions);
             if (autoCommit) {
                 resourceResolver.commit();
             }
             return resourceResolver.getResource(destPath);
-        } catch (ParseException ex) {
-            throw new RuntimeException(ex);
         } catch (IOException ex) {
             throw new RuntimeException(ex);
         }
diff --git a/core/src/main/java/org/apache/sling/testing/mock/sling/loader/LoaderContentHandler.java b/core/src/main/java/org/apache/sling/testing/mock/sling/loader/LoaderContentHandler.java
index 3b44805..4c7c7d4 100644
--- a/core/src/main/java/org/apache/sling/testing/mock/sling/loader/LoaderContentHandler.java
+++ b/core/src/main/java/org/apache/sling/testing/mock/sling/loader/LoaderContentHandler.java
@@ -30,7 +30,7 @@ import org.apache.sling.api.resource.PersistenceException;
 import org.apache.sling.api.resource.Resource;
 import org.apache.sling.api.resource.ResourceResolver;
 import org.apache.sling.api.resource.ResourceUtil;
-import org.apache.sling.jcr.contentparser.ContentHandler;
+import org.apache.sling.contentparser.api.ContentHandler;
 import org.jetbrains.annotations.NotNull;
 import org.jetbrains.annotations.Nullable;