com.sodius.mdw.core.model
Class RichText

java.lang.Object
  extended by com.sodius.mdw.core.model.RichText

public final class RichText
extends Object

Holds a rich text representation, whose underlying format can either be XHTML or RTF. Conversion methods are provided to convert from one format to another (eg. RTF to XHTML).

It is worth noting it is not intended to be a general RTF-XHTML converter. Only a subset of the RTF and XHTML specifications are covered here. The converters have been designed to convert only what can be edited in the Model Editor. Any non-handled RTF or XHTML construct is simply ignored during the conversion process.

Since:
MDWorkbench 3.1.0

Field Summary
static String DOCTYPE_OMIT
          Doctype value to tell the converter to ignore the doctype.
static String DOCTYPE_STRICT
          XHTML Strict doctype.
static String DOCTYPE_TRANSITIONAL
          XHTML Transitional doctype
static String OPTION_PLAIN_ORDERED_LIST_STRING
          Option to specify the String used to prefix in plain text an ordered list item.
static String OPTION_PLAIN_UNORDERED_LIST_STRING
          Option to specify the String used to prefix in plain text an unordered list item.
static String OPTION_XHTML_DOCTYPE
          Options to specify the XHTML doctype to use.
static String OPTION_XHTML_SHOW_BODY_ONLY
          Option to determine if the converter should only output the contents of the body tag as an HTML fragment.
 
Method Summary
 RichText convert(RichTextType type)
          Converts the wrapped text into the specified format.
 RichText convert(RichTextType type, Map<String,?> options)
          Converts the wrapped text into the specified format.
 boolean equals(Object obj)
          Return true if the argument is a RichText of same type wrapping the same text.
 RichTextType getType()
          Return the format of the underlying text.
 String getValue()
          Returns the wrapped text as is.
 int hashCode()
           
 boolean isEmpty()
          Returns true if the underlying value length is 0.
 RichText simplify()
          Returns the most lightweight type of rich text that can represents the underlying value.
 String toPlainText()
          Converts the wrapped text into a plain text format.
 String toPlainText(Map<String,?> options)
          Converts the wrapped text into a plain text format.
 String toRTF()
          Converts the wrapped text into a RTF format.
 String toRTF(Map<String,?> options)
          Converts the wrapped text into a RTF format.
 String toString()
          Returns the plain text version of the underlying text.
 String toXHTML()
          Converts the wrapped text into an XHTML format.
 String toXHTML(Map<String,?> options)
          Converts the wrapped text into an XHTML format.
static RichText valueOf(String text)
          Creates a new RichText instance wrapping the specified text.
static RichText valueOf(String text, RichTextType type)
          Creates a new RichText instance wrapping the specified text, whose underlying format is known by the caller.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

OPTION_XHTML_DOCTYPE

public static final String OPTION_XHTML_DOCTYPE
Options to specify the XHTML doctype to use. Default value is Transitional.

See Also:
Constant Field Values

DOCTYPE_OMIT

public static final String DOCTYPE_OMIT
Doctype value to tell the converter to ignore the doctype.

See Also:
Constant Field Values

DOCTYPE_STRICT

public static final String DOCTYPE_STRICT
XHTML Strict doctype.

See Also:
Constant Field Values

DOCTYPE_TRANSITIONAL

public static final String DOCTYPE_TRANSITIONAL
XHTML Transitional doctype

See Also:
Constant Field Values

OPTION_XHTML_SHOW_BODY_ONLY

public static final String OPTION_XHTML_SHOW_BODY_ONLY
Option to determine if the converter should only output the contents of the body tag as an HTML fragment. Useful for incorporating text fragments as a portion of another page. Default value is false.

See Also:
Constant Field Values

OPTION_PLAIN_ORDERED_LIST_STRING

public static final String OPTION_PLAIN_ORDERED_LIST_STRING
Option to specify the String used to prefix in plain text an ordered list item. Default value is .

See Also:
Constant Field Values

OPTION_PLAIN_UNORDERED_LIST_STRING

public static final String OPTION_PLAIN_UNORDERED_LIST_STRING
Option to specify the String used to prefix in plain text an unordered list item. Default value is -

See Also:
Constant Field Values
Method Detail

valueOf

public static RichText valueOf(String text)
Creates a new RichText instance wrapping the specified text. This method will try to guess the underlying format of the text.

Parameters:
text - the text to wrap as RichText
Returns:
a new instance of RichText
See Also:
valueOf(String, RichTextType)

valueOf

public static RichText valueOf(String text,
                               RichTextType type)
Creates a new RichText instance wrapping the specified text, whose underlying format is known by the caller.

Parameters:
text - the text to wrap as RichText
type - the underlying format of the text
Returns:
a new instance of RichText
See Also:
valueOf(String)

getValue

public String getValue()
Returns the wrapped text as is.

Returns:
the wrapped text

hashCode

public int hashCode()
Overrides:
hashCode in class Object

equals

public boolean equals(Object obj)
Return true if the argument is a RichText of same type wrapping the same text.

Overrides:
equals in class Object

getType

public RichTextType getType()
Return the format of the underlying text.

Returns:
the format of the underlying text

isEmpty

public boolean isEmpty()
Returns true if the underlying value length is 0.

Returns:
true if the underlying value length is 0, false otherwise.

toPlainText

public String toPlainText()
Converts the wrapped text into a plain text format.

Returns:
the plain text conversion result

toPlainText

public String toPlainText(Map<String,?> options)
Converts the wrapped text into a plain text format.

Parameters:
options - Options that configure the conversion process
Returns:
the plain text conversion result

toRTF

public final String toRTF()
Converts the wrapped text into a RTF format.

Returns:
the RTF conversion result

toRTF

public String toRTF(Map<String,?> options)
Converts the wrapped text into a RTF format.

Parameters:
options - Options that configure the conversion process
Returns:
the RTF conversion result

toXHTML

public String toXHTML()
Converts the wrapped text into an XHTML format.

Returns:
the XHTML conversion result

toXHTML

public String toXHTML(Map<String,?> options)
Converts the wrapped text into an XHTML format.

Parameters:
options - Options that configure the conversion process
Returns:
the XHTML conversion result

convert

public RichText convert(RichTextType type)
Converts the wrapped text into the specified format.

Returns:
the conversion result wrapped as a new RichText instance.

convert

public final RichText convert(RichTextType type,
                              Map<String,?> options)
Converts the wrapped text into the specified format.

Parameters:
options - Options that configure the conversion process
Returns:
the conversion result wrapped as a new RichText instance.

simplify

public RichText simplify()

Returns the most lightweight type of rich text that can represents the underlying value.

If the underlying value if a non formatted RTF of XHTML text, it returns the plain text version. If the underlying value is a formatted RTF text, it returns the XHTML version.

Returns:
the most lightweight type of rich text that can represents the underlying value.

toString

public final String toString()
Returns the plain text version of the underlying text.

Overrides:
toString in class Object
Returns:
the plain text version of the underlying text.