192c267b1ed4fa967438c7541e4a15e5169bd733
[pub/Android/ownCloud.git] / oc_framework / src / com / owncloud / android / oc_framework / utils / FileUtils.java
1 /* ownCloud Android client application
2 * Copyright (C) 2012-2013 ownCloud Inc.
3 *
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2,
6 * as published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 */
17
18 package com.owncloud.android.oc_framework.utils;
19
20 import java.io.File;
21
22 import android.util.Log;
23
24 public class FileUtils {
25
26 public static final String PATH_SEPARATOR = "/";
27
28
29 public static String getParentPath(String remotePath) {
30 String parentPath = new File(remotePath).getParent();
31 parentPath = parentPath.endsWith(PATH_SEPARATOR) ? parentPath : parentPath + PATH_SEPARATOR;
32 return parentPath;
33 }
34
35 /**
36 * Validate the fileName to detect if contains any forbidden character: / , \ , < , > , : , " , | , ? , *
37 * @param fileName
38 * @return
39 */
40 public static boolean isValidName(String fileName) {
41 boolean result = true;
42
43 Log.d("FileUtils", "fileName =======" + fileName);
44 if (fileName.contains(PATH_SEPARATOR) ||
45 fileName.contains("\\") || fileName.contains("<") || fileName.contains(">") ||
46 fileName.contains(":") || fileName.contains("\"") || fileName.contains("|") ||
47 fileName.contains("?") || fileName.contains("*")) {
48 result = false;
49 }
50 return result;
51 }
52
53 /**
54 * Validate the path to detect if contains any forbidden character: \ , < , > , : , " , | , ? , *
55 * @param path
56 * @return
57 */
58 public static boolean isValidPath(String path) {
59 boolean result = true;
60
61 Log.d("FileUtils", "path ....... " + path);
62 if (path.contains("\\") || path.contains("<") || path.contains(">") ||
63 path.contains(":") || path.contains("\"") || path.contains("|") ||
64 path.contains("?") || path.contains("*")) {
65 result = false;
66 }
67 return result;
68 }
69
70
71 }