FileDocCategorySizeDatePackage
ScheduleJDOM.javaAPI DocExample1604Sun Sep 02 14:59:02 BST 2001chap4

ScheduleJDOM

public class ScheduleJDOM extends Object
Produces a JDOM Document for a tv schedule.

Fields Summary
private SimpleDateFormat
dateFmt
Constructors Summary
Methods Summary
public ElementcreateShowElement(Show show)
A helper method to convert a Show object into a JDOM Element.

        Element e = new Element("show");
        e.addContent(new Element("channel").setText(
                Integer.toString(show.getChannel())));
        e.addContent(new Element("from").setText(
                this.dateFmt.format(show.getStartTime())));
        e.addContent(new Element("to").setText(
                this.dateFmt.format(show.getEndTime())));
        e.addContent(new Element("title").setText(show.getTitle()));
        return e;
    
public DocumentgetTodaysShows()

return
a new JDOM Document for all TV shows scheduled for today.

        Schedule sched = Schedule.getInstance();
        Show[] shows = sched.getTodaysShows();

        Element rootElem = new Element("schedule");

        for (int i=0; i<shows.length; i++) {
            rootElem.addContent(createShowElement(shows[i]));
        }
        return new Document(rootElem);
    
public static voidmain(java.lang.String[] args)
Simple main() method for printing the XML document to System.out, useful for testing.


                      
           
        Document doc = new ScheduleJDOM().getTodaysShows();
        new XMLOutputter("  ", true, "UTF-8").output(doc, System.out);