bundles/org.eclipse.orion.client.ui/web/shell/paramType-file.js
function(promise, result, output, isProgress) {
				var element = document.createElement("div"); //$NON-NLS-0$

				var waitCount = 0;
				var successFn = function(file) {
					this.callback = function() {
						var string = i18nUtil.formatMessage(
							messages["WroteMsg"],
							typeof(file) === "string" ? file : this.shellPageFileService.computePathString(file)); //$NON-NLS-0$
						var writer = new mResultWriters.ShellStringWriter(element);
						writer.write(string + "\n"); //$NON-NLS-0$
						if (--waitCount !== 0 || isProgress) {
							promise.progress(element);
						} else {
							promise.resolve(element);
						}
					}.bind(this);
					return this;
				}.bind(this);
				var errorFn = function(file) {
					this.callback = function(error) {
						var string = i18nUtil.formatMessage(
							messages["WriteFailMsg"],
							typeof(file) === "string" ? file : this.shellPageFileService.computePathString(file)); //$NON-NLS-0$
						string += " [" + error + "]"; //$NON-NLS-1$ //$NON-NLS-0$
						var writer = new mResultWriters.ShellStringWriter(element);
						writer.write(string + "\n"); //$NON-NLS-0$
						if (--waitCount !== 0 || isProgress) {
							promise.progress(element);
						} else {
							promise.resolve(element);
						}
					}.bind(this);
					return this;
				}.bind(this);

				var destination = output || this.shellPageFileService.getCurrentDirectory();
				waitCount++;
				this.shellPageFileService.ensureDirectory(null, destination).then(
					function(directory) {
						waitCount--;

						var files = result.getValue();
						if (!result.isArray()) {
							files = [files];
						}
						files.forEach(function(file) {
							waitCount++;
							var pathSegments = file.path.split(this.shellPageFileService.SEPARATOR);

							/* normalize instances of '.' and '..' in the path */
							var index = 0;
							while (index < pathSegments.length) {
								var segment = pathSegments[index];
								if (segment === ".") { //$NON-NLS-0$
									pathSegments.splice(index, 1);
								} else if (segment === "..") { //$NON-NLS-0$
									if (index === 0) {
										/* invalid, destination must be a descendent of the cwd */
										errorFn(i18nUtil.formatMessage(messages["WriteFailNotDescendentOfOutputDir"], file.path));
										return;
									}
									pathSegments.splice(index-- - 1, 2);
								} else {
									index++;
								}
							}

							var writeFile = function(parentNode, fileToWrite, pathSegments) {
								var segment = pathSegments[0];
								pathSegments.splice(0,1);
								var nodeString = this.shellPageFileService.computePathString(parentNode) + this.shellPageFileService.SEPARATOR + segment;
								if (pathSegments.length === 0) {
									/* attempt to write the new resource */
									if (fileToWrite.isDirectory) {
										this.shellPageFileService.ensureDirectory(parentNode, segment).then(successFn(nodeString).callback, errorFn(nodeString).callback);
									} else {
										this.shellPageFileService.ensureFile(parentNode, segment).then(
											function(file) {
												var writer = new mResultWriters.FileBlobWriter(file, this.shellPageFileService);
												writer.addBlob(fileToWrite.blob);
												writer.write().then(successFn(file).callback, errorFn(file).callback);
											}.bind(this),
											errorFn(nodeString).callback
										);
									}
									return;
								}
								/* more lead-up path segments to go */
								this.shellPageFileService.ensureDirectory(parentNode, segment).then(
									function(newNode) {
										writeFile(newNode, fileToWrite, pathSegments);
									},
									errorFn(this.shellPageFileService.computePathString(parentNode) + this.shellPageFileService.SEPARATOR + segment).callback
								);
							}.bind(this);
							writeFile(directory, file, pathSegments);
						}.bind(this));
					}.bind(this),
					errorFn(destination).callback
				);
			}
