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 6cefe40f28d63bc9975e384ff24acc3146672813 Author: Stefan Seifert <[email protected]> AuthorDate: Tue Mar 14 10:57:31 2017 +0000 SLING-6592 remove parse(File) method from API git-svn-id: https://svn.apache.org/repos/asf/sling/trunk/bundles/jcr/contentparser@1786876 13f79535-47bb-0310-9956-ffa450edef68 --- .../apache/sling/jcr/contentparser/ContentParser.java | 10 ---------- .../jcr/contentparser/impl/JcrXmlContentParser.java | 9 --------- .../sling/jcr/contentparser/impl/JsonContentParser.java | 9 --------- .../jcr/contentparser/impl/JcrXmlContentParserTest.java | 11 ++++++----- .../jcr/contentparser/impl/JsonContentParserTest.java | 17 +++++++++-------- .../apache/sling/jcr/contentparser/impl/TestUtils.java | 12 ++++++++++++ 6 files changed, 27 insertions(+), 41 deletions(-) diff --git a/src/main/java/org/apache/sling/jcr/contentparser/ContentParser.java b/src/main/java/org/apache/sling/jcr/contentparser/ContentParser.java index cb6d013..1d9595a 100644 --- a/src/main/java/org/apache/sling/jcr/contentparser/ContentParser.java +++ b/src/main/java/org/apache/sling/jcr/contentparser/ContentParser.java @@ -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 diff --git a/src/main/java/org/apache/sling/jcr/contentparser/impl/JcrXmlContentParser.java b/src/main/java/org/apache/sling/jcr/contentparser/impl/JcrXmlContentParser.java index dde8c16..2af30e7 100644 --- a/src/main/java/org/apache/sling/jcr/contentparser/impl/JcrXmlContentParser.java +++ b/src/main/java/org/apache/sling/jcr/contentparser/impl/JcrXmlContentParser.java @@ -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 implements ContentParser { } @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(); diff --git a/src/main/java/org/apache/sling/jcr/contentparser/impl/JsonContentParser.java b/src/main/java/org/apache/sling/jcr/contentparser/impl/JsonContentParser.java index b070701..a17e91e 100644 --- a/src/main/java/org/apache/sling/jcr/contentparser/impl/JsonContentParser.java +++ b/src/main/java/org/apache/sling/jcr/contentparser/impl/JsonContentParser.java @@ -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 implements ContentParser { } @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()); diff --git a/src/test/java/org/apache/sling/jcr/contentparser/impl/JcrXmlContentParserTest.java b/src/test/java/org/apache/sling/jcr/contentparser/impl/JcrXmlContentParserTest.java index d99a025..1faaf4e 100644 --- a/src/test/java/org/apache/sling/jcr/contentparser/impl/JcrXmlContentParserTest.java +++ b/src/test/java/org/apache/sling/jcr/contentparser/impl/JcrXmlContentParserTest.java @@ -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")); diff --git a/src/test/java/org/apache/sling/jcr/contentparser/impl/JsonContentParserTest.java b/src/test/java/org/apache/sling/jcr/contentparser/impl/JsonContentParserTest.java index a98757a..3aa9531 100644 --- a/src/test/java/org/apache/sling/jcr/contentparser/impl/JsonContentParserTest.java +++ b/src/test/java/org/apache/sling/jcr/contentparser/impl/JsonContentParserTest.java @@ -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")); diff --git a/src/test/java/org/apache/sling/jcr/contentparser/impl/TestUtils.java b/src/test/java/org/apache/sling/jcr/contentparser/impl/TestUtils.java index bd3bb10..f91c5ee 100644 --- a/src/test/java/org/apache/sling/jcr/contentparser/impl/TestUtils.java +++ b/src/test/java/org/apache/sling/jcr/contentparser/impl/TestUtils.java @@ -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); + } + } + } -- To stop receiving notification emails like this one, please contact "[email protected]" <[email protected]>.
