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: Created Oct. 5, 2012, 9:44 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
« assets/subscriptions.xml ('K') | « 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;
Felix Dahlke 2012/11/13 09:58:12 How about naming this "currentSubscription" to hig
Andrey Novikov 2012/11/14 07:13:59 Do not see any reason but done.
+ private Subscription subscription;
+
+ 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))
+ {
+ subscription = new Subscription();
+ subscription.title = attributes.getValue(TITLE);
+ subscription.specialization = attributes.getValue(SPECIALIZATION);
+ subscription.url = attributes.getValue(URL);
+ subscription.homepage = attributes.getValue(HOMEPAGE);
+ String prefix = attributes.getValue(PREFIXES);
+ if (prefix != null)
+ {
+ String[] prefixes = prefix.split(",");
+ subscription.prefixes = prefixes;
+ }
+ subscription.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 && subscription != null)
+ {
+ subscriptions.add(subscription);
+ }
+ subscription = null;
+ }
+ super.endElement(uri, localName, qName);
+ }
+}
« assets/subscriptions.xml ('K') | « src/org/adblockplus/android/Subscription.java ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld