Roster.cs :  » Network-Clients » Jabber-Net » jabber » protocol » iq » 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 Clients » Jabber Net 
Jabber Net » jabber » protocol » iq » Roster.cs
/* --------------------------------------------------------------------------
 *
 * License
 *
 * The contents of this file are subject to the Jabber Open Source License
 * Version 1.0 (the "License").  You may not copy or use this file, in either
 * source code or executable form, except in compliance with the License.  You
 * may obtain a copy of the License at http://www.jabber.com/license/ or at
 * http://www.opensource.org/.  
 *
 * Software distributed under the License is distributed on an "AS IS" basis,
 * WITHOUT WARRANTY OF ANY KIND, either express or implied.  See the License
 * for the specific language governing rights and limitations under the
 * License.
 *
 * Copyrights
 * 
 * Portions created by or assigned to Cursive Systems, Inc. are 
 * Copyright (c) 2002 Cursive Systems, Inc.  All Rights Reserved.  Contact
 * information for Cursive Systems, Inc. is available at http://www.cursive.net/.
 *
 * Portions Copyright (c) 2002 Joe Hildebrand.
 * 
 * Acknowledgements
 * 
 * Special thanks to the Jabber Open Source Contributors for their
 * suggestions and support of Jabber.
 * 
 * --------------------------------------------------------------------------*/
using System;
using System.Xml;

using bedrock.util;

namespace jabber.protocol.iq{
    /// <summary>
    /// IQ packet with a roster query element inside.
    /// </summary>
    [RCS(@"$Header: /home/cvs/jabber-net/jabber/protocol/iq/Roster.cs,v 1.1 2002/07/11 21:59:37 hildjj Exp $")]
    public class RosterIQ : jabber.protocol.client.IQ
    {
        /// <summary>
        /// Create a roster IQ.
        /// </summary>
        /// <param name="doc"></param>
        public RosterIQ(XmlDocument doc) : base(doc)
        {
            this.Query = new Roster(doc);
        }
    }

    /// <summary>
    /// A roster query element.
    /// </summary>
    [RCS(@"$Header: /home/cvs/jabber-net/jabber/protocol/iq/Roster.cs,v 1.1 2002/07/11 21:59:37 hildjj Exp $")]
    public class Roster : Element
    {
        /// <summary>
        /// 
        /// </summary>
        /// <param name="doc"></param>
        public Roster(XmlDocument doc) : base("query", URI.ROSTER, doc)
        {
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="prefix"></param>
        /// <param name="qname"></param>
        /// <param name="doc"></param>
        public Roster(string prefix, XmlQualifiedName qname, XmlDocument doc) :
            base(prefix, qname, doc)
        {
        }

        /// <summary>
        /// Add a roster item
        /// </summary>
        /// <returns></returns>
        public Item AddItem()
        {
            Item i = new Item(this.OwnerDocument);
            AddChild(i);
            return i;
        }

        /// <summary>
        /// List of roster items
        /// </summary>
        /// <returns></returns>
        public Item[] GetItems()
        {
            XmlNodeList nl = GetElementsByTagName("item", URI.ROSTER);
            Item[] items = new Item[nl.Count];
            int i=0;
            foreach (XmlNode n in nl)
            {
                items[i] = (Item) n;
                i++;
            }
            return items;
        }
    }

    /// <summary>
    /// The current status of the subscription related to this item.
    /// </summary>
    public enum Subscription
    {
        /// <summary>
        /// Subscription to this person.  They are a lurkee.
        /// </summary>
        to,
        /// <summary>
        /// Subscription from this person.  They are a lurker.
        /// </summary>
        from,
        /// <summary>
        /// subscriptions in both ways.
        /// </summary>
        both,
        /// <summary>
        /// No subscription yet.  Often an Ask on this item.
        /// </summary>
        none,
        /// <summary>
        /// Remove this subscription from the local roster.
        /// </summary>
        remove,
    }

    /// <summary>
    /// An optional attribute specifying the current status of a request to this contact.
    /// </summary>
    public enum Ask
    {
        /// <summary>
        /// this entity is asking to subscribe to that contact's presence
        /// </summary>
        subscribe,
        /// <summary>
        /// this entity is asking unsubscribe from that contact's presence
        /// </summary>
        unsubscribe
    }

