Skip to content
Snippets Groups Projects
Commit fad8e543 authored by srosse's avatar srosse
Browse files

OO-1456: add svg to the list of mime type which must be downloaded

parent 33c9a8af
No related branches found
No related tags found
No related merge requests found
...@@ -51,7 +51,7 @@ public class DownloadComponent extends AbstractComponent { ...@@ -51,7 +51,7 @@ public class DownloadComponent extends AbstractComponent {
* @param downloadItem * @param downloadItem
*/ */
public DownloadComponent(String name, VFSLeaf downloadItem) { public DownloadComponent(String name, VFSLeaf downloadItem) {
this(name, downloadItem, downloadItem.getName(), null, this(name, downloadItem, true, downloadItem.getName(), null,
getCssIconClass(downloadItem.getName())); getCssIconClass(downloadItem.getName()));
} }
...@@ -77,10 +77,10 @@ public class DownloadComponent extends AbstractComponent { ...@@ -77,10 +77,10 @@ public class DownloadComponent extends AbstractComponent {
* will be added when this argument is used. Use the render * will be added when this argument is used. Use the render
* argument when you want to provide additional CSS classes. * argument when you want to provide additional CSS classes.
*/ */
public DownloadComponent(String name, VFSLeaf downloadItem, public DownloadComponent(String name, VFSLeaf downloadItem, boolean forceDownload,
String linkText, String linkToolTip, String linkCssIconClass) { String linkText, String linkToolTip, String linkCssIconClass) {
super(name); super(name);
setDownloadItem(downloadItem); setDownloadItem(downloadItem, forceDownload);
setLinkText(linkText); setLinkText(linkText);
setLinkToolTip(linkToolTip); setLinkToolTip(linkToolTip);
setLinkCssIconClass(linkCssIconClass); setLinkCssIconClass(linkCssIconClass);
...@@ -90,13 +90,17 @@ public class DownloadComponent extends AbstractComponent { ...@@ -90,13 +90,17 @@ public class DownloadComponent extends AbstractComponent {
* @param downloadItem * @param downloadItem
* the VFS item to download * the VFS item to download
*/ */
public void setDownloadItem(VFSLeaf downloadItem) { public void setDownloadItem(VFSLeaf downloadItem, boolean forceDownload) {
if (downloadItem == null) { if (downloadItem == null) {
this.mediaResource = null; mediaResource = null;
} else { } else {
this.mediaResource = new VFSMediaResource(downloadItem); VFSMediaResource mResource = new VFSMediaResource(downloadItem);
if(forceDownload) {
mResource.setDownloadable(forceDownload);
}
mediaResource = mResource;
} }
this.setDirty(true); setDirty(true);
} }
public void setMediaResource(MediaResource mediaResource) { public void setMediaResource(MediaResource mediaResource) {
......
...@@ -59,7 +59,8 @@ public class VFSMediaResource implements MediaResource { ...@@ -59,7 +59,8 @@ public class VFSMediaResource implements MediaResource {
//html, xhtml and javascript are set to force download //html, xhtml and javascript are set to force download
if (mimeType == null || "text/html".equals(mimeType) if (mimeType == null || "text/html".equals(mimeType)
|| "application/xhtml+xml".equals(mimeType) || "application/xhtml+xml".equals(mimeType)
|| "application/javascript".equals(mimeType)) { || "application/javascript".equals(mimeType)
|| "image/svg+xml".equals(mimeType)) {
mimeType = MIME_TYPE_FORCE_DOWNLOAD; mimeType = MIME_TYPE_FORCE_DOWNLOAD;
unknownMimeType = true; unknownMimeType = true;
} else if (encoding != null) { } else if (encoding != null) {
......
...@@ -24,6 +24,8 @@ import java.util.Collections; ...@@ -24,6 +24,8 @@ import java.util.Collections;
import java.util.Comparator; import java.util.Comparator;
import java.util.List; import java.util.List;
import org.olat.core.CoreSpringFactory;
import org.olat.core.commons.modules.bc.FolderModule;
import org.olat.core.gui.UserRequest; import org.olat.core.gui.UserRequest;
import org.olat.core.gui.components.Component; import org.olat.core.gui.components.Component;
import org.olat.core.gui.components.download.DownloadComponent; import org.olat.core.gui.components.download.DownloadComponent;
...@@ -81,6 +83,8 @@ public class BCPeekviewController extends BasicController implements Controller ...@@ -81,6 +83,8 @@ public class BCPeekviewController extends BasicController implements Controller
addItems(rootFolder, allLeafs); addItems(rootFolder, allLeafs);
// Sort messages by last modified date // Sort messages by last modified date
Collections.sort(allLeafs, dateSortingComparator); Collections.sort(allLeafs, dateSortingComparator);
boolean forceDownload = CoreSpringFactory.getImpl(FolderModule.class).isForceDownload();
// only take the configured amount of messages // only take the configured amount of messages
List<VFSLeaf> leafs = new ArrayList<VFSLeaf>(); List<VFSLeaf> leafs = new ArrayList<VFSLeaf>();
for (int i = 0; i < allLeafs.size(); i++) { for (int i = 0; i < allLeafs.size(); i++) {
...@@ -92,7 +96,9 @@ public class BCPeekviewController extends BasicController implements Controller ...@@ -92,7 +96,9 @@ public class BCPeekviewController extends BasicController implements Controller
// add link to item // add link to item
// Add link to jump to course node // Add link to jump to course node
if (leaf instanceof LocalFileImpl) { if (leaf instanceof LocalFileImpl) {
DownloadComponent dlComp = new DownloadComponent("nodeLinkDL_"+(i+1), leaf, leaf.getName(), translate("preview.downloadfile"), CSSHelper.createFiletypeIconCssClassFor(leaf.getName())); DownloadComponent dlComp = new DownloadComponent("nodeLinkDL_"+(i+1), leaf, forceDownload,
leaf.getName(), translate("preview.downloadfile"),
CSSHelper.createFiletypeIconCssClassFor(leaf.getName()));
dlComp.setElementCssClass("o_gotoNode"); dlComp.setElementCssClass("o_gotoNode");
peekviewVC.put("nodeLinkDL_"+(i+1),dlComp); peekviewVC.put("nodeLinkDL_"+(i+1),dlComp);
} else { } else {
......
...@@ -64,8 +64,9 @@ public class ForumArtefactDetailsController extends BasicController { ...@@ -64,8 +64,9 @@ public class ForumArtefactDetailsController extends BasicController {
int i=1; //vc-shift! int i=1; //vc-shift!
for (VFSItem vfsItem : attachments) { for (VFSItem vfsItem : attachments) {
VFSLeaf file = (VFSLeaf) vfsItem; VFSLeaf file = (VFSLeaf) vfsItem;
// DownloadComponent downlC = new DownloadComponent("download"+i, file); DownloadComponent downlC = new DownloadComponent("download"+i, file, true,
DownloadComponent downlC = new DownloadComponent("download"+i, file, file.getName() + " (" + String.valueOf(file.getSize() / 1024) + " KB)", null, CSSHelper.createFiletypeIconCssClassFor(file.getName())); file.getName() + " (" + String.valueOf(file.getSize() / 1024) + " KB)", null,
CSSHelper.createFiletypeIconCssClassFor(file.getName()));
vC.put("download"+i, downlC); vC.put("download"+i, downlC);
i++; i++;
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment