Browse Source

OC-2067: Adapt CreateRemoteFolderOperation, new class FileUtils.java. Try to create folder with invalid characters return an error message

masensio 11 years ago
parent
commit
3ee1c51039

+ 11 - 0
oc_framework-test-project/oc_framework-test-test/src/com/owncloud/android/oc_framework_test_project/test/CreateFolderTest.java

@@ -9,6 +9,11 @@ import com.owncloud.android.oc_framework_test_project.TestActivity;
 
 import android.test.ActivityInstrumentationTestCase2;
 
+/**
+ * Class to test Create Folder Operation
+ * @author masensio
+ *
+ */
 public class CreateFolderTest extends ActivityInstrumentationTestCase2<TestActivity> {
 
 	private TestActivity mActivity;
@@ -28,6 +33,9 @@ public class CreateFolderTest extends ActivityInstrumentationTestCase2<TestActiv
 	    mActivity = getActivity();
 	}
 	
+	/**
+	 * Test Create Folder
+	 */
 	public void testCreateFolder() {
 
 		String remotePath = "/testCreateFolder" + mCurrentDate;
@@ -37,6 +45,9 @@ public class CreateFolderTest extends ActivityInstrumentationTestCase2<TestActiv
 		assertTrue(result.isSuccess() || result.getCode() == ResultCode.TIMEOUT);
 	}
 	
+	/**
+	 * Test to Create Folder with special characters
+	 */
 	public void testCreateFolderSpecialCharacters() {		
 		boolean createFullPath = true;
 		

+ 36 - 0
oc_framework/src/com/owncloud/android/oc_framework/utils/FileUtils.java

@@ -0,0 +1,36 @@
+package com.owncloud.android.oc_framework.utils;
+
+import java.io.File;
+
+import android.util.Log;
+
+public class FileUtils {
+
+	public static final String PATH_SEPARATOR = "/";
+
+
+	public static String getParentPath(String remotePath) {
+		String parentPath = new File(remotePath).getParent();
+		parentPath = parentPath.endsWith(PATH_SEPARATOR) ? parentPath : parentPath + PATH_SEPARATOR;
+		return parentPath;
+	}
+	
+	/**
+	 * Validate the fileName to detect if contains any forbidden character: / , \ , < , > , : , " , | , ? , *
+	 * @param fileName
+	 * @return
+	 */
+	public static boolean validateName(String fileName) {
+		boolean result = true;
+		
+		Log.d("FileUtils", "fileName =======" + fileName);
+		String name = fileName.substring(1);
+		if ((fileName.indexOf("/") > 0 && name.indexOf("/") < (name.length() - 1 ) ) || 
+				fileName.contains("\\") || fileName.contains("<") || fileName.contains(">") ||
+				fileName.contains(":") || fileName.contains("\"") || fileName.contains("|") || 
+				fileName.contains("?") || fileName.contains("*")) {
+			result = false;
+		}
+		return result;
+	}
+}

+ 1 - 0
res/values/strings.xml

@@ -182,6 +182,7 @@
     <string name="sync_file_fail_msg">Remote file could not be checked</string>
     <string name="sync_file_nothing_to_do_msg">File contents already synchronized</string>
     <string name="create_dir_fail_msg">Directory could not be created</string>
+    <string name="create_dir_fail_msg_invalid_characters">Invalid character in foldername: /  \\  &lt;  &gt;  :  "  |  ?  *</string>
     <string name="wait_a_moment">Wait a moment</string>
     <string name="filedisplay_unexpected_bad_get_content">"Unexpected problem ; please select the file from a different app"</string>
     <string name="filedisplay_no_file_selected">No file was selected</string>

+ 4 - 1
src/com/owncloud/android/ui/activity/FileDisplayActivity.java

@@ -31,7 +31,6 @@ import android.content.Context;
 import android.content.DialogInterface;
 import android.content.Intent;
 import android.content.IntentFilter;
-import android.content.IntentFilter.AuthorityEntry;
 import android.content.ServiceConnection;
 import android.content.SharedPreferences;
 import android.content.SyncRequest;
@@ -1335,6 +1334,9 @@ OCFileListFragment.ContainerActivity, FileDetailFragment.ContainerActivity, OnNa
 
         } else {
             dismissLoadingDialog();
+            if (result.getCode() == ResultCode.INVALID_CHARACTER_IN_NAME) {
+                Toast.makeText(FileDisplayActivity.this, R.string.create_dir_fail_msg_invalid_characters, Toast.LENGTH_LONG).show();
+            } else {
             try {
                 Toast msg = Toast.makeText(FileDisplayActivity.this, R.string.create_dir_fail_msg, Toast.LENGTH_LONG); 
                 msg.show();
@@ -1342,6 +1344,7 @@ OCFileListFragment.ContainerActivity, FileDetailFragment.ContainerActivity, OnNa
             } catch (NotFoundException e) {
                 Log_OC.e(TAG, "Error while trying to show fail message " , e);
             }
+            }
         }
     }
 

+ 3 - 0
tests/.classpath

@@ -1,5 +1,8 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <classpath>
 	<classpathentry combineaccessrules="false" kind="src" path="/owncloud-android"/>
+	<classpathentry kind="con" path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/>
+	<classpathentry exported="true" kind="con" path="com.android.ide.eclipse.adt.LIBRARIES"/>
+	<classpathentry exported="true" kind="con" path="com.android.ide.eclipse.adt.DEPENDENCIES"/>
 	<classpathentry kind="output" path="bin/classes"/>
 </classpath>