Skip to content

Commit 38ea55f

Browse files
pom version update
pom version update
1 parent 457f953 commit 38ea55f

File tree

9 files changed

+41
-38
lines changed

9 files changed

+41
-38
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
.project
66
.classpath
77
factoryConfiguration.json
8+
.vscode
9+
.vscode/
810

911
### Eclipse ###
1012
.metadata

README.md

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
11
# Contentstack-Utils-Java
22

3-
### Embedded Objects
3+
## Embedded Objects
44

55
This guide will help you get started with Contentstack Java Utils SDK to build apps powered by Contentstack.
66

77
### Prerequisites
8+
89
- JDK 8 or later
910
- Contentstack account
10-
- Latest version of IntelliJ IDEA / Eclipse / VSCode / Spring Tool Suite
11+
- Latest version of IntelliJ IDEA / eclipse / vscode / spring tool suite
1112

1213
### SDK Installation and Setup
14+
1315
To setup Utils SDK in your Java project, add the following dependency in the pom.xml file
1416

1517
```java
@@ -20,7 +22,6 @@ To setup Utils SDK in your Java project, add the following dependency in the pom
2022
</dependency>
2123
```
2224

23-
2425
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
2526

2627
```java
@@ -31,11 +32,14 @@ If you are using Contentstack Java SDK, then the Utils SDK is already imported i
3132
</dependency>
3233
```
3334

