public virtual void RemoveAttribute(string name) { if (Adaptee == null) { return; } AttVal att = Adaptee.Attributes; AttVal pre = null; while (att != null) { if (att.Attribute.Equals(name)) { break; } pre = att; att = att.Next; } if (att != null) { if (pre == null) { Adaptee.Attributes = att.Next; } else { pre.Next = att.Next; } } }
public object Clone() { var av = new AttVal(); if (Next != null) { av.Next = (AttVal)Next.Clone(); } if (Attribute != null) { av.Attribute = Attribute; } if (Val != null) { av.Val = Val; } av.Delim = Delim; if (Asp != null) { av.Asp = (Node)Asp.Clone(); } if (Php != null) { av.Php = (Node)Php.Clone(); } av.Dict = AttributeTable.DefaultAttributeTable.FindAttribute(this); return(av); }
public virtual void Check(Lexer lexer, Node node) { node.CheckUniqueAttributes(lexer); AttVal lang = node.GetAttrByName("language"); AttVal type = node.GetAttrByName("type"); if (type == null) { Report.AttrError(lexer, node, "type", Report.MISSING_ATTRIBUTE); /* check for javascript */ if (lang != null) { string str = lang.Val; if (str.Length > 10) { str = str.Substring(0, 10); } if ((String.CompareOrdinal(str, "javascript") == 0) || (String.CompareOrdinal(str, "jscript") == 0)) { node.AddAttribute("type", "text/javascript"); } } else { node.AddAttribute("type", "text/javascript"); } } }
public virtual IAttr CreateAttribute(string name) { var av = new AttVal(null, null, '"', name, null); av.Dict = AttributeTable.DefaultAttributeTable.FindAttribute(av); return(av.Adapter); }
public virtual void Check(Lexer lexer, Node node, AttVal attval) { string val = attval.Val; if (val == null) { Report.AttrError(lexer, node, attval.Attribute, Report.MISSING_ATTR_VALUE); } else if (String.CompareOrdinal(val, "top") == 0 || String.CompareOrdinal(val, "middle") == 0 || String.CompareOrdinal(val, "bottom") == 0 || String.CompareOrdinal(val, "baseline") == 0) { /* all is fine */ } else if (String.CompareOrdinal(val, "left") == 0 || String.CompareOrdinal(val, "right") == 0) { if (!(node.Tag != null && ((node.Tag.Model & ContentModel.IMG) != 0))) { Report.AttrError(lexer, node, val, Report.BAD_ATTRIBUTE_VALUE); } } else if (String.CompareOrdinal(val, "texttop") == 0 || String.CompareOrdinal(val, "absmiddle") == 0 || String.CompareOrdinal(val, "absbottom") == 0 || String.CompareOrdinal(val, "textbottom") == 0) { lexer.Versions &= HtmlVersion.Proprietary; Report.AttrError(lexer, node, val, Report.PROPRIETARY_ATTR_VALUE); } else { Report.AttrError(lexer, node, val, Report.BAD_ATTRIBUTE_VALUE); } }
/* remove attribute from node then free it */ public virtual void RemoveAttribute(AttVal attr) { AttVal av; AttVal prev = null; AttVal next; for (av = Attributes; av != null; av = next) { next = av.Next; if (av == attr) { if (prev != null) { prev.Next = next; } else { Attributes = next; } } else { prev = av; } } }
public AttVal(AttVal next, Attribute dict, int delim, string attribute, string val) { Next = next; _dict = dict; _asp = null; Php = null; Delim = delim; Attribute = attribute; Val = val; }
public AttVal(AttVal next, Attribute dict, Node asp, Node php, int delim, string attribute, string val) { Next = next; _dict = dict; _asp = asp; Php = php; Delim = delim; Attribute = attribute; Val = val; }
public virtual Attribute FindAttribute(AttVal attval) { if (attval.Attribute != null) { Attribute np = Lookup(attval.Attribute); return(np); } return(null); }
public virtual INode GetNamedItem(string name) { AttVal att = _first; while (att != null) { if (att.Attribute.Equals(name)) { break; } att = att.Next; } return(att != null ? att.Adapter : null); }
public virtual INode Item(int index) { int i = 0; AttVal att = _first; while (att != null) { if (i >= index) { break; } i++; att = att.Next; } return(att != null ? att.Adapter : null); }
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 static void AddClass(Node node, string classname) { AttVal classattr = node.GetAttrByName("class"); /* * if there already is a class attribute * then append class name after a space */ if (classattr != null) { classattr.Val = classattr.Val + " " + classname; } /* create new class attribute */ else { node.AddAttribute("class", classname); } }
public virtual IAttr GetAttributeNode(string name) { if (Adaptee == null) { return(null); } AttVal att = Adaptee.Attributes; while (att != null) { if (att.Attribute.Equals(name)) { break; } att = att.Next; } return(att != null ? att.Adapter : null); }
public virtual string GetAttribute(string name) { if (Adaptee == null) { return(null); } AttVal att = Adaptee.Attributes; while (att != null) { if (att.Attribute.Equals(name)) { break; } att = att.Next; } return(att != null ? att.Val : String.Empty); }
public virtual void Check(Lexer lexer, Node node, AttVal attval) { /* IMG, OBJECT, APPLET and EMBED use align for vertical position */ if (node.Tag != null && ((node.Tag.Model & ContentModel.IMG) != 0)) { AttrCheckImpl.CheckValign.Check(lexer, node, attval); return; } string val = attval.Val; if (val == null) { Report.AttrError(lexer, node, attval.Attribute, Report.MISSING_ATTR_VALUE); } else if ( !(String.CompareOrdinal(val, "left") == 0 || String.CompareOrdinal(val, "center") == 0 || String.CompareOrdinal(val, "right") == 0 || String.CompareOrdinal(val, "justify") == 0)) { Report.AttrError(lexer, node, attval.Val, Report.BAD_ATTRIBUTE_VALUE); } }
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); }
public virtual void AddAttribute(string name, string val) { var av = new AttVal(null, null, null, null, '"', name, val); av.Dict = AttributeTable.DefaultAttributeTable.FindAttribute(av); if (Attributes == null) { Attributes = av; /* append to end of attributes */ } else { AttVal here = Attributes; while (here.Next != null) { here = here.Next; } here.Next = av; } }
public virtual void SetAttribute(string name, string val) { if (Adaptee == null) { return; } AttVal att = Adaptee.Attributes; while (att != null) { if (att.Attribute.Equals(name)) { break; } att = att.Next; } if (att != null) { att.Val = val; } else { att = new AttVal(null, null, '"', name, val); att.Dict = AttributeTable.DefaultAttributeTable.FindAttribute(att); if (Adaptee.Attributes == null) { Adaptee.Attributes = att; } else { att.Next = Adaptee.Attributes; Adaptee.Attributes = att; } } }
protected internal DomAttrImpl(AttVal adaptee) : base(null) { _attValAdaptee = adaptee; }
public virtual IAttr CreateAttribute(string name) { var av = new AttVal(null, null, '"', name, null); av.Dict = AttributeTable.DefaultAttributeTable.FindAttribute(av); return av.Adapter; }
public virtual AttVal CloneAttributes(AttVal attrs) { var cattrs = (AttVal) attrs.Clone(); for (AttVal att = cattrs; att != null; att = att.Next) { if (att.Asp != null) _nodeList.Add(att.Asp); if (att.Php != null) _nodeList.Add(att.Php); } return cattrs; }
public virtual void FixHtmlNameSpace(Node root, string profile) { Node node; //TODO:odd! for (node = root.Content; node != null && node.Tag != Options.TagTable.TagHtml; node = node.Next) { } if (node != null) { AttVal attr; for (attr = node.Attributes; attr != null; attr = attr.Next) { if (attr.Attribute.Equals("xmlns")) { break; } } if (attr != null) { if (!attr.Val.Equals(profile)) { Report.Warning(this, node, null, Report.INCONSISTENT_NAMESPACE); attr.Val = profile; } } else { attr = new AttVal(node.Attributes, null, '"', "xmlns", profile); attr.Dict = AttributeTable.DefaultAttributeTable.FindAttribute(attr); node.Attributes = attr; } } }
public virtual Attribute FindAttribute(AttVal attval) { if (attval.Attribute != null) { Attribute np = Lookup(attval.Attribute); return np; } return null; }
public object Clone() { var av = new AttVal(); if (Next != null) { av.Next = (AttVal) Next.Clone(); } if (Attribute != null) { av.Attribute = Attribute; } if (Val != null) { av.Val = Val; } av.Delim = Delim; if (Asp != null) { av.Asp = (Node) Asp.Clone(); } if (Php != null) { av.Php = (Node) Php.Clone(); } av.Dict = AttributeTable.DefaultAttributeTable.FindAttribute(this); return av; }
protected internal DomAttrMapImpl(AttVal first) { _first = first; }
private void MergeStyles(Node node, Node child) { AttVal av; string s1, s2; for (s2 = null, av = child.Attributes; av != null; av = av.Next) { if (av.Attribute.Equals("style")) { s2 = av.Val; break; } } for (s1 = null, av = node.Attributes; av != null; av = av.Next) { if (av.Attribute.Equals("style")) { s1 = av.Val; break; } } if (s1 != null) { if (s2 != null) { /* merge styles from both */ string style = MergeProperties(s1, s2); av.Val = style; } } else if (s2 != null) { /* copy style of child */ av = new AttVal(node.Attributes, null, '"', "style", s2); av.Dict = AttributeTable.DefaultAttributeTable.FindAttribute(av); node.Attributes = av; } }
/* add style properties to node corresponding to the font face, size and color attributes */ private void AddFontStyles(Node node, AttVal av) { while (av != null) { if (av.Attribute.Equals("face")) { AddFontFace(node, av.Val); } else if (av.Attribute.Equals("size")) { AddFontSize(node, av.Val); } else if (av.Attribute.Equals("color")) { AddFontColor(node, av.Val); } av = av.Next; } }
/* Add style property to element, creating style attribute as needed and adding ; delimiter */ private void AddStyleProperty(Node node, string property) { AttVal av; for (av = node.Attributes; av != null; av = av.Next) { if (av.Attribute.Equals("style")) { break; } } /* if style attribute already exists then insert property */ if (av != null) { string s = AddProperty(av.Val, property); av.Val = s; } else { /* else create new style attribute */ av = new AttVal(node.Attributes, null, '"', "style", property); av.Dict = AttributeTable.DefaultAttributeTable.FindAttribute(av); node.Attributes = av; } }
private void PrintAttrs(Out fout, int indent, Node node, AttVal attr) { if (attr != null) { if (attr.Next != null) { PrintAttrs(fout, indent, node, attr.Next); } if (attr.Attribute != null) { PrintAttribute(fout, indent, node, attr); } else if (attr.Asp != null) { AddC(' ', _linelen++); PrintAsp(fout, indent, attr.Asp); } else if (attr.Php != null) { AddC(' ', _linelen++); PrintPhp(fout, indent, attr.Php); } } /* add xml:space attribute to pre and other elements */ if (_options.XmlOut && _options.XmlSpace && ParserImpl.XmlPreserveWhiteSpace(node, _options.TagTable) && node.GetAttrByName("xml:space") == null) { PrintString(" xml:space=\"preserve\""); } }
private void PrintAttribute(Out fout, int indent, Node node, AttVal attr) { bool wrappable = false; if (_options.IndentAttributes) { FlushLine(fout, indent); indent += _options.Spaces; } string name = attr.Attribute; if (indent + _linelen >= _options.WrapLen) { WrapLine(fout, indent); } if (!_options.XmlTags && !_options.XmlOut && attr.Dict != null) { if (AttributeTable.DefaultAttributeTable.IsScript(name)) { wrappable = _options.WrapScriptlets; } else if (!attr.Dict.Nowrap && _options.WrapAttVals) { wrappable = true; } } if (indent + _linelen < _options.WrapLen) { _wraphere = _linelen; AddC(' ', _linelen++); } else { CondFlushLine(fout, indent); AddC(' ', _linelen++); } for (int i = 0; i < name.Length; i++) { AddC(Lexer.FoldCase(name[i], _options.UpperCaseAttrs, _options.XmlTags), _linelen++); } if (indent + _linelen >= _options.WrapLen) { WrapLine(fout, indent); } if (attr.Val == null) { if (_options.XmlTags || _options.XmlOut) { PrintAttrValue(fout, indent, attr.Attribute, attr.Delim, true); } else if (!attr.BoolAttribute && !Node.IsNewNode(node)) { PrintAttrValue(fout, indent, "", attr.Delim, true); } else if (indent + _linelen < _options.WrapLen) { _wraphere = _linelen; } } else { PrintAttrValue(fout, indent, attr.Val, attr.Delim, wrappable); } }
/* swallows closing '>' */ public virtual AttVal ParseAttrs(MutableBoolean isempty) { var delim = new MutableInteger(); var asp = new MutableObject(); var php = new MutableObject(); AttVal list = null; while (!EndOfInput()) { string attribute = ParseAttribute(isempty, asp, php); AttVal av; if (attribute == null) { /* check if attributes are created by ASP markup */ if (asp.Object != null) { av = new AttVal(list, null, (Node) asp.Object, null, '\x0000', null, null); list = av; continue; } /* check if attributes are created by PHP markup */ if (php.Object != null) { av = new AttVal(list, null, null, (Node) php.Object, '\x0000', null, null); list = av; continue; } break; } string val = ParseValue(attribute, false, isempty, delim); if (IsValidAttrName(attribute)) { av = new AttVal(list, null, null, null, delim.Val, attribute, val); av.Dict = AttributeTable.DefaultAttributeTable.FindAttribute(av); list = av; } else { //av = new AttVal(null, null, null, null, 0, attribute, val); Report.AttrError(this, Token, val, Report.BAD_ATTRIBUTE_VALUE); } } return list; }
/* create style element using rules from dictionary */ private void CreateStyleElement(Lexer lexer, Node doc) { Style style; if (lexer.Styles == null && NiceBody(lexer, doc)) { return; } Node node = lexer.NewNode(Node.START_TAG, null, 0, 0, "style"); node.Isimplicit = true; /* insert type attribute */ var av = new AttVal(null, null, '"', "type", "text/css"); av.Dict = AttributeTable.DefaultAttributeTable.FindAttribute(av); node.Attributes = av; Node body = doc.FindBody(lexer.Options.TagTable); lexer.Txtstart = lexer.Lexsize; if (body != null) { CleanBodyAttrs(lexer, body); } for (style = lexer.Styles; style != null; style = style.Next) { lexer.AddCharToLexer(' '); lexer.AddStringLiteral(style.Tag); lexer.AddCharToLexer('.'); lexer.AddStringLiteral(style.TagClass); lexer.AddCharToLexer(' '); lexer.AddCharToLexer('{'); lexer.AddStringLiteral(style.Properties); lexer.AddCharToLexer('}'); lexer.AddCharToLexer('\n'); } lexer.Txtend = lexer.Lexsize; Node.InsertNodeAtEnd(node, lexer.NewNode(Node.TEXT_NODE, lexer.Lexbuf, lexer.Txtstart, lexer.Txtend)); /* now insert style element into document head doc is root node. search its children for html node the head node should be first child of html node */ Node head = doc.FindHead(lexer.Options.TagTable); if (head != null) { Node.InsertNodeAtEnd(head, node); } }