Giter Club home page Giter Club logo

atom-archive-traverser's Introduction

atom-archive-traverser

This is a java client for processing an atom feed as described in this article or the awesome Rest In Practice book. It uses Abdera and Jersey Client (Though it is trivial to create FeedReaders for other REST/Http clients).

The idea is that it loads an atom feed and then examines each entry in turn until it finds the first entry we wish for it to process. If it reaches the end of the feed, then it will follow "prev-archive" links to traverse through all the archive feeds that have ever been published. When it reaches the entry we are looking for (or the first ever published event), it will then process each event in publication order, following "next-archive" links until it reaches the last published feed.

This is available in the central maven repository:

 <dependency>
    <groupId>uk.co.optimisticpanda</groupId>
    <artifactId>atom-archive-traverser</artifactId>
    <version>0.0.2</version>
 </dependency>

Creating a new feed traverser is trivial:

import org.apache.abdera.model.Entry;
import com.sun.jersey.api.client.Client;
import static uk.co.optimisticpanda.atom.EntryFunctions.*;

public class TestDependencies {

    public static void main(String[] args) {
        // Obtain a jersey client
        Client client = new Client();

        // Create Feed Traverser
        FeedTraverser traverser = FeedTraverserBuilder.createFeedTraverser(client)//
                
                // Start processing entries that occured after the entry with an id of 0
                .foundLastProcessedEntryWhen(idEquals("0")) //
                
                // Filter the feed to only process entries that have the CREATE category
                .processEntriesWhich(haveACategoryOf("CREATE")) //
                
                // Print out each matching entry
                .whenFound(printEntryDetails) //
                
                .build();
        
        // Traverse Feed
        traverser.traverse("http://localhost:8080/service/notifications/");
    }

    // EntryVisitor that just prints out the details of each visited entry.  
    private static EntryVisitor printEntryDetails = new EntryVisitor() {
        public void visit(Entry entry) {
            System.out.printf("\t%s\t:\t%s\n", entry.getId(), entry.getTitle());
        }
    };
}

atom-archive-traverser's People

Contributors

andrewrlee avatar

Watchers

James Cloos avatar  avatar

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.