Add a util method to clean a string
This commit is contained in:
parent
1a38155c01
commit
7946b2a62d
@ -13,7 +13,6 @@ import com.readrops.readropslibrary.utils.ParseException;
|
||||
|
||||
import org.joda.time.DateTimeZone;
|
||||
import org.joda.time.LocalDateTime;
|
||||
import org.jsoup.Jsoup;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@ -72,7 +71,7 @@ public final class ItemMatcher {
|
||||
newItem.setContent(item.getContent()); // Jsoup.clean(item.getContent(), Whitelist.relaxed())
|
||||
newItem.setDescription(item.getDescription());
|
||||
newItem.setGuid(item.getGuid());
|
||||
newItem.setTitle(Jsoup.parse(item.getTitle()).text().trim());
|
||||
newItem.setTitle(Utils.cleanText(item.getTitle()));
|
||||
|
||||
try {
|
||||
newItem.setPubDate(DateUtils.stringToLocalDateTime(item.getDate()));
|
||||
@ -117,13 +116,14 @@ public final class ItemMatcher {
|
||||
dbItem.setContent(item.getContent()); // Jsoup.clean(item.getContent(), Whitelist.relaxed())
|
||||
dbItem.setDescription(item.getSummary());
|
||||
dbItem.setGuid(item.getId());
|
||||
dbItem.setTitle(Jsoup.parse(item.getTitle()).text().trim());
|
||||
dbItem.setTitle(Utils.cleanText(item.getTitle()));
|
||||
|
||||
try {
|
||||
dbItem.setPubDate(DateUtils.stringToLocalDateTime(item.getUpdated()));
|
||||
} catch (Exception e) {
|
||||
throw new ParseException();
|
||||
}
|
||||
|
||||
dbItem.setLink(item.getUrl());
|
||||
|
||||
dbItem.setFeedId(feed.getId());
|
||||
@ -146,7 +146,7 @@ public final class ItemMatcher {
|
||||
dbItem.setContent(item.getContent()); // Jsoup.clean(item.getContent(), Whitelist.relaxed())
|
||||
dbItem.setDescription(item.getSummary());
|
||||
dbItem.setGuid(item.getId());
|
||||
dbItem.setTitle(Jsoup.parse(item.getTitle()).text().trim());
|
||||
dbItem.setTitle(Utils.cleanText(item.getTitle()));
|
||||
|
||||
try {
|
||||
dbItem.setPubDate(DateUtils.stringToLocalDateTime(item.getPubDate()));
|
||||
|
@ -15,6 +15,8 @@ import androidx.annotation.NonNull;
|
||||
|
||||
import com.google.android.material.snackbar.Snackbar;
|
||||
|
||||
import org.jsoup.Jsoup;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.util.Locale;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
@ -95,4 +97,13 @@ public final class Utils {
|
||||
Snackbar snackbar = Snackbar.make(root, message, Snackbar.LENGTH_LONG);
|
||||
snackbar.show();
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove html tags and trim the text
|
||||
* @param text string to clean
|
||||
* @return cleaned text
|
||||
*/
|
||||
public static String cleanText(String text) {
|
||||
return Jsoup.parse(text).text().trim();
|
||||
}
|
||||
}
|
||||
|
17
app/src/test/java/com/readrops/app/UtilsTest.java
Normal file
17
app/src/test/java/com/readrops/app/UtilsTest.java
Normal file
@ -0,0 +1,17 @@
|
||||
package com.readrops.app;
|
||||
|
||||
import com.readrops.app.utils.Utils;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import static junit.framework.TestCase.assertEquals;
|
||||
|
||||
public class UtilsTest {
|
||||
|
||||
@Test
|
||||
public void cleanTextTest() {
|
||||
String text = " <p>This is a text<br/>to</p> clean ";
|
||||
|
||||
assertEquals("This is a text to clean", Utils.cleanText(text));
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user