using System;
using WebDAVSharp.Server.Exceptions;
namespace WebDAVSharp.Server.Stores.BaseClasses {
///
/// This is the base class for implementations.
///
public class WebDavStoreItemBase : IWebDavStoreItem {
private readonly IWebDavStoreCollection _parentCollection;
private string _name;
///
/// Initializes a new instance of the class.
///
/// The parent that contains this implementation.
/// The name of this
/// name
/// is null.
protected WebDavStoreItemBase(IWebDavStoreCollection parentCollection, string name) {
//if (String.IsNullOrWhiteSpace(name))
// throw new ArgumentNullException("name");
_parentCollection = parentCollection;
_name = name;
}
#region IWebDAVStoreItem Members
///
/// Gets the parent that owns this .
///
public IWebDavStoreCollection ParentCollection {
get {
return _parentCollection;
}
}
///
/// Gets or sets the name of this .
///
///
public string Name {
get {
return _name;
}
set {
string fixedName = (value ?? string.Empty).Trim();
if (fixedName == _name) return;
if (!OnNameChanging(_name, fixedName))
throw new WebDavForbiddenException();
string oldName = _name;
_name = fixedName;
OnNameChanged(oldName, _name);
}
}
///
/// Gets the creation date of this .
///
public virtual DateTime CreationDate {
get {
return DateTime.Now;
}
}
///
/// Gets the modification date of this .
///
public virtual DateTime ModificationDate {
get {
return DateTime.Now;
}
}
///
/// Gets the path to this .
///
public virtual string ItemPath {
get { return String.Empty; }
}
///
/// Gets if this is a collection.
///
public bool IsCollection {
get {
return true;
}
}
///
/// Gets the hidden state of this .
///
public int Hidden {
get {
return 0;
}
}
#endregion
///
/// Called before the name of this is changing.
///
/// The old name of this .
/// The new name of this .
///
/// true if the name change is allowed;
/// otherwise,
/// false.
///
protected virtual bool OnNameChanging(string oldName, string newName) {
return true;
}
///
/// Called after the name of this has changed.
///
/// The old name of this .
/// The new name of this .
protected virtual void OnNameChanged(string oldName, string newName) {
}
}
}