Skip to content

Commit 8f0846e

Browse files
Merge pull request #19 from contentstack/next
bug: [CS-37173]-unexpected-newlines
2 parents ea61385 + 6d263dc commit 8f0846e

19 files changed

+196
-55
lines changed

.github/workflows/maven-publish.yml

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
name: Publish package to the Maven Central Repository
2+
on:
3+
release:
4+
types: [ created ]
5+
jobs:
6+
publish-maven:
7+
runs-on: ubuntu-latest
8+
permissions:
9+
contents: read
10+
packages: write
11+
steps:
12+
- uses: actions/checkout@v3
13+
- name: Set up Maven Central Repository
14+
uses: actions/setup-java@v3
15+
with:
16+
java-version: '8'
17+
distribution: 'adopt'
18+
server-id: ossrh
19+
server-username: ${{ secrets.OSSRH_USERNAME }}
20+
server-password: ${{ secrets.OSSRH_TOKEN }}
21+
gpg-passphrase: ${{ secrets.GPG_PASSPHRASE }}
22+
- name: Publish package
23+
run: mvn --batch-mode deploy
24+
publish-github:
25+
runs-on: ubuntu-latest
26+
steps:
27+
- uses: actions/checkout@v3
28+
- name: Set up Java for publishing to GitHub Packages
29+
uses: actions/setup-java@v3
30+
with:
31+
java-version: '8'
32+
distribution: 'adopt'
33+
server-id: github
34+
- name: Publish to GitHub Packages
35+
run: mvn --batch-mode deploy
36+
env:
37+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

AUTHORS.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Authors
2+
3+
- [ishaileshmishra](shailesh.mishra@***REMOVED***)
4+
- [shaileshmishra](mshaileshr@***REMOVED***)
5+
- [admin](dev@***REMOVED***)

Changelog.md

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
2+
# Changelog
3+
4+
A brief description of what changes project contains
5+
6+
7+
## Jun 26, 2023
8+
#### v1.2.1
9+
##### Jun 26, 2023
10+
New Line Issues while rendering Json object To HTML
11+
12+
## Updated Jsoup vulnerable dependency
13+
#### v1.2.0
14+
##### Oct 6, 2022
15+
- Updated Jsoup vulnerable dependency
16+
- jsonToHTML function support added
17+
18+
19+
## Fixed compile Issue
20+
#### v1.1.2
21+
##### Jun 16, 2022
22+
Fixed compile Issue
23+
24+
## Transitive dependencies updated
25+
#### v1.1.1
26+
##### Apr-06-2021
27+
Updated transitive dependencies to pom.xml
28+
29+
30+
## JSON RTE Feature Support
31+
#### v1.1.0
32+
##### Jun 1, 2022
33+
JSON RTE Feature Support
34+
35+
## Introducing Release Of Java Utils SDK
36+
#### v1.0.0
37+
##### Apr 6, 2021
38+
Initial release for Utils SDK
39+
## Support
40+
41+
For support, email [email protected] or join our Slack channel.
42+

LICENSE

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MIT License
22

3-
Copyright (c) 2012 - 2021 Contentstack
3+
Copyright (c) 2012 - 2023 Contentstack
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ This guide will help you get started with Contentstack Java Utils SDK to build a
1212

1313
### SDK Installation and Setup
1414

