/*******************************************************************************
 * @license
 * Copyright (c) 2012 IBM Corporation and others.
 * All rights reserved. This program and the accompanying materials are made 
 * available under the terms of the Eclipse Public License v1.0 
 * (http://www.eclipse.org/legal/epl-v10.html), and the Eclipse Distribution 
 * License v1.0 (http://www.eclipse.org/org/documents/edl-v10.html). 
 * 
 * Contributors: IBM Corporation - initial API and implementation
 ******************************************************************************/
/*******************************************************************************
 * @license
 * Copyright (c) 2011, 2012 IBM Corporation and others.
 * All rights reserved. This program and the accompanying materials are made 
 * available under the terms of the Eclipse Public License v1.0 
 * (http://www.eclipse.org/legal/epl-v10.html), and the Eclipse Distribution 
 * License v1.0 (http://www.eclipse.org/org/documents/edl-v10.html). 
 *
 * Contributors:
 *     IBM Corporation - initial API and implementation
 *******************************************************************************/
/*******************************************************************************
 * @license
 * Copyright (c) 2012 IBM Corporation and others.
 * All rights reserved. This program and the accompanying materials are made 
 * available under the terms of the Eclipse Public License v1.0 
 * (http://www.eclipse.org/legal/epl-v10.html), and the Eclipse Distribution 
 * License v1.0 (http://www.eclipse.org/org/documents/edl-v10.html). 
 *
 * Contributors:
 *     IBM Corporation - initial API and implementation
 *******************************************************************************/
/*******************************************************************************
 * @license
 * Copyright (c) 2012 IBM Corporation and others.
 * All rights reserved. This program and the accompanying materials are made 
 * available under the terms of the Eclipse Public License v1.0 
 * (http://www.eclipse.org/legal/epl-v10.html), and the Eclipse Distribution 
 * License v1.0 (http://www.eclipse.org/org/documents/edl-v10.html). 
 *
 * Contributors:
 *     IBM Corporation - initial API and implementation
 *******************************************************************************/
/*******************************************************************************
 * @license
 * Copyright (c) 2010, 2012 IBM Corporation and others.
 * All rights reserved. This program and the accompanying materials are made 
 * available under the terms of the Eclipse Public License v1.0 
 * (http://www.eclipse.org/legal/epl-v10.html), and the Eclipse Distribution 
 * License v1.0 (http://www.eclipse.org/org/documents/edl-v10.html). 
 * 
 * Contributors: IBM Corporation - initial API and implementation
 ******************************************************************************/
/**
 * @license RequireJS domReady 1.0.0 Copyright (c) 2010-2011, The Dojo Foundation All Rights Reserved.
 * Available via the MIT or new BSD license.
 * see: http://github.com/jrburke/requirejs for details
 */
/*******************************************************************************
 * @license
 * Copyright (c) 2010, 2012 IBM Corporation and others.
 * All rights reserved. This program and the accompanying materials are made 
 * available under the terms of the Eclipse Public License v1.0 
 * (http://www.eclipse.org/legal/epl-v10.html), and the Eclipse Distribution 
 * License v1.0 (http://www.eclipse.org/org/documents/edl-v10.html). 
 * 
 * Contributors: IBM Corporation - initial API and implementation
 ******************************************************************************/
