Skip to content

Commit

Permalink
Merge pull request #30 from contentstack/next
Browse files Browse the repository at this point in the history
Next: Attribute Support Added
  • Loading branch information
ishaileshmishra authored Aug 8, 2023
2 parents c2980bc + 5b7ff7c commit b1631d1
Show file tree
Hide file tree
Showing 27 changed files with 619 additions and 347 deletions.
11 changes: 0 additions & 11 deletions .github/workflows/sast-scan.yml

This file was deleted.

11 changes: 0 additions & 11 deletions .github/workflows/secrets-scan.yml

This file was deleted.

8 changes: 8 additions & 0 deletions .idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

27 changes: 15 additions & 12 deletions Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,40 +3,43 @@

A brief description of what changes project contains

## Aug 8, 2023
#### v1.2.3
- Attribute support added


## Jun 7un 26, 2023
#### v1.2.2
- Added Support For Nested Assets
- General Code Improvement

## Jun 26, 2023
#### v1.2.1
##### Jun 26, 2023
New Line Issues while rendering Json object To HTML
- 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
- Fixed compile Issue

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


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

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

For support, email [email protected] or join our Slack channel.
- For support, email [email protected] or join our Slack channel.

147 changes: 78 additions & 69 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,23 +12,25 @@ This guide will help you get started with Contentstack Java Utils SDK to build a

### SDK Installation and Setup

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
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>
<groupId>com.contentstack.sdk</groupId>
<artifactId>util</artifactId>
<version>{latest}</version>
<groupId>com.contentstack.sdk</groupId>
<artifactId>util</artifactId>
<version>{latest}</version>
</dependency>
```

If you are using Contentstack Java SDK, then the Utils SDK is already imported into your project, and the dependency snippet will look as below
If you are using Contentstack Java SDK, then the Utils SDK is already imported into your project, and the dependency
snippet will look as below

```java
<dependency>
<groupId>com.contentstack.sdk</groupId>
<artifactId>java</artifactId>
<version>{latest}</version>
<groupId>com.contentstack.sdk</groupId>
<artifactId>java</artifactId>
<version>{latest}</version>
</dependency>
```

Expand All @@ -40,18 +42,20 @@ Let’s learn how you can use Utils SDK to render embedded items.

### Create Render Option

To render embedded items on the front-end, use the renderContents function, and define the UI elements you want to show in the front-end of your website, as shown in the example code below:
To render embedded items on the front-end, use the renderContents function, and define the UI elements you want to show
in the front-end of your website, as shown in the example code below:

```java

package com.contentstack.utils;

import com.contentstack.utils.helper.Metadata;
import com.contentstack.utils.interfaces.NodeCallback;
import com.contentstack.utils.interfaces.Option;
import com.contentstack.utils.node.MarkType;
import com.contentstack.utils.render.DefaultOption;
import org.json.JSONObject;

public class DefaultOptionClass implements Option {
public class DefaultOptionClass extends DefaultOption {

@Override
public String renderOptions(JSONObject embeddedObject, Metadata metadata) {
Expand All @@ -69,7 +73,7 @@ public class DefaultOptionClass implements Option {
return "<p>" + embeddedObject.getString("someTitle") + "</p><span>" +
embeddedObject.getString("multi") + "</span>";
default:
return null;
return super.renderOptions(embeddedObject, metadata);
}
}

Expand All @@ -78,7 +82,7 @@ public class DefaultOptionClass implements Option {
if (markType == MarkType.BOLD) {
return "<b>" + renderText + "</b>";
}
return null;
return super.renderMark(markType, renderText);
}

@Override
Expand All @@ -88,94 +92,99 @@ public class DefaultOptionClass implements Option {
return "<p class='class-id'>" + children + "</p>";
}

return null;
return super.renderNode(nodeType, nodeObject, callback);
}
}


```

### Basic Queries

Contentstack Utils SDK lets you interact with the Content Delivery APIs and retrieve embedded items from the RTE field of an entry.
Contentstack Utils SDK lets you interact with the Content Delivery APIs and retrieve embedded items from the RTE field
of an entry.

#### Fetch Embedded Item(s) from a Single Entry

To get an embedded item of a single entry, you need to provide the stack API key, environment name, delivery token, content type’s UID and entry’s UID. Then, use the includeEmbeddedItems function as shown below:
To get an embedded item of a single entry, you need to provide the stack API key, environment name, delivery token,
content type’s UID and entry’s UID. Then, use the includeEmbeddedItems function as shown below:

```java

