From acc2653f04ffd1d95826bf32e5ce1bcd31fae31d Mon Sep 17 00:00:00 2001 From: "Christian P. MOMON" Date: Tue, 9 May 2017 10:07:55 +0200 Subject: [PATCH] Completed demo. --- src/fr/devinsy/util/rss/demo/RSSDemo.java | 62 ++++++++++++++++++----- 1 file changed, 49 insertions(+), 13 deletions(-) diff --git a/src/fr/devinsy/util/rss/demo/RSSDemo.java b/src/fr/devinsy/util/rss/demo/RSSDemo.java index 2483e78..1cce745 100644 --- a/src/fr/devinsy/util/rss/demo/RSSDemo.java +++ b/src/fr/devinsy/util/rss/demo/RSSDemo.java @@ -18,7 +18,22 @@ */ package fr.devinsy.util.rss.demo; -import fr.devinsy.util.strings.StringList; +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; + +import javax.xml.stream.XMLStreamException; + +import org.apache.log4j.BasicConfigurator; +import org.apache.log4j.Level; +import org.apache.log4j.Logger; +import org.joda.time.DateTime; + +import fr.devinsy.util.rss.RSSElement; +import fr.devinsy.util.rss.RSSWriter; +import fr.devinsy.util.strings.StringListWriter; +import fr.devinsy.util.xml.XMLBadFormatException; +import fr.devinsy.util.xml.XMLTools; /** * The Class RssDemo. @@ -30,27 +45,48 @@ public class RSSDemo * * @param args * the arguments + * @throws IOException + * @throws XMLBadFormatException + * @throws XMLStreamException */ - public static void main(final String[] args) + public static void main(final String[] args) throws IOException, XMLStreamException, XMLBadFormatException { + // + BasicConfigurator.configure(); + Logger.getRootLogger().setLevel(Level.ERROR); + // #1 { - StringList strings = new StringList(); + System.out.println("========== DEMO #1;"); - strings.appendln("========== DEMO #1;"); - strings.appendln(); + StringListWriter target = new StringListWriter(); + RSSWriter out = new RSSWriter(target); - System.out.println(strings.toString()); - } + // + List elements = new ArrayList(); + elements.add(new RSSElement("pubDate", DateTime.now())); + elements.add(new RSSElement("lastBuildDate", DateTime.now())); + elements.add(new RSSElement("generator", "Generated by Kiwa")); - // #2 - { - StringList strings = new StringList(); + // + out.writeChannel("my FEED_TITLE", "https://www.devinsy.fr/rss/news-en.rss", "my FEED_DESCRIPTION", elements.toArray(new RSSElement[0])); - strings.appendln("========== DEMO #2;"); - strings.appendln(); + // + elements.clear(); + elements.add(new RSSElement("guid", "devinsy-news-000001", "isPermaLink", "false")); + elements.add(new RSSElement("pubDate", DateTime.now())); + elements.add(new RSSElement("author", "Christian P. MOMON ")); + elements.add(new RSSElement("category", "Announce")); - System.out.println(strings.toString()); + // + out.writeItem("First news", null, null, elements.toArray(new RSSElement[0])); + + // + out.close(); + + // + System.out.println(target.toString()); + System.out.println(XMLTools.indent(target.toString())); } } }