(function(c,k){"function"===typeof define&&define.amd?define("orion/Deferred",k):"object"===typeof exports?module.exports=k():(c.orion=c.orion||{},c.orion.Deferred=k())})(this,function(){function c(){for(var h;h=d.shift();)h();f=!1}function k(h){d.push(h);f||(f=!0,g())}function p(d){return function(c){d(c)}}function l(){function d(){for(var b;b=e.shift();){var a=b.deferred,c="fulfilled"===m?"resolve":"reject";b=b[c];if("function"===typeof b)try{var h=b(r),f=h&&("object"===typeof h||"function"===typeof h)&&
h.then;if("function"===typeof f)if(h===a.promise)a.reject(new TypeError);else{var g=h.cancel;"function"===typeof g?a._parentCancel=g.bind(h):delete a._parentCancel;f.call(h,p(a.resolve),p(a.reject),p(a.progress))}else a.resolve(h)}catch(l){a.reject(l)}else a[c](r)}}function c(b){delete a._parentCancel;m="rejected";r=b;e.length&&k(d)}function f(b){function q(a){return function(b){(!m||"assumed"===m)&&a(b)}}delete a._parentCancel;try{var t=b&&("object"===typeof b||"function"===typeof b)&&b.then;if("function"===
typeof t)if(b===a)c(new TypeError);else{m="assumed";var g=b&&b.cancel;if("function"!==typeof g){var p=new l;b=p.promise;try{t(p.resolve,p.reject,p.progress)}catch(v){p.reject(v)}g=b.cancel;t=b.then}r=b;t.call(b,q(f),q(c));a._parentCancel=g.bind(b)}else m="fulfilled",r=b,e.length&&k(d)}catch(u){q(c)(u)}}function g(){var b=a._parentCancel;b?(delete a._parentCancel,b()):m||(b=Error("Cancel"),b.name="Cancel",c(b))}var r,m,e=[],a=this;this.resolve=function(b){m||f(b);return a};this.reject=function(b){m||
c(b);return a};this.progress=function(b){m||e.forEach(function(a){if(a.progress)try{a.progress(b)}catch(e){}});return a.promise};this.cancel=function(){a._parentCancel?setTimeout(g,0):g();return a};this.then=function(b,q,c){var f=new l;f._parentCancel=a.promise.cancel;e.push({resolve:b,reject:q,progress:c,deferred:f});("fulfilled"===m||"rejected"===m)&&k(d);return f.promise};this.promise={then:a.then,cancel:a.cancel}}var d=[],f=!1,g=function(){if("undefined"!==typeof process&&"function"===typeof process.nextTick){var d=
process.nextTick;return function(){d(c)}}if("function"===typeof MutationObserver){var f=document.createElement("div");(new MutationObserver(c)).observe(f,{attributes:!0});return function(){f.setAttribute("class","_tick")}}return function(){setTimeout(c,0)}}();l.all=function(d,c){function f(b,d){e||(m[b]=d,0===--k&&a.resolve(m))}function g(b,d){if(!e){if(c)try{f(b,c(d));return}catch(h){d=h}a.reject(d)}}var k=d.length,m=[],e=!1,a=new l;a.then(void 0,function(){e=!0;d.forEach(function(a){a.cancel&&a.cancel()})});
0===k?a.resolve(m):d.forEach(function(a,e){a.then(f.bind(void 0,e),g.bind(void 0,e))});return a.promise};l.when=function(d,c,f,g){var k;d&&"function"===typeof d.then||(k=new l,k.resolve(d),d=k.promise);return d.then(c,f,g)};return l});
(function(c,k){"function"===typeof define&&define.amd?define("orion/plugin",["orion/Deferred"],k):"object"===typeof exports?module.exports=k(require("orion/Deferred")):(c.orion=c.orion||{},c.orion.PluginProvider=k(c.orion.Deferred))})(this,function(c){function k(c,l){this.__objectId=c;this.__methods=l}return function(p){function l(a){e&&("undefined"===typeof ArrayBuffer&&(a=JSON.stringify(a)),e===self?e.postMessage(a):e.postMessage(a,"*"))}function d(){var a=[];Object.keys(x).forEach(function(b){var e=
x[b];a.push({serviceId:b,names:e.names,methods:e.methods,properties:e.properties})});return{headers:r||{},services:a}}function f(a,b){if(b&&b instanceof XMLHttpRequest){var e,d;try{e=b.status,d=b.statusText}catch(c){e=0,d=""}return{status:e||0,statusText:d}}return b}function g(a){var b=a?JSON.parse(JSON.stringify(a,f)):a;a instanceof Error&&(b.__isError=!0,b.message=b.message||a.message,b.name=b.name||a.name);return b}function h(d){if(!e)return(new c).reject(Error("plugin not connected"));d.id=String(a++);
var f=new c;w[d.id]=f;f.then(null,function(a){m&&a instanceof Error&&"Cancel"===a.name&&u({requestId:d.id,method:"cancel",params:a.message?[a.message]:[]})});var g=Object.prototype.toString;d.params.forEach(function(a,e){if("[object Object]"===g.call(a)&&!(a instanceof k)){var c,q;for(c in a)"[object Function]"===g.call(a[c])&&(q=q||[],q.push(c));if(q){var h=b++;y[h]=a;c=function(){delete y[h]};f.then(c,c);d.params[e]=new k(h,q)}}});u(d);return f.promise}function n(a,b){a||0===a?u({id:a,result:null,
error:b}):console.log(b)}function s(a,b,e,d){d.forEach(function(a,b){if(a&&"undefined"!==typeof a.__objectId){var e={};a.__methods.forEach(function(b){e[b]=function(){return h({objectId:a.__objectId,method:b,params:Array.prototype.slice.call(arguments)})}});d[b]=e}});var c=void 0===typeof a?null:{id:a,result:null,error:null};try{var f=e.apply(b,d);c&&(f&&"function"===typeof f.then?(t[a]=f,f.then(function(b){delete t[a];c.result=b;u(c)},function(b){t[a]&&(delete t[a],c.error=g(b),u(c))},function(){u({responseId:a,
method:"progress",params:Array.prototype.slice.call(arguments)})})):(c.result=f,u(c)))}catch(q){c&&(c.error=g(q),u(c))}}function v(a){if(!(a.source!==e&&"undefined"!==typeof window)){a="string"!==typeof a.data?a.data:JSON.parse(a.data);try{if(a.method){var b=a.method,d=a.params||[];if("serviceId"in a){var c=x[a.serviceId];c||n(a.id,"service not found");c=c.implementation;b in c?s(a.id,c,c[b],d):n(a.id,"method not found")}else if("objectId"in a){var f=y[a.objectId];f||n(a.id,"object not found");!b in
f?s(a.id,f,f[b],d):n(a.id,"method not found")}else if("requestId"in a){var q=t[a.requestId];q&&"cancel"===b&&q.cancel&&q.cancel.apply(q,d)}else if("responseId"in a){var g=w[a.responseId];g&&"progress"===b&&g.progress&&g.progress.apply(g,d)}else throw Error("Bad method: "+a.method);}else{var h=w[String(a.id)];delete w[String(a.id)];a.error?h.reject(a.error):h.resolve(a.result)}}catch(l){console.log("Plugin._messageHandler "+l)}}}var r=p,m=!1,e=null,a=0,b=0,q=0,t={},w={},y={},x={},u=l;this.updateHeaders=
function(a){if(m)throw Error("Cannot update headers. Plugin Provider is connected");r=a};this.registerServiceProvider=this.registerService=function(a,b,e){if(m)throw Error("Cannot register service. Plugin Provider is connected");"string"===typeof a?a=[a]:Array.isArray(a)||(a=[]);var d=null,c=[];for(d in b)"function"===typeof b[d]&&c.push(d);x[q++]={names:a,methods:c,implementation:b,properties:e||{},listeners:{}}};this.connect=function(a,b){if(!m){if("undefined"===typeof window)e=self;else if(window!==
window.parent)e=window.parent;else if(null!==window.opener)e=window.opener;else{b&&b("No valid plugin target");return}addEventListener("message",v,!1);var c={method:"plugin",params:[d()]};l(c);m=!0}a&&a()};this.disconnect=function(){m&&(removeEventListener("message",v),e=null,m=!1)}}});
define("orion/i18nUtil",["require","orion/Deferred"],function(c,k){function p(d){if(d=localStorage.getItem("orion/messageBundle/"+d))if(d=JSON.parse(d),d._expires&&d._expires>(new Date).getTime())return delete d._expires,d;return null}var l={};return{getMessageBundle:function(d){function f(f){f?c(["i18n!"+d],function(c){if(c){var f=d;c._expires=(new Date).getTime()+9E5;localStorage.setItem("orion/messageBundle/"+f,JSON.stringify(c));delete c._expires}h.resolve(c)}):g(Error(d))}function g(d){h.reject(d)}
if(l[d])return l[d];var h=new k;l[d]=h;var n=p(d);if(n)return h.resolve(n),h;try{c([d],f,g)}catch(s){c(["orion/i18n!"+d],f,g)}return h},formatMessage:function(d){var c=arguments;return d.replace(/\$\{([^\}]+)\}/g,function(d,h){return c[(h<<0)+1]})}}});
define("orion/xhr",["orion/Deferred"],function(c){function k(c,l,d,f){var g="undefined"!==typeof d.response?d.response:d.responseText,h;try{h=d.status}catch(k){h=0}c={args:l,response:g,responseText:"string"===typeof g?g:null,status:h,url:c,xhr:d};"undefined"!==typeof f&&(c.error=f);return c}return function(p,l,d){d=d||{};var f=3<arguments.length&&arguments[3]?arguments[3]:new XMLHttpRequest,g=new c,h=d.headers||{},n=d.log||!1,s;"undefined"===typeof h["X-Requested-With"]&&(h["X-Requested-With"]="XMLHttpRequest");
if("undefined"!==typeof d.data&&("POST"===p||"PUT"===p))s=d.data;var v=!1,r=!1;g.promise.then(void 0,function(a){v=!0;!r&&a instanceof Error&&"Cancel"===a.name&&f.abort()});f.onabort=function(){r=!0;if(!v){var a=Error("Cancel");a.name="Cancel";g.reject(a)}};f.onload=function(){var a=k(l,d,f);200<=f.status&&400>f.status?g.resolve(a):(g.reject(a),n&&"undefined"!==typeof console&&console.log(Error(f.statusText)))};f.onerror=function(){var a=k(l,d,f);g.reject(a);n&&"undefined"!==typeof console&&console.log(Error(f.statusText))};
f.onprogress=function(a){a.xhr=f;g.progress(a)};try{f.open(p,l,!0);"string"===typeof d.responseType&&(f.responseType=d.responseType);if("number"===typeof d.timeout)if("number"===typeof f.timeout)f.timeout=d.timeout,f.addEventListener("timeout",function(a){g.reject(k(l,d,f,"Timeout exceeded"))});else{var m=setTimeout(function(){g.reject(k(l,d,f,"Timeout exceeded"))},d.timeout);g.promise.then(clearTimeout.bind(null,m),clearTimeout.bind(null,m))}Object.keys(h).forEach(function(a){f.setRequestHeader(a,
h[a])});f.send(s||null)}catch(e){g.reject(k(l,d,f,e))}return g.promise}});define("orion/regex",[],function(){return{escape:function(c){return c.replace(/([\\$\^*\/+?\.\(\)|{}\[\]])/g,"\\$\x26")},parse:function(c){return(c=/^\s*\/(.+)\/([gim]{0,3})\s*$/.exec(c))?{pattern:c[1],flags:c[2]}:null}}});
define("plugins/site/siteServiceImpl",["require","orion/i18nUtil","orion/xhr","orion/regex"],function(c,k,p,l){function d(e){var a=document.createElement("a");a.href=e;return a.href}function f(){var e=c.toUrl("._"),e=d(e);return e.substring(0,e.length-2)}function g(e){return-1!==e.indexOf(":")?e.substring(e.indexOf(window.location.host)+window.location.host.length):e}function h(e){e&&"object"===typeof e&&Object.keys(e).forEach(function(a){var b=e[a];-1!==a.indexOf("Location")?(m.href=b,e[a]=m.href):
h(b)});return e}function n(e,a){for(var b,c=e.split("/"),d=c[1],f=0;f<a.length;f++){var g=a[f];if(g.Id===d){c[1]=g.Name;b=c.join("/");break}}return b}function s(e,a,b){b&&"undefined"!==typeof b.data&&(b.data=JSON.stringify(b.data));return p.apply(null,Array.prototype.slice.call(arguments)).then(function(a){return JSON.parse(a.response||null)})}function v(e){this.projects={};this.getProjects=function(a){var b={"Orion-Version":"1"};this.projects[a]||(this.projects[a]=s("GET",e,{headers:b}).then(function(e){e=
e.Workspaces;for(var c,d=0;d<e.length&&!(c=e[d],c.Id===a);d++);return s("GET",c.Location,{headers:b}).then(function(a){return a.Children||[]})}));return this.projects[a]}}function r(e,a,b){this.filePrefix=e;this.cache=new v(a);this.makeAbsolute=a&&-1!==a.indexOf("://");this.selfHostingRules=b;var c=b.Rules,d=b.Types.File,h=b.Types.API;this._generateSelfHostingMappings=function(a){var b="http://localhost"+g(f());return c.map(function(e){var c;c=e.type===d?k.formatMessage.apply(k,[e.targetPattern].concat(a)):
k.formatMessage(e.targetPattern,b);return{Source:e.source,Target:c}})};this._matchesSelfHostingTemplate=function(a,b){var e=/(\$\{[^}]+?\})/,k=l.escape("http://localhost")+"(:\\d+)?"+l.escape(g(f()));return c.every(function(c){return b.Mappings.some(function(b){if(b.Source===c.source){var f;c.type===d?f=l.escape(a)+".*?":c.type===h&&(f=k);var g=[];c.targetPattern.split(e).forEach(function(a){e.test(a)?g.push(f):g.push(l.escape(a))});return RegExp(g.join("")).test(b.Target)}return!1})})}}var m=document.createElement("a");
r.prototype={getSiteConfigurations:function(){var e=c.toUrl("site._"),e=e.substring(0,e.length-2);return s("GET",e,{headers:{"Orion-Version":"1"},timeout:15E3}).then(function(a){return a.SiteConfigurations}).then(function(a){this.makeAbsolute&&h(a);return a}.bind(this))},loadSiteConfiguration:function(e){return s("GET",e,{headers:{"Orion-Version":"1"},timeout:15E3}).then(function(a){this.makeAbsolute&&h(a);return a}.bind(this))},createSiteConfiguration:function(e,a,b,d,f){e={Name:e,Workspace:a,HostHint:e.replace(/ /g,
"-").replace(/[^A-Za-z0-9-_]/g,"").toLowerCase()};b&&(e.Mappings=b);d&&(e.HostHint=d);f&&(e.HostingStatus=f);b=c.toUrl("site._");b=b.substring(0,b.length-2);return s("POST",b,{data:e,headers:{"Content-Type":"application/json; charset\x3dutf-8","Orion-Version":"1"},timeout:15E3}).then(function(a){this.makeAbsolute&&h(a);return a}.bind(this))},updateSiteConfiguration:function(e,a){return s("PUT",e,{data:a,headers:{"Content-Type":"application/json; charset\x3dutf-8","Orion-Version":"1"},timeout:15E3}).then(function(a){this.makeAbsolute&&
h(a);return a}.bind(this))},deleteSiteConfiguration:function(e){return s("DELETE",e,{headers:{"Orion-Version":"1"},timeout:15E3}).then(function(a){this.makeAbsolute&&h(a);return a}.bind(this))},toInternalForm:function(e){var a=g(this.filePrefix);e=g(e);var b;0===e.indexOf(a)&&(b=e.substring(a.length));"/"===b[b.length-1]&&(b=b.substring(0,b.length-1));return b},toFileLocation:function(e){var a=c.toUrl(this.filePrefix+e+"._"),a=a.substring(0,a.length-2);1===function(a){return a.filter(function(a){return""!==
a})}(e.split("/")).length&&(a+="/");return g(d(a))},getMappingObject:function(e,a,b){var c=this.toInternalForm(a);return this.cache.getProjects(e.Workspace).then(function(a){a=n(c,a);return{Source:b,Target:c,FriendlyPath:a||b}})},getMappingProposals:function(c){var a=this;return this.cache.getProjects(c.Workspace).then(function(b){return b.map(function(b){return{Source:"/"+b.Name,Target:a.toInternalForm(b.Location),FriendlyPath:"/"+b.Name}})})},updateMappingsDisplayStrings:function(c){return this.cache.getProjects(c.Workspace).then(function(a){for(var b=
c.Mappings,d=0;d<b.length;d++){var f=b[d];/^\//.test(f.Target)&&(f.FriendlyPath=n(f.Target,a))}return c})},parseInternalForm:function(c,a){return/^\//.test(a)?this.cache.getProjects(c.Workspace).then(function(b){for(var c=a.split("/"),d=0;d<b.length;d++){var e=b[d];if(c[1]===e.Name)return c[1]=e.Id,c.join("/")}}):null},isSelfHostingSite:function(c){var a=this;return this.cache.getProjects(c.Workspace).then(function(b){return b.some(function(b){b=a.toInternalForm(b.Location);return a._matchesSelfHostingTemplate(b,
c)})})},convertToSelfHosting:function(c,a){var b=a.map(this.toInternalForm.bind(this)),b=this._generateSelfHostingMappings(b);c.Mappings=b;return c},getURLOnSite:function(c,a){var b=c.Mappings,d=this.toInternalForm(a.Location);if(!b)return null;for(var f=0;f<b.length;f++){var g=b[f];if(g.Target===d)return c.HostingStatus.URL+("/"!==g.Source[0]?"/":"")+g.Source+(a.Directory?"/":"")}return null}};return{SiteImpl:r}});
define("plugins/site/selfHostingRules",[],function(){return{Rules:[{type:0,source:"/",targetPattern:"${0}/bundles/org.eclipse.orion.client.ui/web/index.html"},{type:0,source:"/",targetPattern:"${0}/bundles/org.eclipse.orion.client.ui/web"},{type:0,source:"/",targetPattern:"${0}/bundles/org.eclipse.orion.client.core/web"},{type:0,source:"/",targetPattern:"${0}/bundles/org.eclipse.orion.client.editor/web"},{type:0,source:"/",targetPattern:"${0}/bundles/org.eclipse.orion.client.cf/web"},{type:1,source:"/file",
targetPattern:"${0}file"},{type:1,source:"/prefs",targetPattern:"${0}prefs"},{type:1,source:"/workspace",targetPattern:"${0}workspace"},{type:1,source:"/users",targetPattern:"${0}users"},{type:1,source:"/authenticationPlugin.html",targetPattern:"${0}authenticationPlugin.html"},{type:1,source:"/login",targetPattern:"${0}login"},{type:1,source:"/loginstatic",targetPattern:"${0}loginstatic"},{type:1,source:"/useremailconfirmation",targetPattern:"${0}useremailconfirmation"},{type:1,source:"/site",targetPattern:"${0}site"},
{type:0,source:"/",targetPattern:"${0}/bundles/org.eclipse.orion.client.git/web"},{type:0,source:"/",targetPattern:"${0}/bundles/org.eclipse.orion.client.javascript/web"},{type:1,source:"/gitapi",targetPattern:"${0}gitapi"},{type:0,source:"/",targetPattern:"${0}/bundles/org.eclipse.orion.client.users/web"},{type:1,source:"/xfer",targetPattern:"${0}xfer"},{type:1,source:"/filesearch",targetPattern:"${0}filesearch"},{type:1,source:"/index.jsp",targetPattern:"${0}index.jsp"},{type:1,source:"/plugins/git",
targetPattern:"${0}plugins/git"},{type:1,source:"/plugins/user",targetPattern:"${0}plugins/user"},{type:1,source:"/logout",targetPattern:"${0}logout"},{type:1,source:"/mixlogin/manageopenids",targetPattern:"${0}mixlogin/manageopenids"},{type:1,source:"/openids",targetPattern:"${0}openids"},{type:1,source:"/task",targetPattern:"${0}task"},{type:1,source:"/help",targetPattern:"${0}help"},{type:1,source:"/docker",targetPattern:"${0}docker"}],Types:{File:0,API:1}}});
define("built-sitePlugin.js",["orion/plugin","plugins/site/siteServiceImpl","plugins/site/selfHostingRules"],function(c,k,p){function l(c){var d=document.createElement("a");d.href=c;c=d.href;try{if(window.location.host===parent.location.host&&window.location.protocol===parent.location.protocol)return c.substring(parent.location.href.indexOf(parent.location.host)+parent.location.host.length)}catch(f){}return c}function d(c){return[{source:"Location|Directory"},{source:"Location",match:"^"+c}]}var f=
l("../../site"),g=l("../../file"),h=l("../../workspace"),n=document.createElement("a");n.href="../../mixloginstatic/LoginWindow.html";c=new c({name:"Orion Site Service",version:"1.0",description:"This plugin provides virtual site support for hosting client web applications from your Orion workspace.",login:n.href});n=document.createElement("a");n.href="/";c.registerService("orion.page.link.category",null,{id:"sites",nameKey:"Sites",nls:"orion/nls/messages",imageClass:"core-sprite-sites",order:50,
uriTemplate:"{+OrionHome}/sites/"});c.registerService("orion.page.link",null,{nameKey:"Sites",id:"orion.sites",nls:"orion/nls/messages",category:"sites","default":!0,order:10,uriTemplate:"{+OrionHome}/sites/sites.html"});c.registerService("orion.page.link",null,{nameKey:"Sites",id:"orion.sites.2",nls:"orion/nls/messages",category:"sites",order:10,uriTemplate:"{+OrionHome}/sites/sites.html"});c.registerService("orion.navigate.command",null,{id:"orion.site."+n.hostname+".viewon",nameKey:"View on Site",
tooltipKey:"View this file or folder on a web site hosted by Orion",nls:"orion/nls/messages",forceSingleItem:!0,category:"sites",validationProperties:d(g),uriTemplate:"{+OrionHome}/sites/view.html#,file\x3d{,Location}"});c.registerService("orion.page.link.related",null,{id:"orion.site."+n.hostname+".viewon",nameKey:"View on Site",tooltipKey:"View this file or folder on a web site hosted by Orion",nls:"orion/nls/messages",category:"sites",validationProperties:d(g),uriTemplate:"{+OrionHome}/sites/view.html#,file\x3d{,Location}"});
c.registerService("orion.site",new k.SiteImpl(g,h,p),{id:"orion.site."+n.hostname,name:"Orion Sites at "+n.hostname,pattern:f,filePattern:g,canSelfHost:!0,selfHostingConfig:{folders:[{name:"org.eclipse.orion.client",labelKey:"orionClientLabel",nls:"orion/sites/nls/messages"}]}});c.connect()});
//@ sourceMappingURL=built-sitePlugin.js.map