DavProperty.cs :  » Network-Servers » WebDAV.NET-Server » Sphorium » WebDAV » Server » Framework » Classes » C# / CSharp Open Source

Home
C# / CSharp Open Source
1.2.6.4 mono .net core
2.2.6.4 mono core
3.Aspect Oriented Frameworks
4.Bloggers
5.Build Systems
6.Business Application
7.Charting Reporting Tools
8.Chat Servers
9.Code Coverage Tools
10.Content Management Systems CMS
11.CRM ERP
12.Database
13.Development
14.Email
15.Forum
16.Game
17.GIS
18.GUI
19.IDEs
20.Installers Generators
21.Inversion of Control Dependency Injection
22.Issue Tracking
23.Logging Tools
24.Message
25.Mobile
26.Network Clients
27.Network Servers
28.Office
29.PDF
30.Persistence Frameworks
31.Portals
32.Profilers
33.Project Management
34.RSS RDF
35.Rule Engines
36.Script
37.Search Engines
38.Sound Audio
39.Source Control
40.SQL Clients
41.Template Engines
42.Testing
43.UML
44.Web Frameworks
45.Web Service
46.Web Testing
47.Wiki Engines
48.Windows Presentation Foundation
49.Workflows
50.XML Parsers
C# / C Sharp
C# / C Sharp by API
C# / CSharp Tutorial
C# / CSharp Open Source » Network Servers » WebDAV.NET Server 
WebDAV.NET Server » Sphorium » WebDAV » Server » Framework » Classes » DavProperty.cs
using System;
using System.Xml;
using System.Xml.XPath;

using Sphorium.WebDAV.Server.Framework.BaseClasses;
using Sphorium.WebDAV.Server.Framework.Collections;

namespace Sphorium.WebDAV.Server.Framework.Classes{
  /// <summary>
  /// WebDav Property.
  /// </summary>
  [Serializable]
  public class DavProperty : DavPropertyBase, ICloneable
  {
    private DavPropertyCollection __nestedProperties = new DavPropertyCollection();
    private DavPropertyAttributeCollection __attributes = new DavPropertyAttributeCollection();

    /// <summary>
    /// WebDav Property.
    /// </summary>
    public DavProperty() { }

    /// <summary>
    /// WebDav Property.
    /// </summary>
    /// <param name="property"></param>
    public DavProperty(XPathNavigator property)
    {
      if (property == null)
        throw new ArgumentNullException("property", InternalFunctions.GetResourceString("ArgumentNullException", "Property"));
      else if (property.NodeType != XPathNodeType.Element)
        throw new ArgumentException(InternalFunctions.GetResourceString("XPathNavigatorElementArgumentException", "Property"), "property");

      base.Name = property.LocalName;
      base.Namespace = property.NamespaceURI;

      if (property.HasAttributes)
      {
        //TODO: Support element attributes
        //string _here = "";
        //Add the attributes first
        //      foreach (XmlAttribute _xmlAttribute in property.Attributes)
        //        Attributes.Add(new DavPropertyAttribute(_xmlAttribute));
      }

      if (property.MoveToFirstChild())
      {
        if (property.NodeType == XPathNodeType.Element)
        {
          NestedProperties.Add(new DavProperty(property.Clone()));

          while (property.MoveToNext())
          {
            if (property.NodeType == XPathNodeType.Element)
              NestedProperties.Add(new DavProperty(property.Clone()));
          }
        }
        else if (property.NodeType == XPathNodeType.Text)
        {
          base.Value = property.Value;
          property.MoveToParent();
        }
      }
    }

    /// <summary>
    /// WebDav Property.
    /// </summary>
    /// <param name="propertyName"></param>
    /// <param name="propertyValue"></param>
    /// <param name="propertyNamespace"></param>
    public DavProperty(string propertyName, string propertyValue, string propertyNamespace)
    {
      base.Name = propertyName;
      base.Value = propertyValue;
      base.Namespace = propertyNamespace;
    }

    /// <summary>
    /// WebDav Property
    /// </summary>
    /// <param name="propertyName"></param>
    /// <param name="propertyNamespace"></param>
    public DavProperty(string propertyName, string propertyNamespace)
    {
      base.Name = propertyName;
      base.Namespace = propertyNamespace;
    }

    /// <summary>
    /// Nested Dav Properties
    /// </summary>
    public DavPropertyCollection NestedProperties
    {
      get
      {
        return this.__nestedProperties;
      }
    }

    /// <summary>
    /// Nested Dav Properties
    /// </summary>
    public DavPropertyAttributeCollection Attributes
    {
      get
      {
        return this.__attributes;
      }
    }

    internal void ToXML(XmlTextWriter xmlWriter)
    {
      xmlWriter.WriteStartElement(base.Name, base.Namespace);

      foreach (DavPropertyAttribute _propertyAttribute in Attributes)
      {
        if (_propertyAttribute.XPathAttribute != null)
          xmlWriter.WriteAttributeString(_propertyAttribute.AttributeName, _propertyAttribute.AttributeNamespace, _propertyAttribute.AttributeValue);
        else
          xmlWriter.WriteAttributeString(_propertyAttribute.AttributeNamespace + ":" + _propertyAttribute.AttributeName, _propertyAttribute.AttributeValue);
      }

      if (base.Value != null && base.Value.Length != 0)
        xmlWriter.WriteString(base.Value);

      //Append all the nested elements
      foreach (DavProperty _nestedProperty in NestedProperties)
        _nestedProperty.ToXML(xmlWriter);

      //Close the prop element section
      xmlWriter.WriteEndElement();
    }

    #region ICloneable Members
      // Explicit interface method impl
      object ICloneable.Clone()
      {
        return this.Clone();
      }

      /// <summary>
      /// DavProperty Clone
      /// </summary>
      /// <remarks>Deep copy</remarks>
      /// <returns></returns>
      public DavProperty Clone()
      {
        // Start with a flat, memberwise copy
        DavProperty _davProperty = (DavProperty)this.MemberwiseClone();

        // Then deep-copy everything that needs the 
        _davProperty.__attributes = this.Attributes.Clone();
        _davProperty.__nestedProperties = this.NestedProperties.Clone();

        return _davProperty;
      }
    #endregion
  }
}


www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.