summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordaniel oeh <daniel.oeh@gmail.com>2012-07-26 18:52:32 +0200
committerdaniel oeh <daniel.oeh@gmail.com>2012-07-26 18:52:32 +0200
commit1b287ea9dc26bfd5b153ef955215c777adb8672c (patch)
tree6145875cc46600214dee455f0d751e60f53e30c3
parent59791481739bafd33bae4bd56d90f915471e419a (diff)
downloadAntennaPod-1b287ea9dc26bfd5b153ef955215c777adb8672c.zip
Implemented opml writer
-rw-r--r--src/de/danoeh/antennapod/opml/OpmlSymbols.java3
-rw-r--r--src/de/danoeh/antennapod/opml/OpmlWriter.java66
2 files changed, 69 insertions, 0 deletions
diff --git a/src/de/danoeh/antennapod/opml/OpmlSymbols.java b/src/de/danoeh/antennapod/opml/OpmlSymbols.java
index 54088f821..4b0b7316a 100644
--- a/src/de/danoeh/antennapod/opml/OpmlSymbols.java
+++ b/src/de/danoeh/antennapod/opml/OpmlSymbols.java
@@ -10,6 +10,9 @@ public final class OpmlSymbols {
public static final String XMLURL = "xmlUrl";
public static final String HTMLURL = "htmlUrl";
public static final String TYPE = "type";
+ public static final String VERSION = "version";
+ public static final String HEAD = "head";
+ public static final String TITLE = "title";
private OpmlSymbols() {
diff --git a/src/de/danoeh/antennapod/opml/OpmlWriter.java b/src/de/danoeh/antennapod/opml/OpmlWriter.java
new file mode 100644
index 000000000..9ad7def05
--- /dev/null
+++ b/src/de/danoeh/antennapod/opml/OpmlWriter.java
@@ -0,0 +1,66 @@
+package de.danoeh.antennapod.opml;
+
+import java.io.IOException;
+import java.io.Writer;
+import java.util.List;
+
+import org.xmlpull.v1.XmlSerializer;
+
+import android.util.Log;
+import android.util.Xml;
+
+import de.danoeh.antennapod.AppConfig;
+import de.danoeh.antennapod.feed.Feed;
+
+/** Writes OPML documents. */
+public class OpmlWriter {
+ private static final String TAG = "OpmlWriter";
+ private static final String ENCODING = "UTF-8";
+ private static final String OPML_VERSION = "2.0";
+ private static final String OPML_TITLE = "AntennaPod Subscriptions";
+
+ /**
+ * Takes a list of feeds and a writer and writes those into an OPML
+ * document.
+ *
+ * @throws IOException
+ * @throws IllegalStateException
+ * @throws IllegalArgumentException
+ */
+ public void writeDocument(List<Feed> feeds, Writer writer)
+ throws IllegalArgumentException, IllegalStateException, IOException {
+ if (AppConfig.DEBUG)
+ Log.d(TAG, "Starting to write document");
+ XmlSerializer xs = Xml.newSerializer();
+ xs.setOutput(writer);
+
+ xs.startDocument(ENCODING, false);
+ xs.startTag(null, OpmlSymbols.OPML);
+ xs.attribute(null, OpmlSymbols.VERSION, OPML_VERSION);
+
+ xs.startTag(null, OpmlSymbols.HEAD);
+ xs.startTag(null, OpmlSymbols.TITLE);
+ xs.text(OPML_TITLE);
+ xs.endTag(null, OpmlSymbols.TITLE);
+ xs.endTag(null, OpmlSymbols.HEAD);
+
+ xs.startTag(null, OpmlSymbols.BODY);
+ for (Feed feed : feeds) {
+ xs.startTag(null, OpmlSymbols.OUTLINE);
+ xs.attribute(null, OpmlSymbols.TEXT, feed.getTitle());
+ if (feed.getType() != null) {
+ xs.attribute(null, OpmlSymbols.TYPE, feed.getType());
+ }
+ xs.attribute(null, OpmlSymbols.XMLURL, feed.getDownload_url());
+ if (feed.getLink() != null) {
+ xs.attribute(null, OpmlSymbols.HTMLURL, feed.getLink());
+ }
+ xs.endTag(null, OpmlSymbols.OUTLINE);
+ }
+ xs.endTag(null, OpmlSymbols.BODY);
+ xs.endTag(null, OpmlSymbols.OPML);
+ xs.endDocument();
+ if (AppConfig.DEBUG)
+ Log.d(TAG, "Finished writing document");
+ }
+}