//=====================================================================

        /// <inheritdoc />
        public override void Initialize(XPathNavigator configuration)
        {
            TargetDirectory targetDirectory;
            XPathExpression urlExp, textExp, linkTextExp;
            ConceptualLinkType linkType = ConceptualLinkType.None;
            string attribute, basePath;

            targetDirectories = new TargetDirectoryCollection();

            // This is a simple cache.  If the cache size limit is reached, it clears the cache and starts over
            cache = new Dictionary<string, TargetInfo>(CacheSize);

            attribute = (string)configuration.Evaluate("string(showBrokenLinkText/@value)");

            if(!String.IsNullOrWhiteSpace(attribute))
                showBrokenLinkText = Convert.ToBoolean(attribute, CultureInfo.InvariantCulture);

            foreach(XPathNavigator navigator in configuration.Select("targets"))
            {
                basePath = navigator.GetAttribute("base", String.Empty);

                if(String.IsNullOrEmpty(basePath))
                    base.WriteMessage(MessageLevel.Error, "Every targets element must have a base attribute " +
                        "that specifies the path to a directory of target metadata files.");

                basePath = Environment.ExpandEnvironmentVariables(basePath);

                if(!Directory.Exists(basePath))
                    base.WriteMessage(MessageLevel.Error, "The specified target metadata directory '{0}' " +
                        "does not exist.", basePath);

                attribute = navigator.GetAttribute("url", String.Empty);

                if(String.IsNullOrEmpty(attribute))
                    urlExp = XPathExpression.Compile("concat(/metadata/topic/@id,'.htm')");
                else
                    urlExp = this.CompileXPathExpression(attribute);

                attribute = navigator.GetAttribute("text", String.Empty);

                if(String.IsNullOrEmpty(attribute))
                    textExp = XPathExpression.Compile("string(/metadata/topic/title)");
                else
                    textExp = this.CompileXPathExpression(attribute);

                // EFW - Added support for linkText option
                attribute = navigator.GetAttribute("linkText", String.Empty);

                if(String.IsNullOrEmpty(attribute))
                    linkTextExp = XPathExpression.Compile("string(/metadata/topic/linkText)");
                else
                    linkTextExp = this.CompileXPathExpression(attribute);

                attribute = navigator.GetAttribute("type", String.Empty);

                if(String.IsNullOrEmpty(attribute))
                    base.WriteMessage(MessageLevel.Error, "Every targets element must have a type attribute " +
                        "that specifies what kind of link to create to targets found in that directory.");

                if(!Enum.TryParse<ConceptualLinkType>(attribute, true, out linkType))
                    base.WriteMessage(MessageLevel.Error, "'{0}' is not a valid link type.", attribute);

                targetDirectory = new TargetDirectory(basePath, urlExp, textExp, linkTextExp, linkType);
                targetDirectories.Add(targetDirectory);
            }

            base.WriteMessage(MessageLevel.Info, "Collected {0} targets directories.", targetDirectories.Count);
        }
Beispiel #2
0
        //=====================================================================

        /// <inheritdoc />
        public override void Initialize(XPathNavigator configuration)
        {
            TargetDirectory    targetDirectory;
            XPathExpression    urlExp, textExp, linkTextExp;
            ConceptualLinkType linkType = ConceptualLinkType.None;
            string             attribute, basePath;

            targetDirectories = new TargetDirectoryCollection();

            // This is a simple cache.  If the cache size limit is reached, it clears the cache and starts over
            cache = new Dictionary <string, TargetInfo>(CacheSize);

            attribute = (string)configuration.Evaluate("string(showBrokenLinkText/@value)");

            if (!String.IsNullOrWhiteSpace(attribute))
            {
                showBrokenLinkText = Convert.ToBoolean(attribute, CultureInfo.InvariantCulture);
            }

            foreach (XPathNavigator navigator in configuration.Select("targets"))
            {
                basePath = navigator.GetAttribute("base", String.Empty);

                if (String.IsNullOrEmpty(basePath))
                {
                    base.WriteMessage(MessageLevel.Error, "Every targets element must have a base attribute " +
                                      "that specifies the path to a directory of target metadata files.");
                }

                basePath = Environment.ExpandEnvironmentVariables(basePath);

                if (!Directory.Exists(basePath))
                {
                    base.WriteMessage(MessageLevel.Error, "The specified target metadata directory '{0}' " +
                                      "does not exist.", basePath);
                }

                attribute = navigator.GetAttribute("url", String.Empty);

                if (String.IsNullOrEmpty(attribute))
                {
                    urlExp = XPathExpression.Compile("concat(/metadata/topic/@id,'.htm')");
                }
                else
                {
                    urlExp = this.CompileXPathExpression(attribute);
                }

                attribute = navigator.GetAttribute("text", String.Empty);

                if (String.IsNullOrEmpty(attribute))
                {
                    textExp = XPathExpression.Compile("string(/metadata/topic/title)");
                }
                else
                {
                    textExp = this.CompileXPathExpression(attribute);
                }

                // EFW - Added support for linkText option
                attribute = navigator.GetAttribute("linkText", String.Empty);

                if (String.IsNullOrEmpty(attribute))
                {
                    linkTextExp = XPathExpression.Compile("string(/metadata/topic/linkText)");
                }
                else
                {
                    linkTextExp = this.CompileXPathExpression(attribute);
                }

                attribute = navigator.GetAttribute("type", String.Empty);

                if (String.IsNullOrEmpty(attribute))
                {
                    base.WriteMessage(MessageLevel.Error, "Every targets element must have a type attribute " +
                                      "that specifies what kind of link to create to targets found in that directory.");
                }

                if (!Enum.TryParse <ConceptualLinkType>(attribute, true, out linkType))
                {
                    base.WriteMessage(MessageLevel.Error, "'{0}' is not a valid link type.", attribute);
                }

                targetDirectory = new TargetDirectory(basePath, urlExp, textExp, linkTextExp, linkType);
                targetDirectories.Add(targetDirectory);
            }

            base.WriteMessage(MessageLevel.Info, "Collected {0} targets directories.", targetDirectories.Count);
        }