From 8c81f645d22961861e59a8b231d66fa9174888a7 Mon Sep 17 00:00:00 2001 From: Shailesh Mishra Date: Wed, 28 Sep 2022 21:14:49 +0530 Subject: [PATCH 1/6] jsoup dependency updated --- pom.xml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pom.xml b/pom.xml index 2d91c0f..76f65fe 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ com.contentstack.sdk utils - {$utils.version} + 1.1.3-SNAPSHOT jar Contentstack-utils Java Utils SDK for Contentstack Content Delivery API, Contentstack is a headless CMS with an API-first @@ -24,7 +24,7 @@ 2.2.1 3.1.1 4.13.2 - 1.14.3 + 1.15.3 1.1.1 3.3 1.5 @@ -109,7 +109,7 @@ org.springframework spring-web - 5.3.20 + 5.3.23 compile From 827fa277529dab86d4f5e21e6e0e906bf00a38bb Mon Sep 17 00:00:00 2001 From: Shailesh Mishra Date: Wed, 28 Sep 2022 21:16:47 +0530 Subject: [PATCH 2/6] Update pom.xml --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 76f65fe..066b3a4 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ com.contentstack.sdk utils - 1.1.3-SNAPSHOT + 1.2.0-SNAPSHOT jar Contentstack-utils Java Utils SDK for Contentstack Content Delivery API, Contentstack is a headless CMS with an API-first From f2fe0d8a487ff64c4a80cad2fe681e1cd144792b Mon Sep 17 00:00:00 2001 From: Shailesh Mishra Date: Wed, 28 Sep 2022 21:35:11 +0530 Subject: [PATCH 3/6] #5 #5 scope added --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 066b3a4..11604ff 100644 --- a/pom.xml +++ b/pom.xml @@ -104,7 +104,7 @@ com.googlecode.json-simple json-simple ${json.simple.version} - compile + exclusion org.springframework From e25ae76ae33badaaa172b66b6ef0d8b27a74d87a Mon Sep 17 00:00:00 2001 From: Shailesh Mishra Date: Thu, 29 Sep 2022 16:59:08 +0530 Subject: [PATCH 4/6] :sparkles: jsonRteToHtml returns String JSONRTE returns String --- .../java/com/contentstack/utils/Utils.java | 41 ++++++++ .../com/contentstack/utils/RTEResult.java | 21 ++++ .../com/contentstack/utils/RTEString.java | 29 ++++++ .../contentstack/utils/RteJsonToString.java | 96 +++++++++++++++++++ .../com/contentstack/utils/TestRender.java | 28 ------ .../com/contentstack/utils/UtilTests.java | 5 - 6 files changed, 187 insertions(+), 33 deletions(-) create mode 100644 src/test/java/com/contentstack/utils/RTEResult.java create mode 100644 src/test/java/com/contentstack/utils/RTEString.java create mode 100644 src/test/java/com/contentstack/utils/RteJsonToString.java delete mode 100644 src/test/java/com/contentstack/utils/TestRender.java diff --git a/src/main/java/com/contentstack/utils/Utils.java b/src/main/java/com/contentstack/utils/Utils.java index fd2c38a..aa19971 100644 --- a/src/main/java/com/contentstack/utils/Utils.java +++ b/src/main/java/com/contentstack/utils/Utils.java @@ -181,6 +181,47 @@ public static void jsonToHTML(@NotNull JSONObject entry, @NotNull String[] keyPa } + /** + * Converts jsonRTE to String + * + * @param jsonRTE + * The JsonRTE object {@link JSONObject} + * @param renderOption + * The Option Interface + * @param embeddeditems + * The Embedded Objects {@link JSONObject} + * @return String + */ + public static String jsonToHTML(@NotNull JSONObject jsonRTE, Option renderOption, JSONObject embeddeditems) { + MetaToEmbedCallback converter = metadata -> { + if (embeddeditems != null && !embeddeditems.isEmpty()) { + return findEmbeddedItems(embeddeditems, metadata); + } + return Optional.empty(); + }; + return enumerateContent(jsonRTE, renderOption, converter); + } + + /** + * @param jsonRTE + * The JsonRTE Array {@link JSONArray} + * @param renderOption + * The Option Interface + * @param embeddeditems + * The Embedded Objects {@link JSONObject} + * @return String + */ + public static Object jsonToHTML(@NotNull JSONArray jsonRTE, Option renderOption, JSONObject embeddeditems) { + MetaToEmbedCallback converter = metadata -> { + if (embeddeditems != null && !embeddeditems.isEmpty()) { + return findEmbeddedItems(embeddeditems, metadata); + } + return Optional.empty(); + }; + return enumerateContents(jsonRTE, renderOption, converter); + } + + /** * Render. * diff --git a/src/test/java/com/contentstack/utils/RTEResult.java b/src/test/java/com/contentstack/utils/RTEResult.java new file mode 100644 index 0000000..1cc2e40 --- /dev/null +++ b/src/test/java/com/contentstack/utils/RTEResult.java @@ -0,0 +1,21 @@ +package com.contentstack.utils; + +public class RTEResult { + + public static String kParagraphHtml = "

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed condimentum iaculis magna in vehicula. Vestibulum vitae convallis lacus. Praesent a diam iaculis turpis rhoncus faucibus. Aliquam sed pulvinar sem.

"; + public static String kPlainTextHtml = "Aliquam sit amet libero dapibus, eleifend ligula at, varius justoLorem ipsumdolor sit ametconsectetur adipiscing elit.Sed condimentum iaculis magna in vehicula. Vestibulum vitae convallis lacus. "; + public static String kH1Html = "

Lorem ipsum dolor sit amet.

"; + public static String kH2Html = "

Vestibulum a ligula eget massa sagittis aliquam sit amet quis tortor.

"; + public static String kH3Html = "

Mauris venenatis dui id massa sollicitudin, non bibendum nunc dictum.

"; + public static String kH4Html = "

MaNullam feugiat turpis quis elit interdum, vitae laoreet quam viverra

"; + public static String kH5Html = "
Mauris venenatis dui id massa sollicitudin, non bibendum nunc dictum.
"; + public static String kH6Html = "
Nunc porta diam vitae purus semper, ut consequat lorem vehicula.
"; + public static String kOrderListHtml = "
  1. Morbi in quam molestie, fermentum diam vitae, bibendum ipsum.
  2. Pellentesque mattis lacus in quam aliquam congue
  3. Integer feugiat leo dignissim, lobortis enim vitae, mollis lectus.
  4. Sed in ante lacinia, molestie metus eu, fringilla sapien.
"; + public static String kIUnorderListHtml = "
  • Sed quis metus sed mi hendrerit mollis vel et odio.
  • Integer vitae sem dignissim, elementum libero vel, fringilla massa.
  • Integer imperdiet arcu sit amet tortor faucibus aliquet.
  • Aenean scelerisque velit vitae dui vehicula, at congue massa sagittis.
"; + public static String kImgHtml = ""; + public static String kTableHtml = "

Header 1

Header 2

Body row 1 data 1

Body row 1 data 2

Body row 2 data 1

Body row 2 data 2

"; + public static String kBlockquoteHtml = "
Praesent eu ex sed nibh venenatis pretium.
"; + public static String kCodeHtml = "Code template."; + public static String kLinkInPHtml = "

LINK

