Created SyndHandler and Namespace classes
This commit is contained in:
parent
f78755bd13
commit
b1dbb0f45e
|
@ -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;
|
||||||
|
|
|
@ -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;
|
|
@ -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;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
|
@ -1,4 +1,4 @@
|
||||||
package de.podfetcher.syndication;
|
package de.podfetcher.syndication.handler;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
|
@ -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;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -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;
|
|
@ -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);
|
||||||
|
}
|
|
@ -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();
|
||||||
|
}
|
|
@ -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";
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in New Issue