OC-2067: Adapt CreateRemoteFolderOperation, new class FileUtils.java. Try to create...
authormasensio <masensio@solidgear.es>
Thu, 14 Nov 2013 08:27:34 +0000 (09:27 +0100)
committermasensio <masensio@solidgear.es>
Thu, 14 Nov 2013 08:27:34 +0000 (09:27 +0100)
oc_framework-test-project/oc_framework-test-test/src/com/owncloud/android/oc_framework_test_project/test/CreateFolderTest.java
oc_framework/src/com/owncloud/android/oc_framework/utils/FileUtils.java [new file with mode: 0644]
res/values/strings.xml
src/com/owncloud/android/ui/activity/FileDisplayActivity.java
tests/.classpath

index 2ec2d3a..667f7eb 100644 (file)
@@ -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;
                
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
new file mode 100644 (file)
index 0000000..1fafd89
--- /dev/null
@@ -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;
+       }
+}
index 4f75db1..21699cf 100644 (file)
     <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>
index 13646e8..37455d2 100644 (file)
@@ -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);
             }
+            }
         }
     }
 
index 0e30785..794d0d9 100644 (file)
@@ -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>