blob: 4fc47fb6317085e8cd4cc29c344d8d3afdb5c4c7 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
|
package de.podfetcher.syndication.handler;
import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.DefaultHandler;
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 */
public abstract class SyndHandler extends DefaultHandler{
private static final String TAG = "SyndHandler";
protected HandlerState state;
public SyndHandler(Feed feed) {
state = new HandlerState(feed);
}
@Override
public void startElement(String uri, String localName, String qName,
Attributes attributes) throws SAXException {
state.tagstack.push(new SyndElement(qName));
String[] parts = qName.split(":");
String prefix = "";
if (parts.length >= 2) {
prefix = parts[0];
}
Namespace handler = state.namespaces.get(prefix);
if (handler != null) {
handler.handleElement(localName, state, attributes);
}
}
@Override
public void endElement(String uri, String localName, String qName)
throws SAXException {
state.tagstack.pop();
}
@Override
public void endPrefixMapping(String prefix) throws SAXException {
state.namespaces.remove(prefix);
}
@Override
public void startPrefixMapping(String prefix, String uri)
throws SAXException {
Log.d(TAG, "Found Prefix Mapping with prefix " + prefix + " and uri " + uri);
// Find the right namespace
if (prefix.equals(NSAtom.NSTAG) || uri.equals(NSAtom.NSURI)) {
state.namespaces.put(prefix, new NSAtom());
}
}
public HandlerState getState() {
return state;
}
}
|