Skip to content

Commit b1631d1

Browse files
Merge pull request #30 from contentstack/next
Next: Attribute Support Added
2 parents c2980bc + 5b7ff7c commit b1631d1

27 files changed

+619
-347
lines changed

.github/workflows/sast-scan.yml

-11
This file was deleted.

.github/workflows/secrets-scan.yml

-11
This file was deleted.

.idea/.gitignore

+8
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Changelog.md

+15-12
Original file line numberDiff line numberDiff line change
@@ -3,40 +3,43 @@
33

44
A brief description of what changes project contains
55

6+
## Aug 8, 2023
7+
#### v1.2.3
8+
- Attribute support added
9+
10+
11+
## Jun 7un 26, 2023
12+
#### v1.2.2
13+
- Added Support For Nested Assets
14+
- General Code Improvement
615

716
## Jun 26, 2023
817
#### v1.2.1
9-
##### Jun 26, 2023
10-
New Line Issues while rendering Json object To HTML
18+
- New Line Issues while rendering Json object To HTML
1119

1220
## Updated Jsoup vulnerable dependency
1321
#### v1.2.0
14-
##### Oct 6, 2022
1522
- Updated Jsoup vulnerable dependency
1623
- jsonToHTML function support added
1724

1825

1926
## Fixed compile Issue
2027
#### v1.1.2
21-
##### Jun 16, 2022
22-
Fixed compile Issue
28+
- Fixed compile Issue
2329

2430
## Transitive dependencies updated
2531
#### v1.1.1
26-
##### Apr-06-2021
27-
Updated transitive dependencies to pom.xml
32+
- Updated transitive dependencies to pom.xml
2833

2934

3035
## JSON RTE Feature Support
3136
#### v1.1.0
32-
##### Jun 1, 2022
33-
JSON RTE Feature Support
37+
- JSON RTE Feature Support
3438

3539
## Introducing Release Of Java Utils SDK
3640
#### v1.0.0
37-
##### Apr 6, 2021
38-
Initial release for Utils SDK
41+
- Initial release for Utils SDK
3942
## Support
4043

41-
For support, email [email protected] or join our Slack channel.
44+
- For support, email [email protected] or join our Slack channel.
4245

README.md

