If an image has been inserted in a DOORS object,
the image data can be retrieved in the Object.image
attribute.
Here is a sample code using this attribute to export the image as a PNG file:
import java.awt.image.BufferedImage; import javax.imageio.ImageIO; import com.sodius.mdw.corext.model.ImportedImage; import com.sodius.mdw.metamodel.doors.*; ... com.sodius.mdw.metamodel.doors.Object object = ...; String imageData = object.getImage(); if (imageData != null && imageData.length() != 0) { ImportedImage importedImage = ImportedImage.read(imageData, null); BufferedImage image = ImageIO.read(new ByteArrayInputStream(importedImage.getContents())); if (image != null) { ImageIO.write(image, "png", myFile); } }
Note: it is recommended to set the
Common.OPTION_IGNORE_OLE_PREVIEW_IMAGES
option to true
so that Object.getImage()
returns an image content
only if this is a DOORS picture object.
To read OLE objects preview images, refer to the next section.
OLE objects can be inserted in a DOORS Object Text.
In that case the Object.objectText
attribute contains HTML tags that reference the OLE objects, e.g.:
<html><body><p><object data="path_to_ole_object"/></p></body></html>
The class
RichTextUtils
provides facilities to read attachments contained in OLE objects.
Here is a sample code that determines attached OLE objects and get access to their content (including their preview images):
import com.sodius.mdw.metamodel.doors.*; import com.sodius.mdw.metamodel.doors.richtext.Attachment; import com.sodius.mdw.metamodel.doors.richtext.AttachmentResolver; import com.sodius.mdw.metamodel.doors.richtext.RichTextUtils; ... com.sodius.mdw.metamodel.doors.Object object = ...; AttachmentResolver resolver = RichTextUtils.createAttachmentResolver(object.eModel()); for (Attachment attachment : RichTextUtils.getAttachments(object.getObjectText())) { System.out.println("Found an OLE object: " + attachment.getPath()); InputStream input = resolver.getInputStream(attachment); ... // now handling the preview image of the OLE object Attachment preview = RichTextUtils.getAttachmentPreview(attachment); input = resolver.getInputStream(preview); } resolver.dispose();
The Common.OPTION_IGNORE_OLE_PREVIEW_IMAGES
option must be set to false
so that preview images of OLE objects are available.