Class RichTextUtils


  • public final class RichTextUtils
    extends Object
    Provides utilities to handle DOORS rich text formatting and OLE objects.
    Since:
    3.2.0
    • 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 computed
        defaultType - 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 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);

        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. The WrappedException cause is likely to be an instance of SAXParseException. 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 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);

        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 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);

        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. The WrappedException cause is likely to be an instance of SAXParseException. 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 to false.

        The preview image content (i.e. the bytes) shall then be obtained with an AttachmentResolver provided by the createAttachmentResolver(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 of 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.

        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 of 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.

        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)