1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
|
/* <copyright>
This file contains proprietary software owned by Motorola Mobility, Inc.<br/>
No rights, expressed or implied, whatsoever to this software are provided by Motorola Mobility, Inc. hereunder.<br/>
(c) Copyright 2011 Motorola Mobility, Inc. All Rights Reserved.
</copyright> */
/* /////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////
NOTES: All logic should be handled in the FileSystem and I/O classes
Dialog methods on NativeShellApp
ShowFileOpenDialog(initialDir) - shows a file open dialog
initialDir is optional and if specified will cause the dialog to initially display that directory as the open location
ShowFileSaveAsDialog(initialURI) - shows a file Save As dialog
initialURI is optional and if specified will cause the dialog to initially display the directory as the default location
and the filename as the current filename.
ShowSelectDirectoryDialog(initialDir, dialogTitle) - displays a directory select/chooser dialog
intitalDir is optional and specifies the directory that should be selected/shown when the dialog opens
dialogTitle is optional and specifies the title that should appear in the dialog caption
////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////// */
//Exporting as Project I/O
exports.ShellApi = (require("montage/core/core").Montage).create(require("montage/ui/component").Component, {
////////////////////////////////////////////////////////////////////
//
init: {
enumerable: false,
value: function() {
try {
var xhr = new XMLHttpRequest(), file, directory;
//
xhr.open("GET", 'cloud/config.xml', false);
xhr.send();
//
if (xhr.readyState === 4) {
file = xhr.responseXML.getElementsByTagName('file')[0].firstChild.nodeValue;
directory = xhr.responseXML.getElementsByTagName('directory')[0].firstChild.nodeValue;
if (file.length)
this._fileServiceURL = file;
if (directory.length)
this._directoryServiceURL = directory;
//
//console.log(file, directory);
}
}
catch(error) {
console.log(error);
}
}
},
////////////////////////////////////////////////////////////////////
//
openShellDialog: {
enumerable: false,
value: function(dialog) {
//Initializing return variable
var input = null;
//Checking for the type of prompt set via object
switch (dialog.type) {
case 'file':
//Checking for action the prompt will ask the user
if (dialog.action.toLowerCase() == 'open') {
//File open dialog
input = window.NativeShellApp.ShowFileOpenDialog();
} else if (dialog.action.toLowerCase() == 'new') {
//File new dialog
input = window.NativeShellApp.ShowFileSaveAsDialog();
}
break;
case 'directory':
//Checking for action the prompt will ask the user
if (dialog.action.toLowerCase() == 'open') {
//Directory open dialog
input = window.NativeShellApp.ShowSelectDirectoryDialog();
} else if (dialog.action.toLowerCase() == 'new') {
//Directory new dialog
input = window.NativeShellApp.ShowSelectDirectoryDialog();
}
break;
break;
default:
break;
}
return input;
}
},
////////////////////////////////////////////////////////////////////
//
startServer: {
enumerable: false,
value: function (dir) {
var server = window.NativeShellApp.StartWebServer(dir);
return server;
}
},
////////////////////////////////////////////////////////////////////
// private property containing the file service URL to use for all file IO calls
_fileServiceURL: {
enumerable: false,
value: "http://localhost:16380/file" //default value.. updated with base uri in config.xml
},
////////////////////////////////////////////////////////////////////
// private property containing the directory service URL to use for all file IO calls
_directoryServiceURL: {
enumerable: false,
value: "http://localhost:16380/directory" //default value.. updated with base uri in config.xml
},
////////////////////////////////////////////////////////////////////
// private helper to parse URIs and append them to the service URL
_prepareServiceURL: {
enumerable: false,
value: function(serviceURL, path) {
var urlOut = path.replace(/\\/g,"/");
urlOut = urlOut.replace(/:/g,"");
urlOut = encodeURI(urlOut);
//add leading / if not already there
if((urlOut.length > 0) && (urlOut.charAt(0) !== "/")){
urlOut = "/" + urlOut;
}
return serviceURL + urlOut;
}
},
////////////////////////////////////////////////////////////////////
// Checks for the existence of a file
// Parameters:
// the file parameter must contain the following properties
// uri: string value containing the full file path/URI i.e. "c:/foo/bar.html"
//
// Return values:
// returns an object with two properties
// success: boolean indicating if the call succeeded or failed
// status: int indicating the request HTTP status code
// 204 - the file exists
// 404 - the file does not exist
// 500 - unknown server error occurred
fileExists: {
enumerable: false,
value: function(file) {
//
var retValue = { success:null, status:null };
//
if(file && file.uri && file.uri.length) {
try {
var serviceURL = this._prepareServiceURL(this._fileServiceURL, file.uri),
xhr = new XMLHttpRequest();
//
xhr.open("GET", serviceURL, false);
xhr.setRequestHeader("check-existence-only", "true");
xhr.send();
//
if (xhr.readyState === 4) {
retValue.status = xhr.status;
retValue.success = true;
}
}
catch(error) {
xhr = null;
retValue.success = false;
}
}
//
return retValue;
}
},
////////////////////////////////////////////////////////////////////
// Creates a new file at the specified path
// Parameters:
// the file parameter must contain the following properties
// uri: string value containing the full file path/URI i.e. "c:/foo/bar.html"
// it can optionally contain the following properties
// contentType: string with the content type i.e. "text/plain". "text/plain" is assumed if this property is not specified
// contents: string containing the file contents. These contents will be saved to the new file.
//
// Return values:
// returns an object with two properties
// success: boolean indicating if the call succeeded or failed
// status: int indicating the request HTTP status code
// 201 - the file was created and contents were saved if they were passed
// 400 - the file already exists and could not be created
// 500 - unknown server error occurred
createFile: {
enumerable: false,
value: function(file) {
var retValue = { success:null, status:null };
if(file && file.uri && file.uri.length) {
try {
var serviceURL = this._prepareServiceURL(this._fileServiceURL, file.uri),
xhr = new XMLHttpRequest();
//
xhr.open("POST", serviceURL, false);
if(file.contentType && file.contentType.length)
xhr.setRequestHeader("Content-Type", file.contentType);
else
xhr.setRequestHeader("Content-Type", "text/plain");
if(file.contents && file.contents.length)
xhr.send(file.contents);
else
xhr.send();
if (xhr.readyState === 4) {
retValue.status = xhr.status;
retValue.success = true;
}
}
catch(error) {
xhr = null;
retValue.success = false;
}
}
return retValue;
}
},
////////////////////////////////////////////////////////////////////
// Save contents into an existing file at the specified path
// Parameters:
// the file parameter must contain the following properties
// uri: string value containing the full file path/URI i.e. "c:/foo/bar.html"
// it can optionally contain the following properties
// contentType: string with the content type i.e. "text/plain". "text/plain" is assumed if this property is not specified
// contents: string containing the file contents. These contents will be saved to the new file.
//
// Return values:
// returns an object with two properties
// success: boolean indicating if the call succeeded or failed
// status: int indicating the request HTTP status code
// 204 - the file was saved
// 404 - the file specified does not exist
// 500 - unknown server error occurred
updateFile: {
enumerable: false,
value: function(file) {
var retValue = { success:null, status:null };
if(file && file.uri && file.uri.length && file.contents && file.contents.length) {
try {
var serviceURL = this._prepareServiceURL(this._fileServiceURL, file.uri),
xhr = new XMLHttpRequest();
//
xhr.open("PUT", serviceURL, false);
if(file.contentType && file.contentType.length)
xhr.setRequestHeader("Content-Type", file.contentType);
else
xhr.setRequestHeader("Content-Type", "text/plain");
xhr.send(file.contents);
if (xhr.readyState === 4) {
retValue.status = xhr.status;
retValue.success = true;
}
}
catch(error) {
xhr = null;
retValue.success = false;
}
}
return retValue;
}
},
////////////////////////////////////////////////////////////////////
// Copies a file from one location to another
// Parameters:
// the file parameter must contain the following properties
// sourceUri: string value containing the full file path/URI to copy from i.e. "c:/foo/bar.html"
// destUri: string containing the full path/URI to copy to
// it can optionally contain the following properties
// overwriteDestination: bool indicating whether it is okay to overwrite the file specified at destUri if it already exists
//
// Return values:
// returns an object with two properties
// success: boolean indicating if the call succeeded or failed
// status: int indicating the request HTTP status code
// 204 - the file was copied
// 404 - the file specified in sourceUri does not exist
// 500 - unknown server error occurred
copyFile: {
enumerable: false,
value: function(file) {
var retValue = { success:null, status:null };
if(file && file.sourceUri && file.sourceUri.length && file.destUri && file.destUri.length) {
try {
var serviceURL = this._prepareServiceURL(this._fileServiceURL, file.destUri),
xhr = new XMLHttpRequest();
//
xhr.open("PUT", serviceURL, false);
xhr.setRequestHeader("sourceURI", file.sourceUri);
//
if(file.overwriteDestination && file.overwriteDestination === true) {
xhr.setRequestHeader("overwrite-destination", "true");
}
//
xhr.send();
//
if (xhr.readyState === 4) {
retValue.status = xhr.status;
retValue.success = true;
}
}
catch(error) {
xhr = null;
retValue.success = false;
}
}
//
return retValue;
}
},
////////////////////////////////////////////////////////////////////
// Moves a file from one location to another
// Parameters:
// the file parameter must contain the following properties
// sourceUri: string value containing the full file path/URI to copy from i.e. "c:/foo/bar.html"
// destUri: string containing the full path/URI to copy to
// it can optionally contain the following properties
// overwriteDestination: bool indicating whether it is okay to overwrite the file specified at destUri if it already exists
//
// Return values:
// returns an object with two properties
// success: boolean indicating if the call succeeded or failed
// status: int indicating the request HTTP status code
// 204 - the file was moved
// 404 - the file specified in sourceUri does not exist
// 500 - unknown server error occurred
moveFile: {
enumerable: false,
value: function(file) {
var retValue = { success:null, status:null };
if(file && file.sourceUri && file.sourceUri.length && file.destUri && file.destUri.length) {
try {
var serviceURL = this._prepareServiceURL(this._fileServiceURL, file.destUri),
xhr = new XMLHttpRequest();
//
xhr.open("PUT", serviceURL, false);
xhr.setRequestHeader("sourceURI", file.sourceUri);
xhr.setRequestHeader("delete-source", "true");
//
if(file.overwriteDestination && file.overwriteDestination === true) {
xhr.setRequestHeader("overwrite-destination", "true");
}
//
xhr.send();
//
if (xhr.readyState === 4) {
retValue.status = xhr.status;
retValue.success = true;
}
}
catch(error) {
xhr = null;
retValue.success = false;
}
}
//
return retValue;
}
},
////////////////////////////////////////////////////////////////////
// Deletes an existing file
// Parameters:
// the file parameter must contain the following properties
// uri: string value containing the full file path/URI i.e. "c:/foo/bar.html"
//
// Return values:
// returns an object with two properties
// success: boolean indicating if the call succeeded or failed
// status: int indicating the request HTTP status code
// 204 - the file was deleted
// 404 - the file does not exist
// 500 - unknown server error occurred
deleteFile: {
enumerable: false,
value: function(file) {
var retValue = { success:null, status:null };
if(file && file.uri && file.uri.length) {
try {
var serviceURL = this._prepareServiceURL(this._fileServiceURL, file.uri),
xhr = new XMLHttpRequest();
//
xhr.open("DELETE", serviceURL, false);
xhr.send();
//
if (xhr.readyState === 4) {
retValue.status = xhr.status;
retValue.success = true;
}
}
catch(error) {
xhr = null;
retValue.success = false;
}
}
//
return retValue;
}
},
////////////////////////////////////////////////////////////////////
// Reads an existing file
// Parameters:
// the file parameter must contain the following properties
// uri: string value containing the full file path/URI i.e. "c:/foo/bar.html"
//
// Return values:
// returns an object with two properties
// success: boolean indicating if the call succeeded or failed
// content: string containing the file contents
// status: int indicating the request HTTP status code
// 200 - the file was read and its contents were returned
// 404 - the file does not exist
// 500 - unknown server error occurred
openFile: {
enumerable: false,
value: function(file) {
//
var retValue = { success:null, content:null, status:null };
//
if(file && file.uri && file.uri.length) {
try {
var serviceURL = this._prepareServiceURL(this._fileServiceURL, file.uri),
xhr = new XMLHttpRequest();
//
xhr.open("GET", serviceURL, false);
xhr.send();
//
if (xhr.readyState === 4) {
retValue.status = xhr.status;
if(xhr.status == 200) {
retValue.content = xhr.responseText;
}
retValue.success = true;
}
}
catch(error) {
xhr = null;
retValue.success = false;
}
}
//
return retValue;
}
},
////////////////////////////////////////////////////////////////////
// Create a new directory/folder
// Parameters:
// the dir parameter must contain the following properties
// uri: string value containing the full file path/URI i.e. "c:/dir/subdir"
//
// Return values:
// returns an object with two properties
// success: boolean indicating if the call succeeded or failed
// status: int indicating the request HTTP status code
// 201 - the directory was created
// 400 - the directory was unable to be created
// 500 - unknown server error occurred
createDirectory: {
enumerable: false,
value: function(dir) {
var retValue = { success:null, status:null };
if(dir && dir.uri && dir.uri.length) {
try {
var serviceURL = this._prepareServiceURL(this._directoryServiceURL, dir.uri),
xhr = new XMLHttpRequest();
//
xhr.open("POST", serviceURL, false);
xhr.send();
//
if (xhr.readyState === 4) {
retValue.status = xhr.status;
retValue.success = true;
}
}
catch(error) {
xhr = null;
retValue.success = false;
}
}
//
return retValue;
}
},
////////////////////////////////////////////////////////////////////
// Delete a directory/folder
// Parameters:
// the dir parameter must contain the following properties
// uri: string value containing the full file path/URI i.e. "c:/dir/subdir"
//
// Return values:
// returns an object with two properties
// success: boolean indicating if the call succeeded or failed
// status: int indicating the request HTTP status code
// 204 - the directory was deleted
// 404 - the directory does not exist
// 500 - unknown server error occurred
deleteDirectory: {
enumerable: false,
value: function(dir) {
var retValue = { success:null, status:null };
if(dir && dir.uri && dir.uri.length) {
try {
var serviceURL = this._prepareServiceURL(this._directoryServiceURL, dir.uri),
xhr = new XMLHttpRequest();
//
xhr.open("DELETE", serviceURL, false);
xhr.send();
//
if (xhr.readyState === 4) {
retValue.status = xhr.status;
retValue.success = true;
}
}
catch(error) {
xhr = null;
retValue.success = false;
}
}
//
return retValue;
}
},
////////////////////////////////////////////////////////////////////
// List the contents of a directory/folder
// Parameters:
// the dir parameter must contain the following properties
// uri: string value containing the full file path/URI i.e. "c:/dir/subdir"
// recursive: boolean true to list contents of all subdirectories as well. if this is not specified "false" is the default.
// returnType: string "all", "files", "directories". Specifies the types to return. if this is not specified, the default is "all"
// fileFilters: string containing the file extensions to include in the return listing. This list is semi-colon separated. i.e. "xml;html"
//
// Return values:
// returns an object with two properties
// success: boolean indicating if the call succeeded or failed
// content: string containing the JSON structure of the file contents
// status: int indicating the request HTTP status code
// 200 - the directory was read and the content JSON string was returned in dir.content
// 404 - the directory does not exist
// 500 - unknown server error occurred
getDirectoryContents: {
enumerable: false,
value: function(dir) {
var retValue = { success:null, content:null, status:null };
if(!!dir && (typeof dir.uri !== "undefined") && (dir.uri !== null) ) {
try {
var serviceURL = this._prepareServiceURL(this._directoryServiceURL, dir.uri),
xhr = new XMLHttpRequest();
//
xhr.open("GET", serviceURL, false);
//
if(dir.recursive) {
xhr.setRequestHeader("recursive", dir.recursive.toString());
}
//
if (dir.fileFilters) {
xhr.setRequestHeader("file-filters", dir.fileFilters.toString());
}
//
//
if(dir.returnType) {
xhr.setRequestHeader("return-type", dir.returnType.toString());
}
//
xhr.send();
//
if (xhr.readyState === 4) {
retValue.status = xhr.status;
if(xhr.status == 200) {
retValue.content = xhr.responseText;
}
retValue.success = true;
}
}
catch(error) {
xhr = null;
retValue.success = false;
}
}
//
return retValue;
}
},
////////////////////////////////////////////////////////////////////
// Check if a directory/folder exists
// Parameters:
// the dir parameter must contain the following properties
// uri: string value containing the full file path/URI i.e. "c:/dir/subdir"
//
// Return values:
// returns an object with two properties
// success: boolean indicating if the call succeeded or failed
// status: int indicating the request HTTP status code
// 204 - the directory exists
// 404 - the directory does not exist
// 500 - unknown server error occurred
directoryExists: {
enumerable: false,
value: function(dir) {
var retValue = { success:null, content:null, status:null };
if(dir && dir.uri && dir.uri.length) {
try {
var serviceURL = this._prepareServiceURL(this._directoryServiceURL, dir.uri),
xhr = new XMLHttpRequest();
//
xhr.open("GET", serviceURL, false);
xhr.setRequestHeader("check-existence-only", "true");
//
xhr.send();
//
if (xhr.readyState === 4) {
retValue.status = xhr.status;
retValue.success = true;
}
}
catch(error) {
xhr = null;
retValue.success = false;
}
}
//
return retValue;
}
},
////////////////////////////////////////////////////////////////////
// copies an existing directory/folder to a new location
// Parameters:
// the dir parameter must contain the following properties
// sourceUri: string value containing the full file path/URI to copy from i.e. "c:/foo/bar"
// destUri: string containing the full path/URI to copy to
//
// Return values:
// returns an object with two properties
// success: boolean indicating if the call succeeded or failed
// status: int indicating the request HTTP status code
// 204 - the operation succeeded
// 400 - the operation could not be performed because the destUri existed
// 404 - the source directory does not exist
// 500 - unknown server error occurred
copyDirectory: {
enumerable: false,
value: function(dir) {
return this._copyMoveDirHelper(dir.sourceUri, dir.destUri, "copy");
}
},
////////////////////////////////////////////////////////////////////
// Moves an existing directory/folder to a new location
// Parameters:
// the dir parameter must contain the following properties
// sourceUri: string value containing the full file path/URI to copy from i.e. "c:/foo/bar"
// destUri: string containing the full path/URI to move to
//
// Return values:
// returns an object with two properties
// success: boolean indicating if the call succeeded or failed
// status: int indicating the request HTTP status code
// 204 - the operation succeeded
// 400 - the operation could not be performed because the destUri existed
// 404 - the source directory does not exist
// 500 - unknown server error occurred
moveDirectory: {
enumerable: false,
value: function(dir) {
return this._copyMoveDirHelper(dir.sourceUri, dir.destUri, "move");
}
},
////////////////////////////////////////////////////////////////////
// Moves an existing directory/folder to a new location
// Parameters:
// the dir parameter must contain the following properties
// sourceUri: string value containing the full file path/URI to copy from i.e. "c:/foo/bar"
// newDirectoryName: string containing the new name of the directory i.e. "bar2"
//
// Return values:
// returns an object with two properties
// success: boolean indicating if the call succeeded or failed
// status: int indicating the request HTTP status code
// 204 - the operation succeeded
// 400 - the operation could not be performed because the destUri existed
// 404 - the source directory does not exist
// 500 - unknown server error occurred
renameDirectory: {
enumerable: false,
value: function(dir) {
return this._copyMoveDirHelper(dir.sourceUri, dir.sourceUri + "/" + dir.newDirectoryName, "move");
}
},
////////////////////////////////////////////////////////////////////
//Helper that is used by copyDirectory, moveDirectory, renameDirectory
_copyMoveDirHelper: {
enumerable: false,
value: function(sourceDir, destDir, operation) {
var retValue = {};
if(sourceDir && sourceDir.length && destDir && destDir.length && operation && operation.length) {
try {
var serviceURL = this._prepareServiceURL(this._directoryServiceURL, destDir),
xhr = new XMLHttpRequest();
//
xhr.open("PUT", serviceURL, false);
xhr.setRequestHeader("sourceURI", sourceDir);
xhr.setRequestHeader("operation", operation);
//
xhr.send();
//
if (xhr.readyState === 4) {
retValue.status = xhr.status;
retValue.success = true;
}
}
catch(error) {
xhr = null;
retValue.success = false;
}
}
//
return retValue;
}
},
////////////////////////////////////////////////////////////////////
// Checks if the file has been modified since it was last queried
// Parameters:
// the file parameter must contain the following properties
// uri: string value containing the full file path/URI i.e. "c:/foo/bar.html"
// recursive: boolean true to check the modified date of all subdirectories as well. if this is not specified "false" is the default.
//
// Return values:
// returns an object with two properties
// success: boolean indicating if the call succeeded or failed
// status: int indicating the request HTTP status code
// 200 - the file has been modified
// 304 - the file has not been modified
// 404 - the file does not exist
// 500 - unknown server error occurred
isFileModified:{
enumerable:true,
writable:false,
value:function(file, lastQueriedTimestamp){
var retValue = { success:null, status:null };
if(file && file.uri) {
try {
var serviceURL = this._prepareServiceURL(this._fileServiceURL, file.uri),
xhr = new XMLHttpRequest();
xhr.open("GET", serviceURL, false);
xhr.setRequestHeader("if-modified-since", lastQueriedTimestamp);
xhr.send();
if (xhr.readyState === 4) {
retValue.status = xhr.status;
retValue.success = true;
}
}
catch(error) {
xhr = null;
retValue.success = false;
}
}
return retValue;
}
},
////////////////////////////////////////////////////////////////////
// Checks if the directory content has been modified since it was last queried
// Parameters:
// the file parameter must contain the following properties
// uri: string value containing the full directory path/URI i.e. "c:/foo/bar.html"
// recursive: boolean true to check the modified date of all subdirectories as well. if this is not specified "false" is the default.
//
// Return values:
// returns an object with two properties
// success: boolean indicating if the call succeeded or failed
// status: int indicating the request HTTP status code
// 200 - the file has been modified
// 304 - the file has not been modified
// 404 - the file does not exist
// 500 - unknown server error occurred
isDirectoryModified:{
enumerable:true,
writable:false,
value:function(file, lastQueriedTimestamp){
var retValue = { success:null, status:null };
if(file && file.uri) {
try {
var serviceURL = this._prepareServiceURL(this._directoryServiceURL, file.uri),
xhr = new XMLHttpRequest();
xhr.open("GET", serviceURL, false);
xhr.setRequestHeader("if-modified-since", lastQueriedTimestamp);
xhr.send();
if (xhr.readyState === 4) {
retValue.status = xhr.status;
retValue.success = true;
}
}
catch(error) {
xhr = null;
retValue.success = false;
}
}
return retValue;
}
}
});
////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////
|