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.HIDDEN_NAMEA, 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_ONCLICK, 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, 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(@NotNull ApiElement root,
@NotNull HtmlConfig config,
@NotNull Appendable writer)
Create new instance with empty html headers
|
HtmlElement(@NotNull HtmlConfig config,
@NotNull Appendable writer)
Create new instance with empty html headers
|
| Modifier and Type | Method and Description |
|---|---|
@NotNull Element |
addBody()
Returns a body element
|
Element |
addCDATA(CharSequence charData)
Deprecated.
|
Element |
addComment(CharSequence comment) |
Element |
addCssBodies(@NotNull CharSequence lineSeparator,
CharSequence... css)
Create a new CSS element and return it.
|
Element |
addCssBody(@NotNull CharSequence css)
Create a new CSS element and return it
|
Element |
addCssLink(@NotNull CharSequence css)
Create a new CSS element and return it
|
void |
addCssLinks(CharSequence... css)
Create a new CSS element and return it
|
@NotNull Element |
addElement(@NotNull 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(@NotNull CharSequence javascript)
Deprecated.
|
Element |
addJavascriptLink(boolean defer,
@NotNull 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(@NotNull CharSequence template,
Object... values) |
void |
close() |
@NotNull Element |
getBody()
Returns a body element
|
@NotNull HtmlConfig |
getConfig()
Get config
|
Element |
getHead()
Returns a head element
|
@NotNull String |
getName() |
CharSequence |
getTitle()
Get title of configuration
|
static @NotNull HtmlElement |
niceOf(@NotNull javax.servlet.http.HttpServletResponse response,
CharSequence... cssLinks)
Create new instance with empty html headers
|
static @NotNull HtmlElement |
niceOf(@NotNull CharSequence title,
@NotNull javax.servlet.http.HttpServletResponse response,
CharSequence... cssLinks)
Create new instance with empty html headers
|
static @NotNull HtmlElement |
niceOf(@NotNull CharSequence title,
@NotNull javax.servlet.http.HttpServletResponse response,
@NotNull Charset charset,
CharSequence... cssLinks)
Create new instance with empty html headers
|
static @NotNull HtmlElement |
of(@Nullable HtmlConfig config)
Create new instance with empty html headers
|
static HtmlElement |
of(@NotNull HtmlConfig config,
@NotNull Appendable writer)
Create root element for a required element name
|
static @NotNull HtmlElement |
of(@NotNull HtmlConfig config,
@NotNull javax.servlet.http.HttpServletResponse response)
A base method to create new instance with empty html headers
|
static @NotNull HtmlElement |
of(@NotNull javax.servlet.http.HttpServletRequest request,
@NotNull javax.servlet.http.HttpServletResponse response)
A base method to create new instance
|
static @NotNull HtmlElement |
of(@NotNull javax.servlet.http.HttpServletRequest request,
@NotNull javax.servlet.http.HttpServletResponse response,
@NotNull HtmlConfig config)
A base method to create new instance
|
static @NotNull HtmlElement |
of(@NotNull javax.servlet.http.HttpServletResponse response,
@NotNull HtmlConfig config)
Deprecated.
Use the method
of(org.ujorm.tools.xml.config.HtmlConfig, javax.servlet.http.HttpServletResponse) rather. |
static @NotNull HtmlElement |
of(@NotNull javax.servlet.http.HttpServletResponse response,
CharSequence... cssLinks)
Create new instance with empty html headers
|
static @NotNull HtmlElement |
of(@NotNull CharSequence title,
@NotNull javax.servlet.http.HttpServletResponse response,
CharSequence... cssLinks)
Create new instance with empty html headers
|
static @NotNull HtmlElement |
of(@NotNull CharSequence title,
@NotNull javax.servlet.http.HttpServletResponse response,
@NotNull Charset charset,
CharSequence... cssLinks)
Create new instance with empty html headers
|
@NotNull Element |
original()
Get an original root element
|
Element |
setAttribute(String name,
Object value) |
@NotNull ExceptionProvider |
then(@NotNull Consumer<HtmlElement> builder)
Apply body of element by a lambda expression.
|
@NotNull String |
toString()
Returns an Render the HTML code including header.
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitsetAttribpublic HtmlElement(@NotNull
@NotNull HtmlConfig config,
@NotNull
@NotNull Appendable writer)
public HtmlElement(@NotNull
@NotNull ApiElement root,
@NotNull
@NotNull HtmlConfig config,
@NotNull
@NotNull Appendable writer)
@NotNull public @NotNull String 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(@NotNull @NotNull CharSequence template, @NotNull 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>@NotNull public final @NotNull Element addElement(@NotNull @NotNull String name) throws IllegalStateException
addElement in interface ApiElement<Element>name - The element nameIllegalStateException - An envelope for IO exceptionspublic Element getHead()
public Element addHead()
@NotNull public @NotNull Element getBody()
@NotNull public @NotNull Element addBody()
public void addJavascriptLinks(boolean defer,
@NotNull
CharSequence... javascriptLinks)
javascriptLinks - URL list to Javascriptdefer - A script that will not run until after the page has loadedpublic Element addJavascriptLink(boolean defer, @NotNull @NotNull CharSequence javascriptLink)
javascriptLink - URL to Javascriptdefer - A script that will not run until after the page has loaded@Deprecated public Element addJavascriptContents(@NotNull @NotNull CharSequence javascript)
addJavascriptBody(java.lang.CharSequence...) ratherpublic Element addJavascriptBody(@Nullable CharSequence... javascript)
javascript - Add a javascriptLink linkpublic void addCssLinks(@NotNull
CharSequence... css)
css - Add a CSS linkpublic Element addCssLink(@NotNull @NotNull CharSequence css)
css - Add a CSS linkpublic Element addCssBody(@NotNull @NotNull CharSequence css)
css - CSS contentpublic Element addCssBodies(@NotNull @NotNull CharSequence lineSeparator, @NotNull CharSequence... css)
lineSeparator - Row separatorcss - CSS content rows@NotNull public @NotNull Element original()
@NotNull public @NotNull String toString() throws IllegalStateException
toString in class ObjectIllegalStateExceptionpublic void close()
throws IllegalStateException
close in interface Closeableclose in interface AutoCloseableclose in interface ApiElement<Element>IllegalStateException@NotNull public @NotNull HtmlConfig getConfig()
public CharSequence getTitle()
@NotNull public static @NotNull HtmlElement of(@NotNull @NotNull javax.servlet.http.HttpServletResponse response, @NotNull CharSequence... cssLinks)
IllegalStateException - IO exceptionsMockServletResponse@NotNull public static @NotNull HtmlElement of(@NotNull @NotNull CharSequence title, @NotNull @NotNull javax.servlet.http.HttpServletResponse response, @NotNull CharSequence... cssLinks)
IllegalStateException - IO exceptionsMockServletResponse@NotNull public static @NotNull HtmlElement of(@NotNull @NotNull CharSequence title, @NotNull @NotNull javax.servlet.http.HttpServletResponse response, @NotNull @NotNull Charset charset, @NotNull CharSequence... cssLinks)
IllegalStateException - IO exceptionsMockServletResponse@NotNull public static @NotNull HtmlElement niceOf(@NotNull @NotNull CharSequence title, @NotNull @NotNull javax.servlet.http.HttpServletResponse response, @NotNull CharSequence... cssLinks)
IllegalStateException - IO exceptionsMockServletResponse@NotNull public static @NotNull HtmlElement niceOf(@NotNull @NotNull CharSequence title, @NotNull @NotNull javax.servlet.http.HttpServletResponse response, @NotNull @NotNull Charset charset, @NotNull CharSequence... cssLinks)
IllegalStateException - IO exceptionsMockServletResponse@NotNull public static @NotNull HtmlElement niceOf(@NotNull @NotNull javax.servlet.http.HttpServletResponse response, @NotNull CharSequence... cssLinks)
IllegalStateException - IO exceptionsMockServletResponse@NotNull public static @NotNull HtmlElement of(@NotNull @NotNull javax.servlet.http.HttpServletRequest request, @NotNull @NotNull 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@NotNull public static @NotNull HtmlElement of(@NotNull @NotNull javax.servlet.http.HttpServletRequest request, @NotNull @NotNull javax.servlet.http.HttpServletResponse response, @NotNull @NotNull 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 @NotNull public static @NotNull HtmlElement of(@NotNull @NotNull javax.servlet.http.HttpServletResponse response, @NotNull @NotNull 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@NotNull public static @NotNull HtmlElement of(@NotNull @NotNull HtmlConfig config, @NotNull @NotNull javax.servlet.http.HttpServletResponse response) throws IllegalStateException
response - HttpResponse to write a resultconfig - Html configurationIllegalStateException - IO exceptionsMockServletResponse@NotNull public static @NotNull HtmlElement of(@Nullable @Nullable HtmlConfig config) throws IllegalStateException
config - Html configurationIllegalStateException - IO exceptionspublic static HtmlElement of(@NotNull @NotNull HtmlConfig config, @NotNull @NotNull Appendable writer) throws IllegalStateException
IllegalStateException@NotNull public @NotNull ExceptionProvider then(@NotNull @NotNull Consumer<HtmlElement> builder)
HtmlElement.of(config, writer).addBody()
.then(body -> {
body.addHeading(config.getTitle());
})
.catche(e -> {
logger.log(Level.SEVERE, "An error", e);
});
Copyright 2015, Pavel Ponec