You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The Kontent Delivery Java SDK is a client library used for retrieving content from [Kontent by Kentico](https://kontent.ai).
@@ -16,7 +17,7 @@ You can use the SDK in the form of a Apache Maven package from [Maven Central](h
16
17
17
18
### Gradle
18
19
19
-
```groovy
20
+
```groovy
20
21
21
22
repositories {
22
23
mavenCentral()
@@ -31,14 +32,15 @@ dependencies {
31
32
32
33
### Maven
33
34
34
-
```xml
35
+
```xml
35
36
<dependency>
36
37
<groupId>com.github.kentico</groupId>
37
-
<artifactId>kontent-delivery</artifactId>
38
-
<version>[0.0.2-beta.12,)</version>
38
+
39
+
<artifactId>kontent-delivery</artifactId>
40
+
<version>[0.0.2-beta.12,)</version>
39
41
<type>pom</type>
40
-
</dependency>
41
-
```
42
+
</dependency>
43
+
```
42
44
43
45
> You may want to change version specification - `[0.0.2-beta.12,)` - from [range one](https://cwiki.apache.org/confluence/display/MAVENOLD/Dependency+Mediation+and+Conflict+Resolution#DependencyMediationandConflictResolution-DependencyVersionRanges) to specific one (i.e. `0.0.2-beta.12`).
44
46
@@ -48,10 +50,10 @@ The `DeliveryClient` class is the main class of the SDK. Using this class, you c
48
50
49
51
To create an instance of the class, you need to provide a [project ID](https://docs.kontent.ai/tutorials/develop-apps/get-content/getting-content#a-getting-content-items).
50
52
51
-
```java
52
-
// Initializes an instance of the DeliveryClient client
You can also provide the project ID and other parameters by passing the [`DeliveryOptions`](./src/main/java/kentico/kontent/delivery/DeliveryOptions.java) object to the class constructor. The `DeliveryOptions` object can be used to set the following parameters:
57
59
@@ -68,15 +70,16 @@ You can also provide the project ID and other parameters by passing the [`Delive
68
70
69
71
The `DeliveryOptions.builder()` can also simplify creating a `DeliveryClient`:
Once you create a `DeliveryClient`, you can start querying your project repository by calling methods on the client instance. See [Basic querying](#basic-querying) for details.
82
85
@@ -91,21 +94,21 @@ DeliveryClient client = new DeliveryClient(
91
94
"YOUR_PROJECT_ID",
92
95
"YOUR_PREVIEW_API_KEY"
93
96
);
94
-
```
97
+
```
95
98
96
99
For more details, see [Previewing unpublished content using the Delivery API](https://docs.kontent.ai/tutorials/write-and-collaborate/preview-content/previewing-unpublished-content).
97
100
98
101
## Basic querying
99
102
100
103
Once you have a `DeliveryClient` instance, you can start querying your project repository by calling methods on the instance.
As you may have noticed from the example `DeliveryClient` is returning [`CompletionStage<T>`](https://docs.oracle.com/javase/8/docs/api/java/util/concurrent/CompletionStage.html) that allows you to chain the requests, perform filtering, data transformation, etc.
@@ -172,27 +175,30 @@ When retrieving a list of content items, you get an instance of the `ContentItem
172
175
173
176
The `ContentItem` class provides the following:
174
177
175
-
-`getSystem()` returns a `System` object with metadata such as code name, display name, type, collection, or sitemap location.
178
+
-`getSystem()` returns a `System` object with metadata such as code name, display name, type, collection, sitemap location, or workflow step.
176
179
-`getElements()` returns a Map containing all the elements included in the response keyed by code names.
177
180
- Methods for easier access to certain types of content elements such as linked items, or assets.
178
181
179
182
## Getting content item properties
180
183
181
184
You can access information about a content item (i.e., its ID, codename, name, location in sitemap, date of last modification, its collection codename, and its content type codename) by using the `System` object.
182
185
183
-
```java
184
-
// Retrieves name of an article content item
185
-
articleItem.getSystem().getName()
186
-
187
-
// Retrieves codename of an article content item
188
-
articleItem.getSystem().getCodename()
189
-
190
-
// Retrieves codename of the collection of an article content item
191
-
articleItem.getSystem().getCollection()
192
-
193
-
// Retrieves codename of the content type of an article content item
194
-
articleItem.getSystem().getType()
195
-
```
186
+
```java
187
+
// Retrieves name of an article content item
188
+
articleItem.getSystem().getName()
189
+
190
+
// Retrieves codename of an article content item
191
+
articleItem.getSystem().getCodename()
192
+
193
+
// Retrieves codename of the collection of an article content item
194
+
articleItem.getSystem().getCollection()
195
+
196
+
// Retrieves codename of the content type of an article content item
197
+
articleItem.getSystem().getType()
198
+
199
+
// Retrieves codename of the workflow step of an article content item
200
+
articleItem.getSystem().getWorkflowStep()
201
+
```
196
202
197
203
## Getting element values
198
204
@@ -202,37 +208,37 @@ The SDK provides methods for retrieving content from content elements such as As
202
208
203
209
For text elements, you can use the `getString` method.
204
210
205
-
```java
206
-
// Retrieves an article text from the 'body_copy' Text element
207
-
articleItem.getString("body_copy")
208
-
```
211
+
```java
212
+
// Retrieves an article text from the 'body_copy' Text element
213
+
articleItem.getString("body_copy")
214
+
```
209
215
210
216
The Rich text element can contain links to other content items within your project. See [Resolving links to content items](https://github.com/Kentico/kontent-delivery-sdk-java/wiki/Resolving-links-to-content-items) for more details.
To get a list of options defined in a Multiple choice content element, you first need to retrieve the content element itself. For this purpose, you can use the `getContentTypeElement` method, which takes the codename of a content type and the codename of a content element.
222
228
223
-
```java
224
-
// Retrieves the 'processing' element of the 'coffee' content type
225
-
MultipleChoiceElement element = (MultipleChoiceElement) client.getContentTypeElement("coffee", "processing");
226
-
```
229
+
```java
230
+
// Retrieves the 'processing' element of the 'coffee' content type
231
+
MultipleChoiceElement element = (MultipleChoiceElement) client.getContentTypeElement("coffee", "processing");
232
+
```
227
233
228
234
After you retrieve the Multiple choice element, you can work with its list of options. Each option has the following methods:
229
235
230
236
Method | Description | Example
231
-
---------|----------|---------
232
-
getName() | The display name of the option. | `Dry (Natural)`
233
-
getCodename() | The codename of the option. | `dry__natural_
237
+
---------|----------|---------
238
+
getName() | The display name of the option. | `Dry (Natural)`
239
+
getCodename() | The codename of the option. | `dry__natural_
234
240
235
-
To put the element's options in a list, you can use the following code:
241
+
To put the element's options in a list, you can use the following code:
236
242
237
243
```java
238
244
List<SelectListItem> items =newList<>();
@@ -243,28 +249,28 @@ for (Option option : element.getOptions()) {
To use this SDK for [Android](https://developer.android.com/) development, you can use any approach compatible with [Java CompletionStage API](https://docs.oracle.com/javase/8/docs/api/java/util/concurrent/CompletionStage.html). Most common is to use [Kotlin coroutines](https://kotlinlang.org/docs/reference/coroutines-overview.html) for Android applications written in Kotlin and [Java RX](https://github.com/ReactiveX/RxJava) for Android applications written in Java. Both of these approaches are showcased in this repository:
To use this SDK for [Android](https://developer.android.com/) development, you can use any approach compatible with [Java CompletionStage API](https://docs.oracle.com/javase/8/docs/api/java/util/concurrent/CompletionStage.html). Most common is to use [Kotlin coroutines](https://kotlinlang.org/docs/reference/coroutines-overview.html) for Android applications written in Kotlin and [Java RX](https://github.com/ReactiveX/RxJava) for Android applications written in Java. Both of these approaches are showcased in this repository:
You need to instantiate the Delivery client with the constructor that disables the template engine. The template engine is meant to be used with the web platform only. For Android development, use the constructor `DeliveryClient#DeliveryClient(DeliveryOptions, TemplateEngineConfig)` and set the second parameter to `null`.
See it [used in a sample app](../sample-app-android/src/main/java/com/github/kentico/delivery_android_sample/data/source/DeliveryClientProvider.java)).
283
289
@@ -308,7 +314,6 @@ We would like to express our thanks to the following people who contributed and
0 commit comments