From: masensio Date: Thu, 14 Nov 2013 16:44:23 +0000 (+0100) Subject: OC-1990: Isolate code from RenameFileOperation to remove dependecies on local storage... X-Git-Tag: oc-android-1.5.5~123^2~8 X-Git-Url: http://git.linex4red.de/pub/Android/ownCloud.git/commitdiff_plain/b9808f69380b70f3925f129854e9489cf695b6e3?hp=--cc OC-1990: Isolate code from RenameFileOperation to remove dependecies on local storage. Filter invalid characters in fileName --- b9808f69380b70f3925f129854e9489cf695b6e3 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 5ee07d79..f25c22ed 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 @@ -56,11 +56,7 @@ public class CreateRemoteFolderOperation extends RemoteOperation { RemoteOperationResult result = null; MkColMethod mkcol = null; -<<<<<<< HEAD - boolean noInvalidChars = FileUtils.validateName(mRemotePath, true); -======= boolean noInvalidChars = FileUtils.validateName(mFolderName); ->>>>>>> refactor_remote_operation_to_create_folder if (noInvalidChars) { try { mkcol = new MkColMethod(client.getBaseUri() + WebdavUtils.encodePath(mRemotePath)); diff --git a/oc_framework/src/com/owncloud/android/oc_framework/operations/remote/RenameRemoteFileOperation.java b/oc_framework/src/com/owncloud/android/oc_framework/operations/remote/RenameRemoteFileOperation.java index 799ce2f1..05a58e27 100644 --- a/oc_framework/src/com/owncloud/android/oc_framework/operations/remote/RenameRemoteFileOperation.java +++ b/oc_framework/src/com/owncloud/android/oc_framework/operations/remote/RenameRemoteFileOperation.java @@ -29,7 +29,6 @@ public class RenameRemoteFileOperation extends RemoteOperation { private String mOldRemotePath; private String mNewName; private String mNewRemotePath; - private boolean mIsFolder; /** @@ -40,12 +39,11 @@ public class RenameRemoteFileOperation extends RemoteOperation { * @param newName New name to set as the name of file. * @param newRemotePath New remote path to move the file, for folders it starts and ends by "/" */ - public RenameRemoteFileOperation(String oldName, String oldRemotePath, String newName, String newRemotePath, boolean isFolder) { + public RenameRemoteFileOperation(String oldName, String oldRemotePath, String newName, String newRemotePath) { mOldName = oldName; mOldRemotePath = oldRemotePath; mNewName = newName; mNewRemotePath = newRemotePath; - mIsFolder = isFolder; } /** @@ -59,12 +57,7 @@ public class RenameRemoteFileOperation extends RemoteOperation { LocalMoveMethod move = null; - boolean noInvalidChars = true; - - if (mIsFolder) - noInvalidChars = FileUtils.validateName(mNewRemotePath, mIsFolder); - else - noInvalidChars = FileUtils.validateName(mNewName, mIsFolder); + boolean noInvalidChars = FileUtils.validateName(mNewName); if (noInvalidChars) { try { diff --git a/oc_framework/src/com/owncloud/android/oc_framework/utils/FileUtils.java b/oc_framework/src/com/owncloud/android/oc_framework/utils/FileUtils.java index 1ba399b4..75bd5669 100644 --- a/oc_framework/src/com/owncloud/android/oc_framework/utils/FileUtils.java +++ b/oc_framework/src/com/owncloud/android/oc_framework/utils/FileUtils.java @@ -20,15 +20,11 @@ public class FileUtils { * @param fileName * @return */ - public static boolean validateName(String fileName, boolean isFolder) { + public static boolean validateName(String fileName) { boolean result = true; Log.d("FileUtils", "fileName ======= " + fileName); - String name = fileName.substring(1); - if (isFolder) { - name = name.substring(0, name.length() - 1); - } - if (name.contains("/") || fileName.contains("\\") || fileName.contains("<") || + if (fileName.contains("/") || fileName.contains("\\") || fileName.contains("<") || fileName.contains(">") || fileName.contains(":") || fileName.contains("\"") || fileName.contains("|") || fileName.contains("?") || fileName.contains("*")) { result = false; diff --git a/src/com/owncloud/android/files/services/FileUploader.java b/src/com/owncloud/android/files/services/FileUploader.java index 6e80fd50..e8dcf949 100644 --- a/src/com/owncloud/android/files/services/FileUploader.java +++ b/src/com/owncloud/android/files/services/FileUploader.java @@ -33,9 +33,7 @@ import org.apache.jackrabbit.webdav.DavConstants; import org.apache.jackrabbit.webdav.MultiStatus; import org.apache.jackrabbit.webdav.client.methods.PropFindMethod; -import com.owncloud.android.MainApp; import com.owncloud.android.R; -import com.owncloud.android.authentication.AccountAuthenticator; import com.owncloud.android.authentication.AuthenticatorActivity; import com.owncloud.android.datamodel.FileDataStorageManager; import com.owncloud.android.datamodel.OCFile; diff --git a/src/com/owncloud/android/operations/RenameFileOperation.java b/src/com/owncloud/android/operations/RenameFileOperation.java index 1eecfc28..69ca2f23 100644 --- a/src/com/owncloud/android/operations/RenameFileOperation.java +++ b/src/com/owncloud/android/operations/RenameFileOperation.java @@ -100,7 +100,7 @@ public class RenameFileOperation extends RemoteOperation { } RenameRemoteFileOperation operation = new RenameRemoteFileOperation(mFile.getFileName(), mFile.getRemotePath(), mNewName, - mNewRemotePath, mFile.isFolder()); + mNewRemotePath); result = operation.execute(client); if (result.isSuccess()) { diff --git a/src/com/owncloud/android/ui/activity/FileDisplayActivity.java b/src/com/owncloud/android/ui/activity/FileDisplayActivity.java index 199f8c23..2ec9f2e2 100644 --- a/src/com/owncloud/android/ui/activity/FileDisplayActivity.java +++ b/src/com/owncloud/android/ui/activity/FileDisplayActivity.java @@ -1375,6 +1375,9 @@ OCFileListFragment.ContainerActivity, FileDetailFragment.ContainerActivity, OnNa Toast msg = Toast.makeText(this, R.string.rename_local_fail_msg, Toast.LENGTH_LONG); msg.show(); // TODO throw again the new rename dialog + } if (result.getCode().equals(ResultCode.INVALID_CHARACTER_IN_NAME)) { + Toast msg = Toast.makeText(this, R.string.create_dir_fail_msg_invalid_characters, Toast.LENGTH_LONG); + msg.show(); } else { Toast msg = Toast.makeText(this, R.string.rename_server_fail_msg, Toast.LENGTH_LONG); msg.show(); diff --git a/src/com/owncloud/android/ui/fragment/FileDetailFragment.java b/src/com/owncloud/android/ui/fragment/FileDetailFragment.java index 01ef8d07..66febdf4 100644 --- a/src/com/owncloud/android/ui/fragment/FileDetailFragment.java +++ b/src/com/owncloud/android/ui/fragment/FileDetailFragment.java @@ -816,6 +816,9 @@ public class FileDetailFragment extends FileFragment implements Toast msg = Toast.makeText(getActivity(), R.string.rename_local_fail_msg, Toast.LENGTH_LONG); msg.show(); // TODO throw again the new rename dialog + } if (result.getCode().equals(ResultCode.INVALID_CHARACTER_IN_NAME)) { + Toast msg = Toast.makeText(getActivity(), R.string.create_dir_fail_msg_invalid_characters, Toast.LENGTH_LONG); + msg.show(); } else { Toast msg = Toast.makeText(getActivity(), R.string.rename_server_fail_msg, Toast.LENGTH_LONG); msg.show();