mirror of https://github.com/readrops/Readrops.git
Delete unused code
This commit is contained in:
parent
6a1ddaeabb
commit
5998fa9126
|
@ -1,9 +0,0 @@
|
|||
package com.readrops.api.localfeed
|
||||
|
||||
/*
|
||||
A simple class to give an abstract level to rss/atom/json feed classes
|
||||
*/
|
||||
abstract class AFeed {
|
||||
var etag: String? = null
|
||||
var lastModified: String? = null
|
||||
}
|
|
@ -1,198 +0,0 @@
|
|||
package com.readrops.api.localfeed;
|
||||
|
||||
import android.accounts.NetworkErrorException;
|
||||
import android.util.Log;
|
||||
|
||||
import com.readrops.api.localfeed.atom.ATOMFeed;
|
||||
import com.readrops.api.localfeed.json.JSONFeed;
|
||||
import com.readrops.api.localfeed.rss.RSSFeed;
|
||||
import com.readrops.api.localfeed.rss.RSSLink;
|
||||
import com.readrops.api.utils.HttpManager;
|
||||
import com.readrops.api.utils.LibUtils;
|
||||
import com.readrops.api.utils.UnknownFormatException;
|
||||
import com.squareup.moshi.JsonAdapter;
|
||||
import com.squareup.moshi.Moshi;
|
||||
|
||||
import org.simpleframework.xml.Serializer;
|
||||
import org.simpleframework.xml.core.Persister;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import okhttp3.OkHttpClient;
|
||||
import okhttp3.Request;
|
||||
import okhttp3.Response;
|
||||
|
||||
public class RSSQuery {
|
||||
|
||||
private static final String TAG = RSSQuery.class.getSimpleName();
|
||||
|
||||
private static final String RSS_CONTENT_TYPE_REGEX = "([^;]+)";
|
||||
|
||||
private static final String RSS_2_REGEX = "rss.*version=\"2.0\"";
|
||||
|
||||
private static final String ATOM_REGEX = "<feed.* xmlns=\"http://www.w3.org/2005/Atom\"";
|
||||
|
||||
/**
|
||||
* Request the url given in parameter.
|
||||
* This method is synchronous, it <b>has</b> to be called from another thread than the main one.
|
||||
*
|
||||
* @param url url to request
|
||||
* @throws Exception
|
||||
*/
|
||||
public RSSQueryResult queryUrl(String url, Map<String, String> headers) throws Exception {
|
||||
Response response = query(url, headers);
|
||||
|
||||
if (response.isSuccessful()) {
|
||||
String header = response.header(LibUtils.CONTENT_TYPE_HEADER);
|
||||
RSSType type = getRSSType(header);
|
||||
|
||||
if (type == null)
|
||||
return new RSSQueryResult(new UnknownFormatException("bad content type : " + header + "for " + url));
|
||||
|
||||
return parseFeed(response.body().byteStream(), type, response);
|
||||
} else if (response.code() == 304)
|
||||
return null;
|
||||
else
|
||||
return new RSSQueryResult(new NetworkErrorException("Error " + response.code() + " when requesting url " + url));
|
||||
}
|
||||
|
||||
public boolean isUrlFeedLink(String url) throws IOException {
|
||||
Response response = query(url, new HashMap<>());
|
||||
|
||||
if (response.isSuccessful()) {
|
||||
String header = response.header(LibUtils.CONTENT_TYPE_HEADER);
|
||||
RSSType type = getRSSType(header);
|
||||
|
||||
if (type == RSSType.RSS_UNKNOWN) {
|
||||
RSSType contentType = getContentRSSType(response.body().string());
|
||||
return contentType != RSSType.RSS_UNKNOWN;
|
||||
} else return type != null;
|
||||
} else
|
||||
return false;
|
||||
}
|
||||
|
||||
private Response query(String url, Map<String, String> headers) throws IOException {
|
||||
OkHttpClient okHttpClient = HttpManager.getInstance().getOkHttpClient();
|
||||
HttpManager.getInstance().setCredentials(null);
|
||||
|
||||
Request.Builder builder = new Request.Builder().url(url);
|
||||
for (String header : headers.keySet()) {
|
||||
String value = headers.get(header);
|
||||
builder.addHeader(header, value);
|
||||
}
|
||||
|
||||
Request request = builder.build();
|
||||
return okHttpClient.newCall(request).execute();
|
||||
}
|
||||
|
||||
private RSSType getRSSType(String contentType) {
|
||||
Pattern pattern = Pattern.compile(RSS_CONTENT_TYPE_REGEX);
|
||||
Matcher matcher = pattern.matcher(contentType);
|
||||
|
||||
String header;
|
||||
if (matcher.find())
|
||||
header = matcher.group(0);
|
||||
else
|
||||
header = contentType;
|
||||
|
||||
switch (header) {
|
||||
case LibUtils.RSS_DEFAULT_CONTENT_TYPE:
|
||||
return RSSType.RSS_2;
|
||||
case LibUtils.RSS_TEXT_CONTENT_TYPE:
|
||||
case LibUtils.HTML_CONTENT_TYPE:
|
||||
case LibUtils.RSS_APPLICATION_CONTENT_TYPE:
|
||||
return RSSType.RSS_UNKNOWN;
|
||||
case LibUtils.ATOM_CONTENT_TYPE:
|
||||
return RSSType.RSS_ATOM;
|
||||
case LibUtils.JSON_CONTENT_TYPE:
|
||||
return RSSType.RSS_JSON;
|
||||
default:
|
||||
Log.d(TAG, "bad content type : " + contentType);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse input feed
|
||||
*
|
||||
* @param stream source to parse
|
||||
* @param type rss type, important to know the feed format
|
||||
* @param response query response
|
||||
* @throws Exception
|
||||
*/
|
||||
private RSSQueryResult parseFeed(InputStream stream, RSSType type, Response response) throws Exception {
|
||||
String xml = LibUtils.inputStreamToString(stream);
|
||||
Serializer serializer = new Persister();
|
||||
|
||||
if (type == RSSType.RSS_UNKNOWN) {
|
||||
RSSType contentType = getContentRSSType(xml);
|
||||
if (contentType == RSSType.RSS_UNKNOWN) {
|
||||
return new RSSQueryResult(new UnknownFormatException("Unknown content format"));
|
||||
} else
|
||||
type = contentType;
|
||||
}
|
||||
|
||||
String etag = response.header(LibUtils.ETAG_HEADER);
|
||||
String lastModified = response.header(LibUtils.LAST_MODIFIED_HEADER);
|
||||
AFeed feed = null;
|
||||
RSSQueryResult queryResult = new RSSQueryResult();
|
||||
|
||||
switch (type) {
|
||||
case RSS_2:
|
||||
feed = serializer.read(RSSFeed.class, xml);
|
||||
|
||||
// workaround if the channel does not have any atom:link tag
|
||||
if (((RSSFeed) feed).getChannel().getFeedUrl() == null) {
|
||||
((RSSFeed) feed).getChannel().getLinks().add(new RSSLink(null, response.request().url().toString()));
|
||||
}
|
||||
break;
|
||||
case RSS_ATOM:
|
||||
feed = serializer.read(ATOMFeed.class, xml);
|
||||
((ATOMFeed) feed).setWebsiteUrl(response.request().url().scheme() + "://" + response.request().url().host());
|
||||
((ATOMFeed) feed).setUrl(response.request().url().toString());
|
||||
break;
|
||||
case RSS_JSON:
|
||||
Moshi moshi = new Moshi.Builder()
|
||||
.build();
|
||||
|
||||
JsonAdapter<JSONFeed> jsonFeedAdapter = moshi.adapter(JSONFeed.class);
|
||||
feed = jsonFeedAdapter.fromJson(xml);
|
||||
break;
|
||||
}
|
||||
|
||||
queryResult.setFeed(feed);
|
||||
queryResult.setRssType(type);
|
||||
|
||||
feed.setEtag(etag);
|
||||
feed.setLastModified(lastModified);
|
||||
|
||||
return queryResult;
|
||||
}
|
||||
|
||||
private RSSType getContentRSSType(String content) {
|
||||
RSSType type;
|
||||
|
||||
if (Pattern.compile(RSS_2_REGEX).matcher(content).find())
|
||||
type = RSSType.RSS_2;
|
||||
else if (Pattern.compile(ATOM_REGEX).matcher(content).find())
|
||||
type = RSSType.RSS_ATOM;
|
||||
else
|
||||
type = RSSType.RSS_UNKNOWN;
|
||||
|
||||
return type;
|
||||
}
|
||||
|
||||
public enum RSSType {
|
||||
RSS_2,
|
||||
RSS_ATOM,
|
||||
RSS_JSON,
|
||||
RSS_UNKNOWN
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -1,42 +0,0 @@
|
|||
package com.readrops.api.localfeed;
|
||||
|
||||
public class RSSQueryResult {
|
||||
|
||||
private AFeed feed;
|
||||
|
||||
private RSSQuery.RSSType rssType;
|
||||
|
||||
private Exception exception;
|
||||
|
||||
public RSSQueryResult(Exception exception) {
|
||||
this.exception = exception;
|
||||
}
|
||||
|
||||
public RSSQueryResult() {
|
||||
|
||||
}
|
||||
|
||||
public AFeed getFeed() {
|
||||
return feed;
|
||||
}
|
||||
|
||||
public void setFeed(AFeed feed) {
|
||||
this.feed = feed;
|
||||
}
|
||||
|
||||
public RSSQuery.RSSType getRssType() {
|
||||
return rssType;
|
||||
}
|
||||
|
||||
public void setRssType(RSSQuery.RSSType rssType) {
|
||||
this.rssType = rssType;
|
||||
}
|
||||
|
||||
public void setException(Exception exception) {
|
||||
this.exception = exception;
|
||||
}
|
||||
|
||||
public Exception getException() {
|
||||
return exception;
|
||||
}
|
||||
}
|
|
@ -1,22 +0,0 @@
|
|||
package com.readrops.api.localfeed.atom;
|
||||
|
||||
import org.simpleframework.xml.Element;
|
||||
import org.simpleframework.xml.Root;
|
||||
|
||||
@Root(name = "author", strict = false)
|
||||
public class ATOMAuthor {
|
||||
|
||||
@Element(required = false)
|
||||
private String name;
|
||||
|
||||
@Element(required = false)
|
||||
private String email;
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public String getEmail() {
|
||||
return email;
|
||||
}
|
||||
}
|
|
@ -1,98 +0,0 @@
|
|||
package com.readrops.api.localfeed.atom;
|
||||
|
||||
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 {
|
||||
|
||||
@Element(required = false)
|
||||
private String title;
|
||||
|
||||
@ElementList(name = "link", inline = true, required = false)
|
||||
private List<ATOMLink> links;
|
||||
|
||||
@Element(required = false)
|
||||
private String updated;
|
||||
|
||||
@Element(required = false)
|
||||
private String summary;
|
||||
|
||||
@Element(required = false)
|
||||
private String id;
|
||||
|
||||
@Element(required = false)
|
||||
private String content;
|
||||
|
||||
@Attribute(name = "type", required = false)
|
||||
private String contentType;
|
||||
|
||||
public String getTitle() {
|
||||
return title;
|
||||
}
|
||||
|
||||
public void setTitle(String title) {
|
||||
this.title = title;
|
||||
}
|
||||
|
||||
public List<ATOMLink> getLinks() {
|
||||
return links;
|
||||
}
|
||||
|
||||
public void setLinks(List<ATOMLink> links) {
|
||||
this.links = links;
|
||||
}
|
||||
|
||||
public String getUpdated() {
|
||||
return updated;
|
||||
}
|
||||
|
||||
public void setUpdated(String updated) {
|
||||
this.updated = updated;
|
||||
}
|
||||
|
||||
public String getSummary() {
|
||||
return summary;
|
||||
}
|
||||
|
||||
public void setSummary(String summary) {
|
||||
this.summary = summary;
|
||||
}
|
||||
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(String id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getContent() {
|
||||
return content;
|
||||
}
|
||||
|
||||
public void setContent(String content) {
|
||||
this.content = content;
|
||||
}
|
||||
|
||||
public String getContentType() {
|
||||
return contentType;
|
||||
}
|
||||
|
||||
public void setContentType(String contentType) {
|
||||
this.contentType = contentType;
|
||||
}
|
||||
|
||||
public String getUrl() {
|
||||
for (ATOMLink link : links) {
|
||||
if (link.getRel() == null || link.getRel().equals("self") || link.getRel().equals("alternate"))
|
||||
return link.getHref();
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
|
@ -1,128 +0,0 @@
|
|||
package com.readrops.api.localfeed.atom;
|
||||
|
||||
import com.readrops.api.localfeed.AFeed;
|
||||
|
||||
import org.simpleframework.xml.Element;
|
||||
import org.simpleframework.xml.ElementList;
|
||||
import org.simpleframework.xml.Root;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Root(name = "feed", strict = false)
|
||||
public class ATOMFeed extends AFeed {
|
||||
|
||||
@Element(required = false)
|
||||
private String title;
|
||||
|
||||
@ElementList(name = "link", inline = true, required = false)
|
||||
private List<ATOMLink> links;
|
||||
|
||||
private String url;
|
||||
|
||||
private String websiteUrl;
|
||||
|
||||
@Element(required = false)
|
||||
private String id;
|
||||
|
||||
@Element(required = false)
|
||||
private String subtitle;
|
||||
|
||||
@Element(required = false)
|
||||
private String updated;
|
||||
|
||||
@Element(required = false)
|
||||
private ATOMAuthor author;
|
||||
|
||||
@ElementList(inline = true, required = false)
|
||||
private List<ATOMEntry> entries;
|
||||
|
||||
public String getTitle() {
|
||||
return title;
|
||||
}
|
||||
|
||||
public void setTitle(String title) {
|
||||
this.title = title;
|
||||
}
|
||||
|
||||
public List<ATOMLink> getLinks() {
|
||||
return links;
|
||||
}
|
||||
|
||||
public void setLinks(List<ATOMLink> links) {
|
||||
this.links = links;
|
||||
}
|
||||
|
||||
public String getSubtitle() {
|
||||
return subtitle;
|
||||
}
|
||||
|
||||
public void setSubtitle(String subtitle) {
|
||||
this.subtitle = subtitle;
|
||||
}
|
||||
|
||||
public String getUpdated() {
|
||||
return updated;
|
||||
}
|
||||
|
||||
public void setUpdated(String updated) {
|
||||
this.updated = updated;
|
||||
}
|
||||
|
||||
public ATOMAuthor getAuthor() {
|
||||
return author;
|
||||
}
|
||||
|
||||
public void setAuthor(ATOMAuthor author) {
|
||||
this.author = author;
|
||||
}
|
||||
|
||||
public List<ATOMEntry> getEntries() {
|
||||
return entries;
|
||||
}
|
||||
|
||||
public void setEntries(List<ATOMEntry> entries) {
|
||||
this.entries = entries;
|
||||
}
|
||||
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(String id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getUrl() {
|
||||
return url;
|
||||
}
|
||||
|
||||
public void setUrl(String url) {
|
||||
this.url = url;
|
||||
}
|
||||
|
||||
public String getWebsiteUrl() {
|
||||
return websiteUrl;
|
||||
}
|
||||
|
||||
public void setWebsiteUrl(String websiteUrl) {
|
||||
this.websiteUrl = websiteUrl;
|
||||
}
|
||||
|
||||
/*public String getWebSiteUrl() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public String getUrl() {
|
||||
if (links.size() > 0) {
|
||||
if (links.get(0).getRel() != null)
|
||||
return links.get(0).getHref();
|
||||
else {
|
||||
if (links.size() > 1)
|
||||
return links.get(1).getHref();
|
||||
else
|
||||
return null;
|
||||
}
|
||||
} else
|
||||
return null;
|
||||
}*/
|
||||
}
|
|
@ -1,30 +0,0 @@
|
|||
package com.readrops.api.localfeed.atom;
|
||||
|
||||
import org.simpleframework.xml.Attribute;
|
||||
import org.simpleframework.xml.Root;
|
||||
|
||||
@Root(name = "link", strict = false)
|
||||
public class ATOMLink {
|
||||
|
||||
@Attribute(name = "href", required = false)
|
||||
private String href;
|
||||
|
||||
@Attribute(name = "rel", required = false)
|
||||
private String rel;
|
||||
|
||||
public String getHref() {
|
||||
return href;
|
||||
}
|
||||
|
||||
public void setHref(String href) {
|
||||
this.href = href;
|
||||
}
|
||||
|
||||
public String getRel() {
|
||||
return rel;
|
||||
}
|
||||
|
||||
public void setRel(String rel) {
|
||||
this.rel = rel;
|
||||
}
|
||||
}
|
|
@ -1,9 +0,0 @@
|
|||
package com.readrops.api.localfeed.json
|
||||
|
||||
import com.squareup.moshi.Json
|
||||
import com.squareup.moshi.JsonClass
|
||||
|
||||
@JsonClass(generateAdapter = true)
|
||||
data class JSONAuthor(val name: String,
|
||||
val url: String,
|
||||
@Json(name = "avatar") val avatarUrl: String?)
|
|
@ -1,15 +0,0 @@
|
|||
package com.readrops.api.localfeed.json
|
||||
|
||||
import com.readrops.api.localfeed.AFeed
|
||||
import com.squareup.moshi.Json
|
||||
import com.squareup.moshi.JsonClass
|
||||
|
||||
@JsonClass(generateAdapter = true)
|
||||
data class JSONFeed(val version: String,
|
||||
val title: String,
|
||||
@Json(name = "home_page_url") val homePageUrl: String?,
|
||||
@Json(name = "feed_url") val feedUrl: String?,
|
||||
val description: String?,
|
||||
@Json(name = "icon") val iconUrl: String?,
|
||||
@Json(name = "favicon") val faviconUrl: String?,
|
||||
val items: List<JSONItem>) : AFeed()
|
|
@ -1,21 +0,0 @@
|
|||
package com.readrops.api.localfeed.json
|
||||
|
||||
import com.squareup.moshi.Json
|
||||
import com.squareup.moshi.JsonClass
|
||||
|
||||
@JsonClass(generateAdapter = true)
|
||||
data class JSONItem(val id: String,
|
||||
val title: String?,
|
||||
val summary: String?,
|
||||
@Json(name = "content_text") val contentText: String?,
|
||||
@Json(name = "content_html") val contentHtml: String?,
|
||||
val url: String?,
|
||||
@Json(name = "image") val imageUrl: String?,
|
||||
@Json(name = "date_published") val pubDate: String,
|
||||
@Json(name = "date_modified") val modDate: String?,
|
||||
val author: JSONAuthor?) {
|
||||
|
||||
fun getContent(): String? {
|
||||
return contentHtml ?: contentText
|
||||
}
|
||||
}
|
|
@ -1,87 +0,0 @@
|
|||
package com.readrops.api.localfeed.rss;
|
||||
|
||||
import org.simpleframework.xml.Element;
|
||||
import org.simpleframework.xml.ElementList;
|
||||
import org.simpleframework.xml.Root;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Root(name = "channel", strict = false)
|
||||
public class RSSChannel {
|
||||
|
||||
@Element(name = "title", required = false)
|
||||
private String title;
|
||||
|
||||
@Element(name = "description", required = false)
|
||||
private String description;
|
||||
|
||||
// workaround to get the two links (feed and regular)
|
||||
@ElementList(name = "link", inline = true, required = false)
|
||||
private List<RSSLink> links;
|
||||
|
||||
@Element(name = "lastBuildDate", required = false)
|
||||
private String lastUpdated;
|
||||
|
||||
@ElementList(inline = true, required = false)
|
||||
private List<RSSItem> items;
|
||||
|
||||
public String getTitle() {
|
||||
return title;
|
||||
}
|
||||
|
||||
public void setTitle(String title) {
|
||||
this.title = title;
|
||||
}
|
||||
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
|
||||
public void setDescription(String description) {
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
public List<RSSLink> getLinks() {
|
||||
return links;
|
||||
}
|
||||
|
||||
public void setLinks(List<RSSLink> links) {
|
||||
this.links = links;
|
||||
}
|
||||
|
||||
public List<RSSItem> getItems() {
|
||||
return items;
|
||||
}
|
||||
|
||||
public void setItems(List<RSSItem> items) {
|
||||
this.items = items;
|
||||
}
|
||||
|
||||
public String getLastUpdated() {
|
||||
return lastUpdated;
|
||||
}
|
||||
|
||||
public void setLastUpdated(String lastUpdated) {
|
||||
this.lastUpdated = lastUpdated;
|
||||
}
|
||||
|
||||
public String getFeedUrl() {
|
||||
if (links.size() > 1) {
|
||||
if (links.get(0).getHref() != null)
|
||||
return links.get(0).getHref();
|
||||
else
|
||||
return links.get(1).getHref();
|
||||
} else
|
||||
return null;
|
||||
}
|
||||
|
||||
public String getUrl() {
|
||||
if (links.size() > 1) {
|
||||
if (links.get(1).getText() != null)
|
||||
return links.get(1).getText();
|
||||
else
|
||||
return links.get(0).getText();
|
||||
} else
|
||||
return null;
|
||||
}
|
||||
}
|
|
@ -1,30 +0,0 @@
|
|||
package com.readrops.api.localfeed.rss;
|
||||
|
||||
import org.simpleframework.xml.Attribute;
|
||||
import org.simpleframework.xml.Root;
|
||||
|
||||
@Root(name = "enclosure", strict = false)
|
||||
public class RSSEnclosure {
|
||||
|
||||
@Attribute(required = false)
|
||||
private String type;
|
||||
|
||||
@Attribute(required = false)
|
||||
private String url;
|
||||
|
||||
public String getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public void setType(String type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public String getUrl() {
|
||||
return url;
|
||||
}
|
||||
|
||||
public void setUrl(String url) {
|
||||
this.url = url;
|
||||
}
|
||||
}
|
|
@ -1,21 +0,0 @@
|
|||
package com.readrops.api.localfeed.rss;
|
||||
|
||||
import com.readrops.api.localfeed.AFeed;
|
||||
|
||||
import org.simpleframework.xml.Element;
|
||||
import org.simpleframework.xml.Root;
|
||||
|
||||
@Root(name = "rss", strict = false)
|
||||
public class RSSFeed extends AFeed {
|
||||
|
||||
@Element(name = "channel", required = false)
|
||||
private RSSChannel channel;
|
||||
|
||||
public RSSChannel getChannel() {
|
||||
return channel;
|
||||
}
|
||||
|
||||
public void setChannel(RSSChannel channel) {
|
||||
this.channel = channel;
|
||||
}
|
||||
}
|
|
@ -1,154 +0,0 @@
|
|||
package com.readrops.api.localfeed.rss;
|
||||
|
||||
import org.simpleframework.xml.Element;
|
||||
import org.simpleframework.xml.ElementList;
|
||||
import org.simpleframework.xml.Namespace;
|
||||
import org.simpleframework.xml.Root;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Root(name = "item", strict = false)
|
||||
public class RSSItem {
|
||||
|
||||
@Element
|
||||
private String title;
|
||||
|
||||
@Element(name = "link", required = false)
|
||||
private String link;
|
||||
|
||||
@Element(name = "imageLink", required = false)
|
||||
private String imageLink;
|
||||
|
||||
@ElementList(name = "content", inline = true, required = false)
|
||||
@Namespace(prefix = "media")
|
||||
private List<RSSMediaContent> mediaContents;
|
||||
|
||||
@ElementList(name = "enclosure", inline = true, required = false)
|
||||
private List<RSSEnclosure> enclosures;
|
||||
|
||||
@ElementList(name = "creator", inline = true, required = false)
|
||||
@Namespace(prefix = "dc", reference = "http://purl.org/dc/elements/1.1/")
|
||||
private List<String> creator;
|
||||
|
||||
@Element(required = false)
|
||||
private String author;
|
||||
|
||||
@Element(name = "pubDate", required = false)
|
||||
private String pubDate;
|
||||
|
||||
@Element(name = "date", required = false)
|
||||
@Namespace(prefix = "dc")
|
||||
private String date;
|
||||
|
||||
@Element(name = "description", required = false)
|
||||
private String description;
|
||||
|
||||
@Element(name = "encoded", required = false)
|
||||
@Namespace(prefix = "content")
|
||||
private String content;
|
||||
|
||||
@Element(required = false)
|
||||
private String guid;
|
||||
|
||||
public String getTitle() {
|
||||
return title;
|
||||
}
|
||||
|
||||
public void setTitle(String title) {
|
||||
this.title = title;
|
||||
}
|
||||
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
|
||||
public void setDescription(String description) {
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
public String getLink() {
|
||||
return link;
|
||||
}
|
||||
|
||||
public void setLink(String link) {
|
||||
this.link = link;
|
||||
}
|
||||
|
||||
public String getImageLink() {
|
||||
return imageLink;
|
||||
}
|
||||
|
||||
public void setImageLink(String imageLink) {
|
||||
this.imageLink = imageLink;
|
||||
}
|
||||
|
||||
public List<String> getCreator() {
|
||||
return creator;
|
||||
}
|
||||
|
||||
public void setCreator(List<String> creator) {
|
||||
this.creator = creator;
|
||||
}
|
||||
|
||||
public String getPubDate() {
|
||||
return pubDate;
|
||||
}
|
||||
|
||||
public void setPubDate(String pubDate) {
|
||||
this.pubDate = pubDate;
|
||||
}
|
||||
|
||||
public String getContent() {
|
||||
return content;
|
||||
}
|
||||
|
||||
public void setContent(String content) {
|
||||
this.content = content;
|
||||
}
|
||||
|
||||
public String getGuid() {
|
||||
return guid;
|
||||
}
|
||||
|
||||
public void setGuid(String guid) {
|
||||
this.guid = guid;
|
||||
}
|
||||
|
||||
public List<RSSMediaContent> getMediaContents() {
|
||||
return mediaContents;
|
||||
}
|
||||
|
||||
public void setMediaContents(List<RSSMediaContent> mediaContents) {
|
||||
this.mediaContents = mediaContents;
|
||||
}
|
||||
|
||||
public List<RSSEnclosure> getEnclosures() {
|
||||
return enclosures;
|
||||
}
|
||||
|
||||
public void setEnclosures(List<RSSEnclosure> enclosures) {
|
||||
this.enclosures = enclosures;
|
||||
}
|
||||
|
||||
public String getDate() {
|
||||
if (pubDate != null)
|
||||
return pubDate;
|
||||
else
|
||||
return date;
|
||||
}
|
||||
|
||||
public void setDate(String date) {
|
||||
this.date = date;
|
||||
}
|
||||
|
||||
public String getAuthor() {
|
||||
if (creator != null && !creator.isEmpty())
|
||||
return creator.get(0);
|
||||
else
|
||||
return author;
|
||||
}
|
||||
|
||||
public void setAuthor(String author) {
|
||||
this.author = author;
|
||||
}
|
||||
}
|
|
@ -1,40 +0,0 @@
|
|||
package com.readrops.api.localfeed.rss;
|
||||
|
||||
import org.simpleframework.xml.Attribute;
|
||||
import org.simpleframework.xml.Root;
|
||||
import org.simpleframework.xml.Text;
|
||||
|
||||
@Root(name = "link", strict = false)
|
||||
public class RSSLink {
|
||||
|
||||
@Text(required = false)
|
||||
private String text;
|
||||
|
||||
@Attribute(name = "href", required = false)
|
||||
private String href;
|
||||
|
||||
public RSSLink() {
|
||||
|
||||
}
|
||||
|
||||
public RSSLink(String text, String href) {
|
||||
this.text = text;
|
||||
this.href = href;
|
||||
}
|
||||
|
||||
public String getHref() {
|
||||
return href;
|
||||
}
|
||||
|
||||
public void setHref(String href) {
|
||||
this.href = href;
|
||||
}
|
||||
|
||||
public String getText() {
|
||||
return text;
|
||||
}
|
||||
|
||||
public void setText(String text) {
|
||||
this.text = text;
|
||||
}
|
||||
}
|
|
@ -1,30 +0,0 @@
|
|||
package com.readrops.api.localfeed.rss;
|
||||
|
||||
import org.simpleframework.xml.Attribute;
|
||||
import org.simpleframework.xml.Root;
|
||||
|
||||
@Root(name = "content", strict = false)
|
||||
public class RSSMediaContent {
|
||||
|
||||
@Attribute(required = false)
|
||||
private String url;
|
||||
|
||||
@Attribute(required = false)
|
||||
private String medium;
|
||||
|
||||
public String getUrl() {
|
||||
return url;
|
||||
}
|
||||
|
||||
public void setUrl(String url) {
|
||||
this.url = url;
|
||||
}
|
||||
|
||||
public String getMedium() {
|
||||
return medium;
|
||||
}
|
||||
|
||||
public void setMedium(String medium) {
|
||||
this.medium = medium;
|
||||
}
|
||||
}
|
|
@ -1,65 +0,0 @@
|
|||
package com.readrops.app.utils.matchers;
|
||||
|
||||
import com.readrops.db.entities.Feed;
|
||||
import com.readrops.api.localfeed.atom.ATOMFeed;
|
||||
import com.readrops.api.localfeed.json.JSONFeed;
|
||||
import com.readrops.api.localfeed.rss.RSSChannel;
|
||||
import com.readrops.api.localfeed.rss.RSSFeed;
|
||||
|
||||
import org.jsoup.Jsoup;
|
||||
|
||||
public final class FeedMatcher {
|
||||
|
||||
public static Feed feedFromRSS(RSSFeed rssFeed) {
|
||||
Feed feed = new Feed();
|
||||
RSSChannel channel = rssFeed.getChannel();
|
||||
|
||||
feed.setName(Jsoup.parse(channel.getTitle()).text());
|
||||
feed.setUrl(channel.getFeedUrl());
|
||||
feed.setSiteUrl(channel.getUrl());
|
||||
feed.setDescription(channel.getDescription());
|
||||
feed.setLastUpdated(channel.getLastUpdated());
|
||||
|
||||
feed.setEtag(rssFeed.getEtag());
|
||||
feed.setLastModified(rssFeed.getLastModified());
|
||||
|
||||
feed.setFolderId(null);
|
||||
|
||||
return feed;
|
||||
}
|
||||
|
||||
public static Feed feedFromATOM(ATOMFeed atomFeed) {
|
||||
Feed feed = new Feed();
|
||||
|
||||
feed.setName(atomFeed.getTitle());
|
||||
feed.setDescription(atomFeed.getSubtitle());
|
||||
feed.setUrl(atomFeed.getUrl());
|
||||
feed.setSiteUrl(atomFeed.getWebsiteUrl());
|
||||
feed.setDescription(atomFeed.getSubtitle());
|
||||
feed.setLastUpdated(atomFeed.getUpdated());
|
||||
|
||||
feed.setEtag(atomFeed.getEtag());
|
||||
feed.setLastModified(atomFeed.getLastModified());
|
||||
|
||||
feed.setFolderId(null);
|
||||
|
||||
return feed;
|
||||
}
|
||||
|
||||
public static Feed feedFromJSON(JSONFeed jsonFeed) {
|
||||
Feed feed = new Feed();
|
||||
|
||||
feed.setName(jsonFeed.getTitle());
|
||||
feed.setUrl(jsonFeed.getFeedUrl());
|
||||
feed.setSiteUrl(jsonFeed.getHomePageUrl());
|
||||
feed.setDescription(jsonFeed.getDescription());
|
||||
|
||||
feed.setEtag(jsonFeed.getEtag());
|
||||
feed.setLastModified(jsonFeed.getLastModified());
|
||||
feed.setIconUrl(jsonFeed.getFaviconUrl());
|
||||
|
||||
feed.setFolderId(null);
|
||||
|
||||
return feed;
|
||||
}
|
||||
}
|
|
@ -1,123 +0,0 @@
|
|||
package com.readrops.app.utils.matchers;
|
||||
|
||||
import com.readrops.api.localfeed.atom.ATOMEntry;
|
||||
import com.readrops.api.localfeed.json.JSONItem;
|
||||
import com.readrops.api.localfeed.rss.RSSEnclosure;
|
||||
import com.readrops.api.localfeed.rss.RSSItem;
|
||||
import com.readrops.api.localfeed.rss.RSSMediaContent;
|
||||
import com.readrops.api.utils.DateUtils;
|
||||
import com.readrops.api.utils.LibUtils;
|
||||
import com.readrops.api.utils.ParseException;
|
||||
import com.readrops.app.utils.Utils;
|
||||
import com.readrops.db.entities.Feed;
|
||||
import com.readrops.db.entities.Item;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public final class ItemMatcher {
|
||||
|
||||
public static List<Item> itemsFromRSS(List<RSSItem> items, Feed feed) throws ParseException {
|
||||
List<Item> dbItems = new ArrayList<>();
|
||||
|
||||
for (RSSItem item : items) {
|
||||
Item newItem = new Item();
|
||||
|
||||
newItem.setAuthor(item.getAuthor());
|
||||
newItem.setContent(item.getContent()); // Jsoup.clean(item.getContent(), Whitelist.relaxed())
|
||||
newItem.setDescription(item.getDescription());
|
||||
newItem.setGuid(item.getGuid() != null ? item.getGuid() : item.getLink());
|
||||
newItem.setTitle(LibUtils.cleanText(item.getTitle()));
|
||||
|
||||
try {
|
||||
newItem.setPubDate(DateUtils.stringToLocalDateTime(item.getDate()));
|
||||
} catch (Exception e) {
|
||||
throw new ParseException();
|
||||
}
|
||||
|
||||
newItem.setLink(item.getLink());
|
||||
newItem.setFeedId(feed.getId());
|
||||
|
||||
if (item.getMediaContents() != null && !item.getMediaContents().isEmpty()) {
|
||||
for (RSSMediaContent mediaContent : item.getMediaContents()) {
|
||||
if (mediaContent.getMedium() != null && Utils.isTypeImage(mediaContent.getMedium())) {
|
||||
newItem.setImageLink(mediaContent.getUrl());
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (item.getEnclosures() != null) {
|
||||
for (RSSEnclosure enclosure : item.getEnclosures()) {
|
||||
if (enclosure.getType() != null && Utils.isTypeImage(enclosure.getType())
|
||||
&& enclosure.getUrl() != null) {
|
||||
newItem.setImageLink(enclosure.getUrl());
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
dbItems.add(newItem);
|
||||
}
|
||||
|
||||
return dbItems;
|
||||
}
|
||||
|
||||
public static List<Item> itemsFromATOM(List<ATOMEntry> items, Feed feed) throws ParseException {
|
||||
List<Item> dbItems = new ArrayList<>();
|
||||
|
||||
for (ATOMEntry item : items) {
|
||||
Item dbItem = new Item();
|
||||
|
||||
dbItem.setContent(item.getContent()); // Jsoup.clean(item.getContent(), Whitelist.relaxed())
|
||||
dbItem.setDescription(item.getSummary());
|
||||
dbItem.setGuid(item.getId());
|
||||
dbItem.setTitle(LibUtils.cleanText(item.getTitle()));
|
||||
|
||||
try {
|
||||
dbItem.setPubDate(DateUtils.stringToLocalDateTime(item.getUpdated()));
|
||||
} catch (Exception e) {
|
||||
throw new ParseException();
|
||||
}
|
||||
|
||||
dbItem.setLink(item.getUrl());
|
||||
|
||||
dbItem.setFeedId(feed.getId());
|
||||
|
||||
dbItems.add(dbItem);
|
||||
}
|
||||
|
||||
return dbItems;
|
||||
}
|
||||
|
||||
public static List<Item> itemsFromJSON(List<JSONItem> items, Feed feed) throws ParseException {
|
||||
List<Item> dbItems = new ArrayList<>();
|
||||
|
||||
for (JSONItem item : items) {
|
||||
Item dbItem = new Item();
|
||||
|
||||
if (item.getAuthor() != null)
|
||||
dbItem.setAuthor(item.getAuthor().getName());
|
||||
|
||||
dbItem.setContent(item.getContent()); // Jsoup.clean(item.getContent(), Whitelist.relaxed())
|
||||
dbItem.setDescription(item.getSummary());
|
||||
dbItem.setGuid(item.getId());
|
||||
dbItem.setTitle(LibUtils.cleanText(item.getTitle()));
|
||||
|
||||
try {
|
||||
dbItem.setPubDate(DateUtils.stringToLocalDateTime(item.getPubDate()));
|
||||
} catch (Exception e) {
|
||||
throw new ParseException();
|
||||
}
|
||||
|
||||
dbItem.setLink(item.getUrl());
|
||||
|
||||
dbItem.setFeedId(feed.getId());
|
||||
|
||||
dbItems.add(dbItem);
|
||||
}
|
||||
|
||||
return dbItems;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue