//--- Extension Methods --- public static StringBuilder AppendLiteral(this StringBuilder builder, DekiScriptLiteral literal) { if(literal is DekiScriptString) { builder.Append(((DekiScriptString)literal).Value); } else { builder.Append(literal.ToString()); } return builder; }
private void AddText(XmlNode context, DekiScriptLiteral literal) { if(context == null) { ConvertStateToHtml(null); } // TODO (steveb): this is just plain retarded; why do we need to distinguish between string and non-string?!? if(literal is DekiScriptString) { (context ?? _body).AppendChild(_document.CreateTextNode(((DekiScriptString)literal).Value)); } else { (context ?? _body).AppendChild(_document.CreateTextNode(literal.ToString())); } }
internal void InsertValueBeforeNode(XmlNode parent, XmlNode reference, DekiScriptLiteral value) { if((value is DekiScriptXml) || (value is DekiScriptUri)) { XDoc xml = value.AsEmbeddableXml(Mode == DekiScriptEvalMode.EvaluateSafeMode); if(xml.HasName("html")) { // TODO (steveb): merge XML namespaces // merge <head> and <tail> sections AddHeadElements(xml); AddTailElements(xml); // loop over body elements in response foreach(XDoc body in xml["body"]) { string target = body["@target"].AsText; string conflict = body["@conflict"].AsText ?? "ignore"; // check if the main body is targeted or something else if(string.IsNullOrEmpty(target)) { // append body nodes foreach(XmlNode node in body.AsXmlNode.ChildNodes) { parent.InsertBefore(parent.OwnerDocument.ImportNode(node, true), reference); } } else { // check if the targeted body already exists if(Bodies.ContainsKey(target) && !StringUtil.EqualsInvariant(conflict, "replace")) { if(StringUtil.EqualsInvariant(conflict, "append")) { // append nodes to existing body Bodies[target].Add(body.AsXmlNode); } } else { // create a new body element List<XmlNode> list = new List<XmlNode>(); list.Add(body.AsXmlNode); Bodies[target] = list; } } } } else if(!xml.IsEmpty) { // replace the current node with the entire document parent.InsertBefore(parent.OwnerDocument.ImportNode(xml.AsXmlNode, true), reference); } } else if(value is DekiScriptComplexLiteral) { // append text respresentation of value parent.InsertBefore(CreateTextNode(value.ToString()), reference); } else { // append value cast to text string text = value.AsString(); if(!string.IsNullOrEmpty(text)) { parent.InsertBefore(CreateTextNode(text), reference); } } }