public abstract class MicrosoftTranslatorAPI<RQ,RP>
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 |
HTTP_GET |
protected static java.lang.String |
HTTP_POST |
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_SCOPE |
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 |
protected static java.lang.String |
protocol |
protected static java.lang.String |
PROTOCOL_HTTP |
protected static java.lang.String |
PROTOCOL_HTTPS |
| Constructor and Description |
|---|
MicrosoftTranslatorAPI() |
| Modifier and Type | Method and Description |
|---|---|
protected static java.lang.String |
buildStringArrayParam(java.lang.Object[] values) |
protected static java.lang.String |
getProtocol()
Get current protocol.
|
static java.lang.String |
getToken(java.lang.String subscriptionKey)
Gets the OAuth access token.
|
static boolean |
isUsingSSL()
Is using SSL protocol now.
|
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 RP |
retrieveResponseV3(java.net.URL url,
java.lang.String httpMethod,
RQ requestBody,
TypeReference<RP> type) |
protected RP |
retrieveResponseV3(java.net.URL url,
java.lang.String httpMethod,
RQ requestBody,
TypeReference<RP> type,
java.util.HashMap<java.lang.String,java.lang.String> headers) |
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) |
static void |
setUsingSSL(boolean usingSSL)
Set using SSL protocol.
|
protected java.lang.String |
toJsonString(java.lang.Object object) |
protected static void |
validateServiceState() |
protected static final java.lang.String PROTOCOL_HTTP
protected static final java.lang.String PROTOCOL_HTTPS
protected static final java.lang.String HTTP_GET
protected static final java.lang.String HTTP_POST
protected static final java.lang.String ENCODING
protected static java.lang.String protocol
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
protected static final java.lang.String PARAM_SCOPE
public static void setUsingSSL(boolean usingSSL)
usingSSL - Using SSL protocol.protected static java.lang.String getProtocol()
public static boolean isUsingSSL()
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 java.lang.String toJsonString(java.lang.Object object)
protected RP retrieveResponseV3(java.net.URL url, java.lang.String httpMethod, RQ requestBody, TypeReference<RP> type) throws java.lang.Exception
java.lang.Exceptionprotected RP retrieveResponseV3(java.net.URL url, java.lang.String httpMethod, RQ requestBody, TypeReference<RP> type, java.util.HashMap<java.lang.String,java.lang.String> headers) throws java.lang.Exception
java.lang.Exceptionprotected 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)