|
| 1 | +using System; |
| 2 | +using System.Collections.Generic; |
| 3 | +using System.Linq; |
| 4 | +using System.Text; |
| 5 | +using System.Threading.Tasks; |
| 6 | + |
| 7 | +namespace IntentoSDK.Handlers |
| 8 | +{ |
| 9 | + /// <summary> |
| 10 | + /// Xml symbols prepare |
| 11 | + /// </summary> |
| 12 | + internal class XmlSymbolHandler : BaseSymbolHandler |
| 13 | + { |
| 14 | + protected override IReadOnlyDictionary<string, string> SpecialCodesIn => new Dictionary<string, string> |
| 15 | + { |
| 16 | + { "&gt;" , "<tph1/>" }, |
| 17 | + { "&lt;" , "<tph2/>" }, |
| 18 | + { "<" , "<tph3/>" }, |
| 19 | + { ">" , "<tph4/>" } |
| 20 | + }; |
| 21 | + |
| 22 | + protected override IReadOnlyDictionary<string, string> SpecialCodesOut => new Dictionary<string, string> |
| 23 | + { |
| 24 | + { "<tph1>" , "&gt;" }, |
| 25 | + { "<tph2>" , "&lt;" }, |
| 26 | + { "<tph3>" , "<" }, |
| 27 | + { "<tph4>" , ">" }, |
| 28 | + { "<tph1/>", "&gt;" }, |
| 29 | + { "<tph2/>", "&lt;" }, |
| 30 | + { "<tph3/>", "<" }, |
| 31 | + { "<tph4/>", ">" }, |
| 32 | + { "<tph1 />", "&gt;" }, |
| 33 | + { "<tph2 />", "&lt;" }, |
| 34 | + { "<tph3 />", "<" }, |
| 35 | + { "<tph4 />", ">" }, |
| 36 | + { "</tph1>", "" }, |
| 37 | + { "</tph2>", "" }, |
| 38 | + { "</tph3>", "" }, |
| 39 | + { "</tph4>", "" } |
| 40 | + }; |
| 41 | + |
| 42 | + public override string Format => "xml"; |
| 43 | + |
| 44 | + protected override string PrepareResult(string text) |
| 45 | + { |
| 46 | + text = base.PrepareResult(text); |
| 47 | + |
| 48 | + // Remove <? > tag |
| 49 | + int n1 = text.IndexOf("<?"); |
| 50 | + string text2 = text; |
| 51 | + if (n1 != -1) |
| 52 | + { |
| 53 | + int n2 = text.IndexOf(">"); |
| 54 | + text2 = text.Substring(n2 + 1); |
| 55 | + } |
| 56 | + |
| 57 | + // Remove <root> and </root> tags |
| 58 | + string text3 = text2.Replace("<root>", "").Replace("</root>", ""); |
| 59 | + return text3; |
| 60 | + } |
| 61 | + |
| 62 | + protected override string PrepareText(string data) |
| 63 | + { |
| 64 | + data = base.PrepareText(data); |
| 65 | + return string.Format("<root>{0}</root>", data); |
| 66 | + } |
| 67 | + } |
| 68 | +} |
0 commit comments