+ * This method allows you to specify one or more field names, and only those fields
+ * will be included in the returned asset data. This is useful for reducing response size
+ * and fetching only the required asset properties.
+ *
+ * @param fields Variable number of field names to be included in the asset response.
+ * @return The {@link Asset} instance for chaining further calls.
+ *
+ * Example:
+ *
+ * Asset asset = stack.asset("asset_uid");
+ * asset.assetFields("title", "filename");
+ *
+ */
+
+ public Asset setLocale(String locale) {
+ urlQueries.put("locale",locale);
+ return this;
+ }
+
+
+ /**
+ * Returns the locale (language) associated with this asset.
+ *
+ * @return The asset's locale as a {@link String}, or {@code null} if not set.
+ */
+ public String getLocale() {
+ return this.language;
+ }
+
/**
* Fetch.
*
diff --git a/src/main/java/com/contentstack/sdk/AssetLibrary.java b/src/main/java/com/contentstack/sdk/AssetLibrary.java
index 29fd0c4b..628ee1ab 100644
--- a/src/main/java/com/contentstack/sdk/AssetLibrary.java
+++ b/src/main/java/com/contentstack/sdk/AssetLibrary.java
@@ -151,6 +151,28 @@ public AssetLibrary includeMetadata() {
return this;
}
+ /**
+ * Sets the locale for asset queries.
+ * + * This method allows you to specify a locale code, so asset results are returned + * for a particular language or region. If not explicitly set, the default locale + * configured in the stack will be used. + * + * @param locale The locale code to filter assets by (e.g., "en-us"). + * @return The {@link AssetLibrary} instance for method chaining. + * + * Example: + *
+ * Stack stack = Contentstack.stack("apiKey", "deliveryToken", "environment");
+ * AssetLibrary assetLibrary = stack.assetLibrary();
+ * assetLibrary.setLocale("en-us");
+ *
+ */
+ public AssetLibrary setLocale(String locale) {
+ urlQueries.put("locale",locale);
+ return this;
+ }
+
/**
* Gets count.
*
diff --git a/src/main/java/com/contentstack/sdk/AssetModel.java b/src/main/java/com/contentstack/sdk/AssetModel.java
index 3aa4a122..5d0a0b1b 100644
--- a/src/main/java/com/contentstack/sdk/AssetModel.java
+++ b/src/main/java/com/contentstack/sdk/AssetModel.java
@@ -21,6 +21,7 @@ class AssetModel {
String fileSize;
String fileName;
String uploadUrl;
+ String language;
String[] tags;
JSONObject json;
int count = 0;
@@ -45,6 +46,7 @@ public AssetModel(JSONObject response, boolean isArray) {
fileSize = (String) json.opt("file_size");
fileName = (String) json.opt("filename");
uploadUrl = (String) json.opt("url");
+ language = (String) json.opt("locale");
if (json.opt("tags") instanceof JSONArray) {
extractTags();
}
diff --git a/src/main/java/com/contentstack/sdk/CSHttpConnection.java b/src/main/java/com/contentstack/sdk/CSHttpConnection.java
index b60532db..5d5e3549 100644
--- a/src/main/java/com/contentstack/sdk/CSHttpConnection.java
+++ b/src/main/java/com/contentstack/sdk/CSHttpConnection.java
@@ -268,17 +268,21 @@ private Response
- * Example
- *
+ * Example
+ *
- * The Get a single asset request fetches the latest version of a specific asset of a particular stack.
+ * The Get a single asset request fetches the latest version of a specific asset
+ * of a particular stack.
*
*
* @param uid uid of {@link Asset}
- * @return {@link Asset} instance Tip: If no version is mentioned, the request will retrieve the latest
- * published version of the asset. To retrieve a specific version, use the version parameter, keep the environment
- * parameter blank, and use the management token instead of the delivery token.
- *
- * Example Stack stack = contentstack.Stack("apiKey",
- * "deliveryToken", "environment"); Asset asset = stack.asset("assetUid");
+ * @return {@link Asset} instance Tip: If no version is mentioned, the
+ * request will retrieve the latest
+ * published version of the asset. To retrieve a specific version, use
+ * the version parameter, keep the environment
+ * parameter blank, and use the management token instead of the delivery
+ * token.
+ *
+ * Example Stack stack = contentstack.Stack("apiKey",
+ * "deliveryToken", "environment"); Asset asset =
+ * stack.asset("assetUid");
*/
public Asset asset(@NotNull String uid) {
Asset asset = new Asset(uid);
@@ -274,14 +333,15 @@ protected Asset asset() {
}
/**
- * The Get all assets request fetches the list of all the assets of a particular stack. It returns the content of
+ * The Get all assets request fetches the list of all the assets of a particular
+ * stack. It returns the content of
* each asset in JSON format.
*
* @return {@link AssetLibrary} asset library
- *
- * Example
- *
- *
+ * Example
+ *
+ *
- * If the result of the initial sync (or subsequent sync) contains more than 100 records, the response would
- * be paginated. It provides pagination token in the response. However, you do not have to use the
- * pagination token manually to get the next batch, the SDK does that automatically until the sync is
- * complete. Pagination token can be used in case you want to fetch only selected batches. It is especially
- * useful if the sync process is interrupted midway (due to network issues, etc.). In such cases, this token
- * can be used to restart the sync process from where it was interrupted.
- * You can use the sync token (that you receive after initial sync) to get the updated content next time.
- * The sync token fetches only the content that was added after your last sync, and the details of the
+ * You can use the sync token (that you receive after
+ * initial sync) to get the updated content next time.
+ * The sync token fetches only the content that was added
+ * after your last sync, and the details of the
* content that was deleted or updated.
- * You can also initialize sync with entries published after a specific date. To do this, use syncWithDate
+ * You can also initialize sync with entries published after
+ * a specific date. To do this, use syncWithDate
* and specify the start date as its value.
- * You can also initialize sync with entries of only specific content_type. To do this, use syncContentType
- * and specify the content type uid as its value. However, if you do this, the subsequent syncs will only
+ * You can also initialize sync with entries of only
+ * specific content_type. To do this, use syncContentType
+ * and specify the content type uid as its value. However,
+ * if you do this, the subsequent syncs will only
* include the entries of the specified content_type.
- * stack.syncContentType(String content_type, new SyncResultCallBack()){ }
+ * stack.syncContentType(String content_type, new
+ * SyncResultCallBack()){ }
*/
public void syncContentType(@NotNull String contentType, SyncResultCallBack syncCallBack) {
syncParams = new JSONObject();
@@ -493,12 +576,16 @@ public void syncContentType(@NotNull String contentType, SyncResultCallBack sync
* @param localeCode Select the required locale code.
* @param syncCallBack Returns callback for sync result.
*
- * You can also initialize sync with entries of only specific locales. To do this, use syncLocale and
- * specify the locale code as its value. However, if you do this, the subsequent syncs will only include the
+ * You can also initialize sync with entries of only
+ * specific locales. To do this, use syncLocale and
+ * specify the locale code as its value. However, if you do
+ * this, the subsequent syncs will only include the
* entries of the specified locales.
- * (asset_published, entry_published, asset_unpublished, asset_deleted, entry_unpublished, entry_deleted,
+ * (asset_published, entry_published, asset_unpublished,
+ * asset_deleted, entry_unpublished, entry_deleted,
* content_type_deleted.)
* @param syncCallBack returns callback for sync result.
*
- * Use the type parameter to get a specific type of content. You can pass one of the following values:
- * asset_published, entry_published, asset_unpublished, asset_deleted, entry_unpublished, entry_deleted,
- * content_type_deleted. If you do not specify any value, it will bring all published entries and published
+ * Use the type parameter to get a specific type of content.
+ * You can pass one of the following values:
+ * asset_published, entry_published, asset_unpublished,
+ * asset_deleted, entry_unpublished, entry_deleted,
+ * content_type_deleted. If you do not specify any value, it
+ * will bring all published entries and published
* assets.
*
- * You can also initialize sync with entries that satisfy multiple parameters. To do this, use syncWith and
- * specify the parameters. However, if you do this, the subsequent syncs will only include the entries of
+ * You can also initialize sync with entries that satisfy
+ * multiple parameters. To do this, use syncWith and
+ * specify the parameters. However, if you do this, the
+ * subsequent syncs will only include the entries of
* the specified parameters
+ *
* Stack stack = contentstack.Stack("apiKey", "deliveryToken", "environment"); ContentType contentType =
* stack.contentType("contentTypeUid")
*
@@ -233,7 +285,7 @@ public ContentType contentType(String contentTypeUid) {
return ct;
}
- public GlobalField globalField(@NotNull String globalFieldUid) {
+ public GlobalField globalField(@NotNull String globalFieldUid) {
this.globalField = globalFieldUid;
GlobalField gf = new GlobalField(globalFieldUid);
gf.setStackInstance(this);
@@ -247,19 +299,26 @@ public GlobalField globalField() {
}
/**
- * Assets refer to all the media files (images, videos, PDFs, audio files, and so on) uploaded in your Contentstack
- * repository for future use. These files can be attached and used in multiple entries.
+ * Assets refer to all the media files (images, videos, PDFs, audio files, and
+ * so on) uploaded in your Contentstack
+ * repository for future use. These files can be attached and used in multiple
+ * entries.
*
+ *
* Stack stack = contentstack.Stack("apiKey", "deliveryToken", "environment"); AssetLibrary assets =
* stack.assetLibrary();
*
@@ -301,7 +361,6 @@ public String getApplicationKey() {
return apiKey;
}
-
/**
* Returns deliveryToken of particular stack
*
@@ -335,8 +394,10 @@ public void setHeader(@NotNull String headerKey, @NotNull String headerValue) {
}
/**
- * Image transform string. This document is a detailed reference to Contentstack Image Delivery API and covers the
- * parameters that you can add to the URL to retrieve, manipulate (or convert) image files and display it to your
+ * Image transform string. This document is a detailed reference to Contentstack
+ * Image Delivery API and covers the
+ * parameters that you can add to the URL to retrieve, manipulate (or convert)
+ * image files and display it to your
* web or mobile properties.
*
* @param imageUrl the image url
@@ -361,11 +422,13 @@ protected String getQueryParam(Map
+ * If the result of the initial sync (or subsequent sync)
+ * contains more than 100 records, the response would
+ * be paginated. It provides pagination token in the
+ * response. However, you do not have to use the
+ * pagination token manually to get the next batch, the
+ * SDK does that automatically until the sync is
+ * complete. Pagination token can be used in case you
+ * want to fetch only selected batches. It is especially
+ * useful if the sync process is interrupted midway (due
+ * to network issues, etc.). In such cases, this token
+ * can be used to restart the sync process from where it
+ * was interrupted.
*
* Example :
- * Stack stack = contentstack.Stack("apiKey", "deliveryToken", "environment");
+ * Stack stack = contentstack.Stack("apiKey",
+ * "deliveryToken", "environment");
* stack.syncPaginationToken("paginationToken)
*/
public void syncPaginationToken(@NotNull String paginationToken, SyncResultCallBack syncCallBack) {
@@ -421,16 +494,21 @@ public void syncPaginationToken(@NotNull String paginationToken, SyncResultCallB
/**
* Sync token.
*
- * @param syncToken Use the sync token that you received in the previous/initial sync under this parameter.
+ * @param syncToken Use the sync token that you received in the
+ * previous/initial sync under this parameter.
* @param syncCallBack returns callback for sync result
*
*
* Example :
+ *
*
- * Stack stack = contentstack.Stack("apiKey", "deliveryToken", "environment");
+ * Stack stack = contentstack.Stack("apiKey", "deliveryToken", "environment");
+ *
*/
public void syncToken(String syncToken, SyncResultCallBack syncCallBack) {
syncParams = new JSONObject();
@@ -444,11 +522,13 @@ public void syncToken(String syncToken, SyncResultCallBack syncCallBack) {
* @param fromDate Enter the start date for initial sync.
* @param syncCallBack Returns callback for sync result.
*
*
* Example :
- * Stack stack = contentstack.Stack("apiKey", "deliveryToken", "environment");
+ * Stack stack = contentstack.Stack("apiKey",
+ * "deliveryToken", "environment");
* stack.syncFromDate("fromDate")
*/
public void syncFromDate(@NotNull Date fromDate, SyncResultCallBack syncCallBack) {
@@ -472,13 +552,16 @@ protected String convertUTCToISO(Date date) {
* @param contentType Provide uid of your content_type
* @param syncCallBack Returns callback for sync result.
*
*
* Example :
*
*
* Example :
- * Stack stack = contentstack.Stack("apiKey", "deliveryToken", "environment"); stack.syncContentType(String
+ * Stack stack = contentstack.Stack("apiKey",
+ * "deliveryToken", "environment");
+ * stack.syncContentType(String
* content_type, new SyncResultCallBack()){ }
*/
public void syncLocale(String localeCode, SyncResultCallBack syncCallBack) {
@@ -511,15 +598,20 @@ public void syncLocale(String localeCode, SyncResultCallBack syncCallBack) {
/**
* Sync publish type.
*
- * @param publishType Use the type parameter to get a specific type of content like
+ * @param publishType Use the type parameter to get a specific type of content
+ * like
*
*
@@ -545,14 +637,16 @@ public void syncPublishType(PublishType publishType, SyncResultCallBack syncCall
* @param publishType type as PublishType
* @param syncCallBack Callback
*
*
* Example :
*/
public void sync(String contentType, Date fromDate, String localeCode,
- PublishType publishType, SyncResultCallBack syncCallBack) {
+ PublishType publishType, SyncResultCallBack syncCallBack) {
String newDate = convertUTCToISO(fromDate);
syncParams = new JSONObject();
syncParams.put("init", true);
@@ -570,9 +664,8 @@ private void requestSync(final SyncResultCallBack callback) {
fetchFromNetwork(SYNCHRONISATION, syncParams, this.headers, callback);
}
- private void fetchContentTypes(String urlString, JSONObject
- contentTypeParam, HashMap