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