Load just enough HTML to parse out the title.
This commit is contained in:
parent
a780f08ca8
commit
f2792ced87
@ -38,6 +38,9 @@ public class PageDownloader {
|
||||
String line = "";
|
||||
while ((line = reader.readLine()) != null) {
|
||||
output += line;
|
||||
if(TitleParser.retrieveTitle(output) != null) {
|
||||
return output;
|
||||
}
|
||||
}
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
@ -52,6 +55,4 @@ public class PageDownloader {
|
||||
}
|
||||
return output;
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,16 @@
|
||||
package in.sdqali.sharewithtitle;
|
||||
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
public class TitleParser {
|
||||
public static String retrieveTitle(String html) {
|
||||
Pattern p = Pattern.compile("<head>.*?<title>(.*?)</title>", Pattern.DOTALL);
|
||||
Matcher m = p.matcher(html);
|
||||
String title = null;
|
||||
while (m.find()) {
|
||||
title = m.group(1);
|
||||
}
|
||||
return title;
|
||||
}
|
||||
}
|
@ -45,14 +45,9 @@ public class TitleRetriever {
|
||||
|
||||
@Override
|
||||
protected void onPostExecute(String rawHtml) {
|
||||
Log.d("Share With Title", "On post: " + rawHtml);
|
||||
Pattern p = Pattern.compile("<head>.*?<title>(.*?)</title>.*?</head>", Pattern.DOTALL);
|
||||
Matcher m = p.matcher(rawHtml);
|
||||
String title;
|
||||
String title = TitleParser.retrieveTitle(rawHtml);
|
||||
String output = urlText;
|
||||
while (m.find()) {
|
||||
title = m.group(1);
|
||||
Log.d("Share With Title", "Title: " + title);
|
||||
if (title != null) {
|
||||
output = title + " " + urlText;
|
||||
}
|
||||
callback.onSuccess(output);
|
||||
|
Loading…
Reference in New Issue
Block a user