Changed type of the Elements of tagstack to SyndElement
This commit is contained in:
parent
dc3ae95a89
commit
7f978fde78
|
@ -5,6 +5,7 @@ import java.util.HashMap;
|
||||||
import java.util.Stack;
|
import java.util.Stack;
|
||||||
|
|
||||||
import de.podfetcher.syndication.namespace.Namespace;
|
import de.podfetcher.syndication.namespace.Namespace;
|
||||||
|
import de.podfetcher.syndication.namespace.SyndElement;
|
||||||
import de.podfetcher.feed.Feed;
|
import de.podfetcher.feed.Feed;
|
||||||
import de.podfetcher.feed.FeedItem;
|
import de.podfetcher.feed.FeedItem;
|
||||||
|
|
||||||
|
@ -13,13 +14,13 @@ public class HandlerState {
|
||||||
/** Feed that the Handler is currently processing. */
|
/** Feed that the Handler is currently processing. */
|
||||||
protected Feed feed;
|
protected Feed feed;
|
||||||
protected FeedItem currentItem;
|
protected FeedItem currentItem;
|
||||||
protected Stack<String> tagstack;
|
protected Stack<SyndElement> tagstack;
|
||||||
/** Namespaces that have been defined so far. */
|
/** Namespaces that have been defined so far. */
|
||||||
protected HashMap<String, Namespace> namespaces;
|
protected HashMap<String, Namespace> namespaces;
|
||||||
|
|
||||||
public HandlerState(Feed feed) {
|
public HandlerState(Feed feed) {
|
||||||
this.feed = feed;
|
this.feed = feed;
|
||||||
tagstack = new Stack<String>();
|
tagstack = new Stack<SyndElement>();
|
||||||
namespaces = new HashMap<String, Namespace>();
|
namespaces = new HashMap<String, Namespace>();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -30,7 +31,7 @@ public class HandlerState {
|
||||||
public FeedItem getCurrentItem() {
|
public FeedItem getCurrentItem() {
|
||||||
return currentItem;
|
return currentItem;
|
||||||
}
|
}
|
||||||
public Stack<String> getTagstack() {
|
public Stack<SyndElement> getTagstack() {
|
||||||
return tagstack;
|
return tagstack;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -6,6 +6,7 @@ import de.podfetcher.feed.Feed;
|
||||||
import de.podfetcher.feed.FeedImage;
|
import de.podfetcher.feed.FeedImage;
|
||||||
import de.podfetcher.feed.FeedItem;
|
import de.podfetcher.feed.FeedItem;
|
||||||
import de.podfetcher.feed.FeedMedia;
|
import de.podfetcher.feed.FeedMedia;
|
||||||
|
import de.podfetcher.syndication.namespace.SyndElement;
|
||||||
|
|
||||||
import org.xml.sax.Attributes;
|
import org.xml.sax.Attributes;
|
||||||
import org.xml.sax.SAXException;
|
import org.xml.sax.SAXException;
|
||||||
|
@ -42,9 +43,10 @@ public class RSSHandler extends SyndHandler {
|
||||||
throws SAXException {
|
throws SAXException {
|
||||||
if (state.tagstack.size() >= 2) {
|
if (state.tagstack.size() >= 2) {
|
||||||
String content = new String(ch, start, length);
|
String content = new String(ch, start, length);
|
||||||
String top = state.tagstack.pop();
|
SyndElement topElement = state.tagstack.pop();
|
||||||
String second = state.tagstack.peek();
|
String top = topElement.getName();
|
||||||
state.tagstack.push(top);
|
String second = state.tagstack.peek().getName();
|
||||||
|
state.tagstack.push(topElement);
|
||||||
if (top.equals(TITLE)) {
|
if (top.equals(TITLE)) {
|
||||||
if (second.equals(ITEM)) {
|
if (second.equals(ITEM)) {
|
||||||
state.currentItem.setTitle(content);
|
state.currentItem.setTitle(content);
|
||||||
|
|
|
@ -8,6 +8,7 @@ import android.util.Log;
|
||||||
|
|
||||||
import de.podfetcher.feed.Feed;
|
import de.podfetcher.feed.Feed;
|
||||||
import de.podfetcher.syndication.namespace.Namespace;
|
import de.podfetcher.syndication.namespace.Namespace;
|
||||||
|
import de.podfetcher.syndication.namespace.SyndElement;
|
||||||
import de.podfetcher.syndication.namespace.atom.NSAtom;
|
import de.podfetcher.syndication.namespace.atom.NSAtom;
|
||||||
|
|
||||||
/** Superclass for all SAX Handlers which process Syndication formats */
|
/** Superclass for all SAX Handlers which process Syndication formats */
|
||||||
|
@ -22,7 +23,7 @@ public abstract class SyndHandler extends DefaultHandler{
|
||||||
@Override
|
@Override
|
||||||
public void startElement(String uri, String localName, String qName,
|
public void startElement(String uri, String localName, String qName,
|
||||||
Attributes attributes) throws SAXException {
|
Attributes attributes) throws SAXException {
|
||||||
state.tagstack.push(qName);
|
state.tagstack.push(new SyndElement(qName));
|
||||||
|
|
||||||
String[] parts = qName.split(":");
|
String[] parts = qName.split(":");
|
||||||
String prefix = "";
|
String prefix = "";
|
||||||
|
|
|
@ -6,7 +6,20 @@ import de.podfetcher.feed.Feed;
|
||||||
import de.podfetcher.syndication.handler.HandlerState;
|
import de.podfetcher.syndication.handler.HandlerState;
|
||||||
|
|
||||||
/** Defines a XML Element of a specific namespace */
|
/** 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 */
|
/** Called by its namespace if the processing of the element gets more complex */
|
||||||
public abstract void handleElement(String localName, HandlerState state, Attributes attributes);
|
public abstract void handleElement(String localName, HandlerState state, Attributes attributes);
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Namespace getNamespace() {
|
||||||
|
return namespace;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -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;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in New Issue