Line data Source code
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_WRITERFILTER_SOURCE_OOXML_OOXMLFASTCONTEXTHANDLER_HXX
21 : #define INCLUDED_WRITERFILTER_SOURCE_OOXML_OOXMLFASTCONTEXTHANDLER_HXX
22 :
23 : #include <com/sun/star/xml/sax/XFastShapeContextHandler.hpp>
24 :
25 : #include <string>
26 : #include <set>
27 : #include "sal/config.h"
28 : #include "com/sun/star/uno/XComponentContext.hpp"
29 : #include "cppuhelper/implbase.hxx"
30 : #include "com/sun/star/xml/sax/XFastContextHandler.hpp"
31 : #include "OOXMLParserState.hxx"
32 : #include "OOXMLPropertySetImpl.hxx"
33 : #include "OOXMLDocumentImpl.hxx"
34 : #include <oox/token/tokens.hxx>
35 : #include <svtools/embedhlp.hxx>
36 :
37 : #include <oox/mathml/import.hxx>
38 : #include <oox/mathml/importutils.hxx>
39 :
40 : namespace writerfilter {
41 : namespace ooxml
42 : {
43 :
44 :
45 257 : class OOXMLFastContextHandler: public ::cppu::WeakImplHelper<css::xml::sax::XFastContextHandler>
46 : {
47 : public:
48 : typedef std::shared_ptr<OOXMLFastContextHandler> Pointer_t;
49 :
50 : enum ResourceEnum_t { UNKNOWN, STREAM, PROPERTIES, TABLE, SHAPE };
51 :
52 : OOXMLFastContextHandler();
53 : explicit OOXMLFastContextHandler(css::uno::Reference< css::uno::XComponentContext > const & context);
54 :
55 : explicit OOXMLFastContextHandler(OOXMLFastContextHandler * pContext);
56 :
57 : virtual ~OOXMLFastContextHandler();
58 :
59 : // css::xml::sax::XFastContextHandler:
60 : virtual void SAL_CALL startFastElement (Token_t Element, const css::uno::Reference< css::xml::sax::XFastAttributeList >& Attribs)
61 : throw (css::uno::RuntimeException, css::xml::sax::SAXException, std::exception) SAL_OVERRIDE;
62 :
63 : virtual void SAL_CALL startUnknownElement(const OUString & Namespace, const OUString & Name, const css::uno::Reference< css::xml::sax::XFastAttributeList > & Attribs)
64 : throw (css::uno::RuntimeException, css::xml::sax::SAXException, std::exception) SAL_OVERRIDE;
65 :
66 : virtual void SAL_CALL endFastElement(Token_t Element)
67 : throw (css::uno::RuntimeException, css::xml::sax::SAXException, std::exception) SAL_OVERRIDE;
68 :
69 : virtual void SAL_CALL endUnknownElement(const OUString & Namespace, const OUString & Name)
70 : throw (css::uno::RuntimeException, css::xml::sax::SAXException, std::exception) SAL_OVERRIDE;
71 :
72 : virtual css::uno::Reference<css::xml::sax::XFastContextHandler> SAL_CALL createFastChildContext(Token_t Element,
73 : const css::uno::Reference<css::xml::sax::XFastAttributeList>& Attribs)
74 : throw (css::uno::RuntimeException, css::xml::sax::SAXException, std::exception) SAL_OVERRIDE;
75 :
76 : virtual css::uno::Reference< css::xml::sax::XFastContextHandler > SAL_CALL createUnknownChildContext(const OUString & Namespace, const OUString & Name,
77 : const css::uno::Reference< css::xml::sax::XFastAttributeList > & Attribs)
78 : throw (css::uno::RuntimeException, css::xml::sax::SAXException, std::exception) SAL_OVERRIDE;
79 :
80 : virtual void SAL_CALL characters(const OUString & aChars)
81 : throw (css::uno::RuntimeException, css::xml::sax::SAXException, std::exception) SAL_OVERRIDE;
82 :
83 : // local
84 :
85 : void setStream(Stream * pStream);
86 :
87 : /**
88 : Return value of this context(element).
89 :
90 : @return the value
91 : */
92 : virtual OOXMLValue::Pointer_t getValue() const;
93 :
94 : /**
95 : Returns a string describing the type of the context.
96 :
97 : This is the name of the define normally.
98 :
99 : @return type string
100 : */
101 0 : virtual std::string getType() const { return "??"; }
102 :
103 13157 : virtual ResourceEnum_t getResource() const { return STREAM; }
104 :
105 : virtual void attributes(const css::uno::Reference< css::xml::sax::XFastAttributeList > & Attribs) throw (css::uno::RuntimeException, css::xml::sax::SAXException);
106 :
107 : virtual void newProperty(const Id & rId, OOXMLValue::Pointer_t pVal);
108 : virtual void setPropertySet(OOXMLPropertySet::Pointer_t pPropertySet);
109 : virtual OOXMLPropertySet::Pointer_t getPropertySet() const;
110 :
111 : virtual void setToken(Token_t nToken);
112 : virtual Token_t getToken() const;
113 :
114 : void resolveFootnote(const sal_Int32 nId);
115 : void resolveEndnote(const sal_Int32 nId);
116 : void resolveComment(const sal_Int32 nId);
117 : void resolvePicture(const OUString & rId);
118 : void resolveHeader(const sal_Int32 type,
119 : const OUString & rId);
120 : void resolveFooter(const sal_Int32 type,
121 : const OUString & rId);
122 : void resolveData(const OUString & rId);
123 :
124 : OUString getTargetForId(const OUString & rId);
125 :
126 : css::uno::Reference < css::xml::sax::XFastContextHandler > createFromStart(Token_t Element, const css::uno::Reference< css::xml::sax::XFastAttributeList >& Attribs);
127 :
128 : void setDocument(OOXMLDocumentImpl* pDocument);
129 : OOXMLDocumentImpl* getDocument();
130 : void setXNoteId(OOXMLValue::Pointer_t pValue);
131 : void setXNoteId(const sal_Int32 nId);
132 : sal_Int32 getXNoteId() const;
133 : void setForwardEvents(bool bForwardEvents);
134 : bool isForwardEvents() const;
135 : virtual void setParent(OOXMLFastContextHandler * pParent);
136 : virtual void setId(Id nId);
137 : virtual Id getId() const;
138 :
139 : void setDefine(Id nDefine);
140 16268328 : Id getDefine() const { return mnDefine;}
141 :
142 2910 : OOXMLParserState::Pointer_t getParserState() const { return mpParserState;}
143 :
144 : void sendTableDepth() const;
145 : void setHandle();
146 :
147 : void startSectionGroup();
148 : void setLastParagraphInSection();
149 : void setLastSectionGroup();
150 : void endSectionGroup();
151 : void startParagraphGroup();
152 : void endParagraphGroup();
153 : void startCharacterGroup();
154 : void endCharacterGroup();
155 : void startSdt();
156 : void endSdt();
157 :
158 : void startField();
159 : void fieldSeparator();
160 : void endField();
161 : void lockField();
162 : void ftnednref();
163 : void ftnedncont();
164 : void ftnednsep();
165 : void pgNum();
166 : void tab();
167 : void cr();
168 : void noBreakHyphen();
169 : void softHyphen();
170 : void handleLastParagraphInSection();
171 : void endOfParagraph();
172 : void text(const OUString & sText);
173 : void positionOffset(const OUString & sText);
174 : static void ignore();
175 : void alignH(const OUString & sText);
176 : void alignV(const OUString & sText);
177 : void positivePercentage(const OUString& rText);
178 : void startTxbxContent();
179 : void endTxbxContent();
180 : void propagateCharacterProperties();
181 : void propagateCharacterPropertiesAsSet(const Id & rId);
182 : void propagateTableProperties();
183 : void propagateRowProperties();
184 : void propagateCellProperties();
185 : void sendPropertiesWithId(const Id & rId);
186 : void sendPropertiesToParent();
187 : void sendCellProperties();
188 : void sendRowProperties();
189 : void sendTableProperties();
190 : void clearTableProps();
191 : void clearProps();
192 :
193 : virtual void setDefaultBooleanValue();
194 : virtual void setDefaultIntegerValue();
195 : virtual void setDefaultHexValue();
196 : virtual void setDefaultStringValue();
197 :
198 : void sendPropertyToParent();
199 :
200 : sal_uInt32 getInstanceNumber() { return mnInstanceNumber; }
201 : protected:
202 : OOXMLFastContextHandler * mpParent;
203 : Id mId;
204 : Id mnDefine;
205 : Token_t mnToken;
206 :
207 : // the stream to send the stream events to.
208 : Stream * mpStream;
209 :
210 : // the current global parser state
211 : OOXMLParserState::Pointer_t mpParserState;
212 :
213 : // the table depth of this context
214 : unsigned int mnTableDepth;
215 :
216 : virtual void lcl_startFastElement(Token_t Element, const css::uno::Reference< css::xml::sax::XFastAttributeList > & Attribs)
217 : throw (css::uno::RuntimeException, css::xml::sax::SAXException, std::exception);
218 :
219 : virtual void lcl_endFastElement(Token_t Element)
220 : throw (css::uno::RuntimeException, css::xml::sax::SAXException, std::exception);
221 :
222 : virtual css::uno::Reference< css::xml::sax::XFastContextHandler > lcl_createFastChildContext(Token_t Element, const css::uno::Reference< css::xml::sax::XFastAttributeList > & Attribs)
223 : throw (css::uno::RuntimeException, css::xml::sax::SAXException, std::exception);
224 :
225 : virtual void lcl_characters(const OUString & aChars)
226 : throw (css::uno::RuntimeException, css::xml::sax::SAXException, std::exception);
227 :
228 : void startAction(Token_t Element);
229 : void endAction(Token_t Element);
230 :
231 : virtual void resolvePropertySetAttrs();
232 :
233 799 : css::uno::Reference< css::uno::XComponentContext > getComponentContext() { return m_xContext;}
234 :
235 : sal_uInt32 mnInstanceNumber;
236 :
237 : bool inPositionV;
238 :
239 : private:
240 : void operator =(OOXMLFastContextHandler &) SAL_DELETED_FUNCTION;
241 : /// Handles AlternateContent. Returns true, if children of the current element should be ignored.
242 : bool prepareMceContext(Token_t nElement, const css::uno::Reference<css::xml::sax::XFastAttributeList>& Attribs);
243 :
244 : css::uno::Reference< css::uno::XComponentContext > m_xContext;
245 : bool m_bDiscardChildren;
246 : bool m_bTookChoice; ///< Did we take the Choice or want Fallback instead?
247 :
248 : static sal_uInt32 mnInstanceCount;
249 :
250 : };
251 :
252 : class OOXMLFastContextHandlerStream : public OOXMLFastContextHandler
253 : {
254 : public:
255 : explicit OOXMLFastContextHandlerStream(OOXMLFastContextHandler * pContext);
256 : virtual ~OOXMLFastContextHandlerStream();
257 :
258 74218 : virtual ResourceEnum_t getResource() const SAL_OVERRIDE { return STREAM; }
259 :
260 15027 : OOXMLPropertySet::Pointer_t getPropertySetAttrs() const { return mpPropertySetAttrs;}
261 :
262 : virtual void newProperty(const Id & rId, OOXMLValue::Pointer_t pVal) SAL_OVERRIDE;
263 : void sendProperty(Id nId);
264 : virtual OOXMLPropertySet::Pointer_t getPropertySet() const SAL_OVERRIDE;
265 :
266 : void handleHyperlink();
267 :
268 : protected:
269 : virtual void resolvePropertySetAttrs() SAL_OVERRIDE;
270 :
271 : private:
272 : mutable OOXMLPropertySet::Pointer_t mpPropertySetAttrs;
273 : };
274 :
275 : class OOXMLFastContextHandlerProperties : public OOXMLFastContextHandler
276 : {
277 : public:
278 : explicit OOXMLFastContextHandlerProperties(OOXMLFastContextHandler * pContext);
279 : virtual ~OOXMLFastContextHandlerProperties();
280 :
281 : virtual OOXMLValue::Pointer_t getValue() const SAL_OVERRIDE;
282 976070 : virtual ResourceEnum_t getResource() const SAL_OVERRIDE { return PROPERTIES; }
283 :
284 : virtual void newProperty(const Id & nId, OOXMLValue::Pointer_t pVal) SAL_OVERRIDE;
285 :
286 : void handleXNotes();
287 : void handleHdrFtr();
288 : void handleComment();
289 : void handlePicture();
290 : void handleBreak();
291 : void handleOLE();
292 : void handleFontRel();
293 :
294 : virtual void setPropertySet(OOXMLPropertySet::Pointer_t pPropertySet) SAL_OVERRIDE;
295 : virtual OOXMLPropertySet::Pointer_t getPropertySet() const SAL_OVERRIDE;
296 :
297 : protected:
298 : /// the properties
299 : OOXMLPropertySet::Pointer_t mpPropertySet;
300 :
301 : virtual void lcl_endFastElement(Token_t Element)
302 : throw (css::uno::RuntimeException, css::xml::sax::SAXException, std::exception) SAL_OVERRIDE;
303 : virtual void setParent(OOXMLFastContextHandler * pParent) SAL_OVERRIDE;
304 :
305 : private:
306 :
307 : bool mbResolve;
308 : };
309 :
310 : class OOXMLFastContextHandlerPropertyTable :
311 : public OOXMLFastContextHandlerProperties
312 : {
313 : public:
314 : explicit OOXMLFastContextHandlerPropertyTable(OOXMLFastContextHandler * pContext);
315 : virtual ~OOXMLFastContextHandlerPropertyTable();
316 :
317 : protected:
318 : OOXMLTableImpl mTable;
319 :
320 : virtual void lcl_endFastElement(Token_t Element)
321 : throw (css::uno::RuntimeException, css::xml::sax::SAXException, std::exception) SAL_OVERRIDE;
322 : };
323 :
324 : class OOXMLFastContextHandlerValue :
325 : public OOXMLFastContextHandler
326 : {
327 : public:
328 : explicit OOXMLFastContextHandlerValue(OOXMLFastContextHandler * pContext);
329 : virtual ~OOXMLFastContextHandlerValue();
330 :
331 : void setValue(OOXMLValue::Pointer_t pValue);
332 : virtual OOXMLValue::Pointer_t getValue() const SAL_OVERRIDE;
333 :
334 : virtual void lcl_endFastElement(Token_t Element)
335 : throw (css::uno::RuntimeException, css::xml::sax::SAXException, std::exception) SAL_OVERRIDE;
336 :
337 0 : virtual std::string getType() const SAL_OVERRIDE { return "Value"; }
338 :
339 : virtual void setDefaultBooleanValue() SAL_OVERRIDE;
340 : virtual void setDefaultIntegerValue() SAL_OVERRIDE;
341 : virtual void setDefaultHexValue() SAL_OVERRIDE;
342 : virtual void setDefaultStringValue() SAL_OVERRIDE;
343 :
344 : protected:
345 : OOXMLValue::Pointer_t mpValue;
346 : };
347 :
348 : class OOXMLFastContextHandlerTable : public OOXMLFastContextHandler
349 : {
350 : public:
351 : explicit OOXMLFastContextHandlerTable(OOXMLFastContextHandler * pContext);
352 : virtual ~OOXMLFastContextHandlerTable();
353 :
354 : virtual css::uno::Reference< css::xml::sax::XFastContextHandler > SAL_CALL createFastChildContext (Token_t Element,
355 : const css::uno::Reference< css::xml::sax::XFastAttributeList > & Attribs)
356 : throw (css::uno::RuntimeException, css::xml::sax::SAXException, std::exception) SAL_OVERRIDE;
357 :
358 : protected:
359 : OOXMLTableImpl mTable;
360 :
361 : css::uno::Reference<css::xml::sax::XFastContextHandler> mCurrentChild;
362 :
363 : virtual void lcl_endFastElement(Token_t Element)
364 : throw (css::uno::RuntimeException, css::xml::sax::SAXException, std::exception) SAL_OVERRIDE;
365 :
366 58804 : virtual ResourceEnum_t getResource() const SAL_OVERRIDE { return TABLE; }
367 :
368 0 : virtual std::string getType() const SAL_OVERRIDE { return "Table"; }
369 :
370 : void addCurrentChild();
371 : };
372 :
373 : class OOXMLFastContextHandlerXNote : public OOXMLFastContextHandlerProperties
374 : {
375 : public:
376 : explicit OOXMLFastContextHandlerXNote(OOXMLFastContextHandler * pContext);
377 : virtual ~OOXMLFastContextHandlerXNote();
378 :
379 : void checkId(OOXMLValue::Pointer_t pValue);
380 :
381 : void checkType(OOXMLValue::Pointer_t pValue);
382 :
383 0 : virtual std::string getType() const SAL_OVERRIDE { return "XNote"; }
384 :
385 : private:
386 : bool mbForwardEventsSaved;
387 : sal_Int32 mnMyXNoteId;
388 : sal_Int32 mnMyXNoteType;
389 :
390 : virtual void lcl_startFastElement(Token_t Element, const css::uno::Reference< css::xml::sax::XFastAttributeList > & Attribs)
391 : throw (css::uno::RuntimeException, css::xml::sax::SAXException, std::exception) SAL_OVERRIDE;
392 :
393 : virtual void lcl_endFastElement(Token_t Element)
394 : throw (css::uno::RuntimeException, css::xml::sax::SAXException, std::exception) SAL_OVERRIDE;
395 :
396 0 : virtual ResourceEnum_t getResource() const SAL_OVERRIDE { return STREAM; }
397 : };
398 :
399 : class OOXMLFastContextHandlerTextTableCell : public OOXMLFastContextHandler
400 : {
401 : public:
402 : explicit OOXMLFastContextHandlerTextTableCell(OOXMLFastContextHandler * pContext);
403 : virtual ~OOXMLFastContextHandlerTextTableCell();
404 :
405 0 : virtual std::string getType() const SAL_OVERRIDE { return "TextTableCell"; }
406 :
407 : static void startCell();
408 : void endCell();
409 : };
410 :
411 : class OOXMLFastContextHandlerTextTableRow : public OOXMLFastContextHandler
412 : {
413 : public:
414 : explicit OOXMLFastContextHandlerTextTableRow(OOXMLFastContextHandler * pContext);
415 : virtual ~OOXMLFastContextHandlerTextTableRow();
416 :
417 0 : virtual std::string getType() const SAL_OVERRIDE { return "TextTableRow"; }
418 :
419 : static void startRow();
420 : void endRow();
421 : void handleGridBefore( OOXMLValue::Pointer_t val );
422 : private:
423 : static OOXMLProperty::Pointer_t fakeNoBorder( Id id );
424 : };
425 :
426 : class OOXMLFastContextHandlerTextTable : public OOXMLFastContextHandler
427 : {
428 : public:
429 : explicit OOXMLFastContextHandlerTextTable(OOXMLFastContextHandler * pContext);
430 :
431 : virtual ~OOXMLFastContextHandlerTextTable();
432 :
433 0 : virtual std::string getType() const SAL_OVERRIDE { return "TextTable"; }
434 :
435 : protected:
436 : virtual void lcl_startFastElement(Token_t Element, const css::uno::Reference< css::xml::sax::XFastAttributeList > & Attribs)
437 : throw (css::uno::RuntimeException, css::xml::sax::SAXException, std::exception) SAL_OVERRIDE;
438 :
439 : virtual void lcl_endFastElement(Token_t Element)
440 : throw (css::uno::RuntimeException, css::xml::sax::SAXException, std::exception) SAL_OVERRIDE;
441 : };
442 :
443 : class OOXMLFastContextHandlerShape: public OOXMLFastContextHandlerProperties
444 : {
445 : private:
446 : bool m_bShapeSent;
447 : bool m_bShapeStarted;
448 :
449 : public:
450 : explicit OOXMLFastContextHandlerShape(OOXMLFastContextHandler * pContext);
451 : virtual ~OOXMLFastContextHandlerShape();
452 :
453 0 : virtual std::string getType() const SAL_OVERRIDE { return "Shape"; }
454 :
455 : // css::xml::sax::XFastContextHandler:
456 : virtual void SAL_CALL startUnknownElement (const OUString & Namespace, const OUString & Name, const css::uno::Reference< css::xml::sax::XFastAttributeList > & Attribs)
457 : throw (css::uno::RuntimeException, css::xml::sax::SAXException, std::exception) SAL_OVERRIDE;
458 :
459 : virtual void SAL_CALL endUnknownElement(const OUString & Namespace, const OUString & Name)
460 : throw (css::uno::RuntimeException, css::xml::sax::SAXException, std::exception) SAL_OVERRIDE;
461 :
462 : virtual css::uno::Reference< css::xml::sax::XFastContextHandler > SAL_CALL createUnknownChildContext(const OUString & Namespace, const OUString & Name,
463 : const css::uno::Reference< css::xml::sax::XFastAttributeList > & Attribs)
464 : throw (css::uno::RuntimeException, css::xml::sax::SAXException, std::exception) SAL_OVERRIDE;
465 :
466 : virtual void setToken(Token_t nToken) SAL_OVERRIDE;
467 :
468 74 : virtual ResourceEnum_t getResource() const SAL_OVERRIDE { return SHAPE; }
469 :
470 : void sendShape( Token_t Element );
471 82 : bool isShapeSent( ) { return m_bShapeSent; }
472 :
473 : protected:
474 : typedef css::uno::Reference<css::xml::sax::XFastShapeContextHandler> ShapeContextRef;
475 : ShapeContextRef mrShapeContext;
476 :
477 : virtual void lcl_startFastElement(Token_t Element, const css::uno::Reference< css::xml::sax::XFastAttributeList > & Attribs)
478 : throw (css::uno::RuntimeException, css::xml::sax::SAXException, std::exception) SAL_OVERRIDE;
479 :
480 : virtual void lcl_endFastElement(Token_t Element)
481 : throw (css::uno::RuntimeException, css::xml::sax::SAXException, std::exception) SAL_OVERRIDE;
482 :
483 : virtual css::uno::Reference< css::xml::sax::XFastContextHandler > lcl_createFastChildContext (Token_t Element, const css::uno::Reference< css::xml::sax::XFastAttributeList > & Attribs)
484 : throw (css::uno::RuntimeException, css::xml::sax::SAXException, std::exception) SAL_OVERRIDE;
485 :
486 : virtual void lcl_characters(const OUString & aChars)
487 : throw (css::uno::RuntimeException, css::xml::sax::SAXException, std::exception) SAL_OVERRIDE;
488 :
489 : };
490 :
491 : /**
492 : OOXMLFastContextHandlerWrapper wraps an OOXMLFastContextHandler.
493 :
494 : The method calls for the interface css::xml::sax::XFastContextHandler are
495 : forwarded to the wrapped OOXMLFastContextHandler.
496 : */
497 : class OOXMLFastContextHandlerWrapper : public OOXMLFastContextHandler
498 : {
499 : public:
500 : explicit OOXMLFastContextHandlerWrapper(OOXMLFastContextHandler * pParent, css::uno::Reference<css::xml::sax::XFastContextHandler> xContext);
501 : virtual ~OOXMLFastContextHandlerWrapper();
502 :
503 : // css::xml::sax::XFastContextHandler:
504 : virtual void SAL_CALL startUnknownElement(const OUString & Namespace, const OUString & Name, const css::uno::Reference< css::xml::sax::XFastAttributeList > & Attribs)
505 : throw (css::uno::RuntimeException, css::xml::sax::SAXException, std::exception) SAL_OVERRIDE;
506 :
507 : virtual void SAL_CALL endUnknownElement(const OUString & Namespace, const OUString & Name)
508 : throw (css::uno::RuntimeException, css::xml::sax::SAXException, std::exception) SAL_OVERRIDE;
509 :
510 : virtual css::uno::Reference< css::xml::sax::XFastContextHandler > SAL_CALL createUnknownChildContext (const OUString & Namespace, const OUString & Name,
511 : const css::uno::Reference< css::xml::sax::XFastAttributeList > & Attribs)
512 : throw (css::uno::RuntimeException, css::xml::sax::SAXException, std::exception) SAL_OVERRIDE;
513 :
514 : virtual void attributes(const css::uno::Reference< css::xml::sax::XFastAttributeList > & Attribs)
515 : throw (css::uno::RuntimeException, css::xml::sax::SAXException) SAL_OVERRIDE;
516 :
517 : virtual ResourceEnum_t getResource() const SAL_OVERRIDE;
518 :
519 : void addNamespace(const Id & nId);
520 : void addToken( Token_t Element );
521 :
522 : virtual void newProperty(const Id & rId, OOXMLValue::Pointer_t pVal) SAL_OVERRIDE;
523 : virtual void setPropertySet(OOXMLPropertySet::Pointer_t pPropertySet) SAL_OVERRIDE;
524 : virtual OOXMLPropertySet::Pointer_t getPropertySet() const SAL_OVERRIDE;
525 :
526 : virtual std::string getType() const SAL_OVERRIDE;
527 :
528 : protected:
529 : virtual void lcl_startFastElement(Token_t Element, const css::uno::Reference< css::xml::sax::XFastAttributeList > & Attribs)
530 : throw (css::uno::RuntimeException, css::xml::sax::SAXException, std::exception) SAL_OVERRIDE;
531 :
532 : virtual void lcl_endFastElement(Token_t Element)
533 : throw (css::uno::RuntimeException, css::xml::sax::SAXException, std::exception) SAL_OVERRIDE;
534 :
535 : virtual css::uno::Reference< css::xml::sax::XFastContextHandler > lcl_createFastChildContext(Token_t Element, const css::uno::Reference< css::xml::sax::XFastAttributeList > & Attribs)
536 : throw (css::uno::RuntimeException, css::xml::sax::SAXException, std::exception) SAL_OVERRIDE;
537 :
538 : virtual void lcl_characters(const OUString & aChars)
539 : throw (css::uno::RuntimeException, css::xml::sax::SAXException, std::exception) SAL_OVERRIDE;
540 :
541 : virtual void setId(Id nId) SAL_OVERRIDE;
542 : virtual Id getId() const SAL_OVERRIDE;
543 :
544 : virtual void setToken(Token_t nToken) SAL_OVERRIDE;
545 : virtual Token_t getToken() const SAL_OVERRIDE;
546 :
547 : private:
548 : css::uno::Reference<css::xml::sax::XFastContextHandler> mxContext;
549 : std::set<Id> mMyNamespaces;
550 : std::set<Token_t> mMyTokens;
551 : OOXMLPropertySet::Pointer_t mpPropertySet;
552 :
553 : OOXMLFastContextHandler * getFastContextHandler() const;
554 : };
555 :
556 : /**
557 : A class that converts from XFastParser/XFastContextHandler usage to a liner XML stream of data.
558 :
559 : The purpose of this class is to convert the rather complex XFastContextHandler-based XML
560 : processing that requires context subclasses, callbacks, etc. into a linear stream of XML tokens
561 : that can be handled simply by reading the tokens one by one and directly processing them.
562 : See the oox::formulaimport::XmlStream class documentation for more information.
563 :
564 : Usage: Create a subclass of OOXMLFastContextHandlerLinear, reimplemented getType() to provide
565 : type of the subclass and process() to actually process the XML stream. Also make sure to
566 : add a line like the following to model.xml (for class OOXMLFastContextHandlerMath):
567 :
568 : <resource name="CT_OMath" resource="Math"/>
569 :
570 : @since 3.5
571 : */
572 195 : class OOXMLFastContextHandlerLinear: public OOXMLFastContextHandlerProperties
573 : {
574 : public:
575 : explicit OOXMLFastContextHandlerLinear(OOXMLFastContextHandler * pContext);
576 : /**
577 : Return the type of the class, as written in model.xml .
578 : */
579 : virtual std::string getType() const SAL_OVERRIDE = 0;
580 :
581 : protected:
582 : /**
583 : Called when the tokens for the element, its content and sub-elements have been linearized
584 : and should be processed. The data member @ref buffer contains the converted data.
585 : */
586 : virtual void process() = 0;
587 :
588 : virtual void lcl_startFastElement(Token_t Element, const css::uno::Reference< css::xml::sax::XFastAttributeList > & Attribs)
589 : throw (css::uno::RuntimeException, css::xml::sax::SAXException, std::exception) SAL_OVERRIDE;
590 :
591 : virtual void lcl_endFastElement(Token_t Element) throw (css::uno::RuntimeException, css::xml::sax::SAXException, std::exception) SAL_OVERRIDE;
592 :
593 : virtual css::uno::Reference< css::xml::sax::XFastContextHandler > lcl_createFastChildContext(Token_t Element,
594 : const css::uno::Reference< css::xml::sax::XFastAttributeList > & Attribs)
595 : throw (css::uno::RuntimeException, css::xml::sax::SAXException, std::exception) SAL_OVERRIDE;
596 :
597 : virtual void lcl_characters(const OUString & aChars) throw (css::uno::RuntimeException, css::xml::sax::SAXException, std::exception) SAL_OVERRIDE;
598 :
599 : // should be private, but not much point in making deep copies of it
600 : oox::formulaimport::XmlStreamBuilder buffer;
601 :
602 : private:
603 : int depthCount;
604 : };
605 :
606 390 : class OOXMLFastContextHandlerMath: public OOXMLFastContextHandlerLinear
607 : {
608 : public:
609 : explicit OOXMLFastContextHandlerMath(OOXMLFastContextHandler * pContext);
610 0 : virtual std::string getType() const SAL_OVERRIDE { return "Math"; }
611 : protected:
612 : virtual void process() SAL_OVERRIDE;
613 : };
614 :
615 : }}
616 : #endif // INCLUDED_WRITERFILTER_SOURCE_OOXML_OOXMLFASTCONTEXTHANDLER_HXX
617 :
618 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|