public final class RichTextUtils extends Object
Modifier and Type | Method and Description |
---|---|
static AttachmentResolver |
createAttachmentResolver(File baseLocation)
Returns an instance of
AttachmentResolver that uses the specified base location
to resolve logical attachment paths to access to file content. |
static AttachmentResolver |
createAttachmentResolver(Model model)
Returns an instance of
AttachmentResolver that can retrieve OLE objects content stored in the DOORS database
and read in the specified Model. |
static Attachment |
getAttachmentPreview(Attachment attachment)
Returns a logical attachment describing the preview image of the specified OLE object attachment.
|
static Collection<Attachment> |
getAttachments(Model model)
Parses all logical attachments contained in all DOORS objects of the specified Model.
|
static Collection<Attachment> |
getAttachments(RichText text)
Parses logical attachments contained in the specified rich text.
|
static Collection<Attachment> |
getAttachments(String xhtml)
Parses logical attachments contained in the specified text.
|
static String |
getMimeType(String filename,
String defaultType)
Returns the known MIME type (e.g.
|
public static String getMimeType(String filename, String defaultType)
image/jpeg
) associated with the specified file name,
based on the file extension.filename
- the file name for which MIME type is to be computeddefaultType
- the default MIME type to return, if one cannot be determined for the file namedefaultType
.public static Collection<Attachment> getAttachments(RichText text)
An attachment might be embedded in a rich text as in the following snippet:
"<html><body><p>Attachment: <object data="myFile.docx"/></p></body></html>"
The attachment content (i.e. the bytes) shall then be obtained with an AttachmentResolver
.
A preview image of the attachment might be available using the getAttachmentPreview()
method.
Attachment properties
Since 3.8.1, each returned Attachment
is also instance of com.sodius.mdw.core.util.PropertySet
. The
PropertySet
contains a property corresponding to each nested <param/>
element. Typically the following XHTML
construct:
<object data="path"><param name="inline" value="true"/></object>
results in Attachment instance on which the following call returns true:
boolean isInline = myAttachment.getProperty("inline", false);
text
- rich text that might contains attachments.org.eclipse.emf.common.util.WrappedException
- if the rich text contains invalid XHTML data.
The WrappedException
cause is likely to be an instance of SAXParseException
.
Such exception was silently ignored until MDWAccess for DOORS 3.8.1.AttachmentResolver
,
getAttachmentPreview(Attachment)
public static Collection<Attachment> getAttachments(String xhtml)
An attachment might be embedded in a rich text as in the following snippet:
"<html><body><p>Attachment: <object data="myFile.docx"/></p></body></html>"
The attachment content (i.e. the bytes) shall then be obtained with an AttachmentResolver
.
A preview image of the attachment might be available using the getAttachmentPreview()
method.
Attachment properties
Since 3.8.1, each returned Attachment
is also instance of com.sodius.mdw.core.util.PropertySet
. The
PropertySet
contains a property corresponding to each nested <param/>
element. Typically the following XHTML
construct:
<object data="path"><param name="inline" value="true"/></object>
results in Attachment instance on which the following call returns true:
boolean isInline = myAttachment.getProperty("inline", false);
xhtml
- rich text that might contains attachments.AttachmentResolver
,
getAttachmentPreview(Attachment)
public static Collection<Attachment> getAttachments(Model model)
An attachment might be embedded in a rich text as in the following snippet:
"<html><body><p>Attachment: <object data="myFile.docx"/></p></body></html>"
The attachment content (i.e. the bytes) shall then be obtained with an AttachmentResolver
.
A preview image of the attachment might be available using the getAttachmentPreview()
method.
Attachment properties
Since 3.8.1, each returned Attachment
is also instance of com.sodius.mdw.core.util.PropertySet
. The
PropertySet
contains a property corresponding to each nested <param/>
element. Typically the following XHTML
construct:
<object data="path"><param name="inline" value="true"/></object>
results in Attachment instance on which the following call returns true:
boolean isInline = myAttachment.getProperty("inline", false);
model
- a model which contains modules and objects.org.eclipse.emf.common.util.WrappedException
- if a rich text contains invalid XHTML data.
The WrappedException
cause is likely to be an instance of SAXParseException
.
Such exception was silently ignored until MDWAccess for DOORS 3.8.1.AttachmentResolver
,
getAttachmentPreview(Attachment)
public static Attachment getAttachmentPreview(Attachment attachment)
This method is used to retrieve the preview images of OLE objects read from a DOORS module. OLE object previews are available only if the model
was read with the OPTION_IGNORE_OLE_PREVIEW_IMAGES
option set to false
.
The preview image content (i.e. the bytes) shall then be obtained with an AttachmentResolver
provided by the
createAttachmentResolver(Model)
method.
attachment
- the OLE object attachment for which a preview image is desired.createAttachmentResolver(Model)
,
Common.OPTION_IGNORE_OLE_PREVIEW_IMAGES
public static AttachmentResolver createAttachmentResolver(File baseLocation)
AttachmentResolver
that uses the specified base location
to resolve logical attachment paths to access to file content.
If the base location is a directory, the resolver will combine this directory and the relative path of an attachment to resolve to a file and access its content. If the base location is a zip file, the resolver will look for entries inside the zip matching the attachment path.
The returned instance also implements the AttachmentSizeProvider
interface.
baseLocation
- either a directory or a zip file.AttachmentSizeProvider
public static AttachmentResolver createAttachmentResolver(Model model)
AttachmentResolver
that can retrieve OLE objects content stored in the DOORS database
and read in the specified Model.
The returned instance also implements the AttachmentSizeProvider
interface.
The returned instance can provide content for OLE object preview images obtained with the getAttachmentPreview()
method.
model
- a DOORS model read using the DOORS Application model reader.AttachmentSizeProvider
,
getAttachmentPreview(Attachment)