aboutsummaryrefslogtreecommitdiff
path: root/js/io/utils
diff options
context:
space:
mode:
Diffstat (limited to 'js/io/utils')
-rw-r--r--js/io/utils/file-utils.js75
1 files changed, 75 insertions, 0 deletions
diff --git a/js/io/utils/file-utils.js b/js/io/utils/file-utils.js
new file mode 100644
index 00000000..c43fb41c
--- /dev/null
+++ b/js/io/utils/file-utils.js
@@ -0,0 +1,75 @@
1/* <copyright>
2This file contains proprietary software owned by Motorola Mobility, Inc.<br/>
3No rights, expressed or implied, whatsoever to this software are provided by Motorola Mobility, Inc. hereunder.<br/>
4(c) Copyright 2011 Motorola Mobility, Inc. All Rights Reserved.
5</copyright> */
6
7var fileSystem = require("js/io/system/filesystem").FileSystem;
8
9var FileUtils = exports.FileUtils = Object.create(Object.prototype, {
10
11 /***
12 * checks for valid uri pattern
13 * also flags if Windows uri pattern and Unix uri patterns are mixed
14 */
15 isValidUri:{
16 value: function(uri){
17 var isWindowsUri=false, isUnixUri=false,status=false;
18 if(uri !== ""){
19 uri = uri.replace(/^\s+|\s+$/g,""); // strip any leading or trailing spaces
20
21 //for local machine folder uri
22 isWindowsUri = /^([a-zA-Z]:)(\\[^<>:"/\\|?*]+)*\\?$/gi.test(uri);
23 isUnixUri = /^(\/)?(\/(?![.])[^/]*)*\/?$/gi.test(uri);//folders beginning with . are hidden on Mac / Unix
24 status = isWindowsUri || isUnixUri;
25 if(isWindowsUri && isUnixUri){status = false;}
26 }
27 return status;
28 }
29 },
30
31 /***
32 * file name validation
33 */
34 isValidFileName:{
35 value: function(fileName){
36 var status = false;
37 if(fileName !== ""){
38 fileName = fileName.replace(/^\s+|\s+$/g,"");
39 status = !(/[/\\]/g.test(fileName));
40 if(status && navigator.userAgent.indexOf("Macintosh") != -1){//for Mac files beginning with . are hidden
41 status = !(/^\./g.test(fileName));
42 }
43 }
44 return status;
45 }
46 },
47
48 /***
49 * check if the file exists
50 */
51 checkFileExists:{
52 value: function(fileUri, folderUri, fileType){
53 var uri = "", response=null, status=true;
54
55 //prepare absolute uri
56 if(/[^/\\]$/g.test(folderUri)){
57 folderUri = folderUri + "/";
58 }
59
60 //todo:add file extension check if fileType present
61
62 uri = ""+folderUri+fileUri;
63
64 response = fileSystem.shellApiHandler.fileExists({"uri":uri});
65 if(!!response && response.success && (response.status === 204)){
66 status = true;
67 }else if(!!response && response.success && (response.status === 404)){
68 status = false;
69 }else{
70 status = false;
71 }
72 return status;
73 }
74 }
75}); \ No newline at end of file