private void PublishAllBinaries(Dynamic.Page page)
        {

            GeneralUtils.TimedLog("page: " + page);
            GeneralUtils.TimedLog("page metadata fields property: " + (page.MetadataFields == null ? "null" : page.MetadataFields.ToString()));
            GeneralUtils.TimedLog("page metadata fields count: " + page.MetadataFields.Count);
            foreach (Dynamic.Field field in page.MetadataFields.Values)
            {
                if (field.FieldType == Dynamic.FieldType.ComponentLink || field.FieldType == Dynamic.FieldType.MultiMediaLink)
                {
                    foreach (Dynamic.Component linkedComponent in field.LinkedComponentValues)
                    {
                        PublishAllBinaries(linkedComponent);
                    }
                }
                if (field.FieldType == Dynamic.FieldType.Embedded)
                {
                    foreach (Dynamic.FieldSet embeddedFields in field.EmbeddedValues)
                    {
                        PublishAllBinaries(embeddedFields);
                    }
                }
                if (field.FieldType == Dynamic.FieldType.Xhtml)
                {
                    for (int i = 0; i < field.Values.Count; i++)
                    {
                        string xhtml = field.Values[i];
                        field.Values[i] = BinaryPublisher.PublishBinariesInRichTextField(xhtml);
                    }
                }
            }

        }
Exemplo n.º 2
0
 protected void PublishAllBinaries(Dynamic.FieldSet fieldSet)
 {
     foreach (Dynamic.Field field in fieldSet.Values)
     {
         if (field.FieldType == Dynamic.FieldType.ComponentLink || field.FieldType == Dynamic.FieldType.MultiMediaLink)
         {
             foreach (Dynamic.Component linkedComponent in field.LinkedComponentValues)
             {
                 PublishAllBinaries(linkedComponent);
             }
         }
         if (field.FieldType == Dynamic.FieldType.Embedded)
         {
             foreach (Dynamic.FieldSet embeddedFields in field.EmbeddedValues)
             {
                 PublishAllBinaries(embeddedFields);
             }
         }
         if (field.FieldType == Dynamic.FieldType.Xhtml)
         {
             for (int i = 0; i < field.Values.Count; i++)
             {
                 string xhtml = field.Values[i];
                 field.Values[i] = BinaryPublisher.PublishBinariesInRichTextField(xhtml, Manager.BuildProperties);
             }
         }
     }
 }
      protected override void TransformComponent(Dynamic.Component component)
      {

         TCM.Component tcmComponent = this.GetTcmComponent();
         TCM.Folder tcmFolder = (TCM.Folder)tcmComponent.OrganizationalItem;

         String mergeActionStr = Package.GetValue("MergeAction");
         Dynamic.MergeAction mergeAction;
         if (string.IsNullOrEmpty(mergeActionStr))
         {
            mergeAction = defaultMergeAction;
         }
         else
         {
            mergeAction = (Dynamic.MergeAction)Enum.Parse(typeof(Dynamic.MergeAction), mergeActionStr);
         }

         while (tcmFolder.OrganizationalItem != null)
         {
            if (tcmFolder.MetadataSchema != null)
            {
               TCM.Fields.ItemFields tcmFields = new TCM.Fields.ItemFields(tcmFolder.Metadata, tcmFolder.MetadataSchema);
               // change
               FieldsBuilder.AddFields(component.MetadataFields, tcmFields, 1, false,false, mergeAction, Manager);
                
            }
            tcmFolder = (TCM.Folder)tcmFolder.OrganizationalItem;
         }

      }
 protected void PublishAllBinaries(Dynamic.Component component)
 {
     if (component.ComponentType.Equals(Dynamic.ComponentType.Multimedia))
     {
         component.Multimedia.Url = BinaryPublisher.PublishMultimediaComponent(component.Id, Manager.BuildProperties);
     }
     PublishAllBinaries(component.Fields);
     PublishAllBinaries(component.MetadataFields);
 }
