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);
        }
        /// <summary>
        /// For Publish and UnPublish, remove all items from the website structure Publication from the list.
        /// Website structure Publication URI is read from the config file.
        /// </summary>
        /// <param name="item">Item to be resolved (e.g. a page, structure group, template)</param>
        /// <param name="instruction">Resolve instruction</param>
        /// <param name="context">Publish context</param>
        /// <param name="resolvedItems">List of items that are currently to be rendered and published (added by previous resolvers in the chain)</param>
        public void Resolve(IdentifiableObject item, ResolveInstruction instruction, PublishContext context, Tridion.Collections.ISet<ResolvedItem> resolvedItems)
        {
            List<ResolvedItem> itemsToRemove = new List<ResolvedItem>();
            StringBuilder infoMessage = new StringBuilder();
            infoMessage.AppendLine(string.Format("Removed the following items from a {0} Transaction to {1}:", instruction.Purpose, context.PublicationTarget.Title));

            // check for items from website structure publication (these do not need to be published or unpublished) 
            foreach (ResolvedItem resolvedItem in resolvedItems)
            {
                // mark all items from website structure publication for removal
                if (resolvedItem.Item.Id.PublicationId == _websiteStructurePublicationUri.ItemId)
                {
                    itemsToRemove.Add(resolvedItem);
                }
            }

            // remove all items that we need to discard
            foreach (ResolvedItem itemToRemove in itemsToRemove)
            {
                infoMessage.AppendLine(string.Format("{0}: {1} ({2})", itemToRemove.Item.Id.ItemType, itemToRemove.Item.Title, itemToRemove.Item.Id));
                resolvedItems.Remove(itemToRemove);
            }
            if (itemsToRemove.Count > 0)
            {
                // log info mesage about which items have been removed (optionally this can be logged as a warning to stand out in the logfile)
                Logger.Write(infoMessage.ToString(), "ChildPublicationsOnlyResolver", LoggingCategory.General, TraceEventType.Information);
            }
        }
        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);
        }
        //http://codedweapon.com/2012/12/getting-using-and-used-items-with-core-services/
        private static List GetListOfType(string publicationTcmId, Tridion.ContentManager.CoreService.Client.ItemType searchForType)
        {
            RepositoryItemsFilterData filter = new RepositoryItemsFilterData
            {
                ItemTypes = new[] { searchForType },
                Recursive = true
            };

            IEnumerable<XNode> searchResult = core.GetListXml(publicationTcmId, filter).Nodes();
            var list = new List(searchResult);

            return list;
        }
 /// <summary>
 /// Build a DD4T Target group from a AM Target Group
 /// </summary>
 public static Dynamic.TargetGroup BuildTargetGroup(Tridion.ContentManager.AudienceManagement.TargetGroup targetGroup)
 {
     var tg = new Dynamic.TargetGroup
     {
         Conditions = MapConditions(targetGroup.Conditions),
         Description = targetGroup.Description,
         Id = targetGroup.Id,
         OwningPublication = PublicationBuilder.BuildPublication(targetGroup.OwningRepository),
         Publication = PublicationBuilder.BuildPublication(targetGroup.ContextRepository),
         PublicationId = targetGroup.ContextRepository.Id,
         Title = targetGroup.Title
     };
     return tg;
 }
        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);
        }
        /// <summary>
        /// Implement the resolver function to control the resolving
        /// </summary>
        /// <param name="item">the item published</param>
        /// <param name="instruction">Resolve Instructiuons</param>
        /// <param name="context">Publish Context</param>
        /// <param name="resolvedItems">Collection of Resolved Items</param>
        public void Resolve(IdentifiableObject item, ResolveInstruction instruction, PublishContext context, Tridion.Collections.ISet<ResolvedItem> resolvedItems)
        {
            // Array of schemas which are supposed to publish independently with out resolved items
            string[] lookupSchemas = { "Schema Title1", "Schema Title2" };

            // If published item is a component and it's type belongs to look up schemas array, start the process
            if (item is Component)
            {
                Component comp1 = (Component)item;
                if (lookupSchemas.Contains(comp1.Schema.Title))
                {
                    // Temp collection of resolved items
                    List<ResolvedItem> tempItems = new List<ResolvedItem>();

                    // Loop through resolved items
                    foreach (var resolvedItem in resolvedItems)
                    {
                        // If the resolved item is the published item
                        // Allow it to be published by adding to temp items collection
                        if (resolvedItem.Item is Component)
                        {
                            Component compResolved = (Component)resolvedItem.Item;
                            if (resolvedItem.Item.Id == item.Id)
                            {
                                tempItems.Add(resolvedItem);
                            }
                        }
                    }

                    // Delete all resolved items
                    resolvedItems.Clear();

                    // Add temp items(needs to be published) to resolvedItems collection
                    foreach (ResolvedItem tempResolvedItem in tempItems)
                    {
                        resolvedItems.Add(tempResolvedItem);
                    }

                }
            }
        }
 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());
 }
Ejemplo n.º 9
0
 /// <summary>
 /// Initializes a new instance of the <see cref="LockInfo"/> class.
 /// </summary>
 /// <param name="client"><see cref="T:TcmCoreService.Client" /></param>
 /// <param name="lockInfo"><see cref="T:Tridion.ContentManager.CoreService.Client.LockInfo" /></param>
 public LockInfo(Client client, Tridion.ContentManager.CoreService.Client.LockInfo lockInfo)
     : base(client)
 {
     mLockInfo = lockInfo;
 }