FileDocCategorySizeDatePackage
ViewMonthJDOM.javaAPI DocExample2513Sun Sep 02 14:59:06 BST 2001com.oreilly.forum.xml

ViewMonthJDOM

public class ViewMonthJDOM extends Object
Creates the JDOM for the month view of a board.

Fields Summary
Constructors Summary
private ViewMonthJDOM()

    
Methods Summary
public static ElementproduceElement(BoardSummary board, MonthYear month)

param
board the message board to generate JDOM for.
param
month the month and year to view.

        Element viewMonthElem = new Element("viewMonth");
        viewMonthElem.addAttribute("month",
                Integer.toString(month.getMonth()));
        viewMonthElem.addAttribute("year",
                Integer.toString(month.getYear()));

        // create the <board> element...
        Element boardElem = BoardSummaryJDOM.produceNameIDElement(board);
        viewMonthElem.addContent(boardElem);

        DataAdapter adapter = DataAdapter.getInstance();

        MessageTree msgTree = new MessageTree(adapter.getAllMessages(
                board.getID(), month));

        // get an iterator of MessageSummary objects
        Iterator msgs = msgTree.getTopLevelMessages();

        while (msgs.hasNext()) {
            MessageSummary curMsg = (MessageSummary) msgs.next();
            Element elem = produceMessageElement(curMsg, msgTree);
            viewMonthElem.addContent(elem);
        }

        return viewMonthElem;
    
private static ElementproduceMessageElement(MessageSummary msg, MessageTree msgTree)
Produce a fragment of XML for an individual message. This is a recursive function.

        Element msgElem = new Element("message");
        msgElem.addAttribute("id", Long.toString(msg.getID()));
        msgElem.addAttribute("day",
                Integer.toString(msg.getCreateDate().getDay()));

        msgElem.addContent(new Element("subject")
                .setText(msg.getSubject()));
        msgElem.addContent(new Element("authorEmail")
                .setText(msg.getAuthorEmail()));

        Iterator iter = msgTree.getReplies(msg);
        while (iter.hasNext()) {
            MessageSummary curReply = (MessageSummary) iter.next();

            // recursively build the XML for all replies
            msgElem.addContent(produceMessageElement(curReply, msgTree));
        }
        return msgElem;