Class RichTextUtils
- java.lang.Object
-
- com.sodius.mdw.metamodel.doors.richtext.RichTextUtils
-
public final class RichTextUtils extends Object
Provides utilities to handle DOORS rich text formatting and OLE objects.- Since:
- 3.2.0
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static AttachmentResolver
createAttachmentResolver(Model model)
Returns an instance ofAttachmentResolver
that can retrieve OLE objects content stored in the DOORS database and read in the specified Model.static AttachmentResolver
createAttachmentResolver(File baseLocation)
Returns an instance ofAttachmentResolver
that uses the specified base location to resolve logical attachment paths to access to file content.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.
-
-
-
Method Detail
-
getMimeType
public static String getMimeType(String filename, String defaultType)
Returns the known MIME type (e.g.image/jpeg
) associated with the specified file name, based on the file extension.- Parameters:
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 name- Returns:
- the known MIME type of the file name, otherwise the given
defaultType
.
-
getAttachments
public static Collection<Attachment> getAttachments(RichText text)
Parses logical attachments contained in the specified rich 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 returnedAttachment
is also instance ofcom.sodius.mdw.core.util.PropertySet
. ThePropertySet
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);
- Parameters:
text
- rich text that might contains attachments.- Returns:
- all attachments contained in the specified rich text.
- Throws:
org.eclipse.emf.common.util.WrappedException
- if the rich text contains invalid XHTML data. TheWrappedException
cause is likely to be an instance ofSAXParseException
. Such exception was silently ignored until MDWAccess for DOORS 3.8.1.- See Also:
AttachmentResolver
,getAttachmentPreview(Attachment)
-
getAttachments
public static Collection<Attachment> getAttachments(String xhtml)
Parses logical attachments contained in the specified 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 returnedAttachment
is also instance ofcom.sodius.mdw.core.util.PropertySet
. ThePropertySet
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);
- Parameters:
xhtml
- rich text that might contains attachments.- Returns:
- all attachments contained in the specified rich text.
- See Also:
AttachmentResolver
,getAttachmentPreview(Attachment)
-
getAttachments
public static Collection<Attachment> getAttachments(Model model)
Parses all logical attachments contained in all DOORS objects of the specified 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 returnedAttachment
is also instance ofcom.sodius.mdw.core.util.PropertySet
. ThePropertySet
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);
- Parameters:
model
- a model which contains modules and objects.- Returns:
- all logical attachments contained in all DOORS objects of the specified Model.
- Throws:
org.eclipse.emf.common.util.WrappedException
- if a rich text contains invalid XHTML data. TheWrappedException
cause is likely to be an instance ofSAXParseException
. Such exception was silently ignored until MDWAccess for DOORS 3.8.1.- See Also:
AttachmentResolver
,getAttachmentPreview(Attachment)
-
getAttachmentPreview
public static Attachment getAttachmentPreview(Attachment attachment)
Returns a logical attachment describing the preview image of the specified OLE object 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 tofalse
.The preview image content (i.e. the bytes) shall then be obtained with an
.AttachmentResolver
provided by thecreateAttachmentResolver(Model)
method.- Parameters:
attachment
- the OLE object attachment for which a preview image is desired.- Returns:
- the logical attachment describing the preview image.
- Since:
- 3.5.0
- See Also:
createAttachmentResolver(Model)
,Common.OPTION_IGNORE_OLE_PREVIEW_IMAGES
-
createAttachmentResolver
public static AttachmentResolver createAttachmentResolver(File baseLocation)
Returns an instance ofAttachmentResolver
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.- Parameters:
baseLocation
- either a directory or a zip file.- Returns:
- a attachment resolver that uses the base location to access attachment content.
- See Also:
AttachmentSizeProvider
-
createAttachmentResolver
public static AttachmentResolver createAttachmentResolver(Model model)
Returns an instance ofAttachmentResolver
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.- Parameters:
model
- a DOORS model read using the DOORS Application model reader.- Returns:
- a attachment resolver that can retrieve OLE objects content stored in the DOORS database.
- See Also:
AttachmentSizeProvider
,getAttachmentPreview(Attachment)
-
-