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