Giter VIP home page Giter VIP logo

earl's Introduction

Android Arsenal

Features

  • Earl parses both Atom and RSS 1.0/2.0
  • Supports RSS extensions (Itunes and Media RSS for now)
  • It's lightweight. There is nothing there but parser. The only dependency it has is android annotations
  • Parser produces easy-to-use immutable POJOs
  • Runs on android versions starting from Android 2.2 (API 8)

Usage

Earl is available on jcenter. Just add a dependency in your build.gradle file:

compile 'com.einmalfel:earl:1.2.0'

Simple example:

InputStream inputStream = new URL(link).openConnection().getInputStream();
Feed feed = EarlParser.parseOrThrow(inputStream, 0);
Log.i(TAG, "Processing feed: " + feed.getTitle());
for (Item item : feed.getItems()) {
  String title = item.getTitle();
  Log.i(TAG, "Item title: " + (title == null ? "N/A" : title));
}

More complex example:

/** @return a set of keywords assigned to all items of given feed */
Set<String> getFeedKeywords(URL feedLink) {
  InputStream inputStream = new URL(feedLink).openConnection().getInputStream();
  Feed feed = EarlParser.parseOrThrow(inputStream, 0);

  // media and itunes RSS extensions allow to assign keywords to feed items
  if (RSSFeed.class.isInstance(feed)) {
    RSSFeed rssFeed = (RSSFeed) feed;
    for (RSSItem item : rssFeed.items) {
      if (item.itunes != null) {
        result.addAll(item.itunes.keywords);
      }
      if (item.media != null) {
        result.addAll(item.media.keywords);
      }
    }
  }

  return result;
}

License

Earl is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License (LGPL) as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

Earl is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

See included copy of GNU LGPLv3.0 for more details. Alternatively, you can find its text at http://www.gnu.org/licenses/lgpl-3.0.txt.

earl's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

earl's Issues

Feature Request Parse Custom Xml Tag

Hi,
Appreciate your effort creating this library.

A feature request, can you implement parsing custom xml tag from the Rss feed.
For example, most of the rss feed includes "" tag, but there's no method to get its value. Something like:
mItem.getCustomTag("lastbuilddate");

Handle relative paths properly

Any relative paths that exist in a feed should be properly handled by Utils.tryParseUrl(). Once you merge in the pulls awaiting you, I can send another pull to take care of this.

Bad parsing of timezone in RFC3339 dates

Error message is:
"Failed to parse RFC3339 string 2016-03-12T0936:25+00:00"

Note how there's a colon missing in the time part. I think it's caused by the timezone being prefixed with a + instead of a - which breaks an assumption made in Utils.java#L78-80

      //step one, split off the timezone.
      String firstPart = string.substring(0, string.lastIndexOf('-'));
      String secondPart = string.substring(string.lastIndexOf('-'));

RSS 1.0 not supported

this "RDF" / RSS 1.0 feed will fail aswell, although Earl claims to support RSS 1.0

feed: http://www.polizei.bayern.de/niederbayern/polizei.rss
exception:

W/System.err: org.xmlpull.v1.XmlPullParserException: expected: START_TAG {}channel (position:START_TAG <channel {http://www.w3.org/1999/02/22-rdf-syntax-ns#}rdf:about='http://www.polizei.bayern.de/muenchen'>@13:60 in java.io.InputStreamReader@c6cbf9d) 
W/System.err:     at org.kxml2.io.KXmlParser.require(KXmlParser.java:2065)
W/System.err:     at com.einmalfel.earl.RSSFeed.read(RSSFeed.java:77)
W/System.err:     at com.einmalfel.earl.EarlParser.parseOrThrow(EarlParser.java:55)

The feed looks pretty much like the standard RSS 1.0 to me :
http://web.resource.org/rss/1.0/spec

It's a valid feed;
https://validator.w3.org/feed/check.cgi?url=http%3A%2F%2Fwww.polizei.bayern.de%2Fniederbayern%2Fpolizei.rss

A quick debug shows that the feed offers a namespace:

xmlns="http://purl.org/rss/1.0/"
However in RSSFeed.java read(...) the first line expects the namesspace to be "" :

parser.require(XmlPullParser.START_TAG, XmlPullParser.NO_NAMESPACE, XML_TAG);
this will always fail. This what I can get out of it without any expert XML , RSS background.

This is the link to the line in code above

https://github.com/einmalfel/Earl/blob/master/earl/src/main/java/com/einmalfel/earl/RSSFeed.java#L77

Description and summary separation

Why the description and summary of an Item are not separated?
There is only one method to retrieve the description. What if I want for example to retrieve the summary instead?
Maybe they can be used for different purposes, like for example to have a "read more" button which will extend the summary into description.

Error when I was trying to develop unit test.

Hey,

I was testing my application and I got the error:

java.lang.NullPointerException
	at com.einmalfel.earl.EarlParser.parseOrThrow(EarlParser.java:46)
	at org.secfirst.umbrella.RSSFeedParserTest.getInformationAboutChannelInXmlV1(RSSFeedParserTest.java:74)

I believe that occurs ever you try to mock your RSS like this: src/test/resources/bbc_rss.xml.

@Test
    public void getInformationAboutChannelInXmlV1() throws IOException, XmlPullParserException, DataFormatException {
        InputStream inputStream = getClass().getClassLoader()
                .getResourceAsStream("rss_parse/" + "rss_bbc.xml");
        Feed feed = EarlParser.parseOrThrow(inputStream, 0);
        assertEquals(feed.getTitle(), "BBC News - Business");
        assertEquals(feed.getDescription(), "BBC News - Business");
        assertEquals(feed.getImageLink(), "http://news.bbcimg.co.uk/nol/shared/img/bbc_news_120x60.gif");
    }

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.