Webiyo

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

org/webiyo/xml/dtds/Html.java

package org.webiyo.xml.dtds;

import org.webiyo.xml.AttributeType;
import org.webiyo.xml.CharEntity;
import org.webiyo.xml.DocType;
import org.webiyo.xml.TagType;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

import static java.util.Arrays.asList;

public class Html {

    private Html() {
    }

    private static AttributeType att(String name) {
        return new AttributeType(name);
    }

    public static final AttributeType HREF = att("href");
    public static final AttributeType REL = att("rel");
    public static final AttributeType TYPE = att("type");
    public static final AttributeType CLASS = att("class");
    public static final AttributeType SRC = att("src");
    public static final AttributeType ALT = att("alt");
    public static final AttributeType WIDTH = att("width");
    public static final AttributeType HEIGHT = att("height");
    public static final AttributeType COLSPAN = att("colspan");
    public static final AttributeType ROWSPAN = att("rowspan");
    public static final AttributeType METHOD = att("method");
    public static final AttributeType ACTION = att("action");
    public static final AttributeType NAME = att("name");
    public static final AttributeType VALUE = att("value");

    private static TagType tag(String name) {
        return new TagType(name, true);
    }

    private static TagType noNewlineTag(String name) {
        return new TagType(name, false);
    }

    public static final TagType HTML = tag("html");
    public static final TagType HEAD = tag("head");
    public static final TagType LINK = tag("link");
    public static final TagType TITLE = tag("title");
    public static final TagType STYLE = tag("style");
    public static final TagType BODY = tag("body");
    public static final TagType H1 = tag("h1");
    public static final TagType H2 = tag("h2");
    public static final TagType H3 = tag("h3");
    public static final TagType P = tag("p");
    public static final TagType TABLE = tag("table");
    public static final TagType TR = tag("tr");
    public static final TagType TD = tag("td");
    public static final TagType TH = tag("th");
    public static final TagType DIV = tag("div");
    public static final TagType BR = tag("br");
    public static final TagType PRE = tag("pre");

    public static final TagType FORM = tag("form");
    public static final TagType INPUT = tag("input");

    public static final TagType A = noNewlineTag("a");
    public static final TagType IMG = noNewlineTag("img");
    public static final TagType SPAN = noNewlineTag("span");

    public static final TagType DL = tag("dl");
    public static final TagType DT = tag("dt");
    public static final TagType DD = tag("dd");
    public static final TagType UL = tag("ul");
    public static final TagType LI = tag("li");

    public static final CharEntity NBSP = new CharEntity("nbsp", (char) 160);

    public static final DocType DOCTYPE =
            new DocType(HTML, "-//W3C//DTD XHTML 1.0 Transitional//EN",
                        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd");

    static {
        List<TagType> inline = asList(A, IMG, BR, SPAN, INPUT);
        List<TagType> block = asList(P, H1, H2, H3, DIV, TABLE, DL, UL, PRE, FORM);
        List<TagType> flow = concat(inline, block);

        HTML.allow(HEAD, BODY);
        HEAD.allow(TITLE, LINK, STYLE);
        BODY.allow(flow);

        P.allow(inline);
        H1.allow(inline);
        H2.allow(inline);
        H3.allow(inline);
        PRE.allow(inline);
        DIV.allow(flow);
        FORM.allow(flow); // TODO: is this right? FORM shouldn't allow FORM, should it?

        TABLE.allow(TR);
        TR.allow(TD, TH);
        TD.allow(flow);

        A.allow(IMG);

        DL.allow(DT, DD);
        DD.allow(flow);

        UL.allow(LI);
        LI.allow(flow);
    }

    private static List<TagType> concat(List<TagType> list1, List<TagType> list2) {
        List<TagType> result = Collections.checkedList(new ArrayList<TagType>(), TagType.class);
        result.addAll(list1);
        result.addAll(list2);
        return result;
    }

}

SourceForge