Пример #1
0
        /// <summary>
        /// Performs the actual transformation logic of this <see cref="T:TcmTemplatingTemplateBase" />.
        /// </summary>
        /// <remarks>
        /// Transform is the main entry-point for template functionality.
        /// </remarks>
        protected override void Transform()
        {
            using (StringWriterEncoding sw = new StringWriterEncoding(Encoding.UTF8))
            {
                using (TemplateHtmlWriter hw = new TemplateHtmlWriter(sw))
                {
                    hw.RenderBeginTag(HtmlTextWriterTag.Html);
                    hw.RenderBeginTag(HtmlTextWriterTag.Head);

                    hw.AddAttribute(HtmlTextWriterAttribute.Name, "Robots");
                    hw.AddAttribute(HtmlTextWriterAttribute.Content, "NoIndex, NoFollow");
                    hw.RenderBeginTag(HtmlTextWriterTag.Meta);
                    hw.RenderEndTag();

                    hw.RenderBeginTag(HtmlTextWriterTag.Title);
                    hw.Write("Last Published");
                    hw.RenderEndTag();

                    hw.RenderBeginTag(HtmlTextWriterTag.Body);
                    hw.RenderBeginTag(HtmlTextWriterTag.P);
                    hw.Write("Last Published at {0}", DateTime.Now.ToString("dd-MMM-yyyy HH:mm:ss"));

                    if (PublishingUser != null)
                        hw.Write(" by {0}", PublishingUser.Title);

                    hw.RenderEndTag();
                    hw.RenderEndTag();

                    hw.RenderEndTag();
                    hw.RenderEndTag();
                }

                Package.AddString(Package.OutputName, sw.ToString());
            }
        }
Пример #2
0
        /// <summary>
        /// Performs the actual transformation logic of this <see cref="T:TcmTemplating.TemplateBase" />.
        /// </summary>
        /// <remarks>
        /// Transform is the main entry-point for template functionality.
        /// </remarks>
        protected override void Transform()
        {
            using (StringWriterEncoding sw = new StringWriterEncoding(Encoding.UTF8))
            {
                using (XmlWriter xml = XmlTextWriter.Create(sw, TemplateXmlWriterSettings))
                {
                    // Ensure the XmlWriter is available in the current rendering context
                    Engine.PublishingContext.RenderContext.ContextVariables.Add(NATIVE_XML_WRITER, xml);

                    foreach (global::Tridion.ContentManager.CommunicationManagement.ComponentPresentation componentPresentation in Page.ComponentPresentations)
                    {
                        xml.WriteRaw(Engine.RenderComponentPresentation(componentPresentation.Component.Id, componentPresentation.ComponentTemplate.Id));
                    }

                    xml.WriteProcessingTime(ProcessedTime);

                    xml.Close();

                    // Remove the XmlWriter from the current rendering context
                    Engine.PublishingContext.RenderContext.ContextVariables.Remove(NATIVE_XML_WRITER);
                }

                Package.AddXml(global::Tridion.ContentManager.Templating.Package.OutputName, sw.ToString());
            }
        }
        /// <summary>
        /// Executes a XSLT transformation for the given xml
        /// </summary>
        /// <param name="xml">XML to transform</param>
        /// <param name="removeNameSpaces">if set to <c>true</c> [remove name spaces].</param>
        /// <returns>Transformed XSLT result</returns>
        public String Execute(String xml, bool removeNameSpaces = true)
        {
            using (StringWriterEncoding sw = new StringWriterEncoding())
            {
                using (XmlWriter xw = removeNameSpaces ?
                                      new XmlNoNamespaceWriter(sw, new XmlWriterSettings()
                {
                    Indent = false,
                    OmitXmlDeclaration = true,
                    ConformanceLevel = ConformanceLevel.Fragment
                }) :
                                      XmlWriter.Create(sw, new XmlWriterSettings()
                {
                    Indent = false,
                    OmitXmlDeclaration = true,
                    ConformanceLevel = ConformanceLevel.Fragment
                })
                       )
                {
                    using (StringReader sr = new StringReader(xml))
                    {
                        using (XmlReader xr = XmlReader.Create(sr))
                        {
                            mXslCompiledTransform.Transform(xr, XsltArgumentList, xw, new XmlTcmUriResolver(mEngine));
                        }
                    }
                }

                return(sw.ToString());
            }
        }
        /// <summary>
        /// Performs the actual transformation logic of this <see cref="T:TcmTemplating.TemplateBase" />.
        /// </summary>
        /// <remarks>
        /// Transform is the main entry-point for template functionality.
        /// </remarks>
        protected override void Transform()
        {
            using (StringWriterEncoding sw = new StringWriterEncoding(Encoding.UTF8))
            {
                using (XmlWriter xml = XmlTextWriter.Create(sw))
                {
                    xml.WriteStartDocument();
                    xml.WriteStartElement("binary");
                    xml.WriteAttribute("uri", Component.Id);
                    xml.WriteAttribute("id", Component.Id.ItemId);
                    xml.WriteAttribute("title", Component.Title);
                    xml.WriteAttribute("url", PublishBinary(Component));
                    xml.WriteEndElement();
                    xml.WriteEndDocument();
                }

                Package.AddString(Tridion.ContentManager.Templating.Package.OutputName, sw.ToString());
            }
        }
        /// <summary>
        /// Resolves the XHTML.
        /// </summary>
        /// <param name="formatTextResolver"><see cref="T:TcmTemplating.Helpers.FormatTextResolver" /></param>
        /// <param name="xhtml">Tridion XHTML.</param>
        /// <returns><see cref="T:System.Xml.XPath.XPathNodeIterator" /></returns>
        protected XPathNodeIterator ResolveXHTML(FormatTextResolver formatTextResolver, XPathNodeIterator xhtml)
        {
            using (StringWriterEncoding sw = new StringWriterEncoding())
            {
                using (XmlWriter xw = XmlWriter.Create(sw, TemplateBase.TemplateXmlWriterSettings))
                {
                    xw.WriteStartElement("root");

                    foreach (XPathNavigator node in xhtml)
                    {
                        xw.WriteRaw(node.OuterXml);
                    }

                    xw.WriteEndElement();
                }

                String xml = formatTextResolver.Resolve(sw.ToString());

                XElement parsedXml = XElement.Parse(xml);

                return(parsedXml.CreateNavigator().Select("node()"));
            }
        }
