public static XmlReader GetAsXmlReader(ITagAttribute attribute, TagModel model, string fallBack) { XmlReader reader = null; object raw = Get(attribute, model) ?? fallBack; if (raw == null) { return(reader); } if (raw is string && !String.IsNullOrEmpty((string)raw)) { var textReader = new StringReader((string)raw); reader = XmlReader.Create(textReader); } else if (raw is Stream) { XmlReader.Create((Stream)raw); } else if (raw is TextReader) { reader = XmlReader.Create((TextReader)raw); } else if (raw is XmlReader) { reader = (XmlReader)raw; } else { throw TagException.UnsupportedInput(raw.GetType(), typeof(string), typeof(Stream), typeof(TextReader), typeof(XmlReader)).Decorate(attribute.Context); } return(reader); }
private NumberStyles GetAsNumberStyle(ITagAttribute styles, TagModel model, NumberStyles style) { if (Styles == null) { return(style); } string stylesAsString = GetAsString(Styles, model); if (stylesAsString != null) { bool first = true; string[] stylesStr = stylesAsString.Split(','); foreach (string styleStr in stylesStr) { if (first) { style = EnumParser <NumberStyles> .Parse(styleStr); } else { style = style | EnumParser <NumberStyles> .Parse(styleStr); } first = false; } } return(style); }
public static XPathNodeIterator GetAndEvaluate(ITagAttribute source, ITagAttribute xPath, TagModel model) { string xPathAsStr = GetAsString(xPath, model); object var = model[GetAsString(source, model) ?? String.Empty]; XPathNodeIterator result = null; if (var != null && xPathAsStr != null) { // XmlNode node; XPathNavigator navigator; if (var is XPathNavigator) { navigator = (XPathNavigator)var; } else { navigator = ((IXPathNavigable)var).CreateNavigator(); } var nsmgr = new XmlNamespaceManager(navigator.NameTable); nsmgr.AddNamespace("xsl", "http://www.w3.org/1999/XSL/Transform"); result = navigator.Select(xPathAsStr, nsmgr); } return(result); }
private static bool IsAngularAttribute(ITagAttribute attribute) { // TODO: We can do better than this... // Perhaps follow the reference and get the attribute type, as defined in // the HtmlElements.xml. E.g. ng-include is %AngularJsUrl return(attribute.AttributeName.StartsWith("ng-", StringComparison.OrdinalIgnoreCase) || attribute.AttributeName.StartsWith("data-ng-", StringComparison.OrdinalIgnoreCase) || attribute.AttributeName.StartsWith("x-ng-", StringComparison.OrdinalIgnoreCase)); }
private static bool IsAngularAttribute(ITagAttribute attribute) { // TODO: We can do better than this... // Perhaps follow the reference and get the attribute type, as defined in // the HtmlElements.xml. E.g. ng-include is %AngularJsUrl return attribute.AttributeName.StartsWith("ng-", StringComparison.OrdinalIgnoreCase) || attribute.AttributeName.StartsWith("data-ng-", StringComparison.OrdinalIgnoreCase) || attribute.AttributeName.StartsWith("x-ng-", StringComparison.OrdinalIgnoreCase); }
public static T?GetAs <T>(ITagAttribute expressions, TagModel model, T?fallBack) where T : struct { string result = GetAsString(expressions, model); if (!String.IsNullOrEmpty(result)) { return(EnumParser <T> .Parse(result)); } return(fallBack); }
public static XPathDocument GetAsXmlDocument(ITagAttribute attribute, TagModel model, string fallBack) { XPathDocument xDoc = null; object raw = Get(attribute, model) ?? fallBack; if (raw == null) { return(xDoc); } if (raw is XPathDocument) { xDoc = (XPathDocument)raw; } else if (raw is string) { if (!String.IsNullOrEmpty((string)raw)) { var rawAsString = (string)raw; using (var textReader = new StringReader(rawAsString.Trim())) { xDoc = new XPathDocument(textReader); } } else { xDoc = null; } } else if (raw is Stream) { xDoc = new XPathDocument((Stream)raw); } else if (raw is TextReader) { xDoc = new XPathDocument((TextReader)raw); } else if (raw is XmlReader) { xDoc = new XPathDocument((XmlReader)raw); } else { throw TagException.UnsupportedInput(raw.GetType(), typeof(XPathDocument), typeof(string), typeof(Stream), typeof(TextReader), typeof(XmlReader)).Decorate(attribute.Context); } return(xDoc); }
public static XPathDocument GetAsXmlDocument(ITagAttribute attribute, TagModel model, string fallBack) { XPathDocument xDoc = null; object raw = Get(attribute, model) ?? fallBack; if (raw == null) { return xDoc; } if (raw is XPathDocument) { xDoc = (XPathDocument) raw; } else if (raw is string) { if (!String.IsNullOrEmpty((string) raw)) { var rawAsString = (string) raw; using (var textReader = new StringReader(rawAsString.Trim())) { xDoc = new XPathDocument(textReader); } } else { xDoc = null; } } else if (raw is Stream) { xDoc = new XPathDocument((Stream) raw); } else if (raw is TextReader) { xDoc = new XPathDocument((TextReader) raw); } else if (raw is XmlReader) { xDoc = new XPathDocument((XmlReader) raw); } else { throw TagException.UnsupportedInput(raw.GetType(), typeof (XPathDocument), typeof (string), typeof (Stream), typeof (TextReader), typeof (XmlReader)).Decorate(attribute.Context); } return xDoc; }
public string EvaluateNested(TagModel model) { var sb = new StringBuilder(); string paramStr = GetAsString(_name, model) ?? String.Empty; if (!String.IsNullOrEmpty(paramStr)) { ITagAttribute valueAttribute = Value ?? Body; string valueStr = GetAsString(valueAttribute, model) ?? String.Empty; sb.Append(paramStr); sb.Append("="); sb.Append(HttpUtility.UrlPathEncode(valueStr)); } return(sb.ToString()); }
public static string GetAsUrl(ITagAttribute expressions, TagModel model) { var result = GetAsString(expressions, model); if (result!=null && result.StartsWith("~")) { var relativePart = result.Substring(1); var appName = model.ApplicationName; result = ""; if(!"/".Equals(appName)) { result += model.ApplicationName; } result += relativePart; } return result; }
public static string GetAsUrl(ITagAttribute expressions, TagModel model) { var result = GetAsString(expressions, model); if (result != null && result.StartsWith("~")) { var relativePart = result.Substring(1); var appName = model.ApplicationName; result = ""; if (!"/".Equals(appName)) { result += model.ApplicationName; } result += relativePart; } return(result); }
public static bool GetAndEvaluateAsBool(ITagAttribute source, ITagAttribute xPath, TagModel model, bool fallBack) { bool result = fallBack; try { XPathNodeIterator nodes = GetAndEvaluate(source, xPath, model); if (nodes != null && nodes.Count > 0) { XPathNavigator node = GuardSingleNode(model, nodes, xPath); result = ParseBoolean(nodes.Current) ?? fallBack; } } catch (FormatException Fe) { throw TagException.IllegalXPath(Fe).Decorate(xPath.Context); } return result; }
public static bool GetAndEvaluateAsBool(ITagAttribute source, ITagAttribute xPath, TagModel model, bool fallBack) { bool result = fallBack; try { XPathNodeIterator nodes = GetAndEvaluate(source, xPath, model); if (nodes != null && nodes.Count > 0) { XPathNavigator node = GuardSingleNode(model, nodes, xPath); result = ParseBoolean(nodes.Current) ?? fallBack; } } catch (FormatException Fe) { throw TagException.IllegalXPath(Fe).Decorate(xPath.Context); } return(result); }
protected override Action <ITextControl> ExecutePsiTransaction(ISolution solution, IProgressIndicator progress) { IHtmlTagHeader tagHeader = GetTag(); if (tagHeader == null) { return(null); } // The easiest way to create an attribute is to create an HTML tag with an attribute in it // and then get the attribute from the tag. HtmlElementFactory factory = HtmlElementFactory.GetInstance(tagHeader.Language); IHtmlTag dummy = factory.CreateHtmlTag("<tag id=\"\"/>", tagHeader); ITagAttribute idAttr = dummy.Attributes.Single(); tagHeader.AddAttributeBefore(idAttr, null); // continuation to do after transaction committed return(textControl => // move cursor inside new created id attribute textControl.Caret.MoveTo(idAttr.ValueElement.GetDocumentRange().TextRange.StartOffset, CaretVisualPlacement.Generic)); }
public static XPathNodeIterator GetAndEvaluate(ITagAttribute source, ITagAttribute xPath, TagModel model) { string xPathAsStr = GetAsString(xPath, model); object var = model[GetAsString(source, model) ?? String.Empty]; XPathNodeIterator result = null; if (var != null && xPathAsStr != null) { // XmlNode node; XPathNavigator navigator; if (var is XPathNavigator) { navigator = (XPathNavigator) var; } else { navigator = ((IXPathNavigable) var).CreateNavigator(); } var nsmgr = new XmlNamespaceManager(navigator.NameTable); nsmgr.AddNamespace("xsl", "http://www.w3.org/1999/XSL/Transform"); result = navigator.Select(xPathAsStr, nsmgr); } return result; }
public object EvaluateNested(TagModel model) { ITagAttribute valueAttribute = Value ?? Body; return(Get(valueAttribute, model) ?? String.Empty); }
public static string GetAsString(ITagAttribute expressions, TagModel model) { object result = Get(expressions, model); return(result != null?result.ToString() : null); }
private static XPathNavigator GuardSingleNode(TagModel model, XPathNodeIterator nodes, ITagAttribute select) { if (nodes.Count > 1) { throw TagException.SingleNodeExpected(GetAsString(select, model)).Decorate(select.Context); } nodes.MoveNext(); return nodes.Current; }
public static XmlReader GetAsXmlReader(ITagAttribute attribute, TagModel model, string fallBack) { XmlReader reader = null; object raw = Get(attribute, model) ?? fallBack; if (raw == null) { return reader; } if (raw is string && !String.IsNullOrEmpty((string) raw)) { var textReader = new StringReader((string) raw); reader = XmlReader.Create(textReader); } else if (raw is Stream) { XmlReader.Create((Stream) raw); } else if (raw is TextReader) { reader = XmlReader.Create((TextReader) raw); } else if (raw is XmlReader) { reader = (XmlReader) raw; } else { throw TagException.UnsupportedInput(raw.GetType(), typeof (string), typeof (Stream), typeof (TextReader), typeof (XmlReader)).Decorate(attribute.Context); } return reader; }
public static int?GetAsInt(ITagAttribute expressions, TagModel model) { object result = Get(expressions, model); return((int?)TypeConverter.To(result, typeof(int?))); }
protected bool?GetAsBool(ITagAttribute attribute, TagModel model) { return((bool?)TypeConverter.To(Get(attribute, model), typeof(bool?))); }
public static object Get(ITagAttribute expressions, TagModel model) { return(expressions != null?expressions.Evaluate(model) : null); }
private void HandleBody(ITagAttribute value) { new Reflection(_tag)[TAG_BODY_NAME] = value; }
public static T?GetAs <T>(ITagAttribute expressions, TagModel model) where T : struct { string result = GetAsString(expressions, model); return(result != null ? EnumParser <T> .Parse(result) : default(T?)); }
private static XPathNavigator GuardSingleNode(TagModel model, XPathNodeIterator nodes, ITagAttribute select) { if (nodes.Count > 1) { throw TagException.SingleNodeExpected(GetAsString(select, model)).Decorate(select.Context); } nodes.MoveNext(); return(nodes.Current); }