1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: OOXMLFastContextHandler.hxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 #ifndef INCLUDED_OOXML_FAST_CONTEXT_HANDLER_HXX
32 #define INCLUDED_OOXML_FAST_CONTEXT_HANDLER_HXX
34 #include <com/sun/star/xml/sax/XFastShapeContextHandler.hpp>
38 #include "sal/config.h"
39 #include "com/sun/star/uno/XComponentContext.hpp"
40 #include "cppuhelper/implbase1.hxx"
41 #include "com/sun/star/xml/sax/XFastContextHandler.hpp"
42 #include "OOXMLParserState.hxx"
43 #include "OOXMLPropertySetImpl.hxx"
44 #include "OOXMLDocumentImpl.hxx"
45 #include "RefAndPointer.hxx"
46 #include <ooxml/OOXMLFastTokens.hxx>
48 namespace writerfilter
{
51 using namespace ::std
;
52 using namespace ::com::sun::star
;
53 using namespace ::com::sun::star::xml::sax
;
55 typedef boost::shared_ptr
<Stream
> StreamPointer_t
;
57 class OOXMLFastContextHandler
:
58 public ::cppu::WeakImplHelper1
<
59 xml::sax::XFastContextHandler
>
62 typedef RefAndPointer
<XFastContextHandler
, OOXMLFastContextHandler
>
64 typedef boost::shared_ptr
<OOXMLFastContextHandler
> Pointer_t
;
66 enum ResourceEnum_t
{ UNKNOWN
, STREAM
, PROPERTIES
, TABLE
, SHAPE
};
68 OOXMLFastContextHandler();
69 explicit OOXMLFastContextHandler
70 (uno::Reference
< uno::XComponentContext
> const & context
);
72 explicit OOXMLFastContextHandler
73 (OOXMLFastContextHandler
* pContext
);
75 virtual ~OOXMLFastContextHandler();
77 // ::com::sun::star::xml::sax::XFastContextHandler:
78 virtual void SAL_CALL startFastElement
80 const uno::Reference
< xml::sax::XFastAttributeList
> & Attribs
)
81 throw (uno::RuntimeException
, xml::sax::SAXException
);
83 virtual void SAL_CALL startUnknownElement
84 (const ::rtl::OUString
& Namespace
,
85 const ::rtl::OUString
& Name
,
86 const uno::Reference
< xml::sax::XFastAttributeList
> & Attribs
)
87 throw (uno::RuntimeException
, xml::sax::SAXException
);
89 virtual void SAL_CALL
endFastElement(Token_t Element
)
90 throw (uno::RuntimeException
, xml::sax::SAXException
);
92 virtual void SAL_CALL endUnknownElement
93 (const ::rtl::OUString
& Namespace
, const ::rtl::OUString
& Name
)
94 throw (uno::RuntimeException
, xml::sax::SAXException
);
96 virtual uno::Reference
< xml::sax::XFastContextHandler
> SAL_CALL
97 createFastChildContext
99 const uno::Reference
< xml::sax::XFastAttributeList
> & Attribs
)
100 throw (uno::RuntimeException
, xml::sax::SAXException
);
102 virtual uno::Reference
< xml::sax::XFastContextHandler
> SAL_CALL
103 createUnknownChildContext
104 (const ::rtl::OUString
& Namespace
,
105 const ::rtl::OUString
& Name
,
106 const uno::Reference
< xml::sax::XFastAttributeList
> & Attribs
)
107 throw (uno::RuntimeException
, xml::sax::SAXException
);
109 virtual void SAL_CALL
characters(const ::rtl::OUString
& aChars
)
110 throw (uno::RuntimeException
, xml::sax::SAXException
);
112 static const uno::Sequence
< sal_Int8
> & getUnoTunnelId();
113 virtual sal_Int64 SAL_CALL
getSomething(const uno::Sequence
<sal_Int8
> & rId
)
114 throw (uno::RuntimeException
);
118 void setStream(Stream
* pStream
);
121 Return value of this context(element).
125 virtual OOXMLValue::Pointer_t
getValue() const;
128 Returns a string describing the type of the context.
130 This is the name of the define normally.
134 virtual string
getType() const { return "??"; }
136 virtual ResourceEnum_t
getResource() const { return UNKNOWN
; }
138 static XMLTag::Pointer_t
toPropertiesTag(OOXMLPropertySet::Pointer_t
);
139 virtual XMLTag::Pointer_t
toTag() const;
140 virtual string
toString() const;
142 virtual void attributes
143 (const uno::Reference
< xml::sax::XFastAttributeList
> & Attribs
)
144 throw (uno::RuntimeException
, xml::sax::SAXException
);
146 virtual void newProperty(const Id
& rId
, OOXMLValue::Pointer_t pVal
);
147 virtual void setPropertySet(OOXMLPropertySet::Pointer_t pPropertySet
);
148 virtual OOXMLPropertySet::Pointer_t
getPropertySet() const;
150 virtual void setToken(Token_t nToken
);
151 virtual Token_t
getToken() const;
153 void mark(const Id
& rId
, OOXMLValue::Pointer_t pVal
);
155 void resolveFootnote(const rtl::OUString
& rId
);
156 void resolveEndnote(const rtl::OUString
& rId
);
157 void resolveComment(const rtl::OUString
& rId
);
158 void resolvePicture(const rtl::OUString
& rId
);
159 void resolveHeader(const sal_Int32 type
,
160 const rtl::OUString
& rId
);
161 void resolveFooter(const sal_Int32 type
,
162 const rtl::OUString
& rId
);
163 void resolveOLE(const rtl::OUString
& rId
);
165 ::rtl::OUString
getTargetForId(const ::rtl::OUString
& rId
);
167 uno::Reference
< xml::sax::XFastContextHandler
>
170 const uno::Reference
< xml::sax::XFastAttributeList
> & Attribs
);
172 void setDocument(OOXMLDocument
* pDocument
);
173 OOXMLDocument
* getDocument();
174 void setXNoteId(const ::rtl::OUString
& rId
);
175 const rtl::OUString
& 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;
182 void setFallback(bool bFallbac
);
183 bool isFallback() const;
185 OOXMLParserState::Pointer_t
getParserState() const;
188 virtual void SAL_CALL
acquire() throw();
189 virtual void SAL_CALL
release() throw();
192 sal_uInt32
getInstanceNumber() const;
194 static void dumpOpenContexts();
197 OOXMLFastContextHandler
* mpParent
;
201 #ifdef DEBUG_CONTEXT_STACK
202 string msTokenString
;
205 // the stream to send the stream events to.
208 // the current global parser state
209 OOXMLParserState::Pointer_t mpParserState
;
211 // the table depth of this context
212 unsigned int mnTableDepth
;
214 virtual void lcl_startFastElement
216 const uno::Reference
< xml::sax::XFastAttributeList
> & Attribs
)
217 throw (uno::RuntimeException
, xml::sax::SAXException
);
219 virtual void lcl_endFastElement(Token_t Element
)
220 throw (uno::RuntimeException
, xml::sax::SAXException
);
222 virtual uno::Reference
< xml::sax::XFastContextHandler
>
223 lcl_createFastChildContext
225 const uno::Reference
< xml::sax::XFastAttributeList
> & Attribs
)
226 throw (uno::RuntimeException
, xml::sax::SAXException
);
228 virtual void lcl_characters(const ::rtl::OUString
& aChars
)
229 throw (uno::RuntimeException
, xml::sax::SAXException
);
231 void startAction(Token_t Element
);
232 virtual void lcl_startAction(Token_t Element
);
233 void endAction(Token_t Element
);
234 virtual void lcl_endAction(Token_t Element
);
237 // Returns string for resource of this context. (debug)
238 string
getResourceString() const;
240 virtual OOXMLPropertySet
* getPicturePropSet
241 (const ::rtl::OUString
& rId
);
242 virtual void resolvePropertySetAttrs();
244 void sendTableDepth() const;
247 void startSectionGroup();
248 void setLastParagraphInSection();
249 void endSectionGroup();
250 void startParagraphGroup();
251 void endParagraphGroup();
252 void startCharacterGroup();
253 void endCharacterGroup();
256 void fieldSeparator();
264 void noBreakHyphen();
266 void handleLastParagraphInSection();
267 void endOfParagraph();
268 void text(const ::rtl::OUString
& sText
);
269 virtual void propagateCharacterProperties();
270 virtual void propagateCharacterPropertiesAsSet(const Id
& rId
);
271 virtual bool propagatesProperties() const;
272 void sendPropertiesWithId(const Id
& rId
);
273 void propagateTableProperties();
276 void sendPropertyToParent();
278 uno::Reference
< uno::XComponentContext
> getComponentContext();
280 sal_uInt32 mnInstanceNumber
;
281 sal_uInt32 mnRefCount
;
283 void operator =(OOXMLFastContextHandler
&); // not defined
285 uno::Reference
< uno::XComponentContext
> m_xContext
;
287 static sal_uInt32 mnInstanceCount
;
292 class OOXMLFastContextHandlerNoResource
: public OOXMLFastContextHandler
295 OOXMLFastContextHandlerNoResource(OOXMLFastContextHandler
* pContext
);
296 virtual ~OOXMLFastContextHandlerNoResource();
299 class OOXMLFastContextHandlerStream
: public OOXMLFastContextHandler
302 OOXMLFastContextHandlerStream(OOXMLFastContextHandler
* pContext
);
303 virtual ~OOXMLFastContextHandlerStream();
305 virtual ResourceEnum_t
getResource() const { return STREAM
; }
307 OOXMLPropertySet::Pointer_t
getPropertySetAttrs() const;
309 virtual void newProperty(const Id
& rId
, OOXMLValue::Pointer_t pVal
);
310 virtual void sendProperty(Id nId
);
311 virtual OOXMLPropertySet::Pointer_t
getPropertySet() const;
313 void handleHyperlink();
316 void setPropertySetAttrs(OOXMLPropertySet::Pointer_t pPropertySetAttrs
);
317 virtual void resolvePropertySetAttrs();
318 virtual void lcl_characters(const ::rtl::OUString
& aChars
)
319 throw (uno::RuntimeException
, xml::sax::SAXException
);
321 mutable OOXMLPropertySet::Pointer_t mpPropertySetAttrs
;
324 class OOXMLFastContextHandlerProperties
: public OOXMLFastContextHandler
327 OOXMLFastContextHandlerProperties(OOXMLFastContextHandler
* pContext
);
328 virtual ~OOXMLFastContextHandlerProperties();
330 virtual OOXMLValue::Pointer_t
getValue() const;
331 virtual ResourceEnum_t
getResource() const { return PROPERTIES
; }
333 virtual XMLTag::Pointer_t
toTag() const;
335 virtual void newProperty(const Id
& nId
, OOXMLValue::Pointer_t pVal
);
339 void handleComment();
340 void handlePicture();
344 virtual void setPropertySet(OOXMLPropertySet::Pointer_t pPropertySet
);
345 virtual OOXMLPropertySet::Pointer_t
getPropertySet() const;
349 OOXMLPropertySet::Pointer_t mpPropertySet
;
351 virtual void lcl_endFastElement(Token_t Element
)
352 throw (uno::RuntimeException
, xml::sax::SAXException
);
353 virtual void setParent(OOXMLFastContextHandler
* pParent
);
360 class OOXMLFastContextHandlerPropertyTable
:
361 public OOXMLFastContextHandlerProperties
364 OOXMLFastContextHandlerPropertyTable(OOXMLFastContextHandler
* pContext
);
365 virtual ~OOXMLFastContextHandlerPropertyTable();
368 OOXMLTableImpl mTable
;
370 virtual void lcl_endFastElement(Token_t Element
)
371 throw (uno::RuntimeException
, xml::sax::SAXException
);
374 class OOXMLFastContextHandlerBooleanValue
:
375 public OOXMLFastContextHandler
378 OOXMLFastContextHandlerBooleanValue
379 (OOXMLFastContextHandler
* pContext
);
380 virtual ~OOXMLFastContextHandlerBooleanValue();
385 virtual void attributes
386 (const uno::Reference
< xml::sax::XFastAttributeList
> & Attribs
)
387 throw (uno::RuntimeException
, xml::sax::SAXException
);
388 virtual void lcl_endFastElement(Token_t Element
)
389 throw (uno::RuntimeException
, xml::sax::SAXException
);
391 virtual OOXMLValue::Pointer_t
getValue() const;
392 void setValue(const ::rtl::OUString
& rString
);
395 class OOXMLFastContextHandlerIntegerValue
:
396 public OOXMLFastContextHandler
399 OOXMLFastContextHandlerIntegerValue
400 (OOXMLFastContextHandler
* pContext
);
401 virtual ~OOXMLFastContextHandlerIntegerValue();
407 (const uno::Reference
< xml::sax::XFastAttributeList
> & Attribs
)
408 throw (uno::RuntimeException
, xml::sax::SAXException
);
409 virtual void lcl_endFastElement(Token_t Element
)
410 throw (uno::RuntimeException
, xml::sax::SAXException
);
412 virtual OOXMLValue::Pointer_t
getValue() const;
415 class OOXMLFastContextHandlerStringValue
:
416 public OOXMLFastContextHandler
419 OOXMLFastContextHandlerStringValue
420 (OOXMLFastContextHandler
* pContext
);
421 virtual ~OOXMLFastContextHandlerStringValue();
424 ::rtl::OUString msValue
;
427 (const uno::Reference
< xml::sax::XFastAttributeList
> & Attribs
)
428 throw (uno::RuntimeException
, xml::sax::SAXException
);
429 virtual void lcl_endFastElement(Token_t Element
)
430 throw (uno::RuntimeException
, xml::sax::SAXException
);
432 virtual OOXMLValue::Pointer_t
getValue() const;
435 class OOXMLFastContextHandlerHexValue
:
436 public OOXMLFastContextHandler
439 OOXMLFastContextHandlerHexValue
440 (OOXMLFastContextHandler
* pContext
);
441 virtual ~OOXMLFastContextHandlerHexValue();
447 (const uno::Reference
< xml::sax::XFastAttributeList
> & Attribs
)
448 throw (uno::RuntimeException
, xml::sax::SAXException
);
449 virtual void lcl_endFastElement(Token_t Element
)
450 throw (uno::RuntimeException
, xml::sax::SAXException
);
452 virtual OOXMLValue::Pointer_t
getValue() const;
455 class OOXMLFastContextHandlerListValue
:
456 public OOXMLFastContextHandler
459 OOXMLFastContextHandlerListValue
460 (OOXMLFastContextHandler
* pContext
);
461 virtual ~OOXMLFastContextHandlerListValue();
464 mutable OOXMLValue::Pointer_t mpValue
;
466 virtual void lcl_endFastElement(Token_t Element
)
467 throw (uno::RuntimeException
, xml::sax::SAXException
);
468 virtual OOXMLValue::Pointer_t
getValue() const;
471 class OOXMLFastContextHandlerTable
: public OOXMLFastContextHandler
474 OOXMLFastContextHandlerTable(OOXMLFastContextHandler
* pContext
);
475 virtual ~OOXMLFastContextHandlerTable();
477 virtual uno::Reference
< xml::sax::XFastContextHandler
> SAL_CALL
478 createFastChildContext
480 const uno::Reference
< xml::sax::XFastAttributeList
> & Attribs
)
481 throw (uno::RuntimeException
, xml::sax::SAXException
);
483 virtual void newPropertySet(OOXMLPropertySet::Pointer_t pPropertySet
);
485 OOXMLTableImpl mTable
;
487 RefAndPointer_t mCurrentChild
;
489 virtual void lcl_endFastElement(Token_t Element
)
490 throw (uno::RuntimeException
, xml::sax::SAXException
);
492 virtual ResourceEnum_t
getResource() const { return TABLE
; }
494 void addCurrentChild();
497 class OOXMLFastContextHandlerXNote
: public OOXMLFastContextHandler
500 OOXMLFastContextHandlerXNote(OOXMLFastContextHandler
* pContext
);
501 virtual ~OOXMLFastContextHandlerXNote();
503 void checkId(const rtl::OUString
& rId
);
505 bool mbForwardEventsSaved
;
506 ::rtl::OUString msMyXNoteId
;
508 virtual void lcl_startFastElement
510 const uno::Reference
< xml::sax::XFastAttributeList
> & Attribs
)
511 throw (uno::RuntimeException
, xml::sax::SAXException
);
513 virtual void lcl_endFastElement(Token_t Element
)
514 throw (uno::RuntimeException
, xml::sax::SAXException
);
516 virtual ResourceEnum_t
getResource() const { return STREAM
; }
519 class OOXMLFastContextHandlerTextTableCell
: public OOXMLFastContextHandler
522 OOXMLFastContextHandlerTextTableCell
523 (OOXMLFastContextHandler
* pContext
);
524 virtual ~OOXMLFastContextHandlerTextTableCell();
530 class OOXMLFastContextHandlerTextTableRow
: public OOXMLFastContextHandler
533 OOXMLFastContextHandlerTextTableRow
534 (OOXMLFastContextHandler
* pContext
);
535 virtual ~OOXMLFastContextHandlerTextTableRow();
541 class OOXMLFastContextHandlerTextTable
: public OOXMLFastContextHandler
544 OOXMLFastContextHandlerTextTable
545 (OOXMLFastContextHandler
* pContext
);
547 virtual ~OOXMLFastContextHandlerTextTable();
550 virtual void lcl_startFastElement
552 const uno::Reference
< xml::sax::XFastAttributeList
> & Attribs
)
553 throw (uno::RuntimeException
, xml::sax::SAXException
);
555 virtual void lcl_endFastElement(Token_t Element
)
556 throw (uno::RuntimeException
, xml::sax::SAXException
);
559 class OOXMLFastContextHandlerShape
: public OOXMLFastContextHandlerProperties
562 explicit OOXMLFastContextHandlerShape
563 (OOXMLFastContextHandler
* pContext
);
564 virtual ~OOXMLFastContextHandlerShape();
566 // ::com::sun::star::xml::sax::XFastContextHandler:
567 virtual void SAL_CALL startUnknownElement
568 (const ::rtl::OUString
& Namespace
,
569 const ::rtl::OUString
& Name
,
570 const uno::Reference
< xml::sax::XFastAttributeList
> & Attribs
)
571 throw (uno::RuntimeException
, xml::sax::SAXException
);
573 virtual void SAL_CALL endUnknownElement
574 (const ::rtl::OUString
& Namespace
,
575 const ::rtl::OUString
& Name
)
576 throw (uno::RuntimeException
, xml::sax::SAXException
);
578 virtual uno::Reference
< xml::sax::XFastContextHandler
> SAL_CALL
579 createUnknownChildContext
580 (const ::rtl::OUString
& Namespace
,
581 const ::rtl::OUString
& Name
,
582 const uno::Reference
< xml::sax::XFastAttributeList
> & Attribs
)
583 throw (uno::RuntimeException
, xml::sax::SAXException
);
585 virtual void setToken(Token_t nToken
);
587 virtual ResourceEnum_t
getResource() const { return SHAPE
; }
589 typedef uno::Reference
<XFastShapeContextHandler
> ShapeContextRef
;
590 ShapeContextRef mrShapeContext
;
592 virtual void lcl_startFastElement
594 const uno::Reference
< xml::sax::XFastAttributeList
> & Attribs
)
595 throw (uno::RuntimeException
, xml::sax::SAXException
);
597 virtual void lcl_endFastElement(Token_t Element
)
598 throw (uno::RuntimeException
, xml::sax::SAXException
);
600 virtual uno::Reference
< xml::sax::XFastContextHandler
>
601 lcl_createFastChildContext
603 const uno::Reference
< xml::sax::XFastAttributeList
> & Attribs
)
604 throw (uno::RuntimeException
, xml::sax::SAXException
);
606 virtual void lcl_characters(const ::rtl::OUString
& aChars
)
607 throw (uno::RuntimeException
, xml::sax::SAXException
);
612 OOXMLFastContextHandlerWrapper wraps an OOXMLFastContextHandler.
614 The method calls for the interface
615 ::com::sun::star::xml::sax::XFastContextHandler are forwarded to the wrapped
616 OOXMLFastContextHandler.
618 class OOXMLFastContextHandlerWrapper
: public OOXMLFastContextHandler
621 explicit OOXMLFastContextHandlerWrapper
622 (OOXMLFastContextHandler
* pParent
,
623 uno::Reference
<XFastContextHandler
> xContext
);
624 virtual ~OOXMLFastContextHandlerWrapper();
626 // ::com::sun::star::xml::sax::XFastContextHandler:
627 virtual void SAL_CALL startUnknownElement
628 (const ::rtl::OUString
& Namespace
,
629 const ::rtl::OUString
& Name
,
630 const uno::Reference
< xml::sax::XFastAttributeList
> & Attribs
)
631 throw (uno::RuntimeException
, xml::sax::SAXException
);
633 virtual void SAL_CALL endUnknownElement
634 (const ::rtl::OUString
& Namespace
,
635 const ::rtl::OUString
& Name
)
636 throw (uno::RuntimeException
, xml::sax::SAXException
);
638 virtual uno::Reference
< xml::sax::XFastContextHandler
> SAL_CALL
639 createUnknownChildContext
640 (const ::rtl::OUString
& Namespace
,
641 const ::rtl::OUString
& Name
,
642 const uno::Reference
< xml::sax::XFastAttributeList
> & Attribs
)
643 throw (uno::RuntimeException
, xml::sax::SAXException
);
645 virtual void attributes
646 (const uno::Reference
< xml::sax::XFastAttributeList
> & Attribs
)
647 throw (uno::RuntimeException
, xml::sax::SAXException
);
649 virtual ResourceEnum_t
getResource() const;
651 void addNamespace(const Id
& nId
);
653 virtual void newProperty(const Id
& rId
, OOXMLValue::Pointer_t pVal
);
654 virtual void setPropertySet(OOXMLPropertySet::Pointer_t pPropertySet
);
655 virtual OOXMLPropertySet::Pointer_t
getPropertySet() const;
657 virtual string
getType() const;
660 virtual void lcl_startFastElement
662 const uno::Reference
< xml::sax::XFastAttributeList
> & Attribs
)
663 throw (uno::RuntimeException
, xml::sax::SAXException
);
665 virtual void lcl_endFastElement(Token_t Element
)
666 throw (uno::RuntimeException
, xml::sax::SAXException
);
668 virtual uno::Reference
< xml::sax::XFastContextHandler
>
669 lcl_createFastChildContext
671 const uno::Reference
< xml::sax::XFastAttributeList
> & Attribs
)
672 throw (uno::RuntimeException
, xml::sax::SAXException
);
674 virtual void lcl_characters(const ::rtl::OUString
& aChars
)
675 throw (uno::RuntimeException
, xml::sax::SAXException
);
677 virtual void setId(Id nId
);
678 virtual Id
getId() const;
680 virtual void setToken(Token_t nToken
);
681 virtual Token_t
getToken() const;
684 uno::Reference
<XFastContextHandler
> mxContext
;
685 set
<Id
> mMyNamespaces
;
686 OOXMLPropertySet::Pointer_t mpPropertySet
;
688 OOXMLFastContextHandler
* getFastContextHandler() const;
691 #endif // INCLUDED_OOXML_FAST_CONTEXT_HANDLER_HXX