Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 :
3 : /*
4 : * This file is part of the LibreOffice project.
5 : *
6 : * This Source Code Form is subject to the terms of the Mozilla Public
7 : * License, v. 2.0. If a copy of the MPL was not distributed with this
8 : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 : */
10 :
11 : #ifndef INCLUDED_SAX_TOOLS_DOCUMENTHANDLERADAPTER_HXX
12 : #define INCLUDED_SAX_TOOLS_DOCUMENTHANDLERADAPTER_HXX
13 :
14 : #include <com/sun/star/xml/sax/SAXException.hpp>
15 : #include <com/sun/star/xml/sax/XDocumentHandler.hpp>
16 : #include <com/sun/star/xml/sax/XExtendedDocumentHandler.hpp>
17 :
18 : namespace sax
19 : {
20 : /**
21 : * DocumentHandlerAdapter provides a base class for simple decorators to XDocumentHandlers.
22 : * It forwards all method calls to a delegate. An inheriting class only needs to override the
23 : * methods it actually wants to modify.
24 : *
25 : * See filters/source/odfflatxml/FlatXml.cxx for an example.
26 : */
27 : class DocumentHandlerAdapter : public ::com::sun::star::xml::sax::XDocumentHandler
28 : {
29 : public:
30 : // XDocumentHandler
31 : virtual void SAL_CALL
32 0 : startDocument(void) throw (::com::sun::star::xml::sax::SAXException, ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE
33 : {
34 0 : m_handler->startDocument();
35 0 : }
36 :
37 : virtual void SAL_CALL
38 0 : endDocument(void) throw (::com::sun::star::xml::sax::SAXException, ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE
39 : {
40 0 : m_handler->endDocument();
41 0 : }
42 :
43 : virtual void SAL_CALL
44 0 : startElement(const OUString& aName,
45 : const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XAttributeList > & xAttribs)
46 : throw (::com::sun::star::xml::sax::SAXException, ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE
47 : {
48 0 : m_handler->startElement(aName, xAttribs);
49 0 : }
50 :
51 : virtual void SAL_CALL
52 0 : endElement(const OUString& aName) throw (::com::sun::star::xml::sax::SAXException,
53 : ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE
54 : {
55 0 : m_handler->endElement(aName);
56 0 : }
57 :
58 : virtual void SAL_CALL
59 0 : characters(const OUString& aChars) throw (::com::sun::star::xml::sax::SAXException,
60 : ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE
61 : {
62 0 : m_handler->characters(aChars);
63 0 : }
64 :
65 : virtual void SAL_CALL
66 0 : ignorableWhitespace(const OUString& aWhitespaces) throw (::com::sun::star::xml::sax::SAXException,
67 : ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE
68 : {
69 0 : m_handler->ignorableWhitespace(aWhitespaces);
70 0 : }
71 : virtual void SAL_CALL
72 0 : processingInstruction(const OUString& aTarget, const OUString& aData)
73 : throw (::com::sun::star::xml::sax::SAXException, ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE
74 : {
75 0 : m_handler->processingInstruction(aTarget, aData);
76 0 : }
77 : virtual void SAL_CALL
78 0 : setDocumentLocator(const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XLocator > & xLocator)
79 : throw (::com::sun::star::xml::sax::SAXException, ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE
80 : {
81 0 : m_handler->setDocumentLocator(xLocator);
82 0 : }
83 : DocumentHandlerAdapter(const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XDocumentHandler >& delegate);
84 0 : DocumentHandlerAdapter() :
85 0 : m_handler(::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XDocumentHandler > (0, ::com::sun::star::uno::UNO_QUERY))
86 : {
87 0 : }
88 : ;
89 :
90 : protected:
91 : virtual void SAL_CALL
92 0 : setDelegate(const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XDocumentHandler >& delegate)
93 : {
94 0 : m_handler = delegate;
95 0 : }
96 : virtual ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XDocumentHandler > SAL_CALL
97 0 : getDelegate()
98 : {
99 0 : return m_handler;
100 : }
101 : virtual
102 0 : ~DocumentHandlerAdapter()
103 0 : {
104 :
105 0 : }
106 :
107 : private:
108 : ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XDocumentHandler > m_handler;
109 :
110 : };
111 :
112 : /**
113 : * ExtendedDocumentHandlerAdapter provides a base class for simple decorators to XExtendedDocumentHandlers.
114 : * It forwards all method calls to a delegate. An inheriting class only needs to override the
115 : * methods it actually wants to modify.
116 : */
117 : class ExtendedDocumentHandlerAdapter : public ::com::sun::star::xml::sax::XExtendedDocumentHandler
118 :
119 : {
120 :
121 : public:
122 : // XDocumentHandler
123 : virtual void SAL_CALL
124 0 : startDocument(void) throw (::com::sun::star::xml::sax::SAXException, ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE
125 : {
126 0 : m_handler->startDocument();
127 0 : }
128 :
129 : virtual void SAL_CALL
130 0 : endDocument(void) throw (::com::sun::star::xml::sax::SAXException, ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE
131 : {
132 0 : m_handler->endDocument();
133 0 : }
134 :
135 : virtual void SAL_CALL
136 0 : startElement(const OUString& aName,
137 : const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XAttributeList > & xAttribs)
138 : throw (::com::sun::star::xml::sax::SAXException, ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE
139 : {
140 0 : m_handler->startElement(aName, xAttribs);
141 0 : }
142 :
143 : virtual void SAL_CALL
144 0 : endElement(const OUString& aName) throw (::com::sun::star::xml::sax::SAXException,
145 : ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE
146 : {
147 0 : m_handler->endElement(aName);
148 0 : }
149 :
150 : virtual void SAL_CALL
151 0 : characters(const OUString& aChars) throw (::com::sun::star::xml::sax::SAXException,
152 : ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE
153 : {
154 0 : m_handler->characters(aChars);
155 0 : }
156 :
157 : virtual void SAL_CALL
158 0 : ignorableWhitespace(const OUString& aWhitespaces) throw (::com::sun::star::xml::sax::SAXException,
159 : ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE
160 : {
161 0 : m_handler->ignorableWhitespace(aWhitespaces);
162 0 : }
163 : virtual void SAL_CALL
164 0 : processingInstruction(const OUString& aTarget, const OUString& aData)
165 : throw (::com::sun::star::xml::sax::SAXException, ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE
166 : {
167 0 : m_handler->processingInstruction(aTarget, aData);
168 0 : }
169 : virtual void SAL_CALL
170 0 : setDocumentLocator(const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XLocator > & xLocator)
171 : throw (::com::sun::star::xml::sax::SAXException, ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE
172 : {
173 0 : m_handler->setDocumentLocator(xLocator);
174 0 : }
175 : // XExtendedDocumentHandler
176 : virtual void SAL_CALL
177 0 : startCDATA(void) throw (::com::sun::star::xml::sax::SAXException, ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE
178 : {
179 0 : m_handler->startCDATA();
180 0 : }
181 : virtual void SAL_CALL
182 0 : endCDATA(void) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE
183 : {
184 0 : m_handler->endCDATA();
185 0 : }
186 : virtual void SAL_CALL
187 0 : comment(const OUString& sComment) throw (::com::sun::star::xml::sax::SAXException,
188 : ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE
189 : {
190 0 : m_handler->comment(sComment);
191 0 : }
192 : virtual void SAL_CALL
193 0 : unknown(const OUString& sString) throw (::com::sun::star::xml::sax::SAXException, ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE
194 : {
195 0 : m_handler->unknown(sString);
196 0 : }
197 : virtual void SAL_CALL
198 0 : allowLineBreak(void) throw (::com::sun::star::xml::sax::SAXException, ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE
199 : {
200 0 : m_handler->allowLineBreak();
201 0 : }
202 : protected:
203 0 : ExtendedDocumentHandlerAdapter() :
204 0 : m_handler(::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XExtendedDocumentHandler > (0, ::com::sun::star::uno::UNO_QUERY))
205 : {
206 0 : }
207 : ExtendedDocumentHandlerAdapter(
208 : const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XExtendedDocumentHandler > delegate) :
209 : m_handler(delegate)
210 : {
211 : }
212 :
213 : virtual void SAL_CALL
214 0 : setDelegate(const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XExtendedDocumentHandler >& delegate)
215 : {
216 0 : m_handler = delegate;
217 0 : }
218 : virtual ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XExtendedDocumentHandler > SAL_CALL
219 0 : getDelegate()
220 : {
221 0 : return m_handler;
222 : }
223 : virtual
224 0 : ~ExtendedDocumentHandlerAdapter()
225 0 : {
226 :
227 0 : }
228 :
229 : private:
230 : ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XExtendedDocumentHandler > m_handler;
231 : };
232 : }
233 : #endif // INCLUDED_SAX_TOOLS_DOCUMENTHANDLERADAPTER_HXX
234 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|