Indent exported files

This commit is contained in:
Cj Malone 2016-10-31 15:06:31 +00:00
parent cba6e728d2
commit 2a7845ee65
3 changed files with 4 additions and 28 deletions

View File

@ -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";
}

View File

@ -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");
}

View File

@ -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");
}