Skip to content

Commit

Permalink
Merge pull request #19 from contentstack/next
Browse files Browse the repository at this point in the history
bug: [CS-37173]-unexpected-newlines
  • Loading branch information
ishaileshmishra authored Apr 25, 2023
2 parents ea61385 + 6d263dc commit 8f0846e
Show file tree
Hide file tree
Showing 19 changed files with 196 additions and 55 deletions.
37 changes: 37 additions & 0 deletions .github/workflows/maven-publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
name: Publish package to the Maven Central Repository
on:
release:
types: [ created ]
jobs:
publish-maven:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
- uses: actions/checkout@v3
- name: Set up Maven Central Repository
uses: actions/setup-java@v3
with:
java-version: '8'
distribution: 'adopt'
server-id: ossrh
server-username: ${{ secrets.OSSRH_USERNAME }}
server-password: ${{ secrets.OSSRH_TOKEN }}
gpg-passphrase: ${{ secrets.GPG_PASSPHRASE }}
- name: Publish package
run: mvn --batch-mode deploy
publish-github:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up Java for publishing to GitHub Packages
uses: actions/setup-java@v3
with:
java-version: '8'
distribution: 'adopt'
server-id: github
- name: Publish to GitHub Packages
run: mvn --batch-mode deploy
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
5 changes: 5 additions & 0 deletions AUTHORS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Authors

- [ishaileshmishra](shailesh.mishra@***REMOVED***)
- [shaileshmishra](mshaileshr@***REMOVED***)
- [admin](dev@***REMOVED***)
42 changes: 42 additions & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@

# Changelog

A brief description of what changes project contains


## Jun 26, 2023
#### v1.2.1
##### Jun 26, 2023
New Line Issues while rendering Json object To HTML

## Updated Jsoup vulnerable dependency
#### v1.2.0
##### Oct 6, 2022
- Updated Jsoup vulnerable dependency
- jsonToHTML function support added


## Fixed compile Issue
#### v1.1.2
##### Jun 16, 2022
Fixed compile Issue

## Transitive dependencies updated
#### v1.1.1
##### Apr-06-2021
Updated transitive dependencies to pom.xml


## JSON RTE Feature Support
#### v1.1.0
##### Jun 1, 2022
JSON RTE Feature Support

## Introducing Release Of Java Utils SDK
#### v1.0.0
##### Apr 6, 2021
Initial release for Utils SDK
## Support

For support, email fake@fake.com or join our Slack channel.

2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2012 - 2021 Contentstack
Copyright (c) 2012 - 2023 Contentstack

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ This guide will help you get started with Contentstack Java Utils SDK to build a

### SDK Installation and Setup

To setup Utils SDK in your Java project, add the following dependency in the pom.xml file
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