"; + public static String kEmbedHtml = ""; +} diff --git a/src/test/java/com/contentstack/utils/RTEString.java b/src/test/java/com/contentstack/utils/RTEString.java new file mode 100644 index 0000000..4452205 --- /dev/null +++ b/src/test/java/com/contentstack/utils/RTEString.java @@ -0,0 +1,29 @@ +package com.contentstack.utils; + +public class RTEString { + + public static String kBlankDocument = "{ \"uid\":\"06e34a7a4e5d7fc2acd\", \"_version\":13, \"attrs\":{ }, \"children\":[],\"type\":\"doc\"}"; + public static String kPlainTextJson = "{ \"uid\":\"06e34a7a4e5d7fc2acd\", \"_version\":13, \"attrs\":{ }, \"children\":[{\"text\":\"Aliquam sit amet libero dapibus, eleifend ligula at, varius justo\",\"bold\":true},{ \"text\":\"Lorem ipsum\",\"bold\":true,\"italic\":true},{ \"text\":\"dolor sit amet\",\"bold\":true,\"italic\":true,\"underline\":true},{ \"text\":\"consectetur adipiscing elit.\",\"bold\":true,\"italic\":true,\"underline\":true,\"strikethrough\":true},{ \"text\":\"Sed condimentum iaculis magna in vehicula. \",\"bold\":true,\"italic\":true,\"underline\":true,\"inlineCode\":true},{ \"text\":\" Vestibulum vitae convallis \",\"bold\":true,\"italic\":true,\"underline\":true,\"superscript\":true},{ \"text\":\" lacus. \",\"bold\":true,\"italic\":true,\"underline\":true,\"subscript\":true}],\"type\":\"doc\"}"; + public static String kH1Json = "{ \"uid\":\"06e34a7a449d7fc2acd\",\"_version\":13,\"attrs\":{ },\"children\":[{ \"type\":\"h1\",\"attrs\":{ },\"uid\":\"c2dfed70 4d7030c65e2e1\",\"children\":[{ \"text\":\"Lorem ipsum dolor sit amet.\",\"bold\":true,\"italic\":true,\"underline\":true,\"subscript\":true}]}],\"type\":\"doc\"}"; + public static String kH2Json = "{ \"uid\":\"06e34a7a4e2acd\",\"_version\":13,\"attrs\":{ },\"children\":[{ \"type\":\"h2\",\"attrs\":{ },\"uid\":\"c2dfed9a7030c65e2e1\",\"children\":[{ \"text\":\"Vestibulum a ligula eget massa sagittis aliquam sit amet quis tortor. \",\"bold\":true,\"italic\":true,\"underline\":true,\"subscript\":true}]}],\"type\":\"doc\"}"; + public static String kH3Json = "{ \"uid\":\"06e34ad7fc2acd\",\"_version\":13,\"attrs\":{ },\"children\":[{ \"type\":\"h3\",\"attrs\":{ },\"uid\":\"c2df42cfb70 4d7030c65e2e1\",\"children\":[{ \"text\":\"Mauris venenatis dui id massa sollicitudin, non bibendum nunc dictum.\",\"bold\":true,\"italic\":true,\"underline\":true,\"subscript\":true}]}],\"type\":\"doc\"}"; + public static String kH4Json = "{ \"uid\":\"06e34a7a4e54cd\", \"_version\":13, \"attrs\":{ \"style\":{ \"text-align\":\"center\" }, \"redactor-attributes\":{ } }, \"children\":[{\"type\":\"h4\",\"attrs\":{},\"uid\":\"c2dfed4d7030c65e2e1\",\"children\":[{\"text\":\"MaNullam feugiat turpis quis elit interdum, vitae laoreet quam viverra\",\"bold\":true,\"italic\":true,\"underline\":true,\"subscript\":true}]}],\"type\":\"doc\"}"; + public static String kH5Json = "{ \"uid\": \"06e381190849dacd\", \"_version\": 13, \"attrs\": { }, \"children\": [ { \"type\": \"h5\", \"attrs\": {}, \"uid\": \"c2d672242cfb7045e2e1\", \"children\": [ { \"text\": \"Mauris venenatis dui id massa sollicitudin, non bibendum nunc dictum.\", } ] } ], \"type\": \"doc\" }"; + public static String kH6Json = "{ \"uid\": \"06e34a71190849d7fcd\", \"_version\": 13, \"attrs\": { }, \"children\": [ { \"type\": \"h6\", \"attrs\": {}, \"uid\": \"c2dfa672242cfb7e2e1\", \"children\": [ { \"text\": \"Nunc porta diam vitae purus semper, ut consequat lorem vehicula.\", } ] } ], \"type\": \"doc\" }"; + public static String kOrderListJson = "{ \"uid\":\"06e35 48119084 9d7fc2acd\", \"_version\":13, \"attrs\":{ }, \"children\":[{\"uid\":\"2b5b4acbb3cfce02d3e\",\"type\":\"ol\",\"children\":[{\"type\":\"li\",\"attrs\":{\"style\":{\"text-align\":\"justify\"},\"redactor-attributes\":{ }},\"uid\":\"160bbd7430b98bd3d996\",\"children\":[{\"text\":\"Morbi in quam molestie, fermentum diam vitae, bibendum ipsum.\"}]},{ \"type\":\"li\",\"attrs\":{ \"style\":{ \"text-align\":\"justify\"},\"redactor-attributes\":{ } },\"uid\":\"a15f4d749bc2903d\",\"children\":[{ \"text\":\"Pellentesque mattis lacus in quam aliquam congue\"}]},{ \"type\":\"li\",\"attrs\":{ \"style\":{ \"text-align\":\"justify\"},\"redactor-attributes\":{ } },\"uid\":\"e54224bbcb6f9e8f1e43\",\"children\":[{ \"text\":\"Integer feugiat leo dignissim, lobortis enim vitae, mollis lectus.\"}]},{ \"type\":\"li\",\"attrs\":{ \"style\":{ \"text-align\":\"justify\"},\"redactor-attributes\":{ } },\"uid\":\"c0148bab9af758784\",\"children\":[{ \"text\":\"Sed in ante lacinia, molestie metus eu, fringilla sapien.\"}]}],\"id\":\"7f413d448a\",\"attrs\":{ }}],\"type\":\"doc\"}"; + public static String kUnorderListJson = "{ \"uid\":\"0e5481190849a\", \"_version\":13, \"attrs\":{ }, \"children\":[{\"uid\":\"a3a2b443ebffc867b\",\"type\":\"ul\",\"children\":[{\"uid\":\"f67354d4eed64451922\",\"type\":\"li\",\"children\":[{\"text\":\"Sed quis metus sed mi hendrerit mollis vel et odio.\"}],\"attrs\":{ }},{ \"uid\":\"5 50cba5 bea92f23e36fd1\",\"type\":\"li\",\"children\":[{ \"text\":\"Integer vitae sem dignissim, elementum libero vel, fringilla massa.\"}],\"attrs\":{ } },{ \"uid\":\"0e5c9b4cd983e8fd543\",\"type\":\"li\",\"children\":[{ \"text\":\"Integer imperdiet arcu sit amet tortor faucibus aliquet.\"}],\"attrs\":{ } },{ \"uid\":\"6d9a43a3816bd83a9a\",\"type\":\"li\",\"children\":[{ \"text\":\"Aenean scelerisque velit vitae dui vehicula, at congue massa sagittis.\"}],\"attrs\":{ } }],\"id\":\"b083fa46ef899420ab19\",\"attrs\":{ }}],\"type\":\"doc\"}"; + public static String kImgJson = "{ \"uid\":\"06e34a7a4849d7fc2acd\", \"_version\":13, \"attrs\":{ }, \"children\":[{\"uid\":\"f3be74be3b64646e626\",\"type\":\"img\",\"attrs\":{\"url\":\"https://images.***REMOVED***/v3/assets/UID_13/Donald.jog.png\",\"width\":33.69418132611637,\"height\":\"auto\",\"redactor-attributes\":{\"asset_uid\":\"47f1aa5ae422cd1\"}},\"children\":[{\"text\":\"\"}]}],\"type\":\"doc\"}"; + public static String kParagraphJson = "{ \"uid\":\"0d7fd\", \"_version\":13, \"attrs\":{ }, \"children\":[{\"type\":\"p\",\"attrs\":{},\"uid\":\"0a1b5676aa510e5a\",\"children\":[{\"text\":\"Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed condimentum iaculis magna in vehicula. Vestibulum vitae convallis lacus. Praesent a diam iaculis turpis rhoncus faucibus. Aliquam sed pulvinar sem.\"}]}],\"type\":\"doc\"}"; + public static String kBlockquoteJson = "{ \"uid\":\"06084d7fd\", \"_version\":13, \"attrs\":{ }, \"children\":[{\"uid\":\"503f9cc97534db55\",\"type\":\"blockquote\",\"id\":\"431f78e567161460\",\"children\":[{\"text\":\"Praesent eu ex sed nibh venenatis pretium.\"}],\"attrs\":{ }}],\"type\":\"doc\"}"; + public static String kCodeJson = "{ \"uid\":\"06ea490849d7fc2acd\", \"_version\":13, \"attrs\":{ }, \"children\":[{\"uid\":\"83fba92c91b30002b\",\"type\":\"code\",\"attrs\":{},\"children\":[{\"text\":\"Code template.\"}]}],\"type\":\"doc\"}"; + public static String kTableJson = "{ \"uid\": \"06e481190849d7fcd\", \"_version\": 13, \"attrs\": { }, \"children\": [ { \"uid\": \"6dd64343bf634bfadd4\", \"type\": \"table\", \"attrs\": { \"rows\": 4, \"cols\": 2, \"colWidths\": [ 250, 250 ] }, \"children\": [ { \"uid\": \"b9082\", \"type\": \"thead\", \"attrs\": {}, \"children\": [ { \"type\": \"tr\", \"attrs\": {}, \"children\": [ { \"type\": \"th\", \"attrs\": {}, \"children\": [ { \"type\": \"p\", \"attrs\": {}, \"children\": [ { \"text\": \"Header 1\" } ], \"uid\": \"daa3ef\" } ], \"uid\": \"4b3124414a3\" }, { \"type\": \"th\", \"attrs\": { }, \"children\": [ { \"type\": \"p\", \"attrs\": { }, \"children\": [ { \"text\": \"Header 2\" } ], \"uid\": \"eae83c5797d\" } ], \"uid\": \"bca9b6f037a04fb485\" } ], \"uid\": \"b91ae7a48ef2e9da1\" } ] }, { \"type\": \"tbody\", \"attrs\": { }, \"children\": [ { \"type\": \"tr\", \"attrs\": { }, \"children\": [ { \"type\": \"td\", \"attrs\": { }, \"children\": [ { \"type\": \"p\", \"attrs\": { }, \"children\": [ { \"text\": \"Body row 1 data 1\" } ], \"uid\": \"ec674ccc5ce70b7cab\" } ], \"uid\": \"2a70bdeeb99a\" }, { \"type\": \"td\", \"attrs\": { }, \"children\": [ { \"type\": \"p\", \"attrs\": { }, \"children\": [ { \"text\": \"Body row 1 data 2\" } ], \"uid\": \"769a 3f9db34 ce8ec 10486d50\" } ], \"uid\": \"d6407 34a5c6 1ab1e5f7d1\" } ], \"uid\": \"77f6 b951c68 7f9eb397c5\" }, { \"type\": \"tr\", \"attrs\": { }, \"children\": [ { \"type\": \"td\", \"attrs\": { }, \"children\": [ { \"type\": \"p\", \"attrs\": { }, \"children\": [ { \"text\": \"Body row 2 data 1\" } ], \"uid\": \"a6bf 11bb48 630e87d721c0\" } ], \"uid\": \"3da39838b0feaf\" }, { \"type\": \"td\", \"attrs\": { }, \"children\": [ { \"type\": \"p\", \"attrs\": { }, \"children\": [ { \"text\": \"Body row 2 data 2\" } ], \"uid\": \"3b7d12 1f694202 49029e86313\" } ], \"uid\": \"95b38b04abcbc25e94f\" } ], \"uid\": \"b 227fea 8d247013 4f1e1e8\" } ], \"uid\": \"fd5ab86aa642798451b\" } ] }, ], \"type\": \"doc\" }"; + public static String kLinkInPJson = "{ \"uid\":\"06e34a7190849d7f2acd\", \"_version\":13, \"attrs\":{ }, \"children\":[{\"type\":\"p\",\"attrs\":{\"style\":{\"text-align\":\"left\"},\"redactor-attributes\":{ }},\"uid\":\"d88dcdf4590dff2d\",\"children\":[{\"text\":\"\",\"bold\":true,\"italic\":true,\"underline\":true,\"subscript\":true},{ \"uid\":\"0d06598201aa8b47\",\"type\":\"a\",\"attrs\":{ \"url\":\"LINK.com\",\"target\":\"_self\"},\"children\":[{ \"text\":\"LINK\"}]},{ \"text\":\"\"}]}],\"type\":\"doc\"}"; + public static String kEmbedJson = "{ \"uid\":\"06e34a7190849d7f2acd\", \"_version\":13, \"attrs\":{ }, \"children\":[{\"uid\":\"251017315905c35d42c9\",\"type\":\"embed\",\"attrs\":{\"url\":\"https://www.youtube.com/watch?v=AOP0yARiW8U\"},\"children\":[{\"text\":\"\"}]}],\"type\":\"doc\"}"; + public static String kAssetReferenceJson = "{\"uid\":\"06e34a7 5e4 e549d \", \"_version\":1, \"attrs\":{}, \"children\":[{ \"uid\": \"4f7e33 3390a955 de10c1 c836\", \"type\":\"reference\",\"attrs\":{\"display-type\":\"display\",\"asset-uid\":\"UID_12\",\"content-type-uid\":\"sys_assets\",\"asset-link\":\"https://images.***REMOVED***/v3/assets/UID_14/11.jpg\",\"asset-name\":\"11.jpg\",\"asset-type\":\"image/jpeg\",\"type\":\"asset\",\"class-name\":\"embedded-asset\",\"width\":25.16914749661705,\"className\":\"dsd\",\"id\":\"sdf\"},\"children\":[{\"text\":\"\"}]}],\"type\":\"doc\"}"; + public static String kEntryReferenceBlockJson = "{ \"uid\":\"06e34a7 5e4 e549d \", \"_version\":1, \"attrs\":{ }, \"children\":[{\"uid\":\"70f9b 325075d43 128c0d0 aa3eb7f291f\",\"type\":\"reference\",\"attrs\":{\"display-type\":\"block\",\"entry-uid\":\"UID_07\",\"content-type-uid\":\"content_block\",\"locale\":\"en-us\",\"type\":\"entry\",\"class-name\":\"embedded-entry\"},\"children\":[{\"text\":\"\"}]}],\"type\":\"doc\"}"; + public static String kEntryReferenceLinkJson = "{ \"uid\":\"06e34a7 5e4 e549d\", \"_version\":1, \"attrs\":{ }, \"children\":[{\"uid\":\"7626ea98e0e95d602210\",\"type\":\"reference\",\"attrs\":{\"target\":\"_self\",\"href\":\"/copy-of-entry-final-02\",\"display-type\":\"link\",\"entry-uid\":\"UID_08\",\"content-type-uid\":\"embeddedrte\",\"locale\":\"en-us\",\"type\":\"entry\",\"class-name\":\"embedded-entry\"},\"children\":[{\"text\":\"/copy-of-entry-final-02\"}]}],\"type\":\"doc\"}"; + public static String kEntryReferenceInlineJson = "{ \"uid\":\"06e34a7 5e4 e549d\", \"_version\":1, \"attrs\":{ }, \"children\":[{\"uid\":\"506 4878f3f46 s21f0cbc aff\",\"type\":\"reference\",\"attrs\":{\"display-type\":\"inline\",\"entry-uid\":\"UID_09\",\"content-type-uid\":\"embeddedrte\",\"locale\":\"en-us\",\"type\":\"entry\",\"class-name\":\"embedded-entry\"},\"children\":[{\"text\":\"\"}]}],\"type\":\"doc\"}"; + public static String kHRJson = "{ \"uid\":\"06e34a7 5e4 e549d\", \"_version\":1, \"attrs\":{ }, \"children\":[{\"uid\":\"f5a7b57 40a8a5c3 576828276b\",\"type\":\"hr\",\"children\":[{\"text\":\"\"}],\"attrs\":{ }}],\"type\":\"doc\"}"; + + +} diff --git a/src/test/java/com/contentstack/utils/RteJsonToString.java b/src/test/java/com/contentstack/utils/RteJsonToString.java new file mode 100644 index 0000000..d4c35ea --- /dev/null +++ b/src/test/java/com/contentstack/utils/RteJsonToString.java @@ -0,0 +1,96 @@ +package com.contentstack.utils; + +import com.contentstack.utils.render.DefaultOption; +import org.json.JSONObject; +import org.junit.Assert; +import org.junit.BeforeClass; +import org.junit.FixMethodOrder; +import org.junit.Test; +import org.junit.runners.MethodSorters; + +import static com.contentstack.utils.RTEResult.*; +import static com.contentstack.utils.RTEString.*; + +@FixMethodOrder(MethodSorters.NAME_ASCENDING) +public class RteJsonToString { + + @BeforeClass + public static void startTestEmbedItemType() {} + + @Test + public void testkBlankDocument() { + JSONObject rteObject = new JSONObject(kPlainTextJson); + String result = Utils.jsonToHTML(rteObject, new DefaultOption(), null); + Assert.assertEquals(kPlainTextHtml, result); + } + + @Test + public void testkH1Json() { + JSONObject rteObject = new JSONObject(kH1Json); + String result = Utils.jsonToHTML(rteObject, new DefaultOption(), null); + Assert.assertEquals(kH1Html, result); + } + + @Test + public void testkH2Json() { + JSONObject rteObject = new JSONObject(kH2Json); + String result = Utils.jsonToHTML(rteObject, new DefaultOption(), null); + Assert.assertEquals(kH2Html, result); + } + + @Test + public void testkH3Json() { + JSONObject rteObject = new JSONObject(kH3Json); + String result = Utils.jsonToHTML(rteObject, new DefaultOption(), null); + Assert.assertEquals(kH3Html, result); + } + + @Test + public void testkH4Json() { + JSONObject rteObject = new JSONObject(kH4Json); + String result = Utils.jsonToHTML(rteObject, new DefaultOption(), null); + Assert.assertEquals(kH4Html, result); + } + + @Test + public void testkH5Json() { + JSONObject rteObject = new JSONObject(kH5Json); + String result = Utils.jsonToHTML(rteObject, new DefaultOption(), null); + Assert.assertEquals(kH5Html, result); + } + + @Test + public void testkH6Json() { + JSONObject rteObject = new JSONObject(kH6Json); + String result = Utils.jsonToHTML(rteObject, new DefaultOption(), null); + Assert.assertEquals(kH6Html, result); + } + + @Test + public void testkOrderListJson() { + JSONObject rteObject = new JSONObject(kOrderListJson); + String result = Utils.jsonToHTML(rteObject, new DefaultOption(), null); + Assert.assertEquals(kOrderListHtml, result); + } + + @Test + public void testKCodeHtmlTypes() { + JSONObject rteObject = new JSONObject(kUnorderListJson); + String result = Utils.jsonToHTML(rteObject, new DefaultOption(), null); + Assert.assertEquals(kIUnorderListHtml, result); + } + + @Test + public void testkImgJson() { + JSONObject rteObject = new JSONObject(kImgJson); + String result = Utils.jsonToHTML(rteObject, new DefaultOption(), null); + Assert.assertEquals(kImgHtml, result); + } + + @Test + public void testAvailableEntryItemTypes() { + JSONObject rteObject = new JSONObject(kParagraphJson); + String result = Utils.jsonToHTML(rteObject, new DefaultOption(), null); + Assert.assertEquals(kParagraphHtml, result); + } +} diff --git a/src/test/java/com/contentstack/utils/TestRender.java b/src/test/java/com/contentstack/utils/TestRender.java deleted file mode 100644 index 38bac4a..0000000 --- a/src/test/java/com/contentstack/utils/TestRender.java +++ /dev/null @@ -1,28 +0,0 @@ -package com.contentstack.utils; - -import org.json.JSONObject; -import org.junit.BeforeClass; -import org.junit.FixMethodOrder; -import org.junit.Test; -import org.junit.runners.MethodSorters; - -import java.util.logging.Level; -import java.util.logging.Logger; - -@FixMethodOrder(MethodSorters.NAME_ASCENDING) -public class TestRender { - - private final static Logger logger = Logger.getLogger(TestRender.class.getName()); - private static JSONObject localJsonObj; - - @BeforeClass - public static void startTestEmbedItemType() { - logger.setLevel(Level.ALL); - logger.info("Initiated com.contentstack.utils.TestRender testcases"); - } - - @Test - public void testAvailableEntryItemTypes() { - - } -} diff --git a/src/test/java/com/contentstack/utils/UtilTests.java b/src/test/java/com/contentstack/utils/UtilTests.java index fd65d9d..96cc06e 100644 --- a/src/test/java/com/contentstack/utils/UtilTests.java +++ b/src/test/java/com/contentstack/utils/UtilTests.java @@ -1,13 +1,8 @@ package com.contentstack.utils; -import com.contentstack.utils.embedded.StyleType; -import com.contentstack.utils.interfaces.Option; -import com.contentstack.utils.render.DefaultOption; -import org.json.JSONArray; import org.json.JSONObject; import org.junit.BeforeClass; import org.junit.FixMethodOrder; -import org.junit.Test; import org.junit.runners.MethodSorters; import java.io.IOException; From 6120cefbcd73b83370b90bd6d981e7dcd9249d35 Mon Sep 17 00:00:00 2001 From: Shailesh Mishra Date: Thu, 6 Oct 2022 14:38:22 +0530 Subject: [PATCH 5/6] v1.2.0 --- pom.xml | 2 +- .../contentstack/utils/helper/Metadata.java | 21 +++++--- .../contentstack/utils/interfaces/Option.java | 21 +++++--- .../com/contentstack/utils/UtilTests.java | 50 ++++++++++--------- 4 files changed, 55 insertions(+), 39 deletions(-) diff --git a/pom.xml b/pom.xml index 11604ff..48e8878 100644 --- a/pom.xml +++ b/pom.xml @@ -14,7 +14,7 @@ https://www.***REMOVED*** - 1.1.2-SNAPSHOT + 1.2.0-SNAPSHOT UTF-8 UTF-8 1.8 diff --git a/src/main/java/com/contentstack/utils/helper/Metadata.java b/src/main/java/com/contentstack/utils/helper/Metadata.java index df329a0..6d184b7 100644 --- a/src/main/java/com/contentstack/utils/helper/Metadata.java +++ b/src/main/java/com/contentstack/utils/helper/Metadata.java @@ -17,13 +17,20 @@ public class Metadata { /** * Instantiates a new Metadata. * - * @param text the text - * @param itemType the item type - * @param itemUid the item uid - * @param contentTypeUid the content type uid - * @param styleType the style type - * @param outerHTML the outer html - * @param attributes the attributes + * @param text + * the text + * @param itemType + * the item type + * @param itemUid + * the item uid + * @param contentTypeUid + * the content type uid + * @param styleType + * the style type + * @param outerHTML + * the outer html + * @param attributes + * the attributes */ public Metadata(String text, String itemType, String itemUid, String contentTypeUid, String styleType, String outerHTML, Attributes attributes) { diff --git a/src/main/java/com/contentstack/utils/interfaces/Option.java b/src/main/java/com/contentstack/utils/interfaces/Option.java index 3b790a4..2dca2d1 100644 --- a/src/main/java/com/contentstack/utils/interfaces/Option.java +++ b/src/main/java/com/contentstack/utils/interfaces/Option.java @@ -12,8 +12,10 @@ public interface Option { /** * Render options string. * - * @param embeddedObject the embedded object - * @param metadata the metadata + * @param embeddedObject + * the embedded object + * @param metadata + * the metadata * @return the string */ String renderOptions(JSONObject embeddedObject, Metadata metadata); @@ -21,8 +23,10 @@ public interface Option { /** * Render mark string. * - * @param markType the mark type - * @param renderText the render text + * @param markType + * the mark type + * @param renderText + * the render text * @return the string */ String renderMark(MarkType markType, String renderText); @@ -30,9 +34,12 @@ public interface Option { /** * Render node string. * - * @param nodeType the node type - * @param nodeObject the node object - * @param callback the callback + * @param nodeType + * the node type + * @param nodeObject + * the node object + * @param callback + * the callback * @return the string */ String renderNode(String nodeType, JSONObject nodeObject, NodeCallback callback); diff --git a/src/test/java/com/contentstack/utils/UtilTests.java b/src/test/java/com/contentstack/utils/UtilTests.java index 96cc06e..75a7539 100644 --- a/src/test/java/com/contentstack/utils/UtilTests.java +++ b/src/test/java/com/contentstack/utils/UtilTests.java @@ -1,14 +1,20 @@ package com.contentstack.utils; +import com.contentstack.utils.embedded.StyleType; +import com.contentstack.utils.render.DefaultOption; import org.json.JSONObject; +import org.json.simple.JSONArray; import org.junit.BeforeClass; import org.junit.FixMethodOrder; +import org.junit.Test; import org.junit.runners.MethodSorters; import java.io.IOException; import java.util.logging.Level; import java.util.logging.Logger; +import static com.contentstack.utils.embedded.StyleType.*; + @FixMethodOrder(MethodSorters.NAME_ASCENDING) public class UtilTests { @@ -23,30 +29,26 @@ public static void startUtilTests() throws IOException { localJsonObj = (JSONObject) localJsonObj.getJSONArray("entries").get(0); } -// @Test -// public void testRenderFunction() { + @Test + public void testRenderFunction() { // DefaultOption option = (embeddedObject, metadata) -> { // StyleType styleType = metadata.getStyleType(); // return null; // }; -// String[] keys = new String[2]; -// keys[0] = "global_rich_multiple.group.rich_text_editor"; -// keys[1] = "global_rich_multiple.group.rich_text_editor_multiple"; -// Utils.render(localJsonObj, keys, new DefaultOption()); -// } -// -// @Test -// public void testWithoutKeyPath() { -// Option option = (embeddedObject, metadata) -> { -// StyleType styleType = metadata.getStyleType(); -// return null; -// }; -// String[] keys = new String[2]; -// keys[0] = "global_rich_multiple.group.rich_text_editor"; -// keys[1] = "global_rich_multiple.group.rich_text_editor_multiple"; -// Utils.render(localJsonObj, null, new DefaultOption()); -// } -// + String[] keys = new String[2]; + keys[0] = "global_rich_multiple.group.rich_text_editor"; + keys[1] = "global_rich_multiple.group.rich_text_editor_multiple"; + Utils.render(localJsonObj, keys, new DefaultOption()); + } + + @Test + public void testWithoutKeyPath() { + String[] keys = new String[2]; + keys[0] = "global_rich_multiple.group.rich_text_editor"; + keys[1] = "global_rich_multiple.group.rich_text_editor_multiple"; + Utils.render(localJsonObj, null, new DefaultOption()); + } + // @Test // public void testEmbeddedBlockEntry() { // JSONArray rteArray = null; @@ -58,7 +60,7 @@ public static void startUtilTests() throws IOException { // assert rteArray != null; // Utils.renderContents(rteArray, localJsonObj, (embeddedObject, metadata) -> { // StyleType type = metadata.getStyleType(); -// if (type == StyleType.BLOCK) { +// if (type == BLOCK) { // String title = embeddedObject.getString("title"); // String multi_line = embeddedObject.getString("multi_line"); // return "

