Class FileAttachmentsHelper


  • @OpenApiAll
    public class FileAttachmentsHelper
    extends java.lang.Object
    Methods to work with files attached to the model: create attached file, read it or remove the attachment.
    • Constructor Detail

      • FileAttachmentsHelper

        public FileAttachmentsHelper()
    • Method Detail

      • storeFile

        public static boolean storeFile​(Element element,
                                        java.io.File file)
                                 throws java.io.IOException
        Stores a file inside the element. This attachment will not be visible in MagicDraw GUI. If some file was already attached, then it will be replaced.
        Parameters:
        element - any element
        file - existing file to store
        Returns:
        true if file was successfully attached
        Throws:
        java.io.IOException - exception
      • storeFileToAttachedFile

        public static boolean storeFileToAttachedFile​(Comment attachedFileElement,
                                                      @CheckForNull
                                                      java.io.File file)
        Attaches provided file to the AttachedFile element and updates informative element properties that are visible to the user: name, size, dateAdded, dateModified, author. This method can also be used to replace previously stored file.
        Parameters:
        attachedFileElement - stereotyped comment created with the createAttachedFileElement(Element) method.
        file - existing file to store.
      • extractToDirectory

        @CheckForNull
        public static java.io.File extractToDirectory​(java.io.File directory,
                                                      Element element)
                                               throws java.io.IOException
        Parameters:
        directory - directory to save the attachment to. It will be created if not yet exists
        element - element that has a file stored with storeFile(Element, File) or storeFileToAttachedFile(Comment, File) method.
        Returns:
        File with the attachment stored in it. Null if there was no attached file on the element
        Throws:
        java.io.IOException - when saving of the file fails
      • createAttachedFileElement

        public static Comment createAttachedFileElement​(Element owner)
        Creates a comment stereotyped with AttachedFile stereotype. Such element appears as AttachedFile element in MagicDraw UI.
        Parameters:
        owner - parent for the new element
        Returns:
        AttachedFile element