Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Unified Diff: src/org/adblockplus/android/SubscriptionParser.java

Issue 8491080: ABP/Android subscription list (Closed)
Patch Set: ABP/Android subscription list Created Nov. 14, 2012, 7:13 a.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/org/adblockplus/android/Subscription.java ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/org/adblockplus/android/SubscriptionParser.java
===================================================================
new file mode 100755
--- /dev/null
+++ b/src/org/adblockplus/android/SubscriptionParser.java
@@ -0,0 +1,62 @@
+package org.adblockplus.android;
+
+import java.util.List;
+
+import org.xml.sax.Attributes;
+import org.xml.sax.SAXException;
+import org.xml.sax.helpers.DefaultHandler;
+
+class SubscriptionParser extends DefaultHandler
+{
+ private static final String SUBSCRIPTION = "subscription";
+ private static final String TITLE = "title";
+ private static final String SPECIALIZATION = "specialization";
+ private static final String URL = "url";
+ private static final String HOMEPAGE = "homepage";
+ private static final String PREFIXES = "prefixes";
+ private static final String AUTHOR = "author";
+
+ private List<Subscription> subscriptions;
+ private Subscription currentSubscription;
+
+ public SubscriptionParser(List<Subscription> subscriptions)
+ {
+ super();
+ this.subscriptions = subscriptions;
+ }
+
+ @Override
+ public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException
+ {
+ if (localName.equalsIgnoreCase(SUBSCRIPTION))
+ {
+ currentSubscription = new Subscription();
+ currentSubscription.title = attributes.getValue(TITLE);
+ currentSubscription.specialization = attributes.getValue(SPECIALIZATION);
+ currentSubscription.url = attributes.getValue(URL);
+ currentSubscription.homepage = attributes.getValue(HOMEPAGE);
+ String prefix = attributes.getValue(PREFIXES);
+ if (prefix != null)
+ {
+ String[] prefixes = prefix.split(",");
+ currentSubscription.prefixes = prefixes;
+ }
+ currentSubscription.author = attributes.getValue(AUTHOR);
+ }
+ super.startElement(uri, localName, qName, attributes);
+ }
+
+ @Override
+ public void endElement(String uri, String localName, String qName) throws SAXException
+ {
+ if (localName.equalsIgnoreCase(SUBSCRIPTION))
+ {
+ if (subscriptions != null && currentSubscription != null)
+ {
+ subscriptions.add(currentSubscription);
+ }
+ currentSubscription = null;
+ }
+ super.endElement(uri, localName, qName);
+ }
+}
« no previous file with comments | « src/org/adblockplus/android/Subscription.java ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld