Increase version of jsoup and import Link headers

Closes #1.
This commit is contained in:
Peter Stuifzand 2018-02-28 17:13:53 +01:00
parent 1c67c20bc9
commit 3cea3f2e7b
3 changed files with 47 additions and 14 deletions

View File

@ -43,7 +43,7 @@ dependencies {
annotationProcessor "android.arch.lifecycle:compiler:1.1.0" annotationProcessor "android.arch.lifecycle:compiler:1.1.0"
// Java8 support for Lifecycles // Java8 support for Lifecycles
implementation 'android.arch.lifecycle:common-java8:1.1.0' implementation 'android.arch.lifecycle:common-java8:1.1.0'
implementation 'org.jsoup:jsoup:1.10.1' implementation 'org.jsoup:jsoup:1.11.2'
implementation 'com.google.code.gson:gson:2.8.2' implementation 'com.google.code.gson:gson:2.8.2'
testImplementation 'junit:junit:4.12' testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.1' androidTestImplementation 'com.android.support.test:runner:1.0.1'

View File

@ -8,12 +8,19 @@ import android.os.AsyncTask;
import android.os.Bundle; import android.os.Bundle;
import android.util.Log; import android.util.Log;
import org.jsoup.Connection;
import org.jsoup.Jsoup; import org.jsoup.Jsoup;
import org.jsoup.nodes.Document; import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element; import org.jsoup.nodes.Element;
import org.jsoup.select.Elements; import org.jsoup.select.Elements;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.regex.MatchResult;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class WebsigninTask extends AsyncTask<String, Void, Bundle> { public class WebsigninTask extends AsyncTask<String, Void, Bundle> {
@ -33,27 +40,53 @@ public class WebsigninTask extends AsyncTask<String, Void, Bundle> {
@Override @Override
protected Bundle doInBackground(String... strings) { protected Bundle doInBackground(String... strings) {
Log.i("micropub", "Starting WebsigninTask.doInBackground");
Bundle bundle = new Bundle(); Bundle bundle = new Bundle();
HashMap<String,String> linkHeaders = new HashMap<>();
try { try {
bundle.putString(ME, strings[0]); bundle.putString(ME, strings[0]);
Document doc = Jsoup.connect(strings[0]).get(); Connection conn = Jsoup.connect(strings[0]);
Elements links = doc.select("link"); Document doc = conn.get();
for (Element link : links) { Connection.Response resp = conn.response();
String rel = link.attr("rel");
if (rel.equals("authorization_endpoint")) { List<String> headers = resp.headers("Link");
bundle.putString(rel, link.attr("href")); Pattern linkParser = Pattern.compile("<([^>]+)>;\\s+rel=\"([^\"]+)\"");
}
else if (rel .equals("token_endpoint")) { for (String header : headers) {
bundle.putString(rel, link.attr("href")); Log.d("micropub", header);
} Matcher matcher = linkParser.matcher(header);
else if (rel.equals("micropub")) { while (matcher.find()) {
bundle.putString(rel, link.attr("href")); MatchResult results = matcher.toMatchResult();
String url = results.group(1);
String rel = results.group(2);
Log.d("micropub", "Found url=" + url + " and rel=" + rel);
if (!rel.isEmpty() && !linkHeaders.containsKey(rel)) {
linkHeaders.put(rel, url);
}
} }
} }
Elements links = doc.select("link");
for (Element link : links) {
String rel = link.attr("rel");
if (!rel.isEmpty() && !linkHeaders.containsKey(rel)) {
linkHeaders.put(rel, link.attr("href"));
}
}
} catch (IOException e) { } catch (IOException e) {
return bundle; return bundle;
} }
String[] rels = new String[]{"authorization_endpoint","token_endpoint","micropub"};
for (String rel : rels) {
if (linkHeaders.containsKey(rel)) {
bundle.putString(rel, linkHeaders.get(rel));
}
}
Log.i("micropub", bundle.toString()); Log.i("micropub", bundle.toString());
return bundle; return bundle;
} }

View File

@ -71,7 +71,7 @@
app:counterEnabled="true" app:counterEnabled="true"
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/editInReplyToLayout"> app:layout_constraintTop_toBottomOf="@+id/editInReplyToLayout">
<android.support.design.widget.TextInputEditText <android.support.design.widget.TextInputEditText
android:id="@+id/content" android:id="@+id/content"