public class HtmlElement extends Object implements ApiElement<Element>, Html
MockServletResponse response = new MockServletResponse();
try (HtmlElement html = HtmlElement.of(response)) {
html.addBody().addHeading("Hello!");
}
assertTrue(response.toString().contains("<h1>Hello!</h1>"));
For more information see the
next sample.A, A_ACTION, A_ALT, A_CELLPADDING, A_CELLSPACING, A_CLASS, A_COLS, A_COLSPAN, A_CONTENT, A_FOR, A_HREF, A_HTTP_EQUIV, A_CHARSET, A_CHECKED, A_ID, A_LANG, A_LANGUAGE, A_MAXLENGTH, A_MEDIA, A_METHOD, A_NAME, A_PLACEHOLDER, A_READONLY, A_REL, A_ROWS, A_ROWSPAN, A_SELECTED, A_SRC, A_STYLE, A_TARGET, A_TITLE, A_TYPE, A_VALUE, BODY, BR, BUTTON, DIV, FIELDSET, FORM, H1, H2, H3, HEAD, HEADING_PREFIX, HR, HTML, IMAGE, INPUT, LABEL, LEGEND, LI, LINK, META, NON_BREAKING_SPACE, OL, OPTION, P, PRE, SCRIPT, SELECT, SPAN, STYLE, TABLE, TBODY, TD, TEXT_AREA, TH, THEAD, TITLE, TR, UL, V_BLANK, V_GET, V_HIDDEN, V_CHECKBOX, V_PASSWORD, V_POST, V_RESET, V_STYLESHEET, V_SUBMIT, V_TEXT, V_TEXT_CSS| Constructor and Description |
|---|
HtmlElement(ApiElement root,
HtmlConfig config,
Appendable writer)
Create new instance with empty html headers
|
HtmlElement(HtmlConfig config,
Appendable writer)
Create new instance with empty html headers
|
| Modifier and Type | Method and Description |
|---|---|
Element |
addBody()
Returns a body element
|
Element |
addCDATA(CharSequence charData)
Deprecated.
|
Element |
addComment(CharSequence comment) |
Element |
addCssBodies(CharSequence lineSeparator,
CharSequence... css)
Create a new CSS element and return it.
|
Element |
addCssLink(CharSequence css)
Create a new CSS element and return it
|
void |
addCssLinks(CharSequence... css)
Create a new CSS element and return it
|
Element |
addElement(String name)
Create new Element
|
Element |
addHead()
Returns a head element
|
Element |
addJavascriptBody(CharSequence... javascript)
Create a new Javascript element and return it.
|
Element |
addJavascriptContents(CharSequence javascript)
Deprecated.
|
Element |
addJavascriptLink(boolean defer,
CharSequence javascriptLink)
Create a new Javascript element and return it
|
void |
addJavascriptLinks(boolean defer,
CharSequence... javascriptLinks)
Create a new Javascript element and return it
|
Element |
addRawText(Object value) |
Element |
addText(Object value) |
Element |
addTextTemplated(CharSequence template,
Object... values) |
void |
close() |
Element |
getBody()
Returns a body element
|
HtmlConfig |
getConfig()
Get config
|
Element |
getHead()
Returns a head element
|
CharSequence |
getName() |
CharSequence |
getTitle()
Get title of configuration
|
static HtmlElement |
niceOf(javax.servlet.http.HttpServletResponse response,
CharSequence... cssLinks)
Create new instance with empty html headers
|
static HtmlElement |
niceOf(CharSequence title,
javax.servlet.http.HttpServletResponse response,
CharSequence... cssLinks)
Create new instance with empty html headers
|
static HtmlElement |
niceOf(CharSequence title,
javax.servlet.http.HttpServletResponse response,
Charset charset,
CharSequence... cssLinks)
Create new instance with empty html headers
|
static HtmlElement |
of(HtmlConfig config)
Create new instance with empty html headers
|
static HtmlElement |
of(HtmlConfig config,
Appendable writer)
Create root element for a required element name
|
static HtmlElement |
of(HtmlConfig config,
javax.servlet.http.HttpServletResponse response)
A base method to create new instance with empty html headers
|
static HtmlElement |
of(javax.servlet.http.HttpServletRequest request,
javax.servlet.http.HttpServletResponse response)
A base method to create new instance
|
static HtmlElement |
of(javax.servlet.http.HttpServletRequest request,
javax.servlet.http.HttpServletResponse response,
HtmlConfig config)
A base method to create new instance
|
static HtmlElement |
of(javax.servlet.http.HttpServletResponse response,
HtmlConfig config)
Deprecated.
Use the method
of(org.ujorm.tools.xml.config.HtmlConfig, javax.servlet.http.HttpServletResponse) rather. |
static HtmlElement |
of(javax.servlet.http.HttpServletResponse response,
CharSequence... cssLinks)
Create new instance with empty html headers
|
static HtmlElement |
of(CharSequence title,
javax.servlet.http.HttpServletResponse response,
CharSequence... cssLinks)
Create new instance with empty html headers
|
static HtmlElement |
of(CharSequence title,
javax.servlet.http.HttpServletResponse response,
Charset charset,
CharSequence... cssLinks)
Create new instance with empty html headers
|
Element |
original()
Get an original root element
|
Element |
setAttribute(String name,
Object value) |
String |
toString()
Returns an Render the HTML code including header.
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitsetAttribpublic HtmlElement(@Nonnull HtmlConfig config, @Nonnull Appendable writer)
public HtmlElement(@Nonnull ApiElement root, @Nonnull HtmlConfig config, @Nonnull Appendable writer)
public CharSequence getName()
getName in interface ApiElement<Element>public Element setAttribute(String name, Object value)
setAttribute in interface ApiElement<Element>public Element addText(Object value)
addText in interface ApiElement<Element>public Element addTextTemplated(@Nonnull CharSequence template, @Nonnull Object... values)
addTextTemplated in interface ApiElement<Element>public Element addRawText(Object value)
addRawText in interface ApiElement<Element>public Element addComment(CharSequence comment)
addComment in interface ApiElement<Element>@Deprecated public Element addCDATA(CharSequence charData)
addCDATA in interface ApiElement<Element>@Nonnull public final Element addElement(@Nonnull String name) throws IllegalStateException
addElement in interface ApiElement<Element>name - The element nameIllegalStateException - An envelope for IO exceptionspublic Element getHead()
public Element addHead()
public void addJavascriptLinks(boolean defer,
@Nonnull
CharSequence... javascriptLinks)
javascriptLinks - URL list to Javascriptdefer - A script that will not run until after the page has loadedpublic Element addJavascriptLink(boolean defer, @Nonnull CharSequence javascriptLink)
javascriptLink - URL to Javascriptdefer - A script that will not run until after the page has loaded@Deprecated public Element addJavascriptContents(@Nonnull CharSequence javascript)
addJavascriptBody(java.lang.CharSequence...) ratherpublic Element addJavascriptBody(@Nullable CharSequence... javascript)
javascript - Add a javascriptLink linkpublic void addCssLinks(@Nonnull CharSequence... css)
css - Add a CSS linkpublic Element addCssLink(@Nonnull CharSequence css)
css - Add a CSS linkpublic Element addCssBodies(@Nonnull CharSequence lineSeparator, @Nonnull CharSequence... css)
lineSeparator - Row separatorcss - CSS content rows@Nonnull public String toString() throws IllegalStateException
toString in class ObjectIllegalStateExceptionpublic void close()
throws IllegalStateException
close in interface Closeableclose in interface AutoCloseableclose in interface ApiElement<Element>IllegalStateException@Nonnull public HtmlConfig getConfig()
public CharSequence getTitle()
@Nonnull public static HtmlElement of(@Nonnull javax.servlet.http.HttpServletResponse response, @Nonnull CharSequence... cssLinks)
IllegalStateException - IO exceptionsMockServletResponse@Nonnull public static HtmlElement of(@Nonnull CharSequence title, @Nonnull javax.servlet.http.HttpServletResponse response, @Nonnull CharSequence... cssLinks)
IllegalStateException - IO exceptionsMockServletResponse@Nonnull public static HtmlElement of(@Nonnull CharSequence title, @Nonnull javax.servlet.http.HttpServletResponse response, @Nonnull Charset charset, @Nonnull CharSequence... cssLinks)
IllegalStateException - IO exceptionsMockServletResponse@Nonnull public static HtmlElement niceOf(@Nonnull CharSequence title, @Nonnull javax.servlet.http.HttpServletResponse response, @Nonnull CharSequence... cssLinks)
IllegalStateException - IO exceptionsMockServletResponse@Nonnull public static HtmlElement niceOf(@Nonnull CharSequence title, @Nonnull javax.servlet.http.HttpServletResponse response, @Nonnull Charset charset, @Nonnull CharSequence... cssLinks)
IllegalStateException - IO exceptionsMockServletResponse@Nonnull public static HtmlElement niceOf(@Nonnull javax.servlet.http.HttpServletResponse response, @Nonnull CharSequence... cssLinks)
IllegalStateException - IO exceptionsMockServletResponse@Nonnull public static HtmlElement of(@Nonnull javax.servlet.http.HttpServletRequest request, @Nonnull javax.servlet.http.HttpServletResponse response) throws IllegalStateException, UnsupportedEncodingException
request - The HttpRequest gets the code page from the context only.response - HttpResponse to write a resultIllegalStateException - IO exceptionsUnsupportedEncodingExceptionMockServletResponse@Nonnull public static HtmlElement of(@Nonnull javax.servlet.http.HttpServletRequest request, @Nonnull javax.servlet.http.HttpServletResponse response, @Nonnull HtmlConfig config) throws IllegalStateException, UnsupportedEncodingException
request - The HttpRequest gets the code page from the context only.response - HttpResponse to write a resultconfig - Html configurationIllegalStateException - IO exceptionsUnsupportedEncodingExceptionMockServletResponse@Deprecated @Nonnull public static HtmlElement of(@Nonnull javax.servlet.http.HttpServletResponse response, @Nonnull HtmlConfig config) throws IllegalStateException
of(org.ujorm.tools.xml.config.HtmlConfig, javax.servlet.http.HttpServletResponse) rather.response - HttpResponse to write a resultconfig - Html configurationIllegalStateException - IO exceptionsMockServletResponse@Nonnull public static HtmlElement of(@Nonnull HtmlConfig config, @Nonnull javax.servlet.http.HttpServletResponse response) throws IllegalStateException
response - HttpResponse to write a resultconfig - Html configurationIllegalStateException - IO exceptionsMockServletResponse@Nonnull public static HtmlElement of(@Nullable HtmlConfig config) throws IllegalStateException
config - Html configurationIllegalStateException - IO exceptionspublic static HtmlElement of(@Nonnull HtmlConfig config, @Nonnull Appendable writer) throws IllegalStateException
IllegalStateExceptionCopyright 2015, Pavel Ponec