public final class Element extends Object implements ApiElement<Element>, Html
MockServletResponse response = new MockServletResponse(); try (HtmlElement html = HtmlElement.of(response)) { try (Element body = html.getBody()) { body.addHeading("Hello!"); } } assertTrue(response.toString().contains("<h1>Hello!</h1>"));
Modifier and Type | Field and Description |
---|---|
protected ApiElement |
internalElement
An original XML element
|
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
Modifier | Constructor and Description |
---|---|
protected |
Element(ApiElement original)
New element for an API element
|
Modifier and Type | Method and Description |
---|---|
Element |
addAnchor(String url,
CharSequence... cssClasses)
Add an anchor element with URL and CSS classes
|
Element |
addAnchoredText(String url,
Object... text)
Deprecated.
|
Element |
addBody(CharSequence... cssClasses)
Add new body element
|
Element |
addBreak(CharSequence... cssClasses)
Add a line break
|
Element |
addButton(CharSequence... cssClasses)
Add new button element
|
Element |
addCDATA(CharSequence charData)
Add a character data in
CDATA format to XML only. |
Element |
addComment(CharSequence comment)
Add a comment text.
|
Element |
addDiv(CharSequence... cssClasses)
Add new div element
|
Element |
addElement(String name)
Create new Element
|
Element |
addElement(String name,
CharSequence... cssClasses)
Add a new Element with optional CSS classes
|
Element |
addElementIf(boolean enabled,
String name,
CharSequence... cssClasses)
Add an element according to a condition.
|
Element |
addFieldset(String title,
CharSequence... cssClasses)
Add new fieldset element including a title
|
Element |
addForm(CharSequence... cssClasses)
Add new form element
|
Element |
addHeading(CharSequence title,
CharSequence... cssClasses)
Add a top heading (level one)
|
Element |
addHeading(int level,
CharSequence title,
CharSequence... cssClasses)
Add new heading with the required level where the first level is the one,
|
Element |
addImage(CharSequence imageLink,
CharSequence alt,
CharSequence... cssClasses)
Add a link to an image
|
Element |
addImage(InputStream imageStream,
CharSequence alt,
CharSequence... cssClasses)
Add an embeded image
|
Element |
addInput(CharSequence... cssClasses)
Add new input element
|
Element |
addLabel(CharSequence... cssClasses)
Add new label element
|
Element |
addLink(CharSequence... cssClasses)
Add new link element
|
Element |
addLinkedText(String url,
Object... text)
Add a
|
Element |
addListItem(CharSequence... cssClasses) |
Element |
addOption(CharSequence... cssClasses)
Add new option element
|
Element |
addOrderedList(CharSequence... cssClasses)
Add new ordered list element
|
Element |
addParagraph(CharSequence... cssClasses)
Add new paragram element
|
Element |
addPasswordInput(CharSequence... cssClasses)
Add new input element type of password
|
Element |
addPreformatted(CharSequence... cssClasses)
Add new pre element
|
Element |
addRawText(Object... data) |
Element |
addRawText(Object data)
Add an native text with no escaped characters, for example: XML code, JavaScript, CSS styles
|
Element |
addRawTexts(CharSequence separator,
Object... data)
Add many words separated by a delimeter
|
Element |
addScript(CharSequence... cssClasses)
Add new script element
|
Element |
addSelect(CharSequence... cssClasses)
Add new select element
|
Element |
addSelectOptions(Object value,
Map<?,?> options,
CharSequence... cssClasses)
Add options from map to current select element
|
Element |
addSpan(CharSequence... cssClasses)
Add new span element
|
Element |
addStyle(CharSequence... cssClasses)
Add new style element
|
Element |
addSubmitButton(CharSequence... cssClasses)
Add a submit button
|
Element |
addTable(Collection<Object[]> data,
CharSequence... cssClass)
Create a HTML table according to data
|
Element |
addTable(CharSequence... cssClasses)
Add new Table
|
Element |
addTable(Object[][] data,
CharSequence... cssClass)
Create a HTML table according to data
|
<D,V> Element |
addTable(Stream<D> domains,
CharSequence[] cssClass,
Object[] headers,
Function<D,V>... attributes)
Create a HTML table according to data
Usage
element.addTable(getCars(), cssClasses, titles,
Car::getId,
Car::getName,
Car::getEnabled);
|
Element |
addTableDetail(CharSequence... cssClasses)
Add new detail of table element
|
Element |
addTableHead(CharSequence... cssClasses)
Add new head of table element
|
Element |
addTableNoSpaces(CharSequence... cssClasses)
Deprecated.
Use a CSS style rather.
|
Element |
addTableRow(CharSequence... cssClasses)
Add new table row element
|
Element |
addTemplate(String template,
Object... data)
Deprecated.
|
Element |
addText(Object... data)
Add many texts with no separator
|
Element |
addText(Object data)
Add simple text
|
Element |
addTextArea(CharSequence... cssClasses)
Add new text area element
|
<V> Element |
addTextInp(HttpParameter param,
V value,
CharSequence title,
CharSequence... cssClasses)
Add new input element type of text including attributes: name, value, placeholder and title
|
Element |
addTextInput(javax.servlet.http.HttpServletRequest req,
HttpParameter param,
CharSequence title,
CharSequence... cssClasses)
Deprecated.
Use the method of the same name with an explicit value.
|
Element |
addTextInput(CharSequence... cssClasses)
Add new input element type of text
|
Element |
addTexts(CharSequence separator,
Object... data)
Add many words separated by a delimeter
|
Element |
addTextSeparted(CharSequence separator,
Object... data)
Deprecated.
|
Element |
addTextTemplated(CharSequence template,
Object... values)
Add a template based text with parameters with hight performance.
|
Element |
addTitle(CharSequence... cssClasses)
Add new title element
|
Element |
addUnorderedlist(CharSequence... cssClasses)
Add new unordered list element
|
void |
close()
Close the element
|
protected CharSequence |
createEmbededImage(InputStream imageStream,
StringBuilder result)
Create a content of an embeded image
|
static Element |
createHtmlRoot(Object title,
CharSequence... cssLinks)
Crate a root element
|
static Element |
createHtmlRoot(Object title,
Charset charset,
CharSequence... cssLinks)
Crate a root element
|
String |
getName()
Get an element name
|
static Element |
of(ApiElement original)
New element for an API element
|
Element |
setAction(Object value)
Set an action type of from
|
Element |
setAttr(String name,
Object value)
A shortcut for the method
setAttribute(java.lang.String, java.lang.Object) . |
Element |
setAttrib(String name,
Object value)
Deprecated.
|
Element |
setAttribute(String name)
Set an attribute with no value
|
Element |
setAttribute(String name,
Object value)
Set an attribute
|
Element |
setAttributes(String name,
CharSequence separator,
Object... value)
Set an attribute
|
Element |
setCellPadding(int value)
Deprecated.
|
Element |
setCellSpacing(int value)
Deprecated.
|
Element |
setClass(CharSequence... cssClasses)
Set a CSS class attribute optionally, the empty attribute is ignored.
|
Element |
setCols(Object value)
Column count of a text area
|
Element |
setColSpan(int value)
Column span inside the table
|
Element |
setFor(CharSequence value)
Set an value of input element
|
Element |
setHref(CharSequence value)
Set hyperlink reference
|
Element |
setId(CharSequence value)
Set an identifier of the element
|
Element |
setMethod(Object value)
Set a method of form
|
Element |
setName(CharSequence value)
Set an name of input element
|
Element |
setRows(int value)
Row count of a text area
|
Element |
setRowSpan(int value)
Row span inside the table
|
Element |
setType(Object value)
Set a type of input element
|
Element |
setValue(Object value)
Set an value of input element
|
String |
toString()
String value
|
protected final ApiElement internalElement
protected Element(@Nonnull ApiElement original)
of(org.ujorm.tools.xml.ApiElement)
@Nonnull public String getName()
ApiElement
getName
in interface ApiElement<Element>
@Nonnull public final Element setAttribute(@Nonnull String name, @Nullable Object value)
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.model.XmlModel, java.lang.String, java.io.Writer)
method, where the default implementation calls a toString()
only.@Nonnull public final Element setAttributes(@Nonnull String name, @Nonnull CharSequence separator, @Nonnull Object... value)
name
- Required element namevalue
- The null
value is silently ignored. Formatting is performed by the
XmlWriter#writeValue(java.lang.Object, org.ujorm.tools.model.XmlModel, java.lang.String, java.io.Writer)
method, where the default implementation calls a toString()
only.@Nonnull public final Element setAttribute(@Nonnull String name)
name
- Required element name@Deprecated @Nonnull public final Element setAttrib(@Nonnull String name, @Nullable Object value)
setAttribute(java.lang.String, java.lang.Object)
.setAttrib
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.model.XmlModel, java.lang.String, java.io.Writer)
method, where the default implementation calls a toString()
only.@Nonnull public final Element setAttr(@Nonnull String name, @Nullable Object value)
setAttribute(java.lang.String, java.lang.Object)
.name
- Required element namevalue
- The null
value is silently ignored. Formatting is performed by the
XmlWriter#writeValue(java.lang.Object, org.ujorm.tools.model.XmlModel, java.lang.String, java.io.Writer)
method, where the default implementation calls a toString()
only.@Nonnull public Element addText(Object data) throws IllegalStateException
addText
in interface ApiElement<Element>
data
- Text itemIllegalStateException
addAnchoredText(java.lang.String, java.lang.Object...)
@Nonnull public Element addText(@Nonnull Object... data) throws IllegalStateException
data
- Text itemsIllegalStateException
addAnchoredText(java.lang.String, java.lang.Object...)
@Deprecated @Nonnull public Element addTemplate(@Nonnull String template, @Nonnull Object... data) throws IllegalStateException
#addTextTemplated(java.lang.String, java.lang.Object...)
raher.template
- A message template with an ENGLISH locale. See {@link String#format(java.lang.String, java.lang.Object...) for more parameters.data
- A template parametersIllegalStateException
@Nonnull public Element addTextTemplated(CharSequence template, Object... values)
addTextTemplated
in interface ApiElement<Element>
template
- A message template with an ENGLISH locale. See {@link String#format(java.lang.String, java.lang.Object...) for more parameters.values
- A template parameters@Deprecated public Element addTextSeparted(@Nonnull CharSequence separator, @Nonnull Object... data) throws IllegalStateException
addTexts(java.lang.CharSequence, java.lang.Object...)
rather;separator
- The delimiter must contain no special HTML character.data
- Data to printIllegalStateException
public Element addTexts(@Nonnull CharSequence separator, @Nonnull Object... data) throws IllegalStateException
separator
- The delimiter must contain no special HTML character.data
- Data to printIllegalStateException
@Nonnull public Element addRawText(@Nullable Object data) throws IllegalStateException
ApiElement
addRawText
in interface ApiElement<Element>
data
- The null
value is ignored.IllegalStateException
@Nonnull public Element addRawText(@Nonnull Object... data) throws IllegalStateException
IllegalStateException
public Element addRawTexts(@Nonnull CharSequence separator, @Nonnull Object... data) throws IllegalStateException
separator
- The delimiter must contain no special HTML character.data
- Data to printIllegalStateException
@Nonnull public Element addComment(CharSequence comment) throws IllegalStateException
ApiElement
addComment
in interface ApiElement<Element>
comment
- A comment text must not contain a string -->
.IllegalStateException
@Nonnull public Element addCDATA(CharSequence charData) throws IllegalStateException
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.IllegalStateException
@Nonnull public void close() throws IllegalStateException
ApiElement
close
in interface Closeable
close
in interface AutoCloseable
close
in interface ApiElement<Element>
IllegalStateException
@Nonnull public Element addElement(@Nonnull String name) throws IllegalStateException
addElement
in interface ApiElement<Element>
name
- The element nameIllegalStateException
- An envelope for IO exceptions@Nonnull public final Element addElement(@Nonnull String name, @Nonnull CharSequence... cssClasses)
name
- A required name of the elementcssClasses
- Optional CSS classes.@Nonnull public final Element addElementIf(boolean enabled, @Nonnull String name, @Nonnull CharSequence... cssClasses)
enabled
- A condition for rendering the element.name
- An element namecssClasses
- CSS classes@Nonnull public Element addTable(@Nonnull CharSequence... cssClasses)
@Deprecated @Nonnull public Element addTableNoSpaces(@Nonnull CharSequence... cssClasses)
@Nonnull public Element addTable(@Nonnull Object[][] data, @Nonnull CharSequence... cssClass)
@Nonnull public Element addTable(@Nonnull Collection<Object[]> data, @Nonnull CharSequence... cssClass)
@Nonnull public <D,V> Element addTable(@Nonnull Stream<D> domains, @Nullable CharSequence[] cssClass, @Nullable Object[] headers, @Nonnull Function<D,V>... attributes)
element.addTable(getCars(), cssClasses, titles, Car::getId, Car::getName, Car::getEnabled);
@Nonnull public Element addImage(@Nonnull CharSequence imageLink, @Nonnull CharSequence alt, @Nonnull CharSequence... cssClasses) throws IllegalStateException
imageLink
- A link to imagealt
- An alternate textcssClasses
- Optional CSS classesIllegalStateException
@Nonnull public Element addImage(@Nonnull InputStream imageStream, @Nonnull CharSequence alt, @Nonnull CharSequence... cssClasses) throws IllegalStateException
imageStream
- Stream provides a PNG image and it will be closed after reading.alt
- An alternate textcssClasses
- Optional CSS classesIllegalStateException
@Nonnull protected CharSequence createEmbededImage(@Nonnull InputStream imageStream, @Nonnull StringBuilder result)
@Nonnull public Element addBody(@Nonnull CharSequence... cssClasses)
@Nonnull public Element addTitle(@Nonnull CharSequence... cssClasses)
@Nonnull public Element addLink(@Nonnull CharSequence... cssClasses)
@Nonnull public Element addStyle(@Nonnull CharSequence... cssClasses)
@Nonnull public Element addScript(@Nonnull CharSequence... cssClasses)
@Nonnull public Element addDiv(@Nonnull CharSequence... cssClasses)
@Nonnull public Element addFieldset(@Nullable String title, @Nonnull CharSequence... cssClasses)
title
- An optional titlecssClasses
- CSS classesLEGEND
@Nonnull public Element addPreformatted(@Nonnull CharSequence... cssClasses)
@Nonnull public Element addSpan(@Nonnull CharSequence... cssClasses)
@Nonnull public Element addParagraph(@Nonnull CharSequence... cssClasses)
@Nonnull public Element addForm(@Nonnull CharSequence... cssClasses)
@Nonnull public Element addHeading(@Nonnull CharSequence title, @Nonnull CharSequence... cssClasses)
@Nonnull public Element addHeading(int level, @Nonnull CharSequence title, @Nonnull CharSequence... cssClasses)
@Nonnull public Element addTableHead(@Nonnull CharSequence... cssClasses)
@Nonnull public Element addTableRow(@Nonnull CharSequence... cssClasses)
@Nonnull public Element addTableDetail(@Nonnull CharSequence... cssClasses)
@Nonnull public Element addLabel(@Nonnull CharSequence... cssClasses)
@Nonnull public Element addInput(@Nonnull CharSequence... cssClasses)
@Nonnull public Element addTextInput(@Nonnull CharSequence... cssClasses)
@Deprecated @Nonnull public Element addTextInput(@Nonnull javax.servlet.http.HttpServletRequest req, @Nonnull HttpParameter param, @Nonnull CharSequence title, @Nonnull CharSequence... cssClasses)
@Nonnull public <V> Element addTextInp(@Nonnull HttpParameter param, @Nullable V value, @Nonnull CharSequence title, @Nonnull CharSequence... cssClasses)
@Nonnull public Element addPasswordInput(@Nonnull CharSequence... cssClasses)
@Nonnull public Element addTextArea(@Nonnull CharSequence... cssClasses)
@Nonnull public Element addSelect(@Nonnull CharSequence... cssClasses)
@Nonnull public Element addSelectOptions(@Nonnull Object value, @Nonnull Map<?,?> options, @Nonnull CharSequence... cssClasses)
value
- Value of a select elementoptions
- Consider an instance of the LinkedHashMap
class predictable iteration order of options.cssClasses
- this
addSelect(java.lang.CharSequence...)
@Nonnull public Element addOption(@Nonnull CharSequence... cssClasses)
@Nonnull public Element addButton(@Nonnull CharSequence... cssClasses)
@Nonnull public Element addSubmitButton(@Nonnull CharSequence... cssClasses)
@Nonnull public Element addAnchor(@Nonnull String url, @Nonnull CharSequence... cssClasses)
@Deprecated @Nonnull public Element addAnchoredText(@Nonnull String url, @Nonnull Object... text)
@Nonnull public Element addLinkedText(@Nonnull String url, @Nonnull Object... text)
url
- text
- @Nonnull public Element addUnorderedlist(@Nonnull CharSequence... cssClasses)
@Nonnull public Element addOrderedList(@Nonnull CharSequence... cssClasses)
@Nonnull public Element addListItem(@Nonnull CharSequence... cssClasses)
@Nonnull public Element setClass(@Nonnull CharSequence... cssClasses)
cssClasses
- Optional CSS classes. The css item is ignored when the value is empty or null
.@Nonnull public Element addBreak(@Nonnull CharSequence... cssClasses)
@Deprecated @Nonnull public Element setCellPadding(int value)
@Deprecated @Nonnull public Element setCellSpacing(int value)
@Nonnull public static Element createHtmlRoot(@Nonnull Object title, @Nullable CharSequence... cssLinks)
cssLinks
- Nullable CSS link array@Nonnull public static Element createHtmlRoot(@Nonnull Object title, @Nullable Charset charset, @Nullable CharSequence... cssLinks)
title
- A HTML titlecharset
- A charsetcssLinks
- Nullable CSS link array@Nonnull public Element setId(@Nullable CharSequence value)
@Nonnull public Element setName(@Nullable CharSequence value)
@Nonnull public Element setFor(@Nullable CharSequence value)
@Nonnull public Element setHref(@Nullable CharSequence value)
@Nonnull public static final Element of(@Nonnull ApiElement original)
Copyright 2019-2022, Pavel Ponec