Пример #1
0
        public virtual string PublishBinariesInRichTextField(string xhtml)
        {
            // rich text field is well-formed, except that it does not always have a root element
            // to be sure it can be parsed, we will add a root and remove it afterwards

            TridionXml xml = new TridionXml();

            xml.LoadXml("<tmproot>" + xhtml + "</tmproot>");

            foreach (XmlElement img in xml.SelectNodes("//xhtml:img[@xlink:href[starts-with(string(.),'tcm:')]]", xml.NamespaceManager))
            {
                log.Debug("found img node " + img.OuterXml);
                XmlAttribute link = (XmlAttribute)img.SelectSingleNode("@xlink:href", xml.NamespaceManager);
                log.Debug("about to publish binary with uri " + link.Value);
                string path = PublishMultimediaComponent(link.Value);
                log.Debug("binary will be published to path " + path);
                img.SetAttribute("src", path);
            }


            foreach (XmlElement img in xml.SelectNodes("//xhtml:a[@xlink:href[starts-with(string(.),'tcm:')]]", xml.NamespaceManager))
            {
                log.Debug("found link node " + img.OuterXml);
                XmlAttribute link      = (XmlAttribute)img.SelectSingleNode("@xlink:href", xml.NamespaceManager);
                Component    component = (Component)engine.GetObject(link.Value);
                if (component.ComponentType == ComponentType.Multimedia)
                {
                    log.Debug("about to publish binary with uri " + link.Value);
                    string path = PublishMultimediaComponent(link.Value);
                    log.Debug("binary will be published to path " + path);
                    img.SetAttribute("src", path);
                }
                else
                {
                    log.Debug("Component is not a multimedia component.");
                }
            }
            return(xml.DocumentElement.InnerXml);
        }
        public virtual string PublishBinariesInRichTextField(string xhtml, BuildProperties buildProperties)
        {
            // rich text field is well-formed XML (XHTML), except that it does not always have a root element
            // to be sure it can be parsed, we will add a root and remove it afterwards
            TridionXml xml = new TridionXml();

            xml.LoadXml("<tmproot>" + xhtml + "</tmproot>");

            foreach (XmlElement xlinkElement in xml.SelectNodes("//*[@xlink:href[starts-with(string(.),'tcm:')]]", xml.NamespaceManager))
            {
                log.Debug("Found XLink in Rich Text: " + xlinkElement.OuterXml);
                ProcessRichTextXlink(xlinkElement, buildProperties);
            }

            return(xml.DocumentElement.InnerXml);
        }