Exemplo n.º 5
0
 internal static Dynamic.ComponentPresentation BuildComponentPresentation(
     Dynamic.IComponent component, Dynamic.IComponentTemplate template)
 {
     return new Dynamic.ComponentPresentation
         {
             ComponentTemplate = template as Dynamic.ComponentTemplate,
             Component = component as Dynamic.Component
         };
 }
Exemplo n.º 6
0
        protected override void TransformPage(Dynamic.Page page)
        {
            // call helper function to publish all relevant multimedia components
            // Note: this template only published mm components that are found in the metadata of the page
            // MM components that are used as component presentation, or that are linked from a component that is 
            // used as a component presentation, will be published from the component template
            // (e.g. by adding 'Publish binaries for components' to that CT)

            PublishAllBinaries(page);
        }
 protected override void TransformComponent(Dynamic.Component component)
 {
     Log.Debug(string.Format("Started TransformComponent for component {0}", component.Id));
     // persist the ComponentPresentationRenderStyle in the package so that the next TBB in the chain is able to read it
     if (Package != null)
     {
         Item renderStyle = Package.CreateStringItem(ContentType.Text, ComponentPresentationRenderStyle.ToString());
         Package.PushItem("render-style", renderStyle);
     }
 }
        protected override void TransformComponent(Dynamic.Component component)
        {
            // call helper function to publish all relevant multimedia components
            // that could be:
            // - the current component
            // - any component linked to the current component
            // - any component linked to that (the number of levels is configurable in a parameter)

            PublishAllBinaries(component);
        }
        protected override void TransformComponent(Dynamic.Component component)
        {

            TCM.Component tcmComponent = this.GetTcmComponent();
            TCM.Folder tcmFolder = (TCM.Folder)tcmComponent.OrganizationalItem;

            while (tcmFolder.OrganizationalItem != null)
            {
                if (tcmFolder.MetadataSchema != null)
                {
                    TCM.Fields.ItemFields tcmFields = new TCM.Fields.ItemFields(tcmFolder.Metadata, tcmFolder.MetadataSchema);
                    FieldsBuilder.AddFields(component.MetadataFields, tcmFields, Manager);
                }
                tcmFolder = (TCM.Folder)tcmFolder.OrganizationalItem;
            }

        }
      protected override void TransformPage(Dynamic.Page page)
      {
          GeneralUtils.TimedLog("start TransformPage with id " + page.Id);

         Page tcmPage = this.GetTcmPage();
         StructureGroup tcmSG = (StructureGroup)tcmPage.OrganizationalItem;
         
         String mergeActionStr = Package.GetValue("MergeAction");
         Dynamic.MergeAction mergeAction;
         if (! string.IsNullOrEmpty(mergeActionStr))
         {
             try
             {
                 mergeAction = (Dynamic.MergeAction)Enum.Parse(typeof(Dynamic.MergeAction), mergeActionStr);
             }
             catch
             {
                 GeneralUtils.TimedLog("unexpected merge action " + mergeActionStr + ", using default");
                 mergeAction = defaultMergeAction;
             }
         }
         else
         {
             GeneralUtils.TimedLog("no merge action specified, using default");
             mergeAction = defaultMergeAction;
         }
         GeneralUtils.TimedLog("using merge action " + mergeAction.ToString());

         while (tcmSG != null)
         {
             GeneralUtils.TimedLog("found structure group with id " + tcmSG.Id);

            if (tcmSG.MetadataSchema != null)
            {
               TCM.Fields.ItemFields tcmFields = new TCM.Fields.ItemFields(tcmSG.Metadata, tcmSG.MetadataSchema);
               GeneralUtils.TimedLog(string.Format("about to merge {0} fields on structure group with {1} fields on page ", tcmFields.Count, page.MetadataFields.Count));

               // change
               FieldsBuilder.AddFields(page.MetadataFields, tcmFields, LinkLevels, false,false, mergeAction, Manager);
               GeneralUtils.TimedLog(string.Format("finished merging, we now have {0} fields on structure group and {1} fields on page ", tcmFields.Count, page.MetadataFields.Count));
            }
            tcmSG = tcmSG.OrganizationalItem as StructureGroup;
         }

      }
        protected override void TransformPage(Dynamic.Page page)
        {
            GeneralUtils.TimedLog("start TransformPage with id " + page.Id);

            Page tcmPage = this.GetTcmPage();
            StructureGroup tcmSG = (StructureGroup)tcmPage.OrganizationalItem;
            String mergeActionStr = Package.GetValue("MergeAction");

            while (tcmSG != null)
            {

                if (tcmSG.MetadataSchema != null)
                {
                    TCM.Fields.ItemFields tcmFields = new TCM.Fields.ItemFields(tcmSG.Metadata, tcmSG.MetadataSchema);
                    FieldsBuilder.AddFields(page.MetadataFields, tcmFields, Manager);
                }
                tcmSG = tcmSG.OrganizationalItem as StructureGroup;
            }
            GeneralUtils.TimedLog("finished TransformPage");
        }
 private void EnsureExtraProperties(Dynamic.Page page, Page tcmPage)
 {
     // make sure that the Publication, Folder and OwningPublication are always available on the top level
     if (page.Publication == null)
     {
         page.Publication = Manager.BuildPublication(tcmPage.ContextRepository);
     }
     if (page.OwningPublication == null)
     {
         page.OwningPublication = Manager.BuildPublication(tcmPage.OwningRepository);
     }
     if (page.StructureGroup == null)
     {
         page.StructureGroup = Manager.BuildOrganizationalItem((StructureGroup)tcmPage.OrganizationalItem);
     }
 }
 /// <summary>
 /// Abstract method to be implemented by a subclass. The method takes a DynamicDelivery page and can add information to it (e.g. by searching in folders / structure groups / linked components, etc
 /// </summary>
 /// <param name="page">DynamicDelivery page</param>
 protected abstract void TransformPage(Dynamic.Page page);
