?? htmlbuilder.java
字號:
/* * Copyright 2004 original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */package org.extremecomponents.util;import org.apache.commons.lang.StringUtils;/** * @author Jeff Johnston */public class HtmlBuilder { StringBuffer sb = new StringBuffer(); /** * */ public HtmlBuilder format(int tabs, int newlines) { tabs(tabs); newlines(newlines); return this; } /** * */ public HtmlBuilder tabs(int tabs) { for (int i = 0; i < tabs; i++) { tab(); } return this; } /** * */ public HtmlBuilder newlines(int newlines) { for (int i = 0; i < newlines; i++) { newline(); } return this; } /** * */ public HtmlBuilder tab() { sb.append("\t"); return this; } /** * */ public HtmlBuilder newline() { sb.append("\n"); return this; } /** * */ public HtmlBuilder append(Object append) { sb.append(append); return this; } /** * */ public HtmlBuilder close() { sb.append(">"); return this; } /** * */ public HtmlBuilder table(int tabs) { newline(); tabs(tabs); sb.append("<table"); return this; } /** * */ public HtmlBuilder tableEnd(int tabs) { newline(); tabs(tabs); sb.append("</table>"); return this; } /** * */ public HtmlBuilder tr(int tabs) { newline(); tabs(tabs); sb.append("<tr"); return this; } /** * */ public HtmlBuilder trEnd(int tabs) { newline(); tabs(tabs); sb.append("</tr>"); return this; } /** * */ public HtmlBuilder th(int tabs) { newline(); tabs(tabs); sb.append("<th"); return this; } /** * */ public HtmlBuilder thEnd() { sb.append("</th>"); return this; } /** * */ public HtmlBuilder td(int tabs) { newline(); tabs(tabs); sb.append("<td"); return this; } /** * */ public HtmlBuilder tdEnd() { sb.append("</td>"); return this; } /** * */ public HtmlBuilder input(String type) { sb.append("<input type=\"").append(type).append("\" "); return this; } /** * */ public HtmlBuilder select() { sb.append("<select"); return this; } /** * */ public HtmlBuilder selectEnd() { sb.append("</select>"); return this; } /** * */ public HtmlBuilder option() { sb.append("<option"); return this; } /** * */ public HtmlBuilder optionEnd() { sb.append("</option>"); return this; } /** * */ public HtmlBuilder form() { newline(); sb.append("<form"); return this; } /** * */ public HtmlBuilder formEnd() { newline(); sb.append("</form>"); return this; } /** * */ public HtmlBuilder name(String name) { if (StringUtils.isNotBlank(name)) { sb.append(" name=\"").append(name).append("\" "); } return this; } /** * */ public HtmlBuilder value(String value) { if (StringUtils.isNotBlank(value)) { sb.append(" value=\"").append(value).append("\" "); } else { sb.append(" value=\"").append("\" "); } return this; } /** * */ public HtmlBuilder title(String title) { if (StringUtils.isNotBlank(title)) { sb.append(" title=\"").append(title).append("\" "); } return this; } /** * */ public HtmlBuilder action(String action) { if (StringUtils.isNotBlank(action)) { sb.append(" action=\"").append(action).append("\" "); } return this; } /** * */ public HtmlBuilder method(String method) { if (StringUtils.isNotBlank(method)) { sb.append(" method=\"").append(method).append("\" "); } return this; } /** * */ public HtmlBuilder enctype(String enctype) { if (StringUtils.isNotBlank(enctype)) { sb.append(" enctype=\"").append(enctype).append("\" "); } return this; } /** * */ public HtmlBuilder onchange(String onchange) { if (StringUtils.isNotBlank(onchange)) { sb.append(" onchange=\"").append(onchange).append("\" "); } return this; } /** * */ public HtmlBuilder onsubmit(String onsubmit) { if (StringUtils.isNotBlank(onsubmit)) { sb.append(" onsubmit=\"").append(onsubmit).append("\" "); } return this; } /** * */ public HtmlBuilder onclick(String onclick) { if (StringUtils.isNotBlank(onclick)) { sb.append(" onclick=\"").append(onclick).append("\" "); } return this; } /** * */ public HtmlBuilder onmouseover(String onmouseover) { if (StringUtils.isNotBlank(onmouseover)) { sb.append(" onmouseover=\"").append(onmouseover).append("\" "); } return this; } /** * */ public HtmlBuilder onmouseout(String onmouseout) { if (StringUtils.isNotBlank(onmouseout)) { sb.append(" onmouseout=\"").append(onmouseout).append("\" "); } return this; } /** * */ public HtmlBuilder onkeypress(String onkeypress) { if (StringUtils.isNotBlank(onkeypress)) { sb.append(" onkeypress=\"").append(onkeypress).append("\" "); } return this; } /** * */ public HtmlBuilder id(String id) { if (StringUtils.isNotBlank(id)) { sb.append(" id=\"").append(id).append("\" "); } return this; } /** * */ public HtmlBuilder styleClass(String styleClass) { if (StringUtils.isNotBlank(styleClass)) { sb.append(" class=\"").append(styleClass).append("\" "); } return this; } /** * */ public HtmlBuilder style(String style) { if (StringUtils.isNotBlank(style)) { sb.append(" style=\"").append(style).append("\" "); } return this; } /** * */ public HtmlBuilder width(String width) { if (StringUtils.isNotBlank(width)) { sb.append(" width=\"").append(width).append("\" "); } return this; } /** * */ public HtmlBuilder align(String align) { if (StringUtils.isNotBlank(align)) { sb.append(" align=\"").append(align).append("\" "); } return this; } /** * */ public HtmlBuilder valign(String valign) { if (StringUtils.isNotBlank(valign)) { sb.append(" valign=\"").append(valign).append("\" "); } return this; } /** * */ public HtmlBuilder border(String border) { if (StringUtils.isNotBlank(border)) { sb.append(" border=\"").append(border).append("\" "); } return this; } /** * */ public HtmlBuilder cellPadding(String cellPadding) { if (StringUtils.isNotBlank(cellPadding)) { sb.append(" cellpadding=\"").append(cellPadding).append("\" "); } return this; } /** * */ public HtmlBuilder cellSpacing(String cellSpacing) { if (StringUtils.isNotBlank(cellSpacing)) { sb.append(" cellspacing=\"").append(cellSpacing).append("\" "); } return this; } /** * */ public HtmlBuilder colSpan(String colspan) { if (StringUtils.isNotBlank(colspan)) { sb.append(" colspan=\"").append(colspan).append("\" "); } return this; } /** * */ public HtmlBuilder rowSpan(String rowspan) { if (StringUtils.isNotBlank(rowspan)) { sb.append(" rowspan=\"").append(rowspan).append("\" "); } return this; } /** * */ public HtmlBuilder span() { sb.append("<span"); return this; } /** * */ public HtmlBuilder spanEnd() { sb.append("</span>"); return this; } /** */ public HtmlBuilder div() { sb.append("<div"); return this; } /** * */ public HtmlBuilder divEnd() { sb.append("</div>"); return this; } /** * */ public HtmlBuilder param(String name, String value) { append(name); equals(); append(value); return this; } /** * */ public HtmlBuilder a(String href) { append("<a href="); quote(); append(href); quote(); return this; } /** * */ public HtmlBuilder a() { sb.append("<a href="); return this; } /** * */ public HtmlBuilder aEnd() { sb.append("</a>"); return this; } /** * */ public HtmlBuilder bold() { sb.append("<b>"); return this; } /** * */ public HtmlBuilder boldEnd() { sb.append("</b>"); return this; } /** * */ public HtmlBuilder quote() { sb.append("\""); return this; } /** * */ public HtmlBuilder question() { sb.append("?"); return this; } /** * */ public HtmlBuilder equals() { sb.append("="); return this; } /** * */ public HtmlBuilder ampersand() { sb.append("&"); return this; } /** * */ public HtmlBuilder img(String src) { sb.append("<img src=\"").append(src).append("\" style=\"border:0\">"); return this; } /** * <img src="" style="border:0"> */ public HtmlBuilder img(String img, String tooltip) { sb.append("<img src=\"").append(img).append("\" style=\"border:0\""); if (tooltip != null) { sb.append(" title=\"").append(tooltip).append("\">"); } return this; } /** * */ public HtmlBuilder textarea() { sb.append("<textarea"); return this; } /** * */ public HtmlBuilder textareaEnd() { sb.append("</textarea>"); return this; } /** * */ public HtmlBuilder cols(String cols) { if (StringUtils.isNotBlank(cols)) { sb.append(" cols=\"").append(cols).append("\" "); } return this; } /** * */ public HtmlBuilder rows(String rows) { if (StringUtils.isNotBlank(rows)) { sb.append(" rows=\"").append(rows).append("\" "); } return this; } public HtmlBuilder checked() { sb.append(" checked=\"checked\""); return this; } public HtmlBuilder readonly() { sb.append(" readonly=\"readonly\""); return this; } public HtmlBuilder nbsp() { sb.append(" "); return this; } /** * */ public HtmlBuilder comment(String comment) { if (StringUtils.isNotBlank(comment)) { sb.append(" <!-- ").append(comment).append(" -->"); } return this; } /** * */ public HtmlBuilder ul() { sb.append("<ul>"); return this; } /** * */ public HtmlBuilder ulEnd() { sb.append("</ul>"); return this; } /** * */ public HtmlBuilder li(String text) { if (StringUtils.isNotBlank(text)) { sb.append("<li>").append(text).append("</li>"); } return this; } /** * */ public HtmlBuilder br() { sb.append("<br>"); return this; } /** * */ public HtmlBuilder disabled() { sb.append(" disabled=\"disabled\" "); return this; } /** * */ public HtmlBuilder nowrap() { sb.append(" nowrap "); return this; } /** * */ public HtmlBuilder maxlength(String maxlength) { if (StringUtils.isNotBlank(maxlength)) { sb.append(" maxlength=\"").append(maxlength).append("\" "); } return this; } /** * */ public HtmlBuilder tbody(int tabs) { newline(); tabs(tabs); sb.append("<tbody"); return this; } /** * */ public HtmlBuilder tbodyEnd(int tabs) { newline(); tabs(tabs); sb.append("</tbody>"); return this; } public HtmlBuilder p() { sb.append("<p"); return this; } public HtmlBuilder pEnd() { sb.append("</p>"); return this; } /** * */ public String toString() { return sb.toString(); }}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -