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

 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
*/
var eclipse=eclipse||{};eclipse.ServiceProvider=function(l,k){this.dispatchEvent=function(i){k.dispatchEvent.apply(k,[l,i].concat(Array.prototype.slice.call(arguments,1)))};this.unregister=function(){k.unregisterServiceProvider(l)}};
eclipse.PluginProvider=function(l){function k(f){h&&(typeof ArrayBuffer==="undefined"&&(f=JSON.stringify(f)),h===self?h.postMessage(f):h.postMessage(f,"*"))}function i(f,c){return c&&c instanceof XMLHttpRequest?{status:c.status,statusText:c.statusText}:c}function m(f){if(f.source===h){var c=typeof f.data!=="string"?f.data:JSON.parse(f.data),f=d[c.serviceId].implementation,a=f[c.method],b={id:c.id,result:null,error:null};try{var e=a.apply(f,c.params);e&&typeof e.then==="function"?e.then(function(a){b.result=
a;k(b)},function(a){b.error=a?JSON.parse(JSON.stringify(a,i)):a;k(b)},function(){k({requestId:c.id,method:"progress",params:Array.prototype.slice.call(arguments)})}):(b.result=e,k(b))}catch(j){b.error=j?JSON.parse(JSON.stringify(j,i)):j,k(b)}}}var d=[],g=!1,h=null,n={dispatchEvent:function(f,c){if(!g)throw Error("Cannot dispatchEvent. Plugin Provider not connected");var a={serviceId:f,method:"dispatchEvent",params:[c].concat(Array.prototype.slice.call(arguments,2))};k(a)},unregisterServiceProvider:function(f){if(g)throw Error("Cannot unregister. Plugin Provider is connected");
d[f]=null}};this.registerServiceProvider=function(f,c,a){if(g)throw Error("Cannot register. Plugin Provider is connected");var b=null,e=[];for(b in c)typeof c[b]==="function"&&e.push(b);b=d.length;d[b]={type:f,methods:e,implementation:c,properties:a||{}};return new eclipse.ServiceProvider(b,n)};this.connect=function(f,c){if(!g){if(typeof window==="undefined")h=self;else if(window!==window.parent)h=window.parent;else if(window.opener!==null)h=window.opener;else{c&&c("No valid plugin target");return}addEventListener("message",
m,!1);for(var a=[],b=0;b<d.length;b++)d[b]&&a.push({serviceId:b,type:d[b].type,methods:d[b].methods,properties:d[b].properties});k({method:"plugin",params:[{services:a,metadata:l||{}}]});g=!0}f&&f()};this.disconnect=function(){g&&(removeEventListener("message",m),h=null,g=!1)}};define("orion/plugin.js",function(){});(function(){var l=this;if(!l.define)l.define=function(k){l.orion=l.orion||{};l.orion.Deferred=k();delete l.define}})();
define("orion/Deferred",[],function(){function l(n){if(h)i?(m.next={notify:n,next:null},m=m.next):m=i={notify:n,next:null};else{h=!0;do{for(;n;){n();if(d)i?m.next=d:i=d,m=g;i?(d=i.next,g=m,n=i.notify,i=m=null):n=null}h=!1}while(h)}}function k(){function d(){for(;a;){var e=a;a=a.next;var j=e.deferred;if(e[c])try{var o=e[c](f);o&&typeof o.then==="function"?o.then(j.resolve,j.reject,j.update):j.resolve(o)}catch(g){j.reject(g)}else j[c](f)}a=b=null}var f,c,a,b;this.resolve=function(a){if(c)throw Error("'"+
c+"' already called");c="resolve";f=a;l(d)};this.reject=function(a){if(c)throw Error("'"+c+"' already called");c="reject";f=a;l(d)};this.update=this.progress=this.notify=function(b){for(var j=a;j;){if(j.update)try{j.update(b)}catch(c){}j=j.next}};this.then=function(e,j,o){e={resolve:e,reject:j,update:o,deferred:new k};a?b.next=e:a=e;b=e;c&&l(d);return e.deferred.promise};this.promise={then:this.then};this.state=function(){return c||"wait"};this.all=function(a,b){function o(a,b){c||(g[a]=b,--f===0&&
h.resolve(g))}function d(a,e){if(!c){if(b)try{o(a,b(e));return}catch(f){e=f}h.reject(e)}}var f=a.length,g=[],h=this;f===0?this.resolve(g):a.forEach(function(a,b){a.then(o.bind(null,b),d.bind(null,b))});return this.promise}}var i,m,d,g,h=!1;k.when=function(d,f,c,a){var b;if(!(d&&typeof d.then==="function"))b=new k,b.resolve(d),d=b.promise;return d.then(f,c,a)};return k});
define("orion/xhr",["orion/Deferred"],function(l){function k(i){return encodeURIComponent(i).replace(/[!'()*]/g,function(i){return"%"+i.charCodeAt(0).toString(16).toUpperCase()})}return function(i,m,d){var d=d||{},g=arguments.length>3&&arguments[3]?arguments[3]:new XMLHttpRequest,h=new l,n=d.headers||{},f=d.log||!1,c,a;typeof n["X-Requested-With"]==="undefined"&&(n["X-Requested-With"]="XMLHttpRequest");if(d.query&&typeof d.query==="object"){var b=d.query,e=Object.keys(b),j=[];for(a=0;a<e.length;a++){var o=
e[a],r=b[o];j.push(k(o)+"="+k(r))}j.length&&(b=m.split("#"),b[0]+=(b[0].indexOf("?")===-1?"?":"&")+j.join("&"),m=b.join("#"))}if(typeof d.data!=="undefined"&&(i==="POST"||i==="PUT"))c=d.data;if(typeof d.responseType==="string")g.responseType=d.responseType;g.onreadystatechange=function(){if(g.readyState===4){var a=g.status,b=typeof g.response!=="undefined"?g.response:g.responseText,b={args:d,response:b,responseText:typeof b==="string"?b:null,status:a,url:m,xhr:g};200<=a&&a<400?h.resolve(b):(f&&console&&
console.log(Error(g.statusText)),h.reject(b))}};try{g.open(i,m,!0);if(typeof d.timeout==="number")g.timeout=d.timeout,g.addEventListener("timeout",function(a){h.reject("Timeout exceeded: "+a)});var q=Object.keys(n);for(a=0;a<q.length;a++){var p=q[a];g.setRequestHeader(p,n[p])}g.send(c)}catch(s){h.reject(s)}return h}});
define("plugins/site/siteServiceImpl",["require","orion/xhr"],function(l,k){function i(a){var b=document.createElement("a");b.href=a;return b.href}function m(){var a=l.toUrl("._"),a=i(a);return a.substring(0,a.length-2)}function d(a){return a.indexOf(":")!==-1?a.substring(a.indexOf(window.location.host)+window.location.host.length):a}function g(a,b){for(var e,j=a.split("/"),c=j[1],d=0;d<b.length;d++){var f=b[d];if(f.Id===c){j[1]=f.Name;e=j.join("/");break}}return e}function h(a,b,e){if(e&&typeof e.data!==
"undefined")e.data=JSON.stringify(e.data);return k.apply(null,Array.prototype.slice.call(arguments)).then(function(a){return JSON.parse(a.response||null)})}function n(a){this.projects={};this.getProjects=function(b){var e={"Orion-Version":"1"};this.projects[b]||(this.projects[b]=h("GET",a,{headers:e}).then(function(a){for(var a=a.Workspaces,c,d=0;d<a.length;d++)if(c=a[d],c.Id===b)break;return h("GET",c.Location,{headers:e}).then(function(a){return a.Children||[]})}));return this.projects[b]}}function f(a){var b=
"http://localhost:8080"+d(m());return[["/",a+"/bundles/org.eclipse.orion.client.core/web/index.html"],["/",a+"/bundles/org.eclipse.orion.client.core/web"],["/",a+"/bundles/org.eclipse.orion.client.editor/web"],["/org.dojotoolkit/dojo",a+"/bundles/org.eclipse.orion.client.core/web/dojo"],["/org.dojotoolkit/dojox",a+"/bundles/org.eclipse.orion.client.core/web/dojox"],["/file",b+"file"],["/prefs",b+"prefs"],["/workspace",b+"workspace"],["/org.dojotoolkit",b+"org.dojotoolkit"],["/users",b+"users"],["/authenticationPlugin.html",
b+"authenticationPlugin.html"],["/login",b+"login"],["/loginstatic",b+"loginstatic"],["/site",b+"site"],["/",a+"/bundles/org.eclipse.orion.client.git/web"],["/gitapi",b+"gitapi"],["/",a+"/bundles/org.eclipse.orion.client.users/web"],["/xfer",b+"xfer"],["/filesearch",b+"filesearch"],["/index.jsp",b+"index.jsp"],["/plugins/git",b+"plugins/git"],["/plugins/user",b+"plugins/user"],["/logout",b+"logout"],["/mixlogin/manageopenids",b+"mixlogin/manageopenids"],["/openids",b+"openids"],["/task",b+"task"],
["/help",b+"help"]].map(function(a){return{Source:a[0],Target:a[1]}})}function c(a,b){this.filePrefix=a;this.cache=new n(b)}c.prototype={getSiteConfigurations:function(){var a=l.toUrl("site._"),a=a.substring(0,a.length-2);return h("GET",a,{headers:{"Orion-Version":"1"},timeout:15E3}).then(function(a){return a.SiteConfigurations})},loadSiteConfiguration:function(a){return h("GET",a,{headers:{"Orion-Version":"1"},timeout:15E3})},createSiteConfiguration:function(a,b,e,c,d){a={Name:a,Workspace:b,HostHint:a.replace(/ /g,
"-").replace(/[^A-Za-z0-9-_]/g,"").toLowerCase()};if(e)a.Mappings=e;if(c)a.HostHint=c;if(d)a.HostingStatus=d;e=l.toUrl("site._");e=e.substring(0,e.length-2);return h("POST",e,{data:a,headers:{"Content-Type":"application/json; charset=utf-8","Orion-Version":"1"},timeout:15E3})},updateSiteConfiguration:function(a,b){return h("PUT",a,{data:b,headers:{"Content-Type":"application/json; charset=utf-8","Orion-Version":"1"},timeout:15E3})},deleteSiteConfiguration:function(a){return h("DELETE",a,{headers:{"Orion-Version":"1"},
timeout:15E3})},toInternalForm:function(a){var b=d(this.filePrefix),a=d(a),e;a.indexOf(b)===0&&(e=a.substring(b.length));e[e.length-1]==="/"&&(e=e.substring(0,e.length-1));return e},toFileLocation:function(a){var b=l.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(i(b))},getMappingObject:function(a,b,e){var c=this.toInternalForm(b);return this.cache.getProjects(a.Workspace).then(function(a){a=
g(c,a);return{Source:e,Target:c,FriendlyPath:a||e}})},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 e=a.Mappings,c=0;c<e.length;c++){var d=e[c];if(/^\//.test(d.Target))d.FriendlyPath=g(d.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 f=a[d];if(c[1]===f.Name)return c[1]=f.Id,c.join("/")}}):null},isSelfHostingSite:function(a){var b=this;return this.cache.getProjects(a.Workspace).then(function(c){return c.some(function(c){for(var c=b.toInternalForm(c.Location),c=f(c),d=0;d<c.length;d++){var e;a:{e=a.Mappings;for(var g=c[d],h=0;h<e.length;h++){var i=e[h];if(i.Source===g.Source||i.Target===g.Target){e=!0;break a}}e=
!1}if(!e)return!1}return!0})})},convertToSelfHosting:function(a,b){var c=this.toInternalForm(b),c=f(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:c}});
define("plugins/site/sitePlugin",["../../orion/plugin.js","plugins/site/siteServiceImpl"],function(l,k){function i(c){var a=document.createElement("a");a.href=c;c=a.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(b){}return c}function m(c){return[{source:"Location|Directory"},{source:"Location",match:"^"+c}]}var d=i("../../site"),g=i("../../file"),
h=i("../../workspace"),n=new eclipse.PluginProvider;n.registerServiceProvider("orion.navigate.command",null,{id:"orion.site.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:m(g),uriTemplate:"{OrionHome}/sites/view.html#,file={Location}"});n.registerServiceProvider("orion.page.link.related",null,{id:"orion.site.viewon",nameKey:"View on Site",tooltipKey:"View this file or folder on a web site hosted by Orion",
nls:"orion/nls/messages",validationProperties:m(g),uriTemplate:"{OrionHome}/sites/view.html#,file={Location}"});var f=document.createElement("a");f.href="/";n.registerServiceProvider("orion.site",new k.SiteImpl(g,h),{id:"orion.site.default",name:""+f.hostname+" Orion file system",canSelfHost:!0,pattern:d,filePattern:g});n.connect()});