String IMarkupFormatter.Attribute(IAttr attr) { var namespaceUri = attr.NamespaceUri; var localName = attr.LocalName; var value = attr.Value; var temp = Pool.NewStringBuilder(); if (String.IsNullOrEmpty(namespaceUri)) temp.Append(localName); else if (namespaceUri == Namespaces.XmlUri) temp.Append(Namespaces.XmlPrefix).Append(Symbols.Colon).Append(localName); else if (namespaceUri == Namespaces.XLinkUri) temp.Append(Namespaces.XLinkPrefix).Append(Symbols.Colon).Append(localName); else if (namespaceUri == Namespaces.XmlNsUri) temp.Append(XmlNamespaceLocalName(localName)); else temp.Append(attr.Name); temp.Append(Symbols.Equality).Append(Symbols.DoubleQuote); for (int i = 0; i < value.Length; i++) { switch (value[i]) { case Symbols.Ampersand: temp.Append("&"); break; case Symbols.NoBreakSpace: temp.Append(" "); break; case Symbols.DoubleQuote: temp.Append("""); break; default: temp.Append(value[i]); break; } } return temp.Append(Symbols.DoubleQuote).ToPool(); }
public IAttr SetNamedItem(IAttr item) { var proposed = Prepare(item); if (proposed != null) { var name = item.Name; for (int i = 0; i < _items.Count; i++) { if (name.Is(_items[i].Name)) { var attr = _items[i]; _items[i] = proposed; RaiseChangedEvent(proposed, proposed.Value, attr.Value); return(attr); } } _items.Add(proposed); RaiseChangedEvent(proposed, proposed.Value, null); } return(null); }
public IAttr SetNamedItemWithNamespaceUri(IAttr item) { var proposed = Prepare(item); if (proposed != null) { var localName = item.LocalName; var namespaceUri = item.NamespaceUri; for (int i = 0; i < _items.Count; i++) { if (localName.Is(_items[i].LocalName) && namespaceUri.Is(_items[i].NamespaceUri)) { var attr = _items[i]; _items[i] = proposed; RaiseChangedEvent(proposed, proposed.Value, attr.Value); return(attr); } } _items.Add(proposed); RaiseChangedEvent(proposed, proposed.Value, null); } return(null); }
public IAttr SetNamedItemWithNamespaceUri(IAttr item) { var proposed = Prepare(item); if (proposed != null) { var localName = item.LocalName; var namespaceUri = item.NamespaceUri; for (int i = 0; i < _items.Count; i++) { if (String.Equals(_items[i].LocalName, localName, StringComparison.Ordinal) && String.Equals(_items[i].NamespaceUri, namespaceUri, StringComparison.Ordinal)) { var attr = _items[i]; _items[i] = proposed; RaiseChangedEvent(proposed, proposed.Value, attr.Value); return(attr); } } _items.Add(proposed); RaiseChangedEvent(proposed, proposed.Value, null); } return(null); }
/// <summary> /// Check if the value is a integer /// </summary> /// <param name="attr"></param> /// <returns></returns> public static bool IsValueInt(this IAttr attr) { int value = 0; bool isInt = int.TryParse(attr.Value, out value); return(isInt); }
internal static void WriteAttributeName(IAttr attr, StringBuilder stringBuilder) { var namespaceUri = attr.NamespaceUri; var localName = attr.LocalName; if (String.IsNullOrEmpty(namespaceUri)) { stringBuilder.Append(localName); } else if (namespaceUri.Is(NamespaceNames.XmlUri)) { stringBuilder.Append(NamespaceNames.XmlPrefix).Append(Symbols.Colon).Append(localName); } else if (namespaceUri.Is(NamespaceNames.XLinkUri)) { stringBuilder.Append(NamespaceNames.XLinkPrefix).Append(Symbols.Colon).Append(localName); } else if (namespaceUri.Is(NamespaceNames.XmlNsUri)) { stringBuilder.Append(XmlNamespaceLocalName(localName)); } else { stringBuilder.Append(attr.Name); } }
public void Deserialize(IAttr attr, StreamWriter streamWriter) { IAttrContainer container = (attr as Attr <AttrContainer>).Value; streamWriter.WriteLine($"{{{attr.Name}:{attr.Type}:}}"); Deserialize(container, streamWriter); streamWriter.WriteLine($"}}"); }
public static String GetAbsUrl(this IAttr attr, string origin) { try { return(new Uri(new Uri(origin), attr.Value).ToString()); } catch { return(attr.Value); } }
/// <summary> /// Checks if the attribute name starts with a string /// </summary> /// <param name="attr"></param> /// <param name="strData"></param> /// <returns></returns> public static bool NameStartsWith(this IAttr attr, string startString, bool ignoreCase = false) { if (ignoreCase) { return(attr.Name.StartsWith(startString, StringComparison.InvariantCultureIgnoreCase)); } else { return(attr.Name.StartsWith(startString)); } }
/// <summary> /// Removes an attribute from the document. /// </summary> /// <param name="tag">Tag the attribute belongs to</param> /// <param name="attribute">Attribute to be removed</param> /// <param name="reason">Reason for removal</param> private void RemoveAttribute(IElement tag, IAttr attribute, RemoveReason reason) { var e = new RemovingAttributeEventArgs { Tag = tag, Attribute = attribute, Reason = reason }; OnRemovingAttribute(e); if (!e.Cancel) { tag.RemoveAttribute(attribute.Name); } }
public async Task Have_ExpandMode_Attribute_SetToMulti_ByDefault() { // Arrange IRenderedComponent <BfAccordion> cut = RenderComponent <BfAccordion>(); // Asset IAttr attr = cut.Find(FastHtmlElements.FastAccordion) .Attributes .GetNamedItem(FastHtmlElements.FastAccordionAttributes.ExpandMode); attr.Should().NotBeNull(); }
public async Task Have_ExpandMode_Attribute_SetToSingle_WhenConfiguredSo() { // Arrange IRenderedComponent <BfAccordion> cut = RenderComponent <BfAccordion>( p => p.Add(pp => pp.ExpandMode, BfComponentApis.BfAccordion.ExpandModeValues.Single)); // Asset IAttr attr = cut.Find(FastHtmlElements.FastAccordion) .Attributes .GetNamedItem(FastHtmlElements.FastAccordionAttributes.ExpandMode); attr.Should().NotBeNull(); }
public async Task BeOpened_WhenConfiguredSo() { // Arrange IRenderedComponent <BfAccordion> cut = RenderComponent <BfAccordion>( p => p.AddChildContent <BfAccordionItem>(pp => pp.Add( ppp => ppp.IsExpanded, true))); // Assert IAttr attr = cut.Find($"{FastHtmlElements.FastAccordion}>{FastHtmlElements.FastAccordionItem}") .Attributes .GetNamedItem("expanded"); attr.Should().NotBeNull(); }
public async Task SplatUnknownParameters() { // Arrange IRenderedComponent <BfAccordion> cut = RenderComponent <BfAccordion>( ("custom", "value")); // Assert IAttr attr = cut.Find(FastHtmlElements.FastAccordion) .Attributes .GetNamedItem("custom"); attr.Should().NotBeNull(); attr.Value.Should().Be("value"); }
// disable XML comments warnings #pragma warning disable 1591 public virtual string Attribute(IAttr attribute) { var namespaceUri = attribute.NamespaceUri; var localName = attribute.LocalName; var value = attribute.Value; var temp = new StringBuilder(); if (String.IsNullOrEmpty(namespaceUri)) { temp.Append(localName); } else if (namespaceUri == NamespaceNames.XmlUri) { temp.Append(NamespaceNames.XmlPrefix).Append(':').Append(localName); } else if (namespaceUri == NamespaceNames.XLinkUri) { temp.Append(NamespaceNames.XLinkPrefix).Append(':').Append(localName); } else if (namespaceUri == NamespaceNames.XmlNsUri) { temp.Append(XmlNamespaceLocalName(localName)); } else { temp.Append(attribute.Name); } temp.Append('=').Append('"'); for (var i = 0; i < value.Length; i++) { switch (value[i]) { case '&': temp.Append("&"); break; case '\u00a0': temp.Append(" "); break; case '"': temp.Append("""); break; case '<': temp.Append("<"); break; case '>': temp.Append(">"); break; default: temp.Append(value[i]); break; } } return(temp.Append('"').ToString()); }
public bool Equals(IAttr other) { if (object.ReferenceEquals(this, other)) { return(true); } if (other == null) { return(false); } return(property == ((ElementAttributeBase <TDependencyObject, TDependencyProperty>)other).property); }
/// <summary> /// Creates the string representation of the attribute. /// </summary> /// <param name="attr">The attribute to serialize.</param> /// <returns>The string representation.</returns> protected virtual String Attribute(IAttr attr) { var temp = StringBuilderPool.Obtain(); WriteAttributeName(attr, temp); if (attr.Value != null) { temp.Append(Symbols.Equality).Append(Symbols.DoubleQuote); WriteAttributeValue(attr, temp); return(temp.Append(Symbols.DoubleQuote).ToPool()); } return(temp.ToPool()); }
String IMarkupFormatter.Attribute(IAttr attribute) { var namespaceUri = attribute.NamespaceUri; var localName = attribute.LocalName; var value = attribute.Value; var temp = StringBuilderPool.Obtain(); if (String.IsNullOrEmpty(namespaceUri)) { temp.Append(localName); } else if (namespaceUri.Is(NamespaceNames.XmlUri)) { temp.Append(NamespaceNames.XmlPrefix).Append(Symbols.Colon).Append(localName); } else if (namespaceUri.Is(NamespaceNames.XLinkUri)) { temp.Append(NamespaceNames.XLinkPrefix).Append(Symbols.Colon).Append(localName); } else if (namespaceUri.Is(NamespaceNames.XmlNsUri)) { temp.Append(XmlNamespaceLocalName(localName)); } else { temp.Append(attribute.Name); } temp.Append(Symbols.Equality).Append(Symbols.DoubleQuote); for (var i = 0; i < value.Length; i++) { switch (value[i]) { case Symbols.Ampersand: temp.Append("&"); break; case Symbols.NoBreakSpace: temp.Append(" "); break; case Symbols.LessThan: temp.Append("<"); break; case Symbols.DoubleQuote: temp.Append("""); break; default: temp.Append(value[i]); break; } } return(temp.Append(Symbols.DoubleQuote).ToPool()); }
public async Task Splat_UnknownParameters() { // Arrange IRenderedComponent <BfAccordion> cut = RenderComponent <BfAccordion>( p => p.AddChildContent <BfAccordionItem>( ppp => ppp.AddUnmatched("custom", "value") )); // Assert IAttr attr = cut.Find($"{FastHtmlElements.FastAccordion}>{FastHtmlElements.FastAccordionItem}") .Attributes .GetNamedItem("custom"); attr.Should().NotBeNull(); attr.Value.Should().Be("value"); }
public string Attribute(IAttr attr) { var namespaceUri = attr.NamespaceUri; var localName = attr.LocalName; var value = attr.Value; var sb = new StringBuilder(); if (string.IsNullOrEmpty(namespaceUri)) { sb.Append(localName); } else if (Is(namespaceUri, NamespaceNames.XmlUri)) { sb.Append(NamespaceNames.XmlPrefix).Append(':').Append(localName); } else if (Is(namespaceUri, NamespaceNames.XLinkUri)) { sb.Append(NamespaceNames.XLinkPrefix).Append(':').Append(localName); } else if (Is(namespaceUri, NamespaceNames.XmlNsUri)) { sb.Append(XmlNamespaceLocalName(localName)); } else { sb.Append(attr.Name); } sb.Append('=').Append('"'); for (var i = 0; i < value.Length; i++) { switch (value[i]) { // Change: Don't do this as we aren't decoding incoming entities // case '&': temp.Append("&"); break; case '\xA0': sb.Append(" "); break; case '"': sb.Append("""); break; default: sb.Append(value[i]); break; } } return(sb.Append('"').ToString()); }
public virtual IAttr SetAttributeNode(IAttr newAttr) { if (newAttr == null) { return(null); } if (!(newAttr is DomAttrImpl)) { throw new DomException(DomException.WRONG_DOCUMENT, "newAttr not instanceof DomAttrImpl"); } var newatt = (DomAttrImpl)newAttr; string name = newatt.AttValAdaptee.Attribute; IAttr result = null; AttVal att = Adaptee.Attributes; while (att != null) { if (att.Attribute.Equals(name)) { break; } att = att.Next; } if (att != null) { result = att.Adapter; att.Adapter = newAttr; } else { if (Adaptee.Attributes == null) { Adaptee.Attributes = newatt.AttValAdaptee; } else { newatt.AttValAdaptee.Next = Adaptee.Attributes; Adaptee.Attributes = newatt.AttValAdaptee; } } return(result); }
internal static void WriteAttributeValue(IAttr attr, StringBuilder stringBuilder) { var value = attr.Value ?? String.Empty; for (var i = 0; i < value.Length; i++) { switch (value[i]) { case Symbols.Ampersand: stringBuilder.Append("&"); break; case Symbols.NoBreakSpace: stringBuilder.Append(" "); break; case Symbols.DoubleQuote: stringBuilder.Append("""); break; default: stringBuilder.Append(value[i]); break; } } }
Attr Prepare(IAttr item) { var attr = item as Attr; if (attr != null) { if (attr.Container == this) { return(null); } else if (attr.Container != null) { throw new DomException(DomError.InUse); } attr.Container = this; } return(attr); }
public static async Task <AttrData> Instantiate(IAttr attr) { var plainConstraints = await attr.GetConstraints(); var dataType = await attr.GetDataType(); var plainValues = await attr.GetValueCandidates(); var values = from v in plainValues select new AttrValueData(v.EventValue.ID, v.EventValue.Value); return(new AttrData { ID = attr.PropertyID, Label = attr.Label, DataType = dataType, IsBoxed = dataType.IsBoxed, Values = values }); }
Attr Prepare(IAttr item) { var attr = item as Attr; if (attr != null) { if (Object.ReferenceEquals(attr.Container, this)) { return(null); } else if (attr.Container != null) { throw new DomException(DomError.InUse); } attr.Container = this; } return(attr); }
String IMarkupFormatter.Attribute(IAttr attribute) { var value = attribute.Value; var temp = Pool.NewStringBuilder(); temp.Append(attribute.Name); temp.Append(Symbols.Equality).Append(Symbols.DoubleQuote); for (int i = 0; i < value.Length; i++) { switch (value[i]) { case Symbols.SingleQuote: temp.Append("'"); break; case Symbols.DoubleQuote: temp.Append("""); break; default: temp.Append(value[i]); break; } } return(temp.Append(Symbols.DoubleQuote).ToPool()); }
public virtual IAttr RemoveAttributeNode(IAttr oldAttr) { if (oldAttr == null) { return(null); } IAttr result; AttVal att = Adaptee.Attributes; AttVal pre = null; while (att != null) { if (att.Adapter == oldAttr) { break; } pre = att; att = att.Next; } if (att != null) { if (pre == null) { Adaptee.Attributes = att.Next; } else { pre.Next = att.Next; } result = oldAttr; } else { throw new DomException(DomException.NOT_FOUND, "oldAttr not found"); } return(result); }
String IMarkupFormatter.Attribute(IAttr attribute) { var value = attribute.Value; var temp = StringBuilderPool.Obtain(); temp.Append(attribute.Name); temp.Append(Symbols.Equality).Append(Symbols.DoubleQuote); for (var i = 0; i < value.Length; i++) { switch (value[i]) { case Symbols.Ampersand: temp.Append("&"); break; case Symbols.LessThan: temp.Append("<"); break; case Symbols.DoubleQuote: temp.Append("""); break; default: temp.Append(value[i]); break; } } return(temp.Append(Symbols.DoubleQuote).ToPool()); }
public IAttr SetNamedItem(IAttr item) { var proposed = Prepare(item); if (proposed != null) { var name = item.Name; for (var i = 0; i < _items.Count; i++) { if (name.Is(_items[i].Name)) { var attr = _items[i]; _items[i] = proposed; RaiseChangedEvent(proposed, proposed.Value, attr.Value); return attr; } } _items.Add(proposed); RaiseChangedEvent(proposed, proposed.Value, null); } return null; }
/// <summary> /// Compares the given attribute to the current one. /// </summary> /// <param name="other">The attibute to compare to.</param> /// <returns> /// True if both attributes are equal, otherwise false. /// </returns> public Boolean Equals(IAttr other) { return (String.Equals(Prefix, other.Prefix, StringComparison.Ordinal) && String.Equals(NamespaceUri, other.NamespaceUri, StringComparison.Ordinal) && String.Equals(Value, other.Value, StringComparison.Ordinal)); }
Attr Prepare(IAttr item) { var attr = item as Attr; if (attr != null) { if (attr.Container == this) return null; else if (attr.Container != null) throw new DomException(DomError.InUse); attr.Container = this; } return attr; }
public IAttr SetNamedItemWithNamespaceUri(IAttr item) { var proposed = Prepare(item); if (proposed != null) { var localName = item.LocalName; var namespaceUri = item.NamespaceUri; for (int i = 0; i < _items.Count; i++) { if (String.Equals(_items[i].LocalName, localName, StringComparison.Ordinal) && String.Equals(_items[i].NamespaceUri, namespaceUri, StringComparison.Ordinal)) { var attr = _items[i]; _items[i] = proposed; RaiseChangedEvent(proposed, proposed.Value, attr.Value); return attr; } } _items.Add(proposed); RaiseChangedEvent(proposed, proposed.Value, null); } return null; }
public IAttr SetNamedItemWithNamespaceUri(IAttr item, Boolean suppressMutationObservers) { var proposed = Prepare(item); if (proposed != null) { var localName = item.LocalName; var namespaceUri = item.NamespaceUri; for (var i = 0; i < _items.Count; i++) { if (localName.Is(_items[i].LocalName) && namespaceUri.Is(_items[i].NamespaceUri)) { var attr = _items[i]; _items[i] = proposed; if (!suppressMutationObservers) { RaiseChangedEvent(proposed, proposed.Value, attr.Value); } return attr; } } _items.Add(proposed); if (!suppressMutationObservers) { RaiseChangedEvent(proposed, proposed.Value, null); } } return null; }
/// <summary> /// Remove an attribute from the document. /// </summary> /// <param name="tag">tag where the attribute to belongs</param> /// <param name="attribute">to be removed</param> /// <param name="reason">reason why to be removed</param> private void RemoveAttribute(IElement tag, IAttr attribute, RemoveReason reason) { var e = new RemovingAttributeEventArgs { Tag = tag, Attribute = attribute, Reason = reason }; OnRemovingAttribute(e); if (!e.Cancel) tag.RemoveAttribute(attribute.Name); }
/// <summary> /// Initializes a new instance of the <see cref="RemovingAttributeEventArgs"/> class. /// </summary> /// <param name="tag">The element containing the attribute.</param> /// <param name="attribute">The attribute to be removed.</param> /// <param name="reason">The reason why the attribute will be removed.</param> public RemovingAttributeEventArgs(IElement tag, IAttr attribute, RemoveReason reason) { Tag = tag; Attribute = attribute; Reason = reason; }
/// <summary> /// Determines whether the specified attribute can contain a URI. /// </summary> /// <param name="attribute">The attribute.</param> /// <returns><c>true</c> if the attribute can contain a URI; otherwise, <c>false</c>.</returns> private bool IsUriAttribute(IAttr attribute) { return(UriAttributes.Contains(attribute.Name)); }
public IAttr SetNamedItemWithNamespaceUri(IAttr item) { return SetNamedItemWithNamespaceUri(item, false); }
String IMarkupFormatter.Attribute(IAttr attribute) { return HtmlMarkupFormatter.Instance.Attribute(attribute); }
String IMarkupFormatter.Attribute(IAttr attribute) { var value = attribute.Value; var temp = Pool.NewStringBuilder(); temp.Append(attribute.Name); temp.Append(Symbols.Equality).Append(Symbols.DoubleQuote); for (int i = 0; i < value.Length; i++) { switch (value[i]) { case Symbols.Ampersand: temp.Append("&"); break; case Symbols.LessThan: temp.Append("<"); break; case Symbols.DoubleQuote: temp.Append("""); break; default: temp.Append(value[i]); break; } } return temp.Append(Symbols.DoubleQuote).ToPool(); }
/// <summary> /// Determines whether the specified attribute can contain a URI. /// </summary> /// <param name="attribute">The attribute.</param> /// <returns><c>true</c> if the attribute can contain a URI; otherwise, <c>false</c>.</returns> private bool IsUriAttribute(IAttr attribute) { return UriAttributes.Contains(attribute.Name); }
/// <summary> DOM2 - not implemented. </summary> public virtual IAttr SetAttributeNodeNs(IAttr newAttr) { return null; }
/// <summary> /// Formats an attribute specified by the argument. /// </summary> /// <param name="attribute">The attribute to serialize.</param> /// <returns>The formatted attribute.</returns> public String Attribute(IAttr attribute) { return ChildFormatter.Attribute(attribute); }
Attr Prepare(IAttr item) { var attr = item as Attr; if (attr != null) { if (Object.ReferenceEquals(attr.Container, this)) { return null; } else if (attr.Container != null) { throw new DomException(DomError.InUse); } attr.Container = this; } return attr; }
public Boolean Equals(IAttr other) { return Prefix.Is(other.Prefix) && NamespaceUri.Is(other.NamespaceUri) && Value.Is(other.Value); }
public virtual IAttr SetAttributeNode(IAttr newAttr) { if (newAttr == null) { return null; } if (!(newAttr is DomAttrImpl)) { throw new DomException(DomException.WRONG_DOCUMENT, "newAttr not instanceof DomAttrImpl"); } var newatt = (DomAttrImpl) newAttr; string name = newatt.AttValAdaptee.Attribute; IAttr result = null; AttVal att = Adaptee.Attributes; while (att != null) { if (att.Attribute.Equals(name)) { break; } att = att.Next; } if (att != null) { result = att.Adapter; att.Adapter = newAttr; } else { if (Adaptee.Attributes == null) { Adaptee.Attributes = newatt.AttValAdaptee; } else { newatt.AttValAdaptee.Next = Adaptee.Attributes; Adaptee.Attributes = newatt.AttValAdaptee; } } return result; }
public virtual IAttr RemoveAttributeNode(IAttr oldAttr) { if (oldAttr == null) { return null; } IAttr result; AttVal att = Adaptee.Attributes; AttVal pre = null; while (att != null) { if (att.Adapter == oldAttr) { break; } pre = att; att = att.Next; } if (att != null) { if (pre == null) { Adaptee.Attributes = att.Next; } else { pre.Next = att.Next; } result = oldAttr; } else { throw new DomException(DomException.NOT_FOUND, "oldAttr not found"); } return result; }
/// <summary> /// Determines whether the specified attribute is allowed. /// </summary> /// <param name="attribute">The attribute.</param> /// <returns><c>true</c> if the attribute is allowed; otherwise, <c>false</c>.</returns> private bool IsAllowedAttribute(IAttr attribute) { return(AllowedAttributes.Contains(attribute.Name) // test html5 data- attributes || (AllowDataAttributes && attribute.Name != null && attribute.Name.StartsWith("data-", StringComparison.OrdinalIgnoreCase))); }
/// <summary> /// Determines whether the specified attribute is allowed. /// </summary> /// <param name="attribute">The attribute.</param> /// <returns><c>true</c> if the attribute is allowed; otherwise, <c>false</c>.</returns> private bool IsAllowedAttribute(IAttr attribute) { return AllowedAttributes.Contains(attribute.Name) // test html5 data- attributes || (AllowDataAttributes && attribute.Name != null && attribute.Name.StartsWith("data-", StringComparison.OrdinalIgnoreCase)); }