diff --git a/oc_framework-test-project/AndroidManifest.xml b/oc_framework-test-project/AndroidManifest.xml index d4d5316a1a..c913bf0668 100644 --- a/oc_framework-test-project/AndroidManifest.xml +++ b/oc_framework-test-project/AndroidManifest.xml @@ -7,7 +7,9 @@ + + - + diff --git a/oc_framework-test-project/oc_framework-test-test/src/com/owncloud/android/oc_framework_test_project/test/CreateFolderTest.java b/oc_framework-test-project/oc_framework-test-test/src/com/owncloud/android/oc_framework_test_project/test/CreateFolderTest.java index 34b8f3243c..2ec2d3af79 100644 --- a/oc_framework-test-project/oc_framework-test-test/src/com/owncloud/android/oc_framework_test_project/test/CreateFolderTest.java +++ b/oc_framework-test-project/oc_framework-test-test/src/com/owncloud/android/oc_framework_test_project/test/CreateFolderTest.java @@ -4,10 +4,10 @@ import java.text.SimpleDateFormat; import java.util.Date; import com.owncloud.android.oc_framework.operations.RemoteOperationResult; +import com.owncloud.android.oc_framework.operations.RemoteOperationResult.ResultCode; import com.owncloud.android.oc_framework_test_project.TestActivity; import android.test.ActivityInstrumentationTestCase2; -import android.util.Log; public class CreateFolderTest extends ActivityInstrumentationTestCase2 { @@ -34,17 +34,47 @@ public class CreateFolderTest extends ActivityInstrumentationTestCase2"+ am.getUserData(mAccount, "oc_version") ); Log.d(TAG, "oc_base_url --->"+ am.getUserData(mAccount, "oc_base_url") ); - } +// } try { - mClient = OwnCloudClientUtils.createOwnCloudClient(mAccount, this.getApplicationContext(), authorities); + mClient = OwnCloudClientFactory.createOwnCloudClient(mAccount, this.getApplicationContext()); } catch (OperationCanceledException e) { Log.e(TAG, "Error while trying to access to " + mAccount.name, e); e.printStackTrace(); diff --git a/oc_framework/src/com/owncloud/android/oc_framework/operations/RemoteOperationResult.java b/oc_framework/src/com/owncloud/android/oc_framework/operations/RemoteOperationResult.java index 822ed880c3..f26988ccc0 100644 --- a/oc_framework/src/com/owncloud/android/oc_framework/operations/RemoteOperationResult.java +++ b/oc_framework/src/com/owncloud/android/oc_framework/operations/RemoteOperationResult.java @@ -89,7 +89,8 @@ public class RemoteOperationResult implements Serializable { ACCOUNT_NOT_FOUND, ACCOUNT_EXCEPTION, ACCOUNT_NOT_NEW, - ACCOUNT_NOT_THE_SAME + ACCOUNT_NOT_THE_SAME, + INVALID_CHARACTER_IN_NAME } private boolean mSuccess = false; @@ -307,6 +308,8 @@ public class RemoteOperationResult implements Serializable { } else if (mCode == ResultCode.ACCOUNT_NOT_THE_SAME) { return "Authenticated with a different account than the one updating"; + } else if (mCode == ResultCode.INVALID_CHARACTER_IN_NAME) { + return "The file name contains an forbidden character"; } return "Operation finished with HTTP status code " + mHttpCode + " (" + (isSuccess() ? "success" : "fail") + ")"; diff --git a/oc_framework/src/com/owncloud/android/oc_framework/operations/remote/CreateRemoteFolderOperation.java b/oc_framework/src/com/owncloud/android/oc_framework/operations/remote/CreateRemoteFolderOperation.java index 47870dec44..a326ed1030 100644 --- a/oc_framework/src/com/owncloud/android/oc_framework/operations/remote/CreateRemoteFolderOperation.java +++ b/oc_framework/src/com/owncloud/android/oc_framework/operations/remote/CreateRemoteFolderOperation.java @@ -1,7 +1,5 @@ package com.owncloud.android.oc_framework.operations.remote; -import java.io.File; - import org.apache.commons.httpclient.HttpStatus; import org.apache.jackrabbit.webdav.client.methods.MkColMethod; @@ -11,6 +9,8 @@ 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.RemoteOperation; import com.owncloud.android.oc_framework.operations.RemoteOperationResult; +import com.owncloud.android.oc_framework.operations.RemoteOperationResult.ResultCode; +import com.owncloud.android.oc_framework.utils.FileUtils; @@ -28,7 +28,7 @@ public class CreateRemoteFolderOperation extends RemoteOperation { private static final int READ_TIMEOUT = 10000; private static final int CONNECTION_TIMEOUT = 5000; - private static final String PATH_SEPARATOR = "/"; + protected String mRemotePath; protected boolean mCreateFullPath; @@ -54,26 +54,32 @@ public class CreateRemoteFolderOperation extends RemoteOperation { RemoteOperationResult result = null; MkColMethod mkcol = null; - try { - mkcol = new MkColMethod(client.getBaseUri() + WebdavUtils.encodePath(mRemotePath)); - int status = client.executeMethod(mkcol, READ_TIMEOUT, CONNECTION_TIMEOUT); - if (!mkcol.succeeded() && mkcol.getStatusCode() == HttpStatus.SC_CONFLICT && mCreateFullPath) { - result = createParentFolder(getParentPath(), client); - status = client.executeMethod(mkcol, READ_TIMEOUT, CONNECTION_TIMEOUT); // second (and last) try - } - - result = new RemoteOperationResult(mkcol.succeeded(), status, mkcol.getResponseHeaders()); - Log.d(TAG, "Create directory " + mRemotePath + ": " + result.getLogMessage()); - client.exhaustResponse(mkcol.getResponseBodyAsStream()); - - } catch (Exception e) { - result = new RemoteOperationResult(e); - Log.e(TAG, "Create directory " + mRemotePath + ": " + result.getLogMessage(), e); - - } finally { - if (mkcol != null) - mkcol.releaseConnection(); + boolean noInvalidChars = FileUtils.validateName(mRemotePath); + if (noInvalidChars) { + try { + mkcol = new MkColMethod(client.getBaseUri() + WebdavUtils.encodePath(mRemotePath)); + int status = client.executeMethod(mkcol, READ_TIMEOUT, CONNECTION_TIMEOUT); + if (!mkcol.succeeded() && mkcol.getStatusCode() == HttpStatus.SC_CONFLICT && mCreateFullPath) { + result = createParentFolder(FileUtils.getParentPath(mRemotePath), client); + status = client.executeMethod(mkcol, READ_TIMEOUT, CONNECTION_TIMEOUT); // second (and last) try + } + + result = new RemoteOperationResult(mkcol.succeeded(), status, mkcol.getResponseHeaders()); + Log.d(TAG, "Create directory " + mRemotePath + ": " + result.getLogMessage()); + client.exhaustResponse(mkcol.getResponseBodyAsStream()); + + } catch (Exception e) { + result = new RemoteOperationResult(e); + Log.e(TAG, "Create directory " + mRemotePath + ": " + result.getLogMessage(), e); + + } finally { + if (mkcol != null) + mkcol.releaseConnection(); + } + } else { + result = new RemoteOperationResult(ResultCode.INVALID_CHARACTER_IN_NAME); } + return result; } @@ -84,10 +90,6 @@ public class CreateRemoteFolderOperation extends RemoteOperation { return operation.execute(client); } - private String getParentPath() { - String parentPath = new File(mRemotePath).getParent(); - parentPath = parentPath.endsWith(PATH_SEPARATOR) ? parentPath : parentPath + PATH_SEPARATOR; - return parentPath; - } + } diff --git a/project.properties b/project.properties index dbd0f5e587..843526101c 100644 --- a/project.properties +++ b/project.properties @@ -9,5 +9,5 @@ # Project target. target=android-19 -android.library.reference.1=actionbarsherlock/library +android.library.reference.1=actionbarsherlock\\library android.library.reference.2=oc_framework diff --git a/tests/.classpath b/tests/.classpath index 74f453aae0..0e30785e60 100644 --- a/tests/.classpath +++ b/tests/.classpath @@ -1,4 +1,5 @@ + diff --git a/tests/src/com/owncloud/android/test/AccountUtilsTest.java b/tests/src/com/owncloud/android/test/AccountUtilsTest.java index 529776b7d4..1524d3b23a 100644 --- a/tests/src/com/owncloud/android/test/AccountUtilsTest.java +++ b/tests/src/com/owncloud/android/test/AccountUtilsTest.java @@ -20,8 +20,8 @@ package com.owncloud.android.test; import android.test.AndroidTestCase; -import com.owncloud.android.authentication.AccountUtils; -import com.owncloud.android.utils.OwnCloudVersion; +import com.owncloud.android.oc_framework.accounts.AccountUtils; +import com.owncloud.android.oc_framework.utils.OwnCloudVersion; public class AccountUtilsTest extends AndroidTestCase {