Class FileAttachmentsHelper
java.lang.Object
com.nomagic.magicdraw.fileattachments.FileAttachmentsHelper
Methods to work with files attached to the model: create attached file, read it or remove the attachment.
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic Comment
createAttachedFileElement
(Element owner) Creates a comment stereotyped with AttachedFile stereotype.static File
extractToDirectory
(File directory, Element element) static 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
Stores a file inside the element.static boolean
storeFileToAttachedFile
(Comment attachedFileElement, 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.
-
Constructor Details
-
FileAttachmentsHelper
public FileAttachmentsHelper()
-
-
Method Details
-
storeFile
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:
IOException
- exception
-
storeFileToAttachedFile
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
Removes any file that has been previously stored usingstoreFile(Element, File)
orstoreFileToAttachedFile(Comment, File)
methods.- Parameters:
element
- element to remove attachment from
-
getStoredFileInputStream
- 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 File extractToDirectory(File directory, Element element) throws 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:
IOException
- when saving of the file fails
-
createAttachedFileElement
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
-