function(promise, result, output, isProgress) {
				var element = document.createElement("div"); //$NON-NLS-0$

				var waitCount = 0;
				var successFn = function(file) {
					this.callback = function() {
						var string = i18nUtil.formatMessage(
							messages["WroteMsg"],
							typeof(file) === "string" ? file : this.shellPageFileService.computePathString(file)); //$NON-NLS-0$
						var writer = new mResultWriters.ShellStringWriter(element);
						writer.write(string + "\n"); //$NON-NLS-0$
						if (--waitCount !== 0 || isProgress) {
							promise.progress(element);
						} else {
							promise.resolve(element);
						}
					}.bind(this);
					return this;
				}.bind(this);
				var errorFn = function(file) {
					this.callback = function(error) {
						var string = i18nUtil.formatMessage(
							messages["WriteFailMsg"],
							typeof(file) === "string" ? file : this.shellPageFileService.computePathString(file)); //$NON-NLS-0$
						string += " [" + error + "]"; //$NON-NLS-1$ //$NON-NLS-0$
						var writer = new mResultWriters.ShellStringWriter(element);
						writer.write(string + "\n"); //$NON-NLS-0$
						if (--waitCount !== 0 || isProgress) {
							promise.progress(element);
						} else {
							promise.resolve(element);
						}
					}.bind(this);
					return this;
				}.bind(this);

				var destination = output || this.shellPageFileService.getCurrentDirectory();
				waitCount++;
				this.shellPageFileService.ensureDirectory(null, destination).then(
					function(directory) {
						waitCount--;

						var files = result.getValue();
						if (!result.isArray()) {
							files = [files];
						}
						files.forEach(function(file) {
							waitCount++;
							var pathSegments = file.path.split(this.shellPageFileService.SEPARATOR);

							/* normalize instances of '.' and '..' in the path */
							var index = 0;
							while (index < pathSegments.length) {
								var segment = pathSegments[index];
								if (segment === ".") { //$NON-NLS-0$
									pathSegments.splice(index, 1);
								} else if (segment === "..") { //$NON-NLS-0$
									if (index === 0) {
										/* invalid, destination must be a descendent of the cwd */
										errorFn(i18nUtil.formatMessage(messages["WriteFailNotDescendentOfOutputDir"], file.path));
										return;
									}
									pathSegments.splice(index-- - 1, 2);
								} else {
									index++;
								}
							}

							var writeFile = function(parentNode, fileToWrite, pathSegments) {
								var segment = pathSegments[0];
								pathSegments.splice(0,1);
								var nodeString = this.shellPageFileService.computePathString(parentNode) + this.shellPageFileService.SEPARATOR + segment;
								if (pathSegments.length === 0) {
									/* attempt to write the new resource */
									if (fileToWrite.isDirectory) {
										this.shellPageFileService.ensureDirectory(parentNode, segment).then(successFn(nodeString).callback, errorFn(nodeString).callback);
									} else {
										this.shellPageFileService.ensureFile(parentNode, segment).then(
											function(file) {
												var writer = new mResultWriters.FileBlobWriter(file, this.shellPageFileService);
												writer.addBlob(fileToWrite.blob);
												writer.write().then(successFn(file).callback, errorFn(file).callback);
											}.bind(this),
											errorFn(nodeString).callback
										);
									}
									return;
								}
								/* more lead-up path segments to go */
								this.shellPageFileService.ensureDirectory(parentNode, segment).then(
									function(newNode) {
										writeFile(newNode, fileToWrite, pathSegments);
									},
									errorFn(this.shellPageFileService.computePathString(parentNode) + this.shellPageFileService.SEPARATOR + segment).callback
								);
							}.bind(this);
							writeFile(directory, file, pathSegments);
						}.bind(this));
					}.bind(this),
					errorFn(destination).callback
				);
			}