" + title + "

" + multi_line + ""; @@ -67,7 +69,7 @@ public static void startUtilTests() throws IOException { // }); // // Utils.renderContents(rteArray, localJsonObj, (embeddedObject, metadata) -> { -// if (metadata.getStyleType() == StyleType.BLOCK) { +// if (metadata.getStyleType() == BLOCK) { // String title = embeddedObject.getString("title"); // String multi_line = embeddedObject.getString("multi_line"); // return "

" + title + "

" + multi_line + ""; @@ -149,8 +151,8 @@ public static void startUtilTests() throws IOException { // String[] keyPath = { // "rich_text_editor", "global_rich_multiple.group.rich_text_editor" // }; -// Utils.render(rteObject, keyPath, (embeddedObject, metadata) -> { -// if (metadata.getStyleType() == StyleType.BLOCK) { +// Utils.renderContents(rteObject, keyPath, (embeddedObject, metadata) -> { +// if (metadata.getStyleType == BLOCK) { // // Do something // } // return null; From 322d7ea6389b934e6fe7be3de43db78ec070aa8e Mon Sep 17 00:00:00 2001 From: Shailesh Mishra Date: Thu, 6 Oct 2022 18:54:54 +0530 Subject: [PATCH 6/6] v1.2.0 --- README.md | 2 +- pom.xml | 5 ++--- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 2196b46..c7d822a 100644 --- a/README.md +++ b/README.md @@ -32,7 +32,7 @@ If you are using Contentstack Java SDK, then the Utils SDK is already imported i
``` -Download [{latest}](https://search.maven.org/artifact/com.contentstack.sdk/utils) dependency here +Download [Latest](https://central.sonatype.dev/artifact/com.contentstack.sdk/utils/) dependency here ### Usage diff --git a/pom.xml b/pom.xml index 48e8878..3e2715a 100644 --- a/pom.xml +++ b/pom.xml @@ -14,7 +14,6 @@ https://www.***REMOVED*** - 1.2.0-SNAPSHOT UTF-8 UTF-8 1.8 @@ -104,7 +103,7 @@ com.googlecode.json-simple json-simple ${json.simple.version} - exclusion + provided org.springframework @@ -206,7 +205,7 @@ org.sonatype.plugins nexus-staging-maven-plugin - 1.6.7 + 1.6.13 true ossrh