    /// <summary>
    /// Roster items.
    /// </summary>
    [RCS(@"$Header: /home/cvs/jabber-net/jabber/protocol/iq/Roster.cs,v 1.1 2002/07/11 21:59:37 hildjj Exp $")]
    public class Item : Element
    {
        /// <summary>
        /// 
        /// </summary>
        /// <param name="doc"></param>
        public Item(XmlDocument doc) : base("item", URI.ROSTER, doc)
        {
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="prefix"></param>
        /// <param name="qname"></param>
        /// <param name="doc"></param>
        public Item(string prefix, XmlQualifiedName qname, XmlDocument doc) :
            base(prefix, qname, doc)
        {
        }

        /// <summary>
        /// Item JID
        /// </summary>
        public JID JID
        {
            get { return new JID(GetAttribute("jid")); }
            set { this.SetAttribute("jid", value.ToString()); }
        }

        /// <summary>
        /// The user's nick
        /// </summary>
        public string Nickname
        {
            get { return GetAttribute("name"); }
            set { SetAttribute("name", value); }
        }

        /// <summary>
        /// How are we subscribed?
        /// </summary>
        public Subscription Subscription
        {
            get { return (Subscription) GetEnumAttr("subscription", typeof(Subscription)); }
            set { SetAttribute("subscription", value.ToString()); }
        }

        /// <summary>
        /// Pending?
        /// </summary>
        public Ask Ask
        {
            get { return (Ask) GetEnumAttr("subscription", typeof(Ask)); }
            set { SetAttribute("ask", value.ToString()); }
        }

        /// <summary>
        /// Add an item group
        /// </summary>
        /// <returns></returns>
        public Group AddGroup(string name)
        {
      Group g = GetGroup(name);
      if (g == null)
      {
        g = new Group(this.OwnerDocument);
        g.GroupName = name;
        AddChild(g);
      }
            return g;
        }

    /// <summary>
    /// Remove a group of the given name.  Does nothing if that group is not found.
    /// </summary>
    /// <param name="name"></param>
    public void RemoveGroup(string name)
    {
      XmlNodeList nl = GetElementsByTagName("group", URI.ROSTER);
      foreach (Group g in nl)
      {
        if (g.GroupName == name)
        {
          this.RemoveChild(g);
          return;
        }
      }
    }

    /// <summary>
    /// List of item groups
    /// </summary>
    /// <returns></returns>
    public Group[] GetGroups()
    {
      XmlNodeList nl = GetElementsByTagName("group", URI.ROSTER);
      Group[] groups = new Group[nl.Count];
      int i=0;
      foreach (XmlNode n in nl)
      {
        groups[i] = (Group) n;
        i++;
      }
      return groups;
    }

    /// <summary>
    /// Is this item in the specified group?
    /// </summary>
    /// <param name="name">The name of the group to check</param>
    /// <returns></returns>
    public bool HasGroup(string name)
    {
      Group[] gl = GetGroups();
      foreach (Group g in gl)
      {
        if (g.GroupName == name)
          return true;
      }
      return false;
    }

    /// <summary>
    /// Get the group object of the given name in this item.  
    /// If there is no group of that name, returns null.
    /// </summary>
    /// <param name="name">The name of the group to return</param>
    /// <returns>null if none found.</returns>
    public Group GetGroup(string name)
    {
      Group[] gl = GetGroups();
      foreach (Group g in gl)
      {
        if (g.GroupName == name)
          return g;
      }
      return null;
    }
    }
    /// <summary>
    /// Roster item groups.  &lt;group&gt;GroupName&lt;/group&gt;
    /// </summary>
    [RCS(@"$Header: /home/cvs/jabber-net/jabber/protocol/iq/Roster.cs,v 1.1 2002/07/11 21:59:37 hildjj Exp $")]
    public class Group : Element
    {
        /// <summary>
        /// 
        /// </summary>
        /// <param name="doc"></param>
        public Group(XmlDocument doc) : base("group", URI.ROSTER, doc)
        {
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="prefix"></param>
        /// <param name="qname"></param>
        /// <param name="doc"></param>
        public Group(string prefix, XmlQualifiedName qname, XmlDocument doc) :
            base(prefix, qname, doc)
        {
        }

        /// <summary>
        /// Name of the group.
        /// </summary>
        public string GroupName
        {
            get { return this.InnerText; }
            set { this.InnerText = value; }
        }
    }
}
www.java2v.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.