35+
Download [{latest}](https://search.maven.org/artifact/com.contentstack.sdk/utils) dependency here
3436

3537
### Usage
38+
3639
Let’s learn how you can use Utils SDK to render embedded items.
3740

3841
### Create Render Option
42+
3943
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:
4044

4145
```java
@@ -90,12 +94,12 @@ public class DefaultOptionClass implements Option {
9094

9195
```
9296

93-
9497
### Basic Queries
9598

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

98101
#### Fetch Embedded Item(s) from a Single Entry
102+
99103
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:
100104

101105
```java
@@ -116,14 +120,13 @@ entry.fetch(new EntryResultCallBack() {
116120
JSONObject jsonObject = entry.toJSON();
117121
Utils.render(jsonObject, keyPath, new Option());
118122
} else {
119-
[Error block] // handle your error
123+
[Error block] // handle your error
120124
}}
121125
});
122126
```
123127

124-
125-
126128
#### Fetch Embedded Item(s) from Multiple Entries
129+
127130
To get embedded items from multiple entries, you need to provide the stack API key, environment name, delivery token, and content type’s UID.
128131

129132
```java
@@ -145,12 +148,13 @@ query.find(new QueryResultsCallBack() {
145148
Utils.render(jsonObject, keyPath, new Option());
146149
}
147150
}else{
148-
[Error block] // handle your error
151+
[Error block] // handle your error
149152
}}
150153
});
151154
```
152155

153156
#### Render JSON RTE Contents
157+
154158
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:
155159

156160
```java
@@ -175,6 +179,3 @@ query.find(new QueryResultsCallBack() {
175179
});
176180

177181
```
178-
179-
180-

pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@
44

55
<groupId>com.contentstack.sdk</groupId>
66
<artifactId>utils</artifactId>
7-
<version>1.0.1-SNAPSHOT</version>
7+
<version>1.1.1-SNAPSHOT</version>
88
<packaging>jar</packaging>
99
<name>Contentstack-utils</name>
1010
<description>Java Utils SDK for Contentstack Content Delivery API, Contentstack is a headless CMS with an API-first approach</description>
1111
<url>https://www.***REMOVED***</url>
1212

1313
<properties>
14-
<util.version>1.0.1-SNAPSHOT</util.version>
14+
<util.version>1.1.1-SNAPSHOT</util.version>
1515
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
1616
<project.reporting.sourceEncoding>UTF-8</project.reporting.sourceEncoding>
1717
<maven.compiler.source>1.8</maven.compiler.source>

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

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import com.contentstack.utils.callbacks.Content;
44
import com.contentstack.utils.callbacks.Metadata;
5-
import com.contentstack.utils.callbacks.Options;
5+
import com.contentstack.utils.callbacks.Option;
66
import com.contentstack.utils.render.DefaultOption;
77
import org.json.JSONArray;
88
import org.json.JSONObject;
@@ -23,7 +23,7 @@ public class Utils {
2323
* @param renderObject
2424
* renderObject
2525
*/
26-
public static void render(JSONObject entryObj, String[] keyPath, Options renderObject) {
26+
public static void render(JSONObject entryObj, String[] keyPath, Option renderObject) {
2727
Content callback = content -> {
2828
if (content instanceof JSONArray) {
2929
JSONArray contentArray = (JSONArray) content;
@@ -107,7 +107,7 @@ private static void getContent(String[] arrayString, JSONObject entryObj, Conten
107107
* @param renderObject
108108
* renderObjects
109109
*/
110-
public void render(JSONArray jsonArray, String[] keyPath, Options renderObject) {
110+
public void render(JSONArray jsonArray, String[] keyPath, Option renderObject) {
111111
jsonArray.forEach(jsonObj -> render((JSONObject) jsonObj, keyPath, renderObject));
112112
}
113113

@@ -118,11 +118,11 @@ public void render(JSONArray jsonArray, String[] keyPath, Options renderObject)
118118
* String of the rte available for the embedding
119119
* @param embedObject
120120
* JSONObject to get the _embedded_object (_embedded_entries/_embedded_assets)
121-
* @param options
121+
* @param option
122122
* Options take takes input as (StyleType type, JSONObject embeddedObject)
123123
* @return String of rte with replaced tag
124124
*/
125-
public static String renderContent(String rteStringify, JSONObject embedObject, Options options) {
125+
public static String renderContent(String rteStringify, JSONObject embedObject, Option option) {
126126
final String[] sReplaceRTE = {rteStringify};
127127
Document html = Jsoup.parse(rteStringify);
128128
getEmbeddedObjects(html, metadata -> {
@@ -134,7 +134,7 @@ public static String renderContent(String rteStringify, JSONObject embedObject,
134134
}
135135
if (filteredContent.isPresent()) {
136136
JSONObject contentToPass = filteredContent.get();
137-
String stringOption = getStringOption(options, metadata, contentToPass);
137+
String stringOption = getStringOption(option, metadata, contentToPass);
138138
sReplaceRTE[0] = html.body().html().replace(metadata.getOuterHTML(), stringOption);
139139
}
140140
});
@@ -148,15 +148,15 @@ public static String renderContent(String rteStringify, JSONObject embedObject,
148148
* JSONArray of the rte available for the embedding
149149
* @param entryObject
150150
* JSONObject to get the _embedded_object (_embedded_entries/_embedded_assets)
151-
* @param options
151+
* @param option
152152
* Options take takes input as (StyleType type, JSONObject embeddedObject)
153153
* @return String of rte with replaced tag
154154
*/
155-
public static JSONArray renderContents(JSONArray rteArray, JSONObject entryObject, Options options) {
155+
public static JSONArray renderContents(JSONArray rteArray, JSONObject entryObject, Option option) {
156156
JSONArray jsonArrayRTEContent = new JSONArray();
157157
for (Object RTE : rteArray) {
158158
String stringify = (String) RTE;
159-
String renderContent = renderContent(stringify, entryObject, options);
159+
String renderContent = renderContent(stringify, entryObject, option);
160160
jsonArrayRTEContent.put(renderContent);
161161
}
162162
return jsonArrayRTEContent;
@@ -186,9 +186,9 @@ private static Optional<JSONObject> findEmbeddedItems(JSONObject jsonObject,
186186
return Optional.empty();
187187
}
188188

189-
private static String getStringOption(Options options, com.contentstack.utils.helper.Metadata metadata,
189+
private static String getStringOption(Option option, com.contentstack.utils.helper.Metadata metadata,
190190
JSONObject contentToPass) {
191-
String stringOption = options.renderOptions(contentToPass, metadata);
191+
String stringOption = option.renderOptions(contentToPass, metadata);
192192
if (stringOption == null) {
193193
DefaultOption defaultOptions = new DefaultOption();
194194
stringOption = defaultOptions.renderOptions(contentToPass, metadata);

src/main/java/com/contentstack/utils/callbacks/Options.java renamed to src/main/java/com/contentstack/utils/callbacks/Option.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@
33
import com.contentstack.utils.helper.Metadata;
44
import org.json.JSONObject;
55

6-
public interface Options {
6+
public interface Option {
77
String renderOptions(JSONObject embeddedObject, Metadata metadata);
88
}

src/main/java/com/contentstack/utils/render/DefaultOption.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
package com.contentstack.utils.render;
22

3-
import com.contentstack.utils.callbacks.Options;
3+
import com.contentstack.utils.callbacks.Option;
44
import com.contentstack.utils.helper.Metadata;
55
import org.json.JSONObject;
66

77
/**
88
* DefaultOptionsCallback
99
*/
10-
public class DefaultOption implements Options {
10+
public class DefaultOption implements Option {
1111

1212
/**
1313
* Accepts below params to provides defaults options

src/test/java/com/contentstack/utils/DefaultOptionTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ public void testEntryInline() {
6868
public void testEmbeddedLink() {
6969
Attributes attributes = new ReadResource().returnEntryAttributes(localJsonObj);
7070
final DefaultOption defaultOptions = new DefaultOption();
71-
Metadata metadata = new Metadata("TextTest", "entry", "6723673", "content_type_uid", "linked",
71+
Metadata metadata = new Metadata("TextTest", "entry", "6723673", "content_type_uid", "link",
7272
"outerHTMLTet", attributes);
7373
String result = defaultOptions.renderOptions(localJsonObj.optJSONObject("_embedded_items"), metadata);
7474
Assert.assertEquals("<a href=\"\"></a>", result);

src/test/java/com/contentstack/utils/TestEmbedStyleType.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ public void testAvailableStyleTypeInline() {
3434

3535
@Test
3636
public void testAvailableStyleTypeLink() {
37-
StyleType styleType = StyleType.LINKED;
38-
Assert.assertEquals("LINKED", styleType.name());
37+
StyleType styleType = StyleType.LINK;
38+
Assert.assertEquals("LINK", styleType.name());
3939
}
4040

4141
@Test

src/test/java/com/contentstack/utils/UtilTests.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package com.contentstack.utils;
22

3-
import com.contentstack.utils.callbacks.Options;
3+
import com.contentstack.utils.callbacks.Option;
44
import com.contentstack.utils.embedded.StyleType;
55
import com.contentstack.utils.render.DefaultOption;
66
import org.json.JSONArray;
@@ -30,7 +30,7 @@ public static void startUtilTests() throws IOException {
3030

3131
@Test
3232
public void testRenderFunction() {
33-
Options options = (embeddedObject, metadata) -> {
33+
Option option = (embeddedObject, metadata) -> {
3434
StyleType styleType = metadata.getStyleType();
3535
return null;
3636
};
@@ -42,7 +42,7 @@ public void testRenderFunction() {
4242

4343
@Test
4444
public void testWithoutKeyPath() {
45-
Options options = (embeddedObject, metadata) -> {
45+
Option option = (embeddedObject, metadata) -> {
4646
StyleType styleType = metadata.getStyleType();
4747
return null;
4848
};
@@ -101,8 +101,8 @@ public void testEmbeddedInlineEntry() {
101101
// statements of INLINE
102102
return null;
103103

104-
case LINKED:
105-
// statements of LINKED
104+
case LINK:
105+
// statements of LINK
106106
return null;
107107

108108
default:
@@ -112,7 +112,7 @@ public void testEmbeddedInlineEntry() {
112112
}
113113

114114
@Test
115-
public void testEmbeddedLinkedEntry() {
115+
public void testEmbeddedLinkEntry() {
116116
JSONArray rteArray = null;
117117
boolean available = localJsonObj.has("rich_text_editor");
118118
if (available) {
@@ -131,8 +131,8 @@ public void testEmbeddedLinkedEntry() {
131131
// Statements of INLINE
132132
return null;
133133

134-
case LINKED:
135-
// Statements of LINKED
134+
case LINK:
135+
// Statements of LINK
136136
return null;
137137

138138
default:

0 commit comments

Comments
 (0)