aboutsummaryrefslogtreecommitdiff
path: root/js/io/utils/file-utils.js
diff options
context:
space:
mode:
Diffstat (limited to 'js/io/utils/file-utils.js')
-rw-r--r--js/io/utils/file-utils.js73
1 files changed, 73 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..0a4d9687
--- /dev/null
+++ b/js/io/utils/file-utils.js
@@ -0,0 +1,73 @@
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 FileUtils = exports.FileUtils = Object.create(Object.prototype, {
8
9 /***
10 * checks for valid uri pattern
11 * also flags if Windows uri pattern and Unix uri patterns are mixed
12 */
13 isValidUri:{
14 value: function(uri){
15 var isWindowsUri=false, isUnixUri=false,status=false;
16 if(uri !== ""){
17 uri = uri.replace(/^\s+|\s+$/g,""); // strip any leading or trailing spaces
18
19 //for local machine folder uri
20 isWindowsUri = /^([a-zA-Z]:)(\\[^<>:"/\\|?*]+)*\\?$/gi.test(uri);
21 isUnixUri = /^(\/)?(\/(?![.])[^/]*)*\/?$/gi.test(uri);//folders beginning with . are hidden on Mac / Unix
22 status = isWindowsUri || isUnixUri;
23 if(isWindowsUri && isUnixUri){status = false;}
24 }
25 return status;
26 }
27 },
28
29 /***
30 * file name validation
31 */
32 isValidFileName:{
33 value: function(fileName){
34 var status = false;
35 if(fileName !== ""){
36 fileName = fileName.replace(/^\s+|\s+$/g,"");
37 status = !(/[/\\]/g.test(fileName));
38 if(status && navigator.userAgent.indexOf("Macintosh") != -1){//for Mac files beginning with . are hidden
39 status = !(/^\./g.test(fileName));
40 }
41 }
42 return status;
43 }
44 },
45
46 /***
47 * check if the file exists
48 */
49 checkFileExists:{
50 value: function(fileUri, folderUri, fileType){
51 var uri = "", response=null, status=true;
52
53 //prepare absolute uri
54 if(/[^/\\]$/g.test(folderUri)){
55 folderUri = folderUri + "/";
56 }
57
58 //todo:add file extension check if fileType present
59
60 uri = ""+folderUri+fileUri;
61
62 response = this.application.ninja.coreIoApi.fileExists({"uri":uri});
63 if(!!response && response.success && (response.status === 204)){
64 status = true;
65 }else if(!!response && response.success && (response.status === 404)){
66 status = false;
67 }else{
68 status = false;
69 }
70 return status;
71 }
72 }
73}); \ No newline at end of file