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