aboutsummaryrefslogtreecommitdiff
path: root/js/io/system
diff options
context:
space:
mode:
authorJose Antonio Marquez2012-01-27 12:05:17 -0800
committerJose Antonio Marquez2012-01-27 12:05:17 -0800
commit3a754133dbc138390503341fd2e9beba3e43aa4b (patch)
treecdeae7d7dd9a30d7b4fab5afb7efad68d4ec7508 /js/io/system
parentb89a7ee8b956c96a1dcee995ea840feddc5d4b27 (diff)
downloadninja-3a754133dbc138390503341fd2e9beba3e43aa4b.tar.gz
Merged old FileIO
Diffstat (limited to 'js/io/system')
-rw-r--r--js/io/system/config.xml6
-rwxr-xr-x[-rw-r--r--]js/io/system/coreioapi.js (renamed from js/io/system/shellapi.js)191
-rwxr-xr-x[-rw-r--r--]js/io/system/fileio.js0
-rwxr-xr-x[-rw-r--r--]js/io/system/filesystem.js78
-rwxr-xr-x[-rw-r--r--]js/io/system/projectio.js0
5 files changed, 137 insertions, 138 deletions
diff --git a/js/io/system/config.xml b/js/io/system/config.xml
deleted file mode 100644
index 4660d647..00000000
--- a/js/io/system/config.xml
+++ /dev/null
@@ -1,6 +0,0 @@
1<?xml version="1.0" encoding="UTF-8"?>
2<!-- COPY TO 'MainApp/cloud' and set your own URLs -->
3<services>
4 <file><![CDATA[http://file.services.ninja.motorola.com/]]></file>
5 <directory><![CDATA[http://directory.services.ninja.motorola.com/]]></directory>
6</services>
diff --git a/js/io/system/shellapi.js b/js/io/system/coreioapi.js
index 9976dbed..c920d8cd 100644..100755
--- a/js/io/system/shellapi.js
+++ b/js/io/system/coreioapi.js
@@ -6,104 +6,26 @@ No rights, expressed or implied, whatsoever to this software are provided by Mot
6 6
7/* ///////////////////////////////////////////////////////////////////// 7/* /////////////////////////////////////////////////////////////////////
8//////////////////////////////////////////////////////////////////////// 8////////////////////////////////////////////////////////////////////////
9NOTES: All logic should be handled in the FileSystem and I/O classes 9NOTES:
10 10These methods should only be access through the file and project IO classes.
11Dialog methods on NativeShellApp
12ShowFileOpenDialog(initialDir) - shows a file open dialog
13initialDir is optional and if specified will cause the dialog to initially display that directory as the open location
14ShowFileSaveAsDialog(initialURI) - shows a file Save As dialog
15initialURI is optional and if specified will cause the dialog to initially display the directory as the default location
16and the filename as the current filename.
17ShowSelectDirectoryDialog(initialDir, dialogTitle) - displays a directory select/chooser dialog
18intitalDir is optional and specifies the directory that should be selected/shown when the dialog opens
19dialogTitle is optional and specifies the title that should appear in the dialog caption
20//////////////////////////////////////////////////////////////////////// 11////////////////////////////////////////////////////////////////////////
21///////////////////////////////////////////////////////////////////// */ 12///////////////////////////////////////////////////////////////////// */
13var Montage = require("montage/core/core").Montage,
14 Component = require("montage/ui/component").Component;
15////////////////////////////////////////////////////////////////////////
22//Exporting as Project I/O 16//Exporting as Project I/O
23exports.ShellApi = (require("montage/core/core").Montage).create(require("montage/ui/component").Component, { 17exports.CoreIoApi = Montage.create(Component, {
24 ////////////////////////////////////////////////////////////////////
25 //
26 init: {
27 enumerable: false,
28 value: function() {
29 try {
30 var xhr = new XMLHttpRequest(), file, directory;
31 //
32 xhr.open("GET", 'cloud/config.xml', false);
33 xhr.send();
34 //
35 if (xhr.readyState === 4) {
36 file = xhr.responseXML.getElementsByTagName('file')[0].firstChild.nodeValue;
37 directory = xhr.responseXML.getElementsByTagName('directory')[0].firstChild.nodeValue;
38 if (file.length)
39 this._fileServiceURL = file;
40 if (directory.length)
41 this._directoryServiceURL = directory;
42 //
43 //console.log(file, directory);
44 }
45 }
46 catch(error) {
47 console.log(error);
48 }
49 }
50 },
51 ////////////////////////////////////////////////////////////////////
52 //
53 openShellDialog: {
54 enumerable: false,
55 value: function(dialog) {
56 //Initializing return variable
57 var input = null;
58 //Checking for the type of prompt set via object
59 switch (dialog.type) {
60 case 'file':
61 //Checking for action the prompt will ask the user
62 if (dialog.action.toLowerCase() == 'open') {
63 //File open dialog
64 input = window.NativeShellApp.ShowFileOpenDialog();
65 } else if (dialog.action.toLowerCase() == 'new') {
66 //File new dialog
67 input = window.NativeShellApp.ShowFileSaveAsDialog();
68 }
69 break;
70 case 'directory':
71 //Checking for action the prompt will ask the user
72 if (dialog.action.toLowerCase() == 'open') {
73 //Directory open dialog
74 input = window.NativeShellApp.ShowSelectDirectoryDialog();
75 } else if (dialog.action.toLowerCase() == 'new') {
76 //Directory new dialog
77 input = window.NativeShellApp.ShowSelectDirectoryDialog();
78 }
79 break;
80 break;
81 default:
82 break;
83 }
84 return input;
85 }
86 },
87 ////////////////////////////////////////////////////////////////////
88 //
89 startServer: {
90 enumerable: false,
91 value: function (dir) {
92 var server = window.NativeShellApp.StartWebServer(dir);
93 return server;
94 }
95 },
96 //////////////////////////////////////////////////////////////////// 18 ////////////////////////////////////////////////////////////////////
97 // private property containing the file service URL to use for all file IO calls 19 // private property containing the file service URL to use for all file IO calls
98 _fileServiceURL: { 20 _fileServiceURL: {
99 enumerable: false, 21 enumerable: false,
100 value: "http://localhost:16380/file" //default value.. updated with base uri in config.xml 22 value: "http://localhost:16380/file"
101 }, 23 },
102 //////////////////////////////////////////////////////////////////// 24 ////////////////////////////////////////////////////////////////////
103 // private property containing the directory service URL to use for all file IO calls 25 // private property containing the directory service URL to use for all file IO calls
104 _directoryServiceURL: { 26 _directoryServiceURL: {
105 enumerable: false, 27 enumerable: false,
106 value: "http://localhost:16380/directory" //default value.. updated with base uri in config.xml 28 value: "http://localhost:16380/directory"
107 }, 29 },
108 //////////////////////////////////////////////////////////////////// 30 ////////////////////////////////////////////////////////////////////
109 // private helper to parse URIs and append them to the service URL 31 // private helper to parse URIs and append them to the service URL
@@ -117,6 +39,11 @@ exports.ShellApi = (require("montage/core/core").Montage).create(require("montag
117 if((urlOut.length > 0) && (urlOut.charAt(0) !== "/")){ 39 if((urlOut.length > 0) && (urlOut.charAt(0) !== "/")){
118 urlOut = "/" + urlOut; 40 urlOut = "/" + urlOut;
119 } 41 }
42 //remove extra / at the end
43 if((urlOut.length > 1) && (urlOut.charAt(urlOut.length - 1) === "/")){
44 urlOut = urlOut.substring(0, (urlOut.length - 1));
45 }
46
120 return serviceURL + urlOut; 47 return serviceURL + urlOut;
121 } 48 }
122 }, 49 },
@@ -413,7 +340,7 @@ exports.ShellApi = (require("montage/core/core").Montage).create(require("montag
413 enumerable: false, 340 enumerable: false,
414 value: function(file) { 341 value: function(file) {
415 // 342 //
416 var retValue = { success:null, content:null, status:null }; 343 var retValue = { success:null, content:null, status:null};
417 // 344 //
418 if(file && file.uri && file.uri.length) { 345 if(file && file.uri && file.uri.length) {
419 try { 346 try {
@@ -736,7 +663,7 @@ exports.ShellApi = (require("montage/core/core").Montage).create(require("montag
736 writable:false, 663 writable:false,
737 value:function(file, lastQueriedTimestamp){ 664 value:function(file, lastQueriedTimestamp){
738 var retValue = { success:null, status:null }; 665 var retValue = { success:null, status:null };
739 if(file && file.uri) { 666 if(file && file.uri && (typeof lastQueriedTimestamp !== "undefined")) {
740 try { 667 try {
741 var serviceURL = this._prepareServiceURL(this._fileServiceURL, file.uri), 668 var serviceURL = this._prepareServiceURL(this._fileServiceURL, file.uri),
742 xhr = new XMLHttpRequest(); 669 xhr = new XMLHttpRequest();
@@ -778,7 +705,7 @@ exports.ShellApi = (require("montage/core/core").Montage).create(require("montag
778 writable:false, 705 writable:false,
779 value:function(file, lastQueriedTimestamp){ 706 value:function(file, lastQueriedTimestamp){
780 var retValue = { success:null, status:null }; 707 var retValue = { success:null, status:null };
781 if(file && file.uri) { 708 if(file && file.uri && (typeof lastQueriedTimestamp !== "undefined")) {
782 try { 709 try {
783 var serviceURL = this._prepareServiceURL(this._directoryServiceURL, file.uri), 710 var serviceURL = this._prepareServiceURL(this._directoryServiceURL, file.uri),
784 xhr = new XMLHttpRequest(); 711 xhr = new XMLHttpRequest();
@@ -797,6 +724,92 @@ exports.ShellApi = (require("montage/core/core").Montage).create(require("montag
797 } 724 }
798 return retValue; 725 return retValue;
799 } 726 }
727 },
728
729 ////////////////////////////////////////////////////////////////////
730 // Checks if the file is writable
731 // Parameters:
732 // the file parameter must contain the following properties
733 // uri: string value containing the full file path/URI i.e. "c:/foo/bar.html"
734 //
735 // Return values:
736 // returns an object with two properties
737 // success: boolean indicating if the call succeeded or failed
738 // status: int indicating the request HTTP status code
739 // 204 - The file exists and response body has writable flag
740 // 404 - the file does not exist
741 // 500 - unknown server error occurred
742 //TODO:to be finalized
743 isFileWritable:{
744 enumerable:true,
745 writable:false,
746 value:function(file){
747 var retValue = { success:null, status:null };
748 if(file && file.uri) {
749 try {
750 var serviceURL = this._prepareServiceURL(this._fileServiceURL, file.uri),
751 xhr = new XMLHttpRequest();
752 xhr.open("GET", serviceURL, false);
753 xhr.setRequestHeader("get-attributes", "true");
754 xhr.send();
755 if (xhr.readyState === 4) {
756 retValue.status = xhr.status;
757 if(xhr.status == 200) {
758 retValue.content = xhr.responseText;
759 }
760 retValue.success = true;
761 }