public static XhtmlDocument GetRenderingLayout(string formName) { if (HasCustomRenderingLayout(formName)) { var key = GetKey(formName); var layout = Localization.T(key); return(XhtmlDocument.Parse(layout)); } var model = ModelsFacade.GetModel(formName); if (model == null) { throw new ArgumentException($"Form '{formName}' not loaded"); } var doc = new XhtmlDocument(); foreach (var field in model.Fields.Where(f => f.Label != null)) { doc.Body.Add(new XElement(Namespaces.Xhtml + "p", $"%{field.Name}%")); } return(doc); }
public override void ExecutePageHierarchy() { if (RequestContext.IsSuccess) { HandleSubmit(); } if (IntroText == null) { var value = Localization.EvaluateT(Form.Model, "IntroText", null); if (value != null) { try { IntroText = XhtmlDocument.Parse(value); } catch { } } } if (SuccessResponse == null) { var value = Localization.EvaluateT(Form.Model, "SuccessResponse", null); if (value != null) { try { SuccessResponse = XhtmlDocument.Parse(value); } catch { } } } base.ExecutePageHierarchy(); }
public override void OnFinish(object sender, EventArgs e) { var formToken = (IModelReference)((DataEntityToken)EntityToken).Data; var renderingMarkup = GetBinding <string>("RenderingMarkup"); RenderingLayoutFacade.SaveRenderingLayout(formToken.Name, XhtmlDocument.Parse(renderingMarkup)); SetSaveStatus(true); }
private object ExecuteChildAction(Dictionary <string, object> routeValues, ViewContext viewContext) { routeValues.Add("PageModel", viewContext.ViewData.Model); var htmlHelper = (viewContext.TempData["HtmlHelper"] as HtmlHelper) ?? new HtmlHelper(viewContext, new ViewPage()); var functionParameters = new RouteValueDictionary(routeValues); var html = htmlHelper.Action("Index", _controllerDescriptor.ControllerName, functionParameters); return(XhtmlDocument.Parse(html.ToString())); }
/// <summary> /// Cleans HTML documents or fragments into XHTML conformant markup /// </summary> /// <param name="xmlMarkup">The html to clean</param> /// <returns></returns> public static XDocument TidyXml(string xmlMarkup) { try { return(XhtmlDocument.Parse(xmlMarkup)); } catch (Exception) { // take the slow road below... } byte[] xmlByteArray = Encoding.UTF8.GetBytes(xmlMarkup); Tidy tidy = GetXmlConfiguredTidy(); List <string> namespacePrefixedElementNames = LocateNamespacePrefixedElementNames(xmlMarkup); AllowNamespacePrefixedElementNames(tidy, namespacePrefixedElementNames); AllowHtml5ElementNames(tidy); TidyMessageCollection tidyMessages = new TidyMessageCollection(); string xml = ""; using (MemoryStream inputStream = new MemoryStream(xmlByteArray)) { using (MemoryStream outputStream = new MemoryStream()) { tidy.Parse(inputStream, outputStream, tidyMessages); outputStream.Position = 0; C1StreamReader sr = new C1StreamReader(outputStream); xml = sr.ReadToEnd(); } } if (tidyMessages.Errors > 0) { StringBuilder errorMessageBuilder = new StringBuilder(); foreach (TidyMessage message in tidyMessages) { if (message.Level == MessageLevel.Error) { errorMessageBuilder.AppendLine(message.ToString()); } } throw new InvalidOperationException(string.Format("Failed to parse html:\n\n{0}", errorMessageBuilder.ToString())); } xml = RemoveDuplicateAttributes(xml); return(XDocument.Parse(xml)); }
public static bool HasCustomRenderingLayout(string formName) { var key = GetKey(formName); var layout = Localization.T(key); if (layout == null) { return(false); } var xhtml = XhtmlDocument.Parse(layout); return(!xhtml.IsEmpty); }
/// <summary> /// Crawls xhtml content and extracts text parts /// </summary> /// <param name="xhtml"></param> public bool CrawlXhtml(string xhtml) { try { var doc = XhtmlDocument.Parse(xhtml); CrawlXhtml(doc); return(true); } catch (Exception ex) { Log.LogError(nameof(XhtmlCrawlingHelper), ex); return(false); } }
/// <exclude /> public static XhtmlDocument ParsePlaceholderContent(IPagePlaceholderContent placeholderContent) { if (string.IsNullOrEmpty(placeholderContent?.Content)) { return(new XhtmlDocument()); } if (placeholderContent.Content.StartsWith("<html")) { try { return(XhtmlDocument.Parse(placeholderContent.Content)); } catch (Exception) { } } return(XhtmlDocument.Parse($"<html xmlns='{Namespaces.Xhtml}'><head/><body>{placeholderContent.Content}</body></html>")); }
public static XhtmlDocument ParseContent(string content) { if (String.IsNullOrEmpty(content)) { return(new XhtmlDocument()); } if (content.StartsWith("<html")) { try { return(XhtmlDocument.Parse(content)); } catch (Exception) { } } return(XhtmlDocument.Parse("<html xmlns='{0}'><head/><body>{1}</body></html>".FormatWith(new object[] { Namespaces.Xhtml, content }))); }
/// <exclude /> protected override void CreateChildControls() { DataBind(); if (InnerContent == null) { var renderingInfo = MasterPagePageRenderer.GetRenderingInfo(this.Page); string placeholderId = PlaceholderID ?? ID; if (placeholderId != null) { var content = renderingInfo.Contents.SingleOrDefault(c => c.PlaceHolderId == placeholderId); if (content == null) { InnerContent = new XElement(Namespaces.Xhtml + "html", new XAttribute(XNamespace.Xmlns + "f", Namespaces.Function10), new XAttribute(XNamespace.Xmlns + "lang", LocalizationXmlConstants.XmlNamespace), new XElement(Namespaces.Xhtml + "head"), new XElement(Namespaces.Xhtml + "body")); } else { if (content.Content.StartsWith("<html")) { try { InnerContent = XhtmlDocument.Parse(content.Content).Root; } catch (ArgumentException) { } } else { InnerContent = new XElement(Namespaces.Xhtml + "html", new XAttribute(XNamespace.Xmlns + "f", Namespaces.Function10), new XElement(Namespaces.Xhtml + "head"), new XElement(Namespaces.Xhtml + "body", XElement.Parse(content.Content))); } } } } base.CreateChildControls(); }
private void Initialize() { if (_templateDocument == null) { lock (_lock) { if (_templateDocument == null) { Type interfaceType = TypeManager.GetType(_visualFunction.TypeManagerName); _typeDescriptor = DynamicTypeManager.GetDataTypeDescriptor(interfaceType); if (_typeDescriptor == null) { throw new InvalidOperationException(string.Format("DataTypeDescriptor not found for type '{0}'", interfaceType)); } _templateDocument = XhtmlDocument.Parse(_visualFunction.XhtmlTemplate); } } } }
protected BaseFormFunction(IModel form) { var functionName = form.Name; if (!functionName.StartsWith("Forms.")) { functionName = "Forms." + functionName; } var parts = functionName.Split(new[] { '.' }, StringSplitOptions.RemoveEmptyEntries); Namespace = String.Join(".", parts.Take(parts.Length - 1)); Name = parts.Skip(parts.Length - 1).Take(1).Single(); if (_intoText == null) { var value = Localization.EvaluateT(form, "IntroText", null); if (value != null) { try { _intoText = XhtmlDocument.Parse(value); } catch { } } } if (_successResponse == null) { var value = Localization.EvaluateT(form, "SuccessResponse", null); if (value != null) { try { _successResponse = XhtmlDocument.Parse(value); } catch { } } } }
protected void Page_Load(object sender, EventArgs e) { string fieldKey = "SomeKeyHere"; string xhtmlString; using (var connection = new DataConnection()) { xhtmlString = connection.Get <Maw.Content>().Where(f => f.FieldKey == fieldKey).Select(f => f.FieldContent).FirstOrDefault(); } if (xhtmlString != null) { XhtmlDocument htmlDoc = XhtmlDocument.Parse(xhtmlString); foreach (XElement bodyElement in htmlDoc.Body.Elements()) { this.Controls.Add(new LiteralControl(bodyElement.ToString())); } } else { this.Controls.Add(new LiteralControl("Unknown FieldKey: " + fieldKey)); } }
private void IsMarkupValid(object sender, System.Workflow.Activities.ConditionalEventArgs e) { PageTemplateFeatureEntityToken castedEntityToken = (PageTemplateFeatureEntityToken)this.EntityToken; string content = this.GetBinding <string>("Markup"); this.UpdateBinding("Errors", ""); XhtmlDocument document = null; try { document = XhtmlDocument.Parse(content); } catch (Exception ex) { this.UpdateBinding("Errors", ex.Message); e.Result = false; return; } e.Result = true; }
/// <summary> /// Cleans HTML documents or fragments into XHTML conformant markup /// </summary> /// <param name="xmlMarkup">The html to clean</param> /// <returns></returns> public static XDocument TidyXml(string xmlMarkup) { try { return(XhtmlDocument.Parse(xmlMarkup)); } catch (Exception) { // take the slow road below... } Tidy tidy = GetXmlConfiguredTidy(); List <string> namespacePrefixedElementNames = LocateNamespacePrefixedElementNames(xmlMarkup); AllowNamespacePrefixedElementNames(tidy, namespacePrefixedElementNames); AllowHtml5ElementNames(tidy); string xml = ParseMarkup(xmlMarkup, tidy, out TidyMessageCollection _); xml = RemoveDuplicateAttributes(xml); return(XDocument.Parse(xml)); }
private object ExecuteDirectRoute(Dictionary <string, object> routeValues) { var routeData = new RouteData { RouteHandler = new MvcRouteHandler() }; routeData.Values["action"] = "Index"; routeData.Values["controller"] = _controllerDescriptor.ControllerName; foreach (var routeValue in routeValues) { routeData.Values.Add(routeValue.Key, routeValue.Value); } string html; using (var writer = new StringWriter()) { var httpResponse = new HttpResponse(writer); var httpContext = new HttpContext(HttpContext.Current.Request, httpResponse); var requestContext = new RequestContext(new HttpContextWrapper(httpContext), routeData); var handler = routeData.RouteHandler.GetHttpHandler(requestContext); if (handler == null) { throw new InvalidOperationException(String.Format("No handler found for the function '{0}'", Namespace + "." + Name)); } handler.ProcessRequest(httpContext); html = writer.ToString(); } return(XhtmlDocument.Parse(html)); }
private static object TryConvertStringValue(string stringValue, Type targetType, ref Exception conversionError) { if (targetType == typeof(Type)) { return(stringValue != string.Empty ? TypeManager.GetType(stringValue) : null); } if (targetType == typeof(XhtmlDocument)) { if (stringValue == string.Empty) { return(new XhtmlDocument()); } return(XhtmlDocument.Parse(stringValue)); } if (targetType == typeof(XDocument)) { return(XDocument.Parse(stringValue)); } if (targetType == typeof(XElement)) { return(XElement.Parse(stringValue)); } if (targetType == typeof(IEnumerable <XNode>)) { try { XElement wrapper = XElement.Parse(string.Format("<wrapper>{0}</wrapper>", stringValue)); return(wrapper.Nodes()); } catch { throw new InvalidCastException(string.Format("Unable to convert string '{0}' to a list of XNodes.", stringValue)); } } if (targetType == typeof(IEnumerable <XElement>)) { try { XElement wrapper = XElement.Parse(string.Format("<wrapper>{0}</wrapper>", stringValue)); return(wrapper.Elements()); } catch { throw new InvalidCastException(string.Format("Unable to convert string '{0}' to a list of XElements.", stringValue)); } } if (targetType == typeof(XNamespace)) { return(XNamespace.Get(stringValue)); } if (targetType.IsGenericType && targetType.GetGenericTypeDefinition() == typeof(Nullable <>)) { Type valueType = targetType.GetGenericArguments()[0]; if (IsOneOfTheHandledValueTypes(valueType)) { if (stringValue.Trim().Length == 0) { return(null); } return(TryConvertValueType(stringValue, valueType, out conversionError)); } } if (IsOneOfTheHandledValueTypes(targetType)) { return(TryConvertValueType(stringValue, targetType, out conversionError)); } TypeConverter tc = TypeDescriptor.GetConverter(targetType); CultureInfo culture = LocalizationScopeManager.CurrentLocalizationScope; object convertedResult = tc.ConvertFromString(null, culture, stringValue); if (convertedResult == null && !string.IsNullOrEmpty(stringValue)) { throw new InvalidOperationException(string.Format("Unable to convert string value '{0}' to type '{1}'", stringValue, targetType.FullName)); } return(convertedResult); }