private Binary PublishModuleTemplatesConfig(string moduleName, Folder moduleFolder, Component moduleConfigComponent) { OrganizationalItemItemsFilter moduleTemplatesFilter = new OrganizationalItemItemsFilter(Session) { ItemTypes = new[] { ItemType.ComponentTemplate }, Recursive = true }; ComponentTemplate[] moduleComponentTemplates = moduleFolder.GetItems(moduleTemplatesFilter).Cast <ComponentTemplate>().Where(ct => ct.IsRepositoryPublishable).ToArray(); if (!moduleComponentTemplates.Any()) { return(null); } IDictionary <string, int> moduleTemplatesConfig = new Dictionary <string, int>(); foreach (ComponentTemplate moduleTemplate in moduleComponentTemplates) { string templateKey = Utility.GetKeyFromTemplate(moduleTemplate); int sameKeyAsTemplate; if (moduleTemplatesConfig.TryGetValue(templateKey, out sameKeyAsTemplate)) { Logger.Warning(string.Format("{0} has same key ('{1}') as CT '{2}'; supressing from output.", moduleTemplate, templateKey, sameKeyAsTemplate)); continue; } moduleTemplatesConfig.Add(templateKey, moduleTemplate.Id.ItemId); } string fileName = string.Format("{0}.{1}", moduleName, TemplateConfigName); return(AddJsonBinary(moduleTemplatesConfig, moduleConfigComponent, _configStructureGroup, fileName, variantId: "templates")); }
public void Transform(Engine engine, Package package) { TemplatingLogger log = TemplatingLogger.GetLogger(GetType()); if (package.GetByName(Package.ComponentName) == null) { log.Info("This template should only be used with Component Templates. Could not find component in package, exiting"); return; } var c = (Component)engine.GetObject(package.GetByName(Package.ComponentName)); var container = (Folder)c.OrganizationalItem; var filter = new OrganizationalItemItemsFilter(engine.GetSession()) { ItemTypes = new[] { ItemType.Component } }; // Always faster to use GetListItems if we only need limited elements foreach (XmlNode node in container.GetListItems(filter)) { string componentId = node.Attributes["ID"].Value; string componentTitle = node.Attributes["Title"].Value; } // If we need more info, use GetItems instead foreach (Component component in container.GetItems(filter)) { // If your filter is messed up, GetItems will return objects that may // not be a Component, in which case the code will blow up with an // InvalidCastException. Be careful with filter.ItemTypes[] Schema componentSchema = component.Schema; SchemaPurpose purpose = componentSchema.Purpose; XmlElement content = component.Content; } }
private Binary PublishModuleSchemasConfig(string moduleName, Folder moduleFolder, Component moduleConfigComponent) { OrganizationalItemItemsFilter moduleSchemasFilter = new OrganizationalItemItemsFilter(Session) { ItemTypes = new [] { ItemType.Schema }, Recursive = true }; Schema[] moduleSchemas = moduleFolder.GetItems(moduleSchemasFilter).Cast <Schema>().Where(s => s.Purpose == SchemaPurpose.Component).ToArray(); if (!moduleSchemas.Any()) { return(null); } IDictionary <string, int> moduleSchemasConfig = new Dictionary <string, int>(); foreach (Schema moduleSchema in moduleSchemas) { string schemaKey = Utility.GetKeyFromSchema(moduleSchema); int sameKeyAsSchema; if (moduleSchemasConfig.TryGetValue(schemaKey, out sameKeyAsSchema)) { Logger.Warning(string.Format("{0} has same key ('{1}') as Schema '{2}'; supressing from output.", moduleSchema, schemaKey, sameKeyAsSchema)); continue; } moduleSchemasConfig.Add(schemaKey, moduleSchema.Id.ItemId); } string fileName = string.Format("{0}.{1}", moduleName, SchemasConfigName); return(AddJsonBinary(moduleSchemasConfig, moduleConfigComponent, _configStructureGroup, fileName, variantId: "schemas")); }
/// <summary> /// Overrides the TemplateBase method Transform. Implements actual logic -- identifies Root Structure Group /// of current Publication and kicks off recursive building of navigation XML. /// The generated XmlDocument is added to the Package as element "Output". /// </summary> /// <param name="engine"></param> /// <param name="package"></param> public override void Transform(Engine engine, Package package) { DateTime t = DateTime.Now; Initialize(engine, package); Publication publication = GetPublication(); StructureGroup rootSG = publication.RootStructureGroup; filter = new OrganizationalItemItemsFilter(rootSG.Session) { BaseColumns = ListBaseColumns.IdAndTitle, ItemTypes = new ItemType[] { ItemType.Page, ItemType.StructureGroup }, Recursive = true }; XmlElement navigationXml = BuildNavigationGetItems(rootSG); //record build navigation time string message = string.Format("Execution took {0:0.##}s", DateTime.Now.Subtract(t).TotalSeconds); navigationXml.AppendChild(navigationXml.OwnerDocument.CreateComment(message)); package.PushItem("Output", package.CreateXmlDocumentItem(ContentType.Xml, navigationXml.OwnerDocument)); }
protected IList <Page> GetPagesInSG(ListItem sg) { CheckInitialized(); Filter filter = new Filter(); filter.Conditions["ItemType"] = ItemType.Page; filter.BaseColumns = ListBaseColumns.Extended; filter.AdditionalColumns.Add("url"); filter.AdditionalColumns.Add("path"); // TODO: find a way to avoid retrieving the SG StructureGroup structuregroup = MEngine.GetObject(sg.Id) as StructureGroup; OrganizationalItemItemsFilter pageFilter = new OrganizationalItemItemsFilter(filter, structuregroup.Session); IList <RepositoryLocalObject> rlos = (IList <RepositoryLocalObject>)structuregroup.GetItems(pageFilter); List <Page> pages = new List <Page>(rlos.Count); foreach (RepositoryLocalObject o in rlos) { pages.Add((Page)o); } return(pages); }
private IDictionary <string, string> GetContextLabels() { var cacheKey = string.Format("labels|{0}", this.Configuration.LanguageCode); if (this.Cache.Contains(cacheKey)) { return((IDictionary <string, string>) this.Cache.Get(cacheKey)); } var labelsFolderWebDavUrl = this.Publication.WebDavUrl + "/folder/containing/label/components"; var labelsFolder = (Folder)this.Engine.GetObject(labelsFolderWebDavUrl); var filter = new OrganizationalItemItemsFilter(this.Engine.GetSession()); filter.ItemTypes = new List <ItemType> { ItemType.Component }; filter.Recursive = false; var labelComponents = labelsFolder.GetItems(filter).OfType <Component>(); var contextLabels = new Dictionary <string, string>(); foreach (var labelComponent in labelComponents) { if (labelComponent.Schema.Title == "Label") { contextLabels.Add(labelComponent.Title, labelComponent.GetText("value")); } } this.Cache.Set(cacheKey, contextLabels); return(contextLabels); }
private string GetLinkToSgIndexPage(StructureGroup sg, Session session) { OrganizationalItemItemsFilter filter = new OrganizationalItemItemsFilter(session) { ItemTypes = new[] { ItemType.Page } }; string title = StripNumbersFromTitle(sg.Title); const string pageLinkFormat = "<a tridion:href=\"{0}\">{1}</a>"; string result = null; foreach (XmlElement page in sg.GetListItems(filter).ChildNodes) { if (!page.Attributes["Title"].Value.ToLower().Contains(IndexPagePattern)) { continue; } result = string.Format(pageLinkFormat, page.Attributes["ID"].Value, title); break; } if (string.IsNullOrEmpty(result)) { result = title; } return(result); }
public static IEnumerable<StructureGroup> GetStructureGroups(this OrganizationalItem sg, bool recursive) { var filter = new OrganizationalItemItemsFilter(sg.Session) { ItemTypes = new[] { ItemType.StructureGroup }, Recursive = recursive }; return sg.GetItems(filter).Cast<StructureGroup>(); }
public static IEnumerable<Page> GetPages(this OrganizationalItem sg, bool recursive) { var filter = new OrganizationalItemItemsFilter(sg.Session) { ItemTypes = new[] { ItemType.Page }, Recursive = recursive }; return sg.GetItems(filter).Cast<Page>(); }
public static IEnumerable <StructureGroup> GetStructureGroups(this OrganizationalItem sg, bool recursive) { var filter = new OrganizationalItemItemsFilter(sg.Session) { ItemTypes = new[] { ItemType.StructureGroup }, Recursive = recursive }; return(sg.GetItems(filter).Cast <StructureGroup>()); }
public static IEnumerable <Page> GetPages(this OrganizationalItem sg, bool recursive) { var filter = new OrganizationalItemItemsFilter(sg.Session) { ItemTypes = new[] { ItemType.Page }, Recursive = recursive }; return(sg.GetItems(filter).Cast <Page>()); }
public static IEnumerable <Component> GetComponents(this OrganizationalItem folder, IEnumerable <Schema> basedOnSchemas, bool recursive) { var filter = new OrganizationalItemItemsFilter(folder.Session) { ItemTypes = new[] { ItemType.Component }, Recursive = recursive, BasedOnSchemas = basedOnSchemas }; return(folder.GetItems(filter).Cast <Component>()); }
public static IEnumerable<Component> GetComponents(this OrganizationalItem folder, IEnumerable<Schema> basedOnSchemas, bool recursive) { var filter = new OrganizationalItemItemsFilter(folder.Session) { ItemTypes = new[] { ItemType.Component }, Recursive = recursive, BasedOnSchemas = basedOnSchemas }; return folder.GetItems(filter).Cast<Component>(); }
public static IList<KeyValuePair<TcmUri, string>> GetOrganizationalItemContents(this OrganizationalItem orgItem, ItemType[] itemTypes, bool recursive) { OrganizationalItemItemsFilter filter = new OrganizationalItemItemsFilter(orgItem.Session) { ItemTypes = itemTypes, Recursive = recursive }; return (from XmlNode item in orgItem.GetListItems(filter).SelectNodes("/*/*") select new KeyValuePair<TcmUri, string>(new TcmUri(item.Attributes["ID"].Value), item.Attributes["Title"].Value)).ToList(); }
private IEnumerable <RepositoryLocalObject> GetStructureGroupItems(StructureGroup structureGroup, IEnumerable <ItemType> itemTypeFilter = null) { var filter = new OrganizationalItemItemsFilter(structureGroup.Session); filter.ItemTypes = itemTypeFilter ?? _itemTypeFilter; var items = structureGroup.GetItems(filter); return(items); }
public static IList <KeyValuePair <TcmUri, string> > GetOrganizationalItemContents(this OrganizationalItem orgItem, ItemType[] itemTypes, bool recursive) { OrganizationalItemItemsFilter filter = new OrganizationalItemItemsFilter(orgItem.Session) { ItemTypes = itemTypes, Recursive = recursive }; return((from XmlNode item in orgItem.GetListItems(filter).SelectNodes("/*/*") select new KeyValuePair <TcmUri, string>(new TcmUri(item.Attributes["ID"].Value), item.Attributes["Title"].Value)).ToList()); }
protected List <KeyValuePair <TcmUri, string> > GetOrganizationalItemContents(OrganizationalItem orgItem, ItemType itemType, bool recursive) { OrganizationalItemItemsFilter filter = new OrganizationalItemItemsFilter(orgItem.Session) { ItemTypes = new List <ItemType> { itemType }, Recursive = recursive }; return(XmlElementToTcmUriList(orgItem.GetListItems(filter))); }
/// <summary> /// Overrides the TemplateBase method Transform. Implements actual logic -- identifies Root Structure Group /// of current Publication and kicks off recursive building of navigation XML. /// The generated XmlDocument is added to the Package as element "Output". /// </summary> /// <param name="engine">Engine for current transformation</param> /// <param name="package">The current Package object</param> public override void Transform(Engine engine, Package package) { Initialize(engine, package); Publication publication = GetPublication(); StructureGroup rootSG = publication.RootStructureGroup; filter = new OrganizationalItemItemsFilter(rootSG.Session) { BaseColumns = ListBaseColumns.IdAndTitle, ItemTypes = new ItemType[] { ItemType.Page, ItemType.StructureGroup } }; XmlElement navigationXml = BuildNavigation(rootSG); package.PushItem("Output", package.CreateXmlDocumentItem(ContentType.Xml, navigationXml.OwnerDocument)); }
/// <summary> /// Retrieves a list of <see cref="T:Tridion.ContentManager.ContentManagement.Component" /> from a /// <see cref="T:Tridion.ContentManager.ContentManagement.OrganizationalItem" /> /// </summary> /// <param name="organizationalItem"><see cref="T:Tridion.ContentManager.ContentManagement.OrganizationalItem" /></param> /// <param name="recursive">if set to <c>true</c> [recursive].</param> /// <returns> /// List of <see cref="T:Tridion.ContentManager.ContentManagement.Component" /> /// </returns> public static List <Component> Components(this OrganizationalItem organizationalItem, bool recursive) { if (organizationalItem != null) { OrganizationalItemItemsFilter filter = new OrganizationalItemItemsFilter(organizationalItem.Session) { ItemTypes = new ItemType[] { ItemType.Component }, Recursive = recursive }; // Return a list of all matching component types return(organizationalItem.GetItems(filter).OfType <Component>().ToList()); } return(new List <Component>()); }
/// <summary> /// Retrieves a list of <see cref="T:Tridion.ContentManager.ContentManagement.Component" /> from a /// <see cref="T:Tridion.ContentManager.ContentManagement.OrganizationalItem" /> /// </summary> /// <param name="organizationalItem"><see cref="T:Tridion.ContentManager.ContentManagement.OrganizationalItem" /></param> /// <param name="schema">Schema <see cref="T:Tridion.ContentManager.ContentManagement.Schema" /> for filtering.</param> /// <returns>List of <see cref="T:Tridion.ContentManager.ContentManagement.Component" /></returns> public static List<Component> Components(this OrganizationalItem organizationalItem, Schema schema) { if (organizationalItem != null) { OrganizationalItemItemsFilter filter = new OrganizationalItemItemsFilter(organizationalItem.Session) { ItemTypes = new ItemType[] { ItemType.Component }, BasedOnSchemas = schema != null ? new Schema[] { schema } : null }; // Return a list of all matching component types return organizationalItem.GetItems(filter).OfType<Component>().ToList(); } return new List<Component>(); }
/// <summary> /// Retrieves a list of <see cref="T:Tridion.ContentManager.ContentManagement.Component" /> from a /// <see cref="T:Tridion.ContentManager.ContentManagement.OrganizationalItem" /> /// </summary> /// <param name="organizationalItem"><see cref="T:Tridion.ContentManager.ContentManagement.OrganizationalItem" /></param> /// <param name="recursive">if set to <c>true</c> [recursive].</param> /// <returns> /// List of <see cref="T:Tridion.ContentManager.ContentManagement.Component" /> /// </returns> public static List<Component> Components(this OrganizationalItem organizationalItem, bool recursive) { if (organizationalItem != null) { OrganizationalItemItemsFilter filter = new OrganizationalItemItemsFilter(organizationalItem.Session) { ItemTypes = new ItemType[] { ItemType.Component }, Recursive = recursive }; // Return a list of all matching component types return organizationalItem.GetItems(filter).OfType<Component>().ToList(); } return new List<Component>(); }
/// <summary> /// Retrieves a list of <see cref="T:Tridion.ContentManager.ContentManagement.Component" /> from a /// <see cref="T:Tridion.ContentManager.ContentManagement.OrganizationalItem" /> /// </summary> /// <param name="organizationalItem"><see cref="T:Tridion.ContentManager.ContentManagement.OrganizationalItem" /></param> /// <param name="schema">Schema <see cref="T:Tridion.ContentManager.ContentManagement.Schema" /> for filtering.</param> /// <returns>List of <see cref="T:Tridion.ContentManager.ContentManagement.Component" /></returns> public static List <Component> Components(this OrganizationalItem organizationalItem, Schema schema) { if (organizationalItem != null) { OrganizationalItemItemsFilter filter = new OrganizationalItemItemsFilter(organizationalItem.Session) { ItemTypes = new ItemType[] { ItemType.Component }, BasedOnSchemas = schema != null ? new Schema[] { schema } : null }; // Return a list of all matching component types return(organizationalItem.GetItems(filter).OfType <Component>().ToList()); } return(new List <Component>()); }
private string GetLinkToSgIndexPage(StructureGroup sg, Session session) { OrganizationalItemItemsFilter filter = new OrganizationalItemItemsFilter(session) { ItemTypes = new[] { ItemType.Page } }; string title = StripNumbersFromTitle(sg.Title); const string pageLinkFormat = "<a tridion:href=\"{0}\">{1}</a>"; string result = null; foreach (XmlElement page in sg.GetListItems(filter).ChildNodes) { if (!page.Attributes["Title"].Value.ToLower().Contains(IndexPagePattern)) continue; result = string.Format(pageLinkFormat, page.Attributes["ID"].Value, title); break; } if (string.IsNullOrEmpty(result)) { result = title; } return result; }
private bool ShouldBeExcluded(StructureGroup sg) { OrganizationalItemItemsFilter filterData = new OrganizationalItemItemsFilter(engine.GetSession()); filterData.ItemTypes = new ItemType[] { ItemType.StructureGroup, ItemType.Page }; filterData.Recursive = true; filterData.BaseColumns = ListBaseColumns.Extended; int pages = sg.GetListItems(filterData).SelectNodes("*").Count; /* * Filter filter = new Filter(); * filter.Conditions["ItemType"] = ItemType.StructureGroup; * filter.Conditions["Recursive"] = true; * filter.BaseColumns = ListBaseColumns.Id; * int pages = sg.GetListItems(filter).SelectNodes("*").Count;*/ return(pages == 0 ? true : false); }
public void Transform(Engine engine, Package package) { var logger = TemplatingLogger.GetLogger(typeof(PublishFolderMMCsToStructureGroup)); // Get containing folder of the component var componentItem = package.GetByName(Package.ComponentName); var component = (RepositoryLocalObject)engine.GetObject(componentItem); var folder = component.OrganizationalItem; var folderMetadata = new ItemFields(folder.Metadata, folder.MetadataSchema); var sgURL = folderMetadata["sgForBinaryPublish"] as SingleLineTextField; if (sgURL == null || sgURL.Value == null) { logger.Debug("No sgForBinaryPublish configured for this folder. Doing nothing."); return; } IdentifiableObject structureGroup = null; try { structureGroup = engine.GetObject(sgURL.Value); } catch (InvalidTcmUriException) { logger.Error("Folder metadata contains invalid value for sgForBinaryPublish."); } if (structureGroup == null) { logger.Error("Folder metadata contains a value for sgForBinaryPublish which does not locate an item"); } var filter = new OrganizationalItemItemsFilter(engine.GetSession()); filter.ItemTypes = new ItemType[] { ItemType.Component }; var components = folder.GetItems(filter).Cast <Component>().Where(c => c.BinaryContent != null); foreach (var comp in components) { engine.AddBinary(comp.Id, engine.PublishingContext.ResolvedItem.Template.Id, engine.LocalizeUri(structureGroup.Id), comp.BinaryContent.GetByteArray(), comp.Title); } }
protected List <KeyValuePair <TcmUri, string> > GetOrganizationalItemContents(OrganizationalItem orgItem, ItemType itemType, bool recursive) { //Filter filter = new Filter(); //filter.Conditions.Add("ItemType", itemType); //filter.Conditions.Add("Recursive", recursive); OrganizationalItemItemsFilter filter = new OrganizationalItemItemsFilter(orgItem.Session) { ItemTypes = new List <ItemType> { itemType }, Recursive = recursive }; List <KeyValuePair <TcmUri, string> > res = new List <KeyValuePair <TcmUri, string> >(); foreach (XmlNode item in orgItem.GetListItems(filter).SelectNodes("/*/*")) { string title = item.Attributes["Title"].Value; TcmUri id = new TcmUri(item.Attributes["ID"].Value); res.Add(new KeyValuePair <TcmUri, string>(id, title)); } return(res); }
private IEnumerable <XElement> GetItemsInFolderAsAList(StructureGroup startPoint) { OrganizationalItemItemsFilter filter = new OrganizationalItemItemsFilter(Engine.GetSession()) { ItemTypes = new List <ItemType> { ItemType.Page, ItemType.StructureGroup }, BaseColumns = ListBaseColumns.Extended }; //get pages first to see if they have to appear in nav XmlElement pagesXml = startPoint.GetListItems(filter); XmlDocument rootDocument = new XmlDocument(); rootDocument.LoadXml(pagesXml.OuterXml); XDocument pageDoc = XDocument.Parse(rootDocument.OuterXml); List <XElement> orderedDocument = (from XElement el in pageDoc.Root.Descendants() orderby el.Attribute("Title").Value select el).ToList(); return(orderedDocument); }
protected List <ListItem> GetPages(StructureGroup sg) { CheckInitialized(); Filter pageFilter = new Filter(); pageFilter.Conditions["ItemType"] = ItemType.Page; //pageFilter.BaseColumns = ListBaseColumns.Extended; //pageFilter.AdditionalColumns.Add("url"); //pageFilter.AdditionalColumns.Add("path"); OrganizationalItemItemsFilter itemsFilter = new OrganizationalItemItemsFilter(pageFilter, m_Engine.GetSession()); XmlElement orgItems = sg.GetListItems(itemsFilter); XmlNodeList itemElements = orgItems.SelectNodes("*"); List <ListItem> result = new List <ListItem>(itemElements.Count); foreach (XmlElement itemElement in itemElements) { result.Add(new ListItem(itemElement)); } return(result); }
protected List<KeyValuePair<TcmUri, string>> GetOrganizationalItemContents(OrganizationalItem orgItem, ItemType itemType, bool recursive) { OrganizationalItemItemsFilter filter = new OrganizationalItemItemsFilter(orgItem.Session) { ItemTypes = new List<ItemType> { itemType }, Recursive = recursive }; return XmlElementToTcmUriList(orgItem.GetListItems(filter)); }
private Binary PublishModuleSchemasConfig(string moduleName, Folder moduleFolder, Component moduleConfigComponent) { OrganizationalItemItemsFilter moduleSchemasFilter = new OrganizationalItemItemsFilter(Session) { ItemTypes = new [] { ItemType.Schema }, Recursive = true }; Schema[] moduleSchemas = moduleFolder.GetItems(moduleSchemasFilter).Cast<Schema>().Where(s => s.Purpose == SchemaPurpose.Component).ToArray(); if (!moduleSchemas.Any()) { return null; } IDictionary <string, int> moduleSchemasConfig = new Dictionary<string, int>(); foreach (Schema moduleSchema in moduleSchemas) { string schemaKey = Utility.GetKeyFromSchema(moduleSchema); int sameKeyAsSchema; if (moduleSchemasConfig.TryGetValue(schemaKey, out sameKeyAsSchema)) { Logger.Warning(string.Format("{0} has same key ('{1}') as Schema '{2}'; supressing from output.", moduleSchema, schemaKey, sameKeyAsSchema)); continue; } moduleSchemasConfig.Add(schemaKey, moduleSchema.Id.ItemId); } string fileName = string.Format("{0}.{1}", moduleName, SchemasConfigName); return AddJsonBinary(moduleSchemasConfig, moduleConfigComponent, _configStructureGroup, fileName, variantId: "schemas"); }
private Binary PublishModuleTemplatesConfig(string moduleName, Folder moduleFolder, Component moduleConfigComponent) { OrganizationalItemItemsFilter moduleTemplatesFilter = new OrganizationalItemItemsFilter(Session) { ItemTypes = new[] { ItemType.ComponentTemplate }, Recursive = true }; ComponentTemplate[] moduleComponentTemplates = moduleFolder.GetItems(moduleTemplatesFilter).Cast<ComponentTemplate>().Where(ct => ct.IsRepositoryPublishable).ToArray(); if (!moduleComponentTemplates.Any()) { return null; } IDictionary<string, int> moduleTemplatesConfig = new Dictionary<string, int>(); foreach (ComponentTemplate moduleTemplate in moduleComponentTemplates) { string templateKey = Utility.GetKeyFromTemplate(moduleTemplate); int sameKeyAsTemplate; if (moduleTemplatesConfig.TryGetValue(templateKey, out sameKeyAsTemplate)) { Logger.Warning(string.Format("{0} has same key ('{1}') as CT '{2}'; supressing from output.", moduleTemplate, templateKey, sameKeyAsTemplate)); continue; } moduleTemplatesConfig.Add(templateKey, moduleTemplate.Id.ItemId); } string fileName = string.Format("{0}.{1}", moduleName, TemplateConfigName); return AddJsonBinary(moduleTemplatesConfig,moduleConfigComponent, _configStructureGroup, fileName, variantId: "templates"); }
public Binary PublishBinary(Component mComponent, Session session, Package package, Engine engine, TemplatingLogger logger, string strFileName) { string rootFolderId = package.GetValue("RootFolder"); string rootSGId = package.GetValue("RootStructureGroup"); logger.Debug(string.Format("Using root Structure Group with Webdav Url: {0}", rootFolderId)); Folder rootFolder = session.GetObject(rootFolderId) as Folder; StructureGroup parentSG = session.GetObject(rootSGId) as StructureGroup; Stack<string> sgNames = new Stack<string>(); GetStructureGroupToBeCreated(mComponent.OrganizationalItem, rootFolder.Id, sgNames); OrganizationalItemItemsFilter sgFilter = new OrganizationalItemItemsFilter(session); sgFilter.Recursive = false; sgFilter.ItemTypes = new Tridion.ContentManager.ItemType[] { Tridion.ContentManager.ItemType.StructureGroup }; //string strCoreServicesUrl = package.GetValue("CoreServicesUrl"); while (sgNames.Count > 0) { string sgName = sgNames.Pop(); IEnumerable<StructureGroup> list = parentSG.GetItems(sgFilter). Where(w => w.Title.Equals(sgName)).Select(s => (StructureGroup)s); if (list.Count() == 0) { /* * TO DO: Enable tha auto creation of the Structure Group StructureGroupData newSG = SaveStructureGroup(sgName, parentSG.Id.ToString(), session.User.Title, strCoreServicesUrl); parentSG = new StructureGroup(new TcmUri(newSG.Id), session); logger.Debug(string.Format("New Structure Group needs {0} created at: {1}", newSG.Title, parentSG.Path)); * */ logger.Info(string.Format("Utilities.PublishBinary New Structure Group needs {0} created at: {1}", parentSG.Title, parentSG.Path)); } else { StructureGroup existingSG = list.First<StructureGroup>(); logger.Info(string.Format("Utilities.PublishBinary Existing Structure Group {0} found at: {1}", existingSG.Title, existingSG.Path)); parentSG = existingSG; } } Binary binary = null; if (strFileName == null) { binary = engine.PublishingContext.RenderedItem.AddBinary(mComponent, parentSG, mComponent.BinaryContent.Filename); } else { MemoryStream msStream = new MemoryStream(); mComponent.BinaryContent.WriteToStream(msStream); msStream.Seek(0, SeekOrigin.Begin); binary = engine.PublishingContext.RenderedItem.AddBinary(msStream, strFileName, parentSG, strFileName.Replace(" ", string.Empty), "text/xml"); } logger.Debug(string.Format("Binary {0} being published to {1}", mComponent.BinaryContent.Filename, parentSG.PublishLocationUrl)); return binary; }
private IEnumerable<XElement> GetItemsInFolderAsAList(StructureGroup startPoint) { OrganizationalItemItemsFilter filter = new OrganizationalItemItemsFilter(Engine.GetSession()) { ItemTypes = new List<ItemType> {ItemType.Page, ItemType.StructureGroup}, BaseColumns = ListBaseColumns.Extended }; //get pages first to see if they have to appear in nav XmlElement pagesXml = startPoint.GetListItems(filter); XmlDocument rootDocument = new XmlDocument(); rootDocument.LoadXml(pagesXml.OuterXml); XDocument pageDoc = XDocument.Parse(rootDocument.OuterXml); List<XElement> orderedDocument = (from XElement el in pageDoc.Root.Descendants() orderby el.Attribute("Title").Value select el).ToList(); return orderedDocument; }
private XmlDocument GenerateSitemap(StructureGroup sg, XmlDocument doc = null) { //create base doc doc = new XmlDocument(); XmlNode docNode = doc.CreateXmlDeclaration("1.0", "UTF-8", null); doc.AppendChild(docNode); //create root "<urlset>" element and append to the doc. XmlElement urlsetNode = doc.CreateElement("urlset"); urlsetNode.SetAttribute("xmlns", "http://www.sitemaps.org/schemas/sitemap/0.9"); //urlsetNode.SetAttribute("xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance"); doc.AppendChild(urlsetNode); // Get the list of child structure groups and pages in this SG /*Filter filter = new Filter(); * filter.Conditions["ItemType"] = 68;//pages, structure groups * filter.BaseColumns = ListBaseColumns.Extended;*/ OrganizationalItemItemsFilter filterData = new OrganizationalItemItemsFilter(engine.GetSession()); filterData.ItemTypes = new ItemType[] { ItemType.StructureGroup, ItemType.Page }; filterData.Recursive = true; filterData.BaseColumns = ListBaseColumns.Extended; XmlElement childItems = sg.GetListItems(filterData); foreach (XmlElement item in childItems.SelectNodes("*")) { string isPublished = item.GetAttribute("IsPublished"); string itemType = item.GetAttribute("Type"); string itemId = item.GetAttribute("ID"); if (int.Parse(itemType) == (int)ItemType.Page) { //only include published pages & exclude index.aspx,default.aspx,.ascx,.json pages if (bool.Parse(isPublished)) { Page childPage = engine.GetObject(itemId) as Page; if (!ShouldBeExcluded(childPage)) { XmlNode urlNode = doc.CreateElement("url"); urlsetNode.AppendChild(urlNode); XmlNode locNode = doc.CreateElement("loc"); locNode.AppendChild(doc.CreateTextNode(childPage.PublishLocationUrl)); urlNode.AppendChild(locNode); XmlNode lastmodNode = doc.CreateElement("lastmod"); lastmodNode.AppendChild(doc.CreateTextNode(childPage.RevisionDate.ToString())); urlNode.AppendChild(lastmodNode); XmlNode priorityNode = doc.CreateElement("priority"); priorityNode.AppendChild(doc.CreateTextNode("0.5")); urlNode.AppendChild(priorityNode); } } } else { log.Debug("sgId=" + itemId); //if it's a structure group, then get the object, create a child sitemap node StructureGroup childSg = engine.GetObject(itemId) as StructureGroup; if (!ShouldBeExcluded(childSg)) { if (!childSg.Title.Contains("_")) { XmlNode urlNode = doc.CreateElement("url"); urlsetNode.AppendChild(urlNode); XmlNode locNode = doc.CreateElement("loc"); locNode.AppendChild(doc.CreateTextNode(childSg.PublishLocationUrl)); urlNode.AppendChild(locNode); XmlNode lastmodNode = doc.CreateElement("lastmod"); lastmodNode.AppendChild(doc.CreateTextNode(childSg.RevisionDate.ToString())); urlNode.AppendChild(lastmodNode); XmlNode priorityNode = doc.CreateElement("priority"); priorityNode.AppendChild(doc.CreateTextNode("0.5")); urlNode.AppendChild(priorityNode); GenerateSitemap(childSg, doc); } } } } doc.Save(@"C:\Temp\testfolder\testfile.xml"); return(doc); }
public Binary PublishBinary(Component mComponent, Session session, Package package, Engine engine, TemplatingLogger logger, string strFileName) { string rootFolderId = package.GetValue("RootFolder"); string rootSGId = package.GetValue("RootStructureGroup"); logger.Debug(string.Format("Using root Structure Group with Webdav Url: {0}", rootFolderId)); Folder rootFolder = session.GetObject(rootFolderId) as Folder; StructureGroup parentSG = session.GetObject(rootSGId) as StructureGroup; Stack <string> sgNames = new Stack <string>(); GetStructureGroupToBeCreated(mComponent.OrganizationalItem, rootFolder.Id, sgNames); OrganizationalItemItemsFilter sgFilter = new OrganizationalItemItemsFilter(session); sgFilter.Recursive = false; sgFilter.ItemTypes = new Tridion.ContentManager.ItemType[] { Tridion.ContentManager.ItemType.StructureGroup }; //string strCoreServicesUrl = package.GetValue("CoreServicesUrl"); while (sgNames.Count > 0) { string sgName = sgNames.Pop(); IEnumerable <StructureGroup> list = parentSG.GetItems(sgFilter). Where(w => w.Title.Equals(sgName)).Select(s => (StructureGroup)s); if (list.Count() == 0) { /* * TO DO: Enable tha auto creation of the Structure Group * StructureGroupData newSG = SaveStructureGroup(sgName, parentSG.Id.ToString(), session.User.Title, strCoreServicesUrl); * parentSG = new StructureGroup(new TcmUri(newSG.Id), session); * * logger.Debug(string.Format("New Structure Group needs {0} created at: {1}", newSG.Title, parentSG.Path)); * */ logger.Info(string.Format("Utilities.PublishBinary New Structure Group needs {0} created at: {1}", parentSG.Title, parentSG.Path)); } else { StructureGroup existingSG = list.First <StructureGroup>(); logger.Info(string.Format("Utilities.PublishBinary Existing Structure Group {0} found at: {1}", existingSG.Title, existingSG.Path)); parentSG = existingSG; } } Binary binary = null; if (strFileName == null) { binary = engine.PublishingContext.RenderedItem.AddBinary(mComponent, parentSG, mComponent.BinaryContent.Filename); } else { MemoryStream msStream = new MemoryStream(); mComponent.BinaryContent.WriteToStream(msStream); msStream.Seek(0, SeekOrigin.Begin); binary = engine.PublishingContext.RenderedItem.AddBinary(msStream, strFileName, parentSG, strFileName.Replace(" ", string.Empty), "text/xml"); } logger.Debug(string.Format("Binary {0} being published to {1}", mComponent.BinaryContent.Filename, parentSG.PublishLocationUrl)); return(binary); }