Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
XsltDecoder.cs
1using System;
2using System.Collections.Generic;
3using System.IO;
4using System.Text;
5using System.Threading.Tasks;
6using System.Xml;
7using System.Xml.Xsl;
9
11{
16 {
20 public XsltDecoder()
21 {
22 }
23
27 public static readonly string[] XmlContentTypes = new string[]
28 {
29 "text/xsl",
30 "application/xslt+xml"
31 };
32
36 public static readonly string[] XmlFileExtensions = new string[]
37 {
38 "xsl",
39 "xslt"
40 };
41
45 public string[] ContentTypes => XmlContentTypes;
46
51
58 public bool Decodes(string ContentType, out Grade Grade)
59 {
60 if (Array.IndexOf(XmlContentTypes, ContentType) >= 0)
61 {
62 Grade = Grade.Excellent;
63 return true;
64 }
65 else
66 {
67 Grade = Grade.NotAtAll;
68 return false;
69 }
70 }
71
82 public Task<object> DecodeAsync(string ContentType, byte[] Data, Encoding Encoding, KeyValuePair<string, string>[] Fields, Uri BaseUri)
83 {
84 using (Stream f = new MemoryStream(Data))
85 {
86 using (XmlReader r = XmlReader.Create(f))
87 {
88 XslCompiledTransform Xslt = new XslCompiledTransform();
89 Xslt.Load(r);
90
91 return Task.FromResult<object>(Xslt);
92 }
93 }
94 }
95
102 public bool TryGetContentType(string FileExtension, out string ContentType)
103 {
104 switch (FileExtension.ToLower())
105 {
106 case "xsl":
107 case "xslt":
108 ContentType = "application/xslt+xml";
109 return true;
110
111 default:
112 ContentType = string.Empty;
113 return false;
114 }
115 }
116
123 public bool TryGetFileExtension(string ContentType, out string FileExtension)
124 {
125 switch (ContentType.ToLower())
126 {
127 case "application/xslt+xml":
128 FileExtension = "xslt";
129 return true;
130
131 default:
132 FileExtension = string.Empty;
133 return false;
134 }
135 }
136
137 }
138}
bool TryGetContentType(string FileExtension, out string ContentType)
Tries to get the content type of an item, given its file extension.
Definition: XsltDecoder.cs:102
static readonly string[] XmlContentTypes
XML content types.
Definition: XsltDecoder.cs:27
string[] FileExtensions
Supported file extensions.
Definition: XsltDecoder.cs:50
Task< object > DecodeAsync(string ContentType, byte[] Data, Encoding Encoding, KeyValuePair< string, string >[] Fields, Uri BaseUri)
Decodes an object.
Definition: XsltDecoder.cs:82
string[] ContentTypes
Supported content types.
Definition: XsltDecoder.cs:45
bool Decodes(string ContentType, out Grade Grade)
If the decoder decodes an object with a given content type.
Definition: XsltDecoder.cs:58
bool TryGetFileExtension(string ContentType, out string FileExtension)
Tries to get the file extension of an item, given its Content-Type.
Definition: XsltDecoder.cs:123
static readonly string[] XmlFileExtensions
XML file extensions.
Definition: XsltDecoder.cs:36
Basic interface for Internet Content decoders. A class implementing this interface and having a defau...
Grade
Grade enumeration
Definition: Grade.cs:7