Class FileAttachmentsHelper

java.lang.Object
com.nomagic.magicdraw.fileattachments.FileAttachmentsHelper

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

    • FileAttachmentsHelper

      public FileAttachmentsHelper()
  • Method Details

    • storeFile

      public static boolean storeFile(Element element, File file) throws 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:
      IOException - exception
    • storeFileToAttachedFile

      public static boolean storeFileToAttachedFile(Comment attachedFileElement, @CheckForNull 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.
    • removeStoredFile

      public static void removeStoredFile(Element element)
      Removes any file that has been previously stored using storeFile(Element, File) or storeFileToAttachedFile(Comment, File) methods.
      Parameters:
      element - element to remove attachment from
    • getStoredFileInputStream

      @CheckForNull public static InputStream getStoredFileInputStream(Element element)
      Parameters:
      element - element that has a file stored with storeFile(Element, File) or storeFileToAttachedFile(Comment, File) method.
      Returns:
      InputStream to read the contents of the attached file from.
    • extractToDirectory

      @CheckForNull public static File extractToDirectory(File directory, Element element) throws 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:
      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