Exemplo n.º 14
0
 public IContentPresentationData GetModelData(Dynamic.IFieldSet fields, Dynamic.ISchema schema, Dynamic.IComponentTemplate template)
 {
     return new ContentPresentationData(new FieldSet(fields), new Schema(schema), new ComponentTemplate(template));
 }
       public static void AddFields(Dynamic.FieldSet fields, TCM.Fields.ItemFields tcmItemFields, int linkLevels, bool resolveWidthAndHeight, bool publishEmptyFields, Dynamic.MergeAction mergeAction, BuildManager manager)
       {
           GeneralUtils.TimedLog(string.Format("add fields: found {0} fields",tcmItemFields.Count));
           

           foreach (TCM.Fields.ItemField tcmItemField in tcmItemFields)
           {
               GeneralUtils.TimedLog("add fields: found " + tcmItemField.Name);
               try
               {
                   if (fields.ContainsKey(tcmItemField.Name))
                   {
                       GeneralUtils.TimedLog("field exists already, with " + fields[tcmItemField.Name].Values.Count + " values");
                       if (mergeAction.Equals(Dynamic.MergeAction.Skip) || (mergeAction.Equals(Dynamic.MergeAction.MergeMultiValueSkipSingleValue) && tcmItemField.Definition.MaxOccurs == 1))
                       {
                           GeneralUtils.TimedLog(string.Format("skipping field (merge action {0}, maxoccurs {1}", mergeAction.ToString(), tcmItemField.Definition.MaxOccurs));
                           continue;
                       }
                       Dynamic.Field f = manager.BuildField(tcmItemField, linkLevels, resolveWidthAndHeight,publishEmptyFields);
                       if (mergeAction.Equals(Dynamic.MergeAction.Replace) || (mergeAction.Equals(Dynamic.MergeAction.MergeMultiValueReplaceSingleValue) && tcmItemField.Definition.MaxOccurs == 1))
                       {
                           GeneralUtils.TimedLog(string.Format("replacing field (merge action {0}, maxoccurs {1}", mergeAction.ToString(), tcmItemField.Definition.MaxOccurs));
                           fields.Remove(f.Name);
                           fields.Add(f.Name, f);
                       }
                       else
                       {
                           IField existingField = fields[f.Name];
                           switch (existingField.FieldType)
                           {

                               case FieldType.ComponentLink:
                               case FieldType.MultiMediaLink:
                                   foreach (Component linkedComponent in f.LinkedComponentValues)
                                   {
                                       bool valueExists = false;
                                       foreach (Component existingLinkedComponent in existingField.LinkedComponentValues)
                                       {
                                           if (linkedComponent.Id.Equals(existingLinkedComponent.Id))
                                           {
                                               // this value already exists
                                               valueExists = true;
                                               break;
                                           }
                                       }
                                       if (!valueExists)
                                       {
                                           existingField.LinkedComponentValues.Add(linkedComponent);
                                       }
                                   }
                                   break;
                               case FieldType.Date:
                                   foreach (DateTime dateTime in f.DateTimeValues)
                                   {
                                       bool valueExists = false;
                                       foreach (DateTime existingDateTime in existingField.DateTimeValues)
                                       {
                                           if (dateTime.Equals(existingDateTime))
                                           {
                                               // this value already exists
                                               valueExists = true;
                                               break;
                                           }
                                       }
                                       if (!valueExists)
                                       {
                                           existingField.DateTimeValues.Add(dateTime);
                                       }
                                   }
                                   break;
                               case FieldType.Number:
                                   foreach (int nr in f.NumericValues)
                                   {
                                       bool valueExists = false;
                                       foreach (int existingNr in existingField.NumericValues)
                                       {
                                           if (nr == existingNr)
                                           {
                                               // this value already exists
                                               valueExists = true;
                                               break;
                                           }
                                       }
                                       if (!valueExists)
                                       {
                                           existingField.NumericValues.Add(nr);
                                       }
                                   }
                                   break;
                               default:
                                   foreach (string val in f.Values)
                                   {
                                       bool valueExists = false;
                                       foreach (string existingVal in existingField.Values)
                                       {
                                           if (val.Equals(existingVal))
                                           {
                                               // this value already exists
                                               valueExists = true;
                                               break;
                                           }
                                       }
                                       GeneralUtils.TimedLog(string.Format("found value {0}, valueExists: {1}", val, valueExists));
                                       if (!valueExists)
                                       {
                                           existingField.Values.Add(val);
                                       }
                                   }
                                   break;
                           }
                       }
                   }
                   else
                   {
                       Dynamic.Field f = manager.BuildField(tcmItemField, linkLevels, resolveWidthAndHeight,publishEmptyFields);
                       fields.Add(f.Name, f);
                   }
               }
               catch (FieldHasNoValueException)
               {
                   // fail silently, field is not added to the list
               }
               catch (FieldTypeNotDefinedException)
               {
                   // fail silently, field is not added to the list
               }
           }
       }
