protected void GetPages() { CheckInitialized(); Publication publication = GetPublication(); Filter filter = new Filter(); filter.Conditions["ItemType"] = ItemType.Page; filter.Conditions["Recursive"] = true; filter.BaseColumns = ListBaseColumns.Extended; filter.AdditionalColumns.Add("url"); RepositoryItemsFilter pageFilter = new RepositoryItemsFilter(filter, publication.Session); XmlElement orgItems = publication.GetListItems(pageFilter); /* * XmlNodeList itemElements = orgItems.SelectNodes("*"); * List<ListItem> result = new List<ListItem>(itemElements.Count); * foreach (XmlElement itemElement in itemElements) * { * ListItem sg = new ListItem(itemElement); * result.Add(sg); * } */ XmlDocument doc = new XmlDocument(); doc.AppendChild(doc.ImportNode(orgItems, true)); MPackage.PushItem("Pages", MPackage.CreateXmlDocumentItem(ContentType.Xml, doc)); }
protected virtual List <string> ReadPageTemplateIncludes() { //Generate a list of Page Templates which have includes in the metadata List <string> res = new List <string>(); RepositoryItemsFilter templateFilter = new RepositoryItemsFilter(Engine.GetSession()) { ItemTypes = new List <ItemType> { ItemType.PageTemplate }, Recursive = true }; foreach (XmlElement item in GetPublication().GetListItems(templateFilter).ChildNodes) { string id = item.GetAttribute("ID"); PageTemplate template = (PageTemplate)Engine.GetObject(id); if (template.MetadataSchema != null && template.Metadata != null) { ItemFields meta = new ItemFields(template.Metadata, template.MetadataSchema); IEnumerable <string> values = meta.GetTextValues("includes"); if (values != null) { List <string> includes = new List <string>(); foreach (string val in values) { includes.Add(JsonEncode(val)); } string json = String.Format("\"{0}\":[{1}]", template.Id.ItemId, String.Join(",\n", includes)); res.Add(json); } } } return(res); }
private Dictionary <string, XpmRegionData> CollectNativeRegions() { Dictionary <string, XpmRegionData> nativeRegions = new Dictionary <string, XpmRegionData>(); RepositoryItemsFilter filter = new RepositoryItemsFilter(Session) { SchemaPurposes = new[] { SchemaPurpose.Region }, ItemTypes = new[] { ItemType.Schema }, Recursive = true }; IEnumerable <Schema> regionSchemas = Publication.GetItems(filter).Cast <Schema>(); foreach (Schema schema in regionSchemas) { dynamic regionDefinition = schema.RegionDefinition; string regionSchemaId = schema.Id.ItemId.ToString(); if (nativeRegions.All(nr => nr.Key != regionSchemaId)) { XpmRegionData nativeRegion = new XpmRegionData { Region = regionSchemaId, ComponentTypes = GetComponentTypeConstraints(regionDefinition), OccurrenceConstraint = GetOccurrenceConstraint(regionDefinition) }; nativeRegions.Add(regionSchemaId, nativeRegion); } else { Logger.Debug($"Region {regionSchemaId} has already been added. Skipping."); } } return(nativeRegions); }
protected virtual List<string> ReadPageTemplateIncludes() { //Generate a list of Page Templates which have includes in the metadata var res = new List<string>(); var templateFilter = new RepositoryItemsFilter(Engine.GetSession()); templateFilter.ItemTypes = new List<ItemType> { ItemType.PageTemplate }; templateFilter.Recursive = true; foreach (XmlElement item in GetPublication().GetListItems(templateFilter).ChildNodes) { var id = item.GetAttribute("ID"); var template = (PageTemplate)Engine.GetObject(id); if (template.MetadataSchema != null && template.Metadata != null) { ItemFields meta = new ItemFields(template.Metadata, template.MetadataSchema); var values = meta.GetTextValues("includes"); if (values != null) { var includes = new List<string>(); foreach (var val in values) { includes.Add(JsonEncode(val)); } var json = String.Format("\"{0}\":[{1}]", template.Id.ItemId, String.Join(",\n", includes)); res.Add(json); } } } return res; }
/// <summary> /// Returns the root structure group for the specified publication /// </summary> /// <returns>The Root Structure Group in the publication</returns> /// <remarks>copied and modified code from Repository.RootFolder :)</remarks> public static StructureGroup GetRootSG(this Repository publication) { RepositoryItemsFilter filter = new RepositoryItemsFilter(publication.Session) { ItemTypes = new[] { ItemType.StructureGroup } }; List<RepositoryLocalObject> items = (List<RepositoryLocalObject>)publication.GetItems(filter); if (items.Count == 0) return null; return (StructureGroup)items[0]; }
private Binary PublishSemanticSchemas(StructureGroup structureGroup, Component relatedComponent) { RepositoryItemsFilter schemasFilter = new RepositoryItemsFilter(Session) { Recursive = true, ItemTypes = new[] { ItemType.Schema }, SchemaPurposes = new[] { SchemaPurpose.Component, SchemaPurpose.Multimedia, SchemaPurpose.Metadata, SchemaPurpose.Region } }; IEnumerable <Schema> schemas = Publication.GetItems(schemasFilter).Cast <Schema>(); SemanticSchemaData[] semanticSchemas = schemas.Select(GetSemanticSchema).ToArray(); return(AddJsonBinary(semanticSchemas, relatedComponent, structureGroup, "schemas", variantId: "semantic-schemas")); }
private Dictionary <string, XpmRegionData> CollectNativeRegions() { Dictionary <string, XpmRegionData> nativeRegions = new Dictionary <string, XpmRegionData>(); RepositoryItemsFilter filter = new RepositoryItemsFilter(Session) { SchemaPurposes = new[] { SchemaPurpose.Region }, ItemTypes = new[] { ItemType.Schema }, Recursive = true }; IEnumerable <Schema> regionSchemas = Publication.GetItems(filter).Cast <Schema>(); foreach (Schema schema in regionSchemas) { dynamic regionDefinition = schema.RegionDefinition; dynamic schemasNestedRegions = regionDefinition.NestedRegions; if (schemasNestedRegions != null) { foreach (dynamic nestedRegionDefinition in schemasNestedRegions) { string regionName = nestedRegionDefinition.RegionName; if (nativeRegions.All(nr => nr.Key != regionName)) { XpmRegionData nativeRegion = new XpmRegionData { Region = regionName, ComponentTypes = new List <XpmComponentTypeData> { new XpmComponentTypeData { Schema = "*", Template = "*" } // Allow all schemas/templates } }; nativeRegions.Add(regionName, nativeRegion); } else { // TODO : Should be revisited in context of the story CMF1-259 Logger.Debug($"Region {regionName} has already been added. Skipping."); } } } } return(nativeRegions); }
/// <summary> /// Returns the root structure group for the specified publication /// </summary> /// <returns>The Root Structure Group in the publication</returns> /// <remarks>copied and modified code from Repository.RootFolder :)</remarks> protected StructureGroup GetRootSG(Repository publication) { Filter filter = new Filter(); filter.Conditions["ItemType"] = ItemType.StructureGroup; RepositoryItemsFilter repoItemsFilter = new RepositoryItemsFilter(filter, publication.Session); IList <RepositoryLocalObject> items = publication.GetItems(repoItemsFilter).ToList <RepositoryLocalObject>(); if (items.Count == 0) { return(null); } else { return((StructureGroup)items[0]); } }
private Binary PublishSemanticVocabularies(StructureGroup structureGroup, Component relatedComponent) { ApplicationData vocabularyAppData = Session.SystemManager.LoadGlobalApplicationData(VocabulariesAppDataId); if (vocabularyAppData == null) { throw new DxaException("No Vocabularies are defined in Global Application Data: " + VocabulariesAppDataId); } XElement vocabulariesXml = XElement.Parse(Encoding.Unicode.GetString(vocabularyAppData.Data)); List <VocabularyData> vocabularies = vocabulariesXml.Elements() .Select(vocabElement => new VocabularyData { Prefix = vocabElement.Attribute("prefix").Value, Vocab = vocabElement.Attribute("name").Value }) .ToList(); if (_retrofitMode) { Logger.Info("Retrofit mode is enabled; generating semantic vocabularies for each (non-embedded) Schema."); RepositoryItemsFilter schemasFilter = new RepositoryItemsFilter(Session) { Recursive = true, ItemTypes = new[] { ItemType.Schema }, SchemaPurposes = new[] { SchemaPurpose.Component, SchemaPurpose.Multimedia, SchemaPurpose.Metadata, SchemaPurpose.Region } }; IEnumerable <Schema> schemas = Publication.GetItems(schemasFilter).Cast <Schema>(); vocabularies.AddRange(schemas.Select(schema => new VocabularyData { Prefix = GetDefaultVocabularyPrefix(schema), Vocab = schema.NamespaceUri })); } if (!vocabularies.Any(vocab => vocab.Prefix == CoreVocabularyPrefix)) { VocabularyData coreVocabulary = new VocabularyData { Prefix = CoreVocabularyPrefix, Vocab = CoreVocabulary }; vocabularies.Add(coreVocabulary); } return(AddJsonBinary(vocabularies, relatedComponent, structureGroup, "vocabularies")); }
private Schema GetModuleConfigSchema() { Publication pub = GetPublication(); RepositoryItemsFilter filter = new RepositoryItemsFilter(pub.Session) { ItemTypes = new List <ItemType> { ItemType.Schema }, Recursive = true }; foreach (KeyValuePair <TcmUri, string> item in XmlElementToTcmUriList(GetPublication().GetListItems(filter))) { if (item.Value == "Module Configuration") { return((Schema)pub.Session.GetObject(item.Key)); } } throw new Exception("Cannot find Schema named \"Module Configuration\"- please check that this has not been renamed."); }
private Binary PublishPageIncludes(StructureGroup structureGroup, Component relatedComponent) { IDictionary <string, string[]> pageIncludes = new Dictionary <string, string[]>(); RepositoryItemsFilter pageTemplatesFilter = new RepositoryItemsFilter(Session) { ItemTypes = new[] { ItemType.PageTemplate }, Recursive = true }; IEnumerable <PageTemplate> pageTemplates = Publication.GetItems(pageTemplatesFilter).Cast <PageTemplate>(); foreach (PageTemplate pt in pageTemplates.Where(pt => pt.MetadataSchema != null && pt.Metadata != null)) { ItemFields ptMetadataFields = new ItemFields(pt.Metadata, pt.MetadataSchema); string[] includes = ptMetadataFields.GetTextValues("includes").Select(id => GetPublishPath(id)).ToArray(); pageIncludes.Add(pt.Id.ItemId.ToString(), includes); } return(AddJsonBinary(pageIncludes, relatedComponent, structureGroup, "includes")); }
/// <summary> /// Returns the root structure group for the specified publication /// </summary> /// <returns>The Root Structure Group in the publication</returns> /// <remarks>copied and modified code from Repository.RootFolder :)</remarks> protected StructureGroup GetRootSG(Repository publication) { //Filter filter = new Filter(); //filter.Conditions["ItemType"] = ItemType.StructureGroup; RepositoryItemsFilter filter = new RepositoryItemsFilter(publication.Session) { ItemTypes = new List <ItemType> { ItemType.StructureGroup } }; IList <RepositoryLocalObject> items = (IList <RepositoryLocalObject>)publication.GetItems(filter); if (items.Count == 0) { return(null); } else { return((StructureGroup)items[0]); } }
private Binary PublishSemanticSchemas(StructureGroup structureGroup, Component relatedComponent) { RepositoryItemsFilter schemasFilter = new RepositoryItemsFilter(Session) { Recursive = true, ItemTypes = new [] { ItemType.Schema }, SchemaPurposes = new [] { SchemaPurpose.Component, SchemaPurpose.Multimedia, SchemaPurpose.Metadata } }; IEnumerable<Schema> schemas = Publication.GetItems(schemasFilter).Cast<Schema>(); SemanticSchemaData[] semanticSchemas = schemas.Select(GetSemanticSchema).ToArray(); return AddJsonBinary(semanticSchemas, relatedComponent, structureGroup, "schemas", variantId: "semantic-schemas"); }
private Dictionary<string, List<string>> ReadMappingsData() { bool containsDefaultVocabulary = false; // generate a list of vocabulary prefix and name from appdata Dictionary<string, List<string>> res = new Dictionary<string, List<string>> { { VocabulariesConfigName, new List<string>() } }; ApplicationData globalAppData = Engine.GetSession().SystemManager.LoadGlobalApplicationData(VocabulariesAppDataId); if (globalAppData != null) { XElement vocabulariesXml = XElement.Parse(Encoding.Unicode.GetString(globalAppData.Data)); foreach (XElement vocabulary in vocabulariesXml.Elements()) { string prefix = vocabulary.Attribute("prefix").Value; res[VocabulariesConfigName].Add(String.Format("{{\"Prefix\":{0},\"Vocab\":{1}}}", JsonEncode(prefix), JsonEncode(vocabulary.Attribute("name").Value))); if (prefix.Equals(DefaultVocabularyPrefix)) { containsDefaultVocabulary = true; } } } // add default vocabulary if it is not there already if (!containsDefaultVocabulary) { res[VocabulariesConfigName].Add(String.Format("{{\"Prefix\":{0},\"Vocab\":{1}}}", JsonEncode(DefaultVocabularyPrefix), JsonEncode(DefaultVocabulary))); } // generate a list of schema + id, separated by module RepositoryItemsFilter schemaFilter = new RepositoryItemsFilter(Engine.GetSession()) { Recursive = true, ItemTypes = new [] { ItemType.Schema }, // NOTE: including SchemaPurpose.Metadata for Page Metadata SchemaPurposes = new [] { SchemaPurpose.Component, SchemaPurpose.Multimedia, SchemaPurpose.Metadata }, BaseColumns = ListBaseColumns.Extended }; res.Add(SchemasConfigName, new List<string>()); foreach (Schema schema in GetPublication().GetItems(schemaFilter).Cast<Schema>()) { string rootElementName = schema.RootElementName; if (String.IsNullOrEmpty(rootElementName)) { // multimedia/metadata schemas don't have a root element name, so lets use its title without any invalid characters rootElementName = Regex.Replace(schema.Title.Trim(), InvalidCharactersPattern, String.Empty); } // add schema typeof using tridion standard implementation vocabulary prefix string typeOf = String.Format("{0}:{1}", DefaultVocabularyPrefix, rootElementName); StringBuilder schemaSemantics = new StringBuilder(); // append schema typeof from appdata ApplicationData appData = schema.LoadApplicationData(TypeOfAppDataId); if (appData != null) { typeOf += "," + ExtractTypeOfAppData(appData); } schemaSemantics.Append(BuildSchemaSemanticsJson(typeOf)); // TODO: serialize schema fields xml to json in a smart way // field: {"Name":"something","Path":"/something","IsMultiValue":true,"Semantics":[],"Fields":[]} // field semantics: {"Prefix":"s","Entity";"Article","Property":"headline"} StringBuilder fields = new StringBuilder(); // load namespace manager with schema namespaces XmlNamespaceManager nsmgr = SchemaNamespaceManager(schema.Xsd.OwnerDocument.NameTable); // build field elements from schema string path = "/" + rootElementName; fields.Append(BuildSchemaFieldsJson(schema, path, typeOf, nsmgr)); res[SchemasConfigName].Add(String.Format("{{\"Id\":{0},\"RootElement\":{1},\"Fields\":[{2}],\"Semantics\":[{3}]}}", JsonEncode(schema.Id.ItemId), JsonEncode(rootElementName), fields, schemaSemantics)); } // get region mappings for all templates Dictionary<string, List<string>> regions = BuildRegionMappings(); res.Add(RegionConfigName, new List<string>()); foreach (KeyValuePair<string, List<string>> region in regions) { StringBuilder allowedComponentTypes = new StringBuilder(); bool first = true; foreach (string componentType in region.Value) { if (first) { first = false; } else { allowedComponentTypes.Append(","); } allowedComponentTypes.Append(componentType); } res[RegionConfigName].Add(String.Format("{{\"Region\":{0},\"ComponentTypes\":[{1}]}}", JsonEncode(region.Key), allowedComponentTypes)); } return res; }
private Schema GetModuleConfigSchema() { Publication pub = GetPublication(); RepositoryItemsFilter filter = new RepositoryItemsFilter(pub.Session) { ItemTypes = new List<ItemType> { ItemType.Schema }, Recursive = true }; foreach (KeyValuePair<TcmUri, string> item in XmlElementToTcmUriList(GetPublication().GetListItems(filter))) { if (item.Value == "Module Configuration") { return (Schema)pub.Session.GetObject(item.Key); } } throw new Exception("Cannot find Schema named \"Module Configuration\"- please check that this has not been renamed."); }
public void Transform(Engine engine, Package package) { _log.Debug("GetAllComponentTemplates: start Transform"); Stopwatch watch = new Stopwatch(); watch.Start(); Session session = engine.GetSession(); ICache cache = session.Cache; String componentTemplateName = String.Empty; if (package.GetValue("ComponentTemplateName") != null) { componentTemplateName = package.GetValue("ComponentTemplateName"); } if (!(String.IsNullOrEmpty(componentTemplateName)) && (package.GetByName(componentTemplateName) != null)) { // Component Template found in Package return; } RepositoryLocalObject context; if (package.GetByName(Package.ComponentName) != null) context = engine.GetObject(package.GetByName(Package.ComponentName)) as RepositoryLocalObject; else context = engine.GetObject(package.GetByName(Package.PageName)) as RepositoryLocalObject; if (context != null) { Repository contextPublication = context.ContextRepository; RepositoryItemsFilter filter = new RepositoryItemsFilter(session) { ItemTypes = new[] { ItemType.ComponentTemplate }, Recursive = true, BaseColumns = ListBaseColumns.IdAndTitle }; XmlNamespaceManager nm = new XmlNamespaceManager(new NameTable()); nm.AddNamespace(Constants.TcmPrefix, Constants.TcmNamespace); XmlNodeList allComponentTemplates; if (cache.Get("ComponentTemplate", "listcts") != null) { allComponentTemplates = (XmlNodeList)cache.Get("ComponentTemplate", "listcts"); _log.Debug("GetAllComponentTemplates: list already in cache"); } else { allComponentTemplates = contextPublication.GetListItems(filter).SelectNodes("/tcm:ListItems/tcm:Item", nm); cache.Add("ComponentTemplate", "listcts", allComponentTemplates); _log.Debug("GetAllComponentTemplates: list created in cache"); } if (allComponentTemplates != null) foreach (XmlNode ct in allComponentTemplates) { if (ct.Attributes != null) { String ctName = ct.Attributes["Title"].Value.Replace(" ", "").Replace("-", ""); // Avoid duplicates in Package // Possible performance impact, but could be needed if ComponentTemplateName is set to an empty String if (package.GetByName(ctName) == null) package.PushItem(ctName, package.CreateStringItem(ContentType.Text, ct.Attributes["ID"].Value)); } } } watch.Stop(); _log.Debug("Template finished in " + watch.ElapsedMilliseconds + " milliseconds."); }
private Dictionary <string, List <string> > ReadMappingsData() { bool containsDefaultVocabulary = false; // generate a list of vocabulary prefix and name from appdata Dictionary <string, List <string> > res = new Dictionary <string, List <string> > { { VocabulariesConfigName, new List <string>() } }; ApplicationData globalAppData = Engine.GetSession().SystemManager.LoadGlobalApplicationData(VocabulariesAppDataId); if (globalAppData != null) { XElement vocabulariesXml = XElement.Parse(Encoding.Unicode.GetString(globalAppData.Data)); foreach (XElement vocabulary in vocabulariesXml.Elements()) { string prefix = vocabulary.Attribute("prefix").Value; res[VocabulariesConfigName].Add(String.Format("{{\"Prefix\":{0},\"Vocab\":{1}}}", JsonEncode(prefix), JsonEncode(vocabulary.Attribute("name").Value))); if (prefix.Equals(DefaultVocabularyPrefix)) { containsDefaultVocabulary = true; } } } // add default vocabulary if it is not there already if (!containsDefaultVocabulary) { res[VocabulariesConfigName].Add(String.Format("{{\"Prefix\":{0},\"Vocab\":{1}}}", JsonEncode(DefaultVocabularyPrefix), JsonEncode(DefaultVocabulary))); } // generate a list of schema + id, separated by module RepositoryItemsFilter schemaFilter = new RepositoryItemsFilter(Engine.GetSession()) { Recursive = true, ItemTypes = new [] { ItemType.Schema }, // NOTE: including SchemaPurpose.Metadata for Page Metadata SchemaPurposes = new [] { SchemaPurpose.Component, SchemaPurpose.Multimedia, SchemaPurpose.Metadata }, BaseColumns = ListBaseColumns.Extended }; res.Add(SchemasConfigName, new List <string>()); foreach (Schema schema in GetPublication().GetItems(schemaFilter).Cast <Schema>()) { string rootElementName = schema.RootElementName; if (String.IsNullOrEmpty(rootElementName)) { // multimedia/metadata schemas don't have a root element name, so lets use its title without any invalid characters rootElementName = Regex.Replace(schema.Title.Trim(), InvalidCharactersPattern, String.Empty); } // add schema typeof using tridion standard implementation vocabulary prefix string typeOf = String.Format("{0}:{1}", DefaultVocabularyPrefix, rootElementName); StringBuilder schemaSemantics = new StringBuilder(); // append schema typeof from appdata ApplicationData appData = schema.LoadApplicationData(TypeOfAppDataId); if (appData != null) { typeOf += "," + ExtractTypeOfAppData(appData); } schemaSemantics.Append(BuildSchemaSemanticsJson(typeOf)); // TODO: serialize schema fields xml to json in a smart way // field: {"Name":"something","Path":"/something","IsMultiValue":true,"Semantics":[],"Fields":[]} // field semantics: {"Prefix":"s","Entity";"Article","Property":"headline"} StringBuilder fields = new StringBuilder(); // load namespace manager with schema namespaces XmlNamespaceManager nsmgr = SchemaNamespaceManager(schema.Xsd.OwnerDocument.NameTable); // build field elements from schema string path = "/" + rootElementName; fields.Append(BuildSchemaFieldsJson(schema, path, typeOf, nsmgr)); res[SchemasConfigName].Add(String.Format("{{\"Id\":{0},\"RootElement\":{1},\"Fields\":[{2}],\"Semantics\":[{3}]}}", JsonEncode(schema.Id.ItemId), JsonEncode(rootElementName), fields, schemaSemantics)); } // get region mappings for all templates Dictionary <string, List <string> > regions = BuildRegionMappings(); res.Add(RegionConfigName, new List <string>()); foreach (KeyValuePair <string, List <string> > region in regions) { StringBuilder allowedComponentTypes = new StringBuilder(); bool first = true; foreach (string componentType in region.Value) { if (first) { first = false; } else { allowedComponentTypes.Append(","); } allowedComponentTypes.Append(componentType); } res[RegionConfigName].Add(String.Format("{{\"Region\":{0},\"ComponentTypes\":[{1}]}}", JsonEncode(region.Key), allowedComponentTypes)); } return(res); }
public void Transform(Engine engine, Package package) { _log.Debug("GetAllComponentTemplates: start Transform"); Stopwatch watch = new Stopwatch(); watch.Start(); Session session = engine.GetSession(); ICache cache = session.Cache; String componentTemplateName = String.Empty; if (package.GetValue("ComponentTemplateName") != null) { componentTemplateName = package.GetValue("ComponentTemplateName"); } if (!(String.IsNullOrEmpty(componentTemplateName)) && (package.GetByName(componentTemplateName) != null)) { // Component Template found in Package return; } RepositoryLocalObject context; if (package.GetByName(Package.ComponentName) != null) { context = engine.GetObject(package.GetByName(Package.ComponentName)) as RepositoryLocalObject; } else { context = engine.GetObject(package.GetByName(Package.PageName)) as RepositoryLocalObject; } if (context != null) { Repository contextPublication = context.ContextRepository; RepositoryItemsFilter filter = new RepositoryItemsFilter(session) { ItemTypes = new[] { ItemType.ComponentTemplate }, Recursive = true, BaseColumns = ListBaseColumns.IdAndTitle }; XmlNamespaceManager nm = new XmlNamespaceManager(new NameTable()); nm.AddNamespace(Constants.TcmPrefix, Constants.TcmNamespace); XmlNodeList allComponentTemplates; if (cache.Get("ComponentTemplate", "listcts") != null) { allComponentTemplates = (XmlNodeList)cache.Get("ComponentTemplate", "listcts"); _log.Debug("GetAllComponentTemplates: list already in cache"); } else { allComponentTemplates = contextPublication.GetListItems(filter).SelectNodes("/tcm:ListItems/tcm:Item", nm); cache.Add("ComponentTemplate", "listcts", allComponentTemplates); _log.Debug("GetAllComponentTemplates: list created in cache"); } if (allComponentTemplates != null) { foreach (XmlNode ct in allComponentTemplates) { if (ct.Attributes != null) { String ctName = ct.Attributes["Title"].Value.Replace(" ", "").Replace("-", ""); // Avoid duplicates in Package // Possible performance impact, but could be needed if ComponentTemplateName is set to an empty String if (package.GetByName(ctName) == null) { package.PushItem(ctName, package.CreateStringItem(ContentType.Text, ct.Attributes["ID"].Value)); } } } } } watch.Stop(); _log.Debug("Template finished in " + watch.ElapsedMilliseconds + " milliseconds."); }
private Binary PublishSemanticVocabularies(StructureGroup structureGroup, Component relatedComponent) { ApplicationData vocabularyAppData = Session.SystemManager.LoadGlobalApplicationData(VocabulariesAppDataId); if (vocabularyAppData == null) { throw new DxaException("No Vocabularies are defined in Global Application Data: " + VocabulariesAppDataId); } XElement vocabulariesXml = XElement.Parse(Encoding.Unicode.GetString(vocabularyAppData.Data)); List<VocabularyData> vocabularies = vocabulariesXml.Elements() .Select(vocabElement => new VocabularyData { Prefix = vocabElement.Attribute("prefix").Value, Vocab = vocabElement.Attribute("name").Value }) .ToList(); if (_retrofitMode) { Logger.Info("Retrofit mode is enabled; generating semantic vocabularies for each (non-embedded) Schema."); RepositoryItemsFilter schemasFilter = new RepositoryItemsFilter(Session) { Recursive = true, ItemTypes = new[] { ItemType.Schema }, SchemaPurposes = new[] { SchemaPurpose.Component, SchemaPurpose.Multimedia, SchemaPurpose.Metadata } }; IEnumerable<Schema> schemas = Publication.GetItems(schemasFilter).Cast<Schema>(); vocabularies.AddRange(schemas.Select(schema => new VocabularyData { Prefix = GetDefaultVocabularyPrefix(schema), Vocab = schema.NamespaceUri })); } if (!vocabularies.Any(vocab => vocab.Prefix == CoreVocabularyPrefix)) { VocabularyData coreVocabulary = new VocabularyData { Prefix = CoreVocabularyPrefix, Vocab = CoreVocabulary }; vocabularies.Add(coreVocabulary); } return AddJsonBinary(vocabularies, relatedComponent, structureGroup, "vocabularies"); }
protected virtual Dictionary<string, List<string>> ReadSchemaData() { //Generate a list of schema + mapping details, separated by module Dictionary<string, List<string>> res = new Dictionary<string, List<string>>(); RepositoryItemsFilter schemaFilter = new RepositoryItemsFilter(Engine.GetSession()) { Recursive = true, ItemTypes = new List<ItemType> { ItemType.Schema }, BaseColumns = ListBaseColumns.Extended }; foreach (XmlElement item in GetPublication().GetListItems(schemaFilter).ChildNodes) { string type = item.GetAttribute("Type"); string subType = item.GetAttribute("SubType"); //We only consider normal schemas (type=8 subtype=0) if ((type == "8" && subType == "0")) { string id = item.GetAttribute("ID"); Schema schema = (Schema)Engine.GetObject(id); string module = GetModuleNameFromItem(schema, _moduleRoot); if (module != null) { string key = module + "." + SchemasConfigName; if (!res.ContainsKey(key)) { res.Add(key, new List<string>()); } res[key].Add(String.Format("{0}:{1}", JsonEncode(Utility.GetKeyFromSchema(schema)), JsonEncode(schema.Id.ItemId))); } } } return res; }
private Binary PublishPageIncludes(StructureGroup structureGroup, Component relatedComponent) { IDictionary<string, string[]> pageIncludes = new Dictionary<string, string[]>(); RepositoryItemsFilter pageTemplatesFilter = new RepositoryItemsFilter(Session) { ItemTypes = new [] { ItemType.PageTemplate }, Recursive = true }; IEnumerable<PageTemplate> pageTemplates = Publication.GetItems(pageTemplatesFilter).Cast<PageTemplate>(); foreach (PageTemplate pt in pageTemplates.Where(pt => pt.MetadataSchema != null && pt.Metadata != null)) { ItemFields ptMetadataFields = new ItemFields(pt.Metadata, pt.MetadataSchema); string[] includes = ptMetadataFields.GetTextValues("includes").ToArray(); pageIncludes.Add(pt.Id.ItemId.ToString(), includes); } return AddJsonBinary(pageIncludes, relatedComponent, structureGroup, "includes"); }