Fixing Atom link tag parsing and RSS 2 match issues

This commit is contained in:
Shinokuni 2019-02-05 17:50:07 +00:00
parent 0836d45217
commit 5aded28681
4 changed files with 33 additions and 11 deletions

View File

@ -167,8 +167,7 @@ public class Item {
dbItem.setTitle(item.getTitle());
dbItem.setPubDate(DateUtils.stringToDateTime(item.getUpdated(), DateUtils.ATOM_JSON_DATE_FORMAT));
dbItem.setLink(item.getLink().getHref());
dbItem.setLink(item.getUrl());
dbItem.setFeedId(feed.getId());

View File

@ -22,7 +22,7 @@
android:id="@+id/textInputLayout"
android:layout_width="280dp"
android:layout_height="wrap_content"
android:layout_marginTop="6dp"
android:layout_marginTop="12dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/add_feed_title">
@ -42,6 +42,7 @@
android:layout_height="wrap_content"
android:text="@string/add_feed_validate"
app:layout_constraintEnd_toEndOf="parent"
android:textAlignment="center"
app:layout_constraintTop_toBottomOf="@+id/textInputLayout" />
<ProgressBar

View File

@ -25,7 +25,9 @@ public class RSSNetwork {
private static final String TAG = RSSNetwork.class.getSimpleName();
public static final String RSS_CONTENT_TYPE_REGEX = "([^;]+)";
private static final String RSS_CONTENT_TYPE_REGEX = "([^;]+)";
private static final String RSS_2_REGEX = "rss.*version=\"2.0\"";
/**
* Request the url given in parameter.
@ -74,7 +76,7 @@ public class RSSNetwork {
Serializer serializer = new Persister();
if (type == RSSType.RSS_UNKNOWN) {
if (xml.contains("rss version=\"2.0\""))
if (Pattern.compile(RSS_2_REGEX).matcher(xml).find())
type = RSSType.RSS_2;
else if (xml.contains("<feed xmlns=\"http://www.w3.org/2005/Atom\">"))
type = RSSType.RSS_ATOM;

View File

@ -4,16 +4,19 @@ import com.readrops.readropslibrary.localfeed.AItem;
import org.simpleframework.xml.Attribute;
import org.simpleframework.xml.Element;
import org.simpleframework.xml.ElementList;
import org.simpleframework.xml.Root;
import java.util.List;
@Root(name = "entry", strict = false)
public class ATOMEntry extends AItem {
@Element(required = false)
private String title;
@Element(required = false)
private ATOMLink link;
@ElementList(name = "link", inline = true, required = false)
private List<ATOMLink> links;
@Element(required = false)
private String updated;
@ -38,12 +41,12 @@ public class ATOMEntry extends AItem {
this.title = title;
}
public ATOMLink getLink() {
return link;
public List<ATOMLink> getLinks() {
return links;
}
public void setLink(ATOMLink link) {
this.link = link;
public void setLinks(List<ATOMLink> links) {
this.links = links;
}
public String getUpdated() {
@ -85,4 +88,21 @@ public class ATOMEntry extends AItem {
public void setContentType(String contentType) {
this.contentType = contentType;
}
public String getUrl() {
if (links.size() > 0) {
if (links.get(0).getRel() == null)
return links.get(0).getHref();
else {
if (links.size() > 1) {
if (links.get(1).getRel() == null)
return links.get(1).getHref();
else
return null;
} else
return null;
}
} else
return null;
}
}