+78-69
Original file line numberDiff line numberDiff line change
@@ -12,23 +12,25 @@ 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](https://mvnrepository.com/artifact/com.contentstack.sdk/utils) 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
16+
following dependency in the pom.xml file
1617

1718
```java
1819
<dependency>
19-
<groupId>com.contentstack.sdk</groupId>
20-
<artifactId>util</artifactId>
21-
<version>{latest}</version>
20+
<groupId>com.contentstack.sdk</groupId>
21+
<artifactId>util</artifactId>
22+
<version>{latest}</version>
2223
</dependency>
2324
```
2425

25-
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
26+
If you are using Contentstack Java SDK, then the Utils SDK is already imported into your project, and the dependency
27+
snippet will look as below
2628

2729
```java
2830
<dependency>
29-
<groupId>com.contentstack.sdk</groupId>
30-
<artifactId>java</artifactId>
31-
<version>{latest}</version>
31+
<groupId>com.contentstack.sdk</groupId>
32+
<artifactId>java</artifactId>
33+
<version>{latest}</version>
3234
</dependency>
3335
```
3436

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

4143
### Create Render Option
4244

43-
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:
45+
To render embedded items on the front-end, use the renderContents function, and define the UI elements you want to show
46+
in the front-end of your website, as shown in the example code below:
4447

4548
```java
4649

4750
package com.contentstack.utils;
51+
4852
import com.contentstack.utils.helper.Metadata;
4953
import com.contentstack.utils.interfaces.NodeCallback;
50-
import com.contentstack.utils.interfaces.Option;
5154
import com.contentstack.utils.node.MarkType;
55+
import com.contentstack.utils.render.DefaultOption;
5256
import org.json.JSONObject;
5357

54-
public class DefaultOptionClass implements Option {
58+
public class DefaultOptionClass extends DefaultOption {
5559

5660
@Override
5761
public String renderOptions(JSONObject embeddedObject, Metadata metadata) {
@@ -69,7 +73,7 @@ public class DefaultOptionClass implements Option {
6973
return "<p>" + embeddedObject.getString("someTitle") + "</p><span>" +
7074
embeddedObject.getString("multi") + "</span>";
7175
default:
72-
return null;
76+
return super.renderOptions(embeddedObject, metadata);
7377
}
7478
}
7579

@@ -78,7 +82,7 @@ public class DefaultOptionClass implements Option {
7882
if (markType == MarkType.BOLD) {
7983
return "<b>" + renderText + "</b>";
8084
}
81-
return null;
85+
return super.renderMark(markType, renderText);
8286
}
8387

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

91-
return null;
95+
return super.renderNode(nodeType, nodeObject, callback);
9296
}
9397
}
9498

99+
95100
```
96101

97102
### Basic Queries
98103

99-
Contentstack Utils SDK lets you interact with the Content Delivery APIs and retrieve embedded items from the RTE field of an entry.
104+
Contentstack Utils SDK lets you interact with the Content Delivery APIs and retrieve embedded items from the RTE field
105+
of an entry.
100106

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

103-
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:
109+
To get an embedded item of a single entry, you need to provide the stack API key, environment name, delivery token,
110+
content type’s UID and entry’s UID. Then, use the includeEmbeddedItems function as shown below:
104111

105112
```java
106113

107114
import Contentstack
108-
Stack stack = Contentstack.stack("apiKey", "deliveryToken", "environment_name");
109-
ContentType contentType = stack.contentType("content_type_uid");
110-
Entry entry = contentType.entry("entry_uid");
111-
entry.includeEmbeddedItems();
112-
entry.fetch(new EntryResultCallBack() {
113-
@Override
114-
public void onCompletion(ResponseType responseType, Error error) {
115-
if (error == null) {
116-
// [Success block]
117-
String[] keyPath = {
118-
"rich_text_editor", "global_rich_multiple.group.rich_text_editor"
119-
};
120-
JSONObject jsonObject = entry.toJSON();
121-
Utils.render(jsonObject, keyPath, new Option());
122-
} else {
123-
[Error block] // handle your error
115+
Stack stack=Contentstack.stack("apiKey","deliveryToken","environment_name");
116+
ContentType contentType=stack.contentType("content_type_uid");
117+
Entry entry=contentType.entry("entry_uid");
118+
entry.includeEmbeddedItems();
119+
entry.fetch(new EntryResultCallBack(){
120+
@Override
121+
public void onCompletion(ResponseType responseType,Error error){
122+
if(error==null){
123+
// [Success block]
124+
String[]keyPath={
125+
"rich_text_editor","global_rich_multiple.group.rich_text_editor"
126+
};
127+
JSONObject jsonObject=entry.toJSON();
128+
Utils.render(jsonObject,keyPath,new Option());
129+
}else{
130+
[Error block] // handle your error
124131
}}
125-
});
132+
});
126133
```
127134

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

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

132140
```java
133141

134142
import Contentstack
135-
Stack stack = Contentstack.stack("apiKey", "deliveryToken", "environment_name");
136-
Query query = stack.contentType("content_type_uid").query();
137-
query.includeEmbeddedItems();
138-
query.find(new QueryResultsCallBack() {
139-
@Override
140-
public void onCompletion(ResponseType responseType, QueryResult queryResult, Error error) {
141-
if (error == null) {
142-
List<Entry> entries = queryresult.getResultObjects();
143-
String[] keyPath = {
144-
"rich_text_editor", "global_rich_multiple.group.rich_text_editor"
145-
};
146-
for (Entry entry : entries) {
147-
JSONObject jsonObject = entry.toJSON();
148-
Utils.render(jsonObject, keyPath, new Option());
149-
}
143+
Stack stack=Contentstack.stack("apiKey","deliveryToken","environment_name");
144+
Query query=stack.contentType("content_type_uid").query();
145+
query.includeEmbeddedItems();
146+
query.find(new QueryResultsCallBack(){
147+
@Override
148+
public void onCompletion(ResponseType responseType,QueryResult queryResult,Error error){
149+
if(error==null){
150+
List<Entry> entries=queryresult.getResultObjects();
151+
String[]keyPath={
152+
"rich_text_editor","global_rich_multiple.group.rich_text_editor"
153+
};
154+
for(Entry entry:entries){
155+
JSONObject jsonObject=entry.toJSON();
156+
Utils.render(jsonObject,keyPath,new Option());
157+
}
150158
}else{
151-
[Error block] // handle your error
152-
}}
153-
});
159+
[Error block] // handle your error
160+
}}
161+
});
154162
```
155163

156164
#### Render JSON RTE Contents
157165

158-
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:
166+
To get multiple entries, you need to provide the stack API key, environment name, delivery token, content type and entry
167+
UID. Then, use the Utils.jsonToHTML function as shown below:
159168

160169
```java
161170

162171
import Contentstack
163-
Stack stack = Contentstack.stack("apiKey", "deliveryToken", "environment_name");
164-
Query query = stack.contentType("content_type_uid").query();
165-
query.includeEmbeddedItems(); // include embedded items
166-
query.find(new QueryResultsCallBack() {
167-
@Override
168-
public void onCompletion(ResponseType responseType, QueryResult queryResult, Error error) {
169-
if (error == null) {
170-
List<Entry> entries = queryresult.getResultObjects();
171-
String[] keyPath = {
172-
"rte_fieldUid", "group.rteFieldUID"
173-
};
174-
for (Entry entry : entries) {
175-
JSONObject jsonObject = entry.toJSON();
176-
Utils.jsonToHTML(jsonObject, keyPath, new Option());
177-
}
172+
Stack stack=Contentstack.stack("apiKey","deliveryToken","environment_name");
173+
Query query=stack.contentType("content_type_uid").query();
174+
query.includeEmbeddedItems(); // include embedded items
175+
query.find(new QueryResultsCallBack(){
176+
@Override
177+
public void onCompletion(ResponseType responseType,QueryResult queryResult,Error error){
178+
if(error==null){
179+
List<Entry> entries=queryresult.getResultObjects();
180+
String[]keyPath={
181+
"rte_fieldUid","group.rteFieldUID"
182+
};
183+
for(Entry entry:entries){
184+
JSONObject jsonObject=entry.toJSON();
185+
Utils.jsonToHTML(jsonObject,keyPath,new Option());
186+
}
178187
}}
179-
});
188+
});
180189

181190
```

pom.xml

+3-3
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
<groupId>com.contentstack.sdk</groupId>
77
<artifactId>utils</artifactId>
8-
<version>1.2.2</version>
8+
<version>1.2.3</version>
99
<packaging>jar</packaging>
1010
<name>Contentstack-utils</name>
1111
<description>Java Utils SDK for Contentstack Content Delivery API, Contentstack is a headless CMS
@@ -30,7 +30,7 @@
3030
<maven-release-plugin.version>2.5.3</maven-release-plugin.version>
3131
<validation-version>2.0.1.Final</validation-version>
3232
<json-version>20230227</json-version>
33-
<spring-web-version>6.0.7</spring-web-version>
33+
<spring-web-version>6.0.11</spring-web-version>
3434
<org.apache.commons-text>1.10.0</org.apache.commons-text>
3535
</properties>
3636

@@ -237,4 +237,4 @@
237237
</plugins>
238238
</build>
239239

240-
</project>
240+
</project>

0 commit comments

Comments
 (0)