|
@ -21,23 +21,13 @@ import mthmmy.utils.Report; |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
* Singleton used for parsing a topic. |
|
|
* Singleton used for parsing a topic. |
|
|
* <p>Class contains the methods:<ul><li>{@link #parseUsersViewingThisTopic(Document, String)}</li> |
|
|
* <p>Class contains the methods:<ul><li>{@link #parseUsersViewingThisTopic(Document, |
|
|
* <li>{@link #parseCurrentPageIndex(Document, String)}</li> |
|
|
* gr.thmmy.mthmmy.utils.ParseHelpers.Language)}</li> |
|
|
* <li>{@link #parseTopicNumberOfPages(Document, int, String)}</li> |
|
|
* <li>{@link #parseCurrentPageIndex(Document, gr.thmmy.mthmmy.utils.ParseHelpers.Language)}</li> |
|
|
* <li>{@link #parseTopic(Document, String)}</li> |
|
|
* <li>{@link #parseTopicNumberOfPages(Document, int, gr.thmmy.mthmmy.utils.ParseHelpers.Language)}</li> |
|
|
* <li>{@link #defineLanguage(Document)}</li></ul></p> |
|
|
* <li>{@link #parseTopic(Document, gr.thmmy.mthmmy.utils.ParseHelpers.Language)}</li> |
|
|
*/ |
|
|
*/ |
|
|
class TopicParser { |
|
|
class TopicParser { |
|
|
//Languages supported
|
|
|
|
|
|
/** |
|
|
|
|
|
* String constant containing one of the supported forum languages |
|
|
|
|
|
*/ |
|
|
|
|
|
private static final String LANGUAGE_GREEK = "Greek"; |
|
|
|
|
|
/** |
|
|
|
|
|
* String constant containing one of the supported forum languages |
|
|
|
|
|
*/ |
|
|
|
|
|
private static final String LANGUAGE_ENGLISH = "English"; |
|
|
|
|
|
|
|
|
|
|
|
//User colors
|
|
|
//User colors
|
|
|
private static final int USER_COLOR_BLACK = Color.parseColor("#000000"); |
|
|
private static final int USER_COLOR_BLACK = Color.parseColor("#000000"); |
|
|
private static final int USER_COLOR_RED = Color.parseColor("#F44336"); |
|
|
private static final int USER_COLOR_RED = Color.parseColor("#F44336"); |
|
@ -56,13 +46,14 @@ class TopicParser { |
|
|
* Returns users currently viewing this topic. |
|
|
* Returns users currently viewing this topic. |
|
|
* |
|
|
* |
|
|
* @param topic {@link Document} object containing this topic's source code |
|
|
* @param topic {@link Document} object containing this topic's source code |
|
|
* @param language a String containing this topic's language set, this is returned by |
|
|
* @param language a {@link gr.thmmy.mthmmy.utils.ParseHelpers.Language} containing this topic's |
|
|
* {@link #defineLanguage(Document)} |
|
|
* language set, this is returned by |
|
|
|
|
|
* {@link gr.thmmy.mthmmy.utils.ParseHelpers.Language#getLanguage(Document)} |
|
|
* @return String containing html with the usernames of users |
|
|
* @return String containing html with the usernames of users |
|
|
* @see org.jsoup.Jsoup Jsoup |
|
|
* @see org.jsoup.Jsoup Jsoup |
|
|
*/ |
|
|
*/ |
|
|
static String parseUsersViewingThisTopic(Document topic, String language) { |
|
|
static String parseUsersViewingThisTopic(Document topic, ParseHelpers.Language language) { |
|
|
if (Objects.equals(language, LANGUAGE_GREEK)) |
|
|
if (language.is(ParseHelpers.Language.GREEK)) |
|
|
return topic.select("td:containsOwn(διαβάζουν αυτό το θέμα)").first().html(); |
|
|
return topic.select("td:containsOwn(διαβάζουν αυτό το θέμα)").first().html(); |
|
|
return topic.select("td:containsOwn(are viewing this topic)").first().html(); |
|
|
return topic.select("td:containsOwn(are viewing this topic)").first().html(); |
|
|
} |
|
|
} |
|
@ -71,15 +62,16 @@ class TopicParser { |
|
|
* Returns current topic's page index. |
|
|
* Returns current topic's page index. |
|
|
* |
|
|
* |
|
|
* @param topic {@link Document} object containing this topic's source code |
|
|
* @param topic {@link Document} object containing this topic's source code |
|
|
* @param language a String containing this topic's language set, this is returned by |
|
|
* @param language a {@link gr.thmmy.mthmmy.utils.ParseHelpers.Language} containing this topic's |
|
|
* {@link #defineLanguage(Document)} |
|
|
* language set, this is returned by |
|
|
|
|
|
* {@link gr.thmmy.mthmmy.utils.ParseHelpers.Language#getLanguage(Document)} |
|
|
* @return int containing parsed topic's current page |
|
|
* @return int containing parsed topic's current page |
|
|
* @see org.jsoup.Jsoup Jsoup |
|
|
* @see org.jsoup.Jsoup Jsoup |
|
|
*/ |
|
|
*/ |
|
|
static int parseCurrentPageIndex(Document topic, String language) { |
|
|
static int parseCurrentPageIndex(Document topic, ParseHelpers.Language language) { |
|
|
int parsedPage = 1; |
|
|
int parsedPage = 1; |
|
|
|
|
|
|
|
|
if (Objects.equals(language, LANGUAGE_GREEK)) { |
|
|
if (language.is(ParseHelpers.Language.GREEK)) { |
|
|
Elements findCurrentPage = topic.select("td:contains(Σελίδες:)>b"); |
|
|
Elements findCurrentPage = topic.select("td:contains(Σελίδες:)>b"); |
|
|
|
|
|
|
|
|
for (Element item : findCurrentPage) { |
|
|
for (Element item : findCurrentPage) { |
|
@ -108,15 +100,16 @@ class TopicParser { |
|
|
* |
|
|
* |
|
|
* @param topic {@link Document} object containing this topic's source code |
|
|
* @param topic {@link Document} object containing this topic's source code |
|
|
* @param currentPage an int containing current page of this topic |
|
|
* @param currentPage an int containing current page of this topic |
|
|
* @param language a String containing this topic's language set, this is returned by |
|
|
* @param language a {@link gr.thmmy.mthmmy.utils.ParseHelpers.Language} containing this topic's |
|
|
* {@link #defineLanguage(Document)} |
|
|
* language set, this is returned by |
|
|
|
|
|
* {@link gr.thmmy.mthmmy.utils.ParseHelpers.Language#getLanguage(Document)} |
|
|
* @return int containing the number of pages |
|
|
* @return int containing the number of pages |
|
|
* @see org.jsoup.Jsoup Jsoup |
|
|
* @see org.jsoup.Jsoup Jsoup |
|
|
*/ |
|
|
*/ |
|
|
static int parseTopicNumberOfPages(Document topic, int currentPage, String language) { |
|
|
static int parseTopicNumberOfPages(Document topic, int currentPage, ParseHelpers.Language language) { |
|
|
int returnPages = 1; |
|
|
int returnPages = 1; |
|
|
|
|
|
|
|
|
if (Objects.equals(language, LANGUAGE_GREEK)) { |
|
|
if (language.is(ParseHelpers.Language.GREEK)) { |
|
|
Elements pages = topic.select("td:contains(Σελίδες:)>a.navPages"); |
|
|
Elements pages = topic.select("td:contains(Σελίδες:)>a.navPages"); |
|
|
|
|
|
|
|
|
if (pages.size() != 0) { |
|
|
if (pages.size() != 0) { |
|
@ -145,19 +138,20 @@ class TopicParser { |
|
|
* This method parses all the information of a topic and it's posts. |
|
|
* This method parses all the information of a topic and it's posts. |
|
|
* |
|
|
* |
|
|
* @param topic {@link Document} object containing this topic's source code |
|
|
* @param topic {@link Document} object containing this topic's source code |
|
|
* @param language a String containing this topic's language set, this is returned by |
|
|
* @param language a {@link gr.thmmy.mthmmy.utils.ParseHelpers.Language} containing this topic's |
|
|
* {@link #defineLanguage(Document)} |
|
|
* language set, this is returned by |
|
|
|
|
|
* {@link gr.thmmy.mthmmy.utils.ParseHelpers.Language#getLanguage(Document)} |
|
|
* @return {@link ArrayList} of {@link Post}s |
|
|
* @return {@link ArrayList} of {@link Post}s |
|
|
* @see org.jsoup.Jsoup Jsoup |
|
|
* @see org.jsoup.Jsoup Jsoup |
|
|
*/ |
|
|
*/ |
|
|
static ArrayList<Post> parseTopic(Document topic, String language) { |
|
|
static ArrayList<Post> parseTopic(Document topic, ParseHelpers.Language language) { |
|
|
//Method's variables
|
|
|
//Method's variables
|
|
|
final int NO_INDEX = -1; |
|
|
final int NO_INDEX = -1; |
|
|
ArrayList<Post> parsedPostsList = new ArrayList<>(); |
|
|
ArrayList<Post> parsedPostsList = new ArrayList<>(); |
|
|
Elements postRows; |
|
|
Elements postRows; |
|
|
|
|
|
|
|
|
//Each row is a post
|
|
|
//Each row is a post
|
|
|
if (Objects.equals(language, LANGUAGE_GREEK)) |
|
|
if (language.is(ParseHelpers.Language.GREEK)) |
|
|
postRows = topic.select("form[id=quickModForm]>table>tbody>tr:matches(στις)"); |
|
|
postRows = topic.select("form[id=quickModForm]>table>tbody>tr:matches(στις)"); |
|
|
else { |
|
|
else { |
|
|
postRows = topic.select("form[id=quickModForm]>table>tbody>tr:matches(on)"); |
|
|
postRows = topic.select("form[id=quickModForm]>table>tbody>tr:matches(on)"); |
|
@ -213,7 +207,7 @@ class TopicParser { |
|
|
|
|
|
|
|
|
//Language dependent parsing
|
|
|
//Language dependent parsing
|
|
|
Element userName; |
|
|
Element userName; |
|
|
if (Objects.equals(language, LANGUAGE_GREEK)) { |
|
|
if (language.is(ParseHelpers.Language.GREEK)) { |
|
|
//Finds username and profile's url
|
|
|
//Finds username and profile's url
|
|
|
userName = thisRow.select("a[title^=Εμφάνιση προφίλ του μέλους]").first(); |
|
|
userName = thisRow.select("a[title^=Εμφάνιση προφίλ του μέλους]").first(); |
|
|
if (userName == null) { //Deleted profile
|
|
|
if (userName == null) { //Deleted profile
|
|
@ -343,7 +337,7 @@ class TopicParser { |
|
|
Element usersExtraInfo = userName.parent().nextElementSibling(); //Get sibling "div"
|
|
|
Element usersExtraInfo = userName.parent().nextElementSibling(); //Get sibling "div"
|
|
|
List<String> infoList = Arrays.asList(usersExtraInfo.html().split("<br>")); |
|
|
List<String> infoList = Arrays.asList(usersExtraInfo.html().split("<br>")); |
|
|
|
|
|
|
|
|
if (Objects.equals(language, LANGUAGE_GREEK)) { |
|
|
if (language.is(ParseHelpers.Language.GREEK)) { |
|
|
for (String line : infoList) { |
|
|
for (String line : infoList) { |
|
|
if (line.contains("Μηνύματα:")) { |
|
|
if (line.contains("Μηνύματα:")) { |
|
|
postsLineIndex = infoList.indexOf(line); |
|
|
postsLineIndex = infoList.indexOf(line); |
|
@ -423,23 +417,6 @@ class TopicParser { |
|
|
return parsedPostsList; |
|
|
return parsedPostsList; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* Returns one of the supported forum languages. |
|
|
|
|
|
* <p>Forum supports: <ul><li>{@link #LANGUAGE_ENGLISH}</li> |
|
|
|
|
|
* <li>{@link #LANGUAGE_GREEK}</li></ul></p> |
|
|
|
|
|
* |
|
|
|
|
|
* @param topic {@link Document} object containing this topic's source code |
|
|
|
|
|
* @return String containing the language of a topic |
|
|
|
|
|
* @see org.jsoup.Jsoup Jsoup |
|
|
|
|
|
*/ |
|
|
|
|
|
static String defineLanguage(Document topic) { |
|
|
|
|
|
if (topic.select("h3").text().contains("Καλώς ορίσατε")) { |
|
|
|
|
|
return LANGUAGE_GREEK; |
|
|
|
|
|
} else { //Default is english (eg. guest's language)
|
|
|
|
|
|
return LANGUAGE_ENGLISH; |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
* Returns the color of a user according to user's rank on forum. |
|
|
* Returns the color of a user according to user's rank on forum. |
|
|
* |
|
|
* |
|
|