Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorspingel2008-05-02 06:47:32 +0000
committerspingel2008-05-02 06:47:32 +0000
commit7f86af1782ec463946d18ec52bbdc8a79f72af61 (patch)
treedb1a8a480829a1e1a7173f9357c607c0d555c287 /org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/AttachmentUtil.java
parent5ae2b037869f2e1aee6691084a6baec0baf76ad0 (diff)
downloadorg.eclipse.mylyn.tasks-7f86af1782ec463946d18ec52bbdc8a79f72af61.tar.gz
org.eclipse.mylyn.tasks-7f86af1782ec463946d18ec52bbdc8a79f72af61.tar.xz
org.eclipse.mylyn.tasks-7f86af1782ec463946d18ec52bbdc8a79f72af61.zip
NEW - bug 211641: [api] supporting attaching of files for remote tasks
https://bugs.eclipse.org/bugs/show_bug.cgi?id=211641
Diffstat (limited to 'org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/AttachmentUtil.java')
-rw-r--r--org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/AttachmentUtil.java52
1 files changed, 51 insertions, 1 deletions
diff --git a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/AttachmentUtil.java b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/AttachmentUtil.java
index 60888044f..65a428111 100644
--- a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/AttachmentUtil.java
+++ b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/AttachmentUtil.java
@@ -12,6 +12,7 @@ import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
+import java.io.InputStream;
import java.util.HashSet;
import java.util.Set;
@@ -23,7 +24,9 @@ import org.eclipse.core.runtime.Status;
import org.eclipse.mylyn.commons.core.StatusHandler;
import org.eclipse.mylyn.context.core.ContextCore;
import org.eclipse.mylyn.internal.tasks.core.TaskDataStorageManager;
+import org.eclipse.mylyn.internal.tasks.core.data.FileTaskAttachmentSource;
import org.eclipse.mylyn.tasks.core.AbstractAttachmentHandler;
+import org.eclipse.mylyn.tasks.core.AbstractRepositoryConnector;
import org.eclipse.mylyn.tasks.core.AbstractTask;
import org.eclipse.mylyn.tasks.core.FileAttachment;
import org.eclipse.mylyn.tasks.core.RepositoryAttachment;
@@ -31,11 +34,12 @@ import org.eclipse.mylyn.tasks.core.RepositoryStatus;
import org.eclipse.mylyn.tasks.core.RepositoryTaskData;
import org.eclipse.mylyn.tasks.core.TaskRepository;
import org.eclipse.mylyn.tasks.core.AbstractTask.SynchronizationState;
+import org.eclipse.mylyn.tasks.core.data.AbstractTaskAttachmentHandler;
import org.eclipse.mylyn.tasks.core.data.ITaskAttachment2;
+import org.eclipse.mylyn.tasks.core.data.TaskAttribute;
/**
* @author Steffen Pingel
- * @since 3.0
*/
public class AttachmentUtil {
@@ -45,6 +49,8 @@ public class AttachmentUtil {
private static final String CONTEXT_FILENAME = "mylyn-context.zip";
+ private static final int BUFFER_SIZE = 1024;
+
/**
* Attaches the associated context to <code>task</code>.
*
@@ -79,6 +85,21 @@ public class AttachmentUtil {
return true;
}
+ public static boolean postContext(AbstractRepositoryConnector connector, TaskRepository repository,
+ AbstractTask task, String comment, IProgressMonitor monitor) throws CoreException {
+ AbstractTaskAttachmentHandler attachmentHandler = connector.getTaskAttachmentHandler();
+ ContextCore.getContextManager().saveContext(task.getHandleIdentifier());
+ File file = ContextCore.getContextManager().getFileForContext(task.getHandleIdentifier());
+ if (file != null && file.exists()) {
+ FileTaskAttachmentSource attachment = new FileTaskAttachmentSource(file);
+ attachment.setDescription(CONTEXT_DESCRIPTION);
+ attachment.setName(CONTEXT_FILENAME);
+ attachmentHandler.postContent(repository, task, attachment, comment, null, monitor);
+ return true;
+ }
+ return false;
+ }
+
/**
* Implementors of this repositoryOperations must perform it locally without going to the server since it is used
* for frequent repositoryOperations such as decoration.
@@ -112,6 +133,7 @@ public class AttachmentUtil {
}
}
+ @Deprecated
public static boolean isContext(RepositoryAttachment attachment) {
return CONTEXT_DESCRIPTION.equals(attachment.getDescription())
|| CONTEXT_DESCRIPTION_LEGACY.equals(attachment.getDescription());
@@ -127,6 +149,7 @@ public class AttachmentUtil {
*
* @return false, if operation is not supported by repository
*/
+ @Deprecated
public static boolean retrieveContext(AbstractAttachmentHandler attachmentHandler, TaskRepository repository,
AbstractTask task, RepositoryAttachment attachment, String destinationPath, IProgressMonitor monitor)
throws CoreException {
@@ -159,4 +182,31 @@ public class AttachmentUtil {
return true;
}
+ public static boolean getContext(AbstractRepositoryConnector connector, TaskRepository repository,
+ AbstractTask task, TaskAttribute attribute, IProgressMonitor monitor) throws CoreException {
+ AbstractTaskAttachmentHandler attachmentHandler = connector.getTaskAttachmentHandler();
+ File file = ContextCore.getContextManager().getFileForContext(task.getHandleIdentifier());
+ try {
+ FileOutputStream out = new FileOutputStream(file);
+ try {
+ InputStream in = attachmentHandler.getContent(repository, task, attribute, monitor);
+ try {
+ int len;
+ byte[] buffer = new byte[BUFFER_SIZE];
+ while ((len = in.read(buffer)) != -1) {
+ out.write(buffer, 0, len);
+ }
+ } finally {
+ in.close();
+ }
+ } finally {
+ out.close();
+ }
+ } catch (IOException e) {
+ throw new CoreException(new RepositoryStatus(IStatus.ERROR, TasksUiPlugin.ID_PLUGIN,
+ RepositoryStatus.ERROR_INTERNAL, "Could not create context file", e));
+ }
+ return true;
+ }
+
}

Back to the top