Click here to Skip to main content
15,885,546 members
Articles / Web Development / ASP.NET

An extensible DotNetNuke Google Sitemap Generator

Rate me:
Please Sign up or sign in to vote.
4.14/5 (5 votes)
30 Apr 2008CPOL15 min read 82.2K   597   33  
Building a DotNetNuke Sitemap Generator using the ASP.NET Provider model.
/*
 * 
 * iFinity Smart Business Solutions - http://www.ifinity.com.au
 * Copyright (c) 2006
 
 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated 
 * documentation files (the "Software"), the rights to use, copy, modify, merge, publish, distribute, sublicense
 * copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the 
 * following conditions:

 * 1. The above copyright notice and this permission notice shall be included in all copies or substantial portions 
 *    of the Software.  
 * 2. The software may not be claimed as the original work and may not be sold as a stand alone product

 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED 
 * TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 
 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF 
 * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 
 * DEALINGS IN THE SOFTWARE.
 * 
 */

using System;
using System.Collections.Generic;
using System.Text;
using System.Xml;

namespace iFinity.DNN.Modules.GoogleSiteMap
{
    public class SitePage
    {
        string _loc;
        DateTime _lastMod;
        ChangeFrequencies _changeFreq;
        double _priority;

        public SitePage()
        {
        }
        public SitePage(string loc, DateTime lastMod, ChangeFrequencies changeFreq, double priority)
        {
            _loc = loc;
            _lastMod = lastMod;
            _changeFreq = changeFreq;
            _priority = priority;
        }
        public string Loc
        {
            get { return _loc; }
            set { _loc = value; }
        }
        public DateTime LastMod
        {
            get
            {
                return _lastMod;
            }
            set
            {
                _lastMod = value;
            }
        }
        public void SetLastMod(string value)
        {
            _lastMod = DateTime.Parse(value);
        }
        public ChangeFrequencies ChangeFreq
        {
            get
            {
                return _changeFreq;
            }
            set
            {
                _changeFreq = value;
            }
        }
        public double Priority
        {
            get { return _priority; }
            set { _priority = value; }
        }
        /// <summary>
        /// This date should be in ISO 8601 format. 
        /// This format allows you to omit the time portion, use YYYY-MM-DD.
        /// </summary>
        /// <param name="dateValue">string date value</param>
        /// <returns>ISO 8601 date format</returns>
        internal static string FormatISODate(string dateValue)
        {
             return FormatISODate(DateTime.Parse(dateValue));
        }

        /// <summary>
        /// This date should be in ISO 8601 format. 
        /// This format allows you to omit the time portion, use YYYY-MM-DD.
        /// </summary>
        /// <param name="dateValue">datetime date value</param>
        /// <returns>ISO 8601 date format</returns>
        internal static string FormatISODate(DateTime date)
        {
            StringBuilder sb = new StringBuilder();
            sb.Append(date.Year);
            sb.Append("-");
            if (date.Month < 10)
            {
                sb.Append("0");
            }
            sb.Append(date.Month);
            sb.Append("-");
            if (date.Day < 10)
            {
                sb.Append("0");
            }
            sb.Append(date.Day);

            return sb.ToString();
        }

        internal static string ConvertChangeFrequencyToString(ChangeFrequencies changeFreq)
        {
            string retVal="";
            switch (changeFreq)
            {
                case ChangeFrequencies.always:
                    retVal = "always";
                    break;
                case ChangeFrequencies.daily:
                    retVal = "daily";
                    break;
                case ChangeFrequencies.hourly:
                    retVal = "hourly";
                    break;
                case ChangeFrequencies.monthly:
                    retVal = "monthly";
                    break;
                case ChangeFrequencies.never:
                    retVal = "never";
                    break;
                case ChangeFrequencies.weekly:
                    retVal = "weekly";
                    break;
                case ChangeFrequencies.yearly:
                    retVal = "yearly";
                    break;
            }
            return retVal;
        }
        internal static ChangeFrequencies ConvertChangeFrequencyToEnum(string changeFreq)
        {
            ChangeFrequencies retVal = ChangeFrequencies.daily;
            switch (changeFreq)
            {
                case "always":
                    retVal = ChangeFrequencies.always;
                    break;
                case "daily":
                    retVal = ChangeFrequencies.daily;
                    break;
                case "hourly":
                    retVal = ChangeFrequencies.hourly;
                    break;
                case "monthly":
                    retVal = ChangeFrequencies.monthly;
                    break;
                case "never":
                    retVal = ChangeFrequencies.never;
                    break;
                case "weekly":
                    retVal = ChangeFrequencies.weekly;
                    break;
                case "yearly":
                    retVal = ChangeFrequencies.yearly;
                    break;
            }
            return retVal;
        }
                
    }
    public enum ChangeFrequencies
    {
        always,
        hourly,
        daily,
        weekly,
        monthly,
        yearly,
        never
    }
    
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Product Manager DNN Corp
Australia Australia
Bruce Chapman is the Product Manager for Cloud Services at DNN. He’s been an active member of the DNN Community since 2006 as a contributor, vendor and now employee of DNN Corp.

You can read his blog at http://dnnsoftware.com/blog or follow him on Twitter @brucerchapman

Comments and Discussions