Created SyndHandler and Namespace classes

This commit is contained in:
daniel oeh 2012-06-08 21:20:22 +02:00
parent f78755bd13
commit b1dbb0f45e
9 changed files with 117 additions and 4 deletions

View File

@ -13,7 +13,7 @@ import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import de.podfetcher.feed.*; import de.podfetcher.feed.*;
import de.podfetcher.storage.DownloadRequester; import de.podfetcher.storage.DownloadRequester;
import de.podfetcher.syndication.FeedHandler; import de.podfetcher.syndication.handler.FeedHandler;
import android.app.Service; import android.app.Service;
import android.app.DownloadManager; import android.app.DownloadManager;
import android.content.Intent; import android.content.Intent;

View File

@ -1,4 +1,4 @@
package de.podfetcher.syndication; package de.podfetcher.syndication.handler;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;

View File

@ -0,0 +1,30 @@
package de.podfetcher.syndication.handler;
import java.util.ArrayList;
import java.util.Stack;
import de.podfetcher.syndication.namespace.Namespace;
import de.podfetcher.feed.Feed;
import de.podfetcher.feed.FeedItem;
/** Contains all relevant information to describe the current state of a SyndHandler.*/
public class HandlerState {
/** Feed that the Handler is currently processing. */
protected Feed feed;
protected FeedItem currentItem;
protected Stack<String> tagstack;
/** Namespaces that have been defined so far. */
protected ArrayList<Namespace> namespaces;
public Feed getFeed() {
return feed;
}
public FeedItem getCurrentItem() {
return currentItem;
}
public Stack<String> getTagstack() {
return tagstack;
}
}

View File

@ -1,4 +1,4 @@
package de.podfetcher.syndication; package de.podfetcher.syndication.handler;
import java.util.ArrayList; import java.util.ArrayList;

View File

@ -0,0 +1,16 @@
package de.podfetcher.syndication.handler;
import org.xml.sax.helpers.DefaultHandler;
import de.podfetcher.feed.Feed;
import de.podfetcher.feed.FeedItem;
/** Superclass for all SAX Handlers which process Syndication formats */
public abstract class SyndHandler extends DefaultHandler{
protected HandlerState state;
public HandlerState getState() {
return state;
}
}

View File

@ -1,4 +1,4 @@
package de.podfetcher.syndication; package de.podfetcher.syndication.handler;
import java.io.File; import java.io.File;
import java.io.FileNotFoundException; import java.io.FileNotFoundException;

View File

@ -0,0 +1,11 @@
package de.podfetcher.syndication.namespace;
import org.xml.sax.Attributes;
import de.podfetcher.feed.Feed;
/** Defines a XML Element of a specific namespace */
public abstract class NSElement {
/** Called by its namespace if the processing of the element gets more complex */
public abstract void handleElement(String localName, Feed feed, Attributes attributes);
}

View File

@ -0,0 +1,18 @@
package de.podfetcher.syndication.namespace;
import org.xml.sax.Attributes;
import de.podfetcher.feed.Feed;
public abstract class Namespace {
/** Called by a Feedhandler when in startElement and it detects a namespace element */
public abstract void handleElement(String localName, Feed feed, Attributes attributes);
/** Called by a Feedhandler when in characters and it detects a namespace element */
public abstract void handleCharacters(String localName, Feed feed, char ch[], int start, int length);
public abstract String getNsTag();
public abstract String getNsURI();
}

View File

@ -0,0 +1,38 @@
package de.podfetcher.syndication.namespace.atom;
import org.xml.sax.Attributes;
import de.podfetcher.feed.Feed;
import de.podfetcher.syndication.namespace.Namespace;
public class NSAtom extends Namespace {
private static final String TITLE = "title";
private static final String LINK = "link";
private static final String UPDATED = "updated";
private static final String AUTHOR = "author";
@Override
public void handleElement(String localName, Feed feed, Attributes attributes) {
if (localName.equals(TITLE)) {
}
}
@Override
public void handleCharacters(String localName, Feed feed, char[] ch,
int start, int length) {
}
@Override
public String getNsTag() {
return "atom";
}
@Override
public String getNsURI() {
return "http://www.w3.org/2005/Atom";
}
}