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

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

commit 0969aab040265db91b0d447124f7981dda358a87
Author: Stefan Seifert <[email protected]>
AuthorDate: Thu Mar 2 21:54:49 2017 +0000

    SLING-6592 use enum instead of string constants
    
    git-svn-id: 
https://svn.apache.org/repos/asf/sling/trunk/bundles/commons/fscontentparser@1785198
 13f79535-47bb-0310-9956-ffa450edef68
---
 .../fscontentparser/ContentFileParserFactory.java  | 24 ++++++++++----------
 ...tentFileExtension.java => ContentFileType.java} | 26 +++++++++++++++-------
 .../impl/JcrXmlContentFileParserTest.java          | 10 ++++-----
 .../impl/JsonContentFileParserTest.java            | 18 +++++++--------
 4 files changed, 44 insertions(+), 34 deletions(-)

diff --git 
a/src/main/java/org/apache/sling/fscontentparser/ContentFileParserFactory.java 
b/src/main/java/org/apache/sling/fscontentparser/ContentFileParserFactory.java
index d4ebe95..7fc66e7 100644
--- 
a/src/main/java/org/apache/sling/fscontentparser/ContentFileParserFactory.java
+++ 
b/src/main/java/org/apache/sling/fscontentparser/ContentFileParserFactory.java
@@ -18,7 +18,6 @@
  */
 package org.apache.sling.fscontentparser;
 
-import org.apache.commons.lang3.StringUtils;
 import org.apache.sling.fscontentparser.impl.JcrXmlContentFileParser;
 import org.apache.sling.fscontentparser.impl.JsonContentFileParser;
 
