From 2a7845ee655780696ca5314d861435930f4f4e0c Mon Sep 17 00:00:00 2001 From: Cj Malone Date: Mon, 31 Oct 2016 15:06:31 +0000 Subject: [PATCH] Indent exported files --- .../antennapod/core/export/CommonSymbols.java | 2 ++ .../core/export/html/HtmlWriter.java | 12 +----------- .../core/export/opml/OpmlWriter.java | 18 +----------------- 3 files changed, 4 insertions(+), 28 deletions(-) diff --git a/core/src/main/java/de/danoeh/antennapod/core/export/CommonSymbols.java b/core/src/main/java/de/danoeh/antennapod/core/export/CommonSymbols.java index 020a0671f..3ed251047 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/export/CommonSymbols.java +++ b/core/src/main/java/de/danoeh/antennapod/core/export/CommonSymbols.java @@ -19,4 +19,6 @@ public class CommonSymbols { public static final String BODY = "body"; public static final String TITLE = "title"; + public static final String XML_FEATURE_INDENT_OUTPUT = "http://xmlpull.org/v1/doc/features.html#indent-output"; + } diff --git a/core/src/main/java/de/danoeh/antennapod/core/export/html/HtmlWriter.java b/core/src/main/java/de/danoeh/antennapod/core/export/html/HtmlWriter.java index 2fdd8ffa6..c24b39812 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/export/html/HtmlWriter.java +++ b/core/src/main/java/de/danoeh/antennapod/core/export/html/HtmlWriter.java @@ -33,29 +33,22 @@ public class HtmlWriter implements ExportWriter { throws IllegalArgumentException, IllegalStateException, IOException { Log.d(TAG, "Starting to write document"); XmlSerializer xs = Xml.newSerializer(); + xs.setFeature(HtmlSymbols.XML_FEATURE_INDENT_OUTPUT, true); xs.setOutput(writer); xs.startDocument(ENCODING, false); - xs.text("\n"); xs.startTag(null, HtmlSymbols.HTML); - xs.text("\n"); xs.startTag(null, HtmlSymbols.HEAD); - xs.text("\n"); xs.startTag(null, HtmlSymbols.TITLE); xs.text(HTML_TITLE); xs.endTag(null, HtmlSymbols.TITLE); - xs.text("\n"); xs.endTag(null, HtmlSymbols.HEAD); - xs.text("\n"); xs.startTag(null, HtmlSymbols.BODY); - xs.text("\n"); xs.startTag(null, HtmlSymbols.HEADING); xs.text(HTML_TITLE); xs.endTag(null, HtmlSymbols.HEADING); - xs.text("\n"); xs.startTag(null, HtmlSymbols.ORDERED_LIST); - xs.text("\n"); for (Feed feed : feeds) { xs.startTag(null, HtmlSymbols.LIST_ITEM); xs.text(feed.getTitle()); @@ -74,13 +67,10 @@ public class HtmlWriter implements ExportWriter { xs.endTag(null, HtmlSymbols.LINK); xs.text("]"); xs.endTag(null, HtmlSymbols.LIST_ITEM); - xs.text("\n"); } xs.endTag(null, HtmlSymbols.ORDERED_LIST); xs.endTag(null, HtmlSymbols.BODY); - xs.text("\n"); xs.endTag(null, HtmlSymbols.HTML); - xs.text("\n"); xs.endDocument(); Log.d(TAG, "Finished writing document"); } diff --git a/core/src/main/java/de/danoeh/antennapod/core/export/opml/OpmlWriter.java b/core/src/main/java/de/danoeh/antennapod/core/export/opml/OpmlWriter.java index afd652cff..fd0922f72 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/export/opml/OpmlWriter.java +++ b/core/src/main/java/de/danoeh/antennapod/core/export/opml/OpmlWriter.java @@ -35,36 +35,24 @@ public class OpmlWriter implements ExportWriter { throws IllegalArgumentException, IllegalStateException, IOException { Log.d(TAG, "Starting to write document"); XmlSerializer xs = Xml.newSerializer(); + xs.setFeature(OpmlSymbols.XML_FEATURE_INDENT_OUTPUT, true); 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()); @@ -76,13 +64,9 @@ public class OpmlWriter implements ExportWriter { 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(); Log.d(TAG, "Finished writing document"); }