Exemplo n.º 16
0
 private void PublishAllBinaries(Dynamic.Component component)
 {
     if (component.ComponentType.Equals(Dynamic.ComponentType.Multimedia))
     {
         component.Multimedia.Url = BinaryPublisher.PublishMultimediaComponent(component.Id, Manager.BuildProperties);
     }
     foreach (var field in component.Fields.Values)
     {
         if (field.FieldType == Dynamic.FieldType.ComponentLink || field.FieldType == Dynamic.FieldType.MultiMediaLink)
         {
             foreach (IComponent linkedComponent in field.LinkedComponentValues)
             {
                 PublishAllBinaries(linkedComponent as Component);
             }
         }
         if (field.FieldType == Dynamic.FieldType.Embedded)
         {
             foreach (Dynamic.FieldSet embeddedFields in field.EmbeddedValues)
             {
                 PublishAllBinaries(embeddedFields);
             }
         }
         if (field.FieldType == Dynamic.FieldType.Xhtml)
         {
             for (int i = 0; i < field.Values.Count; i++)
             {
                 string xhtml = field.Values[i];
                 field.Values[i] = BinaryPublisher.PublishBinariesInRichTextField(xhtml, Manager.BuildProperties);
             }
         }
     }
     foreach (var field in component.MetadataFields.Values)
     {
         if (field.FieldType == Dynamic.FieldType.ComponentLink || field.FieldType == Dynamic.FieldType.MultiMediaLink)
         {
             foreach (Dynamic.Component linkedComponent in field.LinkedComponentValues)
             {
                 PublishAllBinaries(linkedComponent);
             }
         }
         if (field.FieldType == Dynamic.FieldType.Xhtml)
         {
             for (int i = 0; i < field.Values.Count; i++)
             {
                 string xhtml = field.Values[i];
                 field.Values[i] = BinaryPublisher.PublishBinariesInRichTextField(xhtml, Manager.BuildProperties);
             }
         }
     }
 }
