e4f10bb59a63d6981f3011ae16cfa7af409ebd13
[pub/Android/ownCloud.git] / oc_framework / src / com / owncloud / android / oc_framework / utils / FileUtils.java
1 package com.owncloud.android.oc_framework.utils;
2
3 import java.io.File;
4
5 import android.util.Log;
6
7 public class FileUtils {
8
9 public static final String PATH_SEPARATOR = "/";
10
11
12 public static String getParentPath(String remotePath) {
13 String parentPath = new File(remotePath).getParent();
14 parentPath = parentPath.endsWith(PATH_SEPARATOR) ? parentPath : parentPath + PATH_SEPARATOR;
15 return parentPath;
16 }
17
18 /**
19 * Validate the fileName to detect if contains any forbidden character: / , \ , < , > , : , " , | , ? , *
20 * @param fileName
21 * @return
22 */
23 public static boolean validateName(String fileName) {
24 boolean result = true;
25
26 Log.d("FileUtils", "fileName =======" + fileName);
27 if (fileName.contains(PATH_SEPARATOR) ||
28 fileName.contains("\\") || fileName.contains("<") || fileName.contains(">") ||
29 fileName.contains(":") || fileName.contains("\"") || fileName.contains("|") ||
30 fileName.contains("?") || fileName.contains("*")) {
31 result = false;
32 }
33 return result;
34 }
35
36 /**
37 * Validate the path to detect if contains any forbidden character: \ , < , > , : , " , | , ? , *
38 * @param path
39 * @return
40 */
41 public static boolean validatePath(String path) {
42 boolean result = true;
43
44 Log.d("FileUtils", "path ....... " + path);
45 if (path.contains("\\") || path.contains("<") || path.contains(">") ||
46 path.contains(":") || path.contains("\"") || path.contains("|") ||
47 path.contains("?") || path.contains("*")) {
48 result = false;
49 }
50 return result;
51 }
52 }