1 // SPDX-License-Identifier: GPL-2.0-or-later
2 #ifndef SEEN_INKSCAPE_IO_XSLTSTREAM_H
3 #define SEEN_INKSCAPE_IO_XSLTSTREAM_H
4 /**
5  * @file
6  * Xslt-enabled input and output streams.
7  */
8 /*
9  * Authors:
10  *   Bob Jamison <ishmalius@gmail.com>
11  *
12  * Copyright (C) 2004-2008 Inkscape.org
13  *
14  * Released under GNU GPL v2+, read the file 'COPYING' for more information.
15  */
16 
17 
18 #include "inkscapestream.h"
19 
20 #include <libxslt/xslt.h>
21 #include <libxslt/xsltInternals.h>
22 
23 
24 namespace Inkscape
25 {
26 namespace IO
27 {
28 
29 //#########################################################################
30 //# X S L T    S T Y L E S H E E T
31 //#########################################################################
32 /**
33  * This is a container for reusing a loaded stylesheet
34  */
35 class XsltStyleSheet
36 {
37 
38 public:
39 
40     /**
41      * Constructor with loading
42      */
43     XsltStyleSheet(InputStream &source);
44 
45     /**
46      * Simple constructor, no loading
47      */
48     XsltStyleSheet();
49 
50     /**
51      * Loader
52      */
53     bool read(InputStream &source);
54 
55     /**
56      * Destructor
57      */
58     virtual ~XsltStyleSheet();
59 
60     xsltStylesheetPtr stylesheet;
61 
62 
63 }; // class XsltStyleSheet
64 
65 
66 //#########################################################################
67 //# X S L T    I N P U T    S T R E A M
68 //#########################################################################
69 
70 /**
71  * This class is for transforming stream input by a given stylesheet
72  */
73 class XsltInputStream : public BasicInputStream
74 {
75 
76 public:
77 
78     XsltInputStream(InputStream &xmlSource, XsltStyleSheet &stylesheet);
79 
80     ~XsltInputStream() override;
81 
82     int available() override;
83 
84     void close() override;
85 
86     int get() override;
87 
88 
89 private:
90 
91     XsltStyleSheet &stylesheet;
92 
93     xmlChar *outbuf;
94     int outsize;
95     int outpos;
96 
97 }; // class XsltInputStream
98 
99 
100 
101 
102 //#########################################################################
103 //# X S L T    O U T P U T    S T R E A M
104 //#########################################################################
105 
106 /**
107  * This class is for transforming stream output by a given stylesheet
108  */
109 class XsltOutputStream : public BasicOutputStream
110 {
111 
112 public:
113 
114     XsltOutputStream(OutputStream &destination, XsltStyleSheet &stylesheet);
115 
116     ~XsltOutputStream() override;
117 
118     void close() override;
119 
120     void flush() override;
121 
122     int put(char ch) override;
123 
124 private:
125 
126     XsltStyleSheet &stylesheet;
127 
128     Glib::ustring outbuf;
129 
130     bool flushed;
131 
132 }; // class XsltOutputStream
133 
134 
135 
136 } // namespace IO
137 } // namespace Inkscape
138 
139 
140 #endif /* __INKSCAPE_IO_XSLTSTREAM_H__ */
141