```java
<dependency>
Expand Down
27 changes: 27 additions & 0 deletions SECURITY.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Security

Contentstack takes the security of our software products and services seriously, which includes all source code repositories managed through our GitHub organizations.

If you believe you have found a security vulnerability in any Contentstack-owned repository, please report it to us as described below.

## Reporting Security Issues

**Please do not report security vulnerabilities through public GitHub issues.**

Send email to [security@***REMOVED***](mailto:security@***REMOVED***).

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.

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:

- Type of issue (e.g. buffer overflow, SQL injection, cross-site scripting, etc.)
- Full paths of source file(s) related to the manifestation of the issue
- The location of the affected source code (tag/branch/commit or direct URL)
- Any special configuration required to reproduce the issue
- Step-by-step instructions to reproduce the issue
- Proof-of-concept or exploit code (if possible)
- Impact of the issue, including how an attacker might exploit the issue

This information will help us triage your report more quickly.

[https://www.***REMOVED***/trust/](https://www.***REMOVED***/trust/)
16 changes: 9 additions & 7 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,10 @@

<groupId>com.contentstack.sdk</groupId>
<artifactId>utils</artifactId>
<version>1.2.0-SNAPSHOT</version>
<version>1.2.1</version>
<packaging>jar</packaging>
<name>Contentstack-utils</name>
<description>Java Utils SDK for Contentstack Content Delivery API, Contentstack is a headless CMS with an API-first
approach
<description>Java Utils SDK for Contentstack Content Delivery API, Contentstack is a headless CMS
</description>
<url>https://www.***REMOVED***</url>

Expand All @@ -23,12 +22,15 @@
<maven-source-plugin.version>2.2.1</maven-source-plugin.version>
<maven-javadoc-plugin.version>3.1.1</maven-javadoc-plugin.version>
<junit.version>4.13.2</junit.version>
<jsoup.version>1.15.3</jsoup.version>
<jsoup.version>1.15.4</jsoup.version>
<json.simple.version>1.1.1</json.simple.version>
<maven-site-plugin.version>3.3</maven-site-plugin.version>
<maven-gpg-plugin.version>1.5</maven-gpg-plugin.version>
<nexus-staging-maven-plugin.version>1.6.7</nexus-staging-maven-plugin.version>
<maven-release-plugin.version>2.5.3</maven-release-plugin.version>
<validation-version>2.0.1.Final</validation-version>
<json-version>20230227</json-version>
<spring-web-version>6.0.4</spring-web-version>
</properties>

<developers>
Expand Down Expand Up @@ -85,7 +87,7 @@
<dependency>
<groupId>javax.validation</groupId>
<artifactId>validation-api</artifactId>
<version>2.0.1.Final</version>
<version>${validation-version}</version>
</dependency>
<dependency>
<groupId>org.jsoup</groupId>
Expand All @@ -96,7 +98,7 @@
<dependency>
<groupId>org.json</groupId>
<artifactId>json</artifactId>
<version>20220320</version>
<version>${json-version}</version>
<scope>compile</scope>
</dependency>
<dependency>
Expand All @@ -108,7 +110,7 @@
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>5.3.23</version>
<version>${spring-web-version}</version>
<scope>compile</scope>
</dependency>
</dependencies>
Expand Down
45 changes: 28 additions & 17 deletions src/main/java/com/contentstack/utils/AutomateCommon.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,27 +7,35 @@
import com.contentstack.utils.interfaces.Option;
import com.contentstack.utils.node.NodeToHTML;
import com.contentstack.utils.render.DefaultOption;
import javax.validation.constraints.NotNull;
import org.json.JSONArray;
import org.json.JSONObject;
import org.jsoup.nodes.Attributes;
import org.jsoup.nodes.Document;
import org.jsoup.select.Elements;

import javax.validation.constraints.NotNull;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Optional;

public class AutomateCommon {

private static final String ASSET = "asset";

private AutomateCommon() {
throw new IllegalStateException("Not allowed to create instance of AutomateCommon");
}

/**
* Find dot separated keys
*
* @param entryObj Json Object
* @param path keyPath
* @param contentCallback content callback
* @param entryObj
* Json Object
* @param path
* keyPath
* @param contentCallback
* content callback
*/
protected static void findContent(JSONObject entryObj, String path, ContentCallback contentCallback) {
String[] arrayString = path.split("\\.");
Expand All @@ -36,9 +44,12 @@ protected static void findContent(JSONObject entryObj, String path, ContentCallb


/**
* @param arrayString list of keys available
* @param entryObj entry object
* @param contentCallback content callback
* @param arrayString
* list of keys available
* @param entryObj
* entry object
* @param contentCallback
* content callback
*/
private static void getContent(String[] arrayString, JSONObject entryObj, ContentCallback contentCallback) {
if (arrayString != null && arrayString.length != 0) {
Expand Down Expand Up @@ -78,7 +89,7 @@ protected static String getStringOption(Option option, Metadata metadata, JSONOb
protected static void getEmbeddedObjects(Document html, MetadataCallback metadataCallback) {
Elements embeddedEntries = html.body().getElementsByClass("embedded-entry");
Elements embeddedAssets = html.body().getElementsByClass("embedded-asset");
embeddedEntries.forEach((entry) -> {
embeddedEntries.forEach(entry -> {
String text = entry.text();
String type = entry.attr("type");
String uid = entry.attr("data-sys-entry-uid");
Expand All @@ -89,13 +100,13 @@ protected static void getEmbeddedObjects(Document html, MetadataCallback metadat
metadataCallback.embeddedObject(metadata);
});

embeddedAssets.forEach((asset) -> {
embeddedAssets.forEach(asset -> {
String text = asset.text();
String type = asset.attr("type");
String uid = asset.attr("data-sys-asset-uid");
String style = asset.attr("sys-style-type");
String outerHTML = asset.outerHtml();
Metadata metadata = new Metadata(text, type, uid, "asset", style, outerHTML, asset.attributes());
Metadata metadata = new Metadata(text, type, uid, ASSET, style, outerHTML, asset.attributes());
metadataCallback.embeddedObject(metadata);
});
}
Expand All @@ -114,27 +125,27 @@ protected static Object enumerateContents(JSONArray contentArray, Option renderO
protected static String enumerateContent(JSONObject jsonObject, Option renderObject, MetaToEmbedCallback item) {
if (jsonObject.length() > 0 && jsonObject.has("type") && jsonObject.has("children")) {
if (jsonObject.opt("type").equals("doc")) {
return _doRawProcessing(jsonObject.optJSONArray("children"), renderObject, item);
return doRawProcessing(jsonObject.optJSONArray("children"), renderObject, item);
}
}
return "";
}


private static String _doRawProcessing(@NotNull JSONArray children, Option renderObject, MetaToEmbedCallback embedItem) {
private static String doRawProcessing(@NotNull JSONArray children, Option renderObject, MetaToEmbedCallback embedItem) {
StringBuilder stringBuilder = new StringBuilder();
children.forEach(item -> {
JSONObject child;
if (item instanceof JSONObject) {
child = (JSONObject) item;
stringBuilder.append(_extractKeys(child, renderObject, embedItem));
stringBuilder.append(extractKeys(child, renderObject, embedItem));
}
});
return stringBuilder.toString();
}


private static String _extractKeys(@NotNull JSONObject jsonNode, Option renderObject, MetaToEmbedCallback embedItem) {
private static String extractKeys(@NotNull JSONObject jsonNode, Option renderObject, MetaToEmbedCallback embedItem) {

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

if (attrType.equalsIgnoreCase("asset")) {
if (attrType.equalsIgnoreCase(ASSET)) {
String text = attrObj.optString("text");
String uid = attrObj.optString("asset-uid");
String style = attrObj.optString("display-type");
metadata = new com.contentstack.utils.helper.Metadata(text, attrType, uid,
"asset", style, "", new Attributes());
ASSET, style, "", new Attributes());
} else {
String text = attrObj.optString("text");
String uid = attrObj.optString("entry-uid");
Expand All @@ -167,7 +178,7 @@ private static String _extractKeys(@NotNull JSONObject jsonNode, Option renderOb
}

} else {
return renderObject.renderNode(nodeType, jsonNode, nodeJsonArray -> _doRawProcessing(nodeJsonArray, renderObject, embedItem));
return renderObject.renderNode(nodeType, jsonNode, nodeJsonArray -> doRawProcessing(nodeJsonArray, renderObject, embedItem));
}
}
return "";
Expand Down
15 changes: 9 additions & 6 deletions src/main/java/com/contentstack/utils/GQL.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@
*/
public class GQL {


private GQL() throws IllegalAccessException {
throw new IllegalAccessException("Invalid Access! Could not create instance of GQL");
}


private static JSONArray embeddedItems = null;

/**
Expand Down Expand Up @@ -44,7 +50,7 @@ public static void jsonToHTML(@NotNull JSONObject gqlEntry, @NotNull String[] pa
MetaToEmbedCallback converter = metadata -> {
if (embeddedItems != null) {
Optional<JSONObject> filteredContent = StreamSupport.stream(embeddedItems.spliterator(), false)
.map(val -> (JSONObject) val)
.map(JSONObject.class::cast)
.filter(itemDict -> {
JSONObject nodeObject = itemDict.optJSONObject("node");
if (nodeObject.has("uid")) {
Expand All @@ -70,11 +76,8 @@ public static void jsonToHTML(@NotNull JSONObject gqlEntry, @NotNull String[] pa
}
return null;
};

if (path.length > 0) {
for (String pathKey : path) {
findContent(gqlEntry, pathKey, callback);
}
for (String pathKey : path) {
findContent(gqlEntry, pathKey, callback);
}
}
}
18 changes: 8 additions & 10 deletions src/main/java/com/contentstack/utils/embedded/StyleType.java
Original file line number Diff line number Diff line change
@@ -1,24 +1,22 @@
package com.contentstack.utils.embedded;

/**
* -There are 5 ways of attaching entries inside the RTE field.
* `Block`: Useful for things like image carousels, embedded media, forms, product listings
* basically anything that does not make sense inline
* `Inline`: Useful for passing in some value from a linked entry that might be dynamic,
* such as a working title, a link that opens a modal popup, or any other use case
* where a developer might want an entire entry"\u00a9s" content to be embedded inline.
* `Linked`: Relative link to an entry object
* There are 5 ways of attaching entries inside the RTE field. `Block`: Useful for things like image carousels,
* embedded media, forms, product listings, basically anything that does not make sense inline `Inline`: Useful for
* passing in some value from a linked entry that might be dynamic, such as a working title, a link that opens a modal
* popup, or any other use case where a developer might want an entire entry "00a9s" content to be embedded inline.
* `Linked`: A relative link to an entry object
* <p>
* -There are Two way of attaching assets inside the RTE field.
* -There are Two ways of attaching assets inside the RTE field.
* <p>
* `DISPLAY`:
* <p>
* `DOWNLOAD`:
* <p>
* [`Example`]:
* <p>
* For `Entry`: StyleType.BLOCK, StyleType.INLINE, StyleType.LINKED,
* For `Assets`: StyleType.DISPLAY and StyleType.DOWNLOAD
* For `Entry`: StyleType.BLOCK, StyleType.INLINE, StyleType.LINKED, For `Assets`: StyleType. DISPLAY and StyleType.
* DOWNLOAD
*/
public enum StyleType {
BLOCK, INLINE, LINK, DISPLAY, DOWNLOAD,
Expand Down
Loading

0 comments on commit 8f0846e

Please sign in to comment.