Exemplo n.º 1
0
        public override void Transform(Tridion.ContentManager.Templating.Engine engine, Tridion.ContentManager.Templating.Package package)
        {
            this.Initialize(engine, package);

            Component c;

            if (this.IsPageTemplate())
            {
                c = this.GetPage().ComponentPresentations[0].Component;
            }
            else
            {
                c = this.GetComponent();
            }

            XmlDocument resourceDoc = null;

            resourceDoc = new XmlDocument();
            resourceDoc.LoadXml("<root/>");

            ItemFields fields = new ItemFields(c.Content, c.Schema);

            foreach (ItemField field in fields)
            {
                string name  = field.Name;
                string value = ((TextField)field).Value;

                XmlElement data = resourceDoc.CreateElement("data");
                data.SetAttribute("name", name);
                XmlElement v = resourceDoc.CreateElement("value");
                v.InnerText = value;
                data.AppendChild(v);
                resourceDoc.DocumentElement.AppendChild(data);
            }

            /*
             *
             * Page p = this.GetPage();
             * ItemFields fields = new ItemFields(p.Metadata, p.MetadataSchema);
             * EmbeddedSchemaField resourcesField = fields["Resource"] as EmbeddedSchemaField;
             *
             * foreach (ItemFields innerFields in resourcesField.Values)
             * {
             *  TextField nameField = innerFields["Name"] as TextField;
             *  TextField valueField = innerFields["Resource"] as TextField;
             *
             *  XmlElement data = resourceDoc.CreateElement("data");
             *  data.SetAttribute("name", nameField.Value);
             *  XmlElement v = resourceDoc.CreateElement("value");
             *  v.InnerText = valueField.Value;
             *  data.AppendChild(v);
             *  resourceDoc.DocumentElement.AppendChild(data);
             * }
             *
             * */

            this.CreateStringItem("Output", resourceDoc.OuterXml, ContentType.Xml);
        }
        public override void Transform(tpl.Engine engine, tpl.Package package)
        {
            Initialize(engine, package);
            _config     = LoadConfig(GetComponent());
            _startPoint = GetPublication().RootStructureGroup;

            if (_startPoint != null)
            {
                string nav = GenerateNavigation();
                if (!string.IsNullOrEmpty(GenerateNavigation()))
                {
                    package.PushItem(tpl.Package.OutputName, package.CreateStringItem(tpl.ContentType.Text, nav));
                }
            }
        }
Exemplo n.º 3
0
        public override void Transform(Tridion.ContentManager.Templating.Engine engine, Tridion.ContentManager.Templating.Package package)
        {
            this.Initialize(engine, package);

            if (!this.IsPageTemplate())
            {
                this.Logger.Warning("Calling Sitemap from a Component Template instead of a Page Template!");
                return;
            }

            Publication publication = this.GetPublication();

            _sitemap = new XmlDocument();
            _sitemap.LoadXml("<siteMap xmlns=\"http://schemas.microsoft.com/AspNet/SiteMap-File-1.0\" />");
            AddNodes(_sitemap.DocumentElement, publication.RootStructureGroup, "");

            this.CreateStringItem("Output", _sitemap.OuterXml, ContentType.Xml);
        }
Exemplo n.º 4
0
        public override void Transform(Tridion.ContentManager.Templating.Engine engine, Tridion.ContentManager.Templating.Package package)
        {
            this.Initialize(engine, package);

            if (!this.IsPageTemplate())
            {
                this.Logger.Warning("Calling Sitemap from a Component Template instead of a Page Template!");
                return;
            }

            Publication publication = this.GetPublication();

            _sitemap = new XmlDocument();
            _sitemap.LoadXml("<siteMap xmlns=\"http://schemas.microsoft.com/AspNet/SiteMap-File-1.0\" />");

            string baseUrl = publication.PublicationUrl.Substring(1);

            XmlElement navigation = CreateElement(_sitemap.DocumentElement, "navigation", "", "Navigation", "");

            foreach (Category c in publication.GetCategories())
            {
                if (c.Title == "Navigation") // TODO: make configurable in appSettings
                {
                    foreach (Keyword kw in c.GetKeywords(new KeywordsFilter(Engine.GetSession())
                    {
                        IsRoot = true
                    }))
                    {
                        AddNodes(navigation, kw, c.Title, baseUrl);
                    }

                    break;
                }
            }

            XmlElement structure = CreateElement(_sitemap.DocumentElement, "structure", "", "Structure", "");

            AddNodes(structure, publication.RootStructureGroup, baseUrl);

            this.CreateStringItem("Output", _sitemap.OuterXml, ContentType.Xml);
        }
 public void Initialize(Tridion.ContentManager.Templating.Engine engine, Tridion.ContentManager.Templating.Package package)
 {
     this.Engine  = engine;
     this.Package = package;
     this.Logger  = TemplatingLogger.GetLogger(this.GetType());
 }