public abstract class MicrosoftTranslatorAPI
extends java.lang.Object
Makes the generic Microsoft Translator API calls. Different service classes then extend this to make the specific service calls.
Uses the AJAX Interface V2 - see: http://msdn.microsoft.com/en-us/library/ff512404.aspx
| Modifier and Type | Field and Description |
|---|---|
protected static java.lang.String |
apiKey |
protected static java.lang.String |
ENCODING |
protected static java.lang.String |
PARAM_APP_ID |
protected static java.lang.String |
PARAM_FROM_LANG |
protected static java.lang.String |
PARAM_LANGUAGE_CODES |
protected static java.lang.String |
PARAM_LOCALE |
protected static java.lang.String |
PARAM_SENTENCES_LANGUAGE |
protected static java.lang.String |
PARAM_SPOKEN_LANGUAGE |
protected static java.lang.String |
PARAM_TEXT_ARRAY |
protected static java.lang.String |
PARAM_TEXT_SINGLE |
protected static java.lang.String |
PARAM_TO_LANG |
| Constructor and Description |
|---|
MicrosoftTranslatorAPI() |
| Modifier and Type | Method and Description |
|---|---|
protected static java.lang.String |
buildStringArrayParam(java.lang.Object[] values) |
static java.lang.String |
getToken(java.lang.String subscriptionKey)
Gets the OAuth access token.
|
static void |
resetToken() |
protected static java.lang.Integer[] |
retrieveIntArray(java.net.URL url)
Fetches the JSON response, parses the JSON Response, returns the result of the request as an array of integers.
|
protected static java.lang.String |
retrieveString(java.net.URL url)
Fetches the JSON response, parses the JSON Response, returns the result of the request as a String.
|
protected static java.lang.String[] |
retrieveStringArr(java.net.URL url)
Fetches the JSON response, parses the JSON Response as an array of Strings
and returns the result of the request as a String Array.
|
protected static java.lang.String[] |
retrieveStringArr(java.net.URL url,
java.lang.String jsonProperty)
Fetches the JSON response, parses the JSON Response as an Array of JSONObjects,
retrieves the String value of the specified JSON Property, and returns the result of
the request as a String Array.
|
static void |
setContentType(java.lang.String pKey)
Sets the API key.
|
static void |
setHttpReferrer(java.lang.String pReferrer)
Sets the Http Referrer.
|
static void |
setKey(java.lang.String pKey)
Sets the API key.
|
static void |
setSubscriptionKey(java.lang.String pSubscriptionKey) |
protected static void |
validateServiceState() |
protected static final java.lang.String ENCODING
protected static java.lang.String apiKey
protected static final java.lang.String PARAM_APP_ID
protected static final java.lang.String PARAM_TO_LANG
protected static final java.lang.String PARAM_FROM_LANG
protected static final java.lang.String PARAM_TEXT_SINGLE
protected static final java.lang.String PARAM_TEXT_ARRAY
protected static final java.lang.String PARAM_SPOKEN_LANGUAGE
protected static final java.lang.String PARAM_SENTENCES_LANGUAGE
protected static final java.lang.String PARAM_LOCALE
protected static final java.lang.String PARAM_LANGUAGE_CODES
public static void setKey(java.lang.String pKey)
Note: Should ONLY be used with API Keys generated prior to March 31, 2012. All new applications should obtain a ClientId and Client Secret by following the guide at: http://msdn.microsoft.com/en-us/library/hh454950.aspx
pKey - The API key.public static void setContentType(java.lang.String pKey)
Note: Should ONLY be used with API Keys generated prior to March 31, 2012. All new applications should obtain a ClientId and Client Secret by following the guide at: http://msdn.microsoft.com/en-us/library/hh454950.aspx
pKey - The API key.public static void setSubscriptionKey(java.lang.String pSubscriptionKey)
public static void setHttpReferrer(java.lang.String pReferrer)
pReferrer - The HTTP client referrer.public static java.lang.String getToken(java.lang.String subscriptionKey)
throws java.lang.Exception
subscriptionKey - The Subscription keyjava.lang.Exceptionpublic static void resetToken()
protected static java.lang.String retrieveString(java.net.URL url)
throws java.lang.Exception
url - The URL to query for a String response.java.lang.Exception - on error.protected static java.lang.String[] retrieveStringArr(java.net.URL url,
java.lang.String jsonProperty)
throws java.lang.Exception
url - The URL to query for a String response.java.lang.Exception - on error.protected static java.lang.String[] retrieveStringArr(java.net.URL url)
throws java.lang.Exception
Overloaded to pass null as the JSON Property (assume only Strings instead of JSONObjects)
url - The URL to query for a String response.java.lang.Exception - on error.protected static java.lang.Integer[] retrieveIntArray(java.net.URL url)
throws java.lang.Exception
url - The URL to query for a String response.java.lang.Exception - on error.protected static void validateServiceState()
throws java.lang.Exception
java.lang.Exceptionprotected static java.lang.String buildStringArrayParam(java.lang.Object[] values)