Completed demo.

This commit is contained in:
Christian P. MOMON 2017-05-09 10:07:55 +02:00
parent 672380ce2e
commit acc2653f04

View file

@ -18,7 +18,22 @@
*/ */
package fr.devinsy.util.rss.demo; 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. * The Class RssDemo.
@ -30,27 +45,48 @@ public class RSSDemo
* *
* @param args * @param args
* the arguments * 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 // #1
{ {
StringList strings = new StringList(); System.out.println("========== DEMO #1;");
strings.appendln("========== DEMO #1;"); StringListWriter target = new StringListWriter();
strings.appendln(); RSSWriter out = new RSSWriter(target);
System.out.println(strings.toString()); //
} List<RSSElement> elements = new ArrayList<RSSElement>();
elements.add(new RSSElement("pubDate", DateTime.now()));
elements.add(new RSSElement("lastBuildDate", DateTime.now()));
elements.add(new RSSElement("generator", "Generated by Kiwa"));
// #2 //
{ out.writeChannel("my FEED_TITLE", "https://www.devinsy.fr/rss/news-en.rss", "my FEED_DESCRIPTION", elements.toArray(new RSSElement[0]));
StringList strings = new StringList();
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 <christian.momon@devinsy.fr>"));
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()));
} }
} }
} }