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;
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<ContentResponse> DecodeAsync(string ContentType, byte[] Data, Encoding Encoding,
83 KeyValuePair<string, string>[] Fields, Uri BaseUri, ICodecProgress Progress)
84 {
85 using (Stream f = new MemoryStream(Data))
86 {
87 using (XmlReader r = XmlReader.Create(f))
88 {
89 XslCompiledTransform Xslt = new XslCompiledTransform();
90 Xslt.Load(r);
91
92 return Task.FromResult(new ContentResponse(ContentType, Xslt, Data));
93 }
94 }
95 }
96
103 public bool TryGetContentType(string FileExtension, out string ContentType)
104 {
105 switch (FileExtension.ToLower())
106 {
107 case "xsl":
108 case "xslt":
109 ContentType = "application/xslt+xml";
110 return true;
111
112 default:
113 ContentType = string.Empty;
114 return false;
115 }
116 }
117
124 public bool TryGetFileExtension(string ContentType, out string FileExtension)
125 {
126 switch (ContentType.ToLower())
127 {
128 case "application/xslt+xml":
129 FileExtension = "xslt";
130 return true;
131
132 default:
133 FileExtension = string.Empty;
134 return false;
135 }
136 }
137
138 }
139}
Contains information about a response to a content request.
bool TryGetContentType(string FileExtension, out string ContentType)
Tries to get the content type of an item, given its file extension.
Definition: XsltDecoder.cs:103
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
string[] FileExtensions
Supported file extensions.
Definition: XsltDecoder.cs:50
Task< ContentResponse > DecodeAsync(string ContentType, byte[] Data, Encoding Encoding, KeyValuePair< string, string >[] Fields, Uri BaseUri, ICodecProgress Progress)
Decodes an object.
Definition: XsltDecoder.cs:82
bool TryGetFileExtension(string ContentType, out string FileExtension)
Tries to get the file extension of an item, given its Content-Type.
Definition: XsltDecoder.cs:124
static readonly string[] XmlContentTypes
XML content types.
Definition: XsltDecoder.cs:27
static readonly string[] XmlFileExtensions
XML file extensions.
Definition: XsltDecoder.cs:36
Interface for reporting progress about an encoding or decoding.
Basic interface for Internet Content decoders. A class implementing this interface and having a defau...
Grade
Grade enumeration
Definition: Grade.cs:7