// Instantiation logic

		public ResolveConceptualLinksComponent (BuildAssembler assembler, XPathNavigator configuration) : base(assembler, configuration) {

            string showBrokenLinkTextValue = configuration.GetAttribute("showBrokenLinkText", String.Empty);
            if (!String.IsNullOrEmpty(showBrokenLinkTextValue)) showBrokenLinkText = Convert.ToBoolean(showBrokenLinkTextValue);

			XPathNodeIterator targetsNodes = configuration.Select("targets");
			foreach (XPathNavigator targetsNode in targetsNodes) {

                // the base directory containing target; required
                string baseValue = targetsNode.GetAttribute("base", String.Empty);
                if (String.IsNullOrEmpty(baseValue)) WriteMessage(MessageLevel.Error, "Every targets element must have a base attribute that specifies the path to a directory of target metadata files.");
                baseValue = Environment.ExpandEnvironmentVariables(baseValue);
                if (!Directory.Exists(baseValue)) WriteMessage(MessageLevel.Error, String.Format("The specified target metadata directory '{0}' does not exist.", baseValue));

                // an xpath expression to construct a file name
                // (not currently used; pattern is hard-coded to $target.cmp.xml
                string filesValue = targetsNode.GetAttribute("files", String.Empty);

                // an xpath expression to construct a url
                string urlValue = targetsNode.GetAttribute("url", String.Empty);
                XPathExpression urlExpression;
                if (String.IsNullOrEmpty(urlValue)) {
                    urlExpression = XPathExpression.Compile("concat(/metadata/topic/@id,'.htm')");
                } else {
                    urlExpression = CompileXPathExpression(urlValue);
                }
                
                // an xpath expression to construct link text
                string textValue = targetsNode.GetAttribute("text", String.Empty);
                XPathExpression textExpression;
                if (String.IsNullOrEmpty(textValue)) {
                    textExpression = XPathExpression.Compile("string(/metadata/topic/title)");
                } else {
                    textExpression = CompileXPathExpression(textValue);
                }

                // the type of link to create to targets found in the directory; required
                string typeValue = targetsNode.GetAttribute("type", String.Empty);
                if (String.IsNullOrEmpty(typeValue)) 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.");
                
                // convert the link type to an enumeration member
                LinkType type = LinkType.None;
                try {
                    type = (LinkType) Enum.Parse(typeof(LinkType), typeValue, true);
                } catch (ArgumentException) {
                    WriteMessage(MessageLevel.Error, String.Format("'{0}' is not a valid link type.", typeValue));
                }

                // we have all the required information; create a TargetDirectory and add it to our collection
                TargetDirectory targetDirectory = new TargetDirectory(baseValue, urlExpression, textExpression, type);
                targetDirectories.Add(targetDirectory);

            }

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

		}
Ejemplo n.º 2
0
 public void Add(TargetDirectory targetDirectory)
 {
     targetDirectories.Add(targetDirectory);
 }
Ejemplo n.º 3
0
        // Instantiation logic

        public ResolveConceptualLinksComponent(BuildAssembler assembler, XPathNavigator configuration) : base(assembler, configuration)
        {
            string showBrokenLinkTextValue = configuration.GetAttribute("showBrokenLinkText", String.Empty);

            if (!String.IsNullOrEmpty(showBrokenLinkTextValue))
            {
                showBrokenLinkText = Convert.ToBoolean(showBrokenLinkTextValue);
            }

            XPathNodeIterator targetsNodes = configuration.Select("targets");

            foreach (XPathNavigator targetsNode in targetsNodes)
            {
                // the base directory containing target; required
                string baseValue = targetsNode.GetAttribute("base", String.Empty);
                if (String.IsNullOrEmpty(baseValue))
                {
                    WriteMessage(MessageLevel.Error, "Every targets element must have a base attribute that specifies the path to a directory of target metadata files.");
                }
                baseValue = Environment.ExpandEnvironmentVariables(baseValue);
                if (!Directory.Exists(baseValue))
                {
                    WriteMessage(MessageLevel.Error, String.Format("The specified target metadata directory '{0}' does not exist.", baseValue));
                }

                // an xpath expression to construct a file name
                // (not currently used; pattern is hard-coded to $target.cmp.xml
                string filesValue = targetsNode.GetAttribute("files", String.Empty);

                // an xpath expression to construct a url
                string          urlValue = targetsNode.GetAttribute("url", String.Empty);
                XPathExpression urlExpression;
                if (String.IsNullOrEmpty(urlValue))
                {
                    urlExpression = XPathExpression.Compile("concat(/metadata/topic/@id,'.htm')");
                }
                else
                {
                    urlExpression = CompileXPathExpression(urlValue);
                }

                // an xpath expression to construct link text
                string          textValue = targetsNode.GetAttribute("text", String.Empty);
                XPathExpression textExpression;
                if (String.IsNullOrEmpty(textValue))
                {
                    textExpression = XPathExpression.Compile("string(/metadata/topic/title)");
                }
                else
                {
                    textExpression = CompileXPathExpression(textValue);
                }

                // the type of link to create to targets found in the directory; required
                string typeValue = targetsNode.GetAttribute("type", String.Empty);
                if (String.IsNullOrEmpty(typeValue))
                {
                    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.");
                }

                // convert the link type to an enumeration member
                LinkType type = LinkType.None;
                try {
                    type = (LinkType)Enum.Parse(typeof(LinkType), typeValue, true);
                } catch (ArgumentException) {
                    WriteMessage(MessageLevel.Error, String.Format("'{0}' is not a valid link type.", typeValue));
                }

                // we have all the required information; create a TargetDirectory and add it to our collection
                TargetDirectory targetDirectory = new TargetDirectory(baseValue, urlExpression, textExpression, type);
                targetDirectories.Add(targetDirectory);
            }

            WriteMessage(MessageLevel.Info, String.Format("Collected {0} targets directories.", targetDirectories.Count));
        }
 public void Add (TargetDirectory targetDirectory) {
     targetDirectories.Add(targetDirectory);
 }
Ejemplo n.º 5
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);
        }