This page was generated using Webiyo. See its source code and unit tests.
|
org/webiyo/examples/sourceforge/Page.javapackage org.webiyo.examples.sourceforge; import org.webiyo.web.*; import java.io.IOException; import static org.webiyo.web.Att.cssClass; import static org.webiyo.web.Att.att; import static org.webiyo.xml.dtds.Html.*; abstract class Page implements Renderable { protected final Project project; public Page(Project project) { this.project = project; } public abstract Location getLocation(); public void render(HtmlWriter out) throws IOException { out.startPage(DOCTYPE); renderHead(out); renderBody(out); out.endPage(); } // end of public methods protected String title() { return project.getName(); } protected abstract void renderRightSide(HtmlWriter out) throws IOException; // end of protected methods private void renderHead(HtmlWriter out) throws IOException { out.startTag(HEAD); out.text(TITLE, title()); out.tag(LINK, new StyleSheet(SiteMap.STYLESHEET.toRelativeLink(getLocation()))); out.endTag(HEAD); } private void renderBody(HtmlWriter out) throws IOException { out.startTag(BODY); out.text(H1, "Webiyo"); out.startTag(TABLE); out.startTag(TR); renderLeftSideTop(out); out.startTag(TD, cssClass("right-side"), att(ROWSPAN, 2)); renderRightSide(out); out.endTag(TD); out.endTag(TR); out.startTag(TR); renderLeftSideBottom(out); out.endTag(TR); out.endTag(TABLE); out.endTag(BODY); } private void renderLeftSideTop(HtmlWriter out) throws IOException { out.startTag(TD, cssClass("left-side-top")); renderSiteMap(out); renderSeeSource(out); out.endTag(TD); } private void renderSiteMap(HtmlWriter out) throws IOException { out.startTag(UL); renderLink(out, SiteMap.HOME.toRelativeLink(getLocation()), "Home"); renderLink(out, SiteMap.CHANGELOG.toRelativeLink(getLocation()), "Development History"); renderLink(out, project.getSourceforgeProjectLink(), "SourceForge Project"); out.endTag(UL); } private void renderSeeSource(HtmlWriter out) throws IOException { out.startTag(DIV, cssClass("see-source")); out.text("This page was generated using Webiyo."); Location sourcePageLocation = SiteMap.getSourcePageLocation(project.getSourceIndex(), getClass().getName()); Location unitTestSourcePageLocation = SiteMap.getSourcePageLocation(project.getSourceIndex(), getClass().getName() + "Test"); if (sourcePageLocation != null && unitTestSourcePageLocation != null) { out.text(" See its "); renderLink(out, sourcePageLocation, "source code"); out.text(" and "); renderLink(out, unitTestSourcePageLocation, "unit tests."); } else if (sourcePageLocation != null) { out.text(" See its "); renderLink(out, sourcePageLocation, "source code."); } out.endTag(DIV); } private void renderLink(HtmlWriter out, Location link, String linkText) throws IOException { out.textLink(link.toRelativeLink(getLocation()), linkText); } private void renderLeftSideBottom(HtmlWriter out) throws IOException { out.startTag(TD, cssClass("left-side-bottom")); renderSourceforgeLogo(out); out.endTag(TD); } private void renderSourceforgeLogo(HtmlWriter out) throws IOException { out.startTag(A, Project.SOURCEFORGE_NET); out.img(project.getSourceForgeImage()); out.endTag(A); } private static void renderLink(HtmlWriter out, Link link, String label) throws IOException { out.startTag(LI); out.startTag(A, link); out.nonBreakingText(label); out.endTag(A); out.endTag(LI); } } |