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