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_NAME
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(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)
Add a comment text.
|
Element |
addCssBodies(CharSequence lineSeparator,
CharSequence... css)
Create a new CSS element and return it.
|
Element |
addCssBody(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)
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(CharSequence template,
Object... values)
Message template
|
void |
close()
Close the element
|
Element |
getBody()
Returns a body element
|
HtmlConfig |
getConfig()
Get config
|
Element |
getHead()
Returns a head element
|
String |
getName()
Get an element name
|
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)
Set an attribute
|
String |
toString()
Returns an Render the HTML code including header.
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
setAttrib
public HtmlElement(@Nonnull HtmlConfig config, @Nonnull Appendable writer)
public HtmlElement(@Nonnull ApiElement root, @Nonnull HtmlConfig config, @Nonnull Appendable writer)
@Nonnull public String getName()
ApiElement
getName
in interface ApiElement<Element>
public Element setAttribute(String name, Object value)
ApiElement
setAttribute
in interface ApiElement<Element>
name
- Required element namevalue
- The null
value is silently ignored. Formatting is performed by the
XmlWriter#writeValue(java.lang.Object, org.ujorm.tools.dom.XmlElement, java.lang.String, java.io.Writer)
method, where the default implementation calls a toString()
only.public Element addText(Object value)
ApiElement
addText
in interface ApiElement<Element>
value
- The null
value is allowed. Formatting is performed by the
XmlWriter#writeValue(java.lang.Object, org.ujorm.tools.dom.XmlElement, java.lang.String, java.io.Writer)
method, where the default implementation calls a toString()
only.public Element addTextTemplated(@Nonnull CharSequence template, @Nonnull Object... values)
ApiElement
addTextTemplated
in interface ApiElement<Element>
template
- Message template where parameters are marked by the {}
symbolvalues
- argument valuespublic Element addRawText(Object value)
ApiElement
addRawText
in interface ApiElement<Element>
value
- The null
value is ignored.public Element addComment(CharSequence comment)
ApiElement
addComment
in interface ApiElement<Element>
comment
- A comment text must not contain a string -->
.@Deprecated public Element addCDATA(CharSequence charData)
ApiElement
CDATA
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.@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 addCssBody(@Nonnull CharSequence css)
css
- CSS contentpublic Element addCssBodies(@Nonnull CharSequence lineSeparator, @Nonnull CharSequence... css)
lineSeparator
- Row separatorcss
- CSS content rows@Nonnull public String toString() throws IllegalStateException
toString
in class Object
IllegalStateException
public void close() throws IllegalStateException
ApiElement
close
in interface Closeable
close
in interface AutoCloseable
close
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 exceptionsUnsupportedEncodingException
MockServletResponse
@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 exceptionsUnsupportedEncodingException
MockServletResponse
@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
IllegalStateException
Copyright 2019-2022, Pavel Ponec