public override void Initialize(BuildContext context, ReferenceGroup group)
        {
            base.Initialize(context, group);

            _notApplicable = false;

            BuildGroupContext groupContext = context.GroupContexts[group.Id];

            if (groupContext != null)
            {
                // We do not have to spell check embedded documents...
                string embeddedText = groupContext["$IsEmbeddedGroup"];
                if (!String.IsNullOrEmpty(embeddedText) &&
                    embeddedText.Equals(Boolean.TrueString, StringComparison.OrdinalIgnoreCase))
                {
                    _notApplicable = true;
                    return;
                }
            }

            if (this.IsInitialized)
            {
                if (_tocLayout == null)
                {
                    ReferenceEngineSettings engineSettings = this.EngineSettings;

                    Debug.Assert(engineSettings != null);
                    if (engineSettings == null)
                    {
                        this.IsInitialized = false;
                        return;
                    }

                    _tocLayout = engineSettings.TocLayout;
                    Debug.Assert(_tocLayout != null);

                    if (_tocLayout == null)
                    {
                        this.IsInitialized = false;
                        return;
                    }
                }

                _contentsAfter = _tocLayout.ContentsAfter;

                ReferenceTocLayoutType layoutType = _tocLayout.LayoutType;
                if (layoutType != ReferenceTocLayoutType.Hierarchical &&
                    layoutType != ReferenceTocLayoutType.Custom)
                {
                    this.IsInitialized = false;
                    return;
                }
            }
        }
        private bool Visit(string tocFilePath, BuildLogger logger)
        {
            _projectName = String.Empty;
            _projectFile = String.Empty;

            if (String.IsNullOrEmpty(tocFilePath))
            {
                return(false);
            }
            ReferenceTocLayoutType layoutType = _tocLayout.LayoutType;

            if (layoutType == ReferenceTocLayoutType.None ||
                layoutType == ReferenceTocLayoutType.Null ||
                layoutType == ReferenceTocLayoutType.Flat)
            {
                return(false);
            }

            XPathDocument  document          = new XPathDocument(tocFilePath);
            XPathNavigator documentNavigator = document.CreateNavigator();
            XPathNavigator projectNode       = documentNavigator.SelectSingleNode(
                "topics/topic[starts-with(@id, 'R:')]");

            if (projectNode != null)
            {
                _projectName = projectNode.GetAttribute("id", String.Empty);
                if (_projectName == null)
                {
                    _projectName = String.Empty;
                }
                _projectFile = projectNode.GetAttribute("file", String.Empty);
                if (_projectFile == null)
                {
                    _projectFile = String.Empty;
                }
            }

            XPathNavigator rootNode = projectNode;

            if (rootNode == null)
            {
                rootNode = documentNavigator.SelectSingleNode("topics");
            }

            XPathNodeIterator iterator = rootNode.Select(
                "topic[starts-with(@id, 'N:')]");

            if (iterator == null || iterator.Count == 0)
            {
                return(false);
            }

            _undocumentedNodes =
                new List <KeyValuePair <string, HierarchicalTocNode> >();
            _namingMethod = this.EngineSettings.Naming;
            _tocFilePath  = tocFilePath;

            _dicNavigators = new BuildDictionary <XPathNavigator>();

            if (layoutType == ReferenceTocLayoutType.Hierarchical)
            {
                _tocContents = new HierarchicalTocContent();
                _tocContents.BeginItems(_projectName, _projectFile);

                foreach (XPathNavigator navigator in iterator)
                {
                    string nsText = navigator.GetAttribute("id", String.Empty);
                    if (!String.IsNullOrEmpty(nsText) && nsText.Length > 2)
                    {
                        nsText = nsText.Substring(2);
                        string projName = navigator.GetAttribute("project", String.Empty);
                        string fileName = navigator.GetAttribute("file", String.Empty);

                        if (_tocContents.AddItem(nsText, projName, fileName))
                        {
                            _dicNavigators.Add(nsText, navigator.Clone());
                        }
                    }
                }

                _tocContents.EndItems();
            }
            else if (layoutType == ReferenceTocLayoutType.Custom)
            {
                _tocContents = this.Group.Content.HierarchicalToc;

                if (_tocContents != null)
                {
                    foreach (XPathNavigator navigator in iterator)
                    {
                        string nsText = navigator.GetAttribute("id", String.Empty);
                        if (!String.IsNullOrEmpty(nsText) && nsText.Length > 2)
                        {
                            nsText = nsText.Substring(2);
                            string projName = navigator.GetAttribute("project", String.Empty);
                            string fileName = navigator.GetAttribute("file", String.Empty);

                            _dicNavigators.Add(nsText, navigator.Clone());
                        }
                    }
                }
            }

            if (_tocContents == null)
            {
                return(false);
            }

            _rootNode = _tocContents.RootNode;

            return(_rootNode != null);
        }
 /// <overloads>
 /// Initializes a new instance of the <see cref="ReferenceTocLayoutConfiguration"/> class.
 /// </overloads>
 /// <summary>
 /// Initializes a new instance of the <see cref="ReferenceTocLayoutConfiguration"/> class
 /// to the default values.
 /// </summary>
 public ReferenceTocLayoutConfiguration()
 {
     _layoutType = ReferenceTocLayoutType.Flat;
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="ReferenceTocLayoutConfiguration"/> class
 /// with parameters copied from the specified instance of the
 /// <see cref="ReferenceTocLayoutConfiguration"/> class, a copy constructor.
 /// </summary>
 /// <param name="source">
 /// An instance of the <see cref="ReferenceTocLayoutConfiguration"/> class from which the
 /// initialization parameters or values will be copied.
 /// </param>
 /// <exception cref="ArgumentNullException">
 /// If the parameter <paramref name="source"/> is <see langword="null"/>.
 /// </exception>
 public ReferenceTocLayoutConfiguration(ReferenceTocLayoutConfiguration source)
     : base(source)
 {
     _layoutType = source._layoutType;
 }
        /// <summary>
        /// This reads and sets its state or attributes stored in a <c>XML</c> format
        /// with the given reader.
        /// </summary>
        /// <param name="reader">
        /// The reader with which the <c>XML</c> attributes of this object are accessed.
        /// </param>
        /// <exception cref="ArgumentNullException">
        /// If the <paramref name="reader"/> is <see langword="null"/>.
        /// </exception>
        public override void ReadXml(XmlReader reader)
        {
            BuildExceptions.NotNull(reader, "reader");

            Debug.Assert(reader.NodeType == XmlNodeType.Element);
            if (reader.NodeType != XmlNodeType.Element)
            {
                return;
            }

            if (!String.Equals(reader.Name, TagName,
                               StringComparison.OrdinalIgnoreCase))
            {
                Debug.Assert(false, String.Format(
                                 "The element name '{0}' does not match the expected '{1}'.",
                                 reader.Name, TagName));
                return;
            }

            string tempText = reader.GetAttribute("name");

            if (String.IsNullOrEmpty(tempText) || !String.Equals(tempText,
                                                                 ConfigurationName, StringComparison.OrdinalIgnoreCase))
            {
                throw new BuildException(String.Format(
                                             "ReadXml: The current name '{0}' does not match the expected name '{1}'.",
                                             tempText, ConfigurationName));
            }

            if (reader.IsEmptyElement)
            {
                return;
            }

            while (reader.Read())
            {
                if (reader.NodeType == XmlNodeType.Element)
                {
                    if (String.Equals(reader.Name, "property", StringComparison.OrdinalIgnoreCase))
                    {
                        switch (reader.GetAttribute("name").ToLower())
                        {
                        case "enabled":
                            tempText = reader.ReadString();
                            if (!String.IsNullOrEmpty(tempText))
                            {
                                this.Enabled = Convert.ToBoolean(tempText);
                            }
                            break;

                        case "continueonerror":
                            tempText = reader.ReadString();
                            if (!String.IsNullOrEmpty(tempText))
                            {
                                this.ContinueOnError = Convert.ToBoolean(tempText);
                            }
                            break;

                        case "contentsafter":
                            tempText = reader.ReadString();
                            if (!String.IsNullOrEmpty(tempText))
                            {
                                _contentsAfter = Convert.ToBoolean(tempText);
                            }
                            break;

                        case "layouttype":
                            tempText = reader.ReadString();
                            if (!String.IsNullOrEmpty(tempText))
                            {
                                _layoutType = ReferenceTocLayoutType.Parse(tempText);
                            }
                            break;

                        default:
                            // Should normally not reach here...
                            throw new NotImplementedException(reader.GetAttribute("name"));
                        }
                    }
                }
                else if (reader.NodeType == XmlNodeType.EndElement)
                {
                    if (String.Equals(reader.Name, TagName, StringComparison.OrdinalIgnoreCase))
                    {
                        break;
                    }
                }
            }
        }