public class HtmlElement extends Object implements ApiElement<Element>, Html
ServletResponse response = new ServletResponse();
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_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)
Add a character data in
CDATA format to XML only. |
Element |
addComment(CharSequence comment)
Add a comment text.
|
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 |
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)
Add an native text with no escaped characters, for example: XML code, JavaScript, CSS styles
|
Element |
addText(Object value)
Add a text and escape special character
|
Element |
addTextTemplated(@NotNull CharSequence template,
Object... values)
Message template
|
void |
close()
Close the element
|
@NotNull Element |
getBody()
Returns a body element
|
@NotNull HtmlConfig |
getConfig()
Get config
|
Element |
getHead()
Returns a head element
|
@NotNull String |
getName()
Get an element name
|
CharSequence |
getTitle()
Get title of configuration
|
@NotNull ExceptionProvider |
next(@NotNull Consumer<HtmlElement> builder)
Add nested elements to the element.
|
static @NotNull HtmlElement |
niceOf(@NotNull CharSequence title,
@NotNull Appendable response,
CharSequence... cssLinks)
Create new instance with empty html headers
|
static @NotNull HtmlElement |
niceOf(@NotNull CharSequence title,
@NotNull Appendable response,
@NotNull Charset charset,
CharSequence... cssLinks)
Create new instance with empty html headers
|
static @NotNull HtmlElement |
niceOf(@NotNull String title,
@NotNull Appendable response,
CharSequence... cssLinks)
Create new instance with empty html headers
|
static @NotNull HtmlElement |
niceOf(@NotNull String title,
@NotNull RContext context,
CharSequence... cssLinks)
Create new instance with empty html headers
|
static @NotNull HtmlElement |
niceOfResponse(@NotNull Object httpServletResponse,
CharSequence... cssLinks)
Create new instance with empty html headers
|
static @NotNull HtmlElement |
niceOfResponse(@NotNull String title,
@NotNull Object httpServletResponse,
CharSequence... cssLinks)
Create new instance with empty html headers
|
static @NotNull HtmlElement |
of(@NotNull Appendable writer,
@NotNull HtmlConfig myConfig)
Create root element for a required element name.
|
static @NotNull HtmlElement |
of(@Nullable HtmlConfig config)
Create new instance with empty html headers
|
static @NotNull HtmlElement |
of(@NotNull CharSequence title,
@NotNull Appendable response,
CharSequence... cssLinks)
Create new instance with empty html headers
|
static @NotNull HtmlElement |
of(@NotNull CharSequence title,
@NotNull Appendable response,
@NotNull Charset charset,
CharSequence... cssLinks)
Create new instance with empty html headers
|
static @NotNull HtmlElement |
of(@NotNull RContext context,
@NotNull HtmlConfig myConfig)
Create root element for a required element name.
|
static @NotNull HtmlElement |
ofServlet(@NotNull Object htmlServletResponse,
@Nullable HtmlConfig config)
Create new instance with empty html headers, The MAIN servlet factory method.
|
static @NotNull HtmlElement |
ofServlet(@NotNull String title,
@NotNull Object htmlServletResponse,
CharSequence... cssLinks)
Create new instance with empty html headers
|
@NotNull Element |
original()
Get an original root element
|
Element |
setAttribute(String name,
Object value)
Set an attribute
|
@NotNull ExceptionProvider |
then(@NotNull Consumer<HtmlElement> builder)
Deprecated.
Use the method
next(Consumer) rather. |
@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()
ApiElementgetName in interface ApiElement<Element>public Element setAttribute(String name, Object value)
ApiElementsetAttribute in interface ApiElement<Element>name - Required element namevalue - The null value is silently ignored. Formatting is performed by the
AbstractWriter.writeValue(Object, ApiElement, String)
method, where the default implementation calls a toString() only.public Element addText(Object value)
ApiElementaddText in interface ApiElement<Element>value - The null value is allowed. Formatting is performed by the
AbstractWriter.writeValue(Object, ApiElement, String) }
method, where the default implementation calls a toString() only.public Element addTextTemplated(@NotNull @NotNull CharSequence template, @NotNull Object... values)
ApiElementaddTextTemplated in interface ApiElement<Element>template - Message template where parameters are marked by the {} symbolvalues - argument valuespublic Element addRawText(Object value)
ApiElementaddRawText in interface ApiElement<Element>value - The null value is ignored.public Element addComment(CharSequence comment)
ApiElementaddComment in interface ApiElement<Element>comment - A comment text must not contain a string --> .public Element addCDATA(CharSequence charData)
ApiElementCDATA format to XML only.
The CDATA structure isn't really for HTML at all.addCDATA in interface ApiElement<Element>charData - A text including the final DATA sequence. An empty argument is ignored.@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 loadedpublic 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
ApiElementclose 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 Appendable writer, @NotNull @NotNull HtmlConfig myConfig) throws IllegalStateException
IllegalStateException@NotNull public static @NotNull HtmlElement of(@NotNull @NotNull RContext context, @NotNull @NotNull HtmlConfig myConfig)
@NotNull public static @NotNull HtmlElement ofServlet(@NotNull @NotNull Object htmlServletResponse, @Nullable @Nullable HtmlConfig config)
IllegalStateException - IO exceptionsAppendable@NotNull public static @NotNull HtmlElement ofServlet(@NotNull @NotNull String title, @NotNull @NotNull Object htmlServletResponse, @NotNull CharSequence... cssLinks)
IllegalStateException - IO exceptionsAppendable@NotNull public static @NotNull HtmlElement of(@NotNull @NotNull CharSequence title, @NotNull @NotNull Appendable response, @NotNull CharSequence... cssLinks)
IllegalStateException - IO exceptionsAppendable@NotNull public static @NotNull HtmlElement of(@NotNull @NotNull CharSequence title, @NotNull @NotNull Appendable response, @NotNull @NotNull Charset charset, @NotNull CharSequence... cssLinks)
IllegalStateException - IO exceptionsAppendable@NotNull public static @NotNull HtmlElement niceOf(@NotNull @NotNull CharSequence title, @NotNull @NotNull Appendable response, @NotNull CharSequence... cssLinks)
IllegalStateException - IO exceptionsAppendable@NotNull public static @NotNull HtmlElement niceOf(@NotNull @NotNull CharSequence title, @NotNull @NotNull Appendable response, @NotNull @NotNull Charset charset, @NotNull CharSequence... cssLinks)
IllegalStateException - IO exceptionsAppendable@NotNull public static @NotNull HtmlElement niceOfResponse(@NotNull @NotNull String title, @NotNull @NotNull Object httpServletResponse, @NotNull CharSequence... cssLinks)
IllegalStateException - IO exceptionsAppendable@NotNull public static @NotNull HtmlElement niceOfResponse(@NotNull @NotNull Object httpServletResponse, @NotNull CharSequence... cssLinks)
IllegalStateException - IO exceptionsAppendable@NotNull public static @NotNull HtmlElement niceOf(@NotNull @NotNull String title, @NotNull @NotNull RContext context, @NotNull CharSequence... cssLinks)
IllegalStateException - IO exceptionsAppendable@NotNull public static @NotNull HtmlElement niceOf(@NotNull @NotNull String title, @NotNull @NotNull Appendable response, @NotNull CharSequence... cssLinks)
IllegalStateException - IO exceptionsAppendable@NotNull public static @NotNull HtmlElement of(@Nullable @Nullable HtmlConfig config) throws IllegalStateException
config - Html configurationIllegalStateException - IO exceptions@NotNull public final @NotNull ExceptionProvider then(@NotNull @NotNull Consumer<HtmlElement> builder)
next(Consumer) rather.@NotNull public @NotNull ExceptionProvider next(@NotNull @NotNull Consumer<HtmlElement> builder)
HtmlElement.of(config, writer).addBody()
.next(body -> {
body.addHeading(config.getTitle());
})
.catche(e -> {
logger.log(Level.SEVERE, "An error", e);
});
Copyright 2015, Pavel Ponec