Mercurial > repos > IBDev-IBBoard.WarFoundry.API
comparison API/Exporters/WarFoundryXMLWithXSLExporter.cs @ 497:cd367acd7c48
Re #419: Remove assumptions of a file-based install
* Swap XSLTs to resources
* Update XSL Exporter to use Streams, not files
author | IBBoard <dev@ibboard.co.uk> |
---|---|
date | Wed, 28 Nov 2012 20:24:36 +0000 |
parents | 71fceea2725b |
children |
comparison
equal
deleted
inserted
replaced
496:00d6cf940c3c | 497:cd367acd7c48 |
---|---|
12 using System.Xml.Schema; | 12 using System.Xml.Schema; |
13 using IBBoard.Lang; | 13 using IBBoard.Lang; |
14 using IBBoard.Xml; | 14 using IBBoard.Xml; |
15 using IBBoard.WarFoundry.API.Objects; | 15 using IBBoard.WarFoundry.API.Objects; |
16 using IBBoard.WarFoundry.API.Util; | 16 using IBBoard.WarFoundry.API.Util; |
17 using System.Reflection; | |
18 using IBBoard.IO; | |
17 | 19 |
18 namespace IBBoard.WarFoundry.API.Exporters | 20 namespace IBBoard.WarFoundry.API.Exporters |
19 { | 21 { |
20 /// <summary> | 22 /// <summary> |
21 /// Custom exporter that exports an army as an XML file with an XSLT applied | 23 /// Custom exporter that exports an army as an XML file with an XSLT applied |
38 private WarFoundryXmlWithXslExporter() | 40 private WarFoundryXmlWithXslExporter() |
39 { | 41 { |
40 // Hide constructor | 42 // Hide constructor |
41 } | 43 } |
42 | 44 |
45 public NamedStream[] GetXsltStreams() { | |
46 Assembly assm = GetType().Assembly; | |
47 NamedStream[] streams = new NamedStream[2]; | |
48 streams[0] = new NamedStream("Default Roster", assm.GetManifestResourceStream("IBBoard.WarFoundry.API.xsl.default_html.xsl")); | |
49 streams[1] = new NamedStream("Unit Cards", assm.GetManifestResourceStream("IBBoard.WarFoundry.API.xsl.unitcard.xsl")); | |
50 return streams; | |
51 } | |
52 | |
43 // Write to file | 53 // Write to file |
44 public void ExportArmy(Army army, string path) | 54 public void ExportArmy(Army army, string path) |
45 { | 55 { |
46 XmlDocument xmlDoc = BuildXml(army); | 56 XmlDocument xmlDoc = BuildXml(army); |
47 // Simple XML output settings | 57 // Simple XML output settings |
57 writer.Close(); | 67 writer.Close(); |
58 } | 68 } |
59 } | 69 } |
60 | 70 |
61 // Write to file with transform | 71 // Write to file with transform |
62 public void ExportArmyWithTransform(Army army, string savePath, string xslPath) | 72 public void ExportArmyWithTransform(Army army, string savePath, Stream xslStream) |
63 { | 73 { |
64 XmlDocument xmlDoc = BuildXml(army); | 74 XmlDocument xmlDoc = BuildXml(army); |
65 XslCompiledTransform xslTransform = new XslCompiledTransform(); | 75 XslCompiledTransform xslTransform = new XslCompiledTransform(); |
66 | 76 |
67 xslTransform.Load(xslPath); | 77 xslTransform.Load(new XmlTextReader(xslStream)); |
68 XmlWriter writer = XmlWriter.Create(savePath, xslTransform.OutputSettings); | 78 XmlWriter writer = XmlWriter.Create(savePath, xslTransform.OutputSettings); |
69 xslTransform.Transform(xmlDoc, writer); | 79 xslTransform.Transform(xmlDoc, writer); |
70 writer.Flush(); | 80 writer.Flush(); |
71 writer.Close(); | 81 writer.Close(); |
72 } | 82 } |