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 2017/03/02 21:54:49 UTC

svn commit: r1785198 - in /sling/trunk/bundles/commons/fscontentparser/src: main/java/org/apache/sling/fscontentparser/ test/java/org/apache/sling/fscontentparser/impl/

Author: sseifert
Date: Thu Mar  2 21:54:49 2017
New Revision: 1785198

URL: http://svn.apache.org/viewvc?rev=1785198&view=rev
Log:
SLING-6592 use enum instead of string constants

Added:
    sling/trunk/bundles/commons/fscontentparser/src/main/java/org/apache/sling/fscontentparser/ContentFileType.java   (with props)
Removed:
    sling/trunk/bundles/commons/fscontentparser/src/main/java/org/apache/sling/fscontentparser/ContentFileExtension.java
Modified:
    sling/trunk/bundles/commons/fscontentparser/src/main/java/org/apache/sling/fscontentparser/ContentFileParserFactory.java
    sling/trunk/bundles/commons/fscontentparser/src/test/java/org/apache/sling/fscontentparser/impl/JcrXmlContentFileParserTest.java
    sling/trunk/bundles/commons/fscontentparser/src/test/java/org/apache/sling/fscontentparser/impl/JsonContentFileParserTest.java

Modified: sling/trunk/bundles/commons/fscontentparser/src/main/java/org/apache/sling/fscontentparser/ContentFileParserFactory.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/commons/fscontentparser/src/main/java/org/apache/sling/fscontentparser/ContentFileParserFactory.java?rev=1785198&r1=1785197&r2=1785198&view=diff
==============================================================================
--- sling/trunk/bundles/commons/fscontentparser/src/main/java/org/apache/sling/fscontentparser/ContentFileParserFactory.java (original)
+++ sling/trunk/bundles/commons/fscontentparser/src/main/java/org/apache/sling/fscontentparser/ContentFileParserFactory.java Thu Mar  2 21:54:49 2017
@@ -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 ContentFileParserFact
     
     /**
      * 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);
     }
     
 }

Added: sling/trunk/bundles/commons/fscontentparser/src/main/java/org/apache/sling/fscontentparser/ContentFileType.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/commons/fscontentparser/src/main/java/org/apache/sling/fscontentparser/ContentFileType.java?rev=1785198&view=auto
==============================================================================
--- sling/trunk/bundles/commons/fscontentparser/src/main/java/org/apache/sling/fscontentparser/ContentFileType.java (added)
+++ sling/trunk/bundles/commons/fscontentparser/src/main/java/org/apache/sling/fscontentparser/ContentFileType.java Thu Mar  2 21:54:49 2017
@@ -0,0 +1,50 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.sling.fscontentparser;
+
+/**
+ * Content file types.
+ */
+public enum ContentFileType {
+
+    /**
+     * JSON content files.
+     */
+    JSON("json"),
+
+    /**
+     * JCR XML content files.
+     */
+    JCR_XML("jcr.xml");
+
+
+    private final String extension;
+
+    private ContentFileType(String extension) {
+        this.extension = extension;
+    }
+
+    /**
+     * @return Extension
+     */
+    public String getExtension() {
+        return extension;
+    }
+
+}

Propchange: sling/trunk/bundles/commons/fscontentparser/src/main/java/org/apache/sling/fscontentparser/ContentFileType.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: sling/trunk/bundles/commons/fscontentparser/src/main/java/org/apache/sling/fscontentparser/ContentFileType.java
------------------------------------------------------------------------------
--- svn:keywords (added)
+++ svn:keywords Thu Mar  2 21:54:49 2017
@@ -0,0 +1 @@
+LastChangedDate LastChangedRevision LastChangedBy HeadURL Id Author

Propchange: sling/trunk/bundles/commons/fscontentparser/src/main/java/org/apache/sling/fscontentparser/ContentFileType.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: sling/trunk/bundles/commons/fscontentparser/src/test/java/org/apache/sling/fscontentparser/impl/JcrXmlContentFileParserTest.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/commons/fscontentparser/src/test/java/org/apache/sling/fscontentparser/impl/JcrXmlContentFileParserTest.java?rev=1785198&r1=1785197&r2=1785198&view=diff
==============================================================================
--- sling/trunk/bundles/commons/fscontentparser/src/test/java/org/apache/sling/fscontentparser/impl/JcrXmlContentFileParserTest.java (original)
+++ sling/trunk/bundles/commons/fscontentparser/src/test/java/org/apache/sling/fscontentparser/impl/JcrXmlContentFileParserTest.java Thu Mar  2 21:54:49 2017
@@ -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);

Modified: sling/trunk/bundles/commons/fscontentparser/src/test/java/org/apache/sling/fscontentparser/impl/JsonContentFileParserTest.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/commons/fscontentparser/src/test/java/org/apache/sling/fscontentparser/impl/JsonContentFileParserTest.java?rev=1785198&r1=1785197&r2=1785198&view=diff
==============================================================================
--- sling/trunk/bundles/commons/fscontentparser/src/test/java/org/apache/sling/fscontentparser/impl/JsonContentFileParserTest.java (original)
+++ sling/trunk/bundles/commons/fscontentparser/src/test/java/org/apache/sling/fscontentparser/impl/JsonContentFileParserTest.java Thu Mar  2 21:54:49 2017
@@ -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);