Webiyo

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

org/webiyo/web/HtmlWriter.java

package org.webiyo.web;

import org.webiyo.xml.XmlWriter;

import java.io.File;
import java.io.IOException;

import static org.webiyo.xml.dtds.Html.BR;
import static org.webiyo.xml.dtds.Html.IMG;
import static org.webiyo.xml.dtds.Html.A;
import static org.webiyo.xml.dtds.Html.NBSP;

public class HtmlWriter extends XmlWriter {

    public HtmlWriter(File outputFile) throws IOException {
        super(outputFile);
    }

    public HtmlWriter(Appendable appendable) {
        super(appendable);
    }

    public void render(Object... objects) throws IOException {
        for (Object object : objects) {
            if (object instanceof Renderable) {
                ((Renderable) object).render(this);
            } else {
                text(object.toString());
            }
        }
    }

    public void nonBreakingText(String input) throws IOException {
        int i = 0;
        while (true) {
            int spaceIndex = input.indexOf(' ', i);
            if (spaceIndex == -1) {
                text(input.substring(i));
                return;
            }
            text(input.substring(i, spaceIndex));
            render(NBSP);
            i = spaceIndex + 1;
        }
    }

    public void textLink(Link link, String text) throws IOException {
        startTag(A, link);
        text(text);
        endTag(A);
    }

    public void img(Image image) throws IOException {
        tag(IMG, image);
    }

    public void br() throws IOException {
        tag(BR);
    }
}
SourceForge