class HtmlFormBuilder {

    public String build(DataForm form) {
        if (form == null)
            return "";

        StringBuilder sb = new StringBuilder();
        List<String> instructions = form.getInstructions();
        for (String instruction: instructions) {
            sb.append("<p class='instruction'>" + instruction + "</p>");
        }

        Iterator<FormField> fields = form.getFields().iterator();
        while (fields.hasNext()) {
            FormField field = fields.next();
            FormField.Type type = field.getType();
            sb.append("<p>");
            if (type == FormField.Type.hidden) {
                sb.append(hiddenFieldToHtml(field));
            } else if (type == FormField.Type.fixed) {
                sb.append(fixedFieldToHtml(field));
            } else if (type == FormField.Type.jid_single) {
                sb.append(jidSingleFieldToHtml(field));
            } else if (type == FormField.Type.text_single || type == null) {
                sb.append(textSingleFieldToHtml(field));
            } else if (type == FormField.Type.text_private) {
                sb.append(textPrivateFieldToHtml(field));
            } else if (type == FormField.Type.text_multi) {
                sb.append(textMultiFieldToHtml(field));
            } else if (type == FormField.Type.list_single) {
                sb.append(listSingleFieldToHtml(field));
            } else if (type == FormField.Type.list_multi) {
                sb.append(listMultiFieldToHtml(field));
            } else if (type == FormField.Type.jid_multi) {
                // for now, do jid-multi as a textarea
                sb.append(textMultiFieldToHtml(field));
            } else if (type == FormField.Type.bool) {
                sb.append(booleanFieldToHtml(field));
            } else {
                throw new RuntimeException("Unknown field type: " + type);
            }
            sb.append(descToHtml(field));
            sb.append("</p>");
        }

        return sb.toString();
    }

}