Changed type of the Elements of tagstack to SyndElement

This commit is contained in:
daniel oeh 2012-06-09 11:33:57 +02:00
parent dc3ae95a89
commit 7f978fde78
5 changed files with 47 additions and 8 deletions

View File

@ -5,6 +5,7 @@ import java.util.HashMap;
import java.util.Stack;
import de.podfetcher.syndication.namespace.Namespace;
import de.podfetcher.syndication.namespace.SyndElement;
import de.podfetcher.feed.Feed;
import de.podfetcher.feed.FeedItem;
@ -13,13 +14,13 @@ public class HandlerState {
/** Feed that the Handler is currently processing. */
protected Feed feed;
protected FeedItem currentItem;
protected Stack<String> tagstack;
protected Stack<SyndElement> tagstack;
/** Namespaces that have been defined so far. */
protected HashMap<String, Namespace> namespaces;
public HandlerState(Feed feed) {
this.feed = feed;
tagstack = new Stack<String>();
tagstack = new Stack<SyndElement>();
namespaces = new HashMap<String, Namespace>();
}
@ -30,7 +31,7 @@ public class HandlerState {
public FeedItem getCurrentItem() {
return currentItem;
}
public Stack<String> getTagstack() {
public Stack<SyndElement> getTagstack() {
return tagstack;
}

View File

@ -6,6 +6,7 @@ import de.podfetcher.feed.Feed;
import de.podfetcher.feed.FeedImage;
import de.podfetcher.feed.FeedItem;
import de.podfetcher.feed.FeedMedia;
import de.podfetcher.syndication.namespace.SyndElement;
import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
@ -42,9 +43,10 @@ public class RSSHandler extends SyndHandler {
throws SAXException {
if (state.tagstack.size() >= 2) {
String content = new String(ch, start, length);
String top = state.tagstack.pop();
String second = state.tagstack.peek();
state.tagstack.push(top);
SyndElement topElement = state.tagstack.pop();
String top = topElement.getName();
String second = state.tagstack.peek().getName();
state.tagstack.push(topElement);
if (top.equals(TITLE)) {
if (second.equals(ITEM)) {
state.currentItem.setTitle(content);

View File

@ -8,6 +8,7 @@ import android.util.Log;
import de.podfetcher.feed.Feed;
import de.podfetcher.syndication.namespace.Namespace;
import de.podfetcher.syndication.namespace.SyndElement;
import de.podfetcher.syndication.namespace.atom.NSAtom;
/** Superclass for all SAX Handlers which process Syndication formats */
@ -22,7 +23,7 @@ public abstract class SyndHandler extends DefaultHandler{
@Override
public void startElement(String uri, String localName, String qName,
Attributes attributes) throws SAXException {
state.tagstack.push(qName);
state.tagstack.push(new SyndElement(qName));
String[] parts = qName.split(":");
String prefix = "";

View File

@ -6,7 +6,20 @@ import de.podfetcher.feed.Feed;
import de.podfetcher.syndication.handler.HandlerState;
/** Defines a XML Element of a specific namespace */
public abstract class NSElement {
public abstract class NSElement extends SyndElement{
protected Namespace namespace;
public NSElement(String name, Namespace namespace) {
super(name);
this.namespace = namespace;
}
/** Called by its namespace if the processing of the element gets more complex */
public abstract void handleElement(String localName, HandlerState state, Attributes attributes);
@Override
public Namespace getNamespace() {
return namespace;
}
}

View File

@ -0,0 +1,22 @@
package de.podfetcher.syndication.namespace;
/** Defines a XML Element that is pushed on the tagstack */
public class SyndElement {
protected String name;
public SyndElement(String name) {
super();
this.name = name;
}
public Namespace getNamespace() {
return null;
}
public String getName() {
return name;
}
}