function ( promise , result , output , isProgress ) { var element = document . createElement ( "div" ) ; //$NON-NLS-0$ var waitCount = 0 ; var successFn = function ( file ) { this . callback = function ( ) { var string = i18nUtil . formatMessage ( messages [ "WroteMsg" ] , typeof ( file ) === "string" ? file : this . shellPageFileService . computePathString ( file ) ) ; //$NON-NLS-0$ var writer = new mResultWriters . ShellStringWriter ( element ) ; writer . write ( string + "\n" ) ; //$NON-NLS-0$ if ( -- waitCount !== 0 || isProgress ) { promise . progress ( element ) ; } else { promise . resolve ( element ) ; } } . bind ( this ) ; return this ; } . bind ( this ) ; var errorFn = function ( file ) { this . callback = function ( error ) { var string = i18nUtil . formatMessage ( messages [ "WriteFailMsg" ] , typeof ( file ) === "string" ? file : this . shellPageFileService . computePathString ( file ) ) ; //$NON-NLS-0$ string += " [" + error + "]" ; //$NON-NLS-1$ //$NON-NLS-0$ var writer = new mResultWriters . ShellStringWriter ( element ) ; writer . write ( string + "\n" ) ; //$NON-NLS-0$ if ( -- waitCount !== 0 || isProgress ) { promise . progress ( element ) ; } else { promise . resolve ( element ) ; } } . bind ( this ) ; return this ; } . bind ( this ) ; var destination = output || this . shellPageFileService . getCurrentDirectory ( ) ; waitCount ++ ; this . shellPageFileService . ensureDirectory ( null , destination ) . then ( function ( directory ) { waitCount -- ; var files = result . getValue ( ) ; if ( ! result . isArray ( ) ) { files = [ files ] ; } files . forEach ( function ( file ) { waitCount ++ ; var pathSegments = file . path . split ( this . shellPageFileService . SEPARATOR ) ; /* normalize instances of '.' and '..' in the path */ var index = 0 ; while ( index < pathSegments . length ) { var segment = pathSegments [ index ] ; if ( segment === "." ) { //$NON-NLS-0$ pathSegments . splice ( index , 1 ) ; } else if ( segment === ".." ) { //$NON-NLS-0$ if ( index === 0 ) { /* invalid, destination must be a descendent of the cwd */ errorFn ( i18nUtil . formatMessage ( messages [ "WriteFailNotDescendentOfOutputDir" ] , file . path ) ) ; return ; } pathSegments . splice ( index -- - 1 , 2 ) ; } else { index ++ ; } } var writeFile = function ( parentNode , fileToWrite , pathSegments ) { var segment = pathSegments [ 0 ] ; pathSegments . splice ( 0 , 1 ) ; var nodeString = this . shellPageFileService . computePathString ( parentNode ) + this . shellPageFileService . SEPARATOR + segment ; if ( pathSegments . length === 0 ) { /* attempt to write the new resource */ if ( fileToWrite . isDirectory ) { this . shellPageFileService . ensureDirectory ( parentNode , segment ) . then ( successFn ( nodeString ) . callback , errorFn ( nodeString ) . callback ) ; } else { this . shellPageFileService . ensureFile ( parentNode , segment ) . then ( function ( file ) { var writer = new mResultWriters . FileBlobWriter ( file , this . shellPageFileService ) ; writer . addBlob ( fileToWrite . blob ) ; writer . write ( ) . then ( successFn ( file ) . callback , errorFn ( file ) . callback ) ; } . bind ( this ) , errorFn ( nodeString ) . callback ) ; } return ; } /* more lead-up path segments to go */ this . shellPageFileService . ensureDirectory ( parentNode , segment ) . then ( function ( newNode ) { writeFile ( newNode , fileToWrite , pathSegments ) ; } , errorFn ( this . shellPageFileService . computePathString ( parentNode ) + this . shellPageFileService . SEPARATOR + segment ) . callback ) ; } . bind ( this ) ; writeFile ( directory , file , pathSegments ) ; } . bind ( this ) ) ; } . bind ( this ) , errorFn ( destination ) . callback ) ; }
This function handles results of this custom type returned from commands.
This function handles results of this custom type returned from commands .