//===================================================================== /// <summary> /// Constructor /// </summary> /// <param name="assembler">A reference to the build assembler.</param> /// <param name="configuration">The configuration information</param> public ResolveConceptualLinksComponent(BuildAssembler assembler, XPathNavigator configuration) : base(assembler, configuration) { TargetDirectory targetDirectory; XPathExpression urlExp, textExp, linkTextExp; LinkType linkType = LinkType.None; string attribute, basePath; targetDirectories = new TargetDirectoryCollection(); cache = new Dictionary <string, TargetInfo>(cacheSize); attribute = configuration.GetAttribute("showBrokenLinkText", String.Empty); if (!String.IsNullOrEmpty(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, String.Format( CultureInfo.InvariantCulture, "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."); } try { linkType = (LinkType)Enum.Parse(typeof(LinkType), attribute, true); } catch (ArgumentException) { base.WriteMessage(MessageLevel.Error, String.Format(CultureInfo.InvariantCulture, "'{0}' is not a valid link type.", attribute)); } targetDirectory = new TargetDirectory(basePath, urlExp, textExp, linkTextExp, linkType); targetDirectories.Add(targetDirectory); } base.WriteMessage(MessageLevel.Info, String.Format(CultureInfo.InvariantCulture, "Collected {0} targets directories.", targetDirectories.Count)); }
//===================================================================== /// <summary> /// Add a new target directory to the collection /// </summary> /// <param name="targetDirectory">The target directory to add</param> public void Add(TargetDirectory targetDirectory) { targetDirectories.Add(targetDirectory); }