/*******************************************************************************
 * @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 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) 2011 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
 ******************************************************************************/
/*

 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
 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

 Copyright (c) 2011 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(){var h=this;if(!h.define)h.define=function(b){h.orion=h.orion||{};h.orion.Deferred=b();delete h.define}})();
define("orion/Deferred",[],function(){function h(b){if(i)e?(a.next={notify:b,next:null},a=a.next):a=e={notify:b,next:null};else{i=!0;do{for(;b;){b();if(c)e?a.next=c:e=c,a=g;e?(c=e.next,g=a,b=e.notify,e=a=null):b=null}i=!1}while(i)}}function b(){function a(){for(;e;){var j=e;e=e.next;var b=j.deferred;if(j[d])try{var g=j[d](c);g&&typeof g.then==="function"?g.then(b.resolve,b.reject,b.update):b.resolve(g)}catch(i){b.reject(i)}else b[d](c)}e=f=null}var c,d,e,f;this.resolve=function(j){if(d)throw Error("'"+
d+"' already called");d="resolve";c=j;h(a)};this.reject=function(j){if(d)throw Error("'"+d+"' already called");d="reject";c=j;h(a)};this.update=this.progress=this.notify=function(a){for(var d=e;d;){if(d.update)try{d.update(a)}catch(f){}d=d.next}};this.then=function(j,c,g){j={resolve:j,reject:c,update:g,deferred:new b};e?f.next=j:e=j;f=j;d&&h(a);return j.deferred.promise};this.promise={then:this.then};this.state=function(){return d||"wait"};this.all=function(a,c){function f(a,c){d||(g[a]=c,--b===0&&
m.resolve(g))}function e(a,b){if(!d){if(c)try{f(a,c(b));return}catch(g){b=g}m.reject(b)}}var b=a.length,g=[],m=this;b===0?this.resolve(g):a.forEach(function(a,d){a.then(f.bind(null,d),e.bind(null,d))});return this.promise}}var e,a,c,g,i=!1;b.when=function(a,c,d,e){var f;if(!(a&&typeof a.then==="function"))f=new b,f.resolve(a),a=f.promise;return a.then(c,d,e)};return b});
define("orion/xhr",["orion/Deferred"],function(h){function b(b){return encodeURIComponent(b).replace(/[!'()*]/g,function(a){return"%"+a.charCodeAt(0).toString(16).toUpperCase()})}return function(e,a,c){var c=c||{},g=arguments.length>3&&arguments[3]?arguments[3]:new XMLHttpRequest,i=new h,l=c.headers||{},m=c.log||!1,d,k;typeof l["X-Requested-With"]==="undefined"&&(l["X-Requested-With"]="XMLHttpRequest");if(c.query&&typeof c.query==="object"){var f=c.query,j=Object.keys(f),n=[];for(k=0;k<j.length;k++){var o=
j[k],r=f[o];n.push(b(o)+"="+b(r))}n.length&&(f=a.split("#"),f[0]+=(f[0].indexOf("?")===-1?"?":"&")+n.join("&"),a=f.join("#"))}if(typeof c.data!=="undefined"&&(e==="POST"||e==="PUT"))d=c.data;if(typeof c.responseType==="string")g.responseType=c.responseType;g.onreadystatechange=function(){if(g.readyState===4){var d=g.status,b=typeof g.response!=="undefined"?g.response:g.responseText,b={args:c,response:b,responseText:typeof b==="string"?b:null,status:d,url:a,xhr:g};200<=d&&d<400?i.resolve(b):(m&&console&&
console.log(Error(g.statusText)),i.reject(b))}};try{g.open(e,a,!0);if(typeof c.timeout==="number")g.timeout=c.timeout,g.addEventListener("timeout",function(a){i.reject("Timeout exceeded: "+a)});var q=Object.keys(l);for(k=0;k<q.length;k++){var p=q[k];g.setRequestHeader(p,l[p])}g.send(d)}catch(s){i.reject(s)}return i}});
define("domReady",[],function(){function h(a){for(var d=0,b;b=a[d];d++)b(i)}function b(){var a=l,b=m;g&&(a.length&&(l=[],h(a)),d.resourcesDone&&b.length&&(m=[],h(b)))}function e(){g||(g=!0,f&&clearInterval(f),b())}function a(b){g?b(i):l.push(b);return a}var c=typeof window!=="undefined"&&window.document,g=!c,i=c?document:null,l=[],m=[],d=requirejs||require||{},k=d.resourcesReady,f;if("resourcesReady"in d)d.resourcesReady=function(a){k&&k(a);a&&b()};c&&(document.addEventListener?(document.addEventListener("DOMContentLoaded",
e,!1),window.addEventListener("load",e,!1)):window.attachEvent&&(window.attachEvent("onload",e),self===self.top&&(f=setInterval(function(){try{document.body&&(document.documentElement.doScroll("left"),e())}catch(a){}},30))),document.readyState==="complete"&&e());a.withResources=function(b){g&&d.resourcesDone?b(i):m.push(b);return a};a.version="1.0.0";a.load=function(b,d,c,f){f.isBuild?c(null):a(c)};return a});var eclipse=eclipse||{};
eclipse.ServiceProvider=function(h,b){this.dispatchEvent=function(e){b.dispatchEvent.apply(b,[h,e].concat(Array.prototype.slice.call(arguments,1)))};this.unregister=function(){b.unregisterServiceProvider(h)}};
eclipse.PluginProvider=function(h){function b(a){i&&(typeof ArrayBuffer==="undefined"&&(a=JSON.stringify(a)),i===self?i.postMessage(a):i.postMessage(a,"*"))}function e(a,b){return b&&b instanceof XMLHttpRequest?{status:b.status,statusText:b.statusText}:b}function a(a){if(a.source===i){var d=typeof a.data!=="string"?a.data:JSON.parse(a.data),a=c[d.serviceId].implementation,g=a[d.method],f={id:d.id,result:null,error:null};try{var j=g.apply(a,d.params);j&&typeof j.then==="function"?j.then(function(a){f.result=
a;b(f)},function(a){f.error=a?JSON.parse(JSON.stringify(a,e)):a;b(f)},function(){b({requestId:d.id,method:"progress",params:Array.prototype.slice.call(arguments)})}):(f.result=j,b(f))}catch(h){f.error=h?JSON.parse(JSON.stringify(h,e)):h,b(f)}}}var c=[],g=!1,i=null,l={dispatchEvent:function(a,d){if(!g)throw Error("Cannot dispatchEvent. Plugin Provider not connected");var c={serviceId:a,method:"dispatchEvent",params:[d].concat(Array.prototype.slice.call(arguments,2))};b(c)},unregisterServiceProvider:function(a){if(g)throw Error("Cannot unregister. Plugin Provider is connected");
c[a]=null}};this.registerServiceProvider=function(a,b,e){if(g)throw Error("Cannot register. Plugin Provider is connected");var f=null,h=[];for(f in b)typeof b[f]==="function"&&h.push(f);f=c.length;c[f]={type:a,methods:h,implementation:b,properties:e||{}};return new eclipse.ServiceProvider(f,l)};this.connect=function(e,d){if(!g){if(typeof window==="undefined")i=self;else if(window!==window.parent)i=window.parent;else if(window.opener!==null)i=window.opener;else{d&&d("No valid plugin target");return}addEventListener("message",
a,!1);for(var k=[],f=0;f<c.length;f++)c[f]&&k.push({serviceId:f,type:c[f].type,methods:c[f].methods,properties:c[f].properties});b({method:"plugin",params:[{services:k,metadata:h||{}}]});g=!0}e&&e()};this.disconnect=function(){g&&(removeEventListener("message",a),i=null,g=!1)}};define("orion/plugin",function(){});
define("plugins/authenticationPlugin",["orion/xhr","domReady!","orion/plugin"],function(h){var b=new eclipse.PluginProvider,e;b.registerServiceProvider("orion.core.auth",{getUser:function(){return e?e:e=h("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 h("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"});b.connect()});