/*******************************************************************************
 * @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) 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 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) 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
 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) 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(g,i){typeof define==="function"&&define.amd?define("orion/Deferred",[],i):typeof exports==="object"?module.exports=i():(g.orion=g.orion||{},g.orion.Deferred=i())})(this,function(){function g(j){if(h)f?(a.next={fn:j,next:null},a=a.next):a=f={fn:j,next:null};else{h=!0;do{for(;j;){j();if(b)f?a.next=b:f=b,a=e;f?(b=f.next,e=a,j=f.fn,f=a=null):j=null}h=!1}while(h)}}function i(a){return function(){a.apply(null,arguments)}}function k(a){function b(){for(;l;){var d=l;l=l.next;var a=d.deferred,n=
h.isResolved()?"resolve":"reject";if(d[n])try{var e=d[n](c);e&&typeof e.then==="function"?(d.cancel=e.cancel,e.then(i(a.resolve),i(a.reject),a.progress)):a.resolve(e)}catch(j){a.reject(j)}else a[n](c)}l=f=null}function n(a){if(d){if(a)throw Error("already "+d);return!0}return!1}var c,d,l,f,e=!1,h=this;this.reject=function(a,e){n(e)||(d="rejected",c=a,l&&g(b));return h.promise};this.resolve=function(a,e){n(e)||(d="resolved",c=a,l&&g(b));return h.promise};this.progress=function(a,d){if(!n(d))for(var c=
l;c;)c.progress&&c.progress(a),c=c.next;return h.promise};this.cancel=function(d,c){if(!n(c))return e=!0,a&&(d=a(d)||d),d=d||Error("canceled"),g(h.reject.bind(h,d)),d;for(var f=l;f;){if(f.canceling)return delete f.canceling,b(),f.cancel&&f.cancel(d);f=f.next}};this.then=function(a,c,n){var e={resolve:a,reject:c,progress:n,cancel:this.cancel,deferred:new k(function(d){e.canceling=!0;return e.cancel&&e.cancel(d)})};l?f.next=e:l=e;f=e;d&&g(b);return e.deferred.promise};this.isResolved=function(){return d===
"resolved"};this.isRejected=function(){return d==="rejected"};this.isFulfilled=function(){return!!d};this.isCanceled=function(){return e};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 d||"pending"};this.promise.state=this.state}var f,a,b,e,h=!1;k.all=function(a,e){function f(a,c){b.isFulfilled()||(l[a]=c,--d===0&&b.resolve(l))}function c(a,
d){if(!b.isFulfilled()){if(e)try{f(a,e(d));return}catch(c){d=c}b.reject(d)}}var d=a.length,l=[],b=new k(function(d){a.forEach(function(a){a.cancel&&a.cancel(d)})});d===0?b.resolve(l):a.forEach(function(a,d){a.then(f.bind(null,d),c.bind(null,d))});return b.promise};k.when=function(a,e,b,c){var d;if(!(a&&typeof a.then==="function"))d=new k,d.resolve(a),a=d.promise;return a.then(e,b,c)};return k});
define("orion/xhr",["orion/Deferred"],function(g){function i(f){return encodeURIComponent(f).replace(/[!'()*]/g,function(a){return"%"+a.charCodeAt(0).toString(16).toUpperCase()})}function k(f,a,b,e){var h=typeof b.response!=="undefined"?b.response:b.responseText,f={args:a,response:h,responseText:typeof h==="string"?h:null,status:b.status,url:f,xhr:b};if(typeof e!=="undefined")f.error=e;return f}return function(f,a,b){var b=b||{},e=arguments.length>3&&arguments[3]?arguments[3]:new XMLHttpRequest,h=
new g,j=b.headers||{},m=b.log||!1,n,c;typeof j["X-Requested-With"]==="undefined"&&(j["X-Requested-With"]="XMLHttpRequest");if(b.query&&typeof b.query==="object"){var d=b.query,l=Object.keys(d),s=[];for(c=0;c<l.length;c++){var t=l[c],r=d[t];s.push(i(t)+"="+i(r))}s.length&&(d=a.split("#"),d[0]+=(d[0].indexOf("?")===-1?"?":"&")+s.join("&"),a=d.join("#"))}if(typeof b.data!=="undefined"&&(f==="POST"||f==="PUT"))n=b.data;if(typeof b.responseType==="string")e.responseType=b.responseType;e.onreadystatechange=
function(){if(e.readyState===4){var d=k(a,b,e),c=e.status;200<=c&&c<400?h.resolve(d):(m&&typeof console!=="undefined"&&console.log(Error(e.statusText)),h.reject(d))}};try{e.open(f,a,!0);if(typeof b.timeout==="number")typeof e.timeout==="number"?(e.timeout=b.timeout,e.addEventListener("timeout",function(){h.reject(k(a,b,e,"Timeout exceeded"))})):setTimeout(function(){h.state()!=="resolved"&&h.state()!=="rejected"&&h.reject(k(a,b,e,"Timeout exceeded"))},b.timeout);var q=Object.keys(j);for(c=0;c<q.length;c++){var o=
q[c];e.setRequestHeader(o,j[o])}e.send(n)}catch(p){h.reject(k(a,b,e,p))}return h}});(function(){var g=this;if(!g.define)g.define=function(i){g.orion=g.orion||{};g.orion.PluginProvider=i();g.eclipse=g.orion;delete g.define}})();
define("orion/plugin",[],function(){return function(g){function i(a){m&&(typeof ArrayBuffer==="undefined"&&(a=JSON.stringify(a)),m===self?m.postMessage(a):m.postMessage(a,"*"))}function k(a,c){return c&&c instanceof XMLHttpRequest?{status:c.status,statusText:c.statusText}:c}function f(a){return function(c){h&&i({serviceId:a,method:"dispatchEvent",params:[c]})}}function a(a){if(a.source===m){var c=typeof a.data!=="string"?a.data:JSON.parse(a.data);if(typeof c.cancel==="string"){var d=j[c.id];d&&(delete j[c.id],
d.cancel&&d.cancel(c.cancel))}else{var a=c.serviceId,b=c.method,h=c.params,g=e[a],r=g.implementation,q=r[b];b==="addEventListener"?(b=h[0],g.listeners[b]=g.listeners[b]||f(a),h=[b,g.listeners[b]]):b==="removeEventListener"&&(b=h[0],h=[b,g.listeners[b]],delete g.listeners[b]);var o={id:c.id,result:null,error:null};try{(d=q.apply(r,h))&&typeof d.then==="function"?(j[c.id]=d,d.then(function(a){delete j[c.id];o.result=a;i(o)},function(a){if(j[c.id])delete j[c.id],o.error=a?JSON.parse(JSON.stringify(a,
k)):a,i(o)},function(){i({requestId:c.id,method:"progress",params:Array.prototype.slice.call(arguments)})})):(o.result=d,i(o))}catch(p){o.error=p?JSON.parse(JSON.stringify(p,k)):p,i(o)}}}}var b=g,e=[],h=!1,j={},m=null;this.updateHeaders=function(a){if(h)throw Error("Cannot update headers. Plugin Provider is connected");b=a};this.registerServiceProvider=this.registerService=function(a,b,d){if(h)throw Error("Cannot register service. Plugin Provider is connected");typeof a==="string"?a=[a]:Array.isArray(a)||
(a=[]);var f=null,g=[];for(f in b)typeof b[f]==="function"&&g.push(f);e[e.length]={names:a,methods:g,implementation:b,properties:d||{},listeners:{}}};this.connect=function(f,c){if(!h){if(typeof window==="undefined")m=self;else if(window!==window.parent)m=window.parent;else if(window.opener!==null)m=window.opener;else{c&&c("No valid plugin target");return}addEventListener("message",a,!1);for(var d=[],g=0;g<e.length;g++)d.push({serviceId:g,names:e[g].names,methods:e[g].methods,properties:e[g].properties});
i({method:"plugin",params:[{headers:b||{},services:d}]});h=!0}f&&f()};this.disconnect=function(){h&&(removeEventListener("message",a),m=null,h=!1)}}});
define("domReady",[],function(){function g(a){for(var b=0,c;c=a[b];b++)c(e)}function i(){var a=h,c=j;b&&(a.length&&(h=[],g(a)),m.resourcesDone&&c.length&&(j=[],g(c)))}function k(){b||(b=!0,c&&clearInterval(c),i())}function f(a){b?a(e):h.push(a);return f}var a=typeof window!=="undefined"&&window.document,b=!a,e=a?document:null,h=[],j=[],m=requirejs||require||{},n=m.resourcesReady,c;if("resourcesReady"in m)m.resourcesReady=function(a){n&&n(a);a&&i()};a&&(document.addEventListener?(document.addEventListener("DOMContentLoaded",
k,!1),window.addEventListener("load",k,!1)):window.attachEvent&&(window.attachEvent("onload",k),self===self.top&&(c=setInterval(function(){try{document.body&&(document.documentElement.doScroll("left"),k())}catch(a){}},30))),document.readyState==="complete"&&k());f.withResources=function(a){b&&m.resourcesDone?a(e):j.push(a);return f};f.version="1.0.0";f.load=function(a,b,c,e){e.isBuild?c(null):f(c)};return f});
define("plugins/authenticationPlugin",["orion/xhr","orion/plugin","domReady!"],function(g,i){var k=new i({name:"Orion User Authentication",version:"1.0",description:"This plugin provides a user authentication service to support user verification and logout support."}),f;k.registerService("orion.core.auth",{getUser:function(){return f?f:f=g("POST","../login",{headers:{"Orion-Version":"1"},timeout:15E3}).then(function(a){return f=a.response?JSON.parse(a.response):null},function(a){f=null;return a.response?
JSON.parse(a.response):null})},logout:function(){f=null;return g("POST","../logout",{headers:{"Orion-Version":"1"},timeout:15E3}).then(function(a){f=null;return a.response?JSON.parse(a.response):null},function(a){return a.response?JSON.parse(a.response):null})},getAuthForm:function(a){var a=a?"../mixloginstatic/LoginWindow.html?redirect="+encodeURIComponent(a)+"&key=FORMOpenIdUser":"../mixloginstatic/LoginWindow.html",b=document.createElement("a");b.href=a;return b.href},getKey:function(){return"FORMOpenIdUser"},
getLabel:function(){return"Orion workspace server"}},{name:"FORM+OpenId"});k.connect()});