mirror of
https://github.com/readrops/Readrops.git
synced 2025-02-09 00:18:52 +01:00
Delete unused class and clean RSSQuery code
This commit is contained in:
parent
47dad0027f
commit
1e72cf29d6
@ -1,7 +0,0 @@
|
|||||||
package com.readrops.readropslibrary.localfeed;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Just an abstract class to wrap the three rss items types
|
|
||||||
*/
|
|
||||||
public abstract class AItem {
|
|
||||||
}
|
|
@ -37,6 +37,7 @@ public class RSSQuery {
|
|||||||
/**
|
/**
|
||||||
* Request the url given in parameter.
|
* Request the url given in parameter.
|
||||||
* This method is synchronous, it <b>has</b> to be called from another thread than the main one.
|
* This method is synchronous, it <b>has</b> to be called from another thread than the main one.
|
||||||
|
*
|
||||||
* @param url url to request
|
* @param url url to request
|
||||||
* @throws Exception
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
@ -58,7 +59,7 @@ public class RSSQuery {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public boolean isUrlFeedLink(String url) throws IOException {
|
public boolean isUrlFeedLink(String url) throws IOException {
|
||||||
Response response = query(url, new HashMap<String, String>());
|
Response response = query(url, new HashMap<>());
|
||||||
|
|
||||||
if (response.isSuccessful()) {
|
if (response.isSuccessful()) {
|
||||||
String header = response.header(LibUtils.CONTENT_TYPE_HEADER);
|
String header = response.header(LibUtils.CONTENT_TYPE_HEADER);
|
||||||
@ -97,17 +98,15 @@ public class RSSQuery {
|
|||||||
|
|
||||||
switch (header) {
|
switch (header) {
|
||||||
case LibUtils.RSS_DEFAULT_CONTENT_TYPE:
|
case LibUtils.RSS_DEFAULT_CONTENT_TYPE:
|
||||||
return RSSType.RSS_2;
|
return RSSType.RSS_2;
|
||||||
case LibUtils.RSS_TEXT_CONTENT_TYPE:
|
case LibUtils.RSS_TEXT_CONTENT_TYPE:
|
||||||
return RSSType.RSS_UNKNOWN;
|
case LibUtils.HTML_CONTENT_TYPE:
|
||||||
case LibUtils.RSS_APPLICATION_CONTENT_TYPE:
|
case LibUtils.RSS_APPLICATION_CONTENT_TYPE:
|
||||||
return RSSType.RSS_UNKNOWN;
|
return RSSType.RSS_UNKNOWN;
|
||||||
case LibUtils.ATOM_CONTENT_TYPE:
|
case LibUtils.ATOM_CONTENT_TYPE:
|
||||||
return RSSType.RSS_ATOM;
|
return RSSType.RSS_ATOM;
|
||||||
case LibUtils.JSON_CONTENT_TYPE:
|
case LibUtils.JSON_CONTENT_TYPE:
|
||||||
return RSSType.RSS_JSON;
|
return RSSType.RSS_JSON;
|
||||||
case LibUtils.HTML_CONTENT_TYPE:
|
|
||||||
return RSSType.RSS_UNKNOWN;
|
|
||||||
default:
|
default:
|
||||||
Log.d(TAG, "bad content type : " + contentType);
|
Log.d(TAG, "bad content type : " + contentType);
|
||||||
return null;
|
return null;
|
||||||
@ -116,8 +115,9 @@ public class RSSQuery {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Parse input feed
|
* Parse input feed
|
||||||
* @param stream source to parse
|
*
|
||||||
* @param type rss type, important to know the feed format
|
* @param stream source to parse
|
||||||
|
* @param type rss type, important to know the feed format
|
||||||
* @param response query response
|
* @param response query response
|
||||||
* @throws Exception
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
@ -135,42 +135,35 @@ public class RSSQuery {
|
|||||||
|
|
||||||
String etag = response.header(LibUtils.ETAG_HEADER);
|
String etag = response.header(LibUtils.ETAG_HEADER);
|
||||||
String lastModified = response.header(LibUtils.LAST_MODIFIED_HEADER);
|
String lastModified = response.header(LibUtils.LAST_MODIFIED_HEADER);
|
||||||
AFeed feed;
|
AFeed feed = null;
|
||||||
RSSQueryResult queryResult = new RSSQueryResult();
|
RSSQueryResult queryResult = new RSSQueryResult();
|
||||||
|
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case RSS_2:
|
case RSS_2:
|
||||||
feed = serializer.read(RSSFeed.class, xml);
|
feed = serializer.read(RSSFeed.class, xml);
|
||||||
if (((RSSFeed)feed).getChannel().getFeedUrl() == null) // workaround if the channel does not have any atom:link tag
|
|
||||||
((RSSFeed)feed).getChannel().getLinks().add(new RSSLink(null, response.request().url().toString()));
|
|
||||||
feed.setEtag(etag);
|
|
||||||
feed.setLastModified(lastModified);
|
|
||||||
|
|
||||||
queryResult.setFeed(feed);
|
// workaround if the channel does not have any atom:link tag
|
||||||
queryResult.setRssType(type);
|
if (((RSSFeed) feed).getChannel().getFeedUrl() == null) {
|
||||||
|
((RSSFeed) feed).getChannel().getLinks().add(new RSSLink(null, response.request().url().toString()));
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case RSS_ATOM:
|
case RSS_ATOM:
|
||||||
feed = serializer.read(ATOMFeed.class, xml);
|
feed = serializer.read(ATOMFeed.class, xml);
|
||||||
((ATOMFeed)feed).setWebsiteUrl(response.request().url().scheme() + "://" + response.request().url().host());
|
((ATOMFeed) feed).setWebsiteUrl(response.request().url().scheme() + "://" + response.request().url().host());
|
||||||
((ATOMFeed)feed).setUrl(response.request().url().toString());
|
((ATOMFeed) feed).setUrl(response.request().url().toString());
|
||||||
feed.setEtag(etag);
|
|
||||||
feed.setLastModified(etag);
|
|
||||||
|
|
||||||
queryResult.setFeed(feed);
|
|
||||||
queryResult.setRssType(type);
|
|
||||||
break;
|
break;
|
||||||
case RSS_JSON:
|
case RSS_JSON:
|
||||||
Gson gson = new Gson();
|
Gson gson = new Gson();
|
||||||
feed = gson.fromJson(xml, JSONFeed.class);
|
feed = gson.fromJson(xml, JSONFeed.class);
|
||||||
|
|
||||||
feed.setEtag(etag);
|
|
||||||
feed.setLastModified(lastModified);
|
|
||||||
|
|
||||||
queryResult.setFeed(feed);
|
|
||||||
queryResult.setRssType(type);
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
queryResult.setFeed(feed);
|
||||||
|
queryResult.setRssType(type);
|
||||||
|
|
||||||
|
feed.setEtag(etag);
|
||||||
|
feed.setLastModified(lastModified);
|
||||||
|
|
||||||
return queryResult;
|
return queryResult;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -188,16 +181,10 @@ public class RSSQuery {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public enum RSSType {
|
public enum RSSType {
|
||||||
RSS_2("rss"),
|
RSS_2,
|
||||||
RSS_ATOM("atom"),
|
RSS_ATOM,
|
||||||
RSS_JSON("json"),
|
RSS_JSON,
|
||||||
RSS_UNKNOWN("");
|
RSS_UNKNOWN
|
||||||
|
|
||||||
private String value;
|
|
||||||
|
|
||||||
RSSType(String value) {
|
|
||||||
this.value = value;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -1,7 +1,5 @@
|
|||||||
package com.readrops.readropslibrary.localfeed.atom;
|
package com.readrops.readropslibrary.localfeed.atom;
|
||||||
|
|
||||||
import com.readrops.readropslibrary.localfeed.AItem;
|
|
||||||
|
|
||||||
import org.simpleframework.xml.Attribute;
|
import org.simpleframework.xml.Attribute;
|
||||||
import org.simpleframework.xml.Element;
|
import org.simpleframework.xml.Element;
|
||||||
import org.simpleframework.xml.ElementList;
|
import org.simpleframework.xml.ElementList;
|
||||||
@ -10,7 +8,7 @@ import org.simpleframework.xml.Root;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@Root(name = "entry", strict = false)
|
@Root(name = "entry", strict = false)
|
||||||
public class ATOMEntry extends AItem {
|
public class ATOMEntry {
|
||||||
|
|
||||||
@Element(required = false)
|
@Element(required = false)
|
||||||
private String title;
|
private String title;
|
||||||
|
@ -1,9 +1,8 @@
|
|||||||
package com.readrops.readropslibrary.localfeed.json;
|
package com.readrops.readropslibrary.localfeed.json;
|
||||||
|
|
||||||
import com.google.gson.annotations.SerializedName;
|
import com.google.gson.annotations.SerializedName;
|
||||||
import com.readrops.readropslibrary.localfeed.AItem;
|
|
||||||
|
|
||||||
public class JSONItem extends AItem {
|
public class JSONItem {
|
||||||
|
|
||||||
private String id;
|
private String id;
|
||||||
|
|
||||||
|
@ -1,7 +1,5 @@
|
|||||||
package com.readrops.readropslibrary.localfeed.rss;
|
package com.readrops.readropslibrary.localfeed.rss;
|
||||||
|
|
||||||
import com.readrops.readropslibrary.localfeed.AItem;
|
|
||||||
|
|
||||||
import org.simpleframework.xml.Element;
|
import org.simpleframework.xml.Element;
|
||||||
import org.simpleframework.xml.ElementList;
|
import org.simpleframework.xml.ElementList;
|
||||||
import org.simpleframework.xml.Namespace;
|
import org.simpleframework.xml.Namespace;
|
||||||
@ -10,7 +8,7 @@ import org.simpleframework.xml.Root;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@Root(name = "item", strict = false)
|
@Root(name = "item", strict = false)
|
||||||
public class RSSItem extends AItem {
|
public class RSSItem {
|
||||||
|
|
||||||
@Element
|
@Element
|
||||||
private String title;
|
private String title;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user