You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by ra...@apache.org on 2019/07/22 09:43:58 UTC

[sling-org-apache-sling-contentparser-json] 04/08: SLING-8570 - Extract a generic Content Parser API from org.apache.sling.jcr.contentparser with pluggable implementations

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

radu pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-contentparser-json.git

commit e6239df5616474e37d6da744a1f0e5d03ef48ef1
Author: Radu Cotescu <ra...@apache.org>
AuthorDate: Mon Jul 15 12:02:03 2019 +0200

    SLING-8570 - Extract a generic Content Parser API from org.apache.sling.jcr.contentparser with pluggable implementations
    
    * added parser for JCR-flavoured XML
    * made the ParserHelper compatible with both Java 8 and Java 11
    * reduced the number of dependencies for all modules
---
 pom.xml                                            | 27 ---------------
 .../json/internal/JsonTicksConverter.java          |  3 +-
 .../json/internal/JsonContentParserTest.java       | 39 +++++++++++++---------
 3 files changed, 24 insertions(+), 45 deletions(-)

diff --git a/pom.xml b/pom.xml
index 7e6dbd9..99d3bd0 100644
--- a/pom.xml
+++ b/pom.xml
@@ -62,32 +62,11 @@
             <scope>provided</scope>
         </dependency>
         <dependency>
-            <groupId>org.apache.commons</groupId>
-            <artifactId>commons-lang3</artifactId>
-            <version>3.8</version>
-            <scope>provided</scope>
-        </dependency>
-        <dependency>
             <groupId>org.osgi</groupId>
             <artifactId>org.osgi.service.component.annotations</artifactId>
             <scope>provided</scope>
         </dependency>
         <dependency>
-            <groupId>org.osgi</groupId>
-            <artifactId>org.osgi.service.component</artifactId>
-            <scope>provided</scope>
-        </dependency>
-        <dependency>
-            <groupId>org.osgi</groupId>
-            <artifactId>org.osgi.framework</artifactId>
-            <scope>provided</scope>
-        </dependency>
-        <dependency>
-            <groupId>org.slf4j</groupId>
-            <artifactId>slf4j-api</artifactId>
-            <scope>provided</scope>
-        </dependency>
-        <dependency>
             <groupId>org.apache.sling</groupId>
             <artifactId>org.apache.sling.contentparser.testutils</artifactId>
             <version>0.9.0-SNAPSHOT</version>
@@ -99,12 +78,6 @@
             <scope>test</scope>
         </dependency>
         <dependency>
-            <groupId>com.google.guava</groupId>
-            <artifactId>guava</artifactId>
-            <version>15.0</version>
-            <scope>test</scope>
-        </dependency>
-        <dependency>
             <groupId>org.apache.johnzon</groupId>
             <artifactId>johnzon-core</artifactId>
             <version>1.0.0</version>
