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