private void SetUpTextAreas(bool flush) { Guid selectedTemplateId = this.SelectedTemplateId; PageTemplateDescriptor pageTemplate = PageTemplateFacade.GetPageTemplate(selectedTemplateId); Verify.IsNotNull(pageTemplate, "Failed to get page template by id '{0}'", selectedTemplateId); if (!pageTemplate.IsValid) { throw new InvalidOperationException( "Page template '{0}' contains errors. You can edit the template in the 'Layout' section".FormatWith(selectedTemplateId), pageTemplate.LoadingException); } var handledIds = new List <string>(); ContentsPlaceHolder.Controls.Clear(); foreach (var placeholderDescription in pageTemplate.PlaceholderDescriptions) { string placeholderId = placeholderDescription.Id; if (handledIds.Contains(placeholderId) == false) { var pageTypeContainerClasses = ContainerClassManager.GetPageTypeContainerClasses(this.PageTypeId, placeholderDescription.Id); var allContainerClasses = ContainerClassManager.MergeContainerClasses(placeholderDescription.ContainerClasses, pageTypeContainerClasses); TextBox contentTextBox = new Composite.Core.WebClient.UiControlLib.TextBox(); contentTextBox.TextMode = TextBoxMode.MultiLine; contentTextBox.ID = placeholderId; contentTextBox.Attributes.Add("placeholderid", placeholderId); contentTextBox.Attributes.Add("placeholdername", placeholderDescription.Title); contentTextBox.Attributes.Add("containerclasses", string.Join(",", allContainerClasses)); if (placeholderId == pageTemplate.DefaultPlaceholderId) { contentTextBox.Attributes.Add("selected", "true"); } if (flush) { if (this.NamedXhtmlFragments.ContainsKey(placeholderId)) { contentTextBox.Text = this.NamedXhtmlFragments[placeholderId]; } else { contentTextBox.Text = ""; } } ContentsPlaceHolder.Controls.Add(contentTextBox); handledIds.Add(placeholderId); } } }
public Control BuildWebControl() { _userControl = _userControlType.ActivateAsUserControl<XhtmlEditorTemplateUserControlBase>(this.UiControlID); _userControl.FormControlLabel = this.Label; _userControl.Xhtml = this.Xhtml; _userControl.EmbedableFieldsTypes = this.EmbedableFieldsTypes; _userControl.ClassConfigurationName = this.ClassConfigurationName; _userControl.ContainerClasses = ContainerClassManager.NormalizeClassNamesString(this.ContainerClasses); _userControl.PreviewPageId = PreviewPageId; _userControl.PreviewTemplateId = PreviewTemplateId; _userControl.PreviewPlaceholder = PreviewPlaceholder; return _userControl; }
public IEnumerable <Component> GetComponents(string containerclass = null) { var sepratedContainerClass = ContainerClassManager.ParseToList(containerclass).ToList(); if (!sepratedContainerClass.IsNullOrEmpty()) { return (_componentManager.GetComponents() .Where( f => (f.ContainerClasses.IsNullOrEmpty() || f.ContainerClasses.Intersect(sepratedContainerClass).Any()) && (f.AntiTags.IsNullOrEmpty() || !f.AntiTags.Intersect(sepratedContainerClass).Any()))); } return(_componentManager.GetComponents()); }
private Component GetComponentsFromFile(string componentFile) { XDocument document = null; try { document = XDocumentUtils.Load(componentFile); } catch (XmlException exception) { Log.LogError(nameof(FileBasedComponentProvider), $"Error in reading component file: {exception}"); return(null); } var xElement = document.Descendants().FirstOrDefault(); if (xElement != null) { #warning making id based on file location, check again once function based provider come alive var xmlBytes = new UnicodeEncoding().GetBytes(componentFile); var hashedXmlBytes = ((HashAlgorithm)CryptoConfig.CreateFromName("MD5")).ComputeHash(xmlBytes); var id = new Guid(hashedXmlBytes); var title = xElement.GetAttributeValue(Namespaces.Components + Title) ?? Path.GetFileNameWithoutExtension(componentFile); var description = xElement.GetAttributeValue(Namespaces.Components + Description) ?? ""; var groupingTagsRaw = xElement.GetAttributeValue(Namespaces.Components + Tags) ?? GuessGroupingTagsBasedOnPath(componentFile); List <string> groupingTags = new List <string>(); if (!groupingTagsRaw.IsNullOrEmpty()) { var tagManager = ServiceLocator.GetRequiredService <TagManager>(); groupingTags.AddRange( groupingTagsRaw.ToLower() .Split(',') .Select(f => f.Trim()) .Select(tagManager.GetTagTitle) .ToList()); } var containerClasses = ContainerClassManager.ParseToList(xElement.GetAttributeValue(Namespaces.Components + ContainerClasses)); var antiTags = ContainerClassManager.ParseToList(xElement.GetAttributeValue(Namespaces.Components + AntiTags)); var componentImage = new ComponentImage() { CustomImageUri = xElement.GetAttributeValue(Namespaces.Components + Image), IconName = xElement.GetAttributeValue(Namespaces.Components + Icon) }; xElement.Attributes().Where(f => f.Name.Namespace == Namespaces.Components).Remove(); return(new Component { Id = id, Title = title, Description = description, GroupingTags = groupingTags, ContainerClasses = containerClasses, AntiTags = antiTags, ComponentImage = componentImage, ComponentDefinition = xElement.Document.GetDocumentAsString() }); } return(null); }
/// <summary> /// Builds a page template descriptor. Extracts template's properties and content placeholder properties. /// </summary> /// <param name="templateDefinition">The template definition.</param> /// <param name="descriptorConstructor">The descriptor constructor.</param> /// <param name="placeholderProperties">The placeholder properties.</param> /// <returns></returns> public static DescriptorType BuildPageTemplateDescriptor <DescriptorType>(IPageTemplate templateDefinition, Func <DescriptorType> descriptorConstructor, out IDictionary <string, PropertyInfo> placeholderProperties) where DescriptorType : PageTemplateDescriptor { Verify.ArgumentNotNull(templateDefinition, "templateDefinition"); Verify.ArgumentNotNull(descriptorConstructor, "descriptorConstructor"); DescriptorType pageTemplate = descriptorConstructor(); Verify.ArgumentCondition(pageTemplate != null, "descriptorConstructor", "Not null object expected"); if (templateDefinition.TemplateId == null || templateDefinition.TemplateId == Guid.Empty) { throw new InvalidOperationException("TemplateId has not been correctly defined"); } pageTemplate.Id = templateDefinition.TemplateId; pageTemplate.Title = templateDefinition.TemplateTitle; string defaultPlaceholderId = null; var placeholders = new List <PlaceholderDescriptor>(); placeholderProperties = new Dictionary <string, PropertyInfo>(); var type = templateDefinition.GetType(); while (type.GetInterfaces().Contains(typeof(IPageTemplate))) { foreach (var property in type.GetProperties()) { if (property.ReflectedType != property.DeclaringType) { continue; } var placeholderAttributes = property.GetCustomAttributes(typeof(PlaceholderAttribute), true); if (placeholderAttributes.Length == 0) { continue; } Verify.That(placeholderAttributes.Length == 1, "Multiple '{0}' attributes defined on property", typeof(PlaceholderAttribute), property.Name); var placeholderAttribute = (PlaceholderAttribute)placeholderAttributes[0]; string placeholderId = placeholderAttribute.Id ?? property.Name; string placeholderLabel = placeholderAttribute.Title ?? property.Name; if (placeholderProperties.ContainsKey(placeholderId)) { throw new InvalidOperationException("Placeholder '{0}' defined multiple times".FormatWith(placeholderId)); } var containerClasses = ContainerClassManager.ParseToList(placeholderAttribute.ContainerClasses).ToList(); placeholderProperties.Add(placeholderId, property); placeholders.Add(new PlaceholderDescriptor { Id = placeholderId, Title = placeholderLabel, ContainerClasses = containerClasses }); if (placeholderAttribute.IsDefault) { Verify.IsNull(defaultPlaceholderId, "More than one placeholder is marked as default"); defaultPlaceholderId = placeholderId; } } type = type.BaseType; } if (defaultPlaceholderId == null && placeholders.Any()) { defaultPlaceholderId = placeholders.First().Id; } pageTemplate.DefaultPlaceholderId = defaultPlaceholderId; pageTemplate.PlaceholderDescriptions = placeholders; return(pageTemplate); }