Package com.transifex.common
Class CDSHandler
java.lang.Object
com.transifex.common.CDSHandler
- Direct Known Subclasses:
CDSHandlerAndroid
CDSHandler enables pushing and pulling strings to/from the CDS.
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic interface
The callback to get the results offetchTranslations(String, Set, FetchCallback)
-
Field Summary
-
Constructor Summary
ConstructorDescriptionCDSHandler
(String[] localeCodes, String token, String secret, String csdHost) Creates a CDSHandler instance. -
Method Summary
Modifier and TypeMethodDescriptionfetchTranslations
(String localeCode, Set<String> tags) Fetches translations from CDS.void
fetchTranslations
(String localeCode, Set<String> tags, CDSHandler.FetchCallback callback) Fetches translations from CDS and supplies the raw input stream to the providedCDSHandler.FetchCallback
.pushSourceStrings
(LocaleData.TxPostData postData) Pushes the provided source strings to CDS and waits until the server completes the processing of the pushed strings.
-
Field Details
-
CDS_HOST
- See Also:
-
-
Constructor Details
-
CDSHandler
public CDSHandler(@Nullable String[] localeCodes, @NonNull String token, @Nullable String secret, @NonNull String csdHost) Creates a CDSHandler instance.- Parameters:
localeCodes
- An array of locale codes that can be downloaded from CDS. The source locale can also be included.token
- The API token to use for connecting to the CDS.secret
- The API secret to use for connecting to the CDS.csdHost
- The host of the Content Delivery Service.
-
-
Method Details
-
fetchTranslations
public void fetchTranslations(@Nullable String localeCode, @Nullable Set<String> tags, @NonNull CDSHandler.FetchCallback callback) Fetches translations from CDS and supplies the raw input stream to the providedCDSHandler.FetchCallback
.The method is synchronous and hence the callback is called during the method execution. The method should only run in a background thread.
- Parameters:
localeCode
- An optional locale to fetch translations from; if set tonull
, it will fetch translations for the locale codes provided in the constructor.tags
- An optional set of tags. If defined, only strings that have all of the given tags will be fetched.- See Also:
-
fetchTranslations
@NonNull public LocaleData.TranslationMap fetchTranslations(@Nullable String localeCode, @Nullable Set<String> tags) Fetches translations from CDS.The method is synchronous and should only run in a background thread.
- Parameters:
localeCode
- An optional locale to fetch translations from; if set tonull
, it will fetch translations for the locale codes provided in the constructor.tags
- An optional set of tags. If defined, only strings that have all of the given tags will be fetched.- Returns:
- A
LocaleData.TranslationMap
object that contains the translations for each locale. If an error occurs, some or all locales will be missing from the translation map.
-
pushSourceStrings
@Nullable public LocaleData.TxJobStatus pushSourceStrings(@NonNull LocaleData.TxPostData postData) throws javax.naming.TimeLimitExceededException Pushes the provided source strings to CDS and waits until the server completes the processing of the pushed strings.The method is synchronous.
- Parameters:
postData
- The data structure containing the source strings and the purge value.- Returns:
- A
LocaleData.TxJobStatus
object containing the server's response. The caller should check the job status and act according to the CDS documentation. The job status can be either"completed"
or"failed"
. If everything fails,null
is returned. - Throws:
javax.naming.TimeLimitExceededException
- When the server takes longer than 20 seconds to complete processing the job.
-