use of org.olat.core.util.vfs.VFSMediaResource in project OpenOLAT by OpenOLAT.
the class RevisionListController method event.
@Override
protected void event(UserRequest ureq, Controller source, Event event) {
if (source == revisionListTableCtr) {
if (event instanceof TableEvent) {
TableEvent tEvent = (TableEvent) event;
int row = tEvent.getRowId();
if (CMD_DOWNLOAD.equals(tEvent.getActionId())) {
MediaResource resource;
if (row < versionedFile.getVersions().getRevisions().size()) {
// restore current, do nothing
VFSRevision version = versionedFile.getVersions().getRevisions().get(row);
resource = new VFSRevisionMediaResource(version, true);
} else {
resource = new VFSMediaResource((VFSLeaf) versionedFile);
((VFSMediaResource) resource).setDownloadable(true);
}
ureq.getDispatchResult().setResultingMediaResource(resource);
} else if (CMD_RESTORE.equals(tEvent.getActionId())) {
if (row >= versionedFile.getVersions().getRevisions().size()) {
// restore current, do nothing
status = FolderCommandStatus.STATUS_SUCCESS;
fireEvent(ureq, FolderCommand.FOLDERCOMMAND_FINISHED);
} else {
VFSRevision version = versionedFile.getVersions().getRevisions().get(row);
String comment = translate("version.restore.comment", new String[] { version.getRevisionNr() });
if (versionedFile.getVersions().restore(ureq.getIdentity(), version, comment)) {
status = FolderCommandStatus.STATUS_SUCCESS;
fireEvent(ureq, FolderCommand.FOLDERCOMMAND_FINISHED);
} else {
status = FolderCommandStatus.STATUS_FAILED;
showError("version.restore.failed");
fireEvent(ureq, FolderCommand.FOLDERCOMMAND_FINISHED);
}
}
}
} else if (event instanceof TableMultiSelectEvent) {
TableMultiSelectEvent tEvent = (TableMultiSelectEvent) event;
if (CMD_CANCEL.equals(tEvent.getAction())) {
status = FolderCommandStatus.STATUS_CANCELED;
fireEvent(ureq, FolderCommand.FOLDERCOMMAND_FINISHED);
} else {
List<VFSRevision> selectedVersions = getSelectedRevisions(tEvent.getSelection());
if (!selectedVersions.isEmpty()) {
if (CMD_DELETE.equals(tEvent.getAction())) {
String numOfVersionToDelete = Integer.toString(selectedVersions.size());
confirmDeleteBoxCtr = activateYesNoDialog(ureq, null, translate("version.confirmDelete", new String[] { numOfVersionToDelete }), confirmDeleteBoxCtr);
confirmDeleteBoxCtr.setUserObject(selectedVersions);
}
}
}
}
} else if (source == confirmDeleteBoxCtr) {
if (DialogBoxUIFactory.isYesEvent(event)) {
@SuppressWarnings("unchecked") List<VFSRevision> selectedVersions = (List<VFSRevision>) confirmDeleteBoxCtr.getUserObject();
versionedFile.getVersions().delete(ureq.getIdentity(), selectedVersions);
status = FolderCommandStatus.STATUS_SUCCESS;
} else {
status = FolderCommandStatus.STATUS_CANCELED;
}
fireEvent(ureq, FolderCommand.FOLDERCOMMAND_FINISHED);
}
}
use of org.olat.core.util.vfs.VFSMediaResource in project OpenOLAT by OpenOLAT.
the class DownloadComponent method setDownloadItem.
/**
* @param downloadItem
* the VFS item to download
*/
public void setDownloadItem(VFSLeaf downloadItem, boolean forceDownload) {
if (downloadItem == null) {
mediaResource = null;
} else {
VFSMediaResource mResource = new VFSMediaResource(downloadItem);
if (forceDownload) {
mResource.setDownloadable(forceDownload);
}
mediaResource = mResource;
}
setDirty(true);
}
use of org.olat.core.util.vfs.VFSMediaResource in project openolat by klemens.
the class ProjectDetailsDisplayController method doFileDelivery.
private void doFileDelivery(UserRequest ureq, final Project project, final CourseEnvironment courseEnv, final CourseNode cNode) {
// Create a mapper to deliver the auto-download of the file. We have to
// create a dedicated mapper here
// and can not reuse the standard briefcase way of file delivering, some
// very old fancy code
// Mapper is cleaned up automatically by basic controller
OlatRootFolderImpl rootFolder = new OlatRootFolderImpl(projectBrokerManager.getAttamchmentRelativeRootPath(project, courseEnv, cNode), null);
VFSItem item = rootFolder.resolve(project.getAttachmentFileName());
if (item instanceof VFSLeaf) {
VFSLeaf attachment = (VFSLeaf) item;
MediaResource resource = new VFSMediaResource(attachment);
ureq.getDispatchResult().setResultingMediaResource(resource);
}
}
use of org.olat.core.util.vfs.VFSMediaResource in project openolat by klemens.
the class FeedManagerImpl method createItemMediaFile.
@Override
public MediaResource createItemMediaFile(OLATResourceable feed, String itemId, String fileName) {
VFSMediaResource mediaResource = null;
// Brute force method for fast delivery
try {
VFSItem item = feedFileStorage.getOrCreateFeedItemsContainer(feed);
item = item.resolve(itemId);
item = item.resolve(MEDIA_DIR);
item = item.resolve(fileName);
if (item instanceof VFSLeaf) {
mediaResource = new VFSMediaResource((VFSLeaf) item);
}
} catch (NullPointerException e) {
log.debug("Media resource could not be created from file: ", fileName);
}
return mediaResource;
}
use of org.olat.core.util.vfs.VFSMediaResource in project openolat by klemens.
the class WikiHandler method getAsMediaResource.
@Override
public MediaResource getAsMediaResource(OLATResourceable res, boolean backwardsCompatible) {
VFSContainer rootContainer = FileResourceManager.getInstance().getFileResourceRootImpl(res);
VFSLeaf wikiZip = WikiToZipUtils.getWikiAsZip(rootContainer);
return new VFSMediaResource(wikiZip);
}
Aggregations