public final class Element extends Object implements ApiElement<Element>, Html
ServletResponse response = new ServletResponse();
try (HtmlElement html = HtmlElement.of(response)) {
try (Element body = html.getBody()) {
body.addHeading("Hello!");
}
}
assertTrue(response.toString().contains("<h1>Hello!</h1>"));
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 and Type | Method and Description |
|---|---|
@NotNull Element |
addAnchor(@NotNull String url,
CharSequence... cssClasses)
Add an anchor element with URL and CSS classes
|
@NotNull Element |
addBody(CharSequence... cssClasses)
Add new body element
|
@NotNull Element |
addBreak(CharSequence... cssClasses)
Add a line break
|
@NotNull Element |
addButton(CharSequence... cssClasses)
Add new button element
|
@NotNull Element |
addCDATA(CharSequence charData)
Add a character data in
CDATA format to XML only. |
@NotNull Element |
addComment(CharSequence comment)
Add a comment text.
|
@NotNull Element |
addDiv(CharSequence... cssClasses)
Add new div element
|
@NotNull Element |
addElement(@NotNull String name)
Create new Element
|
@NotNull Element |
addElement(@NotNull String name,
CharSequence... cssClasses)
Add a new Element with optional CSS classes
|
@NotNull Element |
addElementIf(boolean enabled,
@NotNull String name,
CharSequence... cssClasses)
Add an element according to a condition.
|
@NotNull Element |
addFieldset(@Nullable String title,
CharSequence... cssClasses)
Add new fieldset element including a title
|
@NotNull Element |
addForm(CharSequence... cssClasses)
Add new form element
|
@NotNull Element |
addHeading(@NotNull CharSequence title,
CharSequence... cssClasses)
Add a top heading (level one)
|
@NotNull Element |
addHeading(int level,
@NotNull CharSequence title,
CharSequence... cssClasses)
Add new heading with the required level where the first level is the one,
|
@NotNull Element |
addHiddenInput(@Nullable CharSequence name,
@Nullable Object value)
Add a new hidden input element with a name & value
|
@NotNull Element |
addImage(@NotNull CharSequence imageLink,
@NotNull CharSequence alt,
CharSequence... cssClasses)
Add a link to an image
|
@NotNull Element |
addImage(@NotNull InputStream imageStream,
@NotNull CharSequence alt,
CharSequence... cssClasses)
Add an embeded image
|
@NotNull Element |
addInput(CharSequence... cssClasses)
Add new input element
|
@NotNull Element |
addLabel(CharSequence... cssClasses)
Add new label element
|
@NotNull Element |
addLink(CharSequence... cssClasses)
Add new link element
|
@NotNull Element |
addLinkedText(@NotNull String url,
Object... text)
Add a
|
@NotNull Element |
addListItem(CharSequence... cssClasses) |
@NotNull Element |
addOption(CharSequence... cssClasses)
Add new option element
|
@NotNull Element |
addOrderedList(CharSequence... cssClasses)
Add new ordered list element
|
@NotNull Element |
addParagraph(CharSequence... cssClasses)
Add new paragram element
|
@NotNull Element |
addPasswordInput(CharSequence... cssClasses)
Add a new password input element
|
@NotNull Element |
addPreformatted(CharSequence... cssClasses)
Add new pre element
|
@NotNull Element |
addRawText(Object... data) |
@NotNull Element |
addRawText(@Nullable Object data)
Add an native text with no escaped characters, for example: XML code, JavaScript, CSS styles
|
Element |
addRawTexts(@NotNull CharSequence separator,
Object... data)
Add many words separated by a delimeter
|
@NotNull Element |
addScript(CharSequence... cssClasses)
Add new script element
|
@NotNull Element |
addSelect(CharSequence... cssClasses)
Add new select element
|
@NotNull Element |
addSelectOptions(@NotNull Object value,
@NotNull Map<?,?> options,
CharSequence... cssClasses)
Add options from map to current select element
|
@NotNull Element |
addSpan(CharSequence... cssClasses)
Add new span element
|
@NotNull Element |
addStyle(CharSequence... cssClasses)
Add new style element
|
@NotNull Element |
addSubmitButton(CharSequence... cssClasses)
Add a submit button
|
@NotNull Element |
addTable(@NotNull Collection<Object[]> data,
CharSequence... cssClass)
Create a HTML table according to data
|
@NotNull Element |
addTable(CharSequence... cssClasses)
Add new Table
|
@NotNull Element |
addTable(@NotNull Object[][] data,
CharSequence... cssClass)
Create a HTML table according to data
|
<D,V> @NotNull Element |
addTable(@NotNull Stream<D> domains,
@Nullable CharSequence[] cssClass,
@Nullable 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);
|
@NotNull Element |
addTableDetail(CharSequence... cssClasses)
Add new detail of table element
|
@NotNull Element |
addTableHead(CharSequence... cssClasses)
Add new head of table element
|
@NotNull Element |
addTableRow(CharSequence... cssClasses)
Add new table row element
|
@NotNull Element |
addText(Object... data)
Add many texts with no separator
|
@NotNull Element |
addText(Object data)
Add simple text
|
@NotNull Element |
addTextArea(CharSequence... cssClasses)
Add new text area element
|
<V> @NotNull Element |
addTextInp(@NotNull HttpParameter param,
V value,
@NotNull CharSequence title,
CharSequence... cssClasses)
Add new input element type of text including attributes: name, value, placeholder and title
|
@NotNull Element |
addTextInput(CharSequence... cssClasses)
Add new input element type of text
|
Element |
addTexts(@NotNull CharSequence separator,
Object... data)
Add many words separated by a delimeter
|
@NotNull Element |
addTextTemplated(CharSequence template,
Object... values)
Add a template based text with parameters with hight performance.
|
@NotNull Element |
addTitle(CharSequence... cssClasses)
Add new title element
|
@NotNull Element |
addUnorderedlist(CharSequence... cssClasses)
Add new unordered list element
|
void |
close()
Close the element
|
static @NotNull Element |
createHtmlRoot(@NotNull Object title,
CharSequence... cssLinks)
Crate a root element
|
static @NotNull Element |
createHtmlRoot(@NotNull Object title,
@Nullable Charset charset,
CharSequence... cssLinks)
Crate a root element
|
@NotNull String |
getName()
Get an element name
|
@NotNull ExceptionProvider |
next(@NotNull Consumer<Element> builder)
Add nested elements to the element.
|
static @NotNull Element |
of(@NotNull ApiElement original)
New element for an API element
|
@NotNull Element |
setAction(@Nullable Object value)
Set an action type of from
|
@NotNull Element |
setAttr(@NotNull String name,
@Nullable Object value)
A shortcut for the method
setAttribute(java.lang.String, java.lang.Object). |
@NotNull Element |
setAttribute(@NotNull String name)
Set an attribute with no value
|
@NotNull Element |
setAttribute(@NotNull String name,
@Nullable Object value)
Set an attribute
|
@NotNull Element |
setAttributes(@NotNull String name,
@NotNull CharSequence separator,
Object... value)
Set an attribute
|
@NotNull Element |
setClass(CharSequence... cssClasses)
Set a CSS class attribute optionally, the empty attribute is ignored.
|
@NotNull Element |
setCols(@Nullable Object value)
Column count of a text area
|
@NotNull Element |
setColSpan(@Nullable int value)
Column span inside the table
|
@NotNull Element |
setFor(@Nullable CharSequence value)
Set an value of input element
|
@NotNull Element |
setHint(@Nullable CharSequence value)
Set a placeholder name
|
@NotNull Element |
setHref(@Nullable CharSequence value)
Set hyperlink reference
|
@NotNull Element |
setId(@Nullable CharSequence value)
Set an identifier of the element
|
@NotNull Element |
setMethod(@Nullable Object value)
Set a method of form
|
@NotNull Element |
setName(@Nullable CharSequence value)
Set an name of input element
|
@NotNull Element |
setNameValue(@Nullable CharSequence name,
@Nullable Object value)
Set name & value to the input element
|
@NotNull Element |
setRows(@Nullable int value)
Row count of a text area
|
@NotNull Element |
setRowSpan(@Nullable int value)
Row span inside the table
|
@NotNull Element |
setType(@Nullable Object value)
Set a type of input element
|
@NotNull Element |
setValue(@Nullable Object value)
Set an value of input element
|
@NotNull ExceptionProvider |
then(@NotNull Consumer<Element> builder)
Deprecated.
Use the method
next(Consumer) rather. |
@NotNull String |
toString()
String value
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitsetAttrib@NotNull public @NotNull String getName()
ApiElementgetName in interface ApiElement<Element>@NotNull public @NotNull Element setAttribute(@NotNull @NotNull String name, @Nullable @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.@NotNull public @NotNull Element setAttributes(@NotNull @NotNull String name, @NotNull @NotNull CharSequence separator, @NotNull 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.@NotNull public @NotNull Element setAttribute(@NotNull @NotNull String name)
name - Required element name@NotNull public @NotNull Element setAttr(@NotNull @NotNull String name, @Nullable @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.@NotNull public @NotNull Element addText(Object data) throws IllegalStateException
addText in interface ApiElement<Element>data - Text itemIllegalStateException#addAnchoredText(java.lang.String, java.lang.Object...)@NotNull public @NotNull Element addText(@NotNull Object... data) throws IllegalStateException
data - Text itemsIllegalStateException#addAnchoredText(java.lang.String, java.lang.Object...)@NotNull public @NotNull 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 parameterspublic Element addTexts(@NotNull @NotNull CharSequence separator, @NotNull Object... data) throws IllegalStateException
separator - The delimiter must contain no special HTML character.data - Data to printIllegalStateException@NotNull public @NotNull Element addRawText(@Nullable @Nullable Object data) throws IllegalStateException
ApiElementaddRawText in interface ApiElement<Element>data - The null value is ignored.IllegalStateException@NotNull public @NotNull Element addRawText(@NotNull Object... data) throws IllegalStateException
IllegalStateExceptionpublic Element addRawTexts(@NotNull @NotNull CharSequence separator, @NotNull Object... data) throws IllegalStateException
separator - The delimiter must contain no special HTML character.data - Data to printIllegalStateException@NotNull public @NotNull Element addComment(CharSequence comment) throws IllegalStateException
ApiElementaddComment in interface ApiElement<Element>comment - A comment text must not contain a string --> .IllegalStateException@NotNull public @NotNull Element addCDATA(CharSequence charData) throws IllegalStateException
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.IllegalStateException@NotNull
public void close()
throws IllegalStateException
ApiElementclose in interface Closeableclose in interface AutoCloseableclose in interface ApiElement<Element>IllegalStateException@NotNull public @NotNull Element addElement(@NotNull @NotNull String name) throws IllegalStateException
addElement in interface ApiElement<Element>name - The element nameIllegalStateException - An envelope for IO exceptions@NotNull public @NotNull Element addElement(@NotNull @NotNull String name, @NotNull CharSequence... cssClasses)
name - A required name of the elementcssClasses - Optional CSS classes.@NotNull public @NotNull Element addElementIf(boolean enabled, @NotNull @NotNull String name, @NotNull CharSequence... cssClasses)
enabled - A condition for rendering the element.name - An element namecssClasses - CSS classes@NotNull public @NotNull Element addTable(@NotNull CharSequence... cssClasses)
@NotNull public @NotNull Element addTable(@NotNull @NotNull Object[][] data, @NotNull CharSequence... cssClass)
@NotNull public @NotNull Element addTable(@NotNull @NotNull Collection<Object[]> data, @NotNull CharSequence... cssClass)
@NotNull public <D,V> @NotNull Element addTable(@NotNull @NotNull Stream<D> domains, @Nullable @Nullable CharSequence[] cssClass, @Nullable @Nullable Object[] headers, @NotNull Function<D,V>... attributes)
element.addTable(getCars(), cssClasses, titles,
Car::getId,
Car::getName,
Car::getEnabled);
@NotNull public @NotNull Element addImage(@NotNull @NotNull CharSequence imageLink, @NotNull @NotNull CharSequence alt, @NotNull CharSequence... cssClasses) throws IllegalStateException
imageLink - A link to imagealt - An alternate textcssClasses - Optional CSS classesIllegalStateException@NotNull public @NotNull Element addImage(@NotNull @NotNull InputStream imageStream, @NotNull @NotNull CharSequence alt, @NotNull CharSequence... cssClasses) throws IllegalStateException
imageStream - Stream provides a PNG image and it will be closed after reading.alt - An alternate textcssClasses - Optional CSS classesIllegalStateException@NotNull public @NotNull Element addBody(@NotNull CharSequence... cssClasses)
@NotNull public @NotNull Element addTitle(@NotNull CharSequence... cssClasses)
@NotNull public @NotNull Element addLink(@NotNull CharSequence... cssClasses)
@NotNull public @NotNull Element addStyle(@NotNull CharSequence... cssClasses)
@NotNull public @NotNull Element addScript(@NotNull CharSequence... cssClasses)
@NotNull public @NotNull Element addDiv(@NotNull CharSequence... cssClasses)
@NotNull public @NotNull Element addFieldset(@Nullable @Nullable String title, @NotNull CharSequence... cssClasses)
title - An optional titlecssClasses - CSS classesLEGEND@NotNull public @NotNull Element addPreformatted(@NotNull CharSequence... cssClasses)
@NotNull public @NotNull Element addSpan(@NotNull CharSequence... cssClasses)
@NotNull public @NotNull Element addParagraph(@NotNull CharSequence... cssClasses)
@NotNull public @NotNull Element addForm(@NotNull CharSequence... cssClasses)
@NotNull public @NotNull Element addHeading(@NotNull @NotNull CharSequence title, @NotNull CharSequence... cssClasses)
@NotNull public @NotNull Element addHeading(int level, @NotNull @NotNull CharSequence title, @NotNull CharSequence... cssClasses)
@NotNull public @NotNull Element addTableHead(@NotNull CharSequence... cssClasses)
@NotNull public @NotNull Element addTableRow(@NotNull CharSequence... cssClasses)
@NotNull public @NotNull Element addTableDetail(@NotNull CharSequence... cssClasses)
@NotNull public @NotNull Element addLabel(@NotNull CharSequence... cssClasses)
@NotNull public @NotNull Element addInput(@NotNull CharSequence... cssClasses)
@NotNull public @NotNull Element addTextInput(@NotNull CharSequence... cssClasses)
@NotNull public <V> @NotNull Element addTextInp(@NotNull @NotNull HttpParameter param, @Nullable V value, @NotNull @NotNull CharSequence title, @NotNull CharSequence... cssClasses)
@NotNull public @NotNull Element addPasswordInput(@NotNull CharSequence... cssClasses)
@NotNull public @NotNull Element addHiddenInput(@Nullable @Nullable CharSequence name, @Nullable @Nullable Object value)
@NotNull public @NotNull Element addTextArea(@NotNull CharSequence... cssClasses)
@NotNull public @NotNull Element addSelect(@NotNull CharSequence... cssClasses)
@NotNull public @NotNull Element addSelectOptions(@NotNull @NotNull Object value, @NotNull @NotNull Map<?,?> options, @NotNull CharSequence... cssClasses)
value - Value of a select elementoptions - Consider an instance of the LinkedHashMap class predictable iteration order of options.cssClasses - thisaddSelect(java.lang.CharSequence...)@NotNull public @NotNull Element addOption(@NotNull CharSequence... cssClasses)
@NotNull public @NotNull Element addButton(@NotNull CharSequence... cssClasses)
@NotNull public @NotNull Element addSubmitButton(@NotNull CharSequence... cssClasses)
@NotNull public @NotNull Element addAnchor(@NotNull @NotNull String url, @NotNull CharSequence... cssClasses)
@NotNull public @NotNull Element addLinkedText(@NotNull @NotNull String url, @NotNull Object... text)
url - text - @NotNull public @NotNull Element addUnorderedlist(@NotNull CharSequence... cssClasses)
@NotNull public @NotNull Element addOrderedList(@NotNull CharSequence... cssClasses)
@NotNull public @NotNull Element addListItem(@NotNull CharSequence... cssClasses)
@NotNull public @NotNull Element setClass(@NotNull CharSequence... cssClasses)
cssClasses - Optional CSS classes. The css item is ignored when the value is empty or null.@NotNull public @NotNull Element addBreak(@NotNull CharSequence... cssClasses)
@NotNull public static @NotNull Element createHtmlRoot(@NotNull @NotNull Object title, @Nullable CharSequence... cssLinks)
cssLinks - Nullable CSS link array@NotNull public static @NotNull Element createHtmlRoot(@NotNull @NotNull Object title, @Nullable @Nullable Charset charset, @Nullable CharSequence... cssLinks)
title - A HTML titlecharset - A charsetcssLinks - Nullable CSS link array@NotNull public @NotNull Element setId(@Nullable @Nullable CharSequence value)
@NotNull public @NotNull Element setMethod(@Nullable @Nullable Object value)
@NotNull public @NotNull Element setAction(@Nullable @Nullable Object value)
@NotNull public @NotNull Element setType(@Nullable @Nullable Object value)
@NotNull public @NotNull Element setName(@Nullable @Nullable CharSequence value)
@NotNull public @NotNull Element setValue(@Nullable @Nullable Object value)
@NotNull public @NotNull Element setNameValue(@Nullable @Nullable CharSequence name, @Nullable @Nullable Object value)
@NotNull public @NotNull Element setFor(@Nullable @Nullable CharSequence value)
@NotNull public @NotNull Element setRows(@Nullable @Nullable int value)
@NotNull public @NotNull Element setCols(@Nullable @Nullable Object value)
@NotNull public @NotNull Element setColSpan(@Nullable @Nullable int value)
@NotNull public @NotNull Element setRowSpan(@Nullable @Nullable int value)
@NotNull public @NotNull Element setHref(@Nullable @Nullable CharSequence value)
@NotNull public @NotNull Element setHint(@Nullable @Nullable CharSequence value)
@NotNull public @NotNull ExceptionProvider then(@NotNull @NotNull Consumer<Element> builder)
next(Consumer) rather.@NotNull public @NotNull ExceptionProvider next(@NotNull @NotNull Consumer<Element> builder)
HtmlElement.of(config, writer).addBody()
.next(body -> {
body.addHeading(config.getTitle());
})
.catche(e -> {
logger.log(Level.SEVERE, "An error", e);
});
@NotNull public @NotNull String toString()
@NotNull public static @NotNull Element of(@NotNull @NotNull ApiElement original)
Copyright 2015, Pavel Ponec