18 package org.turro.html;
20 import java.io.IOException;
21 import java.io.StringWriter;
22 import java.io.Writer;
23 import java.util.Stack;
24 import java.util.logging.Level;
25 import java.util.logging.Logger;
26 import org.turro.string.Strings;
27 import org.turro.elephant.context.ElephantContext;
34 protected Stack
tags =
new Stack();
35 protected Writer
out =
null;
37 private String extraAttributes;
41 this.out =
new StringWriter();
51 return out.toString().replaceAll(
"&(?![a-z]+;)",
"&");
59 this.extraAttributes = extraAttributes;
63 return doTag(tag, (String[])
null);
67 return doTag(tag,
new String[] { attributes });
71 if(attributes !=
null) {
73 for(
int i = 0; i < attributes.length; i++) {
74 if(!Strings.isBlank(attributes[i])) {
75 write(
" " + attributes[i]);
81 return write(
"<" + tag +
" />");
86 return startTag(tag, (String[])
null);
90 return startTag(tag,
new String[] { attributes });
95 if(attributes !=
null) {
97 for(
int i = 0; i < attributes.length; i++) {
98 if(!Strings.isBlank(attributes[i])) {
99 write(
" " + attributes[i]);
102 if(!Strings.isBlank(extraAttributes)) {
103 write(
" " + extraAttributes);
104 extraAttributes =
null;
109 return write(
"<" + tag +
">");
119 "href='" + url +
"'",
120 (hint !=
null ?
"title=\"" + hint +
"\"" :
""),
121 (hint !=
null ?
"alt=\"" + hint +
"\"" :
""),
122 "target='" + target +
"'",
123 "onclick='event.stopPropagation();'",
138 "href='" + url +
"'",
139 (hint !=
null ?
"title=\"" + hint +
"\"" :
""),
140 (hint !=
null ?
"alt=\"" + hint +
"\"" :
""),
141 (cssClass !=
null ?
"class='" + cssClass +
"'" :
""),
142 (onClick !=
null ?
"onclick=\"" + onClick +
"\"" :
"")
147 return startTable(
new String[] { attributes });
151 return startTag(
"table", attributes);
189 String tag = (String)
tags.pop();
190 return write(
"</" + tag +
">");
196 while(!tag.equals(tmp)) {
197 tmp = (String)
tags.pop();
198 write(
"</" + tmp +
">");
206 while(!tag.equals(
tags.peek())) {
207 tmp = (String)
tags.pop();
208 write(
"</" + tmp +
">");
214 while(!
tags.empty()) {
221 return tags.contains(tag);
230 }
catch (IOException ex) {
245 startTag(
"div",
"style='height:" + pixels +
"px'");
251 return write(
"\n<script language='JavaScript' type='text/javascript'>\n");
255 return write(
"\n</script>\n");
259 return write(
"\n<style type='text/css'>\n");
263 return write(
"\n</style>\n");
267 return write(
"<link rel=\"stylesheet\" type=\"text/css\" href=\"" +
273 return write(
"<script type=\"text/javascript\" src=\"" +
static String logMsg(String msg)
HTMLGenerator endAllTags()
HTMLGenerator write(String value)
HTMLGenerator startTag(String tag, String attributes)
HTMLGenerator doTag(String tag, String[] attributes)
HTMLGenerator doTag(String tag)
void setExtraAttributes(String extraAttributes)
HTMLGenerator writeNewLine()
HTMLGenerator endTableRow()
HTMLGenerator startAnchor(String url, String hint, String cssClass, String onClick)
HTMLGenerator writeHorizontalStrut(int pixels)
HTMLGenerator startTableCol(String[] attributes)
HTMLGenerator startTag(String tag)
HTMLGenerator startTableRow(String[] attributes)
HTMLGenerator endJavaScript()
HTMLGenerator startTag(String tag, String[] attributes)
HTMLGenerator startTableRow(String attributes)
HTMLGenerator startAnchor(String url, String hint, String cssClass)
HTMLGenerator endTableCol()
boolean checkTag(String tag)
HTMLGenerator endTag(String tag)
HTMLGenerator writeSeparator()
HTMLGenerator startJavaScript()
HTMLGenerator doTag(String tag, String attributes)
HTMLGenerator addJavaScriptLink(String jsFile)
HTMLGenerator(Writer out)
HTMLGenerator startTable(String[] attributes)
HTMLGenerator endBeforeTag(String tag)
HTMLGenerator startTargetAnchor(String url, String target, String hint)
HTMLGenerator startExtAnchor(String url, String hint)
HTMLGenerator startAnchor(String url, String hint)
HTMLGenerator startTableCol(String attributes)
HTMLGenerator addCSSLink(String cssFile)
HTMLGenerator startTable(String attributes)