1f81f46ac1c5744355344c2e7c191eaa54782014
[pub/Android/ownCloud.git] / oc_framework / src / com / owncloud / android / oc_framework / utils / FileUtils.java
1 /* ownCloud webDAV Library for Android is available under MIT license
2 * Copyright (C) 2014 ownCloud (http://www.owncloud.org/)
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a copy
5 * of this software and associated documentation files (the "Software"), to deal
6 * in the Software without restriction, including without limitation the rights
7 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 * copies of the Software, and to permit persons to whom the Software is
9 * furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
13 *
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
18 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
19 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21 * THE SOFTWARE.
22 *
23 */
24
25 package com.owncloud.android.oc_framework.utils;
26
27 import java.io.File;
28
29 import android.util.Log;
30
31 public class FileUtils {
32
33 public static final String PATH_SEPARATOR = "/";
34
35
36 public static String getParentPath(String remotePath) {
37 String parentPath = new File(remotePath).getParent();
38 parentPath = parentPath.endsWith(PATH_SEPARATOR) ? parentPath : parentPath + PATH_SEPARATOR;
39 return parentPath;
40 }
41
42 /**
43 * Validate the fileName to detect if contains any forbidden character: / , \ , < , > , : , " , | , ? , *
44 * @param fileName
45 * @return
46 */
47 public static boolean isValidName(String fileName) {
48 boolean result = true;
49
50 Log.d("FileUtils", "fileName =======" + fileName);
51 if (fileName.contains(PATH_SEPARATOR) ||
52 fileName.contains("\\") || fileName.contains("<") || fileName.contains(">") ||
53 fileName.contains(":") || fileName.contains("\"") || fileName.contains("|") ||
54 fileName.contains("?") || fileName.contains("*")) {
55 result = false;
56 }
57 return result;
58 }
59
60 /**
61 * Validate the path to detect if contains any forbidden character: \ , < , > , : , " , | , ? , *
62 * @param path
63 * @return
64 */
65 public static boolean isValidPath(String path) {
66 boolean result = true;
67
68 Log.d("FileUtils", "path ....... " + path);
69 if (path.contains("\\") || path.contains("<") || path.contains(">") ||
70 path.contains(":") || path.contains("\"") || path.contains("|") ||
71 path.contains("?") || path.contains("*")) {
72 result = false;
73 }
74 return result;
75 }
76
77
78 }