public static Dynamic.ComponentPresentation BuildComponentPresentation(TCM.ComponentPresentation tcmComponentPresentation, Engine engine, BuildManager manager) { TemplatingLogger logger = TemplatingLogger.GetLogger(typeof(ComponentPresentationBuilder)); Dynamic.ComponentPresentation cp = new Dynamic.ComponentPresentation(); logger.Debug(string.Format(">BuildCP {0} ({1})", tcmComponentPresentation.ComponentTemplate.Title, tcmComponentPresentation.ComponentTemplate.IsRepositoryPublishable)); if (tcmComponentPresentation.ComponentTemplate.IsRepositoryPublishable) { // call render but ignore the output - render ensures componentlinking will be setup as normal. // don't bother with page flags because the end result is dynamically published so it needs to run with DCP settings engine.RenderComponentPresentation(tcmComponentPresentation.Component.Id, tcmComponentPresentation.ComponentTemplate.Id); // ignore the rendered CP, because it is already available in the broker // instead, we will render a very simple version without any links cp.Component = manager.BuildComponent(tcmComponentPresentation.Component, 0); // linkLevel = 0 means: only summarize the component cp.IsDynamic = true; } else { // render the component presentation using its own CT // but first, set a parameter in the context so that the CT will know it is beng called // from a DynamicDelivery page template if (engine.PublishingContext.RenderContext != null && !engine.PublishingContext.RenderContext.ContextVariables.Contains(BasePageTemplate.VariableNameCalledFromDynamicDelivery)) { engine.PublishingContext.RenderContext.ContextVariables.Add(BasePageTemplate.VariableNameCalledFromDynamicDelivery, BasePageTemplate.VariableValueCalledFromDynamicDelivery); } string renderedContent = engine.RenderComponentPresentation(tcmComponentPresentation.Component.Id, tcmComponentPresentation.ComponentTemplate.Id); renderedContent = TridionUtils.StripTcdlTags(renderedContent); // rendered content could contain si4t search data. if that's the case, the value of renderedCotnent is not valid DD4T data. // lets remove the si4t search data if that's the case. string dd4tData = Si4tUtils.RemoveSearchData(renderedContent); try { // we cannot be sure the component template uses the same serializer service as the page template // so we will call a factory which can detect the correct service based on the content ISerializerService serializerService = SerializerServiceFactory.FindSerializerServiceForContent(dd4tData); cp = serializerService.Deserialize <Dynamic.ComponentPresentation>(dd4tData); // inital renderedContent could contain si4t search data. we need to preserve the search data. // lets retrieve the si4t search data if that's the case and added to the renderedContent property cp.RenderedContent = Si4tUtils.RetrieveSearchData(renderedContent); } catch (Exception e) { log.Error("exception while deserializing into CP", e); // the component presentation could not be deserialized, this probably not a Dynamic Delivery template // just store the output as 'RenderedContent' on the CP cp.RenderedContent = renderedContent; // because the CT was not a DD4T CT, we will generate the DD4T XML code here cp.Component = manager.BuildComponent(tcmComponentPresentation.Component); } cp.IsDynamic = false; } cp.ComponentTemplate = manager.BuildComponentTemplate(tcmComponentPresentation.ComponentTemplate); return(cp); }
public static Dynamic.ComponentPresentation BuildComponentPresentation(TCM.ComponentPresentation tcmComponentPresentation, Engine engine, int linkLevels, bool resolveWidthAndHeight, BuildManager manager) { Dynamic.ComponentPresentation cp = new Dynamic.ComponentPresentation(); if (tcmComponentPresentation.ComponentTemplate.IsRepositoryPublishable) { // call render but ignore the output - render ensures componentlinking will be setup as normal. // don't bother with page flags because the end result is dynamically published so it needs to run with DCP settings engine.RenderComponentPresentation(tcmComponentPresentation.Component.Id, tcmComponentPresentation.ComponentTemplate.Id); // ignore the rendered CP, because it is already available in the broker // instead, we will render a very simple version without any links cp.Component = manager.BuildComponent(tcmComponentPresentation.Component, 0, false,false); // linkLevels = 0 means: only summarize the component cp.IsDynamic = true; } else { // render the component presentation using its own CT // but first, set a parameter in the context so that the CT will know it is beng called // from a DynamicDelivery page template if (engine.PublishingContext.RenderContext != null && !engine.PublishingContext.RenderContext.ContextVariables.Contains(BasePageTemplate.VariableNameCalledFromDynamicDelivery)) { engine.PublishingContext.RenderContext.ContextVariables.Add(BasePageTemplate.VariableNameCalledFromDynamicDelivery, BasePageTemplate.VariableValueCalledFromDynamicDelivery); } string renderedContent = engine.RenderComponentPresentation(tcmComponentPresentation.Component.Id, tcmComponentPresentation.ComponentTemplate.Id); engine.PublishingContext.RenderContext.ContextVariables.Remove(BasePageTemplate.VariableNameCalledFromDynamicDelivery); renderedContent = TridionUtils.StripTcdlTags(renderedContent); cp.IsDynamic = false; TextReader tr = new StringReader(renderedContent); if (serializer == null) { serializer = new ComponentSerializer(); //serializer = new XmlSerializerFactory().CreateSerializer(typeof(Dynamic.Component)); } try { cp.Component = (Dynamic.Component)serializer.Deserialize(tr); } catch (Exception e) { TemplatingLogger.GetLogger(typeof(ComponentPresentationBuilder)).Error("exception while deserializing into CP: " + e.Message); // the component presentation could not be deserialized, this probably not a Dynamic Delivery template // just store the output as 'RenderedContent' on the CP cp.RenderedContent = renderedContent; // because the CT was not a DD4T CT, we will generate the DD4T XML code here cp.Component = manager.BuildComponent(tcmComponentPresentation.Component); } } cp.ComponentTemplate = manager.BuildComponentTemplate(tcmComponentPresentation.ComponentTemplate); return cp; }
public static Dynamic.ComponentPresentation BuildComponentPresentation(TCM.ComponentPresentation tcmComponentPresentation, Engine engine, int linkLevels, bool resolveWidthAndHeight, BuildManager manager) { Dynamic.ComponentPresentation cp = new Dynamic.ComponentPresentation(); if (tcmComponentPresentation.ComponentTemplate.IsRepositoryPublishable) { // call render but ignore the output - render ensures componentlinking will be setup as normal. // don't bother with page flags because the end result is dynamically published so it needs to run with DCP settings engine.RenderComponentPresentation(tcmComponentPresentation.Component.Id, tcmComponentPresentation.ComponentTemplate.Id); // ignore the rendered CP, because it is already available in the broker // instead, we will render a very simple version without any links cp.Component = manager.BuildComponent(tcmComponentPresentation.Component, 0, false, false); // linkLevels = 0 means: only summarize the component cp.IsDynamic = true; } else { // render the component presentation using its own CT // but first, set a parameter in the context so that the CT will know it is beng called // from a DynamicDelivery page template if (engine.PublishingContext.RenderContext != null && !engine.PublishingContext.RenderContext.ContextVariables.Contains(BasePageTemplate.VariableNameCalledFromDynamicDelivery)) { engine.PublishingContext.RenderContext.ContextVariables.Add(BasePageTemplate.VariableNameCalledFromDynamicDelivery, BasePageTemplate.VariableValueCalledFromDynamicDelivery); } string renderedContent = engine.RenderComponentPresentation(tcmComponentPresentation.Component.Id, tcmComponentPresentation.ComponentTemplate.Id); engine.PublishingContext.RenderContext.ContextVariables.Remove(BasePageTemplate.VariableNameCalledFromDynamicDelivery); renderedContent = TridionUtils.StripTcdlTags(renderedContent); cp.IsDynamic = false; TextReader tr = new StringReader(renderedContent); if (serializer == null) { serializer = new ComponentSerializer(); //serializer = new XmlSerializerFactory().CreateSerializer(typeof(Dynamic.Component)); } try { cp.Component = (Dynamic.Component)serializer.Deserialize(tr); } catch (Exception e) { TemplatingLogger.GetLogger(typeof(ComponentPresentationBuilder)).Error("exception while deserializing into CP: " + e.Message); // the component presentation could not be deserialized, this probably not a Dynamic Delivery template // just store the output as 'RenderedContent' on the CP cp.RenderedContent = renderedContent; // because the CT was not a DD4T CT, we will generate the DD4T XML code here cp.Component = manager.BuildComponent(tcmComponentPresentation.Component); } } cp.ComponentTemplate = manager.BuildComponentTemplate(tcmComponentPresentation.ComponentTemplate); return(cp); }
public static Dynamic.ComponentPresentation BuildComponentPresentation(TCM.ComponentPresentation tcmComponentPresentation, Engine engine, BuildManager manager) { TemplatingLogger logger = TemplatingLogger.GetLogger(typeof(ComponentPresentationBuilder)); Dynamic.ComponentPresentation cp = new Dynamic.ComponentPresentation(); logger.Debug(string.Format(">BuildCP {0} ({1})", tcmComponentPresentation.ComponentTemplate.Title, tcmComponentPresentation.ComponentTemplate.IsRepositoryPublishable)); if (tcmComponentPresentation.ComponentTemplate.IsRepositoryPublishable) { // call render but ignore the output - render ensures componentlinking will be setup as normal. // don't bother with page flags because the end result is dynamically published so it needs to run with DCP settings engine.RenderComponentPresentation(tcmComponentPresentation.Component.Id, tcmComponentPresentation.ComponentTemplate.Id); // ignore the rendered CP, because it is already available in the broker // instead, we will render a very simple version without any links cp.Component = manager.BuildComponent(tcmComponentPresentation.Component, 0); // linkLevel = 0 means: only summarize the component cp.IsDynamic = true; } else { // render the component presentation using its own CT // but first, set a parameter in the context so that the CT will know it is beng called // from a DynamicDelivery page template if (engine.PublishingContext.RenderContext != null && !engine.PublishingContext.RenderContext.ContextVariables.Contains(BasePageTemplate.VariableNameCalledFromDynamicDelivery)) { engine.PublishingContext.RenderContext.ContextVariables.Add(BasePageTemplate.VariableNameCalledFromDynamicDelivery, BasePageTemplate.VariableValueCalledFromDynamicDelivery); } string renderedContent = engine.RenderComponentPresentation(tcmComponentPresentation.Component.Id, tcmComponentPresentation.ComponentTemplate.Id); renderedContent = TridionUtils.StripTcdlTags(renderedContent); try { // we cannot be sure the component template uses the same serializer service as the page template // so we will call a factory which can detect the correct service based on the content ISerializerService serializerService = SerializerServiceFactory.FindSerializerServiceForContent(renderedContent); cp = serializerService.Deserialize<Dynamic.ComponentPresentation>(renderedContent); } catch (Exception e) { log.Error("exception while deserializing into CP", e); // the component presentation could not be deserialized, this probably not a Dynamic Delivery template // just store the output as 'RenderedContent' on the CP cp.RenderedContent = renderedContent; // because the CT was not a DD4T CT, we will generate the DD4T XML code here cp.Component = manager.BuildComponent(tcmComponentPresentation.Component); } cp.IsDynamic = false; } cp.ComponentTemplate = manager.BuildComponentTemplate(tcmComponentPresentation.ComponentTemplate); return cp; }
public static Dynamic.Field BuildField(TCM.Fields.ItemField tcmItemField, int currentLinkLevel, BuildManager manager) { Dynamic.Field f = new Dynamic.Field(); if (tcmItemField == null && manager.BuildProperties.PublishEmptyFields) { f.Values.Add(""); return f; } else if (tcmItemField == null && !manager.BuildProperties.PublishEmptyFields) { throw new FieldHasNoValueException(); } f.Name = tcmItemField.Name; if (tcmItemField is TCM.Fields.XhtmlField) { TCM.Fields.XhtmlField sField = (TCM.Fields.XhtmlField)tcmItemField; if (sField.Values.Count == 0 && manager.BuildProperties.PublishEmptyFields) { f.Values.Add(""); } else if (sField.Values.Count == 0 && !manager.BuildProperties.PublishEmptyFields) { throw new FieldHasNoValueException(); } else { foreach (string v in sField.Values) { f.Values.Add(manager.PublishBinariesInRichTextField(v)); } } f.FieldType = FieldType.Xhtml; return f; } if (tcmItemField is TCM.Fields.MultiLineTextField) { TCM.Fields.TextField sField = (TCM.Fields.MultiLineTextField)tcmItemField; if (sField.Values.Count == 0 && manager.BuildProperties.PublishEmptyFields) { f.Values.Add(""); } else if (sField.Values.Count == 0 && !manager.BuildProperties.PublishEmptyFields) { throw new FieldHasNoValueException(); } else { foreach (string v in sField.Values) { f.Values.Add(v); } } f.FieldType = FieldType.MultiLineText; return f; } if (tcmItemField is TCM.Fields.TextField) { TCM.Fields.TextField sField = (TCM.Fields.TextField)tcmItemField; if (sField.Values.Count == 0 && manager.BuildProperties.PublishEmptyFields) { f.Values.Add(""); } else if (sField.Values.Count == 0 && !manager.BuildProperties.PublishEmptyFields) { throw new FieldHasNoValueException(); } else { foreach (string v in sField.Values) { f.Values.Add(v); } } f.FieldType = FieldType.Text; return f; } if (tcmItemField is TCM.Fields.KeywordField) { TCM.Fields.KeywordField sField = (TCM.Fields.KeywordField)tcmItemField; if (sField.Values.Count == 0 && manager.BuildProperties.PublishEmptyFields) { f.Values.Add(""); } else if (sField.Values.Count == 0 && !manager.BuildProperties.PublishEmptyFields) { throw new FieldHasNoValueException(); } else { // add keyword values f.Keywords = new List<Keyword>(); // we will wrap each linked component in a ContentModel component foreach (TCM.Keyword kw in sField.Values) { f.Keywords.Add(manager.BuildKeyword(kw)); } if (!manager.BuildProperties.OmitValueLists) { f.Values = new List<string>(); foreach (TCM.Keyword kw in sField.Values) { f.Values.Add(kw.Title); } } KeywordFieldDefinition fieldDef = (KeywordFieldDefinition)sField.Definition; f.CategoryId = fieldDef.Category.Id; f.CategoryName = fieldDef.Category.Title; } f.FieldType = FieldType.Keyword; return f; } if (tcmItemField is TCM.Fields.NumberField) { TCM.Fields.NumberField sField = (TCM.Fields.NumberField)tcmItemField; if (sField.Values.Count == 0 && manager.BuildProperties.PublishEmptyFields) { f.Values.Add(""); } else if (sField.Values.Count == 0 && !manager.BuildProperties.PublishEmptyFields) { throw new FieldHasNoValueException(); } else { f.NumericValues = (List<double>)sField.Values; if (!manager.BuildProperties.OmitValueLists) { f.Values = new List<string>(); foreach (double d in f.NumericValues) { f.Values.Add(Convert.ToString(d)); } } } f.FieldType = FieldType.Number; return f; } if (tcmItemField is TCM.Fields.DateField) { TCM.Fields.DateField sField = (TCM.Fields.DateField)tcmItemField; if (sField.Values.Count == 0 && manager.BuildProperties.PublishEmptyFields) { f.Values.Add(""); } else if (sField.Values.Count == 0 && !manager.BuildProperties.PublishEmptyFields) { throw new FieldHasNoValueException(); } else { f.DateTimeValues = (List<DateTime>)sField.Values; if (!manager.BuildProperties.OmitValueLists) { f.Values = new List<string>(); foreach (DateTime dt in f.DateTimeValues) { f.Values.Add(Convert.ToString(dt)); } } } f.FieldType = FieldType.Date; return f; } if (tcmItemField is TCM.Fields.MultimediaLinkField) { TCM.Fields.MultimediaLinkField sField = (TCM.Fields.MultimediaLinkField)tcmItemField; if (sField.Values.Count == 0 && manager.BuildProperties.PublishEmptyFields) { f.Values.Add(tcmItemField.Name); } else if (sField.Values.Count == 0 && !manager.BuildProperties.PublishEmptyFields) { throw new FieldHasNoValueException(); } else { // we will wrap each linked component in a ContentModel component f.LinkedComponentValues = new List<Dynamic.Component>(); int nextLinkLevel = currentLinkLevel - 1; if (MustFollowField(sField, manager)) { log.Debug(string.Format("found component link field named {0} with global followLinksPerField property set to false OR followLink set to true for this field", sField.Name)); } else { log.Debug(string.Format("found component link field named {0} with followLink set to false for this field", sField.Name)); nextLinkLevel = 0; } foreach (TCM.Component comp in sField.Values) { f.LinkedComponentValues.Add(manager.BuildComponent(comp, nextLinkLevel)); } if (!manager.BuildProperties.OmitValueLists) { f.Values = new List<string>(); foreach (Dynamic.Component c in f.LinkedComponentValues) { f.Values.Add(c.Id); } } } f.FieldType = FieldType.MultiMediaLink; return f; } if (tcmItemField is TCM.Fields.ComponentLinkField) { TCM.Fields.ComponentLinkField sField = (TCM.Fields.ComponentLinkField)tcmItemField; if (sField.Values.Count == 0 && manager.BuildProperties.PublishEmptyFields) { f.Values.Add(tcmItemField.Name); } else if (sField.Values.Count == 0 && !manager.BuildProperties.PublishEmptyFields) { throw new FieldHasNoValueException(); } else { // we will wrap each linked component in a ContentModel component f.LinkedComponentValues = new List<Dynamic.Component>(); int nextLinkLevel = currentLinkLevel - 1; if (MustFollowField(sField, manager)) { log.Debug(string.Format("found component link field named {0} with global followLinksPerField property set to false OR followLink set to true for this field", sField.Name)); } else { log.Debug(string.Format("found component link field named {0} with followLink set to false for this field", sField.Name)); nextLinkLevel = 0; } foreach (TCM.Component comp in sField.Values) { f.LinkedComponentValues.Add(manager.BuildComponent(comp, nextLinkLevel)); } if (!manager.BuildProperties.OmitValueLists) { f.Values = new List<string>(); foreach (Dynamic.Component c in f.LinkedComponentValues) { f.Values.Add(c.Id); } } } f.FieldType = FieldType.ComponentLink; return f; } if (tcmItemField is TCM.Fields.EmbeddedSchemaField) { TCM.Fields.EmbeddedSchemaField sField = (TCM.Fields.EmbeddedSchemaField)tcmItemField; f.FieldType = FieldType.Embedded; f.EmbeddedValues = new List<Dynamic.FieldSet>(); bool hasValues = CheckIfEmbeddedFieldHasValues(sField); if (!hasValues && manager.BuildProperties.PublishEmptyFields) { Dynamic.FieldSet fields = new FieldSet(); Dynamic.Field fe = new Dynamic.Field(); f.EmbeddedSchema = manager.BuildSchema(((EmbeddedSchemaFieldDefinition)sField.Definition).EmbeddedSchema); EmbeddedSchemaFieldDefinition linksFieldDefinition = sField.Definition as EmbeddedSchemaFieldDefinition; ItemFields newItemField = new ItemFields(linksFieldDefinition.EmbeddedSchema); for (int i = 0; i < newItemField.Count; i++) { if (newItemField[i] is TCM.Fields.EmbeddedSchemaField) { TCM.Fields.EmbeddedSchemaField innerField = (TCM.Fields.EmbeddedSchemaField)newItemField[i]; if (innerField.Values.Count == 0) { Dynamic.FieldSet fieldsinner = new FieldSet(); Dynamic.Field fin = new Dynamic.Field(); fe.EmbeddedSchema = manager.BuildSchema(((EmbeddedSchemaFieldDefinition)innerField.Definition).EmbeddedSchema); EmbeddedSchemaFieldDefinition inlinksFieldDefinition = innerField.Definition as EmbeddedSchemaFieldDefinition; ItemFields newinItemField = new ItemFields(inlinksFieldDefinition.EmbeddedSchema); for (int n = 0; n < newinItemField.Count; n++) { fin.Name = newItemField[n].Name; fieldsinner.Add(newinItemField[n].Name, fin); } fe.EmbeddedValues.Add(fieldsinner); fe.Values.Add(""); } fe.Name = newItemField[i].Name; fields.Add(newItemField[i].Name, fe); } else { Dynamic.Field fein = manager.BuildField(newItemField[i], currentLinkLevel); fein.Values.Clear(); fields.Add(newItemField[i].Name, fein); } } f.EmbeddedValues.Add(fields); f.Values.Add(""); } else if (!hasValues && !manager.BuildProperties.PublishEmptyFields) { throw new FieldHasNoValueException(); } else { // we will wrap each linked component in a ContentModel component f.EmbeddedValues = new List<Dynamic.FieldSet>(); f.EmbeddedSchema = manager.BuildSchema(((EmbeddedSchemaFieldDefinition)sField.Definition).EmbeddedSchema); foreach (TCM.Fields.ItemFields embeddedFields in sField.Values) { f.EmbeddedValues.Add(manager.BuildFields(embeddedFields, currentLinkLevel)); } } return f; } throw new FieldTypeNotDefinedException(); }
public static Dynamic.Field BuildField(TCM.Fields.ItemField tcmItemField, int linkLevels, bool resolveWidthAndHeight, bool publishEmptyFields, BuildManager manager) { Dynamic.Field f = new Dynamic.Field(); if (tcmItemField == null && publishEmptyFields) { GeneralUtils.TimedLog("item field is null"); //throw new FieldHasNoValueException(); f.Values.Add(""); return(f); } else if (tcmItemField == null && !publishEmptyFields) { throw new FieldHasNoValueException(); } f.Name = tcmItemField.Name; if (tcmItemField is TCM.Fields.XhtmlField) { TCM.Fields.XhtmlField sField = (TCM.Fields.XhtmlField)tcmItemField; GeneralUtils.TimedLog(string.Format("item field {0} has {1} values", tcmItemField.Name, sField.Values.Count)); if (sField.Values.Count == 0 && publishEmptyFields) { //throw new FieldHasNoValueException(); f.Values.Add(""); } else if (sField.Values.Count == 0 && !publishEmptyFields) { throw new FieldHasNoValueException(); } else { foreach (string v in sField.Values) { f.Values.Add(v); } } f.FieldType = FieldType.Xhtml; return(f); } if (tcmItemField is TCM.Fields.MultiLineTextField) { TCM.Fields.TextField sField = (TCM.Fields.MultiLineTextField)tcmItemField; GeneralUtils.TimedLog(string.Format("item field {0} has {1} values", tcmItemField.Name, sField.Values.Count)); //if (sField.Values.Count == 0) // throw new FieldHasNoValueException(); if (sField.Values.Count == 0 && publishEmptyFields) { //throw new FieldHasNoValueException(); f.Values.Add(""); } else if (sField.Values.Count == 0 && !publishEmptyFields) { throw new FieldHasNoValueException(); } else { foreach (string v in sField.Values) { f.Values.Add(v); } } f.FieldType = FieldType.MultiLineText; return(f); } if (tcmItemField is TCM.Fields.TextField) { TCM.Fields.TextField sField = (TCM.Fields.TextField)tcmItemField; GeneralUtils.TimedLog(string.Format("item field {0} has {1} values", tcmItemField.Name, sField.Values.Count)); //if (sField.Values.Count == 0) // throw new FieldHasNoValueException(); if (sField.Values.Count == 0 && publishEmptyFields) { //throw new FieldHasNoValueException(); f.Values.Add(""); } else if (sField.Values.Count == 0 && !publishEmptyFields) { throw new FieldHasNoValueException(); } else { foreach (string v in sField.Values) { f.Values.Add(v); } } f.FieldType = FieldType.Text; return(f); } if (tcmItemField is TCM.Fields.KeywordField) { TCM.Fields.KeywordField sField = (TCM.Fields.KeywordField)tcmItemField; GeneralUtils.TimedLog(string.Format("item field {0} has {1} values", tcmItemField.Name, sField.Values.Count)); //if (sField.Values.Count == 0) // throw new FieldHasNoValueException(); if (sField.Values.Count == 0 && publishEmptyFields) { //throw new FieldHasNoValueException(); f.Values.Add(""); } else if (sField.Values.Count == 0 && !publishEmptyFields) { throw new FieldHasNoValueException(); } else { // add keyword values f.Keywords = new List <Keyword>(); // we will wrap each linked component in a ContentModel component f.Values = new List <string>(); foreach (TCM.Keyword kw in sField.Values) { // todo: add binary to package, and add BinaryUrl property to the component f.Values.Add(kw.Title); f.Keywords.Add(manager.BuildKeyword(kw)); } KeywordFieldDefinition fieldDef = (KeywordFieldDefinition)sField.Definition; f.CategoryId = fieldDef.Category.Id; f.CategoryName = fieldDef.Category.Title; } f.FieldType = FieldType.Keyword; return(f); } if (tcmItemField is TCM.Fields.NumberField) { TCM.Fields.NumberField sField = (TCM.Fields.NumberField)tcmItemField; GeneralUtils.TimedLog(string.Format("item field {0} has {1} values", tcmItemField.Name, sField.Values.Count)); //if (sField.Values.Count == 0) // throw new FieldHasNoValueException(); if (sField.Values.Count == 0 && publishEmptyFields) { //throw new FieldHasNoValueException(); f.Values.Add(""); } else if (sField.Values.Count == 0 && !publishEmptyFields) { throw new FieldHasNoValueException(); } else { f.NumericValues = (List <double>)sField.Values; f.Values = new List <string>(); foreach (double d in f.NumericValues) { f.Values.Add(Convert.ToString(d)); } } f.FieldType = FieldType.Number; return(f); } if (tcmItemField is TCM.Fields.DateField) { TCM.Fields.DateField sField = (TCM.Fields.DateField)tcmItemField; GeneralUtils.TimedLog(string.Format("item field {0} has {1} values", tcmItemField.Name, sField.Values.Count)); //if (sField.Values.Count == 0) // throw new FieldHasNoValueException(); if (sField.Values.Count == 0 && publishEmptyFields) { //throw new FieldHasNoValueException(); f.Values.Add(""); } else if (sField.Values.Count == 0 && !publishEmptyFields) { throw new FieldHasNoValueException(); } else { f.DateTimeValues = (List <DateTime>)sField.Values; f.Values = new List <string>(); foreach (DateTime dt in f.DateTimeValues) { f.Values.Add(Convert.ToString(dt)); } } f.FieldType = FieldType.Date; return(f); } if (tcmItemField is TCM.Fields.MultimediaLinkField) { TCM.Fields.MultimediaLinkField sField = (TCM.Fields.MultimediaLinkField)tcmItemField; GeneralUtils.TimedLog(string.Format("item field {0} has {1} values", tcmItemField.Name, sField.Values.Count)); if (sField.Values.Count == 0 && publishEmptyFields) { f.Values.Add(tcmItemField.Name); } else if (sField.Values.Count == 0 && !publishEmptyFields) { throw new FieldHasNoValueException(); } else { // we will wrap each linked component in a ContentModel component f.LinkedComponentValues = new List <Dynamic.Component>(); foreach (TCM.Component comp in sField.Values) { // todo: add binary to package, and add BinaryUrl property to the component f.LinkedComponentValues.Add(manager.BuildComponent(comp, linkLevels - 1, resolveWidthAndHeight, publishEmptyFields)); } f.Values = new List <string>(); foreach (Dynamic.Component c in f.LinkedComponentValues) { f.Values.Add(c.Id); } } f.FieldType = FieldType.MultiMediaLink; return(f); } if (tcmItemField is TCM.Fields.ComponentLinkField) { TCM.Fields.ComponentLinkField sField = (TCM.Fields.ComponentLinkField)tcmItemField; GeneralUtils.TimedLog(string.Format("item field {0} has {1} values", tcmItemField.Name, sField.Values.Count)); //if (sField.Values.Count == 0) // throw new FieldHasNoValueException(); if (sField.Values.Count == 0 && publishEmptyFields) { f.Values.Add(tcmItemField.Name); } else if (sField.Values.Count == 0 && !publishEmptyFields) { throw new FieldHasNoValueException(); } else { // we will wrap each linked component in a ContentModel component f.LinkedComponentValues = new List <Dynamic.Component>(); foreach (TCM.Component comp in sField.Values) { f.LinkedComponentValues.Add(manager.BuildComponent(comp, linkLevels - 1, resolveWidthAndHeight, publishEmptyFields)); } f.Values = new List <string>(); foreach (Dynamic.Component c in f.LinkedComponentValues) { f.Values.Add(c.Id); } } f.FieldType = FieldType.ComponentLink; return(f); } if (tcmItemField is TCM.Fields.EmbeddedSchemaField) { TCM.Fields.EmbeddedSchemaField sField = (TCM.Fields.EmbeddedSchemaField)tcmItemField; GeneralUtils.TimedLog(string.Format("item field {0} has {1} values", tcmItemField.Name, sField.Values.Count)); //if (sField.Values.Count == 0) //throw new FieldHasNoValueException(); f.FieldType = FieldType.Embedded; f.EmbeddedValues = new List <Dynamic.FieldSet>(); if (sField.Values.Count == 0 && publishEmptyFields) { Dynamic.FieldSet fields = new FieldSet(); Dynamic.Field fe = new Dynamic.Field(); f.EmbeddedSchema = manager.BuildSchema(((EmbeddedSchemaFieldDefinition)sField.Definition).EmbeddedSchema); EmbeddedSchemaFieldDefinition linksFieldDefinition = sField.Definition as EmbeddedSchemaFieldDefinition; ItemFields newItemField = new ItemFields(linksFieldDefinition.EmbeddedSchema); for (int i = 0; i < newItemField.Count; i++) { if (newItemField[i] is TCM.Fields.EmbeddedSchemaField) { TCM.Fields.EmbeddedSchemaField innerField = (TCM.Fields.EmbeddedSchemaField)newItemField[i]; if (innerField.Values.Count == 0) { Dynamic.FieldSet fieldsinner = new FieldSet(); Dynamic.Field fin = new Dynamic.Field(); fe.EmbeddedSchema = manager.BuildSchema(((EmbeddedSchemaFieldDefinition)innerField.Definition).EmbeddedSchema); EmbeddedSchemaFieldDefinition inlinksFieldDefinition = innerField.Definition as EmbeddedSchemaFieldDefinition; ItemFields newinItemField = new ItemFields(inlinksFieldDefinition.EmbeddedSchema); for (int n = 0; n < newinItemField.Count; n++) { fin.Name = newItemField[n].Name; fieldsinner.Add(newinItemField[n].Name, fin); } fe.EmbeddedValues.Add(fieldsinner); fe.Values.Add(""); } fe.Name = newItemField[i].Name; fields.Add(newItemField[i].Name, fe); } else { Dynamic.Field fein = manager.BuildField(newItemField[i], linkLevels, resolveWidthAndHeight, publishEmptyFields); fein.Values.Clear(); fields.Add(newItemField[i].Name, fein); } } f.EmbeddedValues.Add(fields); f.Values.Add(""); } else if (sField.Values.Count == 0 && !publishEmptyFields) { throw new FieldHasNoValueException(); } else { // we will wrap each linked component in a ContentModel component f.EmbeddedValues = new List <Dynamic.FieldSet>(); f.EmbeddedSchema = manager.BuildSchema(((EmbeddedSchemaFieldDefinition)sField.Definition).EmbeddedSchema); foreach (TCM.Fields.ItemFields embeddedFields in sField.Values) { f.EmbeddedValues.Add(manager.BuildFields(embeddedFields, linkLevels, resolveWidthAndHeight, publishEmptyFields)); } } return(f); } throw new FieldTypeNotDefinedException(); }
public static Dynamic.Field BuildField(TCM.Fields.ItemField tcmItemField, int currentLinkLevel, BuildManager manager) { Dynamic.Field f = new Dynamic.Field(); if (tcmItemField == null && manager.BuildProperties.PublishEmptyFields) { f.Values.Add(""); return(f); } else if (tcmItemField == null && !manager.BuildProperties.PublishEmptyFields) { throw new FieldHasNoValueException(); } f.Name = tcmItemField.Name; if (tcmItemField is TCM.Fields.XhtmlField) { TCM.Fields.XhtmlField sField = (TCM.Fields.XhtmlField)tcmItemField; if (sField.Values.Count == 0 && manager.BuildProperties.PublishEmptyFields) { f.Values.Add(""); } else if (sField.Values.Count == 0 && !manager.BuildProperties.PublishEmptyFields) { throw new FieldHasNoValueException(); } else { foreach (string v in sField.Values) { f.Values.Add(manager.PublishBinariesInRichTextField(v)); } } f.FieldType = FieldType.Xhtml; return(f); } if (tcmItemField is TCM.Fields.MultiLineTextField) { TCM.Fields.TextField sField = (TCM.Fields.MultiLineTextField)tcmItemField; if (sField.Values.Count == 0 && manager.BuildProperties.PublishEmptyFields) { f.Values.Add(""); } else if (sField.Values.Count == 0 && !manager.BuildProperties.PublishEmptyFields) { throw new FieldHasNoValueException(); } else { foreach (string v in sField.Values) { f.Values.Add(v); } } f.FieldType = FieldType.MultiLineText; return(f); } if (tcmItemField is TCM.Fields.TextField) { TCM.Fields.TextField sField = (TCM.Fields.TextField)tcmItemField; if (sField.Values.Count == 0 && manager.BuildProperties.PublishEmptyFields) { f.Values.Add(""); } else if (sField.Values.Count == 0 && !manager.BuildProperties.PublishEmptyFields) { throw new FieldHasNoValueException(); } else { foreach (string v in sField.Values) { f.Values.Add(v); } } f.FieldType = FieldType.Text; return(f); } if (tcmItemField is TCM.Fields.KeywordField) { TCM.Fields.KeywordField sField = (TCM.Fields.KeywordField)tcmItemField; if (sField.Values.Count == 0 && manager.BuildProperties.PublishEmptyFields) { f.Values.Add(""); } else if (sField.Values.Count == 0 && !manager.BuildProperties.PublishEmptyFields) { throw new FieldHasNoValueException(); } else { // add keyword values f.Keywords = new List <Keyword>(); // we will wrap each linked component in a ContentModel component foreach (TCM.Keyword kw in sField.Values) { f.Keywords.Add(manager.BuildKeyword(kw)); } if (!manager.BuildProperties.OmitValueLists) { f.Values = new List <string>(); foreach (TCM.Keyword kw in sField.Values) { f.Values.Add(kw.Title); } } KeywordFieldDefinition fieldDef = (KeywordFieldDefinition)sField.Definition; f.CategoryId = fieldDef.Category.Id; f.CategoryName = fieldDef.Category.Title; } f.FieldType = FieldType.Keyword; return(f); } if (tcmItemField is TCM.Fields.NumberField) { TCM.Fields.NumberField sField = (TCM.Fields.NumberField)tcmItemField; if (sField.Values.Count == 0 && manager.BuildProperties.PublishEmptyFields) { f.Values.Add(""); } else if (sField.Values.Count == 0 && !manager.BuildProperties.PublishEmptyFields) { throw new FieldHasNoValueException(); } else { f.NumericValues = (List <double>)sField.Values; if (!manager.BuildProperties.OmitValueLists) { f.Values = new List <string>(); foreach (double d in f.NumericValues) { f.Values.Add(Convert.ToString(d)); } } } f.FieldType = FieldType.Number; return(f); } if (tcmItemField is TCM.Fields.DateField) { TCM.Fields.DateField sField = (TCM.Fields.DateField)tcmItemField; if (sField.Values.Count == 0 && manager.BuildProperties.PublishEmptyFields) { f.Values.Add(""); } else if (sField.Values.Count == 0 && !manager.BuildProperties.PublishEmptyFields) { throw new FieldHasNoValueException(); } else { f.DateTimeValues = (List <DateTime>)sField.Values; if (!manager.BuildProperties.OmitValueLists) { f.Values = new List <string>(); foreach (DateTime dt in f.DateTimeValues) { f.Values.Add(Convert.ToString(dt)); } } } f.FieldType = FieldType.Date; return(f); } if (tcmItemField is TCM.Fields.MultimediaLinkField) { TCM.Fields.MultimediaLinkField sField = (TCM.Fields.MultimediaLinkField)tcmItemField; if (sField.Values.Count == 0 && manager.BuildProperties.PublishEmptyFields) { f.Values.Add(tcmItemField.Name); } else if (sField.Values.Count == 0 && !manager.BuildProperties.PublishEmptyFields) { throw new FieldHasNoValueException(); } else { // we will wrap each linked component in a ContentModel component f.LinkedComponentValues = new List <Dynamic.Component>(); int nextLinkLevel = currentLinkLevel - 1; if (MustFollowField(sField, manager)) { log.Debug(string.Format("found component link field named {0} with global followLinksPerField property set to false OR followLink set to true for this field", sField.Name)); } else { log.Debug(string.Format("found component link field named {0} with followLink set to false for this field", sField.Name)); nextLinkLevel = 0; } foreach (TCM.Component comp in sField.Values) { f.LinkedComponentValues.Add(manager.BuildComponent(comp, nextLinkLevel)); } if (!manager.BuildProperties.OmitValueLists) { f.Values = new List <string>(); foreach (Dynamic.Component c in f.LinkedComponentValues) { f.Values.Add(c.Id); } } } f.FieldType = FieldType.MultiMediaLink; return(f); } if (tcmItemField is TCM.Fields.ComponentLinkField) { TCM.Fields.ComponentLinkField sField = (TCM.Fields.ComponentLinkField)tcmItemField; if (sField.Values.Count == 0 && manager.BuildProperties.PublishEmptyFields) { f.Values.Add(tcmItemField.Name); } else if (sField.Values.Count == 0 && !manager.BuildProperties.PublishEmptyFields) { throw new FieldHasNoValueException(); } else { // we will wrap each linked component in a ContentModel component f.LinkedComponentValues = new List <Dynamic.Component>(); int nextLinkLevel = currentLinkLevel - 1; if (MustFollowField(sField, manager)) { log.Debug(string.Format("found component link field named {0} with global followLinksPerField property set to false OR followLink set to true for this field", sField.Name)); } else { log.Debug(string.Format("found component link field named {0} with followLink set to false for this field", sField.Name)); nextLinkLevel = 0; } foreach (TCM.Component comp in sField.Values) { f.LinkedComponentValues.Add(manager.BuildComponent(comp, nextLinkLevel)); } if (!manager.BuildProperties.OmitValueLists) { f.Values = new List <string>(); foreach (Dynamic.Component c in f.LinkedComponentValues) { f.Values.Add(c.Id); } } } f.FieldType = FieldType.ComponentLink; return(f); } if (tcmItemField is TCM.Fields.EmbeddedSchemaField) { TCM.Fields.EmbeddedSchemaField sField = (TCM.Fields.EmbeddedSchemaField)tcmItemField; f.FieldType = FieldType.Embedded; f.EmbeddedValues = new List <Dynamic.FieldSet>(); bool hasValues = CheckIfEmbeddedFieldHasValues(sField); if (!hasValues && manager.BuildProperties.PublishEmptyFields) { Dynamic.FieldSet fields = new FieldSet(); Dynamic.Field fe = new Dynamic.Field(); f.EmbeddedSchema = manager.BuildSchema(((EmbeddedSchemaFieldDefinition)sField.Definition).EmbeddedSchema); EmbeddedSchemaFieldDefinition linksFieldDefinition = sField.Definition as EmbeddedSchemaFieldDefinition; ItemFields newItemField = new ItemFields(linksFieldDefinition.EmbeddedSchema); for (int i = 0; i < newItemField.Count; i++) { if (newItemField[i] is TCM.Fields.EmbeddedSchemaField) { TCM.Fields.EmbeddedSchemaField innerField = (TCM.Fields.EmbeddedSchemaField)newItemField[i]; if (innerField.Values.Count == 0) { Dynamic.FieldSet fieldsinner = new FieldSet(); Dynamic.Field fin = new Dynamic.Field(); fe.EmbeddedSchema = manager.BuildSchema(((EmbeddedSchemaFieldDefinition)innerField.Definition).EmbeddedSchema); EmbeddedSchemaFieldDefinition inlinksFieldDefinition = innerField.Definition as EmbeddedSchemaFieldDefinition; ItemFields newinItemField = new ItemFields(inlinksFieldDefinition.EmbeddedSchema); for (int n = 0; n < newinItemField.Count; n++) { fin.Name = newItemField[n].Name; fieldsinner.Add(newinItemField[n].Name, fin); } fe.EmbeddedValues.Add(fieldsinner); fe.Values.Add(""); } fe.Name = newItemField[i].Name; fields.Add(newItemField[i].Name, fe); } else { Dynamic.Field fein = manager.BuildField(newItemField[i], currentLinkLevel); fein.Values.Clear(); fields.Add(newItemField[i].Name, fein); } } f.EmbeddedValues.Add(fields); f.Values.Add(""); } else if (!hasValues && !manager.BuildProperties.PublishEmptyFields) { throw new FieldHasNoValueException(); } else { // we will wrap each linked component in a ContentModel component f.EmbeddedValues = new List <Dynamic.FieldSet>(); f.EmbeddedSchema = manager.BuildSchema(((EmbeddedSchemaFieldDefinition)sField.Definition).EmbeddedSchema); foreach (TCM.Fields.ItemFields embeddedFields in sField.Values) { f.EmbeddedValues.Add(manager.BuildFields(embeddedFields, currentLinkLevel)); } } return(f); } throw new FieldTypeNotDefinedException(); }
public static Dynamic.Field BuildField(TCM.Fields.ItemField tcmItemField, int linkLevels, bool resolveWidthAndHeight, bool publishEmptyFields, BuildManager manager) { Dynamic.Field f = new Dynamic.Field(); if (tcmItemField == null&&publishEmptyFields) { GeneralUtils.TimedLog("item field is null"); //throw new FieldHasNoValueException(); f.Values.Add(""); return f; } else if (tcmItemField == null && !publishEmptyFields) { throw new FieldHasNoValueException(); } f.Name = tcmItemField.Name; if (tcmItemField is TCM.Fields.XhtmlField) { TCM.Fields.XhtmlField sField = (TCM.Fields.XhtmlField)tcmItemField; GeneralUtils.TimedLog(string.Format("item field {0} has {1} values", tcmItemField.Name, sField.Values.Count)); if (sField.Values.Count == 0 && publishEmptyFields) { //throw new FieldHasNoValueException(); f.Values.Add(""); } else if (sField.Values.Count == 0 && !publishEmptyFields) { throw new FieldHasNoValueException(); } else { foreach (string v in sField.Values) { f.Values.Add(v); } } f.FieldType = FieldType.Xhtml; return f; } if (tcmItemField is TCM.Fields.MultiLineTextField) { TCM.Fields.TextField sField = (TCM.Fields.MultiLineTextField)tcmItemField; GeneralUtils.TimedLog(string.Format("item field {0} has {1} values", tcmItemField.Name, sField.Values.Count)); //if (sField.Values.Count == 0) // throw new FieldHasNoValueException(); if (sField.Values.Count == 0 && publishEmptyFields) { //throw new FieldHasNoValueException(); f.Values.Add(""); } else if (sField.Values.Count == 0 && !publishEmptyFields) { throw new FieldHasNoValueException(); } else { foreach (string v in sField.Values) { f.Values.Add(v); } } f.FieldType = FieldType.MultiLineText; return f; } if (tcmItemField is TCM.Fields.TextField) { TCM.Fields.TextField sField = (TCM.Fields.TextField)tcmItemField; GeneralUtils.TimedLog(string.Format("item field {0} has {1} values", tcmItemField.Name, sField.Values.Count)); //if (sField.Values.Count == 0) // throw new FieldHasNoValueException(); if (sField.Values.Count == 0 && publishEmptyFields) { //throw new FieldHasNoValueException(); f.Values.Add(""); } else if (sField.Values.Count == 0 && !publishEmptyFields) { throw new FieldHasNoValueException(); } else { foreach (string v in sField.Values) { f.Values.Add(v); } } f.FieldType = FieldType.Text; return f; } if (tcmItemField is TCM.Fields.KeywordField) { TCM.Fields.KeywordField sField = (TCM.Fields.KeywordField)tcmItemField; GeneralUtils.TimedLog(string.Format("item field {0} has {1} values", tcmItemField.Name, sField.Values.Count)); //if (sField.Values.Count == 0) // throw new FieldHasNoValueException(); if (sField.Values.Count == 0 && publishEmptyFields) { //throw new FieldHasNoValueException(); f.Values.Add(""); } else if (sField.Values.Count == 0 && !publishEmptyFields) { throw new FieldHasNoValueException(); } else { // add keyword values f.Keywords = new List<Keyword>(); // we will wrap each linked component in a ContentModel component f.Values = new List<string>(); foreach (TCM.Keyword kw in sField.Values) { // todo: add binary to package, and add BinaryUrl property to the component f.Values.Add(kw.Title); f.Keywords.Add(manager.BuildKeyword(kw)); } KeywordFieldDefinition fieldDef = (KeywordFieldDefinition)sField.Definition; f.CategoryId = fieldDef.Category.Id; f.CategoryName = fieldDef.Category.Title; } f.FieldType = FieldType.Keyword; return f; } if (tcmItemField is TCM.Fields.NumberField) { TCM.Fields.NumberField sField = (TCM.Fields.NumberField)tcmItemField; GeneralUtils.TimedLog(string.Format("item field {0} has {1} values", tcmItemField.Name, sField.Values.Count)); //if (sField.Values.Count == 0) // throw new FieldHasNoValueException(); if (sField.Values.Count == 0 && publishEmptyFields) { //throw new FieldHasNoValueException(); f.Values.Add(""); } else if (sField.Values.Count == 0 && !publishEmptyFields) { throw new FieldHasNoValueException(); } else { f.NumericValues = (List<double>)sField.Values; f.Values = new List<string>(); foreach (double d in f.NumericValues) { f.Values.Add(Convert.ToString(d)); } } f.FieldType = FieldType.Number; return f; } if (tcmItemField is TCM.Fields.DateField) { TCM.Fields.DateField sField = (TCM.Fields.DateField)tcmItemField; GeneralUtils.TimedLog(string.Format("item field {0} has {1} values", tcmItemField.Name, sField.Values.Count)); //if (sField.Values.Count == 0) // throw new FieldHasNoValueException(); if (sField.Values.Count == 0 && publishEmptyFields) { //throw new FieldHasNoValueException(); f.Values.Add(""); } else if (sField.Values.Count == 0 && !publishEmptyFields) { throw new FieldHasNoValueException(); } else { f.DateTimeValues = (List<DateTime>)sField.Values; f.Values = new List<string>(); foreach (DateTime dt in f.DateTimeValues) { f.Values.Add(Convert.ToString(dt)); } } f.FieldType = FieldType.Date; return f; } if (tcmItemField is TCM.Fields.MultimediaLinkField) { TCM.Fields.MultimediaLinkField sField = (TCM.Fields.MultimediaLinkField)tcmItemField; GeneralUtils.TimedLog(string.Format("item field {0} has {1} values", tcmItemField.Name, sField.Values.Count)); if (sField.Values.Count == 0 && publishEmptyFields) { f.Values.Add(tcmItemField.Name); } else if (sField.Values.Count == 0 && !publishEmptyFields) { throw new FieldHasNoValueException(); } else { // we will wrap each linked component in a ContentModel component f.LinkedComponentValues = new List<Dynamic.Component>(); foreach (TCM.Component comp in sField.Values) { // todo: add binary to package, and add BinaryUrl property to the component f.LinkedComponentValues.Add(manager.BuildComponent(comp, linkLevels - 1, resolveWidthAndHeight, publishEmptyFields)); } f.Values = new List<string>(); foreach (Dynamic.Component c in f.LinkedComponentValues) { f.Values.Add(c.Id); } } f.FieldType = FieldType.MultiMediaLink; return f; } if (tcmItemField is TCM.Fields.ComponentLinkField) { TCM.Fields.ComponentLinkField sField = (TCM.Fields.ComponentLinkField)tcmItemField; GeneralUtils.TimedLog(string.Format("item field {0} has {1} values", tcmItemField.Name, sField.Values.Count)); //if (sField.Values.Count == 0) // throw new FieldHasNoValueException(); if (sField.Values.Count == 0 && publishEmptyFields) { f.Values.Add(tcmItemField.Name); } else if (sField.Values.Count == 0 && !publishEmptyFields) { throw new FieldHasNoValueException(); } else { // we will wrap each linked component in a ContentModel component f.LinkedComponentValues = new List<Dynamic.Component>(); foreach (TCM.Component comp in sField.Values) { f.LinkedComponentValues.Add(manager.BuildComponent(comp, linkLevels - 1, resolveWidthAndHeight, publishEmptyFields)); } f.Values = new List<string>(); foreach (Dynamic.Component c in f.LinkedComponentValues) { f.Values.Add(c.Id); } } f.FieldType = FieldType.ComponentLink; return f; } if (tcmItemField is TCM.Fields.EmbeddedSchemaField) { TCM.Fields.EmbeddedSchemaField sField = (TCM.Fields.EmbeddedSchemaField)tcmItemField; GeneralUtils.TimedLog(string.Format("item field {0} has {1} values", tcmItemField.Name, sField.Values.Count)); //if (sField.Values.Count == 0) //throw new FieldHasNoValueException(); f.FieldType = FieldType.Embedded; f.EmbeddedValues = new List<Dynamic.FieldSet>(); if (sField.Values.Count == 0 && publishEmptyFields) { Dynamic.FieldSet fields = new FieldSet(); Dynamic.Field fe = new Dynamic.Field(); f.EmbeddedSchema = manager.BuildSchema(((EmbeddedSchemaFieldDefinition)sField.Definition).EmbeddedSchema); EmbeddedSchemaFieldDefinition linksFieldDefinition = sField.Definition as EmbeddedSchemaFieldDefinition; ItemFields newItemField = new ItemFields(linksFieldDefinition.EmbeddedSchema); for (int i = 0; i < newItemField.Count; i++) { if (newItemField[i] is TCM.Fields.EmbeddedSchemaField) { TCM.Fields.EmbeddedSchemaField innerField = (TCM.Fields.EmbeddedSchemaField)newItemField[i]; if (innerField.Values.Count == 0) { Dynamic.FieldSet fieldsinner = new FieldSet(); Dynamic.Field fin = new Dynamic.Field(); fe.EmbeddedSchema = manager.BuildSchema(((EmbeddedSchemaFieldDefinition)innerField.Definition).EmbeddedSchema); EmbeddedSchemaFieldDefinition inlinksFieldDefinition = innerField.Definition as EmbeddedSchemaFieldDefinition; ItemFields newinItemField = new ItemFields(inlinksFieldDefinition.EmbeddedSchema); for (int n = 0; n < newinItemField.Count; n++) { fin.Name = newItemField[n].Name; fieldsinner.Add(newinItemField[n].Name, fin); } fe.EmbeddedValues.Add(fieldsinner); fe.Values.Add(""); } fe.Name = newItemField[i].Name; fields.Add(newItemField[i].Name, fe); } else { Dynamic.Field fein = manager.BuildField(newItemField[i], linkLevels, resolveWidthAndHeight, publishEmptyFields); fein.Values.Clear(); fields.Add(newItemField[i].Name, fein); } } f.EmbeddedValues.Add(fields); f.Values.Add(""); } else if (sField.Values.Count == 0 && !publishEmptyFields) { throw new FieldHasNoValueException(); } else { // we will wrap each linked component in a ContentModel component f.EmbeddedValues = new List<Dynamic.FieldSet>(); f.EmbeddedSchema = manager.BuildSchema(((EmbeddedSchemaFieldDefinition)sField.Definition).EmbeddedSchema); foreach (TCM.Fields.ItemFields embeddedFields in sField.Values) { f.EmbeddedValues.Add(manager.BuildFields(embeddedFields, linkLevels, resolveWidthAndHeight, publishEmptyFields)); } } return f; } throw new FieldTypeNotDefinedException(); }
private Dynamic.Component GetDynamicComponent(BuildManager manager) { GeneralUtils.TimedLog("start getting component from package"); Item item = Package.GetByName(Package.ComponentName); GeneralUtils.TimedLog("finished getting component from package"); if (item == null) { Log.Error("no component found (is this a page template?)"); return null; } Component tcmComponent = (Component)Engine.GetObject(item.GetAsSource().GetValue("ID")); int linkLevels; if (HasPackageValue(Package, "LinkLevels")) { linkLevels = Convert.ToInt32(Package.GetValue("LinkLevels")); } else { GeneralUtils.TimedLog("no link levels configured, using default level " + this.DefaultLinkLevels); linkLevels = this.DefaultLinkLevels; } bool resolveWidthAndHeight; if (HasPackageValue(Package, "ResolveWidthAndHeight")) { resolveWidthAndHeight = Package.GetValue("ResolveWidthAndHeight").ToLower().Equals("yes"); } else { GeneralUtils.TimedLog("no ResolveWidthAndHeight configured, using default value " + this.DefaultResolveWidthAndHeight); resolveWidthAndHeight = this.DefaultResolveWidthAndHeight; } bool publishEmptyFields; if (HasPackageValue(Package, "PublishEmptyFields")) { publishEmptyFields = Package.GetValue("PublishEmptyFields").ToLower().Equals("yes"); } else { GeneralUtils.TimedLog("no PublishEmptyFields configured, using default value " + this.DefaultResolveWidthAndHeight); publishEmptyFields = this.DefaultPublishEmptyFields; } GeneralUtils.TimedLog("found component with title " + tcmComponent.Title + " and id " + tcmComponent.Id); GeneralUtils.TimedLog("constructing dynamic component, links are followed to level " + linkLevels + ", width and height are " + (resolveWidthAndHeight ? "" : "not ") + "resolved"); GeneralUtils.TimedLog("start building dynamic component"); Dynamic.Component component = manager.BuildComponent(tcmComponent, linkLevels, resolveWidthAndHeight,publishEmptyFields); GeneralUtils.TimedLog("finished building dynamic component"); return component; }