diff --git a/src/main/java/org/apache/sling/contentparser/json/internal/JsonTicksConverter.java b/src/main/java/org/apache/sling/contentparser/json/internal/JsonTicksConverter.java
index df0be76..15b6553 100644
--- a/src/main/java/org/apache/sling/contentparser/json/internal/JsonTicksConverter.java
+++ b/src/main/java/org/apache/sling/contentparser/json/internal/JsonTicksConverter.java
@@ -59,8 +59,7 @@ final class JsonTicksConverter {
                     if (in == '"') {
                         if (quoted) {
                             quoted = false;
-                        }
-                        else if (tickQuoted) {
+                        } else {
                             output.append("\\");
                         }
                     }
diff --git a/src/test/java/org/apache/sling/contentparser/json/internal/JsonContentParserTest.java b/src/test/java/org/apache/sling/contentparser/json/internal/JsonContentParserTest.java
index b52e934..f82c8a4 100644
--- a/src/test/java/org/apache/sling/contentparser/json/internal/JsonContentParserTest.java
+++ b/src/test/java/org/apache/sling/contentparser/json/internal/JsonContentParserTest.java
@@ -20,8 +20,11 @@ package org.apache.sling.contentparser.json.internal;
 
 import java.io.File;
 import java.math.BigDecimal;
+import java.util.Arrays;
 import java.util.Calendar;
+import java.util.Collections;
 import java.util.EnumSet;
+import java.util.HashSet;
 import java.util.Map;
 import java.util.TimeZone;
 
@@ -34,8 +37,6 @@ import org.apache.sling.contentparser.testutils.mapsupport.ContentElement;
 import org.junit.Before;
 import org.junit.Test;
 
-import com.google.common.collect.ImmutableSet;
-
 import static junit.framework.TestCase.assertNull;
 import static org.junit.Assert.assertArrayEquals;
 import static org.junit.Assert.assertEquals;
@@ -62,8 +63,9 @@ public class JsonContentParserTest {
     @Test
     public void testDataTypes() throws Exception {
         ContentElement content = TestUtils.parse(contentParser, file);
-
-        Map<String, Object> props = content.getChild("toolbar/profiles/jcr:content").getProperties();
+        ContentElement child = content.getChild("toolbar/profiles/jcr:content");
+        assertNotNull("Expected child at toolbar/profiles/jcr:content", child);
+        Map<String, Object> props = child.getProperties();
         assertEquals(true, props.get("hideInNav"));
 
         assertEquals(1234567890123L, props.get("longProp"));
@@ -78,16 +80,18 @@ public class JsonContentParserTest {
     @Test
     public void testContentProperties() throws Exception {
         ContentElement content = TestUtils.parse(contentParser, file);
-
-        Map<String, Object> props = content.getChild("jcr:content/header").getProperties();
+        ContentElement child = content.getChild("jcr:content/header");
+        assertNotNull("Expected child at jcr:content/header", child);
+        Map<String, Object> props = child.getProperties();
         assertEquals("/content/dam/sample/header.png", props.get("imageReference"));
     }
 
     @Test
     public void testCalendar() throws Exception {
         ContentElement content = TestUtils.parse(contentParser, new ParserOptions().detectCalendarValues(true), file);
-
-        Map<String, Object> props = content.getChild("jcr:content").getProperties();
+        ContentElement child = content.getChild("jcr:content");
+        assertNotNull("Expected child at jcr:content", child);
+        Map<String, Object> props = child.getProperties();
 
         Calendar calendar = (Calendar) props.get("app:lastModified");
         assertNotNull(calendar);
@@ -106,8 +110,9 @@ public class JsonContentParserTest {
     @Test
     public void testIso8601Calendar() throws Exception {
         ContentElement content = TestUtils.parse(contentParser, new ParserOptions().detectCalendarValues(true), file);
-
-        Map<String, Object> props = content.getChild("jcr:content").getProperties();
+        ContentElement child = content.getChild("jcr:content");
+        assertNotNull("Expected child at jcr:content", child);
+        Map<String, Object> props = child.getProperties();
 
         Calendar calendar = (Calendar) props.get("dateISO8601String");
         assertNotNull(calendar);
@@ -124,8 +129,9 @@ public class JsonContentParserTest {
     @Test
     public void testUTF8Chars() throws Exception {
         ContentElement content = TestUtils.parse(contentParser, file);
-
-        Map<String, Object> props = content.getChild("jcr:content").getProperties();
+        ContentElement child = content.getChild("jcr:content");
+        assertNotNull("Expected child at jcr:content", child);
+        Map<String, Object> props = child.getProperties();
 
         assertEquals("äöü߀", props.get("utf8Property"));
     }
@@ -148,10 +154,11 @@ public class JsonContentParserTest {
     public void testIgnoreResourcesProperties() throws Exception {
         ContentElement content = TestUtils.parse(
                 contentParser,
-                new ParserOptions().ignoreResourceNames(ImmutableSet.of("header", "newslist", "security:acl", "security:principals"))
-                        .ignorePropertyNames(ImmutableSet.of("jcr:title")), file);
+                new ParserOptions().ignoreResourceNames(Collections
+                        .unmodifiableSet(new HashSet<>(Arrays.asList("header", "newslist", "security:acl", "security:principals"))))
+                        .ignorePropertyNames(Collections.unmodifiableSet(new HashSet<>(Arrays.asList("jcr:title")))), file);
         ContentElement child = content.getChild("jcr:content");
-
+        assertNotNull("Expected child at jcr:content", child);
         assertEquals("Sample Homepage", child.getProperties().get("pageTitle"));
         assertNull(child.getProperties().get("jcr:title"));
 
@@ -167,8 +174,8 @@ public class JsonContentParserTest {
     public void testGetChild() throws Exception {
         ContentElement content = TestUtils.parse(contentParser, file);
         assertNull(content.getName());
-
         ContentElement deepChild = content.getChild("jcr:content/par/image/file/jcr:content");
+        assertNotNull("Expected child at jcr:content/par/image/file/jcr:content", deepChild);
         assertEquals("jcr:content", deepChild.getName());
         assertEquals("nt:resource", deepChild.getProperties().get("jcr:primaryType"));