public abstract class AbstractJaxb extends Object implements Serializable
base class of all tag type
Constructor and Description |
---|
AbstractJaxb() |
Modifier and Type | Method and Description |
---|---|
<T extends AbstractJaxb> |
addCssClass(String clazz)
add class attribute.
|
<T> T |
cast(Class<T> clazz)
type cast.
|
<T extends AbstractJaxb> |
copy(Class<T> tagType)
return deep copy of myself
|
<T extends AbstractJaxb> |
copyNoException(Class<T> tagType)
same as
copy(Class) but never throw exception. |
String |
getAria(String key)
return the value of area-* attribute.
|
<T extends AbstractJaxb> |
getById(String id)
get tag that has specified id attribute.
|
<T extends AbstractJaxb> |
getById(String id,
Class<T> tagType)
get tag that has specified id attribute.
|
<T extends AbstractJaxb> |
getByName(String name,
Class<T> tagType)
find tag by "name" property.
|
<T extends AbstractJaxb> |
getByNameAsList(String name,
Class<T> tagType)
find tag by "name" property returning as List.
|
List<String> |
getCssClass()
return class attribute as List.
|
String |
getData(String key)
return the value of data-* attribute.
|
<T extends AbstractJaxb> |
getDescendants(Class<T> tagType)
scan descendant elements that has specified tag type and return it as
List.
|
<T extends AbstractJaxb> |
getDescendants(String clazz)
scan descendant elements that has specified class attribute and return it
as List
|
<T extends AbstractJaxb> |
getDescendants(String clazz,
Class<T> tagType)
scan descendant element that is specified tag type having specified class
attribute and return it as List.
|
Footer |
getFooter()
get footer tag (the first one in this tag)
|
List<Footer> |
getFooterAsList()
get footer tag
|
Header |
getHeader()
get header tag (the first one in this tag)
|
List<Header> |
getHeaderAsList()
get header tag
|
String |
getId()
get id attribute.
|
Map<QName,String> |
getOtherAttributes()
get other attribute map.
|
String |
getStyle()
NOTICE: this method is dummy for make coding easy.
|
TreeMap<String,String> |
getStyleAsTreeMap()
return style attributes as TreeMap
|
<T extends AbstractJaxb> |
hasCssClass(String clazz)
return true if have specified class attribute.
|
boolean |
insertAfterId(String id,
String insString)
insert String after the element having specified id attribute
|
<T extends AbstractJaxb> |
insertAfterId(String id,
T insObject)
insert element after the element having specified id attribute.
|
boolean |
insertBeforeId(String id,
String insString)
insert string before the element having specified id attribute.
|
<T extends AbstractJaxb> |
insertBeforeId(String id,
T insObject)
insert element before the element having specified id attribute.
|
boolean |
isSetId()
NOTICE: this method is dummy for make coding easy.
|
<T extends AbstractJaxb> |
remove(T target)
delete element that has specified attribute within descendant element
of oneself.
|
String |
removeAria(String key)
remove a specified aria-* attribute.
|
boolean |
removeById(String id)
delete element that has specified id attribute within descendant element
of oneself.
|
<T extends AbstractJaxb> |
removeCssClass(String clazz)
remove specified class attribute if having it.
|
String |
removeData(String key)
remove a specified data-* attribute.
|
<T extends AbstractJaxb> |
removeDescendants(Class<T> tagType)
delete all descendant elements that is specified tag type.
|
<T extends AbstractJaxb> |
removeDescendants(String clazz)
delete all descendant elements having specified class attribute
|
<T extends AbstractJaxb> |
removeDescendants(String clazz,
Class<T> tagType)
delete all descendant elements that is specified tag type having
specified class attribute.
|
void |
removeEmptyCssClass()
Remove class attribute if it has no value.
|
void |
removeInner()
remove inner content of this tag.
|
<T extends AbstractJaxb> |
replace(T target,
T replacement)
replace element that has specified attribute within descendant element of
oneself.
|
<T extends AbstractJaxb> |
replaceById(String id,
String replacement)
replace element by string.
|
<T extends AbstractJaxb> |
replaceById(String id,
T replacement)
replace element that has specified id attribute within descendant element
of oneself.
|
<T extends AbstractJaxb> |
replaceDescendants(Class<T> tagType,
String replacement)
replace all descendant element that is specified tag type by String
|
<T extends AbstractJaxb> |
replaceDescendants(Class<T> tagType,
T replacement)
replace all descendant elements that is specified tag type.
|
<T extends AbstractJaxb> |
replaceDescendants(String clazz,
Class<T> tagType,
String replacement)
replace all the descendant elements by String.
|
<T extends AbstractJaxb> |
replaceDescendants(String clazz,
Class<T> tagType,
T replacement)
replace all the descendant elements that is specified tag type having
specified class attribute.
|
<T extends AbstractJaxb> |
replaceDescendants(String clazz,
String replacement)
replace descendant tag with string.
|
<T extends AbstractJaxb> |
replaceDescendants(String clazz,
T replacement)
replace all descendant elements that has specified class attribute.
|
void |
replaceInner(List<? extends Object> replacement)
Replace whole of inside the tag by the whole elements of the list.
If the element can not be use in this tag, There is a case that will be exclude. |
void |
replaceInner(String replacement)
Replace whole of inside the tag by replacement.
If this tag can not have String directory (ex. |
<T extends AbstractJaxb> |
replaceInner(T replacement)
Replace whole of inside the tag by replacement.
For various reasons, this method does NOT use deep copy of replacement. It is recommended to use copy(T) in method argument. |
void |
setAria(String key,
String value)
set area-* attribute
|
void |
setData(String key,
String value)
set data-* attribute
|
void |
setId(String id)
set id attribute.
|
void |
setStyle(String value)
NOTICE: this method is dummy for make coding easy.
|
<T extends AbstractJaxb> |
setStyleByTreeMap(TreeMap<String,String> styleMap)
write style attribute by TreeMap
|
byte[] |
toByteArray()
returns byte sequence of myself.
|
String |
toString()
FOR DEBUG.
|
void |
unsetAllId()
remove id attribute of all descendant elements.
|
void |
unsetAllId(Pattern pattern)
remove id attribute that matches specified regex.
|
public <T> T cast(Class<T> clazz)
type cast.
// usage: // get a TD tag of first row, first column. Td td = html.getById("foo", Table.class).getTr().get(0).getThOrTd().get(0) .cast(Td.class);
clazz
- tag type of org.mixer2.jaxb.xhtml.*public <T extends AbstractJaxb> T getById(String id, Class<T> tagType) throws TagTypeUnmatchException
get tag that has specified id attribute. You don't need to cast() because you can specify the tag type.
// sample: get a Div tag having id="foo" attribute. html.getById("foo", Div.class);
id
- tagType
- TagTypeUnmatchException
public <T extends AbstractJaxb> T getById(String id)
get tag that has specified id attribute. To use return value as ussual tag, you must cast() it.
id
- public <T extends AbstractJaxb> boolean remove(T target)
delete element that has specified attribute within descendant element of oneself. you can't delete oneself.
target
- public void removeInner()
remove inner content of this tag.
public boolean removeById(String id)
delete element that has specified id attribute within descendant element of oneself. you can't delete oneself.
id
- public <T extends AbstractJaxb> boolean replace(T target, T replacement) throws TagTypeUnmatchException
replace element that has specified attribute within descendant element of oneself. you can't replace oneself. It will be replaced by deep copy of "replacement"
target
- replacement
- TagTypeUnmatchException
public <T extends AbstractJaxb> boolean replaceById(String id, T replacement) throws TagTypeUnmatchException
replace element that has specified id attribute within descendant element of oneself. you can't replace oneself. It will be replaced by deep copy of "replacement"
id
- replacement
- TagTypeUnmatchException
public <T extends AbstractJaxb> boolean replaceById(String id, String replacement) throws TagTypeUnmatchException
replace element by string. you can't replace oneself.
id
- replacement
- TagTypeUnmatchException
public <T extends AbstractJaxb> List<T> getDescendants(String clazz, Class<T> tagType)
scan descendant element that is specified tag type having specified class attribute and return it as List.
// usage: // get all div objects having "foo" class List<Div> divList = html.getDescendants("foo", Div.class); // get all Table objects having "bar" class within <div id="foo"> List<Table> tbList = html.getById("foo", Div.class).getDescendants("bar", Table.class);
clazz
- tagType
- public <T extends AbstractJaxb> List<T> getDescendants(Class<T> tagType)
scan descendant elements that has specified tag type and return it as List.
// usage: // get all div objects. html.getDescendants(Div.class); // get all table objects within <div id="foo"> html.getById("foo", Div.class).getDescendants(Table.class);
tagType
- public <T extends AbstractJaxb> List<T> getDescendants(String clazz)
scan descendant elements that has specified class attribute and return it as List
clazz
- class attributepublic <T extends AbstractJaxb> void removeDescendants(String clazz, Class<T> tagType)
delete all descendant elements that is specified tag type having specified class attribute.
clazz
- class attributetagType
- public <T extends AbstractJaxb> void removeDescendants(Class<T> tagType)
delete all descendant elements that is specified tag type.
tagType
- public <T extends AbstractJaxb> void removeDescendants(String clazz)
delete all descendant elements having specified class attribute
clazz
- class attributepublic <T extends AbstractJaxb> void replaceDescendants(String clazz, Class<T> tagType, T replacement) throws TagTypeUnmatchException
replace all the descendant elements that is specified tag type having specified class attribute. this method use deep copy of "replacement"
clazz
- class attributetagType
- replacement
- TagTypeUnmatchException
public <T extends AbstractJaxb> void replaceDescendants(String clazz, Class<T> tagType, String replacement) throws TagTypeUnmatchException
replace all the descendant elements by String. The target is specified tag type having specified class attribute.
clazz
- class attributetagType
- replacement
- TagTypeUnmatchException
public <T extends AbstractJaxb> void replaceDescendants(Class<T> tagType, T replacement) throws TagTypeUnmatchException
replace all descendant elements that is specified tag type. This method use deep copy of "replacement"
tagType
- replacement
- TagTypeUnmatchException
public <T extends AbstractJaxb> void replaceDescendants(String clazz, T replacement) throws TagTypeUnmatchException
clazz
- class attributereplacement
- TagTypeUnmatchException
public <T extends AbstractJaxb> void replaceDescendants(Class<T> tagType, String replacement) throws TagTypeUnmatchException
replace all descendant element that is specified tag type by String
指定したタグ型の子孫要素を文字列で置換します。
tagType
- replacement
- TagTypeUnmatchException
public <T extends AbstractJaxb> void replaceDescendants(String clazz, String replacement) throws TagTypeUnmatchException
replace descendant tag with string. specifying class property.
clazz
- class attributereplacement
- TagTypeUnmatchException
public <T extends AbstractJaxb> void replaceInner(T replacement)
Replace whole of inside the tag by replacement.
For various reasons, this method does NOT use deep copy of replacement.
It is recommended to use copy(T) in method argument.
// div and p is instance of Div, p tag object. Div div = TagCreator.div(); P p = TagCreator.p(); p.getContent().add("foo"); div.replaceInner(p.copy(P.class)); // *** using copy() p.getContent().add("bar"); System.out.println(mixer2Engine.saveToString(div)); // you get <div><p>foo</p></div>anti pattern. use with caution.
// divA and divB is instance of Div tag object. Div div = TagCreator.div(); P p = TagCreator.p(); p.getContent().add("foo"); div.replaceInner(p); // *** without copy() p.getContent().add("bar"); System.out.println(mixer2Engine.saveToString(div)); // you get <div><p>foo bar</p></div>
replacement
- public void replaceInner(String replacement)
Replace whole of inside the tag by replacement.
If this tag can not have String directory (ex. <table> tag), do nothing.
replacement
- public void replaceInner(List<? extends Object> replacement)
Replace whole of inside the tag by the whole elements of the list.
If the element can not be use in this tag, There is a case that will be exclude.
replacement
- public <T extends AbstractJaxb> boolean insertAfterId(String id, T insObject) throws TagTypeUnmatchException
insert element after the element having specified id attribute. This method use deep copy of "insObject"
id
- id attributeinsObject
- TagTypeUnmatchException
public boolean insertAfterId(String id, String insString) throws TagTypeUnmatchException
insert String after the element having specified id attribute
id
- insString
- TagTypeUnmatchException
public <T extends AbstractJaxb> boolean insertBeforeId(String id, T insObject) throws TagTypeUnmatchException
insert element before the element having specified id attribute. This method use deep copy of insObject
id
- insObject
- TagTypeUnmatchException
public boolean insertBeforeId(String id, String insString) throws TagTypeUnmatchException
insert string before the element having specified id attribute.
id
- insString
- TagTypeUnmatchException
public <T extends AbstractJaxb> void setStyleByTreeMap(TreeMap<String,String> styleMap)
write style attribute by TreeMap
// usage: TreeMap<String, String> styleMap = new TreeMap<String, String>(); styleMap.put("border-color", "red"); html.getById(Div.class, "hellomsg").setStyleByTreeMap(styleMap); // output: // <div id="hellomsg" style="border-color:red;">...</div>
styleMap
- public TreeMap<String,String> getStyleAsTreeMap()
return style attributes as TreeMap
public <T extends AbstractJaxb> T copy(Class<T> tagType) throws TagTypeUnmatchException
return deep copy of myself
NOTICE: DO NOT USE clone() and copyTo() method ! They has bug. Use this copy() method instead of them.
// usage Div div = html.getById(Div.class, "foo"); Div div2 = div.copy(Div.class);
tagType
- TagTypeUnmatchException
public <T extends AbstractJaxb> T copyNoException(Class<T> tagType)
same as copy(Class)
but never throw exception.
return null if failed to copy.
tagType
- public void setData(String key, String value)
set data-* attribute
Div div = new Div(); div.setData("foo", "bar"); // you get <div data-foo="bar"></div>
key
- data-"key"public String getData(String key)
return the value of data-* attribute. If not set, return null.
key
- data-"key"public void setAria(String key, String value)
set area-* attribute
key
- aria-"key"value
- public String getAria(String key)
return the value of area-* attribute. If not set, return null.
key
- aria-"key"public String removeData(String key)
remove a specified data-* attribute.
key
- data-"key"public String removeAria(String key)
remove a specified aria-* attribute.
key
- data-"key"public Map<QName,String> getOtherAttributes()
get other attribute map. NOTICE: this method is dummy for make coding easy. Acrually, this method is overridden by each tag class.
public String getId()
get id attribute. return null if not set. NOTICE: this method is dummy for make coding easy. Acrually, this method is overridden by each tag class.
public void setId(String id)
set id attribute. NOTICE: this method is dummy for make coding easy. Acrually, this method is overridden by each tag class.
public boolean isSetId()
NOTICE: this method is dummy for make coding easy. Acrually, this method is overridden by each tag class.
public void unsetAllId()
remove id attribute of all descendant elements. Also, remove id attribute of myself.
public void unsetAllId(Pattern pattern)
remove id attribute that matches specified regex. Also, matches and remove of myself.
public String getStyle()
NOTICE: this method is dummy for make coding easy. Acrually, this method is overridden by each tag class.
public void setStyle(String value)
NOTICE: this method is dummy for make coding easy. Acrually, this method is overridden by each tag class.
value
- public List<String> getCssClass()
return class attribute as List. NOTICE: this method is dummy for make coding easy. Acrually, this method is overridden by each tag class.
public <T extends AbstractJaxb> boolean hasCssClass(String clazz)
return true if have specified class attribute.
clazz
- class attributepublic <T extends AbstractJaxb> void addCssClass(String clazz)
add class attribute. If already set, do nothing.
public <T extends AbstractJaxb> void removeCssClass(String clazz)
remove specified class attribute if having it.
public void removeEmptyCssClass()
Remove class attribute if it has no value. This method prevent no-meaning class attribute like below.
<div class="">....</div>
public <T extends AbstractJaxb> List<T> getByNameAsList(String name, Class<T> tagType)
find tag by "name" property returning as List.
T
- name
- tagType
- public <T extends AbstractJaxb> T getByName(String name, Class<T> tagType)
find tag by "name" property. (the first one in this tag)
T
- name
- tagType
- public Header getHeader()
get header tag (the first one in this tag)
public Footer getFooter()
get footer tag (the first one in this tag)
public byte[] toByteArray() throws IOException
returns byte sequence of myself.
IOException
Copyright © 2021 Project Mixer2. All rights reserved.