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 Schema GetNewSchema(SchemaPurpose purpose) { //init engine Component inputItem = (Component)TestSession.GetObject(CoreComponentWebDavUrl); // Create TestData Regions Publication testPublication = (Publication)inputItem.ContextRepository; var title = Guid.NewGuid().ToString("N"); var schema = new Schema(TestSession, testPublication.RootFolder.Id) { Purpose = purpose, Title = title, Description = title }; return(schema); }
internal string GetSchema(string schemaTitle, string parentFolderId, string xsd = null, SchemaPurpose purpose = SchemaPurpose.UnknownByClient, string rootElementName = "Content") { Stopwatch watch = new Stopwatch(); watch.Start(); Console.WriteLine("Creating schema " + schemaTitle); string schemaId = TcmUri.UriNull; OrganizationalItemItemsFilterData filter = new OrganizationalItemItemsFilterData { ItemTypes = new[] { ItemType .Schema } }; foreach (XElement node in _client.GetListXml(parentFolderId, filter).Nodes()) { if (!node.Attribute("Title").Value.Equals(schemaTitle)) { continue; } schemaId = node.Attribute("ID").Value; } if (schemaId.Equals(TcmUri.UriNull) && xsd != null && CreateIfNewItem && purpose != SchemaPurpose.UnknownByClient) { SchemaData schema = (SchemaData)_client.GetDefaultData(ItemType.Schema, parentFolderId); schema.Title = schemaTitle; schema.Description = schemaTitle; schema.Purpose = purpose; schema.RootElementName = rootElementName; schema.Xsd = xsd; schema = (SchemaData)_client.Save(schema, _readOptions); schema = (SchemaData)_client.CheckIn(schema.Id, _readOptions); schemaId = schema.Id; } watch.Stop(); Console.WriteLine("Returning Schema ID " + schemaId + " (" + watch.ElapsedMilliseconds + " milliseconds)"); return(schemaId); }