sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sseif...@apache.org
Subject svn commit: r1786876 - in /sling/trunk/bundles/jcr/contentparser/src: main/java/org/apache/sling/jcr/contentparser/ main/java/org/apache/sling/jcr/contentparser/impl/ test/java/org/apache/sling/jcr/contentparser/impl/
Date Tue, 14 Mar 2017 10:57:31 GMT
Author: sseifert
Date: Tue Mar 14 10:57:31 2017
New Revision: 1786876

URL: http://svn.apache.org/viewvc?rev=1786876&view=rev
Log:
SLING-6592 remove parse(File) method from API

Modified:
    sling/trunk/bundles/jcr/contentparser/src/main/java/org/apache/sling/jcr/contentparser/ContentParser.java
    sling/trunk/bundles/jcr/contentparser/src/main/java/org/apache/sling/jcr/contentparser/impl/JcrXmlContentParser.java
    sling/trunk/bundles/jcr/contentparser/src/main/java/org/apache/sling/jcr/contentparser/impl/JsonContentParser.java
    sling/trunk/bundles/jcr/contentparser/src/test/java/org/apache/sling/jcr/contentparser/impl/JcrXmlContentParserTest.java
    sling/trunk/bundles/jcr/contentparser/src/test/java/org/apache/sling/jcr/contentparser/impl/JsonContentParserTest.java
    sling/trunk/bundles/jcr/contentparser/src/test/java/org/apache/sling/jcr/contentparser/impl/TestUtils.java

Modified: sling/trunk/bundles/jcr/contentparser/src/main/java/org/apache/sling/jcr/contentparser/ContentParser.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/jcr/contentparser/src/main/java/org/apache/sling/jcr/contentparser/ContentParser.java?rev=1786876&r1=1786875&r2=1786876&view=diff
==============================================================================
--- sling/trunk/bundles/jcr/contentparser/src/main/java/org/apache/sling/jcr/contentparser/ContentParser.java
(original)
+++ sling/trunk/bundles/jcr/contentparser/src/main/java/org/apache/sling/jcr/contentparser/ContentParser.java
Tue Mar 14 10:57:31 2017
@@ -18,7 +18,6 @@
  */
 package org.apache.sling.jcr.contentparser;
 
-import java.io.File;
 import java.io.IOException;
 import java.io.InputStream;
 import java.util.Map;
@@ -30,15 +29,6 @@ import java.util.Map;
 public interface ContentParser {
 
     /**
-     * Parse content file.
-     * @param file File
-     * @return Content
-     * @throws IOException When I/O error occurs.
-     * @throws ParseException When parsing error occurs.
-     */
-    Map<String,Object> parse(File file) throws IOException, ParseException;
-    
-    /**
      * Parse content.
      * @param is Stream with serialized content
      * @return Content as Map

Modified: sling/trunk/bundles/jcr/contentparser/src/main/java/org/apache/sling/jcr/contentparser/impl/JcrXmlContentParser.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/jcr/contentparser/src/main/java/org/apache/sling/jcr/contentparser/impl/JcrXmlContentParser.java?rev=1786876&r1=1786875&r2=1786876&view=diff
==============================================================================
--- sling/trunk/bundles/jcr/contentparser/src/main/java/org/apache/sling/jcr/contentparser/impl/JcrXmlContentParser.java
(original)
+++ sling/trunk/bundles/jcr/contentparser/src/main/java/org/apache/sling/jcr/contentparser/impl/JcrXmlContentParser.java
Tue Mar 14 10:57:31 2017
@@ -18,8 +18,6 @@
  */
 package org.apache.sling.jcr.contentparser.impl;
 
-import java.io.File;
-import java.io.FileInputStream;
 import java.io.IOException;
 import java.io.InputStream;
 import java.util.HashMap;
@@ -56,13 +54,6 @@ public final class JcrXmlContentParser i
     }
     
     @Override
