Class MessageMLContext
- java.lang.Object
-
- org.symphonyoss.symphony.messageml.MessageMLContext
-
public class MessageMLContext extends Object
The main entry point for parsing string message data in MessageML or Markdown formats and associated JSON entity data intoMessageMLdocument trees and converting them to output formats (PresentationML and Markdown). To generate a messageML tree, use one of parseMessageML() or parseMarkdown(). Once the message has been parsed, use one of the get() methods to retrieve the desired output format.- Since:
- 3/21/17
- Author:
- lukasz
-
-
Constructor Summary
Constructors Constructor Description MessageMLContext(IDataProvider dataProvider)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description StringgenerateShortId()com.fasterxml.jackson.databind.JsonNodegetEntities()Retrieve message entities (tags, mentions, urls) in the legacy JSON format.com.fasterxml.jackson.databind.node.ObjectNodegetEntityJson()Retrieve a JSON representation of entity data (EntityJSON).StringgetMarkdown()Retrieve a string representation of the message in Markdown.MessageMLgetMessageML()Retrieve the MessageML document tree.StringgetPresentationML()Retrieve a string representation of the message in PresentationML.StringgetText()Retrieve a string representation of the message by getting the values of its PresentationML elements.StringgetText(boolean preserveWhitespace)Retrieve a string representation of the message by getting the values of its PresentationML elements.voidparseMarkdown(String message, com.fasterxml.jackson.databind.JsonNode entities, com.fasterxml.jackson.databind.JsonNode media)Parse a Markdown message into its MessageMLV2 representation.voidparseMessageML(String message, String entityJson, String version)Parse the text contents of the message and optionally EntityJSON into a MessageMLV2 message.
-
-
-
Constructor Detail
-
MessageMLContext
public MessageMLContext(IDataProvider dataProvider)
-
-
Method Detail
-
parseMessageML
public void parseMessageML(String message, String entityJson, String version) throws InvalidInputException, IOException, ProcessingException
Parse the text contents of the message and optionally EntityJSON into a MessageMLV2 message. Expands Freemarker templates and generates document tree structures for serialization into output formats with the respective get() methods.- Parameters:
message- string containing a MessageMLV2 message with optional Freemarker templatesentityJson- string containing EntityJSON dataversion- string containing the version of the message format- Throws:
InvalidInputException- thrown on invalid MessageMLV2 inputProcessingException- thrown on errors generating the document treeIOException- thrown on invalid EntityJSON input
-
parseMarkdown
public void parseMarkdown(String message, com.fasterxml.jackson.databind.JsonNode entities, com.fasterxml.jackson.databind.JsonNode media) throws InvalidInputException
Parse a Markdown message into its MessageMLV2 representation. Generates document tree structures for serialization into output formats with the respective get() methods.- Parameters:
message- string containing a message in Markdownentities- additional entity data in JSON- Throws:
InvalidInputException
-
getMessageML
public MessageML getMessageML() throws IllegalStateException
Retrieve the MessageML document tree.- Throws:
IllegalStateException- thrown if the message hasn't been parsed yet
-
getPresentationML
public String getPresentationML() throws IllegalStateException
Retrieve a string representation of the message in PresentationML.- Throws:
IllegalStateException- thrown if the message hasn't been parsed yet
-
getEntityJson
public com.fasterxml.jackson.databind.node.ObjectNode getEntityJson()
Retrieve a JSON representation of entity data (EntityJSON).
-
getMarkdown
public String getMarkdown() throws IllegalStateException
Retrieve a string representation of the message in Markdown.- Throws:
IllegalStateException- thrown if the message hasn't been parsed yet
-
getEntities
public com.fasterxml.jackson.databind.JsonNode getEntities() throws IllegalStateExceptionRetrieve message entities (tags, mentions, urls) in the legacy JSON format.- Throws:
IllegalStateException- thrown if the message hasn't been parsed yet
-
getText
public String getText() throws InvalidInputException, ProcessingException, IllegalStateException
Retrieve a string representation of the message by getting the values of its PresentationML elements. This method returnsNode.getTextContent()of the top-level document tree.- Throws:
IllegalStateException- thrown if the message hasn't been parsed yetInvalidInputExceptionProcessingException
-
getText
public String getText(boolean preserveWhitespace) throws InvalidInputException, ProcessingException, IllegalStateException
Retrieve a string representation of the message by getting the values of its PresentationML elements. This method returnsNode.getTextContent()of each individual element of the tree, separated by a single space- Parameters:
preserveWhitespace- if false, trims the leading and trailing whitespce of each element- Throws:
IllegalStateException- thrown if the message hasn't been parsed yetInvalidInputExceptionProcessingException
-
generateShortId
public String generateShortId()
-
-