|
|
@ -42,7 +42,6 @@ import org.json.JSONObject;
|
|
|
|
|
|
|
|
|
|
|
|
import java.io.IOException;
|
|
|
|
import java.io.IOException;
|
|
|
|
import java.io.InputStream;
|
|
|
|
import java.io.InputStream;
|
|
|
|
import java.net.HttpURLConnection;
|
|
|
|
|
|
|
|
import java.net.URL;
|
|
|
|
import java.net.URL;
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.List;
|
|
|
@ -50,6 +49,8 @@ import java.util.Locale;
|
|
|
|
import java.util.regex.Matcher;
|
|
|
|
import java.util.regex.Matcher;
|
|
|
|
import java.util.regex.Pattern;
|
|
|
|
import java.util.regex.Pattern;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import javax.net.ssl.HttpsURLConnection;
|
|
|
|
|
|
|
|
|
|
|
|
public class LanguageTool {
|
|
|
|
public class LanguageTool {
|
|
|
|
static final String LT_URI = "https://api.languagetool.org/v2/";
|
|
|
|
static final String LT_URI = "https://api.languagetool.org/v2/";
|
|
|
|
static final String LT_URI_PLUS = "https://api.languagetoolplus.com/v2/";
|
|
|
|
static final String LT_URI_PLUS = "https://api.languagetoolplus.com/v2/";
|
|
|
@ -87,7 +88,7 @@ public class LanguageTool {
|
|
|
|
Log.i("LT uri=" + uri);
|
|
|
|
Log.i("LT uri=" + uri);
|
|
|
|
|
|
|
|
|
|
|
|
URL url = new URL(uri.toString());
|
|
|
|
URL url = new URL(uri.toString());
|
|
|
|
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
|
|
|
|
HttpsURLConnection connection = (HttpsURLConnection) url.openConnection();
|
|
|
|
connection.setRequestMethod("GET");
|
|
|
|
connection.setRequestMethod("GET");
|
|
|
|
connection.setDoOutput(false);
|
|
|
|
connection.setDoOutput(false);
|
|
|
|
connection.setReadTimeout(LT_TIMEOUT * 1000);
|
|
|
|
connection.setReadTimeout(LT_TIMEOUT * 1000);
|
|
|
@ -248,7 +249,7 @@ public class LanguageTool {
|
|
|
|
Log.i("LT uri=" + uri + " request=" + request);
|
|
|
|
Log.i("LT uri=" + uri + " request=" + request);
|
|
|
|
|
|
|
|
|
|
|
|
URL url = new URL(uri.toString());
|
|
|
|
URL url = new URL(uri.toString());
|
|
|
|
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
|
|
|
|
HttpsURLConnection connection = (HttpsURLConnection) url.openConnection();
|
|
|
|
connection.setRequestMethod("POST");
|
|
|
|
connection.setRequestMethod("POST");
|
|
|
|
connection.setDoOutput(true);
|
|
|
|
connection.setDoOutput(true);
|
|
|
|
connection.setReadTimeout(LT_TIMEOUT * 1000);
|
|
|
|
connection.setReadTimeout(LT_TIMEOUT * 1000);
|
|
|
@ -327,7 +328,7 @@ public class LanguageTool {
|
|
|
|
Log.i("LT uri=" + uri + " request=" + request);
|
|
|
|
Log.i("LT uri=" + uri + " request=" + request);
|
|
|
|
|
|
|
|
|
|
|
|
URL url = new URL(uri.toString());
|
|
|
|
URL url = new URL(uri.toString());
|
|
|
|
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
|
|
|
|
HttpsURLConnection connection = (HttpsURLConnection) url.openConnection();
|
|
|
|
connection.setRequestMethod("POST");
|
|
|
|
connection.setRequestMethod("POST");
|
|
|
|
connection.setDoOutput(true);
|
|
|
|
connection.setDoOutput(true);
|
|
|
|
connection.setReadTimeout(LT_TIMEOUT * 1000);
|
|
|
|
connection.setReadTimeout(LT_TIMEOUT * 1000);
|
|
|
@ -378,7 +379,7 @@ public class LanguageTool {
|
|
|
|
Log.i("LT uri=" + uri);
|
|
|
|
Log.i("LT uri=" + uri);
|
|
|
|
|
|
|
|
|
|
|
|
URL url = new URL(uri.toString());
|
|
|
|
URL url = new URL(uri.toString());
|
|
|
|
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
|
|
|
|
HttpsURLConnection connection = (HttpsURLConnection) url.openConnection();
|
|
|
|
connection.setRequestMethod("GET");
|
|
|
|
connection.setRequestMethod("GET");
|
|
|
|
connection.setDoOutput(false);
|
|
|
|
connection.setDoOutput(false);
|
|
|
|
connection.setReadTimeout(LT_TIMEOUT * 1000);
|
|
|
|
connection.setReadTimeout(LT_TIMEOUT * 1000);
|
|
|
@ -460,9 +461,9 @@ public class LanguageTool {
|
|
|
|
return (!TextUtils.isEmpty(lt_user) && !TextUtils.isEmpty(lt_key));
|
|
|
|
return (!TextUtils.isEmpty(lt_user) && !TextUtils.isEmpty(lt_key));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private static void checkStatus(HttpURLConnection connection) throws IOException {
|
|
|
|
private static void checkStatus(HttpsURLConnection connection) throws IOException {
|
|
|
|
int status = connection.getResponseCode();
|
|
|
|
int status = connection.getResponseCode();
|
|
|
|
if (status != HttpURLConnection.HTTP_OK) {
|
|
|
|
if (status != HttpsURLConnection.HTTP_OK) {
|
|
|
|
String error = "Error " + status + ": " + connection.getResponseMessage();
|
|
|
|
String error = "Error " + status + ": " + connection.getResponseMessage();
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
InputStream is = connection.getErrorStream();
|
|
|
|
InputStream is = connection.getErrorStream();
|
|
|
|