LibreOffice Module oox (master) 1
contexthandler2.hxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 */
19
20#ifndef INCLUDED_OOX_CORE_CONTEXTHANDLER2_HXX
21#define INCLUDED_OOX_CORE_CONTEXTHANDLER2_HXX
22
23#include <cstddef>
24#include <memory>
25#include <vector>
26
27#include <com/sun/star/uno/Reference.hxx>
29#include <oox/dllapi.h>
30#include <rtl/ustring.hxx>
31#include <sal/types.h>
32
33namespace com::sun::star {
34 namespace xml::sax { class XFastAttributeList; }
35 namespace xml::sax { class XFastContextHandler; }
36}
37
38namespace oox {
39 class AttributeList;
40 class SequenceInputStream;
41}
42
43namespace oox::core {
44
46
47struct ElementInfo;
48
73{
74public:
75 explicit ContextHandler2Helper( bool bEnableTrimSpace, XmlFilterBase& rFilter );
76 explicit ContextHandler2Helper( const ContextHandler2Helper& rParent );
77 virtual ~ContextHandler2Helper();
78
79 // allow instances to be stored in ::rtl::Reference
80 virtual void SAL_CALL acquire() noexcept = 0;
81 virtual void SAL_CALL release() noexcept = 0;
82
83 // interface --------------------------------------------------------------
84
90 virtual ContextHandlerRef onCreateContext( sal_Int32 nElement, const AttributeList& rAttribs ) = 0;
91
101 virtual void onStartElement( const AttributeList& rAttribs ) = 0;
102
114 virtual void onCharacters( const OUString& rChars ) = 0;
115
121 virtual void onEndElement() = 0;
122
128 virtual ContextHandlerRef onCreateRecordContext( sal_Int32 nRecId, SequenceInputStream& rStrm ) = 0;
129
136 virtual void onStartRecord( SequenceInputStream& rStrm ) = 0;
137
143 virtual void onEndRecord() = 0;
144
145 // helpers ----------------------------------------------------------------
146
148 sal_Int32 getCurrentElement() const;
149
151 sal_Int32 getCurrentElementWithMce() const;
152
155 bool isCurrentElement( sal_Int32 nElement ) const
156 { return getCurrentElement() == nElement; }
157
160 bool isCurrentElement( sal_Int32 nElement1, sal_Int32 nElement2 ) const
161 { return isCurrentElement( nElement1 ) || isCurrentElement( nElement2 ); }
162
164 sal_Int32 getParentElement( sal_Int32 nCountBack = 1 ) const;
165
168 bool isParentElement( sal_Int32 nElement, sal_Int32 nCountBack = 1 ) const
169 { return getParentElement( nCountBack ) == nElement; }
170
173 bool isRootElement() const;
174
175 // implementation ---------------------------------------------------------
176
177protected:
179 css::uno::Reference< css::xml::sax::XFastContextHandler >
180 implCreateChildContext(
181 sal_Int32 nElement,
182 const css::uno::Reference< css::xml::sax::XFastAttributeList >& rxAttribs );
183
185 void implStartElement(
186 sal_Int32 nElement,
187 const css::uno::Reference< css::xml::sax::XFastAttributeList >& rxAttribs );
188
190 void implCharacters( std::u16string_view rChars );
191
193 void implEndElement( sal_Int32 nElement );
194
196 ContextHandlerRef implCreateRecordContext( sal_Int32 nRecId, SequenceInputStream& rStrm );
197
199 void implStartRecord( sal_Int32 nRecId, SequenceInputStream& rStrm );
200
202 void implEndRecord( sal_Int32 nRecId );
203
204 bool prepareMceContext( sal_Int32 nElement, const AttributeList& rAttribs );
206
207 enum class MCE_STATE
208 {
209 Started,
210 FoundChoice
211 };
212
213 MCE_STATE getMCEState() const { return aMceState.back(); }
214 void setMCEState( MCE_STATE aState ) { aMceState.back() = aState; }
215 void addMCEState( MCE_STATE aState ) { aMceState.push_back( aState ); }
216 void removeMCEState() { aMceState.pop_back(); }
217 bool isMCEStateEmpty() const { return aMceState.empty(); }
218
219private:
221
222 ElementInfo& pushElementInfo( sal_Int32 nElement );
223 void popElementInfo();
224 void processCollectedChars();
225
226private:
227 typedef std::vector< ElementInfo > ContextStack;
228 typedef std::shared_ptr< ContextStack > ContextStackRef;
229
232 std::vector<MCE_STATE> aMceState;
233
234protected:
237};
238
240{
241public:
242 explicit ContextHandler2( ContextHandler2Helper const & rParent );
243 virtual ~ContextHandler2() override;
244
247 ContextHandler2 & operator =(ContextHandler2 const &) = delete; // due to ContextHandler
248 ContextHandler2 & operator =(ContextHandler2 &&) = delete; // due to ContextHandler
249
250 // resolve ambiguity from base classes
251 virtual void SAL_CALL acquire() noexcept override { ContextHandler::acquire(); }
252 virtual void SAL_CALL release() noexcept override { ContextHandler::release(); }
253
254 // com.sun.star.xml.sax.XFastContextHandler interface ---------------------
255
256 virtual css::uno::Reference< css::xml::sax::XFastContextHandler > SAL_CALL
257 createFastChildContext(
258 sal_Int32 nElement,
259 const css::uno::Reference< css::xml::sax::XFastAttributeList >& rxAttribs ) final override;
260
261 virtual void SAL_CALL startFastElement(
262 sal_Int32 nElement,
263 const css::uno::Reference< css::xml::sax::XFastAttributeList >& rxAttribs ) final override;
264
265 virtual void SAL_CALL characters( const OUString& rChars ) final override;
266
267 virtual void SAL_CALL endFastElement( sal_Int32 nElement ) final override;
268
269 // oox.core.ContextHandler interface --------------------------------------
270
271 virtual ContextHandlerRef createRecordContext( sal_Int32 nRecId, SequenceInputStream& rStrm ) override;
272 virtual void startRecord( sal_Int32 nRecId, SequenceInputStream& rStrm ) override;
273 virtual void endRecord( sal_Int32 nRecId ) override;
274
275 // oox.core.ContextHandler2Helper interface -------------------------------
276
277 virtual ContextHandlerRef onCreateContext( sal_Int32 nElement, const AttributeList& rAttribs ) override;
278 virtual void onStartElement( const AttributeList& rAttribs ) override;
279 virtual void onCharacters( const OUString& rChars ) override;
280 virtual void onEndElement() override;
281
282 virtual ContextHandlerRef onCreateRecordContext( sal_Int32 nRecId, SequenceInputStream& rStrm ) override;
283 virtual void onStartRecord( SequenceInputStream& rStrm ) override;
284 virtual void onEndRecord() override;
285};
286
287} // namespace oox::core
288
289#endif
290
291/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
Provides access to attribute values of an element.
Wraps a StreamDataSequence and provides convenient access functions.
Helper class that provides a context stack.
bool isCurrentElement(sal_Int32 nElement1, sal_Int32 nElement2) const
Returns true, if either nElement1 or nElement2 contain the identifier of the currently processed elem...
std::vector< MCE_STATE > aMceState
void setMCEState(MCE_STATE aState)
bool mbEnableTrimSpace
True = trim whitespace in characters().
std::vector< ElementInfo > ContextStack
ContextStackRef mxContextStack
Stack of all processed elements.
virtual void SAL_CALL acquire() noexcept=0
std::shared_ptr< ContextStack > ContextStackRef
ContextHandler2Helper & operator=(const ContextHandler2Helper &)=delete
bool isParentElement(sal_Int32 nElement, sal_Int32 nCountBack=1) const
Returns true, if nElement contains the identifier of the specified parent element.
size_t mnRootStackSize
Stack size on construction time.
XmlFilterBase & getDocFilter() const
void addMCEState(MCE_STATE aState)
ContextHandler2(ContextHandler2 &&)=default
virtual void SAL_CALL release() noexcept override
ContextHandler2(ContextHandler2 const &)=default
virtual void SAL_CALL acquire() noexcept override
#define OOX_DLLPUBLIC
Definition: dllapi.h:28
const sal_Int32 XML_ROOT_CONTEXT
const PowerPointImport & mrFilter
Definition: pptimport.cxx:264
Information about a processed element.
#define SAL_MAX_INT32