import Contentstack
Stack stack = Contentstack.stack("apiKey", "deliveryToken", "environment_name");
ContentType contentType = stack.contentType("content_type_uid");
Entry entry = contentType.entry("entry_uid");
entry.includeEmbeddedItems();
entry.fetch(new EntryResultCallBack() {
@Override
public void onCompletion(ResponseType responseType, Error error) {
if (error == null) {
// [Success block]
String[] keyPath = {
"rich_text_editor", "global_rich_multiple.group.rich_text_editor"
};
JSONObject jsonObject = entry.toJSON();
Utils.render(jsonObject, keyPath, new Option());
} else {
[Error block] // handle your error
Stack stack=Contentstack.stack("apiKey","deliveryToken","environment_name");
ContentType contentType=stack.contentType("content_type_uid");
Entry entry=contentType.entry("entry_uid");
entry.includeEmbeddedItems();
entry.fetch(new EntryResultCallBack(){
@Override
public void onCompletion(ResponseType responseType,Error error){
if(error==null){
// [Success block]
String[]keyPath={
"rich_text_editor","global_rich_multiple.group.rich_text_editor"
};
JSONObject jsonObject=entry.toJSON();
Utils.render(jsonObject,keyPath,new Option());
}else{
[Error block] // handle your error
}}
});
});
```

#### Fetch Embedded Item(s) from Multiple Entries

To get embedded items from multiple entries, you need to provide the stack API key, environment name, delivery token, and content type’s UID.
To get embedded items from multiple entries, you need to provide the stack API key, environment name, delivery token,
and content type’s UID.

```java

import Contentstack
Stack stack = Contentstack.stack("apiKey", "deliveryToken", "environment_name");
Query query = stack.contentType("content_type_uid").query();
query.includeEmbeddedItems();
query.find(new QueryResultsCallBack() {
@Override
public void onCompletion(ResponseType responseType, QueryResult queryResult, Error error) {
if (error == null) {
List<Entry> entries = queryresult.getResultObjects();
String[] keyPath = {
"rich_text_editor", "global_rich_multiple.group.rich_text_editor"
};
for (Entry entry : entries) {
JSONObject jsonObject = entry.toJSON();
Utils.render(jsonObject, keyPath, new Option());
}
Stack stack=Contentstack.stack("apiKey","deliveryToken","environment_name");
Query query=stack.contentType("content_type_uid").query();
query.includeEmbeddedItems();
query.find(new QueryResultsCallBack(){
@Override
public void onCompletion(ResponseType responseType,QueryResult queryResult,Error error){
if(error==null){
List<Entry> entries=queryresult.getResultObjects();
String[]keyPath={
"rich_text_editor","global_rich_multiple.group.rich_text_editor"
};
for(Entry entry:entries){
JSONObject jsonObject=entry.toJSON();
Utils.render(jsonObject,keyPath,new Option());
}
}else{
[Error block] // handle your error
}}
});
[Error block] // handle your error
}}
});
```

#### Render JSON RTE Contents

To get multiple entries, you need to provide the stack API key, environment name, delivery token, content type and entry UID. Then, use the Utils.jsonToHTML function as shown below:
To get multiple entries, you need to provide the stack API key, environment name, delivery token, content type and entry
UID. Then, use the Utils.jsonToHTML function as shown below:

```java

import Contentstack
Stack stack = Contentstack.stack("apiKey", "deliveryToken", "environment_name");
Query query = stack.contentType("content_type_uid").query();
query.includeEmbeddedItems(); // include embedded items
query.find(new QueryResultsCallBack() {
@Override
public void onCompletion(ResponseType responseType, QueryResult queryResult, Error error) {
if (error == null) {
List<Entry> entries = queryresult.getResultObjects();
String[] keyPath = {
"rte_fieldUid", "group.rteFieldUID"
};
for (Entry entry : entries) {
JSONObject jsonObject = entry.toJSON();
Utils.jsonToHTML(jsonObject, keyPath, new Option());
}
Stack stack=Contentstack.stack("apiKey","deliveryToken","environment_name");
Query query=stack.contentType("content_type_uid").query();
query.includeEmbeddedItems(); // include embedded items
query.find(new QueryResultsCallBack(){
@Override
public void onCompletion(ResponseType responseType,QueryResult queryResult,Error error){
if(error==null){
List<Entry> entries=queryresult.getResultObjects();
String[]keyPath={
"rte_fieldUid","group.rteFieldUID"
};
for(Entry entry:entries){
JSONObject jsonObject=entry.toJSON();
Utils.jsonToHTML(jsonObject,keyPath,new Option());
}
}}
});
});

```
6 changes: 3 additions & 3 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>1.2.2</version>
<version>1.2.3</version>
<packaging>jar</packaging>
<name>Contentstack-utils</name>
<description>Java Utils SDK for Contentstack Content Delivery API, Contentstack is a headless CMS
Expand All @@ -30,7 +30,7 @@
<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.7</spring-web-version>
<spring-web-version>6.0.11</spring-web-version>
<org.apache.commons-text>1.10.0</org.apache.commons-text>
</properties>

Expand Down Expand Up @@ -237,4 +237,4 @@
</plugins>
</build>

</project>
</project>
Loading

0 comments on commit b1631d1

Please sign in to comment.