Skip to content

Commit

Permalink
Merge pull request #9 from contentstack/development
Browse files Browse the repository at this point in the history
- Jsoup bump vulnerability issue
  • Loading branch information
ishaileshmishra authored Oct 6, 2022
2 parents 180417c + 322d7ea commit 57a6727
Show file tree
Hide file tree
Showing 10 changed files with 244 additions and 75 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ If you are using Contentstack Java SDK, then the Utils SDK is already imported i
</dependency>
```

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

Expand Down
11 changes: 5 additions & 6 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

<groupId>com.contentstack.sdk</groupId>
<artifactId>utils</artifactId>
<version>{$utils.version}</version>
<version>1.2.0-SNAPSHOT</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
Expand All @@ -14,7 +14,6 @@
<url>https://www.***REMOVED***</url>

<properties>
<util.version>1.1.2-SNAPSHOT</util.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.sourceEncoding>UTF-8</project.reporting.sourceEncoding>
<maven.compiler.source>1.8</maven.compiler.source>
Expand All @@ -24,7 +23,7 @@
<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.14.3</jsoup.version>
<jsoup.version>1.15.3</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>
Expand Down Expand Up @@ -104,12 +103,12 @@
<groupId>com.googlecode.json-simple</groupId>
<artifactId>json-simple</artifactId>
<version>${json.simple.version}</version>
<scope>compile</scope>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>5.3.20</version>
<version>5.3.23</version>
<scope>compile</scope>
</dependency>
</dependencies>
Expand Down Expand Up @@ -206,7 +205,7 @@
<plugin>
<groupId>org.sonatype.plugins</groupId>
<artifactId>nexus-staging-maven-plugin</artifactId>
<version>1.6.7</version>
<version>1.6.13</version>
<extensions>true</extensions>
<configuration>
<serverId>ossrh</serverId>
Expand Down
41 changes: 41 additions & 0 deletions src/main/java/com/contentstack/utils/Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down
21 changes: 14 additions & 7 deletions src/main/java/com/contentstack/utils/helper/Metadata.java
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
21 changes: 14 additions & 7 deletions src/main/java/com/contentstack/utils/interfaces/Option.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,27 +12,34 @@ 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);

/**
* 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);

/**
* 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);
Expand Down
21 changes: 21 additions & 0 deletions src/test/java/com/contentstack/utils/RTEResult.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package com.contentstack.utils;

public class RTEResult {

public static String kParagraphHtml = "<p>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.</p>";
public static String kPlainTextHtml = "<strong>Aliquam sit amet libero dapibus, eleifend ligula at, varius justo</strong><strong><em>Lorem ipsum</em></strong><strong><em><u>dolor sit amet</u></em></strong><strong><em><u><strike>consectetur adipiscing elit.</strike></u></em></strong><strong><em><u><span>Sed condimentum iaculis magna in vehicula. </span></u></em></strong><strong><em><u><sup> Vestibulum vitae convallis </sup></u></em></strong><strong><em><u><sub> lacus. </sub></u></em></strong>";
public static String kH1Html = "<h1><strong><em><u><sub>Lorem ipsum dolor sit amet.</sub></u></em></strong></h1>";
public static String kH2Html = "<h2><strong><em><u><sub>Vestibulum a ligula eget massa sagittis aliquam sit amet quis tortor. </sub></u></em></strong></h2>";
public static String kH3Html = "<h3><strong><em><u><sub>Mauris venenatis dui id massa sollicitudin, non bibendum nunc dictum.</sub></u></em></strong></h3>";
public static String kH4Html = "<h4><strong><em><u><sub>MaNullam feugiat turpis quis elit interdum, vitae laoreet quam viverra</sub></u></em></strong></h4>";
public static String kH5Html = "<h5>Mauris venenatis dui id massa sollicitudin, non bibendum nunc dictum.</h5>";
public static String kH6Html = "<h6>Nunc porta diam vitae purus semper, ut consequat lorem vehicula.</h6>";
public static String kOrderListHtml = "<ol><li>Morbi in quam molestie, fermentum diam vitae, bibendum ipsum.</li><li>Pellentesque mattis lacus in quam aliquam congue</li><li>Integer feugiat leo dignissim, lobortis enim vitae, mollis lectus.</li><li>Sed in ante lacinia, molestie metus eu, fringilla sapien.</li></ol>";
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>";
public static String kImgHtml = "<img src=\"https://images.***REMOVED***/v3/assets/UID_13/Donald.jog.png\" />";
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>";
public static String kBlockquoteHtml = "<blockquote>Praesent eu ex sed nibh venenatis pretium.</blockquote>";
public static String kCodeHtml = "<code>Code template.</code>";
public static String kLinkInPHtml = "<p><strong><em><u><sub></sub></u></em></strong><a href=\"LINK.com\">LINK</a></p>";
public static String kEmbedHtml = "<iframe src=\"https://www.youtube.com/watch?v=AOP0yARiW8U\"></iframe>";
}
Loading

0 comments on commit 57a6727

Please sign in to comment.