diff options
author | Martin Fietz <Martin.Fietz@gmail.com> | 2015-10-03 21:39:25 +0200 |
---|---|---|
committer | Martin Fietz <Martin.Fietz@gmail.com> | 2015-10-03 21:39:25 +0200 |
commit | d3f9b2d49f999d444910afaa49c11459313c67a2 (patch) | |
tree | 3525f5e35cf23b3fb62a53f77867a84e6fcb3e48 | |
parent | 18e409523ba479a3db98eb1fddc50b69e3cbb30e (diff) | |
download | AntennaPod-d3f9b2d49f999d444910afaa49c11459313c67a2.zip |
Indent and add line break to exported OPML file
-rw-r--r-- | core/src/main/java/de/danoeh/antennapod/core/opml/OpmlSymbols.java | 1 | ||||
-rw-r--r-- | core/src/main/java/de/danoeh/antennapod/core/opml/OpmlWriter.java | 33 |
2 files changed, 28 insertions, 6 deletions
diff --git a/core/src/main/java/de/danoeh/antennapod/core/opml/OpmlSymbols.java b/core/src/main/java/de/danoeh/antennapod/core/opml/OpmlSymbols.java index 2b831ca2a..c973713cb 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/opml/OpmlSymbols.java +++ b/core/src/main/java/de/danoeh/antennapod/core/opml/OpmlSymbols.java @@ -13,6 +13,7 @@ public final class OpmlSymbols { public static final String VERSION = "version"; public static final String HEAD = "head"; public static final String TITLE = "title"; + public static final String DATE_CREATED = "dateCreated"; private OpmlSymbols() { diff --git a/core/src/main/java/de/danoeh/antennapod/core/opml/OpmlWriter.java b/core/src/main/java/de/danoeh/antennapod/core/opml/OpmlWriter.java index 641190f62..673c602df 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/opml/OpmlWriter.java +++ b/core/src/main/java/de/danoeh/antennapod/core/opml/OpmlWriter.java @@ -2,14 +2,17 @@ package de.danoeh.antennapod.core.opml; import android.util.Log; import android.util.Xml; -import de.danoeh.antennapod.core.BuildConfig; -import de.danoeh.antennapod.core.feed.Feed; + import org.xmlpull.v1.XmlSerializer; import java.io.IOException; import java.io.Writer; +import java.util.Date; import java.util.List; +import de.danoeh.antennapod.core.feed.Feed; +import de.danoeh.antennapod.core.util.DateUtils; + /** Writes OPML documents. */ public class OpmlWriter { private static final String TAG = "OpmlWriter"; @@ -27,23 +30,38 @@ public class OpmlWriter { */ public void writeDocument(List<Feed> feeds, Writer writer) throws IllegalArgumentException, IllegalStateException, IOException { - if (BuildConfig.DEBUG) - Log.d(TAG, "Starting to write document"); + Log.d(TAG, "Starting to write document"); XmlSerializer xs = Xml.newSerializer(); xs.setOutput(writer); xs.startDocument(ENCODING, false); + xs.text("\n"); xs.startTag(null, OpmlSymbols.OPML); xs.attribute(null, OpmlSymbols.VERSION, OPML_VERSION); + xs.text("\n"); + xs.text(" "); xs.startTag(null, OpmlSymbols.HEAD); + xs.text("\n"); + xs.text(" "); xs.startTag(null, OpmlSymbols.TITLE); xs.text(OPML_TITLE); xs.endTag(null, OpmlSymbols.TITLE); + xs.text("\n"); + xs.text(" "); + xs.startTag(null, OpmlSymbols.DATE_CREATED); + xs.text(DateUtils.formatRFC822Date(new Date())); + xs.endTag(null, OpmlSymbols.DATE_CREATED); + xs.text("\n"); + xs.text(" "); xs.endTag(null, OpmlSymbols.HEAD); + xs.text("\n"); + xs.text(" "); xs.startTag(null, OpmlSymbols.BODY); + xs.text("\n"); for (Feed feed : feeds) { + xs.text(" "); xs.startTag(null, OpmlSymbols.OUTLINE); xs.attribute(null, OpmlSymbols.TEXT, feed.getTitle()); xs.attribute(null, OpmlSymbols.TITLE, feed.getTitle()); @@ -55,11 +73,14 @@ public class OpmlWriter { xs.attribute(null, OpmlSymbols.HTMLURL, feed.getLink()); } xs.endTag(null, OpmlSymbols.OUTLINE); + xs.text("\n"); } + xs.text(" "); xs.endTag(null, OpmlSymbols.BODY); + xs.text("\n"); xs.endTag(null, OpmlSymbols.OPML); + xs.text("\n"); xs.endDocument(); - if (BuildConfig.DEBUG) - Log.d(TAG, "Finished writing document"); + Log.d(TAG, "Finished writing document"); } } |