15-
To setup Utils SDK in your Java project, add the following dependency in the pom.xml file
15+
To setup [Utils SDK](https://mvnrepository.com/artifact/com.contentstack.sdk/utils) in your Java project, add the following dependency in the pom.xml file
1616

1717
```java
1818
<dependency>

SECURITY.md

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Security
2+
3+
Contentstack takes the security of our software products and services seriously, which includes all source code repositories managed through our GitHub organizations.
4+
5+
If you believe you have found a security vulnerability in any Contentstack-owned repository, please report it to us as described below.
6+
7+
## Reporting Security Issues
8+
9+
**Please do not report security vulnerabilities through public GitHub issues.**
10+
11+
Send email to [security@***REMOVED***](mailto:security@***REMOVED***).
12+
13+
You should receive a response within 24 hours. If for some reason you do not, please follow up via email to ensure we received your original message.
14+
15+
Please include the requested information listed below (as much as you can provide) to help us better understand the nature and scope of the possible issue:
16+
17+
- Type of issue (e.g. buffer overflow, SQL injection, cross-site scripting, etc.)
18+
- Full paths of source file(s) related to the manifestation of the issue
19+
- The location of the affected source code (tag/branch/commit or direct URL)
20+
- Any special configuration required to reproduce the issue
21+
- Step-by-step instructions to reproduce the issue
22+
- Proof-of-concept or exploit code (if possible)
23+
- Impact of the issue, including how an attacker might exploit the issue
24+
25+
This information will help us triage your report more quickly.
26+
27+
[https://www.***REMOVED***/trust/](https://www.***REMOVED***/trust/)

pom.xml

+9-7
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,10 @@
55

66
<groupId>com.contentstack.sdk</groupId>
77
<artifactId>utils</artifactId>
8-
<version>1.2.0-SNAPSHOT</version>
8+
<version>1.2.1</version>
99
<packaging>jar</packaging>
1010
<name>Contentstack-utils</name>
11-
<description>Java Utils SDK for Contentstack Content Delivery API, Contentstack is a headless CMS with an API-first
12-
approach
11+
<description>Java Utils SDK for Contentstack Content Delivery API, Contentstack is a headless CMS
1312
</description>
1413
<url>https://www.***REMOVED***</url>
1514

@@ -23,12 +22,15 @@
2322
<maven-source-plugin.version>2.2.1</maven-source-plugin.version>
2423
<maven-javadoc-plugin.version>3.1.1</maven-javadoc-plugin.version>
2524
<junit.version>4.13.2</junit.version>
26-
<jsoup.version>1.15.3</jsoup.version>
25+
<jsoup.version>1.15.4</jsoup.version>
2726
<json.simple.version>1.1.1</json.simple.version>
2827
<maven-site-plugin.version>3.3</maven-site-plugin.version>
2928
<maven-gpg-plugin.version>1.5</maven-gpg-plugin.version>
3029
<nexus-staging-maven-plugin.version>1.6.7</nexus-staging-maven-plugin.version>
3130
<maven-release-plugin.version>2.5.3</maven-release-plugin.version>
31+
<validation-version>2.0.1.Final</validation-version>
32+
<json-version>20230227</json-version>
33+
<spring-web-version>6.0.4</spring-web-version>
3234
</properties>
3335

3436
<developers>
@@ -85,7 +87,7 @@
8587
<dependency>
8688
<groupId>javax.validation</groupId>
8789
<artifactId>validation-api</artifactId>
88-
<version>2.0.1.Final</version>
90+
<version>${validation-version}</version>
8991
</dependency>
9092
<dependency>
9193
<groupId>org.jsoup</groupId>
@@ -96,7 +98,7 @@
9698
<dependency>
9799
<groupId>org.json</groupId>
98100
<artifactId>json</artifactId>
99-
<version>20220320</version>
101+
<version>${json-version}</version>
100102
<scope>compile</scope>
101103
</dependency>
102104
<dependency>
@@ -108,7 +110,7 @@
108110
<dependency>
109111
<groupId>org.springframework</groupId>
110112
<artifactId>spring-web</artifactId>
111-
<version>5.3.23</version>
113+
<version>${spring-web-version}</version>
112114
<scope>compile</scope>
113115
</dependency>
114116
</dependencies>

src/main/java/com/contentstack/utils/AutomateCommon.java

+28-17
Original file line numberDiff line numberDiff line change
@@ -7,27 +7,35 @@
77
import com.contentstack.utils.interfaces.Option;
88
import com.contentstack.utils.node.NodeToHTML;
99
import com.contentstack.utils.render.DefaultOption;
10-
import javax.validation.constraints.NotNull;
1110
import org.json.JSONArray;
1211
import org.json.JSONObject;
1312
import org.jsoup.nodes.Attributes;
1413
import org.jsoup.nodes.Document;
1514
import org.jsoup.select.Elements;
1615

16+
import javax.validation.constraints.NotNull;
1717
import java.util.ArrayList;
1818
import java.util.Arrays;
1919
import java.util.List;
2020
import java.util.Optional;
2121

2222
public class AutomateCommon {
2323

24+
private static final String ASSET = "asset";
25+
26+
private AutomateCommon() {
27+
throw new IllegalStateException("Not allowed to create instance of AutomateCommon");
28+
}
2429

2530
/**
2631
* Find dot separated keys
2732
*
28-
* @param entryObj Json Object
29-
* @param path keyPath
30-
* @param contentCallback content callback
33+
* @param entryObj
34+
* Json Object
35+
* @param path
36+
* keyPath
37+
* @param contentCallback
38+
* content callback
3139
*/
3240
protected static void findContent(JSONObject entryObj, String path, ContentCallback contentCallback) {
3341
String[] arrayString = path.split("\\.");
@@ -36,9 +44,12 @@ protected static void findContent(JSONObject entryObj, String path, ContentCallb
3644

3745

3846
/**
39-
* @param arrayString list of keys available
40-
* @param entryObj entry object
41-
* @param contentCallback content callback
47+
* @param arrayString
48+
* list of keys available
49+
* @param entryObj
50+
* entry object
51+
* @param contentCallback
52+
* content callback
4253
*/
4354
private static void getContent(String[] arrayString, JSONObject entryObj, ContentCallback contentCallback) {
4455
if (arrayString != null && arrayString.length != 0) {
@@ -78,7 +89,7 @@ protected static String getStringOption(Option option, Metadata metadata, JSONOb
7889
protected static void getEmbeddedObjects(Document html, MetadataCallback metadataCallback) {
7990
Elements embeddedEntries = html.body().getElementsByClass("embedded-entry");
8091
Elements embeddedAssets = html.body().getElementsByClass("embedded-asset");
81-
embeddedEntries.forEach((entry) -> {
92+
embeddedEntries.forEach(entry -> {
8293
String text = entry.text();
8394
String type = entry.attr("type");
8495
String uid = entry.attr("data-sys-entry-uid");
@@ -89,13 +100,13 @@ protected static void getEmbeddedObjects(Document html, MetadataCallback metadat
89100
metadataCallback.embeddedObject(metadata);
90101
});
91102

92-
embeddedAssets.forEach((asset) -> {
103+
embeddedAssets.forEach(asset -> {
93104
String text = asset.text();
94105
String type = asset.attr("type");
95106
String uid = asset.attr("data-sys-asset-uid");
96107
String style = asset.attr("sys-style-type");
97108
String outerHTML = asset.outerHtml();
98-
Metadata metadata = new Metadata(text, type, uid, "asset", style, outerHTML, asset.attributes());
109+
Metadata metadata = new Metadata(text, type, uid, ASSET, style, outerHTML, asset.attributes());
99110
metadataCallback.embeddedObject(metadata);
100111
});
101112
}
@@ -114,27 +125,27 @@ protected static Object enumerateContents(JSONArray contentArray, Option renderO
114125
protected static String enumerateContent(JSONObject jsonObject, Option renderObject, MetaToEmbedCallback item) {
115126
if (jsonObject.length() > 0 && jsonObject.has("type") && jsonObject.has("children")) {
116127
if (jsonObject.opt("type").equals("doc")) {
117-
return _doRawProcessing(jsonObject.optJSONArray("children"), renderObject, item);
128+
return doRawProcessing(jsonObject.optJSONArray("children"), renderObject, item);
118129
}
119130
}
120131
return "";
121132
}
122133

123134

124-
private static String _doRawProcessing(@NotNull JSONArray children, Option renderObject, MetaToEmbedCallback embedItem) {
135+
private static String doRawProcessing(@NotNull JSONArray children, Option renderObject, MetaToEmbedCallback embedItem) {
125136
StringBuilder stringBuilder = new StringBuilder();
126137
children.forEach(item -> {
127138
JSONObject child;
128139
if (item instanceof JSONObject) {
129140
child = (JSONObject) item;
130-
stringBuilder.append(_extractKeys(child, renderObject, embedItem));
141+
stringBuilder.append(extractKeys(child, renderObject, embedItem));
131142
}
132143
});
133144
return stringBuilder.toString();
134145
}
135146

136147

137-
private static String _extractKeys(@NotNull JSONObject jsonNode, Option renderObject, MetaToEmbedCallback embedItem) {
148+
private static String extractKeys(@NotNull JSONObject jsonNode, Option renderObject, MetaToEmbedCallback embedItem) {
138149

139150
if (!jsonNode.has("type") && jsonNode.has("text")) {
140151
return NodeToHTML.textNodeToHTML(jsonNode, renderObject);
@@ -145,12 +156,12 @@ private static String _extractKeys(@NotNull JSONObject jsonNode, Option renderOb
145156
String attrType = attrObj.optString("type");
146157
com.contentstack.utils.helper.Metadata metadata;
147158

148-
if (attrType.equalsIgnoreCase("asset")) {
159+
if (attrType.equalsIgnoreCase(ASSET)) {
149160
String text = attrObj.optString("text");
150161
String uid = attrObj.optString("asset-uid");
151162
String style = attrObj.optString("display-type");
152163
metadata = new com.contentstack.utils.helper.Metadata(text, attrType, uid,
153-
"asset", style, "", new Attributes());
164+
ASSET, style, "", new Attributes());
154165
} else {
155166
String text = attrObj.optString("text");
156167
String uid = attrObj.optString("entry-uid");
@@ -167,7 +178,7 @@ private static String _extractKeys(@NotNull JSONObject jsonNode, Option renderOb
167178
}
168179

169180
} else {
170-
return renderObject.renderNode(nodeType, jsonNode, nodeJsonArray -> _doRawProcessing(nodeJsonArray, renderObject, embedItem));
181+
return renderObject.renderNode(nodeType, jsonNode, nodeJsonArray -> doRawProcessing(nodeJsonArray, renderObject, embedItem));
171182
}
172183
}
173184
return "";

src/main/java/com/contentstack/utils/GQL.java

+9-6
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,12 @@
1717
*/
1818
public class GQL {
1919

20+
21+
private GQL() throws IllegalAccessException {
22+
throw new IllegalAccessException("Invalid Access! Could not create instance of GQL");
23+
}
24+
25+
2026
private static JSONArray embeddedItems = null;
2127

2228
/**
@@ -44,7 +50,7 @@ public static void jsonToHTML(@NotNull JSONObject gqlEntry, @NotNull String[] pa
4450
MetaToEmbedCallback converter = metadata -> {
4551
if (embeddedItems != null) {
4652
Optional<JSONObject> filteredContent = StreamSupport.stream(embeddedItems.spliterator(), false)
47-
.map(val -> (JSONObject) val)
53+
.map(JSONObject.class::cast)
4854
.filter(itemDict -> {
4955
JSONObject nodeObject = itemDict.optJSONObject("node");
5056
if (nodeObject.has("uid")) {
@@ -70,11 +76,8 @@ public static void jsonToHTML(@NotNull JSONObject gqlEntry, @NotNull String[] pa
7076
}
7177
return null;
7278
};
73-
74-
if (path.length > 0) {
75-
for (String pathKey : path) {
76-
findContent(gqlEntry, pathKey, callback);
77-
}
79+
for (String pathKey : path) {
80+
findContent(gqlEntry, pathKey, callback);
7881
}
7982
}
8083
}

src/main/java/com/contentstack/utils/embedded/StyleType.java

+8-10
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,22 @@
11
package com.contentstack.utils.embedded;
22

33
/**
4-
* -There are 5 ways of attaching entries inside the RTE field.
5-
* `Block`: Useful for things like image carousels, embedded media, forms, product listings
6-
* basically anything that does not make sense inline
7-
* `Inline`: Useful for passing in some value from a linked entry that might be dynamic,
8-
* such as a working title, a link that opens a modal popup, or any other use case
9-
* where a developer might want an entire entry"\u00a9s" content to be embedded inline.
10-
* `Linked`: Relative link to an entry object
4+
* There are 5 ways of attaching entries inside the RTE field. `Block`: Useful for things like image carousels,
5+
* embedded media, forms, product listings, basically anything that does not make sense inline `Inline`: Useful for
6+
* passing in some value from a linked entry that might be dynamic, such as a working title, a link that opens a modal
7+
* popup, or any other use case where a developer might want an entire entry "00a9s" content to be embedded inline.
8+
* `Linked`: A relative link to an entry object
119
* <p>
12-
* -There are Two way of attaching assets inside the RTE field.
10+
* -There are Two ways of attaching assets inside the RTE field.
1311
* <p>
1412
* `DISPLAY`:
1513
* <p>
1614
* `DOWNLOAD`:
1715
* <p>
1816
* [`Example`]:
1917
* <p>
20-
* For `Entry`: StyleType.BLOCK, StyleType.INLINE, StyleType.LINKED,
21-
* For `Assets`: StyleType.DISPLAY and StyleType.DOWNLOAD
18+
* For `Entry`: StyleType.BLOCK, StyleType.INLINE, StyleType.LINKED, For `Assets`: StyleType. DISPLAY and StyleType.
19+
* DOWNLOAD
2220
*/
2321
public enum StyleType {
2422
BLOCK, INLINE, LINK, DISPLAY, DOWNLOAD,

0 commit comments

Comments
 (0)