@@ -33,27 +32,28 @@ public final class ContentFileParserFactory {
     
     /**
      * Create content file parser.
-     * @param fileExtension File extension from {@link ContentFileExtension}.
+     * @param type Content file type
      * @return Content file parser
      */
-    public static ContentFileParser create(String fileExtension) {
-        return create(fileExtension, new ParserOptions());
+    public static ContentFileParser create(ContentFileType type) {
+        return create(type, new ParserOptions());
     }
     
     /**
      * Create content file parser.
-     * @param fileExtension File extension from {@link ContentFileExtension}.
+     * @param type Content file type
      * @param options Parser options
      * @return Content file parser
      */
-    public static ContentFileParser create(String fileExtension, ParserOptions 
options) {
-        if (StringUtils.equals(fileExtension, ContentFileExtension.JSON)) {
-            return new JsonContentFileParser(options);
+    public static ContentFileParser create(ContentFileType type, ParserOptions 
options) {
+        switch (type) {
+            case JSON:
+                return new JsonContentFileParser(options);
+            case JCR_XML:
+                return new JcrXmlContentFileParser(options);
+            default:
+                throw new IllegalArgumentException("Unsupported file 
extension: " + type);
         }
-        else if (StringUtils.equals(fileExtension, 
ContentFileExtension.JCR_XML)) {
-            return new JcrXmlContentFileParser(options);
-        }
-        throw new IllegalArgumentException("Unsupported file extension: " + 
fileExtension);
     }
     
 }
diff --git 
a/src/main/java/org/apache/sling/fscontentparser/ContentFileExtension.java 
b/src/main/java/org/apache/sling/fscontentparser/ContentFileType.java
similarity index 76%
rename from 
src/main/java/org/apache/sling/fscontentparser/ContentFileExtension.java
rename to src/main/java/org/apache/sling/fscontentparser/ContentFileType.java
index a33a4b8..72ca467 100644
--- a/src/main/java/org/apache/sling/fscontentparser/ContentFileExtension.java
+++ b/src/main/java/org/apache/sling/fscontentparser/ContentFileType.java
@@ -21,20 +21,30 @@ package org.apache.sling.fscontentparser;
 /**
  * Content file types.
  */
-public final class ContentFileExtension {
-    
+public enum ContentFileType {
+
     /**
      * JSON content files.
      */
-    public static final String JSON = "json";
+    JSON("json"),
 
     /**
      * JCR XML content files.
      */
-    public static final String JCR_XML = "jcr.xml";
-        
-    private ContentFileExtension() {
-        // constants only
+    JCR_XML("jcr.xml");
+
+
+    private final String extension;
+
+    private ContentFileType(String extension) {
+        this.extension = extension;
     }
-    
+
+    /**
+     * @return Extension
+     */
+    public String getExtension() {
+        return extension;
+    }
+
 }
diff --git 
a/src/test/java/org/apache/sling/fscontentparser/impl/JcrXmlContentFileParserTest.java
 
b/src/test/java/org/apache/sling/fscontentparser/impl/JcrXmlContentFileParserTest.java
index 78f02c8..d89917e 100644
--- 
a/src/test/java/org/apache/sling/fscontentparser/impl/JcrXmlContentFileParserTest.java
+++ 
b/src/test/java/org/apache/sling/fscontentparser/impl/JcrXmlContentFileParserTest.java
@@ -30,7 +30,7 @@ import java.util.Map;
 import java.util.TimeZone;
 
 import org.apache.jackrabbit.util.ISO9075;
-import org.apache.sling.fscontentparser.ContentFileExtension;
+import org.apache.sling.fscontentparser.ContentFileType;
 import org.apache.sling.fscontentparser.ContentFileParser;
 import org.apache.sling.fscontentparser.ContentFileParserFactory;
 import org.apache.sling.fscontentparser.ParseException;
@@ -52,7 +52,7 @@ public class JcrXmlContentFileParserTest {
     @SuppressWarnings("unchecked")
     @Test
     public void testParseJcrXml() throws Exception {
-        ContentFileParser underTest = 
ContentFileParserFactory.create(ContentFileExtension.JCR_XML);
+        ContentFileParser underTest = 
ContentFileParserFactory.create(ContentFileType.JCR_XML);
         Map<String,Object> content = underTest.parse(file);
         assertNotNull(content);
         assertEquals("app:Page", content.get("jcr:primaryType"));
@@ -62,13 +62,13 @@ public class JcrXmlContentFileParserTest {
     @Test(expected=ParseException.class)
     public void testParseInvalidJcrXml() throws Exception {
         file = new File("src/test/resources/invalid-test/invalid.jcr.xml");
-        ContentFileParser underTest = 
ContentFileParserFactory.create(ContentFileExtension.JCR_XML);
+        ContentFileParser underTest = 
ContentFileParserFactory.create(ContentFileType.JCR_XML);
         underTest.parse(file);
     }
 
     @Test
     public void testDataTypes() throws Exception {
-        ContentFileParser underTest = 
ContentFileParserFactory.create(ContentFileExtension.JCR_XML);
+        ContentFileParser underTest = 
ContentFileParserFactory.create(ContentFileType.JCR_XML);
         Map<String,Object> content = underTest.parse(file);
         Map<String,Object> props = getDeep(content, "jcr:content");
         
@@ -99,7 +99,7 @@ public class JcrXmlContentFileParserTest {
 
     @Test
     public void testIgnoreResourcesProperties() throws Exception {
-        ContentFileParser underTest = 
ContentFileParserFactory.create(ContentFileExtension.JCR_XML, new 
ParserOptions()
+        ContentFileParser underTest = 
ContentFileParserFactory.create(ContentFileType.JCR_XML, new ParserOptions()
                 .ignoreResourceNames(ImmutableSet.of("teaserbar", "aside"))
                 .ignorePropertyNames(ImmutableSet.of("longProp", 
"jcr:title")));
         Map<String,Object> content = underTest.parse(file);
diff --git 
a/src/test/java/org/apache/sling/fscontentparser/impl/JsonContentFileParserTest.java
 
b/src/test/java/org/apache/sling/fscontentparser/impl/JsonContentFileParserTest.java
index 175e3bf..074cf67 100644
--- 
a/src/test/java/org/apache/sling/fscontentparser/impl/JsonContentFileParserTest.java
+++ 
b/src/test/java/org/apache/sling/fscontentparser/impl/JsonContentFileParserTest.java
@@ -29,7 +29,7 @@ import java.util.Calendar;
 import java.util.Map;
 import java.util.TimeZone;
 
-import org.apache.sling.fscontentparser.ContentFileExtension;
+import org.apache.sling.fscontentparser.ContentFileType;
 import org.apache.sling.fscontentparser.ContentFileParser;
 import org.apache.sling.fscontentparser.ContentFileParserFactory;
 import org.apache.sling.fscontentparser.ParseException;
@@ -50,7 +50,7 @@ public class JsonContentFileParserTest {
 
     @Test
     public void testPageJcrPrimaryType() throws Exception {
-        ContentFileParser underTest = 
ContentFileParserFactory.create(ContentFileExtension.JSON);
+        ContentFileParser underTest = 
ContentFileParserFactory.create(ContentFileType.JSON);
         Map<String, Object> content = underTest.parse(file);
 
         assertEquals("app:Page", content.get("jcr:primaryType"));
@@ -58,7 +58,7 @@ public class JsonContentFileParserTest {
 
     @Test
     public void testDataTypes() throws Exception {
-        ContentFileParser underTest = 
ContentFileParserFactory.create(ContentFileExtension.JSON);
+        ContentFileParser underTest = 
ContentFileParserFactory.create(ContentFileType.JSON);
         Map<String, Object> content = underTest.parse(file);
 
         Map<String, Object> props = getDeep(content, 
"toolbar/profiles/jcr:content");
@@ -75,7 +75,7 @@ public class JsonContentFileParserTest {
 
     @Test
     public void testContentProperties() throws Exception {
-        ContentFileParser underTest = 
ContentFileParserFactory.create(ContentFileExtension.JSON);
+        ContentFileParser underTest = 
ContentFileParserFactory.create(ContentFileType.JSON);
         Map<String, Object> content = underTest.parse(file);
 
         Map<String, Object> props = getDeep(content, "jcr:content/header");
@@ -84,7 +84,7 @@ public class JsonContentFileParserTest {
 
     @Test
     public void testCalendar() throws Exception {
-        ContentFileParser underTest = 
ContentFileParserFactory.create(ContentFileExtension.JSON,
+        ContentFileParser underTest = 
ContentFileParserFactory.create(ContentFileType.JSON,
                 new ParserOptions().detectCalendarValues(true));
         Map<String, Object> content = underTest.parse(file);
 
@@ -106,7 +106,7 @@ public class JsonContentFileParserTest {
 
     @Test
     public void testUTF8Chars() throws Exception {
-        ContentFileParser underTest = 
ContentFileParserFactory.create(ContentFileExtension.JSON);
+        ContentFileParser underTest = 
ContentFileParserFactory.create(ContentFileType.JSON);
         Map<String, Object> content = underTest.parse(file);
 
         Map<String, Object> props = getDeep(content, "jcr:content");
@@ -117,7 +117,7 @@ public class JsonContentFileParserTest {
     @Test(expected = ParseException.class)
     public void testParseInvalidJson() throws Exception {
         file = new File("src/test/resources/invalid-test/invalid.json");
-        ContentFileParser underTest = 
ContentFileParserFactory.create(ContentFileExtension.JSON);
+        ContentFileParser underTest = 
ContentFileParserFactory.create(ContentFileType.JSON);
         Map<String, Object> content = underTest.parse(file);
         assertNull(content);
     }
@@ -125,14 +125,14 @@ public class JsonContentFileParserTest {
     @Test(expected = ParseException.class)
     public void testParseInvalidJsonWithObjectList() throws Exception {
         file = new 
File("src/test/resources/invalid-test/contentWithObjectList.json");
-        ContentFileParser underTest = 
ContentFileParserFactory.create(ContentFileExtension.JSON);
+        ContentFileParser underTest = 
ContentFileParserFactory.create(ContentFileType.JSON);
         Map<String, Object> content = underTest.parse(file);
         assertNull(content);
     }
 
     @Test
     public void testIgnoreResourcesProperties() throws Exception {
-        ContentFileParser underTest = 
ContentFileParserFactory.create(ContentFileExtension.JSON,
+        ContentFileParser underTest = 
ContentFileParserFactory.create(ContentFileType.JSON,
                 new 
ParserOptions().ignoreResourceNames(ImmutableSet.of("header", "newslist"))
                         .ignorePropertyNames(ImmutableSet.of("jcr:title")));
         Map<String, Object> content = underTest.parse(file);

-- 
To stop receiving notification emails like this one, please contact
"[email protected]" <[email protected]>.

Reply via email to