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 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"); }