Webiyo

This page was generated using Webiyo. See its source code and unit tests.

org/webiyo/examples/sourceforge/ChangeLogPage.java

package org.webiyo.examples.sourceforge;

import org.webiyo.util.MultiMap;
import org.webiyo.web.HtmlWriter;
import org.webiyo.web.Location;
import org.webiyo.xml.dtds.Html;

import java.io.IOException;
import java.text.DateFormat;
import java.util.Date;
import java.util.List;
import java.util.TimeZone;

import static org.webiyo.web.Att.cssClass;
import static org.webiyo.xml.dtds.Html.DD;
import static org.webiyo.xml.dtds.Html.P;
import static org.webiyo.xml.dtds.Html.DL;
import static org.webiyo.xml.dtds.Html.H3;
import static org.webiyo.xml.dtds.Html.H2;
import static org.webiyo.xml.dtds.Html.DIV;

class ChangeLogPage extends Page {

    private static final TimeZone TIME_ZONE = TimeZone.getTimeZone("America/Los_Angeles");
    private static final DateFormat FORMAT = LogEntry.makeFormat("MMMMM d, yyyy", TIME_ZONE);

    private final ChangeLog log;

    public ChangeLogPage(Project project) throws IOException {
        super(project);
        this.log = project.loadChangeLog();
    }

    public Location getLocation() {
        return SiteMap.CHANGELOG;
    }

    // end of public methods

    protected String title() {
        return super.title() + " - Development History";
    }

    protected void renderRightSide(HtmlWriter out) throws IOException {
        out.startTag(DIV, cssClass("changelog"));

        out.text(H2, "Development History");

        if (log.entries().size() == 0) {
            out.text(P, "No entries found");
        } else {
            renderChangeLog(out);
        }

        out.endTag(DIV);
    }

    // end of protected methods

    private void renderChangeLog(HtmlWriter out) throws IOException {
        MultiMap<Date, LogEntry> groups = log.entriesGroupedByDay(TIME_ZONE);

        for (Date day : groups.keySet()) {
            List<LogEntry> entries = groups.get(day);
            renderEntriesForOneDay(out, day, entries);
        }
    }

    private void renderEntriesForOneDay(HtmlWriter out, Date day, List<LogEntry> entries) throws IOException {
        out.startTag(DIV);
        out.text(H3, FORMAT.format(day));

        out.startTag(DL);

        String prevAuthor = null;
        for (LogEntry entry : entries) {
            if (!entry.getAuthor().equals(prevAuthor)) {
                out.text(Html.DT, entry.getAuthor());
            }

            renderComment(out, entry);

            prevAuthor = entry.getAuthor();
        }
        out.endTag(DL);

        out.endTag(DIV);
    }

    private void renderComment(HtmlWriter out, LogEntry entry) throws IOException {
        out.startTag(DD);

        boolean first = true;
        for (String line : entry.getComment().split("\n")) {
            if (!first) out.br();
            out.text(line);
            first = false;
        }

        out.endTag(DD);
    }

}

SourceForge