-    public Map<String,Object> parse(File file) throws IOException, ParseException {
-        try (FileInputStream fis = new FileInputStream(file)) {
-            return parse(fis);
-        }
-    }
-    
-    @Override
     public Map<String,Object> parse(InputStream is) throws IOException, ParseException
{
         try {
             XmlHandler xmlHandler = new XmlHandler();

Modified: sling/trunk/bundles/jcr/contentparser/src/main/java/org/apache/sling/jcr/contentparser/impl/JsonContentParser.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/jcr/contentparser/src/main/java/org/apache/sling/jcr/contentparser/impl/JsonContentParser.java?rev=1786876&r1=1786875&r2=1786876&view=diff
==============================================================================
--- sling/trunk/bundles/jcr/contentparser/src/main/java/org/apache/sling/jcr/contentparser/impl/JsonContentParser.java
(original)
+++ sling/trunk/bundles/jcr/contentparser/src/main/java/org/apache/sling/jcr/contentparser/impl/JsonContentParser.java
Tue Mar 14 10:57:31 2017
@@ -18,8 +18,6 @@
  */
 package org.apache.sling.jcr.contentparser.impl;
 
-import java.io.File;
-import java.io.FileInputStream;
 import java.io.IOException;
 import java.io.InputStream;
 import java.util.Calendar;
@@ -59,13 +57,6 @@ public final class JsonContentParser imp
     }
     
     @Override
-    public Map<String,Object> parse(File file) throws IOException, ParseException {
-        try (FileInputStream fis = new FileInputStream(file)) {
-            return parse(fis);
-        }
-    }
-    
-    @Override
     public Map<String,Object> parse(InputStream is) throws IOException, ParseException
{
         try (JsonReader reader = jsonReaderFactory.createReader(is)) {
             return toMap(reader.readObject());

Modified: sling/trunk/bundles/jcr/contentparser/src/test/java/org/apache/sling/jcr/contentparser/impl/JcrXmlContentParserTest.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/jcr/contentparser/src/test/java/org/apache/sling/jcr/contentparser/impl/JcrXmlContentParserTest.java?rev=1786876&r1=1786875&r2=1786876&view=diff
==============================================================================
--- sling/trunk/bundles/jcr/contentparser/src/test/java/org/apache/sling/jcr/contentparser/impl/JcrXmlContentParserTest.java
(original)
+++ sling/trunk/bundles/jcr/contentparser/src/test/java/org/apache/sling/jcr/contentparser/impl/JcrXmlContentParserTest.java
Tue Mar 14 10:57:31 2017
@@ -19,6 +19,7 @@
 package org.apache.sling.jcr.contentparser.impl;
 
 import static org.apache.sling.jcr.contentparser.impl.TestUtils.getDeep;
+import static org.apache.sling.jcr.contentparser.impl.TestUtils.parse;
 import static org.junit.Assert.assertArrayEquals;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNotNull;
@@ -55,7 +56,7 @@ public class JcrXmlContentParserTest {
     @Test
     public void testParseJcrXml() throws Exception {
         ContentParser underTest = ContentParserFactory.create(ContentType.JCR_XML);
-        Map<String,Object> content = underTest.parse(file);
+        Map<String,Object> content = parse(underTest, file);
         assertNotNull(content);
         assertEquals("app:Page", content.get("jcr:primaryType"));
         assertEquals("app:PageContent", ((Map<String,Object>)content.get("jcr:content")).get("jcr:primaryType"));
@@ -65,13 +66,13 @@ public class JcrXmlContentParserTest {
     public void testParseInvalidJcrXml() throws Exception {
         file = new File("src/test/resources/invalid-test/invalid.jcr.xml");
         ContentParser underTest = ContentParserFactory.create(ContentType.JCR_XML);
-        underTest.parse(file);
+        parse(underTest, file);
     }
 
     @Test
     public void testDataTypes() throws Exception {
         ContentParser underTest = ContentParserFactory.create(ContentType.JCR_XML);
-        Map<String,Object> content = underTest.parse(file);
+        Map<String,Object> content = parse(underTest, file);
         Map<String,Object> props = getDeep(content, "jcr:content");
         
         assertEquals("en", props.get("jcr:title"));
@@ -104,7 +105,7 @@ public class JcrXmlContentParserTest {
         ContentParser underTest = ContentParserFactory.create(ContentType.JCR_XML, new ParserOptions()
                 .ignoreResourceNames(ImmutableSet.of("teaserbar", "aside"))
                 .ignorePropertyNames(ImmutableSet.of("longProp", "jcr:title")));
-        Map<String,Object> content = underTest.parse(file);
+        Map<String,Object> content = parse(underTest, file);
         Map<String,Object> props = getDeep(content, "jcr:content");
         
         assertEquals("HOME", props.get("navTitle"));
@@ -120,7 +121,7 @@ public class JcrXmlContentParserTest {
     @Ignore
     public void testSameNamePropertyAndSubResource() throws Exception {
         ContentParser underTest = ContentParserFactory.create(ContentType.JCR_XML);
-        Map<String,Object> content = underTest.parse(file);
+        Map<String,Object> content = parse(underTest, file);
         Map<String,Object> props = getDeep(content, "jcr:content/teaserbar");
         // teaserbaritem is a direct property as well as a sub resource
         assertEquals("test", props.get("teaserbaritem"));

Modified: sling/trunk/bundles/jcr/contentparser/src/test/java/org/apache/sling/jcr/contentparser/impl/JsonContentParserTest.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/jcr/contentparser/src/test/java/org/apache/sling/jcr/contentparser/impl/JsonContentParserTest.java?rev=1786876&r1=1786875&r2=1786876&view=diff
==============================================================================
--- sling/trunk/bundles/jcr/contentparser/src/test/java/org/apache/sling/jcr/contentparser/impl/JsonContentParserTest.java
(original)
+++ sling/trunk/bundles/jcr/contentparser/src/test/java/org/apache/sling/jcr/contentparser/impl/JsonContentParserTest.java
Tue Mar 14 10:57:31 2017
@@ -19,6 +19,7 @@
 package org.apache.sling.jcr.contentparser.impl;
 
 import static org.apache.sling.jcr.contentparser.impl.TestUtils.getDeep;
+import static org.apache.sling.jcr.contentparser.impl.TestUtils.parse;
 import static org.junit.Assert.assertArrayEquals;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNotNull;
@@ -52,7 +53,7 @@ public class JsonContentParserTest {
     @Test
     public void testPageJcrPrimaryType() throws Exception {
         ContentParser underTest = ContentParserFactory.create(ContentType.JSON);
-        Map<String, Object> content = underTest.parse(file);
+        Map<String, Object> content = parse(underTest, file);
 
         assertEquals("app:Page", content.get("jcr:primaryType"));
     }
@@ -60,7 +61,7 @@ public class JsonContentParserTest {
     @Test
     public void testDataTypes() throws Exception {
         ContentParser underTest = ContentParserFactory.create(ContentType.JSON);
-        Map<String, Object> content = underTest.parse(file);
+        Map<String, Object> content = parse(underTest, file);
 
         Map<String, Object> props = getDeep(content, "toolbar/profiles/jcr:content");
         assertEquals(true, props.get("hideInNav"));
@@ -77,7 +78,7 @@ public class JsonContentParserTest {
     @Test
     public void testContentProperties() throws Exception {
         ContentParser underTest = ContentParserFactory.create(ContentType.JSON);
-        Map<String, Object> content = underTest.parse(file);
+        Map<String, Object> content = parse(underTest, file);
 
         Map<String, Object> props = getDeep(content, "jcr:content/header");
         assertEquals("/content/dam/sample/header.png", props.get("imageReference"));
@@ -87,7 +88,7 @@ public class JsonContentParserTest {
     public void testCalendar() throws Exception {
         ContentParser underTest = ContentParserFactory.create(ContentType.JSON,
                 new ParserOptions().detectCalendarValues(true));
-        Map<String, Object> content = underTest.parse(file);
+        Map<String, Object> content = parse(underTest, file);
 
         Map<String, Object> props = getDeep(content, "jcr:content");
 
@@ -108,7 +109,7 @@ public class JsonContentParserTest {
     @Test
     public void testUTF8Chars() throws Exception {
         ContentParser underTest = ContentParserFactory.create(ContentType.JSON);
-        Map<String, Object> content = underTest.parse(file);
+        Map<String, Object> content = parse(underTest, file);
 
         Map<String, Object> props = getDeep(content, "jcr:content");
 
@@ -119,7 +120,7 @@ public class JsonContentParserTest {
     public void testParseInvalidJson() throws Exception {
         file = new File("src/test/resources/invalid-test/invalid.json");
         ContentParser underTest = ContentParserFactory.create(ContentType.JSON);
-        Map<String, Object> content = underTest.parse(file);
+        Map<String, Object> content = parse(underTest, file);
         assertNull(content);
     }
 
@@ -127,7 +128,7 @@ public class JsonContentParserTest {
     public void testParseInvalidJsonWithObjectList() throws Exception {
         file = new File("src/test/resources/invalid-test/contentWithObjectList.json");
         ContentParser underTest = ContentParserFactory.create(ContentType.JSON);
-        Map<String, Object> content = underTest.parse(file);
+        Map<String, Object> content = parse(underTest, file);
         assertNull(content);
     }
 
@@ -136,7 +137,7 @@ public class JsonContentParserTest {
         ContentParser underTest = ContentParserFactory.create(ContentType.JSON,
                 new ParserOptions().ignoreResourceNames(ImmutableSet.of("header", "newslist"))
                         .ignorePropertyNames(ImmutableSet.of("jcr:title")));
-        Map<String, Object> content = underTest.parse(file);
+        Map<String, Object> content = parse(underTest, file);
         Map<String, Object> props = getDeep(content, "jcr:content");
 
         assertEquals("Sample Homepage", props.get("pageTitle"));

Modified: sling/trunk/bundles/jcr/contentparser/src/test/java/org/apache/sling/jcr/contentparser/impl/TestUtils.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/jcr/contentparser/src/test/java/org/apache/sling/jcr/contentparser/impl/TestUtils.java?rev=1786876&r1=1786875&r2=1786876&view=diff
==============================================================================
--- sling/trunk/bundles/jcr/contentparser/src/test/java/org/apache/sling/jcr/contentparser/impl/TestUtils.java
(original)
+++ sling/trunk/bundles/jcr/contentparser/src/test/java/org/apache/sling/jcr/contentparser/impl/TestUtils.java
Tue Mar 14 10:57:31 2017
@@ -18,9 +18,14 @@
  */
 package org.apache.sling.jcr.contentparser.impl;
 
+import java.io.BufferedInputStream;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
 import java.util.Map;
 
 import org.apache.commons.lang3.StringUtils;
+import org.apache.sling.jcr.contentparser.ContentParser;
 
 public final class TestUtils {
     
@@ -45,4 +50,11 @@ public final class TestUtils {
       }
     }
     
+    public static Map<String,Object> parse(ContentParser contentParser, File file)
throws IOException {
+        try (FileInputStream fis = new FileInputStream(file);
+                BufferedInputStream bis = new BufferedInputStream(fis)) {
+            return contentParser.parse(bis);
+        }
+    }
+    
 }



Mime
View raw message