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.
Modifier and Type | Field and Description |
---|---|
static String |
DOCTYPE_HTML_TRANSITIONAL
HTML Transitional doctype
|
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.
|
static String |
OPTION_XHTML_SHOW_REGULAR_SPACES
Option to determine whether consecutive spaces are to convert as HTML non-breaking spaces or be written as is.
|
static String |
OPTION_XHTML_SHOW_SURROUNDING_PARAGRAPH
Option to determine whether the converter should always insert a paragraph element within the body element
when converting a plain text value to an XHTML value.
|
Modifier and Type | Method and Description |
---|---|
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.
|
public static final String OPTION_XHTML_DOCTYPE
public static final String DOCTYPE_OMIT
public static final String DOCTYPE_STRICT
public static final String DOCTYPE_TRANSITIONAL
public static final String DOCTYPE_HTML_TRANSITIONAL
public static final String OPTION_XHTML_SHOW_BODY_ONLY
false
.public static final String OPTION_XHTML_SHOW_SURROUNDING_PARAGRAPH
public static final String OPTION_XHTML_SHOW_REGULAR_SPACES
Setting this option to true
makes the converter to always output regular spaces as is. Consecutive regular spaces are visually
trimmed
to one in browsers.
Setting this option to false
(or leaving it empty) makes the converter to output non-breaking spaces (" "
)
in the case of consecutive spaces. This allows browsers to display an HTML output that visually reflects the plain text original version.
public static final String OPTION_PLAIN_ORDERED_LIST_STRING
String
used to prefix in plain text an ordered list item.
Default value is .
public static final String OPTION_PLAIN_UNORDERED_LIST_STRING
String
used to prefix in plain text an unordered list item.
Default value is -
public static RichText valueOf(String text)
text
- the text to wrap as RichTextvalueOf(String, RichTextType)
public static RichText valueOf(String text, RichTextType type)
text
- the text to wrap as RichTexttype
- the underlying format of the textvalueOf(String)
public String getValue()
public boolean equals(Object obj)
true
if the argument is a RichText of same type wrapping the same text.public RichTextType getType()
public boolean isEmpty()
true
if the underlying value length is 0
.true
if the underlying value length is 0
, false
otherwise.public String toPlainText()
WrappedException
- if the rich text contains invalid data.
The WrappedException
cause is likely to be an instance of SAXParseException
.
Such exception was silently ignored until MDWorkbench 3.5.14.public String toPlainText(Map<String,?> options)
options
- Options that configure the conversion processWrappedException
- if the rich text contains invalid data.
The WrappedException
cause is likely to be an instance of SAXParseException
.
Such exception was silently ignored until MDWorkbench 3.5.14.public final String toRTF()
RTF Attachments
Since MDWorkbench 3.5.14, each XHTML <object data="myPath.rtf"/>
element is converted to the following RTF construct:
{\*\attachment myPath.rtf}
.
In addition, each <object data="myPath.rtf"><param name="inline" value="true"></object>
element is converted to
the following RTF construct: {\*\attachment\inline myPath.rtf}
Such RTF attachment construct is non standard and safely ignored by RTF processors. It is however handled by MDAccess for DOORS to process
inline RTF attachments and nested attachments. Refer to the documentation of MDAccess for DOORS for more details.
WrappedException
- if the rich text contains invalid data.
The WrappedException
cause is likely to be an instance of SAXParseException
.
Such exception was silently ignored until MDWorkbench 3.5.14.public String toRTF(Map<String,?> options)
RTF Attachments
Since MDWorkbench 3.5.14, each XHTML <object data="myPath.rtf"/>
element is converted to the following RTF construct:
{\*\attachment myPath.rtf}
.
In addition, each <object data="myPath.rtf"><param name="inline" value="true"></object>
element is converted to
the following RTF construct: {\*\attachment\inline myPath.rtf}
Such RTF attachment construct is non standard and safely ignored by RTF processors. It is however handled by MDAccess for DOORS to process
inline RTF attachments and nested attachments. Refer to the documentation of MDAccess for DOORS for more details.
options
- Options that configure the conversion processWrappedException
- if the rich text contains invalid data.
The WrappedException
cause is likely to be an instance of SAXParseException
.
Such exception was silently ignored until MDWorkbench 3.5.14.public String toXHTML()
WrappedException
- if the rich text contains invalid data.
The WrappedException
cause is likely to be an instance of SAXParseException
.
Such exception was silently ignored until MDWorkbench 3.5.14.public String toXHTML(Map<String,?> options)
options
- Options that configure the conversion processWrappedException
- if the rich text contains invalid data.
The WrappedException
cause is likely to be an instance of SAXParseException
.
Such exception was silently ignored until MDWorkbench 3.5.14.public RichText convert(RichTextType type)
type
- the format this text must be converted to.WrappedException
- if the rich text contains invalid data.
The WrappedException
cause is likely to be an instance of SAXParseException
.
Such exception was silently ignored until MDWorkbench 3.5.14.public final RichText convert(RichTextType type, Map<String,?> options)
type
- the format this text must be converted to.options
- Options that configure the conversion process.WrappedException
- if the rich text contains invalid data.
The WrappedException
cause is likely to be an instance of SAXParseException
.
Such exception was silently ignored until MDWorkbench 3.5.14.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.