protected void ParseChildNode(HtmlNode htmlNode, XElement resultElement, ParseContext parseContext, XElement baseFormattingElement) { if (parseContext.ParseDefinitions.IsEscapedNode(htmlNode)) { return; } ParseDefinition definition = parseContext.ParseDefinitions[htmlNode]; if (definition != null) { Type typeInfo = ReflectionUtil.GetTypeInfo(definition.HtmlParserType); if (typeInfo.Name == "CustomHtmlNodeParser") { var customParser = CustomHtmlParseHelper.GetParser <CustomHtmlNodeParser>(definition); if (customParser == null) { return; } customParser.SpecialCharacterMapper = SpecialCharacterMapper; customParser.ParseNode(htmlNode, resultElement, parseContext, baseFormattingElement); } else { object parser = CustomHtmlParseHelper.GetParser <HtmlNodeParser>(definition); ((HtmlNodeParser)parser)?.ParseNode(htmlNode, resultElement, parseContext, baseFormattingElement); } } else if (HtmlParseHelper.IsPlainTextNode(htmlNode)) { XCData xcData = new XCData(HtmlEntityHelper.DeEntitize(htmlNode.InnerHtml)); if (SpecialCharacterMapper != null) { SpecialCharacterMapper.ParseSpecialCharacters(xcData.Value, baseFormattingElement, ref resultElement); return; } if (baseFormattingElement != null) { XElement xelement = new XElement(baseFormattingElement); xelement.Add((object)xcData); resultElement.Add((object)xelement); } else { resultElement.Add(xcData); } } else { XElement formattingElement = StyleParser.GetFormattingElement(htmlNode, baseFormattingElement, true); this.ParseChildNodes(htmlNode, resultElement, parseContext, formattingElement); } }
protected virtual XElement CreateElement(HtmlNode htmlNode, ParseDefinition definition) { if (definition == null || !HtmlParseHelper.IsValidTargetTag(definition.XmlTag)) { return((XElement)null); } XElement element = new XElement((XName)definition.XmlTag); this.SetAttributes(element, htmlNode, definition); return(element); }
public static T GetParser <T>(ParseDefinition definition) { if (!string.IsNullOrEmpty(definition.HtmlParserType)) { try { Type typeInfo = ReflectionUtil.GetTypeInfo(definition.HtmlParserType); return(typeInfo != (Type)null ? (T)ReflectionUtil.CreateObject(typeInfo) : default(T)); } catch (Exception ex) { Logger.Error(ex.Message, (Exception)null); } } return(default(T)); }
public static CustomHtmlNodeParser GetParser2(ParseDefinition definition) { if (!string.IsNullOrEmpty(definition.HtmlParserType)) { try { Type typeInfo = ReflectionUtil.GetTypeInfo(definition.HtmlParserType); return(typeInfo != (Type)null ? ReflectionUtil.CreateObject(typeInfo) as CustomHtmlNodeParser : (CustomHtmlNodeParser)null); } catch (Exception ex) { Logger.Error(ex.Message, (Exception)null); } } return((CustomHtmlNodeParser)null); }
protected virtual XElement CreateImageElement(HtmlNode htmlNode, Item mediaContentItem, ParseContext parseContext, string width, string height) { XElement xelement = RenderItemHelper.CreateXElement("Image", ((TemplateItem)parseContext.Database.GetItem(WebConfigHandler.PrintStudioEngineSettings.EngineTemplates + "P_Image")).StandardValues, parseContext.PrintOptions.IsClient, (Item)null); ParseDefinition definition = parseContext.ParseDefinitions[htmlNode]; if (definition != null) { this.SetAttributes(xelement, htmlNode, definition); } xelement.SetAttributeValue((XName)"Height", (object)height); xelement.SetAttributeValue((XName)"Width", (object)width); xelement.SetAttributeValue((XName)"SitecoreMediaID", (object)mediaContentItem.ID.Guid.ToString()); string imageOnServer = ImageRendering.CreateImageOnServer(parseContext.PrintOptions, (MediaItem)mediaContentItem); string str = parseContext.PrintOptions.FormatResourceLink(imageOnServer); xelement.SetAttributeValue((XName)"LowResSrc", (object)str); xelement.SetAttributeValue((XName)"HighResSrc", (object)str); return(xelement); }
protected virtual XElement CreateImageElement(HtmlNode htmlNode, Item mediaContentItem, ParseContext parseContext, string width, string height) { Item item = parseContext.Database.GetItem(WebConfigHandler.PrintStudioEngineSettings.EngineTemplates + "P_Image"); Item standardValues = item.Template.StandardValues; XElement xElement = RenderItemHelper.CreateXElement("Image", standardValues, parseContext.PrintOptions.IsClient, null); ParseDefinition parseDefinition = parseContext.ParseDefinitions[htmlNode]; if (parseDefinition != null) { this.SetAttributes(xElement, htmlNode, parseDefinition); } xElement.SetAttributeValue("Height", height); xElement.SetAttributeValue("Width", width); xElement.SetAttributeValue("SitecoreMediaID", mediaContentItem.ID.Guid.ToString()); string text = ImageRendering.CreateImageOnServer(parseContext.PrintOptions, mediaContentItem); text = parseContext.PrintOptions.FormatResourceLink(text); xElement.SetAttributeValue("LowResSrc", text); xElement.SetAttributeValue("HighResSrc", text); return(xElement); }
protected virtual void SetAttributes(XElement element, HtmlNode htmlNode, ParseDefinition definition) { List <ParseAttribute> applicableAttributes = definition.FindApplicableAttributes(htmlNode); HtmlAttributeCollection attributes = htmlNode.Attributes; foreach (ParseAttribute parseAttribute in applicableAttributes) { try { if (!string.IsNullOrEmpty(parseAttribute.XmlAttribute)) { string attributeValue = string.Empty; if (!string.IsNullOrEmpty(parseAttribute.HtmlAttribute) && attributes != null && attributes.Contains(parseAttribute.HtmlAttribute)) { attributeValue = attributes[parseAttribute.HtmlAttribute].Value; if (attributeValue.Equals(parseAttribute.HtmlDefaultValue)) { attributeValue = parseAttribute.XmlDefaultValue; } else if (parseAttribute.HtmlAttribute.Equals("width", StringComparison.InvariantCultureIgnoreCase) || parseAttribute.HtmlAttribute.Equals("height", StringComparison.InvariantCultureIgnoreCase)) { attributeValue = HtmlParseHelper.ParseDimensionValue(attributeValue, true); } } if (string.IsNullOrEmpty(attributeValue)) { attributeValue = parseAttribute.XmlDefaultValue; } element.SetAttributeValue((XName)parseAttribute.XmlAttribute, (object)attributeValue); } } catch (Exception ex) { Logger.Error("ParseAttributes", ex); } } }