/*

 Copyright (c) 2012 IBM Corporation and others.
 All rights reserved. This program and the accompanying materials are made 
 available under the terms of the Eclipse Public License v1.0 
 (http://www.eclipse.org/legal/epl-v10.html), and the Eclipse Distribution 
 License v1.0 (http://www.eclipse.org/org/documents/edl-v10.html). 

 Contributors: IBM Corporation - initial API and implementation

 Copyright (c) 2011, 2012 IBM Corporation and others.
 All rights reserved. This program and the accompanying materials are made 
 available under the terms of the Eclipse Public License v1.0 
 (http://www.eclipse.org/legal/epl-v10.html), and the Eclipse Distribution 
 License v1.0 (http://www.eclipse.org/org/documents/edl-v10.html). 

 Contributors:
 IBM Corporation - initial API and implementation

 Copyright (c) 2012 IBM Corporation and others.
 All rights reserved. This program and the accompanying materials are made 
 available under the terms of the Eclipse Public License v1.0 
 (http://www.eclipse.org/legal/epl-v10.html), and the Eclipse Distribution 
 License v1.0 (http://www.eclipse.org/org/documents/edl-v10.html). 

 Contributors:
 IBM Corporation - initial API and implementation

 Copyright (c) 2010, 2012 IBM Corporation and others.
 All rights reserved. This program and the accompanying materials are made 
 available under the terms of the Eclipse Public License v1.0 
 (http://www.eclipse.org/legal/epl-v10.html), and the Eclipse Distribution 
 License v1.0 (http://www.eclipse.org/org/documents/edl-v10.html). 

 Contributors: IBM Corporation - initial API and implementation
 RequireJS domReady 1.0.0 Copyright (c) 2010-2011, The Dojo Foundation All Rights Reserved.
 Available via the MIT or new BSD license.
 see: http://github.com/jrburke/requirejs for details

 Copyright (c) 2010, 2012 IBM Corporation and others.
 All rights reserved. This program and the accompanying materials are made 
 available under the terms of the Eclipse Public License v1.0 
 (http://www.eclipse.org/legal/epl-v10.html), and the Eclipse Distribution 
 License v1.0 (http://www.eclipse.org/org/documents/edl-v10.html). 

 Contributors: IBM Corporation - initial API and implementation

 Copyright (c) 2012 IBM Corporation and others.
 All rights reserved. This program and the accompanying materials are made 
 available under the terms of the Eclipse Public License v1.0 
 (http://www.eclipse.org/legal/epl-v10.html), and the Eclipse Distribution 
 License v1.0 (http://www.eclipse.org/org/documents/edl-v10.html). 

 Contributors:
 IBM Corporation - initial API and implementation
*/
(function(j,e){typeof define==="function"&&define.amd?define("orion/Deferred",[],e):typeof exports==="object"?module.exports=e():(j.orion=j.orion||{},j.orion.Deferred=e())})(this,function(){function j(b){if(a)i?(h.next={fn:b,next:null},h=h.next):h=i={fn:b,next:null};else{a=!0;do{for(;b;){b();if(d)i?h.next=d:i=d,h=c;i?(d=i.next,c=h,b=i.fn,i=h=null):b=null}a=!1}while(a)}}function e(a){return function(){a.apply(null,arguments)}}function g(a){function c(){for(;d;){var a=d;d=d.next;var b=a.deferred,k=
o.isResolved()?"resolve":"reject";if(a[k])try{var l=a[k](f);l&&typeof l.then==="function"?(a.cancel=l.cancel,l.then(e(b.resolve),e(b.reject),b.progress)):b.resolve(l)}catch(m){b.reject(m)}else b[k](f)}d=i=null}function k(a){if(m){if(a)throw Error("already "+m);return!0}return!1}var f,m,d,i,h=!1,o=this;this.reject=function(a,b){k(b)||(m="rejected",f=a,d&&j(c));return o.promise};this.resolve=function(a,b){k(b)||(m="resolved",f=a,d&&j(c));return o.promise};this.progress=function(a,b){if(!k(b))for(var c=
d;c;)c.progress&&c.progress(a),c=c.next;return o.promise};this.cancel=function(f,m){if(!k(m))return h=!0,a&&(f=a(f)||f),f=f||Error("canceled"),j(o.reject.bind(o,f)),f;for(var e=d;e;){if(e.canceling)return delete e.canceling,c(),e.cancel&&e.cancel(f);e=e.next}};this.then=function(a,b,f){var k={resolve:a,reject:b,progress:f,cancel:this.cancel,deferred:new g(function(a){k.canceling=!0;return k.cancel&&k.cancel(a)})};d?i.next=k:d=k;i=k;m&&j(c);return k.deferred.promise};this.isResolved=function(){return m===
"resolved"};this.isRejected=function(){return m==="rejected"};this.isFulfilled=function(){return!!m};this.isCanceled=function(){return h};this.promise={then:this.then,cancel:this.cancel,isResolved:this.isResolved,isRejected:this.isRejected,isFulfilled:this.isFulfilled,isCanceled:this.isCanceled};this.notify=this.progress;this.state=function(){return m||"pending"};this.promise.state=this.state}var i,h,d,c,a=!1;g.all=function(a,c){function k(a,b){i.isFulfilled()||(e[a]=b,--d===0&&i.resolve(e))}function f(a,
b){if(!i.isFulfilled()){if(c)try{k(a,c(b));return}catch(f){b=f}i.reject(b)}}var d=a.length,e=[],i=new g(function(c){a.forEach(function(a){a.cancel&&a.cancel(c)})});d===0?i.resolve(e):a.forEach(function(a,b){a.then(k.bind(null,b),f.bind(null,b))});return i.promise};g.when=function(a,c,k,f){var d;if(!(a&&typeof a.then==="function"))d=new g,d.resolve(a),a=d.promise;return a.then(c,k,f)};return g});
(function(){var j=this;if(!j.define)j.define=function(e){j.orion=j.orion||{};j.orion.PluginProvider=e();j.eclipse=j.orion;delete j.define}})();
define("orion/plugin",[],function(){return function(j){function e(a){l&&(typeof ArrayBuffer==="undefined"&&(a=JSON.stringify(a)),l===self?l.postMessage(a):l.postMessage(a,"*"))}function g(a,b){return b&&b instanceof XMLHttpRequest?{status:b.status,statusText:b.statusText}:b}function i(b){return function(c){a&&e({serviceId:b,method:"dispatchEvent",params:[c]})}}function h(a){if(a.source===l){var f=typeof a.data!=="string"?a.data:JSON.parse(a.data);if(typeof f.cancel==="string"){var d=b[f.id];d&&(delete b[f.id],
d.cancel&&d.cancel(f.cancel))}else{var a=f.serviceId,h=f.method,j=f.params,p=c[a],o=p.implementation,r=o[h];h==="addEventListener"?(h=j[0],p.listeners[h]=p.listeners[h]||i(a),j=[h,p.listeners[h]]):h==="removeEventListener"&&(h=j[0],j=[h,p.listeners[h]],delete p.listeners[h]);var n={id:f.id,result:null,error:null};try{(d=r.apply(o,j))&&typeof d.then==="function"?(b[f.id]=d,d.then(function(a){delete b[f.id];n.result=a;e(n)},function(a){if(b[f.id])delete b[f.id],n.error=a?JSON.parse(JSON.stringify(a,
g)):a,e(n)},function(){e({requestId:f.id,method:"progress",params:Array.prototype.slice.call(arguments)})})):(n.result=d,e(n))}catch(q){n.error=q?JSON.parse(JSON.stringify(q,g)):q,e(n)}}}}var d=j,c=[],a=!1,b={},l=null;this.updateHeaders=function(b){if(a)throw Error("Cannot update headers. Plugin Provider is connected");d=b};this.registerServiceProvider=this.registerService=function(b,d,l){if(a)throw Error("Cannot register service. Plugin Provider is connected");typeof b==="string"?b=[b]:Array.isArray(b)||
(b=[]);var e=null,h=[];for(e in d)typeof d[e]==="function"&&h.push(e);c[c.length]={names:b,methods:h,implementation:d,properties:l||{},listeners:{}}};this.connect=function(b,f){if(!a){if(typeof window==="undefined")l=self;else if(window!==window.parent)l=window.parent;else if(window.opener!==null)l=window.opener;else{f&&f("No valid plugin target");return}addEventListener("message",h,!1);for(var i=[],g=0;g<c.length;g++)i.push({serviceId:g,names:c[g].names,methods:c[g].methods,properties:c[g].properties});
e({method:"plugin",params:[{headers:d||{},services:i}]});a=!0}b&&b()};this.disconnect=function(){a&&(removeEventListener("message",h),l=null,a=!1)}}});
define("orion/xhr",["orion/Deferred"],function(j){function e(e){return encodeURIComponent(e).replace(/[!'()*]/g,function(e){return"%"+e.charCodeAt(0).toString(16).toUpperCase()})}function g(e,g,d,c){var a=typeof d.response!=="undefined"?d.response:d.responseText,e={args:g,response:a,responseText:typeof a==="string"?a:null,status:d.status,url:e,xhr:d};if(typeof c!=="undefined")e.error=c;return e}return function(i,h,d){var d=d||{},c=arguments.length>3&&arguments[3]?arguments[3]:new XMLHttpRequest,a=
new j,b=d.headers||{},l=d.log||!1,k,f;typeof b["X-Requested-With"]==="undefined"&&(b["X-Requested-With"]="XMLHttpRequest");if(d.query&&typeof d.query==="object"){var m=d.query,t=Object.keys(m),s=[];for(f=0;f<t.length;f++){var p=t[f],o=m[p];s.push(e(p)+"="+e(o))}s.length&&(m=h.split("#"),m[0]+=(m[0].indexOf("?")===-1?"?":"&")+s.join("&"),h=m.join("#"))}if(typeof d.data!=="undefined"&&(i==="POST"||i==="PUT"))k=d.data;if(typeof d.responseType==="string")c.responseType=d.responseType;c.onreadystatechange=
function(){if(c.readyState===4){var b=g(h,d,c),e=c.status;200<=e&&e<400?a.resolve(b):(l&&typeof console!=="undefined"&&console.log(Error(c.statusText)),a.reject(b))}};try{c.open(i,h,!0);if(typeof d.timeout==="number")typeof c.timeout==="number"?(c.timeout=d.timeout,c.addEventListener("timeout",function(){a.reject(g(h,d,c,"Timeout exceeded"))})):setTimeout(function(){a.state()!=="resolved"&&a.state()!=="rejected"&&a.reject(g(h,d,c,"Timeout exceeded"))},d.timeout);var r=Object.keys(b);for(f=0;f<r.length;f++){var n=
r[f];c.setRequestHeader(n,b[n])}c.send(k)}catch(q){a.reject(g(h,d,c,q))}return a}});define("orion/es5shim",[],function(){if(!Function.prototype.bind)Function.prototype.bind=function(j){var e=this,g=Array.prototype.slice.call(arguments,1);return g.length?function(){return arguments.length?e.apply(j,g.concat(Array.prototype.slice.call(arguments))):e.apply(j,g)}:function(){return arguments.length?e.apply(j,arguments):e.call(j)}}});
define("plugins/filePlugin/fileImpl",["orion/Deferred","orion/xhr","orion/es5shim"],function(j,e){function g(c){c&&typeof c==="object"&&Object.keys(c).forEach(function(a){var b=c[a];a.indexOf("Location")!==-1?(d.href=b,c[a]=d.href):g(b)});return c}function i(c,a){this.fileBase=c;this.makeAbsolute=(this.workspaceBase=a)&&a.indexOf("://")!==-1}function h(c,a,b,d){var e=new j,f=new XMLHttpRequest,g;try{f.open(c,a);if(b!==null)for(g in b)b.hasOwnProperty(g)&&f.setRequestHeader(g,b[g]);f.responseType=
"arraybuffer";f.send(d);f.onreadystatechange=function(){f.readyState===4&&e.resolve({status:f.status,statusText:f.statusText,headers:f.getAllResponseHeaders(),response:f.response})}}catch(h){e.reject(h)}return e}var d=document.createElement("a");i.prototype={fetchChildren:function(c){return c===this.fileBase?this.loadWorkspace(c).then(function(a){return a.Children||[]}):e("GET",c,{headers:{"Orion-Version":"1","Content-Type":"charset=UTF-8"},timeout:15E3}).then(function(a){return(a.response?JSON.parse(a.response):
{}).Children||[]}).then(function(a){this.makeAbsolute&&g(a);return a}.bind(this))},_createWorkspace:function(c){return e("POST",this.workspaceBase,{headers:{"Orion-Version":"1",Slug:c},timeout:15E3}).then(function(a){return a.response?JSON.parse(a.response):{}})},loadWorkspaces:function(){return e("GET",this.workspaceBase,{headers:{"Orion-Version":"1"},timeout:15E3}).then(function(c){return(c.response?JSON.parse(c.response):{}).Workspaces}).then(function(c){this.makeAbsolute&&g(c);return c}.bind(this))},
loadWorkspace:function(c){c===this.fileBase&&(c=null);return e("GET",c?c:this.workspaceBase,{headers:{"Orion-Version":"1"},timeout:15E3,log:!1}).then(function(a){a=a.response?JSON.parse(a.response):{};return c?a:a.Workspaces.length>0?this.loadWorkspace(a.Workspaces[0].Location):this._createWorkspace("Orion Content")}.bind(this)).then(function(a){this.makeAbsolute&&g(a);return a}.bind(this))},createProject:function(c,a,b,d){if(c){a={Name:a};if(b)a.ContentLocation=b;if(d)a.CreateIfDoesntExist=d;return e("POST",
c,{headers:{"Orion-Version":"1","Content-Type":"application/json;charset=UTF-8"},timeout:15E3,data:JSON.stringify(a)}).then(function(a){return a.response?JSON.parse(a.response):null}).then(function(a){this.makeAbsolute&&g(a);return a}.bind(this))}else console.error("url is undefined, make sure you're signed in before creating a project")},createFolder:function(c,a){return e("POST",c,{headers:{"Orion-Version":"1","X-Create-Options":"no-overwrite",Slug:a,"Content-Type":"application/json;charset=UTF-8"},
data:JSON.stringify({Name:a,LocalTimeStamp:"0",Directory:"true"}),timeout:15E3}).then(function(a){return a.response?JSON.parse(a.response):null}).then(function(a){this.makeAbsolute&&g(a);return a}.bind(this))},createFile:function(c,a){return e("POST",c,{headers:{"Orion-Version":"1","X-Create-Options":"no-overwrite",Slug:a,"Content-Type":"application/json;charset=UTF-8"},data:JSON.stringify({Name:a,LocalTimeStamp:"0",Directory:"false"}),timeout:15E3}).then(function(a){return a.response?JSON.parse(a.response):
null}).then(function(a){this.makeAbsolute&&g(a);return a}.bind(this))},deleteFile:function(c){return e("DELETE",c,{headers:{"Orion-Version":"1"},timeout:15E3}).then(function(a){return a.response?JSON.parse(a.response):null}).then(function(a){this.makeAbsolute&&g(a);return a}.bind(this))},moveFile:function(c,a,b){return this._doCopyMove(c,a,!0,b).then(function(a){this.makeAbsolute&&g(a);return a}.bind(this))},copyFile:function(c,a,b){return this._doCopyMove(c,a,!1,b).then(function(a){this.makeAbsolute&&
g(a);return a}.bind(this))},_doCopyMove:function(c,a,b,d){d||(d=c.split("/"),d=d.pop()||d.pop());return e("POST",a,{headers:{"Orion-Version":"1",Slug:d,"X-Create-Options":"no-overwrite,"+(b?"move":"copy"),"Content-Type":"application/json;charset=UTF-8"},data:JSON.stringify({Location:c,Name:d}),timeout:15E3}).then(function(a){return a.response?JSON.parse(a.response):null})},read:function(c,a){return e("GET",c,{timeout:5E3,headers:{"Orion-Version":"1"},log:!1,query:a?{parts:"meta"}:{}}).then(function(b){return a?
b.response?JSON.parse(b.response):null:b.response}).then(function(a){this.makeAbsolute&&g(a);return a}.bind(this))},write:function(c,a,b){var d={"Orion-Version":"1","Content-Type":"text/plain;charset=UTF-8"};if(b&&b.ETag)d["If-Match"]=b.ETag;b={timeout:5E3,headers:d,data:a,log:!1};if(typeof a!=="string")a.sourceLocation?(b.query={source:a.sourceLocation},b.data=null):b.query={parts:"meta"};return e("PUT",c,b).then(function(a){return a.response?JSON.parse(a.response):null}).then(function(a){this.makeAbsolute&&
g(a);return a}.bind(this))},remoteImport:function(c,a){var b={"Orion-Version":"1"};if(a.OptionHeader)b["X-Xfer-Options"]=a.OptionHeader;return e("POST",c,{headers:b,data:JSON.stringify(a),timeout:15E3}).then(function(a){return a.response?JSON.parse(a.response):null}).then(function(a){this.makeAbsolute&&g(a);return a}.bind(this))},remoteExport:function(c,a){var b={"Orion-Version":"1"};if(a.OptionHeader)b["X-Xfer-Options"]=a.OptionHeader;return e("POST",c,{headers:b,data:JSON.stringify(a),timeout:15E3}).then(function(a){return a.response?
JSON.parse(a.response):null}).then(function(a){this.makeAbsolute&&g(a);return a}.bind(this))},search:function(c,a){var b=a.indexOf("+Location:");if(b!==-1){var d=a.substring(b+10);if(d.indexOf("://")!==-1)var h=d.indexOf("://")+3,h=d.indexOf("/",h),d=h===-1?"":d.substring(h);a=a.substring(0,b+10)+d}return e("GET","/filesearch"+a,{headers:{Accept:"application/json","Orion-Version":"1"},timeout:15E3}).then(function(a){return a.response?JSON.parse(a.response):{}}).then(function(a){this.makeAbsolute&&
g(a);return a}.bind(this))}};window.BlobBuilder=window.MozBlobBuilder||window.WebKitBlobBuilder||window.BlobBuilder;if(window.BlobBuilder)i.prototype.readBlob=function(c){return h("GET",c).then(function(a){if(window.WebKitBlobBuilder){var b=new BlobBuilder;b.append(a.response);return b.getBlob()}return a.response})},i.prototype.writeBlob=function(c,a,b){var d={};if(b&&b.ETag)d["If-Match"]=b.ETag;a.type||(b=new BlobBuilder,a&&b.append(a),a=b.getBlob());return h("PUT",c,d,a)};return i});
define("domReady",[],function(){function j(a){for(var b=0,d;d=a[b];b++)d(c)}function e(){var c=a,e=b;d&&(c.length&&(a=[],j(c)),l.resourcesDone&&e.length&&(b=[],j(e)))}function g(){d||(d=!0,f&&clearInterval(f),e())}function i(b){d?b(c):a.push(b);return i}var h=typeof window!=="undefined"&&window.document,d=!h,c=h?document:null,a=[],b=[],l=requirejs||require||{},k=l.resourcesReady,f;if("resourcesReady"in l)l.resourcesReady=function(a){k&&k(a);a&&e()};h&&(document.addEventListener?(document.addEventListener("DOMContentLoaded",
g,!1),window.addEventListener("load",g,!1)):window.attachEvent&&(window.attachEvent("onload",g),self===self.top&&(f=setInterval(function(){try{document.body&&(document.documentElement.doScroll("left"),g())}catch(a){}},30))),document.readyState==="complete"&&g());i.withResources=function(a){d&&l.resourcesDone?a(c):b.push(a);return i};i.version="1.0.0";i.load=function(a,b,c,d){d.isBuild?c(null):i(c)};return i});
define("plugins/fileClientPlugin",["orion/Deferred","orion/plugin","plugins/filePlugin/fileImpl","domReady!"],function(j,e,g){function i(a){if(h)try{if(window.location.host===parent.location.host&&window.location.protocol===parent.location.protocol)return a.substring(parent.location.href.indexOf(parent.location.host)+parent.location.host.length);else h=!1}catch(b){h=!1}return a}var h=!0,d=document.createElement("a");d.href="../mixloginstatic/LoginWindow.html";e=new e({name:"Orion File Service",version:"1.0",
description:"This plugin provides file access to a users workspace.",login:d.href});d.href="../file";j=i(d.href);d.href="../workspace";var c=i(d.href);d.href="..";d=i(d.href);g=new g(j,c);e.registerService("orion.core.file",g,{Name:"Orion Content",NameKey:"Orion Content",nls:"orion/navigate/nls/messages",top:j,pattern:d});e.connect()});