Class FileAttachmentsHelper
- java.lang.Object
-
- com.nomagic.magicdraw.fileattachments.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 Summary
Constructors Constructor Description FileAttachmentsHelper()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static Comment
createAttachedFileElement(Element owner)
Creates a comment stereotyped with AttachedFile stereotype.static java.io.File
extractToDirectory(java.io.File directory, Element element)
static java.io.InputStream
getStoredFileInputStream(Element element)
static void
removeStoredFile(Element element)
Removes any file that has been previously stored usingstoreFile(Element, File)
orstoreFileToAttachedFile(Comment, File)
methods.static boolean
storeFile(Element element, java.io.File file)
Stores a file inside the element.static boolean
storeFileToAttachedFile(Comment attachedFileElement, 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.
-
-
-
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 elementfile
- 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 thecreateAttachedFileElement(Element)
method.file
- existing file to store.
-
removeStoredFile
public static void removeStoredFile(Element element)
Removes any file that has been previously stored usingstoreFile(Element, File)
orstoreFileToAttachedFile(Comment, File)
methods.- Parameters:
element
- element to remove attachment from
-
getStoredFileInputStream
@CheckForNull public static java.io.InputStream getStoredFileInputStream(Element element)
- Parameters:
element
- element that has a file stored withstoreFile(Element, File)
orstoreFileToAttachedFile(Comment, File)
method.- Returns:
- InputStream to read the contents of the attached file from.
-
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 existselement
- element that has a file stored withstoreFile(Element, File)
orstoreFileToAttachedFile(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
-
-