Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFrank Becker2012-12-17 14:03:54 -0500
committerGerrit Code Review @ Eclipse.org2012-12-18 06:09:07 -0500
commitaca0fb2adb8f72d3b027f1a2952311a34fd2cf77 (patch)
tree9b9963de325bb13d01c1018df0401395133bd5ab /org.eclipse.mylyn.tasks.ui
parent95fb825b312cd2424b194e66b2865e30f9c03929 (diff)
downloadorg.eclipse.mylyn.tasks-aca0fb2adb8f72d3b027f1a2952311a34fd2cf77.tar.gz
org.eclipse.mylyn.tasks-aca0fb2adb8f72d3b027f1a2952311a34fd2cf77.tar.xz
org.eclipse.mylyn.tasks-aca0fb2adb8f72d3b027f1a2952311a34fd2cf77.zip
395095: failed to download Bugzilla attachment
Change-Id: I94895c780e8829b2dfe80b1c3df2aa11841c8aad Task-Url: https://bugs.eclipse.org/bugs/show_bug.cgi?id=395095
Diffstat (limited to 'org.eclipse.mylyn.tasks.ui')
-rw-r--r--org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/util/AttachmentUtil.java42
1 files changed, 25 insertions, 17 deletions
diff --git a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/util/AttachmentUtil.java b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/util/AttachmentUtil.java
index 3871082ad..e90fb4fbd 100644
--- a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/util/AttachmentUtil.java
+++ b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/util/AttachmentUtil.java
@@ -34,6 +34,7 @@ import org.eclipse.jface.operation.IRunnableContext;
import org.eclipse.jface.operation.IRunnableWithProgress;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.mylyn.commons.core.CoreUtil;
import org.eclipse.mylyn.commons.core.StatusHandler;
import org.eclipse.mylyn.commons.net.Policy;
import org.eclipse.mylyn.internal.tasks.core.ITasksCoreConstants;
@@ -76,8 +77,6 @@ public class AttachmentUtil {
private static final String CTYPE_ZIP = "zip"; //$NON-NLS-1$
- private static final String CTYPE_OCTET_STREAM = "octet-stream"; //$NON-NLS-1$
-
private static final String CTYPE_TEXT = "text"; //$NON-NLS-1$
private static final String CTYPE_HTML = "html"; //$NON-NLS-1$
@@ -366,24 +365,33 @@ public class AttachmentUtil {
}
public static String getAttachmentFilename(ITaskAttachment attachment) {
+ Assert.isNotNull(attachment);
String name = attachment.getFileName();
- // if no filename is set, make one up with the proper extension so
- // we can support opening in that filetype's default editor
- if (name == null || "".equals(name)) { //$NON-NLS-1$
+ if (name != null && name.length() > 0) {
+ return CoreUtil.asFileName(name);
+ } else {
+ String extension = ""; //$NON-NLS-1$
+
+ // if no filename is set, make one up with the proper extension so
+ // we can support opening in that filetype's default editor
String ctype = attachment.getContentType();
- if (ctype.endsWith(CTYPE_HTML)) {
- name = ATTACHMENT_DEFAULT_NAME + ".html"; //$NON-NLS-1$
- } else if (ctype.startsWith(CTYPE_TEXT)) {
- name = ATTACHMENT_DEFAULT_NAME + ".txt"; //$NON-NLS-1$
- } else if (ctype.endsWith(CTYPE_OCTET_STREAM)) {
- name = ATTACHMENT_DEFAULT_NAME;
- } else if (ctype.endsWith(CTYPE_ZIP)) {
- name = ATTACHMENT_DEFAULT_NAME + "." + CTYPE_ZIP; //$NON-NLS-1$
- } else {
- name = ATTACHMENT_DEFAULT_NAME + "." + ctype.substring(ctype.indexOf("/") + 1); //$NON-NLS-1$ //$NON-NLS-2$
+ if (ctype != null) {
+ if (ctype.endsWith(CTYPE_HTML)) {
+ extension = ".html"; //$NON-NLS-1$
+ } else if (ctype.startsWith(CTYPE_TEXT)) {
+ extension = ".txt"; //$NON-NLS-1$
+ } else if (ctype.endsWith(CTYPE_ZIP)) {
+ extension = ".zip"; //$NON-NLS-1$
+ } else {
+ int i = ctype.lastIndexOf("/"); //$NON-NLS-1$
+ if (i != -1) {
+ extension = "." + ctype.substring(i + 1); //$NON-NLS-1$
+ }
+ }
}
- }
- return name;
+ return ATTACHMENT_DEFAULT_NAME + extension;
+ }
}
+
}

Back to the top