From 92161460a6cbbdebfd1b0263ec6eb790091920a9 Mon Sep 17 00:00:00 2001 From: Ananya Sen Date: Mon, 30 Jan 2012 14:18:21 -0800 Subject: Moving changes from Gerrit, on 1/27, to the github branch: - added file existence check and validation to save as dialog - minor css fix for file picker, new file dialog Signed-off-by: Ananya Sen --- js/io/utils/file-utils.js | 75 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 75 insertions(+) create mode 100644 js/io/utils/file-utils.js (limited to 'js/io/utils') 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 @@ +/* +This file contains proprietary software owned by Motorola Mobility, Inc.
+No rights, expressed or implied, whatsoever to this software are provided by Motorola Mobility, Inc. hereunder.
+(c) Copyright 2011 Motorola Mobility, Inc. All Rights Reserved. +
*/ + +var fileSystem = require("js/io/system/filesystem").FileSystem; + +var FileUtils = exports.FileUtils = Object.create(Object.prototype, { + + /*** + * checks for valid uri pattern + * also flags if Windows uri pattern and Unix uri patterns are mixed + */ + isValidUri:{ + value: function(uri){ + var isWindowsUri=false, isUnixUri=false,status=false; + if(uri !== ""){ + uri = uri.replace(/^\s+|\s+$/g,""); // strip any leading or trailing spaces + + //for local machine folder uri + isWindowsUri = /^([a-zA-Z]:)(\\[^<>:"/\\|?*]+)*\\?$/gi.test(uri); + isUnixUri = /^(\/)?(\/(?![.])[^/]*)*\/?$/gi.test(uri);//folders beginning with . are hidden on Mac / Unix + status = isWindowsUri || isUnixUri; + if(isWindowsUri && isUnixUri){status = false;} + } + return status; + } + }, + + /*** + * file name validation + */ + isValidFileName:{ + value: function(fileName){ + var status = false; + if(fileName !== ""){ + fileName = fileName.replace(/^\s+|\s+$/g,""); + status = !(/[/\\]/g.test(fileName)); + if(status && navigator.userAgent.indexOf("Macintosh") != -1){//for Mac files beginning with . are hidden + status = !(/^\./g.test(fileName)); + } + } + return status; + } + }, + + /*** + * check if the file exists + */ + checkFileExists:{ + value: function(fileUri, folderUri, fileType){ + var uri = "", response=null, status=true; + + //prepare absolute uri + if(/[^/\\]$/g.test(folderUri)){ + folderUri = folderUri + "/"; + } + + //todo:add file extension check if fileType present + + uri = ""+folderUri+fileUri; + + response = fileSystem.shellApiHandler.fileExists({"uri":uri}); + if(!!response && response.success && (response.status === 204)){ + status = true; + }else if(!!response && response.success && (response.status === 404)){ + status = false; + }else{ + status = false; + } + return status; + } + } +}); \ No newline at end of file -- cgit v1.2.3