Skip to content

Instantly share code, notes, and snippets.

@macsystems
Last active January 20, 2020 08:30
Show Gist options
  • Select an option

  • Save macsystems/01d7e80554efd344b1f9 to your computer and use it in GitHub Desktop.

Select an option

Save macsystems/01d7e80554efd344b1f9 to your computer and use it in GitHub Desktop.

Revisions

  1. macsystems revised this gist Nov 12, 2014. 3 changed files with 0 additions and 0 deletions.
    File renamed without changes.
    File renamed without changes.
    File renamed without changes.
  2. macsystems revised this gist Nov 12, 2014. 2 changed files with 19 additions and 0 deletions.
    15 changes: 15 additions & 0 deletions Create XML Converter
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,15 @@
    public static <T> T createXmlAdapterFor(final Class<T> api, final String endpoint, final Client client) {
    Preconditions.checkNotNull(client);
    Preconditions.checkNotNull(endpoint);
    //
    final RestAdapter.LogLevel level = getLogLevel();
    Log.d(LOG_TAG, "Log Level:" + level);
    final RestAdapter adapter = new RestAdapter.Builder()//
    .setEndpoint(endpoint)//
    .setConverter(new SimpleXMLConverter())//
    .setClient(client)//
    .setLogLevel(level)//
    .build();
    //
    return adapter.create(api);
    }
    4 changes: 4 additions & 0 deletions Using RX Java to receive the Feed
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,4 @@
    final String baseURL = getString(YOU_ENDPOINT_URL);
    final Client client = RestAdapterUtil.createOKClient();
    endpoint = RestAdapterUtil.createXmlAdapterFor(Endpoint.class, baseURL, client);
    final Observable<RSS> events = endpoint.getRSSFeed();
  3. macsystems created this gist Nov 12, 2014.
    103 changes: 103 additions & 0 deletions Channel
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,103 @@

    import org.simpleframework.xml.Attribute;
    import org.simpleframework.xml.Element;
    import org.simpleframework.xml.ElementList;
    import org.simpleframework.xml.Namespace;
    import org.simpleframework.xml.NamespaceList;
    import org.simpleframework.xml.Root;
    import org.simpleframework.xml.Text;

    import java.util.List;

    @NamespaceList({
    @Namespace(reference = "http://www.w3.org/2005/Atom", prefix = "atom")
    })
    @Root(strict = false)
    public class Channel {
    // Tricky part in Simple XML because the link is named twice
    @ElementList(entry = "link", inline = true, required = false)
    public List<Link> links;

    @ElementList(name = "item", required = true, inline = true)
    public List<Item> itemList;


    @Element
    String title;
    @Element
    String language;

    @Element(name = "ttl", required = false)
    int ttl;

    @Element(name = "pubDate", required = false)
    String pubDate;

    @Override
    public String toString() {
    return "Channel{" +
    "links=" + links +
    ", itemList=" + itemList +
    ", title='" + title + '\'' +
    ", language='" + language + '\'' +
    ", ttl=" + ttl +
    ", pubDate='" + pubDate + '\'' +
    '}';
    }

    public static class Link {
    @Attribute(required = false)
    public String href;

    @Attribute(required = false)
    public String rel;

    @Attribute(name = "type", required = false)
    public String contentType;

    @Text(required = false)
    public String link;
    }

    @Root(name = "item", strict = false)
    public static class Item {

    @Element(name = "title", required = true)
    String title;//The title of the item. Venice Film Festival Tries to Quit Sinking
    @Element(name = "link", required = true)
    String link;//The URL of the item. http://www.nytimes.com/2002/09/07/movies/07FEST.html
    @Element(name = "description", required = true)
    String description;//The item synopsis. Some of the most heated chatter at the Venice Film Festival this week was about the way that the arrival of the stars at the Palazzo del Cinema was being staged.
    @Element(name = "author", required = false)
    String author;//Email address of the author of the item. More. [email protected]
    @Element(name = "category", required = false)
    String category;//Includes the item in one or more categories. More. Simpsons Characters
    @Element(name = "comments", required = false)
    String comments;//URL of a page for comments relating to the item. More. http://www.myblog.org/cgi-local/mt/mt-comments.cgi?entry_id=290
    @Element(name = "enclosure", required = false)
    String enclosure;// Describes a media object that is attached to the item. More. <enclosure url="http://live.curry.com/mp3/celebritySCms.mp3" length="1069871" type="audio/mpeg"/>
    @Element(name = "guid", required = false)
    String guid;//A string that uniquely identifies the item. More. <guid isPermaLink="true">http://inessential.com/2002/09/01.php#a2</guid>
    @Element(name = "pubDate", required = false)
    String pubDate;// Indicates when the item was published. More. Sun, 19 May 2002 15:21:36 GMT
    @Element(name = "source", required = false)
    String source;// The RSS channel that the item came from. More.

    @Override
    public String toString() {
    return "Item{" +
    "title='" + title + '\'' +
    ", link='" + link + '\'' +
    ", description='" + description + '\'' +
    ", author='" + author + '\'' +
    ", category='" + category + '\'' +
    ", comments='" + comments + '\'' +
    ", enclosure='" + enclosure + '\'' +
    ", guid='" + guid + '\'' +
    ", pubDate='" + pubDate + '\'' +
    ", source='" + source + '\'' +
    '}';
    }
    }
    }

    27 changes: 27 additions & 0 deletions RSS
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,27 @@

    import org.simpleframework.xml.Attribute;
    import org.simpleframework.xml.Element;
    import org.simpleframework.xml.Root;

    @Root
    public class RSS {

    @Attribute
    String version;

    @Element
    Channel channel;


    public Channel getChannel() {
    return channel;
    }

    @Override
    public String toString() {
    return "RSS{" +
    "version='" + version + '\'' +
    ", channel=" + channel +
    '}';
    }
    }