Class Element
- java.lang.Object
-
- org.symphonyoss.symphony.messageml.elements.Element
-
- Direct Known Subclasses:
Bold,BulletList,Button,Card,CardBody,CardHeader,Chime,Code,Div,Entity,Form,Header,HorizontalRule,Image,Italic,LineBreak,Link,ListItem,MessageML,OrderedList,Paragraph,Preformatted,Span,Table,TableBody,TableCell,TableFooter,TableHeader,TableHeaderCell,TableRow,TextNode
public abstract class Element extends Object
Base class for MessageML elements. Contains methods for constructing MessageML document trees and their PresentationML and Markdown representation, overridden in subclasses if special treatment is required. By default all elements support the "class" and "style" attributes and translate to PresentationML as container elements including their children. To override this behaviour (e.g. to make the element empty), overload the respective methods in subclasses of this class. The intended use of this class is primarily internal. The main entry point are parse() methods inMessageMLContext.- Since:
- 3/27/17
- Author:
- lukasz
-
-
Field Summary
Fields Modifier and Type Field Description static StringCLASS_ATTRprotected FormatEnumformatstatic StringSTYLE_ATTR
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddChild(Element child)Append a child to the element.StringasText()Return a text representation of the element, descending into its children.voidbuildAll(MessageMLParser context, Element element)Process a DOM element, descending into its children, and construct the output MessageML tree.List<Element>findElements(Class<?> type)Search the MessageML tree (depth-first) for elements of a given type.List<Element>findElements(String tag)Search the MessageML tree (depth-first) for elements with a given MessageML tag.List<Element>findElements(String attribute, String value)Search the MessageML tree (depth-first) for elements with a given attribute-value pair.StringgetAttribute(String attr)Return the value of the element's attribute "attr".Map<String,String>getAttributes()Return a map of the element's attributes.ElementgetChild(int n)Return the nth child of the element.List<Element>getChildren()Return a list of the element's children.FormatEnumgetFormat()Return the format (MessageML or PresentationML) of the element.StringgetMessageMLTag()Return the element's MessageML tag.ElementgetParent()Return the parent of the element.intsize()Return the number of children of the element.
-
-
-
Field Detail
-
CLASS_ATTR
public static final String CLASS_ATTR
- See Also:
- Constant Field Values
-
STYLE_ATTR
public static final String STYLE_ATTR
- See Also:
- Constant Field Values
-
format
protected FormatEnum format
-
-
Method Detail
-
buildAll
public void buildAll(MessageMLParser context, Element element) throws InvalidInputException, ProcessingException
Process a DOM element, descending into its children, and construct the output MessageML tree.
-
asText
public String asText()
Return a text representation of the element, descending into its children.
-
getMessageMLTag
public String getMessageMLTag()
Return the element's MessageML tag.
-
getAttribute
public String getAttribute(String attr)
Return the value of the element's attribute "attr".
-
getChild
public Element getChild(int n)
Return the nth child of the element.
-
addChild
public void addChild(Element child)
Append a child to the element.
-
size
public int size()
Return the number of children of the element.
-
getParent
public Element getParent()
Return the parent of the element.
-
getFormat
public FormatEnum getFormat()
Return the format (MessageML or PresentationML) of the element.
-
findElements
public List<Element> findElements(Class<?> type)
Search the MessageML tree (depth-first) for elements of a given type.- Parameters:
type- the class of elements to find- Returns:
- found elements
-
findElements
public List<Element> findElements(String tag)
Search the MessageML tree (depth-first) for elements with a given MessageML tag.- Parameters:
tag- the MessageML tag of elements to find- Returns:
- found elements
-
-