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_READONLY, A_REL, A_ROWS, A_ROWSPAN, A_SELECTED, A_SRC, A_TARGET, 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, 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,
Writer writer)
Create new instance with empty html headers
|
HtmlElement(HtmlConfig config,
Writer 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 |
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 |
addJavascriptContents(CharSequence javascript)
Create a new Javascript element and return it
|
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
|
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(javax.servlet.http.HttpServletResponse response,
HtmlConfig config)
A base method to create new instance with empty html headers
|
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 |
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 Writer writer)
public HtmlElement(@Nonnull ApiElement root, @Nonnull HtmlConfig config, @Nonnull Writer writer)
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 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 loadedpublic Element addJavascriptContents(@Nonnull 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 content@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.HttpServletResponse response, @Nonnull HtmlConfig config) throws IllegalStateException
response
- HttpREsponseconfig
- Html configurationIllegalStateException
- IO exceptionsMockServletResponse
@Nonnull public static HtmlElement of(@Nullable HtmlConfig config) throws IllegalStateException
config
- Html configurationIllegalStateException
- IO exceptionsCopyright 2019-2022, Pavel Ponec