using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Web;
namespace Everest.CmsServices.Rfc.WebDAV{
internal enum WebDavUrlType
{
Root,
Application,
Folder,
Content,
}
/// <summary>
///
/// </summary>
internal class WebDavUrlData
{
string baseUrl;
public WebDavUrlData(string baseUrl, string url)
{
this.baseUrl = baseUrl;
ParseUrl(url);
}
private void ParseUrl(string url)
{
UrlType = WebDavUrlType.Root;
if (!string.IsNullOrEmpty(url))
{
string[] urlPaths = url.Split('/');
this.Application = urlPaths[0];
this.UrlType = WebDavUrlType.Application;
if (urlPaths.Length > 1)
{
this.FolderName = urlPaths[1];
this.UrlType = WebDavUrlType.Folder;
if (urlPaths.Length > 2)
{
this.ContentKey = Path.GetFileNameWithoutExtension(urlPaths[2]);
this.UrlType = WebDavUrlType.Content;
}
}
}
}
/// <summary>
/// Gets or sets the application.
/// </summary>
/// <value>The application.</value>
public string Application { get; private set; }
/// <summary>
/// Gets or sets the name of the folder.
/// </summary>
/// <value>The name of the folder.</value>
public string FolderName { get; private set; }
public string ContentKey { get; private set; }
public WebDavUrlType UrlType { get; private set; }
/// <summary>
/// Builds the next URL.
/// </summary>
/// <param name="key">The key.</param>
/// <returns></returns>
public string BuildNextUrl(string key)
{
string relativeUrl = "";
switch (UrlType)
{
case WebDavUrlType.Root:
relativeUrl = key;
break;
case WebDavUrlType.Application:
relativeUrl = string.Format("{0}/{1}", Application, key);
break;
case WebDavUrlType.Folder:
case WebDavUrlType.Content:
relativeUrl = string.Format("{0}/{1}/{2}", Application, FolderName, key);
break;
default:
break;
}
return WebDavHelper.BuildAbsoluteUrl(baseUrl, relativeUrl);
}
}
}
|