Search in sources :

Example 6 with CleanupAfterDeliveryFileMediaResource

use of org.olat.core.gui.media.CleanupAfterDeliveryFileMediaResource in project openolat by klemens.

the class GlossaryManagerImpl method getAsMediaResource.

/**
 * Export the glossary as a media resource. The resource name is set to the
 * resources display name
 *
 * @param res
 * @return
 */
@Override
public MediaResource getAsMediaResource(OLATResourceable res) {
    RepositoryEntry repoEntry = RepositoryManager.getInstance().lookupRepositoryEntry(res, false);
    String exportFileName = repoEntry.getDisplayname();
    // OO-135 check for special / illegal chars in filename
    exportFileName = StringHelper.transformDisplayNameToFileSystemName(exportFileName);
    try {
        File tmpDir = new File(WebappHelper.getTmpDir());
        File fExportZIP = File.createTempFile(exportFileName, ".zip", tmpDir);
        VFSContainer glossaryRoot = getGlossaryRootFolder(res);
        ZipUtil.zip(glossaryRoot.getItems(), new LocalFileImpl(fExportZIP), false);
        return new CleanupAfterDeliveryFileMediaResource(fExportZIP);
    } catch (IOException e) {
        logError("Cannot export glossar: " + res, e);
        return null;
    }
}
Also used : CleanupAfterDeliveryFileMediaResource(org.olat.core.gui.media.CleanupAfterDeliveryFileMediaResource) VFSContainer(org.olat.core.util.vfs.VFSContainer) LocalFileImpl(org.olat.core.util.vfs.LocalFileImpl) RepositoryEntry(org.olat.repository.RepositoryEntry) IOException(java.io.IOException) File(java.io.File)

Aggregations

File (java.io.File)6 CleanupAfterDeliveryFileMediaResource (org.olat.core.gui.media.CleanupAfterDeliveryFileMediaResource)6 LocalFileImpl (org.olat.core.util.vfs.LocalFileImpl)4 VFSContainer (org.olat.core.util.vfs.VFSContainer)4 RepositoryEntry (org.olat.repository.RepositoryEntry)4 IOException (java.io.IOException)2