X-Git-Url: http://git.linex4red.de/pub/Android/ownCloud.git/blobdiff_plain/68ce2e7a381a19df737664755ff7ca4c026155fd..5fc7cd13e7e561ef528e12d2fa088b58e35e00d0:/src/com/owncloud/android/operations/UploadFileOperation.java diff --git a/src/com/owncloud/android/operations/UploadFileOperation.java b/src/com/owncloud/android/operations/UploadFileOperation.java index f4e1c11d..e005f179 100644 --- a/src/com/owncloud/android/operations/UploadFileOperation.java +++ b/src/com/owncloud/android/operations/UploadFileOperation.java @@ -20,6 +20,8 @@ package com.owncloud.android.operations; import java.io.File; import java.io.IOException; +import java.util.HashSet; +import java.util.Set; import org.apache.commons.httpclient.HttpException; import org.apache.commons.httpclient.methods.PutMethod; @@ -32,6 +34,7 @@ import eu.alefzero.webdav.FileRequestEntity; import eu.alefzero.webdav.OnDatatransferProgressListener; import eu.alefzero.webdav.WebdavClient; import eu.alefzero.webdav.WebdavUtils; +import android.accounts.Account; import android.util.Log; import android.webkit.MimeTypeMap; @@ -44,14 +47,53 @@ public class UploadFileOperation extends RemoteOperation { private static final String TAG = UploadFileOperation.class.getCanonicalName(); + private Account mAccount = null; private String mLocalPath = null; private String mRemotePath = null; private String mMimeType = null; private boolean mIsInstant = false; private boolean mForceOverwrite = false; - private OnDatatransferProgressListener mDataTransferListener = null; + private Set mDataTransferListeners = new HashSet(); + public UploadFileOperation( Account account, + String localPath, + String remotePath, + String mimeType, + boolean isInstant, + boolean forceOverwrite) { + if (account == null) + throw new IllegalArgumentException("Illegal null account in UploadFileOperation creation"); + if (localPath == null || localPath.length() <= 0) + throw new IllegalArgumentException("Illegal null or empty localPath in UploadFileOperation creation"); + if (remotePath == null || remotePath.length() <= 0) + throw new IllegalArgumentException("Illegal null or empty remotePath in UploadFileOperation creation"); + + mAccount = account; + mLocalPath = localPath; + mRemotePath = remotePath; + mMimeType = mimeType; + if (mMimeType == null || mMimeType.length() <= 0) { + try { + mMimeType = MimeTypeMap.getSingleton() + .getMimeTypeFromExtension( + localPath.substring(localPath.lastIndexOf('.') + 1)); + } catch (IndexOutOfBoundsException e) { + Log.e(TAG, "Trying to find out MIME type of a file without extension: " + localPath); + } + } + if (mMimeType == null) { + mMimeType = "application/octet-stream"; + } + mIsInstant = isInstant; + mForceOverwrite = forceOverwrite; + } + + + public Account getAccount() { + return mAccount; + } + public String getLocalPath() { return mLocalPath; } @@ -63,49 +105,25 @@ public class UploadFileOperation extends RemoteOperation { public String getMimeType() { return mMimeType; } - public boolean isInstant() { return mIsInstant; } - public boolean getForceOverwrite() { return mForceOverwrite; } - public OnDatatransferProgressListener getDataTransferListener() { - return mDataTransferListener ; + public Set getDataTransferListeners() { + return mDataTransferListeners; } - - public UploadFileOperation( String localPath, - String remotePath, - String mimeType, - boolean isInstant, - boolean forceOverwrite, - OnDatatransferProgressListener dataTransferProgressListener) { - mLocalPath = localPath; - mRemotePath = remotePath; - mMimeType = mimeType; - if (mMimeType == null) { - try { - mMimeType = MimeTypeMap.getSingleton() - .getMimeTypeFromExtension( - localPath.substring(localPath.lastIndexOf('.') + 1)); - } catch (IndexOutOfBoundsException e) { - Log.e(TAG, "Trying to find out MIME type of a file without extension: " + localPath); - } - } - if (mMimeType == null) { - mMimeType = "application/octet-stream"; - } - mIsInstant = isInstant; - mForceOverwrite = forceOverwrite; - mDataTransferListener = dataTransferProgressListener; + public void addDatatransferProgressListener (OnDatatransferProgressListener listener) { + mDataTransferListeners.add(listener); } + @Override protected RemoteOperationResult run(WebdavClient client) { RemoteOperationResult result = null; @@ -144,7 +162,7 @@ public class UploadFileOperation extends RemoteOperation { try { File f = new File(mLocalPath); FileRequestEntity entity = new FileRequestEntity(f, mMimeType); - entity.addOnDatatransferProgressListener(mDataTransferListener); + entity.addOnDatatransferProgressListeners(mDataTransferListeners); put.setRequestEntity(entity); status = client.executeMethod(put); client.exhaustResponse(put.getResponseBodyAsStream()); @@ -192,4 +210,5 @@ public class UploadFileOperation extends RemoteOperation { } } + }