Skip to content

Commit 748e229

Browse files
Merge pull request #41 from contentstack/next
Next : acknowledged an inlinement issue in v1.2.5
2 parents e22d7c9 + 385bcfe commit 748e229

File tree

19 files changed

+12597
-378
lines changed

19 files changed

+12597
-378
lines changed

pom.xml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<modelVersion>4.0.0</modelVersion>
55
<groupId>com.contentstack.sdk</groupId>
66
<artifactId>utils</artifactId>
7-
<version>1.2.5</version>
7+
<version>1.2.6</version>
88
<packaging>jar</packaging>
99
<name>Contentstack-utils</name>
1010
<description>Java Utils SDK for Contentstack Content Delivery API, Contentstack is a headless CMS</description>
@@ -27,8 +27,8 @@
2727
<nexus-staging-maven-plugin.version>1.6.7</nexus-staging-maven-plugin.version>
2828
<maven-release-plugin.version>2.5.3</maven-release-plugin.version>
2929
<validation-version>2.0.1.Final</validation-version>
30-
<json-version>20230618</json-version>
31-
<spring-web-version>6.0.12</spring-web-version>
30+
<json-version>20231013</json-version>
31+
<spring-web-version>6.0.13</spring-web-version>
3232
<org.apache.commons-text>1.10.0</org.apache.commons-text>
3333
</properties>
3434

@@ -230,7 +230,7 @@
230230
<configuration>
231231
<source>1.8</source>
232232
<target>1.8</target>
233-
<!-- <executable>${JAVA_HOME}/bin/javac</executable>-->
233+
<!-- <executable>${JAVA_HOME}/bin/javac</executable>-->
234234
</configuration>
235235
</plugin>
236236
<plugin>

src/main/java/com/contentstack/utils/node/NodeToHTML.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ private NodeToHTML() {
2929
*/
3030
public static String textNodeToHTML(JSONObject nodeText, Option renderOption) {
3131
String text = nodeText.optString("text");
32-
text = text.replace("\n", "");
32+
text = text.replace("\n", "<br />");
3333
if (nodeText.has("superscript")) {
3434
text = renderOption.renderMark(MarkType.SUPERSCRIPT, text);
3535
}
@@ -52,7 +52,10 @@ public static String textNodeToHTML(JSONObject nodeText, Option renderOption) {
5252
text = renderOption.renderMark(MarkType.BOLD, text);
5353
}
5454
if (nodeText.has("break")) {
55-
text = renderOption.renderMark(MarkType.BREAK, text);
55+
if (!text.contains("<br />")) {
56+
text = renderOption.renderMark(MarkType.BREAK, text);
57+
}
58+
// text = renderOption.renderMark(MarkType.BREAK, text);
5659
}
5760
return text;
5861
}

src/main/java/com/contentstack/utils/render/DefaultOption.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ public String renderMark(MarkType markType, String text) {
7070
case BOLD:
7171
return "<strong>" + text + "</strong>";
7272
case BREAK:
73-
return "<br />" + text; // v1.2.5
73+
return "<br />" + text.replace("\n", "");
7474
default:
7575
return text;
7676
}

src/test/java/com/contentstack/utils/RTEResult.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,15 @@ public class RTEResult {
1212
public static String kH6Html = "<h6>Nunc porta diam vitae purus semper, ut consequat lorem vehicula.</h6>";
1313
public static String kOrderListHtml = "<ol><li redactor-attributes=\"{}\" style=\"text-align: justify; \">Morbi in quam molestie, fermentum diam vitae, bibendum ipsum.</li><li redactor-attributes=\"{}\" style=\"text-align: justify; \">Pellentesque mattis lacus in quam aliquam congue</li><li redactor-attributes=\"{}\" style=\"text-align: justify; \">Integer feugiat leo dignissim, lobortis enim vitae, mollis lectus.</li><li redactor-attributes=\"{}\" style=\"text-align: justify; \">Sed in ante lacinia, molestie metus eu, fringilla sapien.</li></ol>";
1414
public static String kIUnorderListHtml = "<ul><li>Sed quis metus sed mi hendrerit mollis vel et odio.</li><li>Integer vitae sem dignissim, elementum libero vel, fringilla massa.</li><li>Integer imperdiet arcu sit amet tortor faucibus aliquet.</li><li>Aenean scelerisque velit vitae dui vehicula, at congue massa sagittis.</li></ul>";
15-
public static String kImgHtml = "<img redactor-attributes=\"{\"asset_uid\":\"47f1aa5ae422cd1\"}\" width=\"33.69418132611637\" height=\"auto\" src=\"https://images.***REMOVED***/v3/assets/UID_13/Donald.jog.png\" />";
15+
public static String kImgHtml = "<img redactor-attributes=\"{\"asset_uid\":\"47f1aa5ae422cd1\"}\" width=\"33.69418132611637\" height=\"auto\" src=\"images.***REMOVED***/v3/assets/UID_13/Donald.jog.png\" />";
1616
public static String kTableHtml = "<table><thead><tr><th><p>Header 1</p></th><th><p>Header 2</p></th></tr></thead><tbody><tr><td><p>Body row 1 data 1</p></td><td><p>Body row 1 data 2</p></td></tr><tr><td><p>Body row 2 data 1</p></td><td><p>Body row 2 data 2</p></td></tr></tbody></table>";
1717
public static String kBlockquoteHtml = "<blockquote>Praesent eu ex sed nibh venenatis pretium.</blockquote>";
1818
public static String kCodeHtml = "<code>Code template.</code>";
1919
public static String kLinkInPHtml = "<p><strong><em><u><sub></sub></u></em></strong><a href=\"LINK.com\">LINK</a></p>";
20-
public static String kEmbedHtml = "<iframe src=\"https://www.youtube.com/watch?v=AOP0yARiW8U\"></iframe>";
20+
public static String kEmbedHtml = "<iframe src=\"www.youtube.com/watch?v=AOP0yARiW8U\"></iframe>";
21+
public static String kWFSAffectedHtml = "<p redactor-attributes=\"{}\" style=\"\" dir=\"ltr\"><strong>In this article:<br />\t</strong><a target=\"_self\" href=\"#Overview\">Overview</a><br />\t<a target=\"_self\" href=\"#Fulfillment\">Standard Fulfillment</a><br />\t<a target=\"_self\" href=\"#AdditionalFees\">Additional Fees</a><br />\t<a target=\"_self\" href=\"#BigBulkyFulfillment\">Big & Bulky Fulfillment</a><br />\t<a target=\"_self\" href=\"#Storage\">Storage</a><br />\t<a target=\"_self\" href=\"#ProblemInventory\">Problem Inventory</a><br />\t<a target=\"_self\" href=\"#Return\">Return Shipping & Exceptions</a><br />\t<a target=\"_self\" href=\"#DisposalRemoval\">Disposal & Removal</a><br />\t<a target=\"_self\" href=\"#AdditionalPrograms\">Additional WFS Programs</a></p><h2 redactor-attributes=\"{}\" style=\"\" id=\"Overview\" dir=\"ltr\">Overview</h2><p redactor-attributes=\"{}\" style=\"\" dir=\"ltr\">Fulfillment Services is a competitive and cost-effective solution that offers an end-to-end ecommerce fulfillment experience. Our fee structure is simple and straightforward, without signup or monthly subscription fees. You're also free to ship and store any amount of inventory you choose, without minimums or maximums. Use the <a href=\"www.abcd.com/?_gl=1*1t4i6i1*_ga*OTkwMDc3NzQuMTY1MjM3NjY3Nw..*_ga_1LB22TM2MG*MTY1MjcyNDU5My41OS4xLjE2NTI3MjY5NzIuMA..\">WFS Calculator</a> to estimate your fulfillment and storage fees.<br /><br />The following fees are effective as of August 2023 and are subject to change.</p>";
22+
public static String kAnchorHtml = "<p redactor-attributes=\"{}\" style=\"\" dir=\"ltr\">This is a paragraph with break true and<br />backslash nThis para has just one line break without any break key<br />Third paragraph with multiple line breaks<br /><br /><br />Fourth paragraph with multiple line breaks and break key<br /><br />Fifth paragraph with multiple only tab \t and this is text after tab<br />\tThis paragraph should start with a tab and should have a break before.</p>";
23+
public static String kWFSFeesHtml = "<p redactor-attributes=\"{}\" style=\"\" dir=\"ltr\">Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. <br /><br /><br />\t\t\t\tUt enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. <br />Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. <br />\tExcepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>";
24+
25+
public static String kONEHtml = "<p redactor-attributes=\"{}\" style=\"\" dir=\"ltr\"><br />A paragraph with break set as trueA paragraph with line break <br /> and \t tab</p>";
2126
}

src/test/java/com/contentstack/utils/RTEString.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ public class RTEString {
1212
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\" }";
1313
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\"}";
1414
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\"}";
15-
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\"}";
15+
public static String kImgJson = "{ \"uid\":\"06e34a7a4849d7fc2acd\", \"_version\":13, \"attrs\":{ }, \"children\":[{\"uid\":\"f3be74be3b64646e626\",\"type\":\"img\",\"attrs\":{\"url\":\"images.***REMOVED***/v3/assets/UID_13/Donald.jog.png\",\"width\":33.69418132611637,\"height\":\"auto\",\"redactor-attributes\":{\"asset_uid\":\"47f1aa5ae422cd1\"}},\"children\":[{\"text\":\"\"}]}],\"type\":\"doc\"}";
1616
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\"}";
1717
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\"}";
1818
public static String kCodeJson = "{ \"uid\":\"06ea490849d7fc2acd\", \"_version\":13, \"attrs\":{ }, \"children\":[{\"uid\":\"83fba92c91b30002b\",\"type\":\"code\",\"attrs\":{},\"children\":[{\"text\":\"Code template.\"}]}],\"type\":\"doc\"}";

src/test/java/com/contentstack/utils/TestRte.java

Lines changed: 50 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,9 +99,58 @@ public void testAvailableEntryItemTypes() {
9999

100100
@Test
101101
public void testHERFID() throws IOException {
102-
final String rte = "src/test/resources/reports/jsonviewer.json";
102+
final String rte = "src/test/resources/reports/wfs_fees.json";
103+
JSONObject theRTE = new ReadResource().readJson(rte);
104+
String result = Utils.jsonToHTML(theRTE, new DefaultOption(), null);
105+
Assert.assertEquals(kWFSFeesHtml, result);
106+
}
107+
108+
109+
110+
@Test
111+
public void testAnchorIssue() throws IOException {
112+
final String rte = "src/test/resources/reports/anchor.json";
113+
JSONObject theRTE = new ReadResource().readJson(rte);
114+
String result = Utils.jsonToHTML(theRTE, new DefaultOption(), null);
115+
Assert.assertEquals(kAnchorHtml, result);
116+
}
117+
118+
@Test
119+
public void testAffectedEntry() throws IOException {
120+
final String rte = "src/test/resources/reports/wfs.json";
103121
JSONObject theRTE = new ReadResource().readJson(rte);
104122
String result = Utils.jsonToHTML(theRTE, new DefaultOption(), null);
105123
System.out.println(result);
124+
Assert.assertEquals(kWFSAffectedHtml, result);
106125
}
126+
127+
128+
@Test
129+
public void testOne() throws IOException {
130+
final String rte = "src/test/resources/reports/one.json";
131+
JSONObject theRTE = new ReadResource().readJson(rte);
132+
String result = Utils.jsonToHTML(theRTE, new DefaultOption(), null);
133+
System.out.println(result);
134+
Assert.assertEquals(kONEHtml, result);
135+
}
136+
137+
@Test
138+
public void testOCT7Issue() throws IOException {
139+
final String rte = "src/test/resources/reports/oct_7.json";
140+
JSONObject theRTE = new ReadResource().readJson(rte);
141+
String result = Utils.jsonToHTML(theRTE, new DefaultOption(), null);
142+
System.out.println(result);
143+
// Assert.assertEquals(kONEHtml, result);
144+
}
145+
146+
@Test
147+
public void testIssueOct() throws IOException {
148+
final String rte = "src/test/resources/reports/issue_oct.json";
149+
JSONObject theRTE = new ReadResource().readJson(rte);
150+
String result = Utils.jsonToHTML(theRTE, new DefaultOption(), null);
151+
System.out.println(result);
152+
// Assert.assertEquals(kONEHtml, result);
153+
}
154+
155+
107156
}

src/test/resources/index.html

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<title>Response</title>
6+
</head>
7+
<body>
8+
<p redactor-attributes="{}" style="" dir="ltr"><strong>In this article:</strong></p> <a target="_self" href="#Overview">Overview</a><br /> <a target="_self" href="#Create_Variant_Groups">Create Variant Groups</a> <a target="_self" href="#Items_Dashboard_Method">Items Dashboard Method</a><br /> <a target="_self" href="#Full_Item_Spec_Method">Full Item Spec Method</a><br /> <a target="_self" href="#API_Method">API Method</a> <a target="_self" href="#Multi-select">Multi-select Attributes</a> <br /> <a target="_self" href="#Update_Variant_Group">Update Variant Groups</a> <a redactor-attributes="{}" style="" dir="ltr" target="_self" href="#Adding_Items_to_an_Existing_Group">Add Items to an Existing Variant Group</a><br /> <a target="_self" href="#Removing_Items_from_a_Variant_Group">Remove Items from a Variant Group</a> <a target="_self" href="#Combine_group">Combine Two Variant Groups</a> <br /> <a target="_self" href="#Separate_Group">Separate a Single Variant Group into Multiple Groups</a><br /> <a target="_self" href="#Add_New_Attribute">Add New Variant Attributes</a> <a target="_self" href="#Merged_Variant_Groups">Merged Variant Groups</a> <a redactor-attributes="{}" style="" dir="ltr" target="_self" href="#Variant_Limits">Variant Limits</a> <a redactor-attributes="{}" style="" dir="ltr" target="_self" href="#Variant_Errors">Variant Group Errors</a> <a redactor-attributes="{}" style="" dir="ltr" target="_self" href="#Selecting_Invalid_Variant_Attributes">Selecting Invalid Variant Attributes</a><br /> <a target="_self" href="#Variant_Group_Limits">Variant Group Limits</a><br /> <a target="_self" href="#Duplicate_Variants">Duplicate Variants</a> <a redactor-attributes="{}" style="" dir="ltr" target="_self" href="#Helpful_Resources">Helpful Resources</a> <p></p><h2 redactor-attributes="{}" style="" id="Overview" dir="ltr">Overview</h2><p>A variant group is a group of individual items that only differ by a few attributes. This is what a variant group looks like:</p><p redactor-attributes="{}" style="" dir="ltr"></p><img display-type="display" redactor-attributes="{"position":"left"}" inline="false" asset-name="rtaImage_(25).jpeg" asset-type="image/jpeg" asset-uid="blta78588c5804da9e9" style="" type="asset" dir="ltr" content-type-uid="sys_assets" class-name="embedded-asset" src="abcd.com/png.jpeg" /><p redactor-attributes="{}" style="" dir="ltr"></p><p redactor-attributes="{}" style="" dir="ltr"><strong><em>**NOTE: </em></strong><em>All items in a variant group should be included as separate items in the spec sheet. For instance, if you have a T-shirt that comes in two colors and three different sizes, you should have a total of six rows with each variation defined in a separate row. </em></p>
9+
</body>
10+
</html>
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
{
2+
"uid": "a59f9108e99747d4b3358d9e22b7c685",
3+
"type": "doc",
4+
"attrs": {
5+
"dirty": true
6+
},
7+
"children": [
8+
{
9+
"type": "p",
10+
"uid": "a3c0687b2f694bd68ec290fd92a62330",
11+
"attrs": {
12+
"style": {},
13+
"redactor-attributes": {},
14+
"dir": "ltr"
15+
},
16+
"children": [
17+
{
18+
"text": "This is a paragraph with break true and"
19+
},
20+
{
21+
"text": "\n",
22+
"break": true
23+
},
24+
{
25+
"text": "backslash n"
26+
},
27+
{
28+
"text": "This para has just one line break without any break key"
29+
},
30+
{
31+
"text": "\n"
32+
},
33+
{
34+
"text": "Third paragraph with multiple line breaks"
35+
},
36+
{
37+
"text": "\n\n\n"
38+
},
39+
{
40+
"text": "Fourth paragraph with multiple line breaks and break key"
41+
},
42+
{
43+
"text": "\n\n",
44+
"break": true
45+
},
46+
{
47+
"text": "Fifth paragraph with multiple only tab \t and this is text after tab"
48+
},
49+
{
50+
"text": "\n\t"
51+
},
52+
{
53+
"text": "This paragraph should start with a tab and should have a break before."
54+
}
55+
]
56+
}
57+
]
58+
}

0 commit comments

Comments
 (0)