Exemplo n.º 17
0
 public IComponentPresentationData GetModelData(Dynamic.IComponentPresentation cp)
 {
     return new ComponentPresentation(cp);
 }
Exemplo n.º 18
0
 public IPageData GetModelData(Dynamic.IPage page)
 {
     return new Page(page);
 }
		protected override void TransformComponent(Dynamic.Component component) {
			// do nothing, this is the basic operation
		}
Exemplo n.º 20
0
 public IKeywordData GetModelData(Dynamic.IKeyword keyword, string categoryName)
 {
     return new Keyword(keyword, categoryName);
 }
 protected override void TransformComponent(Dynamic.Component component)
 {
 }
 public virtual void AddXpathToFields(Dynamic.FieldSet fieldSet, string baseXpath)
 {
     FieldsBuilder.AddXpathToFields(fieldSet, baseXpath);
 }
 private void EnsureExtraProperties(Dynamic.Component component, Component tcmComponent)
 {
     // make sure that the Publication, Folder and OwningPublication are always available on the top level
     if (component.Publication == null)
     {
         component.Publication = Manager.BuildPublication(tcmComponent.ContextRepository);
     }
     if (component.OwningPublication == null)
     {
         component.OwningPublication = Manager.BuildPublication(tcmComponent.OwningRepository);
     }
     if (component.Folder == null)
     {
         component.Folder = Manager.BuildOrganizationalItem((Folder)tcmComponent.OrganizationalItem);
     }
 }
 /// <summary>
 /// Abstract method to be implemented by a subclass. The method takes a DynamicDelivery component and can add information to it (e.g. by searching in folders / structure groups / linked components, etc
 /// </summary>
 /// <param name="component">DynamicDelivery component </param>
 protected abstract void TransformComponent(Dynamic.Component component);
       public static void AddXpathToFields(Dynamic.FieldSet fieldSet, string baseXpath)
       {
          // add XPath properties to all fields

           if (fieldSet == null)
           {
               GeneralUtils.TimedLog("Error: fieldSet = null");
           }
           if (fieldSet.Values == null)
           {
               GeneralUtils.TimedLog("Error: fieldSet.Values = null");
           }
           try
           {
               foreach (Field f in fieldSet.Values)
               {
                   if (f == null)
                   {
                       GeneralUtils.TimedLog("Error: field = null");
                   }
                   f.XPath = string.Format("{0}/custom:{1}", baseXpath, f.Name);
                   int i = 1;
                   if (f.EmbeddedValues != null)
                   {
                       foreach (FieldSet subFields in f.EmbeddedValues)
                       {
                           AddXpathToFields(subFields, string.Format("{0}/custom:{1}[{2}]", baseXpath, f.Name, i++));
                       }
                   }
               }
           }
           catch (Exception e)
           {
               GeneralUtils.TimedLog("Caught exception: " + e.Message);
           }
       }
		protected override void TransformPage(Dynamic.Page page) {
			// do nothing, this is the basic operation
		}
Exemplo n.º 27
0
 public IComponentData GetModelData(Dynamic.IComponent component)
 {
     return new Component(component);
 }