Search in sources :

Example 1 with IDiagramModelImageProvider

use of com.archimatetool.model.IDiagramModelImageProvider in project archi-modelrepository-plugin by archi-contribs.

the class GraficoModelExporter method saveImages.

/**
 * Extract and save images used inside a model
 *
 * @param model
 * @param folder
 * @throws IOException
 */
private void saveImages() throws IOException {
    List<String> added = new ArrayList<String>();
    IArchiveManager archiveManager = (IArchiveManager) fModel.getAdapter(IArchiveManager.class);
    if (archiveManager == null) {
        archiveManager = IArchiveManager.FACTORY.createArchiveManager(fModel);
    }
    byte[] bytes;
    for (Iterator<EObject> iter = fModel.eAllContents(); iter.hasNext(); ) {
        EObject eObject = iter.next();
        if (eObject instanceof IDiagramModelImageProvider) {
            IDiagramModelImageProvider imageProvider = (IDiagramModelImageProvider) eObject;
            String imagePath = imageProvider.getImagePath();
            if (imagePath != null && !added.contains(imagePath)) {
                bytes = archiveManager.getBytesFromEntry(imagePath);
                Files.write(Paths.get(fLocalRepoFolder.getAbsolutePath() + File.separator + imagePath), bytes, StandardOpenOption.CREATE);
                added.add(imagePath);
            }
        }
    }
}
Also used : IDiagramModelImageProvider(com.archimatetool.model.IDiagramModelImageProvider) EObject(org.eclipse.emf.ecore.EObject) ArrayList(java.util.ArrayList) IArchiveManager(com.archimatetool.editor.model.IArchiveManager)

Example 2 with IDiagramModelImageProvider

use of com.archimatetool.model.IDiagramModelImageProvider in project archi by archimatetool.

the class ArchiveManager method saveImages.

private void saveImages(ZipOutputStream zOut) throws IOException {
    List<String> added = new ArrayList<String>();
    for (Iterator<EObject> iter = fModel.eAllContents(); iter.hasNext(); ) {
        EObject eObject = iter.next();
        if (eObject instanceof IDiagramModelImageProvider) {
            IDiagramModelImageProvider imageProvider = (IDiagramModelImageProvider) eObject;
            String imagePath = imageProvider.getImagePath();
            if (imagePath != null && !added.contains(imagePath)) {
                byte[] bytes = BYTE_ARRAY_STORAGE.getEntry(imagePath);
                if (bytes != null) {
                    ZipEntry zipEntry = new ZipEntry(imagePath);
                    zOut.putNextEntry(zipEntry);
                    zOut.write(bytes);
                    zOut.closeEntry();
                    added.add(imagePath);
                }
            }
        }
    }
}
Also used : IDiagramModelImageProvider(com.archimatetool.model.IDiagramModelImageProvider) EObject(org.eclipse.emf.ecore.EObject) ZipEntry(java.util.zip.ZipEntry) ArrayList(java.util.ArrayList)

Aggregations

IDiagramModelImageProvider (com.archimatetool.model.IDiagramModelImageProvider)2 ArrayList (java.util.ArrayList)2 EObject (org.eclipse.emf.ecore.EObject)2 IArchiveManager (com.archimatetool.editor.model.IArchiveManager)1 ZipEntry (java.util.zip.ZipEntry)1