Пример #6
0
        /// <summary>
        /// Resolves the XHTML.
        /// </summary>
        /// <param name="formatTextResolver"><see cref="T:TcmTemplating.Helpers.FormatTextResolver" /></param>
        /// <param name="xhtml">Tridion XHTML.</param>
        /// <returns><see cref="T:System.Xml.XPath.XPathNodeIterator" /></returns>
        protected XPathNodeIterator ResolveXHTML(FormatTextResolver formatTextResolver, XPathNodeIterator xhtml)
        {
            using (StringWriterEncoding sw = new StringWriterEncoding())
            {
                using (XmlWriter xw = XmlWriter.Create(sw, TemplateBase.TemplateXmlWriterSettings))
                {
                    xw.WriteStartElement("root");

                    foreach (XPathNavigator node in xhtml)
                        xw.WriteRaw(node.OuterXml);

                    xw.WriteEndElement();
                }

                String xml = formatTextResolver.Resolve(sw.ToString());

                XElement parsedXml = XElement.Parse(xml);

                return parsedXml.CreateNavigator().Select("node()");
            }
        }
Пример #7
0
        /// <summary>
        /// Executes a XSLT transformation for the given xml
        /// </summary>
        /// <param name="xml">XML to transform</param>
        /// <param name="removeNameSpaces">if set to <c>true</c> [remove name spaces].</param>
        /// <returns>Transformed XSLT result</returns>
        public String Execute(String xml, bool removeNameSpaces = true)
        {
            using (StringWriterEncoding sw = new StringWriterEncoding())
            {
                using (XmlWriter xw = removeNameSpaces ?
                    new XmlNoNamespaceWriter(sw, new XmlWriterSettings()
                    {
                        Indent = false,
                        OmitXmlDeclaration = true,
                        ConformanceLevel = ConformanceLevel.Fragment
                    }) :
                    XmlWriter.Create(sw, new XmlWriterSettings()
                    {
                        Indent = false,
                        OmitXmlDeclaration = true,
                        ConformanceLevel = ConformanceLevel.Fragment
                    })
                    )
                {
                    using (StringReader sr = new StringReader(xml))
                    {
                        using (XmlReader xr = XmlReader.Create(sr))
                        {
                            mXslCompiledTransform.Transform(xr, XsltArgumentList, xw, new XmlTcmUriResolver(mEngine));
                        }
                    }
                }

                return sw.ToString();
            }
        }
        /// <summary>
        /// Write out any custom metadata for the Tridion deployer extension
        /// </summary>
        /// <remarks>
        /// Sample custom metadata XML:
        /// <!--<my_metadata>
        ///			<keywords>
        ///				<Category Name="my_publication_path">
        ///					<Keyword>\publication\english</Keyword>
        ///				</Category>
        ///			</keywords>
        ///			<custom>
        ///				<ValidityStart>2010-10-31T15:42:00</ValidityStart>
        ///				<ValidityEnd type="dateTime">2020-01-01T23:59:00</ValidityEnd>
        ///				<Subject>Dubai</Subject>
        ///				<Location />
        ///				<ContentType>General</ContentType>
        ///				</custom>
        ///	</my_metadata>--> 
        /// </remarks>
        protected void WriteCustomMetadata()
        {
            if (CustomMetaData.Count > 0 || CustomKeywords.Count > 0)
            {
                using (StringWriter sw = new StringWriterEncoding(Encoding.UTF8))
                {
                    using (XmlTextWriter xw = new XmlTextWriter(sw))
                    {
                        xw.WriteStartElement(CUSTOM_META_INSTRUCTION);

                        if (CustomKeywords.Count > 0)
                        {
                            xw.WriteStartElement("keywords");

                            foreach (IGrouping<String, Keyword> category in CustomKeywords.GroupBy(k => k.OrganizationalItem.Title, k => k))
                            {
                                xw.WriteStartElement("Category");
                                xw.WriteAttributeString("Name", category.Key);

                                foreach (Keyword keyword in category)
                                {
                                    xw.WriteStartElement("Keyword");
                                    xw.WriteValue(keyword.Title);
                                    xw.WriteEndElement();
                                }

                                xw.WriteEndElement();
                            }

                            xw.WriteEndElement(); // </keywords>
                        }

                        if (CustomMetaData.Count > 0)
                        {
                            xw.WriteStartElement("custom");

                            foreach (KeyValuePair<String, Object> entry in CustomMetaData)
                            {
                                switch (Type.GetTypeCode(entry.Value.GetType()))
                                {
                                    case TypeCode.String:
                                        xw.WriteStartElement(entry.Key);
                                        xw.WriteValue(entry.Value as String);
                                        xw.WriteEndElement();
                                        break;
                                    case TypeCode.DateTime:
                                        xw.WriteStartElement(entry.Key);

                                        xw.WriteAttributeString("type", "dateTime");
                                        xw.WriteValue(((DateTime)entry.Value).ToString("yyyy-MM-ddTHH:mm:ss"));

                                        xw.WriteEndElement();
                                        break;
                                    case TypeCode.Byte:
                                    case TypeCode.Decimal:
                                    case TypeCode.Double:
                                    case TypeCode.Int16:
                                    case TypeCode.Int32:
                                    case TypeCode.Int64:
                                    case TypeCode.SByte:
                                    case TypeCode.Single:
                                    case TypeCode.UInt16:
                                    case TypeCode.UInt32:
                                    case TypeCode.UInt64:
                                        xw.WriteStartElement(entry.Key);

                                        xw.WriteAttributeString("type", "float");
                                        xw.WriteValue(entry.Value.ToString());

                                        xw.WriteEndElement();
                                        break;
                                }
                            }

                            xw.WriteEndElement(); // </custom>
                        }

                        xw.WriteEndElement(); // </my_metadata>
                    }

                    sw.Flush();

                    Xml.WriteComment(sw.ToString());
                }
            }
        }