/// <summary> /// Check tt element validity /// </summary> protected override void ValidElements() { bool isValid = true; // we need an extra check to validate the root attributes in order // to ensure parameters are parsed. ValidAttributes(); #region check this elements model switch (Children.Count) { case 0: return; case 1: { #region test if child element is head or body if (Children[0] is HeadElement) { m_head = Children[0] as HeadElement; isValid = true; } else if (Children[0] is BodyElement) { m_body = Children[0] as BodyElement; m_head = new HeadElement(); Children.Clear(); Children.Add(m_head); Children.Add(m_body); isValid = true; } else { isValid = false; } #endregion } break; case 2: { #region Check first child is head, and second is body if (Children[0] is HeadElement) { m_head = Children[0] as HeadElement; } if (Children[1] is BodyElement) { m_body = Children[1] as BodyElement; } else { isValid = (m_body != null && m_head != null); } #endregion } break; default: { #region Cannot be valid isValid = false; #endregion } break; } #endregion if (!isValid) { Error("erroneous child in " + this.ToString()); } #region now check each of the children is individually valid foreach (TimedTextElementBase element in Children) { element.Valid(); } #endregion #region Add default region if none was specified if (isValid && Regions.Count < 1) { LayoutElement defaultLayout = new LayoutElement(); defaultLayout.LocalName = "layout"; defaultLayout.Namespace = m_head.Namespace; m_head.Children.Add(defaultLayout); defaultLayout.Parent = m_head; RegionElement defaultRegion = new RegionElement(); defaultRegion.SetLocalStyle("backgroundColor", "black"); defaultRegion.SetLocalStyle("color", "white"); defaultLayout.Children.Add(defaultRegion); defaultRegion.Parent = defaultLayout; defaultRegion.Id = RegionElement.DefaultRegionName; defaultRegion.Root = Root; Root.Regions[defaultRegion.Id] = defaultRegion; } #endregion }
/// <summary> /// Check tt element validity /// </summary> protected override void ValidElements() { bool isValid = true; // we need an extra check to validate the root attributes in order // to ensure parameters are parsed. ValidAttributes(); #region check this elements model switch (Children.Count) { case 0: return; case 1: { #region test if child element is head or body if (Children[0] is HeadElement) { m_head = Children[0] as HeadElement; isValid = true; } else if (Children[0] is BodyElement) { m_body = Children[0] as BodyElement; m_head = new HeadElement(); Children.Clear(); Children.Add(m_head); Children.Add(m_body); isValid = true; } else { isValid = false; } #endregion } break; case 2: { #region Check first child is head, and second is body if (Children[0] is HeadElement) { m_head = Children[0] as HeadElement; } if (Children[1] is BodyElement) { m_body = Children[1] as BodyElement; } else { isValid = (m_body != null && m_head != null); } #endregion } break; default: { #region Cannot be valid isValid = false; #endregion } break; } #endregion if (!isValid) { Error("erroneous child in " + this.ToString()); } #region now check each of the children is individually valid foreach (TimedTextElementBase element in Children) { element.Valid(); } #endregion #region Add default region if none was specified if (isValid && Regions.Count < 1) { LayoutElement defaultLayout = new LayoutElement(); defaultLayout.LocalName = "layout"; defaultLayout.Namespace = m_head.Namespace; m_head.Children.Add(defaultLayout); defaultLayout.Parent = m_head; RegionElement defaultRegion = new RegionElement(); defaultRegion.SetLocalStyle("backgroundColor", "black"); defaultRegion.SetLocalStyle("color", "white"); defaultLayout.Children.Add(defaultRegion); defaultRegion.Parent = defaultLayout; defaultRegion.Id = RegionElement.DefaultRegionName; Root.Regions[defaultRegion.Id] = defaultRegion; } #endregion }