--- /dev/null
+/* ownCloud Android client application
+ * Copyright (C) 2012-2013 ownCloud Inc.
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2,
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+package com.owncloud.android.oc_framework_test_project.test;
+
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.text.SimpleDateFormat;
+import java.util.Date;
+
+import android.content.res.AssetManager;
+import android.os.Environment;
+import android.test.ActivityInstrumentationTestCase2;
+import android.util.Log;
+
+import com.owncloud.android.oc_framework.operations.RemoteOperationResult;
+import com.owncloud.android.oc_framework_test_project.TestActivity;
+
+/**
+ * Class to test Update File Operation
+ * @author masensio
+ *
+ */
+
+public class UploadFileTest extends ActivityInstrumentationTestCase2<TestActivity> {
+
+ /* Files to upload. These files must exists on the device */
+ private final String mFileToUpload = "fileToUpload.png";
+ private final String mMimeType = "image/png";
+
+ private final String mFileToUploadWithChunks = "fileToUploadChunks.MP4";
+ private final String mMimeTypeWithChunks = "video/mp4";
+
+ private final String mFileNotFound = "fileNotFound.png";
+
+ private final String mStoragePath = "/owncloud/tmp/uploadTest";
+ private String mPath;
+
+ private String mCurrentDate;
+
+ private TestActivity mActivity;
+
+ public UploadFileTest() {
+ super(TestActivity.class);
+
+ }
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+ setActivityInitialTouchMode(false);
+ mActivity = getActivity();
+
+ SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd_HHmmss");
+ mCurrentDate = sdf.format(new Date());
+
+ File sdCard = Environment.getExternalStorageDirectory();
+ mPath = sdCard.getAbsolutePath() + "/" + mStoragePath + mCurrentDate;
+
+ //mActivity.createFolder(mPath, true);
+
+ copyAssets();
+ }
+
+ /**
+ * Copy Files to ulpload to SdCard
+ */
+ private void copyAssets() {
+ AssetManager assetManager = getActivity().getAssets();
+ String[] files = { mFileToUpload, mFileToUploadWithChunks };
+
+ // Folder with contents
+ File folder = new File(mPath);
+ folder.mkdirs();
+
+
+ for(String filename : files) {
+ InputStream in = null;
+ OutputStream out = null;
+ try {
+ in = assetManager.open(filename);
+ File outFile = new File(folder, filename);
+ out = new FileOutputStream(outFile);
+ copyFile(in, out);
+ in.close();
+ in = null;
+ out.flush();
+ out.close();
+ out = null;
+ } catch(IOException e) {
+ Log.e("tag", "Failed to copy asset file: " + filename, e);
+ }
+ }
+ }
+
+ private void copyFile(InputStream in, OutputStream out) throws IOException {
+ byte[] buffer = new byte[1024];
+ int read;
+ while((read = in.read(buffer)) != -1){
+ out.write(buffer, 0, read);
+ }
+ }
+
+
+ /**
+ * Test Upload File without chunks
+ */
+ public void testUploadFile() {
+
+ String storagePath = mPath + "/" + mFileToUpload;
+ //String remotePath = "/uploadTest" + mCurrentDate + "/" + mFileToUpload;
+ String remotePath = "/" + mFileToUpload;
+
+ RemoteOperationResult result = mActivity.uploadFile(storagePath, remotePath, mMimeType);
+ assertTrue(result.isSuccess());
+ }
+
+ /**
+ * Test Upload File with chunks
+ */
+ public void testUploadFileWithChunks() {
+
+ String storagePath = mPath + "/" + mFileToUploadWithChunks;
+ //String remotePath = "/uploadTest" + mCurrentDate + "/" +mFileToUploadWithChunks;
+ String remotePath = "/" + mFileToUploadWithChunks;
+
+ RemoteOperationResult result = mActivity.uploadFile(storagePath, remotePath, mMimeTypeWithChunks);
+ assertTrue(result.isSuccess());
+ }
+
+ /**
+ * Test Upload Not Found File
+ */
+ public void testUploadFileNotFound() {
+
+ String storagePath = mPath + "/" + mFileNotFound;
+ //String remotePath = "/uploadTest" + mCurrentDate + "/" + mFileToUpload;
+ String remotePath = "/" + mFileNotFound;
+
+ RemoteOperationResult result = mActivity.uploadFile(storagePath, remotePath, mMimeType);
+ assertFalse(result.isSuccess());
+ }
+
+}
import com.owncloud.android.oc_framework.network.webdav.WebdavClient;
import com.owncloud.android.oc_framework.operations.RemoteFile;
import com.owncloud.android.oc_framework.operations.RemoteOperationResult;
+import com.owncloud.android.oc_framework.operations.remote.ChunkedUploadRemoteFileOperation;
import com.owncloud.android.oc_framework.operations.remote.CreateRemoteFolderOperation;
import com.owncloud.android.oc_framework.operations.remote.DownloadRemoteFileOperation;
import com.owncloud.android.oc_framework.operations.remote.ReadRemoteFolderOperation;
import com.owncloud.android.oc_framework.operations.remote.RemoveRemoteFileOperation;
import com.owncloud.android.oc_framework.operations.remote.RenameRemoteFileOperation;
+import com.owncloud.android.oc_framework.operations.remote.UploadRemoteFileOperation;
import android.net.Uri;
import android.os.Bundle;
private static final String mServerUri = "https://beta.owncloud.com/owncloud/remote.php/webdav";
private static final String mUser = "testandroid";
private static final String mPass = "testandroid";
+ private static final boolean mChunked = true;
//private Account mAccount = null;
private WebdavClient mClient;
return result;
}
+ /** Access to the library method to Upload a File
+ * @param storagePath
+ * @param remotePath
+ * @param mimeType
+ *
+ * @return
+ */
+ public RemoteOperationResult uploadFile(String storagePath, String remotePath, String mimeType) {
+
+ UploadRemoteFileOperation uploadOperation;
+ if (mChunked) {
+ uploadOperation = new ChunkedUploadRemoteFileOperation(storagePath, remotePath, mimeType);
+ } else {
+ uploadOperation = new UploadRemoteFileOperation(storagePath, remotePath, mimeType);
+ }
+
+ RemoteOperationResult result = uploadOperation.execute(mClient);
+
+ return result;
+ }
}
--- /dev/null
+/* ownCloud Android client application
+ * Copyright (C) 2012 Bartek Przybylski
+ * Copyright (C) 2012-2013 ownCloud Inc.
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2,
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+package com.owncloud.android.oc_framework.operations.remote;
+
+import java.io.File;
+import java.io.IOException;
+import java.io.RandomAccessFile;
+import java.nio.channels.FileChannel;
+import java.util.Random;
+
+import org.apache.commons.httpclient.HttpException;
+import org.apache.commons.httpclient.methods.PutMethod;
+
+import com.owncloud.android.oc_framework.network.ProgressiveDataTransferer;
+import com.owncloud.android.oc_framework.network.webdav.ChunkFromFileChannelRequestEntity;
+import com.owncloud.android.oc_framework.network.webdav.WebdavClient;
+import com.owncloud.android.oc_framework.network.webdav.WebdavUtils;
+
+
+import android.util.Log;
+
+
+public class ChunkedUploadRemoteFileOperation extends UploadRemoteFileOperation {
+
+ public static final long CHUNK_SIZE = 1024000;
+ private static final String OC_CHUNKED_HEADER = "OC-Chunked";
+ private static final String TAG = ChunkedUploadRemoteFileOperation.class.getSimpleName();
+
+ public ChunkedUploadRemoteFileOperation(String storagePath, String remotePath, String mimeType) {
+ super(storagePath, remotePath, mimeType);
+ }
+
+ @Override
+ protected int uploadFile(WebdavClient client) throws HttpException, IOException {
+ int status = -1;
+
+ FileChannel channel = null;
+ RandomAccessFile raf = null;
+ try {
+ File file = new File(mStoragePath);
+ raf = new RandomAccessFile(file, "r");
+ channel = raf.getChannel();
+ mEntity = new ChunkFromFileChannelRequestEntity(channel, mMimeType, CHUNK_SIZE, file);
+ //((ProgressiveDataTransferer)mEntity).addDatatransferProgressListeners(getDataTransferListeners());
+ synchronized (mDataTransferListeners) {
+ ((ProgressiveDataTransferer)mEntity).addDatatransferProgressListeners(mDataTransferListeners);
+ }
+
+ long offset = 0;
+ String uriPrefix = client.getBaseUri() + WebdavUtils.encodePath(mRemotePath) + "-chunking-" + Math.abs((new Random()).nextInt(9000)+1000) + "-" ;
+ long chunkCount = (long) Math.ceil((double)file.length() / CHUNK_SIZE);
+ for (int chunkIndex = 0; chunkIndex < chunkCount ; chunkIndex++, offset += CHUNK_SIZE) {
+ if (mPutMethod != null) {
+ mPutMethod.releaseConnection(); // let the connection available for other methods
+ }
+ mPutMethod = new PutMethod(uriPrefix + chunkCount + "-" + chunkIndex);
+ mPutMethod.addRequestHeader(OC_CHUNKED_HEADER, OC_CHUNKED_HEADER);
+ ((ChunkFromFileChannelRequestEntity)mEntity).setOffset(offset);
+ mPutMethod.setRequestEntity(mEntity);
+ status = client.executeMethod(mPutMethod);
+ client.exhaustResponse(mPutMethod.getResponseBodyAsStream());
+ Log.d(TAG, "Upload of " + mStoragePath + " to " + mRemotePath + ", chunk index " + chunkIndex + ", count " + chunkCount + ", HTTP result status " + status);
+ if (!isSuccess(status))
+ break;
+ }
+
+ } finally {
+ if (channel != null)
+ channel.close();
+ if (raf != null)
+ raf.close();
+ if (mPutMethod != null)
+ mPutMethod.releaseConnection(); // let the connection available for other methods
+ }
+ return status;
+ }
+
+}
--- /dev/null
+/* ownCloud Android client application
+ * Copyright (C) 2012 ownCloud Inc.
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2,
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+package com.owncloud.android.oc_framework.operations.remote;
+
+import org.apache.commons.httpclient.HttpStatus;
+import org.apache.commons.httpclient.methods.HeadMethod;
+
+import com.owncloud.android.oc_framework.network.webdav.WebdavClient;
+import com.owncloud.android.oc_framework.operations.RemoteOperation;
+import com.owncloud.android.oc_framework.operations.RemoteOperationResult;
+import com.owncloud.android.oc_framework.network.webdav.WebdavUtils;
+
+import android.content.Context;
+import android.net.ConnectivityManager;
+import android.util.Log;
+
+/**
+ * Operation to check the existence or absence of a path in a remote server.
+ *
+ * @author David A. Velasco
+ */
+public class ExistenceCheckRemoteOperation extends RemoteOperation {
+
+ /** Maximum time to wait for a response from the server in MILLISECONDs. */
+ public static final int TIMEOUT = 10000;
+
+ private static final String TAG = ExistenceCheckRemoteOperation.class.getSimpleName();
+
+ private String mPath;
+ private Context mContext;
+ private boolean mSuccessIfAbsent;
+
+
+ /**
+ * Full constructor. Success of the operation will depend upon the value of successIfAbsent.
+ *
+ * @param path Path to append to the URL owned by the client instance.
+ * @param context Android application context.
+ * @param successIfAbsent When 'true', the operation finishes in success if the path does NOT exist in the remote server (HTTP 404).
+ */
+ public ExistenceCheckRemoteOperation(String path, Context context, boolean successIfAbsent) {
+ mPath = (path != null) ? path : "";
+ mContext = context;
+ mSuccessIfAbsent = successIfAbsent;
+ }
+
+
+ @Override
+ protected RemoteOperationResult run(WebdavClient client) {
+ if (!isOnline()) {
+ return new RemoteOperationResult(RemoteOperationResult.ResultCode.NO_NETWORK_CONNECTION);
+ }
+ RemoteOperationResult result = null;
+ HeadMethod head = null;
+ try {
+ head = new HeadMethod(client.getBaseUri() + WebdavUtils.encodePath(mPath));
+ int status = client.executeMethod(head, TIMEOUT, TIMEOUT);
+ client.exhaustResponse(head.getResponseBodyAsStream());
+ boolean success = (status == HttpStatus.SC_OK && !mSuccessIfAbsent) || (status == HttpStatus.SC_NOT_FOUND && mSuccessIfAbsent);
+ result = new RemoteOperationResult(success, status, head.getResponseHeaders());
+ Log.d(TAG, "Existence check for " + client.getBaseUri() + WebdavUtils.encodePath(mPath) + " targeting for " + (mSuccessIfAbsent ? " absence " : " existence ") + "finished with HTTP status " + status + (!success?"(FAIL)":""));
+
+ } catch (Exception e) {
+ result = new RemoteOperationResult(e);
+ Log.e(TAG, "Existence check for " + client.getBaseUri() + WebdavUtils.encodePath(mPath) + " targeting for " + (mSuccessIfAbsent ? " absence " : " existence ") + ": " + result.getLogMessage(), result.getException());
+
+ } finally {
+ if (head != null)
+ head.releaseConnection();
+ }
+ return result;
+ }
+
+ private boolean isOnline() {
+ ConnectivityManager cm = (ConnectivityManager) mContext
+ .getSystemService(Context.CONNECTIVITY_SERVICE);
+ return cm != null && cm.getActiveNetworkInfo() != null
+ && cm.getActiveNetworkInfo().isConnectedOrConnecting();
+ }
+
+
+}
--- /dev/null
+/* ownCloud Android client application
+ * Copyright (C) 2012-2013 ownCloud Inc.
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2,
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+package com.owncloud.android.oc_framework.operations.remote;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.HashSet;
+import java.util.Set;
+import java.util.concurrent.atomic.AtomicBoolean;
+
+import org.apache.commons.httpclient.HttpException;
+import org.apache.commons.httpclient.methods.PutMethod;
+import org.apache.commons.httpclient.methods.RequestEntity;
+import org.apache.http.HttpStatus;
+
+import com.owncloud.android.oc_framework.network.ProgressiveDataTransferer;
+import com.owncloud.android.oc_framework.network.webdav.FileRequestEntity;
+import com.owncloud.android.oc_framework.network.webdav.OnDatatransferProgressListener;
+import com.owncloud.android.oc_framework.network.webdav.WebdavClient;
+import com.owncloud.android.oc_framework.network.webdav.WebdavUtils;
+import com.owncloud.android.oc_framework.operations.OperationCancelledException;
+import com.owncloud.android.oc_framework.operations.RemoteOperation;
+import com.owncloud.android.oc_framework.operations.RemoteOperationResult;
+
+/**
+ * Remote operation performing the upload of a remote file to the ownCloud server.
+ *
+ * @author David A. Velasco
+ * @author masensio
+ */
+
+public class UploadRemoteFileOperation extends RemoteOperation {
+
+
+ protected String mStoragePath;
+ protected String mRemotePath;
+ protected String mMimeType;
+ protected PutMethod mPutMethod = null;
+
+ private final AtomicBoolean mCancellationRequested = new AtomicBoolean(false);
+ protected Set<OnDatatransferProgressListener> mDataTransferListeners = new HashSet<OnDatatransferProgressListener>();
+
+ protected RequestEntity mEntity = null;
+
+ public UploadRemoteFileOperation(String storagePath, String remotePath, String mimeType) {
+ mStoragePath = storagePath;
+ mRemotePath = remotePath;
+ mMimeType = mimeType;
+ }
+
+ @Override
+ protected RemoteOperationResult run(WebdavClient client) {
+ RemoteOperationResult result = null;
+
+ try {
+ // / perform the upload
+ synchronized (mCancellationRequested) {
+ if (mCancellationRequested.get()) {
+ throw new OperationCancelledException();
+ } else {
+ mPutMethod = new PutMethod(client.getBaseUri() + WebdavUtils.encodePath(mRemotePath));
+ }
+ }
+
+ int status = uploadFile(client);
+
+ result = new RemoteOperationResult(isSuccess(status), status, (mPutMethod != null ? mPutMethod.getResponseHeaders() : null));
+
+ } catch (Exception e) {
+ // TODO something cleaner with cancellations
+ if (mCancellationRequested.get()) {
+ result = new RemoteOperationResult(new OperationCancelledException());
+ } else {
+ result = new RemoteOperationResult(e);
+ }
+ }
+ return result;
+ }
+
+ public boolean isSuccess(int status) {
+ return ((status == HttpStatus.SC_OK || status == HttpStatus.SC_CREATED || status == HttpStatus.SC_NO_CONTENT));
+ }
+
+ protected int uploadFile(WebdavClient client) throws HttpException, IOException, OperationCancelledException {
+ int status = -1;
+ try {
+ File f = new File(mStoragePath);
+ mEntity = new FileRequestEntity(f, mMimeType);
+ synchronized (mDataTransferListeners) {
+ ((ProgressiveDataTransferer)mEntity).addDatatransferProgressListeners(mDataTransferListeners);
+ }
+ mPutMethod.setRequestEntity(mEntity);
+ status = client.executeMethod(mPutMethod);
+ client.exhaustResponse(mPutMethod.getResponseBodyAsStream());
+
+ } finally {
+ mPutMethod.releaseConnection(); // let the connection available for other methods
+ }
+ return status;
+ }
+
+ public Set<OnDatatransferProgressListener> getDataTransferListeners() {
+ return mDataTransferListeners;
+ }
+
+ public void addDatatransferProgressListener (OnDatatransferProgressListener listener) {
+ synchronized (mDataTransferListeners) {
+ mDataTransferListeners.add(listener);
+ }
+ if (mEntity != null) {
+ ((ProgressiveDataTransferer)mEntity).addDatatransferProgressListener(listener);
+ }
+ }
+
+ public void removeDatatransferProgressListener(OnDatatransferProgressListener listener) {
+ synchronized (mDataTransferListeners) {
+ mDataTransferListeners.remove(listener);
+ }
+ if (mEntity != null) {
+ ((ProgressiveDataTransferer)mEntity).removeDatatransferProgressListener(listener);
+ }
+ }
+
+ public void cancel() {
+ synchronized (mCancellationRequested) {
+ mCancellationRequested.set(true);
+ if (mPutMethod != null)
+ mPutMethod.abort();
+ }
+ }
+
+}
<string name="recommend_subject">Proveu %1$s a un telèfon avançat!</string>
<string name="recommend_text">Vull convidar-te a usar l\'aplicació %1$s al teu telèfon avançat!\nBaixa\'l aquí: %2$s</string>
<string name="auth_check_server">Comprova el servidor</string>
+ <string name="auth_host_url">Adreça del servidor https://…</string>
<string name="auth_username">Nom d\'usuari</string>
<string name="auth_password">Contrasenya</string>
<string name="auth_register">Nou a %1$s?</string>
<string name="recommend_subject">Zkuste %1$s na vašem smartphonu!</string>
<string name="recommend_text">Chtěl bych vás pozvat k používání %1$s na vašem smartphonu.\nKe stažení zde: %2$s</string>
<string name="auth_check_server">Zkontrolovat server</string>
+ <string name="auth_host_url">Adresa serveru https://...</string>
<string name="auth_username">Uživatelské jméno</string>
<string name="auth_password">Heslo</string>
<string name="auth_register">Nováček s %1$s?</string>
<string name="recommend_subject">Probieren Sie %1$s auf Ihrem Smartphone!</string>
<string name="recommend_text">Ich möchte Sie zum Benutzen von %1$s auf Ihrem Smartphone einladen!\nLaden Sie es hier herunter: %2$s</string>
<string name="auth_check_server">Server überprüfen</string>
+ <string name="auth_host_url">Server-Adresse https://…</string>
<string name="auth_username">Benutzername</string>
<string name="auth_password">Passwort</string>
<string name="auth_register">Ist %1$s neu für Sie?</string>
<string name="recommend_subject">Probiere %1$s auf Deinem Smartphone!</string>
<string name="recommend_text">Ich möchte Dich zu %1$s für Dein Smartphone einladen!\nLade es hier herunter: %2$s</string>
<string name="auth_check_server">Überprüfe den Server</string>
+ <string name="auth_host_url">Server-Adresse https://…</string>
<string name="auth_username">Benutzername</string>
<string name="auth_password">Passwort</string>
<string name="auth_register">Ist %1$s neu für dich?</string>
<string name="recommend_subject">Try %1$s on your smartphone!</string>
<string name="recommend_text">I want to invite you to use %1$s on your smartphone!\nDownload here: %2$s</string>
<string name="auth_check_server">Check Server</string>
+ <string name="auth_host_url">Server address https://…</string>
<string name="auth_username">Username</string>
<string name="auth_password">Password</string>
<string name="auth_register">New to %1$s?</string>
--- /dev/null
+<?xml version='1.0' encoding='UTF-8'?>
+<resources>
+ <string name="actionbar_upload">Subir</string>
+ <string name="actionbar_upload_files">Archivos</string>
+ <string name="actionbar_mkdir">Crear directorio</string>
+ <string name="actionbar_settings">Configuración</string>
+ <string name="prefs_category_general">General</string>
+ <string name="prefs_accounts">Cuentas</string>
+ <string name="auth_username">Usuario</string>
+ <string name="auth_password">Clave</string>
+ <string name="sync_string_files">Archivos</string>
+ <string name="setup_btn_connect">Conectar</string>
+ <string name="uploader_btn_upload_text">Subir</string>
+ <string name="uploader_wrn_no_account_title">No se encuentra la cuenta</string>
+</resources>
<string name="recommend_subject">Prueba %1$s en tu smarthphone!</string>
<string name="recommend_text">Quiero invitarte a usar %1$s en tu smarthphone!⏎\nDescargalo aquí: %2$s</string>
<string name="auth_check_server">Compruebe el servidor.</string>
+ <string name="auth_host_url">Dirección del servidor https://…</string>
<string name="auth_username">Nombre de usuario</string>
<string name="auth_password">Contraseña</string>
<string name="auth_register">New to %1$s?</string>
<string name="recommend_subject">Proovi oma nutitelefonil rakendust %1$s!</string>
<string name="recommend_text">Soovin sind kutsuda kasutama oma nutitelefonil rakendust %1$s!\nLae alla siit: %2$s</string>
<string name="auth_check_server">Kontrolli serverit</string>
+ <string name="auth_host_url">Serveri aadress https://...</string>
<string name="auth_username">Kasutajanimi</string>
<string name="auth_password">Parool</string>
<string name="auth_register">Uus %1$s kasutaja?</string>
<string name="recommend_subject">Kokeile %1$sia älypuhelimellasi!</string>
<string name="recommend_text">Ota %1$s käyttöösi älypuhelimessa!\nLataa tästä: %2$s</string>
<string name="auth_check_server">Tarkista palvelin</string>
+ <string name="auth_host_url">Palvelinosoite https://…</string>
<string name="auth_username">Käyttäjätunnus</string>
<string name="auth_password">Salasana</string>
<string name="auth_register">Onko %1$s uusi tuttavuus sinulle?</string>
<string name="recommend_subject">Tente %1$s no seu teléfono intelixente!</string>
<string name="recommend_text">Quero convidalo a empregar %1$s no seu teléfono intelixente!⏎\nDescárgueo de aquí:%2$s</string>
<string name="auth_check_server">Comprobar o servidor</string>
+ <string name="auth_host_url">Enderezo do servidor https://…</string>
<string name="auth_username">Nome de usuario</string>
<string name="auth_password">Contrasinal</string>
<string name="auth_register">Novo en %1$s?</string>
<string name="recommend_subject">Próbálja ki %1$s-t az okostelefonján!</string>
<string name="recommend_text">Kérem próbálja ki %1$s-t az okostelefonján!\nInnen tölthető le: %2$s</string>
<string name="auth_check_server">Szerver állapot ellenörzés</string>
+ <string name="auth_host_url">Kiszolgáló címe https://...</string>
<string name="auth_username">Felhasználói név</string>
<string name="auth_password">Jelszó</string>
<string name="auth_register">Új vagy a %1$s területen?</string>
<string name="sync_file_fail_msg">A távoli fájl nem volt ellenőrizhető</string>
<string name="sync_file_nothing_to_do_msg">Az állományok már szinkonizálva vannak</string>
<string name="create_dir_fail_msg">A mappa nem hozható létre</string>
+ <string name="filename_forbidden_characters">Nem megendedett karakterek: / \\ < > : \" | ? *</string>
<string name="wait_a_moment">Egy pillanat...</string>
<string name="filedisplay_unexpected_bad_get_content">Váratlan hiba; válassza ki a fájlt más programból</string>
<string name="filedisplay_no_file_selected">Egy fájl sincs kiválasztva</string>
<string name="preview_image_description">Előnézeti kép</string>
<string name="preview_image_error_unknown_format">Ez a kép nem jelenik meg</string>
<string name="error__upload__local_file_not_copied">%1$s-t nem sikerült átmásolni ide: %2$s </string>
+ <string name="actionbar_failed_instant_upload">Sikertelen azonnali feltöltés\"</string>
<string name="failed_upload_headline_text">Sikertelen Azonnali feltöltés</string>
<string name="failed_upload_headline_hint">Összefoglaló az összes sikertelen instant feltöltésről</string>
<string name="failed_upload_all_cb">Összes kijelölése</string>
<string name="recommend_subject">スマートフォンで %1$s を試してください!</string>
<string name="recommend_text">スマートフォンで %1$s を利用してみませんか!\nここからダウンロードしてください: %2$s</string>
<string name="auth_check_server">サーバーを確認する</string>
+ <string name="auth_host_url">サーバーアドレス https://…</string>
<string name="auth_username">ユーザー名</string>
<string name="auth_password">パスワード</string>
<string name="auth_register">%1$sは初めてですか?</string>
<string name="recommend_subject">Probeer %1$s op uw smartphone!</string>
<string name="recommend_text">Uitnodiging om %1$s op uw smartphone uit te proberen!\nDownload hier: %2$s</string>
<string name="auth_check_server">Controleer server</string>
+ <string name="auth_host_url">Serveradres https://…</string>
<string name="auth_username">Gebruikersnaam</string>
<string name="auth_password">Wachtwoord</string>
<string name="auth_register">Nieuw bij %1$s?</string>
<string name="recommend_subject">Tentar %1$s em seu smartfone!</string>
<string name="recommend_text">Gostaria de lhe convidar para usar %1$s em seu smartfone!\nBaixe aqui: %2$s</string>
<string name="auth_check_server">Verificar Servidor</string>
+ <string name="auth_host_url">Endereço do servidor https://...</string>
<string name="auth_username">Nome de usuário</string>
<string name="auth_password">Senha</string>
<string name="auth_register">Novo para %1$s?</string>
<string name="recommend_subject">Skúste %1$s na vašom telefóne!</string>
<string name="recommend_text">Chcem vás pozvať na používanie %1$s na vašom smartphone!\nNa stiahnutie tu: %2$s</string>
<string name="auth_check_server">Skontrolovať Server</string>
+ <string name="auth_host_url">Adresa servera https://...</string>
<string name="auth_username">Používateľské meno</string>
<string name="auth_password">Heslo</string>
<string name="auth_register">Ste nový v %1$s?</string>
<string name="recommend_subject">Preizkusi %1$s na pametnem telefonu!</string>
<string name="recommend_text">Želim ti predstaviti program %1$s za pametni telefon!\nPrejmeš ga lahko na: %2$s</string>
<string name="auth_check_server">Preveri strežnik</string>
+ <string name="auth_host_url">Naslov strežnika https://…</string>
<string name="auth_username">Uporabniško ime</string>
<string name="auth_password">Geslo</string>
<string name="auth_register">Ali ste novi uporabnik sistema %1$s?</string>
<string name="about_android">%1$s Android Uygulaması</string>
<string name="about_version">sürüm %1$s</string>
<string name="actionbar_sync">Hesabı yenile</string>
- <string name="actionbar_upload">Dosya yükle</string>
+ <string name="actionbar_upload">Yükle</string>
<string name="actionbar_upload_from_apps">Diğer uygulamalardan içerik</string>
<string name="actionbar_upload_files">Dosyalar</string>
<string name="actionbar_open_with">ile aç</string>
- <string name="actionbar_mkdir">Klasör oluştur</string>
+ <string name="actionbar_mkdir">Dizin oluştur</string>
<string name="actionbar_settings">Ayarlar</string>
<string name="actionbar_see_details">Detaylar</string>
<string name="prefs_category_general">Genel</string>
<string name="setup_btn_connect">Bağlan</string>
<string name="uploader_btn_upload_text">Yükle</string>
<string name="uploader_top_message">Yükleme dizinini seçiniz:</string>
- <string name="uploader_wrn_no_account_title">Hesap bulunamadi</string>
- <string name="uploader_wrn_no_account_text">Cihazınızda %1$s hesabı bulunmamaktadır. Lütfen öncelikle bir hesap ayarı giriniz.</string>
+ <string name="uploader_wrn_no_account_title">Hesap bulunamadı</string>
+ <string name="uploader_wrn_no_account_text">Cihazınızda %1$s hesabı bulunmamaktadır. Lütfen öncelikle bir hesap ayarlayın.</string>
<string name="uploader_wrn_no_account_setup_btn_text">Kurulum</string>
<string name="uploader_wrn_no_account_quit_btn_text">Çıkış</string>
<string name="uploader_wrn_no_content_title">Yüklenecek içerik yok</string>
<string name="uploader_error_forbidden_content">%1$s, paylaşılan içeriğe erişim izni vermiyor</string>
<string name="uploader_info_uploading">Yükleniyor</string>
<string name="file_list_empty">Klasörde dosya yok. Yeni dosyalar yükle\'ye tıklayarak eklenebilir.</string>
- <string name="filedetails_select_file">Ek bilgileri görmek için dosyaya tıklayınız.</string>
+ <string name="filedetails_select_file">Ek bilgileri görmek için dosyaya dokunun.</string>
<string name="filedetails_size">Boyut:</string>
<string name="filedetails_type">Tür:</string>
<string name="filedetails_created">Oluşturulma:</string>
<string name="auth_account_not_the_same">Girilen kullanıcı bu hesabın kullanıcısı ile eşleşmiyor</string>
<string name="auth_unknown_error_title">Bilinmeyen hata oluştu.</string>
<string name="auth_unknown_host_title">Anabilgisayar bulunamadı</string>
- <string name="auth_incorrect_path_title">sunucu servisi bulunamadı.</string>
+ <string name="auth_incorrect_path_title">Sunucu örneği bulunamadı.</string>
<string name="auth_timeout_title">Sunucu çok geç cevap veriyor</string>
<string name="auth_incorrect_address_title">Hatalı biçimlendirilmiş URL</string>
<string name="auth_ssl_general_error_title">SSL başlatılmasında hata</string>
import com.owncloud.android.oc_framework.accounts.OwnCloudAccount;\r
import com.owncloud.android.oc_framework.network.webdav.OwnCloudClientFactory;\r
import com.owncloud.android.oc_framework.network.webdav.WebdavClient;\r
-import com.owncloud.android.operations.ExistenceCheckOperation;\r
import com.owncloud.android.operations.OAuth2GetAccessToken;\r
import com.owncloud.android.oc_framework.operations.OnRemoteOperationListener;\r
import com.owncloud.android.operations.OwnCloudServerCheckOperation;\r
import com.owncloud.android.oc_framework.operations.RemoteOperation;\r
import com.owncloud.android.oc_framework.operations.RemoteOperationResult;\r
import com.owncloud.android.oc_framework.operations.RemoteOperationResult.ResultCode;\r
+import com.owncloud.android.oc_framework.operations.remote.ExistenceCheckRemoteOperation;\r
import com.owncloud.android.ui.dialog.SamlWebViewDialog;\r
import com.owncloud.android.ui.dialog.SslValidatorDialog;\r
import com.owncloud.android.ui.dialog.SslValidatorDialog.OnSslValidatorListener;\r
private final Handler mHandler = new Handler();\r
private Thread mOperationThread;\r
private OwnCloudServerCheckOperation mOcServerChkOperation;\r
- private ExistenceCheckOperation mAuthCheckOperation;\r
+ private ExistenceCheckRemoteOperation mAuthCheckOperation;\r
private RemoteOperationResult mLastSslUntrustedServerResult;\r
\r
private Uri mNewCapturedUriFromOAuth2Redirection;\r
showDialog(DIALOG_LOGIN_PROGRESS);\r
\r
/// test credentials accessing the root folder\r
- mAuthCheckOperation = new ExistenceCheckOperation("", this, false);\r
+ mAuthCheckOperation = new ExistenceCheckRemoteOperation("", this, false);\r
WebdavClient client = OwnCloudClientFactory.createOwnCloudClient(Uri.parse(mHostBaseUrl + webdav_path), this, true);\r
client.setBasicCredentials(username, password);\r
mOperationThread = mAuthCheckOperation.execute(client, this, mHandler);\r
String webdav_path = AccountUtils.getWebdavPath(mDiscoveredVersion, mAuthTokenType);\r
\r
/// test credentials accessing the root folder\r
- mAuthCheckOperation = new ExistenceCheckOperation("", this, false);\r
+ mAuthCheckOperation = new ExistenceCheckRemoteOperation("", this, false);\r
WebdavClient client = OwnCloudClientFactory.createOwnCloudClient(Uri.parse(mHostBaseUrl + webdav_path), this, false);\r
mOperationThread = mAuthCheckOperation.execute(client, this, mHandler);\r
\r
} else if (operation instanceof OAuth2GetAccessToken) {\r
onGetOAuthAccessTokenFinish((OAuth2GetAccessToken)operation, result);\r
\r
- } else if (operation instanceof ExistenceCheckOperation) {\r
+ } else if (operation instanceof ExistenceCheckRemoteOperation) {\r
if (AccountTypeUtils.getAuthTokenTypeSamlSessionCookie(MainApp.getAccountType()).equals(mAuthTokenType)) {\r
onSamlBasedFederatedSingleSignOnAuthorizationStart(operation, result);\r
\r
} else {\r
- onAuthorizationCheckFinish((ExistenceCheckOperation)operation, result);\r
+ onAuthorizationCheckFinish((ExistenceCheckRemoteOperation)operation, result);\r
}\r
}\r
}\r
/// time to test the retrieved access token on the ownCloud server\r
mAuthToken = ((OAuth2GetAccessToken)operation).getResultTokenMap().get(OAuth2Constants.KEY_ACCESS_TOKEN);\r
Log_OC.d(TAG, "Got ACCESS TOKEN: " + mAuthToken);\r
- mAuthCheckOperation = new ExistenceCheckOperation("", this, false);\r
+ mAuthCheckOperation = new ExistenceCheckRemoteOperation("", this, false);\r
WebdavClient client = OwnCloudClientFactory.createOwnCloudClient(Uri.parse(mHostBaseUrl + webdav_path), this, true);\r
client.setBearerCredentials(mAuthToken);\r
mAuthCheckOperation.execute(client, this, mHandler);\r
* @param operation Access check performed.\r
* @param result Result of the operation.\r
*/\r
- private void onAuthorizationCheckFinish(ExistenceCheckOperation operation, RemoteOperationResult result) {\r
+ private void onAuthorizationCheckFinish(ExistenceCheckRemoteOperation operation, RemoteOperationResult result) {\r
try {\r
dismissDialog(DIALOG_LOGIN_PROGRESS);\r
} catch (IllegalArgumentException e) {\r
import com.owncloud.android.datamodel.FileDataStorageManager;
import com.owncloud.android.datamodel.OCFile;
import com.owncloud.android.db.DbHandler;
-import com.owncloud.android.operations.ChunkedUploadFileOperation;
import com.owncloud.android.operations.CreateFolderOperation;
-import com.owncloud.android.operations.ExistenceCheckOperation;
import com.owncloud.android.oc_framework.operations.RemoteOperation;
import com.owncloud.android.oc_framework.operations.RemoteOperationResult;
import com.owncloud.android.operations.UploadFileOperation;
import com.owncloud.android.oc_framework.operations.RemoteOperationResult.ResultCode;
+import com.owncloud.android.oc_framework.operations.remote.ExistenceCheckRemoteOperation;
import com.owncloud.android.oc_framework.utils.OwnCloudVersion;
import com.owncloud.android.oc_framework.network.webdav.OnDatatransferProgressListener;
import com.owncloud.android.oc_framework.accounts.OwnCloudAccount;
-import com.owncloud.android.oc_framework.network.webdav.ChunkFromFileChannelRequestEntity;
import com.owncloud.android.oc_framework.network.webdav.OwnCloudClientFactory;
import com.owncloud.android.oc_framework.network.webdav.WebdavClient;
import com.owncloud.android.oc_framework.network.webdav.WebdavEntry;
files[i] = obtainNewOCFileToUpload(remotePaths[i], localPaths[i], ((mimeTypes != null) ? mimeTypes[i]
: (String) null), storageManager);
if (files[i] == null) {
- // TODO @andomaex add failure Notiification
+ // TODO @andomaex add failure Notification
return Service.START_NOT_STICKY;
}
}
try {
for (int i = 0; i < files.length; i++) {
uploadKey = buildRemoteName(account, files[i].getRemotePath());
- if (chunked
- && (new File(files[i].getStoragePath())).length() > ChunkedUploadFileOperation.CHUNK_SIZE) // added to work around bug in servers 5.x
- {
- newUpload = new ChunkedUploadFileOperation(account, files[i], isInstant, forceOverwrite,
- localAction);
- } else {
- newUpload = new UploadFileOperation(account, files[i], isInstant, forceOverwrite, localAction);
- }
+ newUpload = new UploadFileOperation(account, files[i], chunked, isInstant, forceOverwrite, localAction,
+ getApplicationContext());
+// if (chunked) {
+// newUpload = new ChunkedUploadFileOperation(account, files[i], isInstant, forceOverwrite,
+// localAction, getApplicationContext());
+// } else {
+// newUpload = new UploadFileOperation(account, files[i], isInstant, forceOverwrite, localAction,
+// getApplicationContext());
+// }
if (isInstant) {
newUpload.setRemoteFolderToBeCreated();
}
* @return An {@link OCFile} instance corresponding to the folder where the file will be uploaded.
*/
private RemoteOperationResult grantFolderExistence(String pathToGrant) {
- RemoteOperation operation = new ExistenceCheckOperation(pathToGrant, this, false);
+ RemoteOperation operation = new ExistenceCheckRemoteOperation(pathToGrant, this, false);
RemoteOperationResult result = operation.execute(mUploadClient);
if (!result.isSuccess() && result.getCode() == ResultCode.FILE_NOT_FOUND && mCurrentUpload.isRemoteFolderToBeCreated()) {
operation = new CreateFolderOperation( pathToGrant,
+++ /dev/null
-/* ownCloud Android client application
- * Copyright (C) 2012 Bartek Przybylski
- * Copyright (C) 2012-2013 ownCloud Inc.
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 2,
- * as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- *
- */
-
-package com.owncloud.android.operations;
-
-import java.io.File;
-import java.io.IOException;
-import java.io.RandomAccessFile;
-import java.nio.channels.FileChannel;
-import java.util.Random;
-
-import org.apache.commons.httpclient.HttpException;
-import org.apache.commons.httpclient.methods.PutMethod;
-
-import com.owncloud.android.datamodel.OCFile;
-import com.owncloud.android.oc_framework.network.ProgressiveDataTransferer;
-import com.owncloud.android.oc_framework.network.webdav.ChunkFromFileChannelRequestEntity;
-import com.owncloud.android.oc_framework.network.webdav.WebdavClient;
-import com.owncloud.android.oc_framework.network.webdav.WebdavUtils;
-import com.owncloud.android.utils.Log_OC;
-
-
-import android.accounts.Account;
-
-
-public class ChunkedUploadFileOperation extends UploadFileOperation {
-
- public static final long CHUNK_SIZE = 1024000;
- private static final String OC_CHUNKED_HEADER = "OC-Chunked";
- private static final String TAG = ChunkedUploadFileOperation.class.getSimpleName();
-
- public ChunkedUploadFileOperation( Account account,
- OCFile file,
- boolean isInstant,
- boolean forceOverwrite,
- int localBehaviour) {
-
- super(account, file, isInstant, forceOverwrite, localBehaviour);
- }
-
- @Override
- protected int uploadFile(WebdavClient client) throws HttpException, IOException {
- int status = -1;
-
- FileChannel channel = null;
- RandomAccessFile raf = null;
- try {
- File file = new File(getStoragePath());
- raf = new RandomAccessFile(file, "r");
- channel = raf.getChannel();
- mEntity = new ChunkFromFileChannelRequestEntity(channel, getMimeType(), CHUNK_SIZE, file);
- ((ProgressiveDataTransferer)mEntity).addDatatransferProgressListeners(getDataTransferListeners());
- long offset = 0;
- String uriPrefix = client.getBaseUri() + WebdavUtils.encodePath(getRemotePath()) + "-chunking-" + Math.abs((new Random()).nextInt(9000)+1000) + "-" ;
- long chunkCount = (long) Math.ceil((double)file.length() / CHUNK_SIZE);
- for (int chunkIndex = 0; chunkIndex < chunkCount ; chunkIndex++, offset += CHUNK_SIZE) {
- if (mPutMethod != null) {
- mPutMethod.releaseConnection(); // let the connection available for other methods
- }
- mPutMethod = new PutMethod(uriPrefix + chunkCount + "-" + chunkIndex);
- mPutMethod.addRequestHeader(OC_CHUNKED_HEADER, OC_CHUNKED_HEADER);
- ((ChunkFromFileChannelRequestEntity)mEntity).setOffset(offset);
- mPutMethod.setRequestEntity(mEntity);
- status = client.executeMethod(mPutMethod);
- client.exhaustResponse(mPutMethod.getResponseBodyAsStream());
- Log_OC.d(TAG, "Upload of " + getStoragePath() + " to " + getRemotePath() + ", chunk index " + chunkIndex + ", count " + chunkCount + ", HTTP result status " + status);
- if (!isSuccess(status))
- break;
- }
-
- } finally {
- if (channel != null)
- channel.close();
- if (raf != null)
- raf.close();
- if (mPutMethod != null)
- mPutMethod.releaseConnection(); // let the connection available for other methods
- }
- return status;
- }
-
-}
+++ /dev/null
-/* ownCloud Android client application
- * Copyright (C) 2012 ownCloud Inc.
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 2,
- * as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- *
- */
-
-package com.owncloud.android.operations;
-
-import org.apache.commons.httpclient.HttpStatus;
-import org.apache.commons.httpclient.methods.HeadMethod;
-
-import com.owncloud.android.oc_framework.network.webdav.WebdavClient;
-import com.owncloud.android.oc_framework.operations.RemoteOperation;
-import com.owncloud.android.oc_framework.operations.RemoteOperationResult;
-import com.owncloud.android.oc_framework.network.webdav.WebdavUtils;
-import com.owncloud.android.utils.Log_OC;
-
-import android.content.Context;
-import android.net.ConnectivityManager;
-
-/**
- * Operation to check the existence or absence of a path in a remote server.
- *
- * @author David A. Velasco
- */
-public class ExistenceCheckOperation extends RemoteOperation {
-
- /** Maximum time to wait for a response from the server in MILLISECONDs. */
- public static final int TIMEOUT = 10000;
-
- private static final String TAG = ExistenceCheckOperation.class.getSimpleName();
-
- private String mPath;
- private Context mContext;
- private boolean mSuccessIfAbsent;
-
-
- /**
- * Full constructor. Success of the operation will depend upon the value of successIfAbsent.
- *
- * @param path Path to append to the URL owned by the client instance.
- * @param context Android application context.
- * @param successIfAbsent When 'true', the operation finishes in success if the path does NOT exist in the remote server (HTTP 404).
- */
- public ExistenceCheckOperation(String path, Context context, boolean successIfAbsent) {
- mPath = (path != null) ? path : "";
- mContext = context;
- mSuccessIfAbsent = successIfAbsent;
- }
-
-
- @Override
- protected RemoteOperationResult run(WebdavClient client) {
- if (!isOnline()) {
- return new RemoteOperationResult(RemoteOperationResult.ResultCode.NO_NETWORK_CONNECTION);
- }
- RemoteOperationResult result = null;
- HeadMethod head = null;
- try {
- head = new HeadMethod(client.getBaseUri() + WebdavUtils.encodePath(mPath));
- int status = client.executeMethod(head, TIMEOUT, TIMEOUT);
- client.exhaustResponse(head.getResponseBodyAsStream());
- boolean success = (status == HttpStatus.SC_OK && !mSuccessIfAbsent) || (status == HttpStatus.SC_NOT_FOUND && mSuccessIfAbsent);
- result = new RemoteOperationResult(success, status, head.getResponseHeaders());
- Log_OC.d(TAG, "Existence check for " + client.getBaseUri() + WebdavUtils.encodePath(mPath) + " targeting for " + (mSuccessIfAbsent ? " absence " : " existence ") + "finished with HTTP status " + status + (!success?"(FAIL)":""));
-
- } catch (Exception e) {
- result = new RemoteOperationResult(e);
- Log_OC.e(TAG, "Existence check for " + client.getBaseUri() + WebdavUtils.encodePath(mPath) + " targeting for " + (mSuccessIfAbsent ? " absence " : " existence ") + ": " + result.getLogMessage(), result.getException());
-
- } finally {
- if (head != null)
- head.releaseConnection();
- }
- return result;
- }
-
- private boolean isOnline() {
- ConnectivityManager cm = (ConnectivityManager) mContext
- .getSystemService(Context.CONNECTIVITY_SERVICE);
- return cm != null && cm.getActiveNetworkInfo() != null
- && cm.getActiveNetworkInfo().isConnectedOrConnecting();
- }
-
-
-}
import java.io.InputStream;
import java.io.OutputStream;
import java.util.HashSet;
+import java.util.Iterator;
import java.util.Set;
import java.util.concurrent.atomic.AtomicBoolean;
import com.owncloud.android.oc_framework.network.webdav.FileRequestEntity;
import com.owncloud.android.oc_framework.network.webdav.OnDatatransferProgressListener;
import com.owncloud.android.oc_framework.network.webdav.WebdavClient;
-import com.owncloud.android.oc_framework.network.webdav.WebdavUtils;
import com.owncloud.android.oc_framework.operations.OperationCancelledException;
import com.owncloud.android.oc_framework.operations.RemoteOperation;
import com.owncloud.android.oc_framework.operations.RemoteOperationResult;
import com.owncloud.android.oc_framework.operations.RemoteOperationResult.ResultCode;
+import com.owncloud.android.oc_framework.operations.remote.ChunkedUploadRemoteFileOperation;
+import com.owncloud.android.oc_framework.operations.remote.ExistenceCheckRemoteOperation;
+import com.owncloud.android.oc_framework.operations.remote.UploadRemoteFileOperation;
import com.owncloud.android.utils.FileStorageUtils;
import com.owncloud.android.utils.Log_OC;
import android.accounts.Account;
+import android.content.Context;
/**
private OCFile mFile;
private OCFile mOldFile;
private String mRemotePath = null;
+ private boolean mChunked = false;
private boolean mIsInstant = false;
private boolean mRemoteFolderToBeCreated = false;
private boolean mForceOverwrite = false;
PutMethod mPutMethod = null;
private Set<OnDatatransferProgressListener> mDataTransferListeners = new HashSet<OnDatatransferProgressListener>();
private final AtomicBoolean mCancellationRequested = new AtomicBoolean(false);
+ private Context mContext;
+
+ private UploadRemoteFileOperation mUploadOperation;
protected RequestEntity mEntity = null;
public UploadFileOperation( Account account,
OCFile file,
+ boolean chunked,
boolean isInstant,
boolean forceOverwrite,
- int localBehaviour) {
+ int localBehaviour,
+ Context context) {
if (account == null)
throw new IllegalArgumentException("Illegal NULL account in UploadFileOperation creation");
if (file == null)
mAccount = account;
mFile = file;
mRemotePath = file.getRemotePath();
+ mChunked = chunked;
mIsInstant = isInstant;
mForceOverwrite = forceOverwrite;
mLocalBehaviour = localBehaviour;
mOriginalStoragePath = mFile.getStoragePath();
mOriginalFileName = mFile.getFileName();
+ mContext = context;
}
public Account getAccount() {
// !!!
expectedFile = new File(expectedPath);
- // / check location of local file; if not the expected, copy to a
+ // check location of local file; if not the expected, copy to a
// temporal file before upload (if COPY is the expected behaviour)
if (!mOriginalStoragePath.equals(expectedPath) && mLocalBehaviour == FileUploader.LOCAL_BEHAVIOUR_COPY) {
}
localCopyPassed = true;
- // / perform the upload
- synchronized (mCancellationRequested) {
- if (mCancellationRequested.get()) {
- throw new OperationCancelledException();
- } else {
- mPutMethod = new PutMethod(client.getBaseUri() + WebdavUtils.encodePath(mFile.getRemotePath()));
- }
+ /// perform the upload
+ if (mChunked) {
+ mUploadOperation = new ChunkedUploadRemoteFileOperation(mFile.getStoragePath(), mFile.getRemotePath(),
+ mFile.getMimetype());
+ } else {
+ mUploadOperation = new UploadRemoteFileOperation(mFile.getStoragePath(), mFile.getRemotePath(),
+ mFile.getMimetype());
+ }
+ Iterator <OnDatatransferProgressListener> listener = mDataTransferListeners.iterator();
+ while (listener.hasNext()) {
+ mUploadOperation.addDatatransferProgressListener(listener.next());
}
- int status = uploadFile(client);
+ result = mUploadOperation.execute(client);
- // / move local temporal file or original file to its corresponding
+ /// move local temporal file or original file to its corresponding
// location in the ownCloud local folder
- if (isSuccess(status)) {
+ if (result.isSuccess()) {
if (mLocalBehaviour == FileUploader.LOCAL_BEHAVIOUR_FORGET) {
mFile.setStoragePath(null);
}
}
- result = new RemoteOperationResult(isSuccess(status), status, (mPutMethod != null ? mPutMethod.getResponseHeaders() : null));
-
} catch (Exception e) {
// TODO something cleaner with cancellations
if (mCancellationRequested.get()) {
mFile = newFile;
}
- public boolean isSuccess(int status) {
- return ((status == HttpStatus.SC_OK || status == HttpStatus.SC_CREATED || status == HttpStatus.SC_NO_CONTENT));
- }
-
- protected int uploadFile(WebdavClient client) throws HttpException, IOException, OperationCancelledException {
- int status = -1;
- try {
- File f = new File(mFile.getStoragePath());
- mEntity = new FileRequestEntity(f, getMimeType());
- synchronized (mDataTransferListeners) {
- ((ProgressiveDataTransferer)mEntity).addDatatransferProgressListeners(mDataTransferListeners);
- }
- mPutMethod.setRequestEntity(mEntity);
- status = client.executeMethod(mPutMethod);
- client.exhaustResponse(mPutMethod.getResponseBodyAsStream());
-
- } finally {
- mPutMethod.releaseConnection(); // let the connection available for
- // other methods
- }
- return status;
- }
+// public boolean isSuccess(int status) {
+// return ((status == HttpStatus.SC_OK || status == HttpStatus.SC_CREATED || status == HttpStatus.SC_NO_CONTENT));
+// }
+//
+// protected int uploadFile(WebdavClient client) throws HttpException, IOException, OperationCancelledException {
+// int status = -1;
+// try {
+// File f = new File(mFile.getStoragePath());
+// mEntity = new FileRequestEntity(f, getMimeType());
+// synchronized (mDataTransferListeners) {
+// ((ProgressiveDataTransferer)mEntity).addDatatransferProgressListeners(mDataTransferListeners);
+// }
+// mPutMethod.setRequestEntity(mEntity);
+// status = client.executeMethod(mPutMethod);
+// client.exhaustResponse(mPutMethod.getResponseBodyAsStream());
+//
+// } finally {
+// mPutMethod.releaseConnection(); // let the connection available for
+// // other methods
+// }
+// return status;
+// }
/**
* Checks if remotePath does not exist in the server and returns it, or adds
* @return
*/
private String getAvailableRemotePath(WebdavClient wc, String remotePath) throws Exception {
- boolean check = wc.existsFile(remotePath);
+ boolean check = existsFile(wc, remotePath);
if (!check) {
return remotePath;
}
int count = 2;
do {
suffix = " (" + count + ")";
- if (pos >= 0)
- check = wc.existsFile(remotePath + suffix + "." + extension);
- else
- check = wc.existsFile(remotePath + suffix);
+ if (pos >= 0) {
+ check = existsFile(wc, remotePath + suffix + "." + extension);
+ }
+ else {
+ check = existsFile(wc, remotePath + suffix);
+ }
count++;
} while (check);
}
}
+ private boolean existsFile(WebdavClient client, String remotePath){
+ ExistenceCheckRemoteOperation existsOperation = new ExistenceCheckRemoteOperation(remotePath, mContext, false);
+ RemoteOperationResult result = existsOperation.execute(client);
+ return result.isSuccess();
+ }
+
public void cancel() {
- synchronized (mCancellationRequested) {
- mCancellationRequested.set(true);
- if (mPutMethod != null)
- mPutMethod.abort();
- }
+ mUploadOperation.cancel();
}
}
import com.owncloud.android.MainApp;
import com.owncloud.android.R;
-import com.owncloud.android.R.id;
-import com.owncloud.android.R.layout;
-import com.owncloud.android.R.string;
import com.owncloud.android.authentication.AccountAuthenticator;
import com.owncloud.android.datamodel.FileDataStorageManager;
import com.owncloud.android.datamodel.OCFile;