1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
23 #include <comphelper/servicehelper.hxx>
24 #include <com/sun/star/drawing/XShapes.hpp>
25 #include <com/sun/star/xml/sax/FastShapeContextHandler.hpp>
26 #include <resourcemodel/QNameToString.hxx>
27 #include <resourcemodel/XPathLogger.hxx>
28 #include <resourcemodel/util.hxx>
29 #include <ooxml/resourceids.hxx>
30 #include <oox/token/namespaces.hxx>
31 #include <ooxml/OOXMLnamespaceids.hxx>
32 #include <dmapper/DomainMapper.hxx>
33 #include <dmapper/GraphicHelpers.hxx>
34 #include <comphelper/embeddedobjectcontainer.hxx>
35 #include <tools/globname.hxx>
36 #include <comphelper/classids.hxx>
37 #include <sfx2/sfxbasemodel.hxx>
38 #include "OOXMLFastContextHandler.hxx"
39 #include "OOXMLFactory.hxx"
40 #include "Handler.hxx"
41 #include "ooxmlLoggers.hxx"
43 static const sal_Unicode uCR
= 0xd;
44 static const sal_Unicode uFtnEdnRef
= 0x2;
45 static const sal_Unicode uFtnEdnSep
= 0x3;
46 static const sal_Unicode uTab
= 0x9;
47 static const sal_Unicode uPgNum
= 0x0;
48 static const sal_Unicode uNoBreakHyphen
= 0x2011;
49 static const sal_Unicode uSoftHyphen
= 0xAD;
51 static const sal_uInt8 cFtnEdnCont
= 0x4;
52 static const sal_uInt8 cFieldStart
= 0x13;
53 static const sal_uInt8 cFieldSep
= 0x14;
54 static const sal_uInt8 cFieldEnd
= 0x15;
56 namespace writerfilter
{
59 using namespace ::com::sun::star
;
60 using namespace ::std
;
62 #if OSL_DEBUG_LEVEL > 1
63 static string resourceToString
64 (OOXMLFastContextHandler::ResourceEnum_t eResource
)
70 case OOXMLFastContextHandler::STREAM
:
73 case OOXMLFastContextHandler::PROPERTIES
:
74 sResult
= "Properties";
76 case OOXMLFastContextHandler::TABLE
:
79 case OOXMLFastContextHandler::SHAPE
:
90 set
<OOXMLFastContextHandler
*> aSetContexts
;
92 #if OSL_DEBUG_LEVEL > 1
93 class OOXMLIdToString
: public IdToString
96 OOXMLIdToString() : IdToString() {}
97 virtual ~OOXMLIdToString() {}
99 virtual string
toString(const Id
& rId
) const
101 string
s((*QNameToString::Instance())(rId
));
104 s
= "(fasttoken)" + fastTokenToId(rId
);
114 class OOXMLFastContextHandler
117 sal_uInt32
OOXMLFastContextHandler::mnInstanceCount
= 0;
119 OOXMLFastContextHandler::OOXMLFastContextHandler
120 (uno::Reference
< uno::XComponentContext
> const & context
)
124 mnToken(OOXML_FAST_TOKENS_END
),
127 mnInstanceNumber(mnInstanceCount
),
130 m_bDiscardChildren(false),
134 aSetContexts
.insert(this);
136 if (mpParserState
.get() == NULL
)
137 mpParserState
.reset(new OOXMLParserState());
139 mpParserState
->incContextCount();
142 OOXMLFastContextHandler::OOXMLFastContextHandler
143 (OOXMLFastContextHandler
* pContext
)
144 : cppu::WeakImplHelper1
<com::sun::star::xml::sax::XFastContextHandler
>(),
148 mnToken(OOXML_FAST_TOKENS_END
),
149 mpStream(pContext
->mpStream
),
150 mnTableDepth(pContext
->mnTableDepth
),
151 mnInstanceNumber(mnInstanceCount
),
152 inPositionV(pContext
->inPositionV
),
153 m_xContext(pContext
->m_xContext
),
154 m_bDiscardChildren(pContext
->m_bDiscardChildren
),
155 m_bTookChoice(pContext
->m_bTookChoice
),
156 m_aSavedAlternateStates(pContext
->m_aSavedAlternateStates
)
158 mpParserState
= pContext
->mpParserState
;
160 if (mpParserState
.get() == NULL
)
161 mpParserState
.reset(new OOXMLParserState());
164 aSetContexts
.insert(this);
165 mpParserState
->incContextCount();
168 OOXMLFastContextHandler::~OOXMLFastContextHandler()
170 aSetContexts
.erase(this);
173 bool OOXMLFastContextHandler::prepareMceContext(Token_t nElement
, const uno::Reference
<xml::sax::XFastAttributeList
>& rAttribs
)
175 switch (oox::getBaseToken(nElement
))
177 case OOXML_AlternateContent
:
179 SavedAlternateState aState
;
180 aState
.m_bDiscardChildren
= m_bDiscardChildren
;
181 m_bDiscardChildren
= false;
182 aState
.m_bTookChoice
= m_bTookChoice
;
183 m_bTookChoice
= false;
184 m_aSavedAlternateStates
.push_back(aState
);
189 OUString aRequires
= rAttribs
->getOptionalValue(OOXML_Requires
);
190 static const char* aFeatures
[] = {
194 for (size_t i
= 0; i
< SAL_N_ELEMENTS(aFeatures
); ++i
)
196 if (aRequires
.equalsAscii(aFeatures
[i
]))
198 m_bTookChoice
= true;
206 // If Choice is already taken, then let's ignore the Fallback.
207 return m_bTookChoice
;
210 SAL_WARN("writerfilter", "OOXMLFastContextHandler::prepareMceContext: unhandled element:" << oox::getBaseToken(nElement
));
216 // ::com::sun::star::xml::sax::XFastContextHandler:
217 void SAL_CALL
OOXMLFastContextHandler::startFastElement
219 const uno::Reference
< xml::sax::XFastAttributeList
> & Attribs
)
220 throw (uno::RuntimeException
, xml::sax::SAXException
, std::exception
)
222 #ifdef DEBUG_CONTEXT_HANDLER
223 debug_logger
->startElement("contexthandler.element");
224 string sToken
= fastTokenToId(Element
);
225 mpParserState
->getXPathLogger().startElement(sToken
);
226 debug_logger
->attribute("token", sToken
);
227 debug_logger
->attribute("type", getType());
228 debug_logger
->attribute("xpath", mpParserState
->getXPathLogger().getXPath());
229 debug_logger
->startElement("at-start");
230 dumpXml( debug_logger
);
231 debug_logger
->endElement();
233 if (oox::getNamespace(Element
) == static_cast<sal_Int32
>(NS_mce
))
234 m_bDiscardChildren
= prepareMceContext(Element
, Attribs
);
236 else if (!m_bDiscardChildren
)
239 lcl_startFastElement(Element
, Attribs
);
243 void SAL_CALL
OOXMLFastContextHandler::startUnknownElement
244 (const OUString
& Namespace
, const OUString
& Name
,
245 const uno::Reference
< xml::sax::XFastAttributeList
> & /*Attribs*/)
246 throw (uno::RuntimeException
, xml::sax::SAXException
, std::exception
)
248 #ifdef DEBUG_CONTEXT_HANDLER
249 debug_logger
->startElement("contexthandler.unknown-element");
250 debug_logger
->attribute("namespace", Namespace
);
251 debug_logger
->attribute("name", Name
);
252 mpParserState
->getXPathLogger().startElement("unknown");
259 void SAL_CALL
OOXMLFastContextHandler::endFastElement(Token_t Element
)
260 throw (uno::RuntimeException
, xml::sax::SAXException
, std::exception
)
262 #ifdef DEBUG_CONTEXT_HANDLER
263 string sToken
= fastTokenToId(Element
);
267 if (Element
== (NS_mce
| OOXML_Choice
) || Element
== (NS_mce
| OOXML_Fallback
))
268 m_bDiscardChildren
= false;
269 else if (Element
== (NS_mce
| OOXML_AlternateContent
))
271 SavedAlternateState
aState(m_aSavedAlternateStates
.back());
272 m_aSavedAlternateStates
.pop_back();
273 m_bDiscardChildren
= aState
.m_bDiscardChildren
;
274 m_bTookChoice
= aState
.m_bTookChoice
;
277 else if (!m_bDiscardChildren
)
278 lcl_endFastElement(Element
);
280 #ifdef DEBUG_CONTEXT_HANDLER
281 debug_logger
->startElement("at-end");
282 dumpXml( debug_logger
);
283 debug_logger
->endElement();
284 debug_logger
->endElement();
285 mpParserState
->getXPathLogger().endElement();
289 void OOXMLFastContextHandler::lcl_startFastElement
291 const uno::Reference
< xml::sax::XFastAttributeList
> & /*Attribs*/)
292 throw (uno::RuntimeException
, xml::sax::SAXException
)
294 OOXMLFactory::getInstance()->startAction(this, Element
);
295 if( Element
== (NS_wordprocessingDrawing
|OOXML_positionV
) )
297 else if( Element
== (NS_wordprocessingDrawing
|OOXML_positionH
) )
302 void OOXMLFastContextHandler::lcl_endFastElement
304 throw (uno::RuntimeException
, xml::sax::SAXException
)
306 OOXMLFactory::getInstance()->endAction(this, Element
);
309 void SAL_CALL
OOXMLFastContextHandler::endUnknownElement
310 (const OUString
& , const OUString
& )
311 throw (uno::RuntimeException
, xml::sax::SAXException
, std::exception
)
313 #ifdef DEBUG_CONTEXT_HANDLER
314 debug_logger
->endElement();
315 mpParserState
->getXPathLogger().endElement();
319 uno::Reference
< xml::sax::XFastContextHandler
> SAL_CALL
320 OOXMLFastContextHandler::createFastChildContext
322 const uno::Reference
< xml::sax::XFastAttributeList
> & Attribs
)
323 throw (uno::RuntimeException
, xml::sax::SAXException
, std::exception
)
325 #ifdef DEBUG_CONTEXT_HANDLER
326 debug_logger
->startElement("contexthandler.createFastChildContext");
327 debug_logger
->attribute("token", fastTokenToId(Element
));
328 debug_logger
->attribute("type", getType());
329 debug_logger
->attribute("discard-children", OUString::number(m_bDiscardChildren
));
332 uno::Reference
< xml::sax::XFastContextHandler
> xResult
;
333 if ((Element
& 0xffff0000) != NS_mce
&& !m_bDiscardChildren
)
334 xResult
.set(lcl_createFastChildContext(Element
, Attribs
));
335 else if ((Element
& 0xffff0000) == NS_mce
)
338 #ifdef DEBUG_CONTEXT_HANDLER
339 debug_logger
->endElement();
345 uno::Reference
< xml::sax::XFastContextHandler
>
346 OOXMLFastContextHandler::lcl_createFastChildContext
348 const uno::Reference
< xml::sax::XFastAttributeList
> & /*Attribs*/)
349 throw (uno::RuntimeException
, xml::sax::SAXException
)
351 return OOXMLFactory::getInstance()->createFastChildContext(this, Element
);
354 uno::Reference
< xml::sax::XFastContextHandler
> SAL_CALL
355 OOXMLFastContextHandler::createUnknownChildContext
356 (const OUString
& Namespace
,
357 const OUString
& Name
,
358 const uno::Reference
< xml::sax::XFastAttributeList
> & /*Attribs*/)
359 throw (uno::RuntimeException
, xml::sax::SAXException
, std::exception
)
361 #ifdef DEBUG_CONTEXT_HANDLER
362 debug_logger
->startElement("contexthandler.createUnknownChildContext");
363 debug_logger
->attribute("namespace", Namespace
);
364 debug_logger
->attribute("name", Name
);
365 debug_logger
->endElement();
371 return uno::Reference
< xml::sax::XFastContextHandler
>
372 (new OOXMLFastContextHandler(*const_cast<const OOXMLFastContextHandler
*>(this)));
375 void SAL_CALL
OOXMLFastContextHandler::characters
376 (const OUString
& aChars
)
377 throw (uno::RuntimeException
, xml::sax::SAXException
, std::exception
)
379 lcl_characters(aChars
);
382 void OOXMLFastContextHandler::lcl_characters
383 (const OUString
& rString
)
384 throw (uno::RuntimeException
, xml::sax::SAXException
)
386 if (!m_bDiscardChildren
)
387 OOXMLFactory::getInstance()->characters(this, rString
);
392 class theOOXMLFastContextHandlerUnoTunnelId
: public rtl::Static
< UnoTunnelIdInit
, theOOXMLFastContextHandlerUnoTunnelId
> {};
395 const uno::Sequence
< sal_Int8
> & OOXMLFastContextHandler::getUnoTunnelId()
397 return theOOXMLFastContextHandlerUnoTunnelId::get().getSeq();
400 sal_Int64 SAL_CALL
OOXMLFastContextHandler::getSomething( const uno::Sequence
< sal_Int8
>& rId
)
401 throw(uno::RuntimeException
)
403 if( rId
.getLength() == 16
404 && 0 == memcmp( getUnoTunnelId().getConstArray(),
405 rId
.getConstArray(), 16 ) )
407 return sal::static_int_cast
<sal_Int64
>
408 (reinterpret_cast<sal_IntPtr
>(this));
414 void OOXMLFastContextHandler::setStream(Stream
* pStream
)
419 OOXMLValue::Pointer_t
OOXMLFastContextHandler::getValue() const
421 return OOXMLValue::Pointer_t();
424 void OOXMLFastContextHandler::attributes
425 (const uno::Reference
< xml::sax::XFastAttributeList
> & Attribs
)
426 throw (uno::RuntimeException
, xml::sax::SAXException
)
428 OOXMLFactory::getInstance()->attributes(this, Attribs
);
431 void OOXMLFastContextHandler::startAction(Token_t Element
)
433 #ifdef DEBUG_CONTEXT_HANDLER
434 debug_logger
->startElement("contexthandler.startAction");
436 lcl_startAction(Element
);
437 #ifdef DEBUG_CONTEXT_HANDLER
438 debug_logger
->endElement();
442 void OOXMLFastContextHandler::lcl_startAction(Token_t Element
)
444 OOXMLFactory::getInstance()->startAction(this, Element
);
447 void OOXMLFastContextHandler::endAction(Token_t Element
)
449 #ifdef DEBUG_CONTEXT_HANDLER
450 debug_logger
->startElement("contexthandler.endAction");
452 lcl_endAction(Element
);
453 #ifdef DEBUG_CONTEXT_HANDLER
454 debug_logger
->endElement();
458 void OOXMLFastContextHandler::lcl_endAction(Token_t Element
)
460 OOXMLFactory::getInstance()->endAction(this, Element
);
463 #if OSL_DEBUG_LEVEL > 1
464 void OOXMLFastContextHandler::dumpXml( const TagLogger::Pointer_t pLogger
) const
466 pLogger
->startElement("context");
468 static char sBuffer
[128];
469 snprintf(sBuffer
, sizeof(sBuffer
), "%p", this);
471 pLogger
->attribute("parent", std::string(sBuffer
));
472 pLogger
->attribute("type", getType());
473 pLogger
->attribute("resource", resourceToString(getResource()));
474 pLogger
->attribute("token", fastTokenToId(getToken()));
475 pLogger
->attribute("id", (*QNameToString::Instance())(getId()));
477 OOXMLValue::Pointer_t
pVal(getValue());
479 if (pVal
.get() != NULL
)
480 pLogger
->attribute("value", pVal
->toString());
482 pLogger
->attribute("value", std::string("(null)"));
484 pLogger
->propertySet(getPropertySet(),
485 IdToString::Pointer_t(new OOXMLIdToString()));
487 mpParserState
->dumpXml( pLogger
);
489 pLogger
->endElement();
494 void OOXMLFastContextHandler::setId(Id rId
)
496 #ifdef DEBUG_CONTEXT_HANDLER
497 debug_logger
->startElement("contexthandler.setId");
499 static char sBuffer
[256];
500 snprintf(sBuffer
, sizeof(sBuffer
), "%" SAL_PRIuUINT32
, rId
);
502 debug_logger
->attribute("id", std::string(sBuffer
));
503 debug_logger
->attribute("name", (*QNameToString::Instance())(rId
));
504 debug_logger
->endElement();
510 Id
OOXMLFastContextHandler::getId() const
515 void OOXMLFastContextHandler::setDefine(Id nDefine
)
520 Id
OOXMLFastContextHandler::getDefine() const
525 OOXMLParserState::Pointer_t
OOXMLFastContextHandler::getParserState() const
527 return mpParserState
;
530 void OOXMLFastContextHandler::setToken(Token_t nToken
)
534 #ifdef DEBUG_CONTEXT_HANDLER
535 msTokenString
= fastTokenToId(mnToken
);
539 Token_t
OOXMLFastContextHandler::getToken() const
544 void OOXMLFastContextHandler::setParent
545 (OOXMLFastContextHandler
* pParent
)
550 OOXMLPropertySet
* OOXMLFastContextHandler::getPicturePropSet
551 (const OUString
& rId
)
553 return mpParserState
->getDocument()->getPicturePropSet(rId
);
556 void OOXMLFastContextHandler::sendTableDepth() const
558 #ifdef DEBUG_CONTEXT_HANDLER
559 debug_logger
->startElement("contexthandler.sendTableDepth");
562 if (mnTableDepth
> 0)
564 OOXMLPropertySet
* pProps
= new OOXMLPropertySetImpl();
566 OOXMLValue::Pointer_t pVal
567 (new OOXMLIntegerValue(mnTableDepth
));
568 OOXMLProperty::Pointer_t pProp
569 (new OOXMLPropertyImpl(NS_ooxml::LN_tblDepth
, pVal
, OOXMLPropertyImpl::SPRM
));
573 OOXMLValue::Pointer_t pVal
574 (new OOXMLIntegerValue(1));
575 OOXMLProperty::Pointer_t pProp
576 (new OOXMLPropertyImpl(NS_ooxml::LN_inTbl
, pVal
, OOXMLPropertyImpl::SPRM
));
580 mpStream
->props(writerfilter::Reference
<Properties
>::Pointer_t(pProps
));
582 #ifdef DEBUG_CONTEXT_HANDLER
583 debug_logger
->endElement();
587 void OOXMLFastContextHandler::setHandle()
589 mpParserState
->setHandle();
590 mpStream
->info(mpParserState
->getHandle());
593 void OOXMLFastContextHandler::startCharacterGroup()
595 #ifdef DEBUG_CONTEXT_HANDLER
596 debug_logger
->element("contexthandler.startCharacterGroup");
599 if (isForwardEvents())
601 if (mpParserState
->isInCharacterGroup())
604 if (! mpParserState
->isInParagraphGroup())
605 startParagraphGroup();
607 if (! mpParserState
->isInCharacterGroup())
609 mpStream
->startCharacterGroup();
610 mpParserState
->setInCharacterGroup(true);
611 mpParserState
->resolveCharacterProperties(*mpStream
);
616 void OOXMLFastContextHandler::endCharacterGroup()
618 #ifdef DEBUG_CONTEXT_HANDLER
619 debug_logger
->element("contexthandler.endCharacterGroup");
622 if (isForwardEvents() && mpParserState
->isInCharacterGroup())
624 mpStream
->endCharacterGroup();
625 mpParserState
->setInCharacterGroup(false);
629 void OOXMLFastContextHandler::startParagraphGroup()
631 #ifdef DEBUG_CONTEXT_HANDLER
632 debug_logger
->element("contexthandler.startParagraphGroup");
635 if (isForwardEvents())
637 if (mpParserState
->isInParagraphGroup())
640 if (! mpParserState
->isInSectionGroup())
643 if (! mpParserState
->isInParagraphGroup())
645 mpStream
->startParagraphGroup();
646 mpParserState
->setInParagraphGroup(true);
651 void OOXMLFastContextHandler::endParagraphGroup()
653 #ifdef DEBUG_CONTEXT_HANDLER
654 debug_logger
->element("contexthandler.endParagraphGroup");
657 if (isForwardEvents())
659 if (mpParserState
->isInCharacterGroup())
662 if (mpParserState
->isInParagraphGroup())
664 mpStream
->endParagraphGroup();
665 mpParserState
->setInParagraphGroup(false);
670 void OOXMLFastContextHandler::startSdt()
672 #ifdef DEBUG_CONTEXT_HANDLER
673 debug_logger
->element("contexthandler.startSdt");
676 OOXMLPropertySet
* pProps
= new OOXMLPropertySetImpl();
677 OOXMLValue::Pointer_t
pVal(new OOXMLIntegerValue(1));
678 OOXMLProperty::Pointer_t
pProp(new OOXMLPropertyImpl(NS_ooxml::LN_CT_SdtBlock_sdtContent
, pVal
, OOXMLPropertyImpl::ATTRIBUTE
));
680 mpStream
->props(writerfilter::Reference
<Properties
>::Pointer_t(pProps
));
683 void OOXMLFastContextHandler::endSdt()
685 #ifdef DEBUG_CONTEXT_HANDLER
686 debug_logger
->element("contexthandler.endSdt");
689 OOXMLPropertySet
* pProps
= new OOXMLPropertySetImpl();
690 OOXMLValue::Pointer_t
pVal(new OOXMLIntegerValue(1));
691 OOXMLProperty::Pointer_t
pProp(new OOXMLPropertyImpl(NS_ooxml::LN_CT_SdtBlock_sdtEndContent
, pVal
, OOXMLPropertyImpl::ATTRIBUTE
));
693 mpStream
->props(writerfilter::Reference
<Properties
>::Pointer_t(pProps
));
696 void OOXMLFastContextHandler::startSectionGroup()
698 #ifdef DEBUG_CONTEXT_HANDLER
699 debug_logger
->element("contexthandler.startSectionGroup");
702 if (isForwardEvents())
704 if (mpParserState
->isInSectionGroup())
707 if (! mpParserState
->isInSectionGroup())
709 mpStream
->info(mpParserState
->getHandle());
710 mpStream
->startSectionGroup();
711 mpParserState
->setInSectionGroup(true);
716 void OOXMLFastContextHandler::endSectionGroup()
718 #ifdef DEBUG_CONTEXT_HANDLER
719 debug_logger
->element("contexthandler.endSectionGroup");
722 if (isForwardEvents())
724 if (mpParserState
->isInParagraphGroup())
727 if (mpParserState
->isInSectionGroup())
729 mpStream
->endSectionGroup();
730 mpParserState
->setInSectionGroup(false);
735 void OOXMLFastContextHandler::setLastParagraphInSection()
737 mpParserState
->setLastParagraphInSection(true);
738 mpStream
->markLastParagraphInSection( );
741 void OOXMLFastContextHandler::setLastSectionGroup()
743 mpStream
->markLastSectionGroup( );
746 void OOXMLFastContextHandler::newProperty
747 (const Id
& /*nId*/, OOXMLValue::Pointer_t
/*pVal*/)
751 void OOXMLFastContextHandler::setPropertySet
752 (OOXMLPropertySet::Pointer_t
/* pPropertySet */)
756 OOXMLPropertySet::Pointer_t
OOXMLFastContextHandler::getPropertySet() const
758 return OOXMLPropertySet::Pointer_t();
761 void OOXMLFastContextHandler::startField()
763 #ifdef DEBUG_CONTEXT_HANDLER
764 debug_logger
->element("contexthandler.startField");
766 startCharacterGroup();
767 if (isForwardEvents())
768 mpStream
->text(&cFieldStart
, 1);
772 void OOXMLFastContextHandler::fieldSeparator()
774 #ifdef DEBUG_CONTEXT_HANDLER
775 debug_logger
->element("contexthandler.fieldSeparator");
777 startCharacterGroup();
778 if (isForwardEvents())
779 mpStream
->text(&cFieldSep
, 1);
783 void OOXMLFastContextHandler::endField()
785 #ifdef DEBUG_CONTEXT_HANDLER
786 debug_logger
->element("contexthandler.endField");
788 startCharacterGroup();
789 if (isForwardEvents())
790 mpStream
->text(&cFieldEnd
, 1);
794 void OOXMLFastContextHandler::ftnednref()
796 #ifdef DEBUG_CONTEXT_HANDLER
797 debug_logger
->element("contexthandler.ftnednref");
799 if (isForwardEvents())
800 mpStream
->utext((const sal_uInt8
*)&uFtnEdnRef
, 1);
803 void OOXMLFastContextHandler::ftnednsep()
805 #ifdef DEBUG_CONTEXT_HANDLER
806 debug_logger
->element("contexthandler.ftnednsep");
808 if (isForwardEvents())
809 mpStream
->utext((const sal_uInt8
*)&uFtnEdnSep
, 1);
812 void OOXMLFastContextHandler::ftnedncont()
814 #ifdef DEBUG_CONTEXT_HANDLER
815 debug_logger
->element("contexthandler.ftnedncont");
817 if (isForwardEvents())
818 mpStream
->text(&cFtnEdnCont
, 1);
821 void OOXMLFastContextHandler::pgNum()
823 #ifdef DEBUG_CONTEXT_HANDLER
824 debug_logger
->element("contexthandler.pgNum");
826 if (isForwardEvents())
827 mpStream
->utext((const sal_uInt8
*)&uPgNum
, 1);
830 void OOXMLFastContextHandler::tab()
832 #ifdef DEBUG_CONTEXT_HANDLER
833 debug_logger
->element("contexthandler.tab");
835 if (isForwardEvents())
836 mpStream
->utext((const sal_uInt8
*)&uTab
, 1);
839 void OOXMLFastContextHandler::cr()
841 #ifdef DEBUG_CONTEXT_HANDLER
842 debug_logger
->element("contexthandler.cr");
844 if (isForwardEvents())
845 mpStream
->utext((const sal_uInt8
*)&uCR
, 1);
848 void OOXMLFastContextHandler::noBreakHyphen()
850 #ifdef DEBUG_CONTEXT_HANDLER
851 debug_logger
->element("contexthandler.noBreakHyphen");
853 if (isForwardEvents())
854 mpStream
->utext((const sal_uInt8
*)&uNoBreakHyphen
, 1);
857 void OOXMLFastContextHandler::softHyphen()
859 #ifdef DEBUG_CONTEXT_HANDLER
860 debug_logger
->element("contexthandler.softHyphen");
862 if (isForwardEvents())
863 mpStream
->utext((const sal_uInt8
*)&uSoftHyphen
, 1);
866 void OOXMLFastContextHandler::handleLastParagraphInSection()
868 #ifdef DEBUG_CONTEXT_HANDLER
869 debug_logger
->element("contexthandler.handleLastParagraphInSection");
872 if (mpParserState
->isLastParagraphInSection())
874 mpParserState
->setLastParagraphInSection(false);
879 void OOXMLFastContextHandler::endOfParagraph()
881 #ifdef DEBUG_CONTEXT_HANDLER
882 debug_logger
->element("contexthandler.endOfParagraph");
884 if (! mpParserState
->isInCharacterGroup())
885 startCharacterGroup();
886 if (isForwardEvents())
887 mpStream
->utext((const sal_uInt8
*)&uCR
, 1);
889 mpParserState
->getDocument()->incrementProgress();
892 void OOXMLFastContextHandler::startTxbxContent()
894 #ifdef DEBUG_CONTEXT_HANDLER
895 debug_logger
->element("contexthandler.startTxbxContent");
898 This usually means there are recursive <w:p> elements, and the ones
899 inside and outside of w:txbxContent should not interfere (e.g.
900 the lastParagraphInSection setting). So save the whole state
901 and possibly start new groups for the nested content (not section
902 group though, as that'd cause the txbxContent to be moved onto
903 another page, I'm not sure how that should work exactly).
905 mpParserState
->startTxbxContent();
906 startParagraphGroup();
909 void OOXMLFastContextHandler::endTxbxContent()
911 #ifdef DEBUG_CONTEXT_HANDLER
912 debug_logger
->element("contexthandler.endTxbxContent");
915 mpParserState
->endTxbxContent();
918 void OOXMLFastContextHandler::text(const OUString
& sText
)
920 #ifdef DEBUG_CONTEXT_HANDLER
921 debug_logger
->startElement("contexthandler.text");
922 debug_logger
->chars(sText
);
923 debug_logger
->endElement();
925 if (isForwardEvents())
926 mpStream
->utext(reinterpret_cast < const sal_uInt8
* >
932 HACK. An ugly hack. The problem with wp:positionOffset, wp:alignV and wp:alignH
933 is that they do not work in the usual OOXML way of <tag val="value"/> but instead
934 it's <tag>value</tag>, which is otherwise used only things like <t>. And I really
935 haven't managed to find out how to make this XML parsing monstrosity to handle this
936 on its own, so the code is modelled after <t> handling and does it manually in a hackish
937 way - it reads the value as text and converts itself, moreover the reading of the value
938 is done sooner than lcl_sprms() actually results in processing the tags it is enclosed
939 in, so the values are stored in PositionHandler for later use.
941 void OOXMLFastContextHandler::positionOffset(const OUString
& sText
)
944 debug_logger
->startElement("positionOffset");
945 debug_logger
->chars(sText
);
946 debug_logger
->endElement();
948 if (isForwardEvents())
949 ::writerfilter::dmapper::PositionHandler::setPositionOffset( sText
, inPositionV
);
952 void OOXMLFastContextHandler::alignH(const OUString
& sText
)
955 debug_logger
->startElement("alignH");
956 debug_logger
->chars(sText
);
957 debug_logger
->endElement();
959 if (isForwardEvents())
960 ::writerfilter::dmapper::PositionHandler::setAlignH( sText
);
963 void OOXMLFastContextHandler::alignV(const OUString
& sText
)
966 debug_logger
->startElement("alignV");
967 debug_logger
->chars(sText
);
968 debug_logger
->endElement();
970 if (isForwardEvents())
971 ::writerfilter::dmapper::PositionHandler::setAlignV( sText
);
974 void OOXMLFastContextHandler::positivePercentage(const OUString
& rText
)
977 debug_logger
->startElement("positivePercentage");
978 debug_logger
->chars(rText
);
979 debug_logger
->endElement();
981 if (isForwardEvents())
982 mpStream
->positivePercentage(rText
);
985 void OOXMLFastContextHandler::propagateCharacterProperties()
987 #ifdef DEBUG_CONTEXT_HANDLER
988 debug_logger
->startElement("contexthandler.propagateCharacterProperties");
989 debug_logger
->propertySet(getPropertySet(),
990 IdToString::Pointer_t(new OOXMLIdToString()));
991 debug_logger
->endElement();
994 mpParserState
->setCharacterProperties(getPropertySet());
997 void OOXMLFastContextHandler::propagateCharacterPropertiesAsSet(const Id
& rId
)
999 #ifdef DEBUG_CONTEXT_HANDLER
1000 debug_logger
->startElement("contexthandler.propagateCharacterPropertiesAsSet");
1001 debug_logger
->propertySet(getPropertySet(),
1002 IdToString::Pointer_t(new OOXMLIdToString()));
1003 debug_logger
->endElement();
1006 OOXMLValue::Pointer_t
pValue(new OOXMLPropertySetValue(getPropertySet()));
1007 OOXMLPropertySet::Pointer_t
pPropertySet(new OOXMLPropertySetImpl());
1009 OOXMLProperty::Pointer_t pProp
1010 (new OOXMLPropertyImpl(rId
, pValue
, OOXMLPropertyImpl::SPRM
));
1012 pPropertySet
->add(pProp
);
1013 mpParserState
->setCharacterProperties(pPropertySet
);
1016 bool OOXMLFastContextHandler::propagatesProperties() const
1021 void OOXMLFastContextHandler::propagateCellProperties()
1023 #ifdef DEBUG_CONTEXT_HANDLER
1024 debug_logger
->element("contexthandler.propagateCellProperties");
1027 mpParserState
->setCellProperties(getPropertySet());
1030 void OOXMLFastContextHandler::propagateRowProperties()
1032 #ifdef DEBUG_CONTEXT_HANDLER
1033 debug_logger
->element("contexthandler.propagateRowProperties");
1036 mpParserState
->setRowProperties(getPropertySet());
1039 void OOXMLFastContextHandler::propagateTableProperties()
1041 OOXMLPropertySet::Pointer_t pProps
= getPropertySet();
1042 #ifdef DEBUG_CONTEXT_HANDLER
1043 debug_logger
->startElement("contexthandler.propagateTableProperties");
1044 debug_logger
->propertySet(getPropertySet(),
1045 IdToString::Pointer_t(new OOXMLIdToString()));
1046 debug_logger
->endElement();
1049 mpParserState
->setTableProperties(pProps
);
1052 void OOXMLFastContextHandler::sendCellProperties()
1054 #ifdef DEBUG_CONTEXT_HANDLER
1055 debug_logger
->startElement("contexthandler.sendCellProperties");
1058 mpParserState
->resolveCellProperties(*mpStream
);
1060 #ifdef DEBUG_CONTEXT_HANDLER
1061 debug_logger
->endElement();
1065 void OOXMLFastContextHandler::sendRowProperties()
1067 #ifdef DEBUG_CONTEXT_HANDLER
1068 debug_logger
->startElement("contexthandler.sendRowProperties");
1071 mpParserState
->resolveRowProperties(*mpStream
);
1073 #ifdef DEBUG_CONTEXT_HANDLER
1074 debug_logger
->endElement();
1078 void OOXMLFastContextHandler::sendTableProperties()
1080 #ifdef DEBUG_CONTEXT_HANDLER
1081 debug_logger
->startElement("contexthandler.sendTableProperties");
1084 mpParserState
->resolveTableProperties(*mpStream
);
1086 #ifdef DEBUG_CONTEXT_HANDLER
1087 debug_logger
->endElement();
1091 void OOXMLFastContextHandler::clearTableProps()
1093 #ifdef DEBUG_CONTEXT_HANDLER
1094 debug_logger
->element("contexthandler.clearTableProps");
1097 mpParserState
->setTableProperties(OOXMLPropertySet::Pointer_t
1098 (new OOXMLPropertySetImpl()));
1101 void OOXMLFastContextHandler::sendPropertiesWithId(const Id
& rId
)
1103 #ifdef DEBUG_CONTEXT_HANDLER
1104 debug_logger
->startElement("contexthandler.sendPropertiesWithId");
1105 debug_logger
->attribute("id", fastTokenToId(rId
));
1108 OOXMLValue::Pointer_t
pValue(new OOXMLPropertySetValue(getPropertySet()));
1109 OOXMLPropertySet::Pointer_t
pPropertySet(new OOXMLPropertySetImpl());
1111 OOXMLProperty::Pointer_t pProp
1112 (new OOXMLPropertyImpl(rId
, pValue
, OOXMLPropertyImpl::SPRM
));
1114 pPropertySet
->add(pProp
);
1115 mpStream
->props(pPropertySet
);
1117 #ifdef DEBUG_CONTEXT_HANDLER
1118 debug_logger
->propertySet(getPropertySet(),
1119 IdToString::Pointer_t(new OOXMLIdToString()));
1120 debug_logger
->endElement();
1124 void OOXMLFastContextHandler::clearProps()
1126 #ifdef DEBUG_CONTEXT_HANDLER
1127 debug_logger
->element("contexthandler.clearProps");
1130 setPropertySet(OOXMLPropertySet::Pointer_t(new OOXMLPropertySetImpl()));
1133 void OOXMLFastContextHandler::setDefaultBooleanValue()
1137 void OOXMLFastContextHandler::setDefaultIntegerValue()
1141 void OOXMLFastContextHandler::setDefaultHexValue()
1145 void OOXMLFastContextHandler::setDefaultStringValue()
1149 void OOXMLFastContextHandler::setDocument(OOXMLDocumentImpl
* pDocument
)
1151 mpParserState
->setDocument(pDocument
);
1154 OOXMLDocumentImpl
* OOXMLFastContextHandler::getDocument()
1156 return mpParserState
->getDocument();
1159 void OOXMLFastContextHandler::setForwardEvents(bool bForwardEvents
)
1161 #ifdef DEBUG_CONTEXT_HANDLER
1162 debug_logger
->startElement("contexthandler.setForwardEvents");
1165 debug_logger
->chars(std::string("true"));
1167 debug_logger
->chars(std::string("false"));
1169 debug_logger
->endElement();
1172 mpParserState
->setForwardEvents(bForwardEvents
);
1175 bool OOXMLFastContextHandler::isForwardEvents() const
1177 return mpParserState
->isForwardEvents();
1180 void OOXMLFastContextHandler::setXNoteId(const sal_Int32 nId
)
1182 mpParserState
->setXNoteId(nId
);
1185 void OOXMLFastContextHandler::setXNoteId(OOXMLValue::Pointer_t pValue
)
1187 mpParserState
->setXNoteId(sal_Int32(pValue
->getInt()));
1190 sal_Int32
OOXMLFastContextHandler::getXNoteId() const
1192 return mpParserState
->getXNoteId();
1195 void OOXMLFastContextHandler::resolveFootnote
1196 (const sal_Int32 nId
)
1198 mpParserState
->getDocument()->resolveFootnote
1199 (*mpStream
, 0, nId
);
1202 void OOXMLFastContextHandler::resolveEndnote(const sal_Int32 nId
)
1204 mpParserState
->getDocument()->resolveEndnote
1205 (*mpStream
, 0, nId
);
1208 void OOXMLFastContextHandler::resolveComment(const sal_Int32 nId
)
1210 mpParserState
->getDocument()->resolveComment(*mpStream
, nId
);
1213 void OOXMLFastContextHandler::resolvePicture(const OUString
& rId
)
1215 mpParserState
->getDocument()->resolvePicture(*mpStream
, rId
);
1218 void OOXMLFastContextHandler::resolveHeader
1219 (const sal_Int32 type
, const OUString
& rId
)
1221 mpParserState
->getDocument()->resolveHeader(*mpStream
, type
, rId
);
1224 void OOXMLFastContextHandler::resolveFooter
1225 (const sal_Int32 type
, const OUString
& rId
)
1227 mpParserState
->getDocument()->resolveFooter(*mpStream
, type
, rId
);
1230 // Add the data pointed to by the reference as another property.
1231 void OOXMLFastContextHandler::resolveData(const OUString
& rId
)
1233 OOXMLDocument
* objDocument
= getDocument();
1234 SAL_WARN_IF(!objDocument
, "writerfilter", "no document to resolveData");
1238 uno::Reference
<io::XInputStream
> xInputStream
1239 (objDocument
->getInputStreamForId(rId
));
1241 OOXMLValue::Pointer_t
aValue(new OOXMLInputStreamValue(xInputStream
));
1243 newProperty(NS_ooxml::LN_inputstream
, aValue
);
1246 OUString
OOXMLFastContextHandler::getTargetForId
1247 (const OUString
& rId
)
1249 return mpParserState
->getDocument()->getTargetForId(rId
);
1252 void OOXMLFastContextHandler::resolvePropertySetAttrs()
1256 void OOXMLFastContextHandler::sendPropertyToParent()
1258 #ifdef DEBUG_CONTEXT_HANDLER
1259 debug_logger
->element("sendPropertyToParent");
1262 if (mpParent
!= NULL
)
1264 OOXMLPropertySet::Pointer_t
pProps(mpParent
->getPropertySet());
1266 if (pProps
.get() != NULL
)
1268 OOXMLProperty::Pointer_t
1269 pProp(new OOXMLPropertyImpl(mId
, getValue(),
1270 OOXMLPropertyImpl::SPRM
));
1276 void OOXMLFastContextHandler::sendPropertiesToParent()
1278 #ifdef DEBUG_CONTEXT_HANDLER
1279 debug_logger
->startElement("contexthandler.sendPropertiesToParent");
1281 if (mpParent
!= NULL
)
1283 OOXMLPropertySet::Pointer_t
pParentProps(mpParent
->getPropertySet());
1285 if (pParentProps
.get() != NULL
)
1287 OOXMLPropertySet::Pointer_t
pProps(getPropertySet());
1289 if (pProps
.get() != NULL
)
1291 OOXMLValue::Pointer_t pValue
1292 (new OOXMLPropertySetValue(getPropertySet()));
1294 OOXMLProperty::Pointer_t pProp
1295 (new OOXMLPropertyImpl(getId(), pValue
, OOXMLPropertyImpl::SPRM
));
1298 pParentProps
->add(pProp
);
1303 #ifdef DEBUG_CONTEXT_HANDLER
1304 debug_logger
->endElement();
1308 uno::Reference
< uno::XComponentContext
>
1309 OOXMLFastContextHandler::getComponentContext()
1315 class OOXMLFastContextHandlerStream
1318 OOXMLFastContextHandlerStream::OOXMLFastContextHandlerStream
1319 (OOXMLFastContextHandler
* pContext
)
1320 : OOXMLFastContextHandler(pContext
),
1321 mpPropertySetAttrs(new OOXMLPropertySetImpl())
1325 OOXMLFastContextHandlerStream::~OOXMLFastContextHandlerStream()
1329 void OOXMLFastContextHandlerStream::newProperty(const Id
& rId
,
1330 OOXMLValue::Pointer_t pVal
)
1334 OOXMLPropertyImpl::Pointer_t pProperty
1335 (new OOXMLPropertyImpl(rId
, pVal
, OOXMLPropertyImpl::ATTRIBUTE
));
1337 mpPropertySetAttrs
->add(pProperty
);
1341 void OOXMLFastContextHandlerStream::sendProperty(Id nId
)
1343 #ifdef DEBUG_CONTEXT_HANDLER
1344 debug_logger
->startElement("contexthandler.sendProperty");
1345 debug_logger
->attribute("id", (*QNameToString::Instance())(nId
));
1346 debug_logger
->chars(xmlify(getPropertySetAttrs()->toString()));
1347 debug_logger
->endElement();
1350 OOXMLPropertySetEntryToString
aHandler(nId
);
1351 getPropertySetAttrs()->resolve(aHandler
);
1352 const OUString
& sText
= aHandler
.getString();
1353 mpStream
->utext(reinterpret_cast < const sal_uInt8
* >
1358 OOXMLPropertySet::Pointer_t
1359 OOXMLFastContextHandlerStream::getPropertySetAttrs() const
1361 return mpPropertySetAttrs
;
1364 void OOXMLFastContextHandlerStream::resolvePropertySetAttrs()
1366 #ifdef DEBUG_CONTEXT_HANDLER
1367 debug_logger
->startElement("contexthandler.resolvePropertySetAttrs");
1368 debug_logger
->chars(mpPropertySetAttrs
->toString());
1369 debug_logger
->endElement();
1371 mpStream
->props(mpPropertySetAttrs
);
1374 OOXMLPropertySet::Pointer_t
OOXMLFastContextHandlerStream::getPropertySet()
1377 return getPropertySetAttrs();
1380 void OOXMLFastContextHandlerStream::handleHyperlink()
1382 OOXMLHyperlinkHandler
aHyperlinkHandler(this);
1383 getPropertySetAttrs()->resolve(aHyperlinkHandler
);
1387 class OOXMLFastContextHandlerProperties
1389 OOXMLFastContextHandlerProperties::OOXMLFastContextHandlerProperties
1390 (OOXMLFastContextHandler
* pContext
)
1391 : OOXMLFastContextHandler(pContext
), mpPropertySet(new OOXMLPropertySetImpl()),
1394 if (pContext
->getResource() == STREAM
)
1398 OOXMLFastContextHandlerProperties::~OOXMLFastContextHandlerProperties()
1402 void OOXMLFastContextHandlerProperties::lcl_endFastElement
1404 throw (uno::RuntimeException
, xml::sax::SAXException
)
1410 if (isForwardEvents())
1412 mpStream
->props(mpPropertySet
);
1417 sendPropertiesToParent();
1421 OOXMLValue::Pointer_t
OOXMLFastContextHandlerProperties::getValue() const
1423 return OOXMLValue::Pointer_t(new OOXMLPropertySetValue(mpPropertySet
));
1426 #if OSL_DEBUG_LEVEL > 1
1427 void OOXMLFastContextHandlerProperties::dumpXml( const TagLogger::Pointer_t pLogger
) const
1429 pLogger
->startElement("context");
1431 static char sBuffer
[128];
1432 snprintf(sBuffer
, sizeof(sBuffer
), "%p", this);
1434 pLogger
->attribute("parent", std::string(sBuffer
));
1435 pLogger
->attribute("type", getType());
1436 pLogger
->attribute("resource", resourceToString(getResource()));
1437 pLogger
->attribute("token", fastTokenToId(getToken()));
1438 pLogger
->attribute("id", (*QNameToString::Instance())(getId()));
1440 OOXMLValue::Pointer_t
pVal(getValue());
1442 if (pVal
.get() != NULL
)
1443 pLogger
->attribute("value", pVal
->toString());
1445 pLogger
->attribute("value", std::string("(null)"));
1447 pLogger
->attribute("resolve", mbResolve
? "resolve" : "noResolve");
1449 pLogger
->propertySet(getPropertySet(),
1450 IdToString::Pointer_t(new OOXMLIdToString()));
1452 mpParserState
->dumpXml( pLogger
);
1454 pLogger
->endElement();
1458 void OOXMLFastContextHandlerProperties::newProperty
1459 (const Id
& rId
, OOXMLValue::Pointer_t pVal
)
1463 OOXMLPropertyImpl::Pointer_t pProperty
1464 (new OOXMLPropertyImpl(rId
, pVal
, OOXMLPropertyImpl::ATTRIBUTE
));
1466 mpPropertySet
->add(pProperty
);
1470 void OOXMLFastContextHandlerProperties::handleXNotes()
1474 case NS_wordprocessingml
|OOXML_footnoteReference
:
1476 OOXMLFootnoteHandler
aFootnoteHandler(this);
1477 mpPropertySet
->resolve(aFootnoteHandler
);
1480 case NS_wordprocessingml
|OOXML_endnoteReference
:
1482 OOXMLEndnoteHandler
aEndnoteHandler(this);
1483 mpPropertySet
->resolve(aEndnoteHandler
);
1491 void OOXMLFastContextHandlerProperties::handleHdrFtr()
1495 case NS_wordprocessingml
|OOXML_footerReference
:
1497 OOXMLFooterHandler
aFooterHandler(this);
1498 mpPropertySet
->resolve(aFooterHandler
);
1501 case NS_wordprocessingml
|OOXML_headerReference
:
1503 OOXMLHeaderHandler
aHeaderHandler(this);
1504 mpPropertySet
->resolve(aHeaderHandler
);
1512 void OOXMLFastContextHandlerProperties::handleComment()
1514 #ifdef DEBUG_ELEMENT
1515 debug_logger
->element("handleComment");
1518 OOXMLCommentHandler
aCommentHandler(this);
1519 getPropertySet()->resolve(aCommentHandler
);
1522 void OOXMLFastContextHandlerProperties::handlePicture()
1524 #ifdef DEBUG_ELEMENT
1525 debug_logger
->element("handlePicture");
1528 OOXMLPictureHandler
aPictureHandler(this);
1529 getPropertySet()->resolve(aPictureHandler
);
1532 void OOXMLFastContextHandlerProperties::handleBreak()
1534 #ifdef DEBUG_ELEMENT
1535 debug_logger
->element("handleBreak");
1538 OOXMLBreakHandler
aBreakHandler(*mpStream
);
1539 getPropertySet()->resolve(aBreakHandler
);
1542 void OOXMLFastContextHandlerProperties::handleOLE()
1544 #ifdef DEBUG_ELEMENT
1545 debug_logger
->element("handleOLE");
1548 OOXMLOLEHandler
aOLEHandler(this);
1549 getPropertySet()->resolve(aOLEHandler
);
1552 void OOXMLFastContextHandlerProperties::handleFontRel()
1554 OOXMLEmbeddedFontHandler
handler(this);
1555 getPropertySet()->resolve(handler
);
1558 void OOXMLFastContextHandlerProperties::setParent
1559 (OOXMLFastContextHandler
* pParent
)
1561 #ifdef DEBUG_ELEMENT
1562 debug_logger
->startElement("setParent");
1563 debug_logger
->chars(std::string("OOXMLFastContextHandlerProperties"));
1564 debug_logger
->endElement();
1567 OOXMLFastContextHandler::setParent(pParent
);
1569 if (mpParent
->getResource() == STREAM
)
1573 void OOXMLFastContextHandlerProperties::setPropertySet
1574 (OOXMLPropertySet::Pointer_t pPropertySet
)
1576 if (pPropertySet
.get() != NULL
)
1577 mpPropertySet
= pPropertySet
;
1580 OOXMLPropertySet::Pointer_t
1581 OOXMLFastContextHandlerProperties::getPropertySet() const
1583 return mpPropertySet
;
1587 * class OOXMLFasContextHandlerPropertyTable
1590 OOXMLFastContextHandlerPropertyTable::OOXMLFastContextHandlerPropertyTable
1591 (OOXMLFastContextHandler
* pContext
)
1592 : OOXMLFastContextHandlerProperties(pContext
)
1596 OOXMLFastContextHandlerPropertyTable::~OOXMLFastContextHandlerPropertyTable()
1600 void OOXMLFastContextHandlerPropertyTable::lcl_endFastElement
1602 throw (uno::RuntimeException
, xml::sax::SAXException
)
1604 OOXMLPropertySet::Pointer_t
pPropSet(mpPropertySet
->clone());
1605 OOXMLTableImpl::ValuePointer_t pTmpVal
1606 (new OOXMLPropertySetValue(pPropSet
));
1608 mTable
.add(pTmpVal
);
1610 writerfilter::Reference
<Table
>::Pointer_t
pTable(mTable
.clone());
1612 #ifdef DEBUG_PROPERTIES
1613 debug_logger
->startElement("table");
1614 debug_logger
->attribute("id", (*QNameToString::Instance())(mId
));
1615 debug_logger
->endElement();
1618 mpStream
->table(mId
, pTable
);
1624 class OOXMLFastContextHandlerValue
1627 OOXMLFastContextHandlerValue::OOXMLFastContextHandlerValue
1628 (OOXMLFastContextHandler
* pContext
)
1629 : OOXMLFastContextHandler(pContext
)
1633 OOXMLFastContextHandlerValue::~OOXMLFastContextHandlerValue()
1637 void OOXMLFastContextHandlerValue::setValue(OOXMLValue::Pointer_t pValue
)
1639 #ifdef DEBUG_CONTEXT_HANDLER
1640 debug_logger
->startElement("contexthandler.setValue");
1641 debug_logger
->attribute("value", pValue
->toString());
1646 #ifdef DEBUG_CONTEXT_HANDLER
1647 debug_logger
->endElement();
1651 OOXMLValue::Pointer_t
OOXMLFastContextHandlerValue::getValue() const
1656 void OOXMLFastContextHandlerValue::lcl_endFastElement
1658 throw (uno::RuntimeException
, xml::sax::SAXException
)
1660 sendPropertyToParent();
1665 void OOXMLFastContextHandlerValue::setDefaultBooleanValue()
1667 #ifdef DEBUG_ELEMENT
1668 debug_logger
->element("setDefaultBooleanValue");
1671 if (mpValue
.get() == NULL
)
1673 OOXMLValue::Pointer_t
pValue(new OOXMLBooleanValue(true));
1678 void OOXMLFastContextHandlerValue::setDefaultIntegerValue()
1680 #ifdef DEBUG_ELEMENT
1681 debug_logger
->element("setDefaultIntegerValue");
1684 if (mpValue
.get() == NULL
)
1686 OOXMLValue::Pointer_t
pValue(new OOXMLIntegerValue(0));
1691 void OOXMLFastContextHandlerValue::setDefaultHexValue()
1693 #ifdef DEBUG_ELEMENT
1694 debug_logger
->element("setDefaultHexValue");
1697 if (mpValue
.get() == NULL
)
1699 OOXMLValue::Pointer_t
pValue(new OOXMLHexValue(0));
1704 void OOXMLFastContextHandlerValue::setDefaultStringValue()
1706 #ifdef DEBUG_ELEMENT
1707 debug_logger
->element("setDefaultStringValue");
1710 if (mpValue
.get() == NULL
)
1712 OOXMLValue::Pointer_t
pValue(new OOXMLStringValue(OUString()));
1717 class OOXMLFastContextHandlerTable
1720 OOXMLFastContextHandlerTable::OOXMLFastContextHandlerTable
1721 (OOXMLFastContextHandler
* pContext
)
1722 : OOXMLFastContextHandler(pContext
)
1726 OOXMLFastContextHandlerTable::~OOXMLFastContextHandlerTable()
1730 uno::Reference
< xml::sax::XFastContextHandler
> SAL_CALL
1731 OOXMLFastContextHandlerTable::createFastChildContext
1733 const uno::Reference
< xml::sax::XFastAttributeList
> & Attribs
)
1734 throw (uno::RuntimeException
, xml::sax::SAXException
, std::exception
)
1739 (OOXMLFastContextHandler::createFastChildContext(Element
, Attribs
));
1741 return mCurrentChild
;
1744 void OOXMLFastContextHandlerTable::lcl_endFastElement
1745 (Token_t
/*Element*/)
1746 throw (uno::RuntimeException
, xml::sax::SAXException
)
1750 writerfilter::Reference
<Table
>::Pointer_t
pTable(mTable
.clone());
1751 if (isForwardEvents() && mId
!= 0x0)
1753 #ifdef DEBUG_PROPERTIES
1754 debug_logger
->startElement("table");
1755 string str
= (*QNameToString::Instance())(mId
);
1756 debug_logger
->attribute("id", str
);
1757 debug_logger
->endElement();
1760 mpStream
->table(mId
, pTable
);
1764 void OOXMLFastContextHandlerTable::addCurrentChild()
1766 OOXMLFastContextHandler
* pHandler
= mCurrentChild
.getPointer();
1767 if ( pHandler
!= NULL
)
1769 OOXMLValue::Pointer_t
pValue(pHandler
->getValue());
1771 if (pValue
.get() != NULL
)
1773 OOXMLTableImpl::ValuePointer_t
pTmpVal(pValue
->clone());
1774 mTable
.add(pTmpVal
);
1779 void OOXMLFastContextHandlerTable::newPropertySet
1780 (OOXMLPropertySet::Pointer_t
/*pPropertySet*/)
1786 class OOXMLFastContextHandlerXNote
1789 OOXMLFastContextHandlerXNote::OOXMLFastContextHandlerXNote
1790 (OOXMLFastContextHandler
* pContext
)
1791 : OOXMLFastContextHandlerProperties(pContext
)
1792 , mbForwardEventsSaved(false)
1798 OOXMLFastContextHandlerXNote::~OOXMLFastContextHandlerXNote()
1802 void OOXMLFastContextHandlerXNote::lcl_startFastElement
1804 const uno::Reference
< xml::sax::XFastAttributeList
> & /*Attribs*/)
1805 throw (uno::RuntimeException
, xml::sax::SAXException
)
1807 mbForwardEventsSaved
= isForwardEvents();
1809 // If this is the note we're looking for or this is the footnote separator one.
1810 if (mnMyXNoteId
== getXNoteId() || static_cast<sal_uInt32
>(mnMyXNoteType
) == NS_ooxml::LN_Value_wordprocessingml_ST_FtnEdn_separator
)
1811 setForwardEvents(true);
1813 setForwardEvents(false);
1815 startAction(Element
);
1818 void OOXMLFastContextHandlerXNote::lcl_endFastElement
1820 throw (uno::RuntimeException
, xml::sax::SAXException
)
1824 OOXMLFastContextHandlerProperties::lcl_endFastElement(Element
);
1826 setForwardEvents(mbForwardEventsSaved
);
1829 void OOXMLFastContextHandlerXNote::checkId(OOXMLValue::Pointer_t pValue
)
1831 #ifdef DEBUG_ELEMENT
1832 debug_logger
->startElement("checkId");
1833 debug_logger
->attribute("myId", sal_Int32(pValue
->getInt()));
1834 debug_logger
->attribute("id", getXNoteId());
1835 debug_logger
->endElement();
1838 mnMyXNoteId
= sal_Int32(pValue
->getInt());
1841 void OOXMLFastContextHandlerXNote::checkType(OOXMLValue::Pointer_t pValue
)
1843 #ifdef DEBUG_ELEMENT
1844 debug_logger
->startElement("checkType");
1845 debug_logger
->attribute("myType", sal_Int32(pValue
->getInt()));
1846 debug_logger
->endElement();
1848 mnMyXNoteType
= pValue
->getInt();
1852 class OOXMLFastContextHandlerTextTableCell
1855 OOXMLFastContextHandlerTextTableCell::OOXMLFastContextHandlerTextTableCell
1856 (OOXMLFastContextHandler
* pContext
)
1857 : OOXMLFastContextHandler(pContext
)
1861 OOXMLFastContextHandlerTextTableCell::~OOXMLFastContextHandlerTextTableCell()
1865 void OOXMLFastContextHandlerTextTableCell::startCell()
1869 void OOXMLFastContextHandlerTextTableCell::endCell()
1871 if (isForwardEvents())
1873 OOXMLPropertySet
* pProps
= new OOXMLPropertySetImpl();
1875 OOXMLValue::Pointer_t pVal
1876 (new OOXMLIntegerValue(mnTableDepth
));
1877 OOXMLProperty::Pointer_t pProp
1878 (new OOXMLPropertyImpl(NS_ooxml::LN_tblDepth
, pVal
, OOXMLPropertyImpl::SPRM
));
1882 OOXMLValue::Pointer_t pVal
1883 (new OOXMLIntegerValue(1));
1884 OOXMLProperty::Pointer_t pProp
1885 (new OOXMLPropertyImpl(NS_ooxml::LN_inTbl
, pVal
, OOXMLPropertyImpl::SPRM
));
1889 OOXMLValue::Pointer_t pVal
1890 (new OOXMLBooleanValue(mnTableDepth
> 0));
1891 OOXMLProperty::Pointer_t pProp
1892 (new OOXMLPropertyImpl(NS_ooxml::LN_tblCell
, pVal
, OOXMLPropertyImpl::SPRM
));
1896 #ifdef DEBUG_PROPERTIES
1897 debug_logger
->startElement("endcell");
1898 debug_logger
->propertySet(OOXMLPropertySet::Pointer_t(pProps
->clone()),
1899 IdToString::Pointer_t(new OOXMLIdToString()));
1900 debug_logger
->endElement();
1902 mpStream
->props(writerfilter::Reference
<Properties
>::Pointer_t(pProps
));
1907 class OOXMLFastContextHandlerTextTableRow
1910 OOXMLFastContextHandlerTextTableRow::OOXMLFastContextHandlerTextTableRow
1911 (OOXMLFastContextHandler
* pContext
)
1912 : OOXMLFastContextHandler(pContext
)
1916 OOXMLFastContextHandlerTextTableRow::~OOXMLFastContextHandlerTextTableRow()
1920 void OOXMLFastContextHandlerTextTableRow::startRow()
1924 void OOXMLFastContextHandlerTextTableRow::endRow()
1926 startParagraphGroup();
1928 if (isForwardEvents())
1930 OOXMLPropertySet
* pProps
= new OOXMLPropertySetImpl();
1932 OOXMLValue::Pointer_t pVal
1933 (new OOXMLIntegerValue(mnTableDepth
));
1934 OOXMLProperty::Pointer_t pProp
1935 (new OOXMLPropertyImpl(NS_ooxml::LN_tblDepth
, pVal
, OOXMLPropertyImpl::SPRM
));
1939 OOXMLValue::Pointer_t pVal
1940 (new OOXMLIntegerValue(1));
1941 OOXMLProperty::Pointer_t pProp
1942 (new OOXMLPropertyImpl(NS_ooxml::LN_inTbl
, pVal
, OOXMLPropertyImpl::SPRM
));
1946 OOXMLValue::Pointer_t pVal
1947 (new OOXMLIntegerValue(1));
1948 OOXMLProperty::Pointer_t pProp
1949 (new OOXMLPropertyImpl(NS_ooxml::LN_tblRow
, pVal
, OOXMLPropertyImpl::SPRM
));
1953 #ifdef DEBUG_PROPERTIES
1954 debug_logger
->startElement("endrow");
1955 debug_logger
->propertySet(OOXMLPropertySet::Pointer_t(pProps
->clone()),
1956 IdToString::Pointer_t(new OOXMLIdToString()));
1957 debug_logger
->endElement();
1960 mpStream
->props(writerfilter::Reference
<Properties
>::Pointer_t(pProps
));
1963 startCharacterGroup();
1965 if (isForwardEvents())
1966 mpStream
->utext((const sal_uInt8
*)&uCR
, 1);
1968 endCharacterGroup();
1969 endParagraphGroup();
1972 // Handle w:gridBefore here by faking necessary input that'll fake cells. I'm apparently
1973 // not insane enough to find out how to add cells in dmapper.
1974 void OOXMLFastContextHandlerTextTableRow::handleGridBefore( OOXMLValue::Pointer_t val
)
1976 int count
= val
->getInt();
1983 if (isForwardEvents())
1985 // This whole part is OOXMLFastContextHandlerTextTableCell::endCell() .
1986 OOXMLPropertySet
* pProps
= new OOXMLPropertySetImpl();
1988 OOXMLValue::Pointer_t pVal
1989 (new OOXMLIntegerValue(mnTableDepth
));
1990 OOXMLProperty::Pointer_t pProp
1991 (new OOXMLPropertyImpl(NS_ooxml::LN_tblDepth
, pVal
, OOXMLPropertyImpl::SPRM
));
1995 OOXMLValue::Pointer_t pVal
1996 (new OOXMLIntegerValue(1));
1997 OOXMLProperty::Pointer_t pProp
1998 (new OOXMLPropertyImpl(NS_ooxml::LN_inTbl
, pVal
, OOXMLPropertyImpl::SPRM
));
2002 OOXMLValue::Pointer_t pVal
2003 (new OOXMLBooleanValue(mnTableDepth
> 0));
2004 OOXMLProperty::Pointer_t pProp
2005 (new OOXMLPropertyImpl(NS_ooxml::LN_tblCell
, pVal
, OOXMLPropertyImpl::SPRM
));
2009 #ifdef DEBUG_PROPERTIES
2010 debug_logger
->startElement("handlegridbefore");
2011 debug_logger
->propertySet(OOXMLPropertySet::Pointer_t(pProps
->clone()),
2012 IdToString::Pointer_t(new OOXMLIdToString()));
2013 debug_logger
->endElement();
2015 mpStream
->props(writerfilter::Reference
<Properties
>::Pointer_t(pProps
));
2017 // fake <w:tcBorders> with no border
2018 OOXMLPropertySet::Pointer_t
pCellProps( new OOXMLPropertySetImpl());
2020 OOXMLPropertySet::Pointer_t
pBorderProps( new OOXMLPropertySetImpl());
2021 static Id borders
[] = { NS_ooxml::LN_CT_TcBorders_top
, NS_ooxml::LN_CT_TcBorders_bottom
,
2022 NS_ooxml::LN_CT_TcBorders_start
, NS_ooxml::LN_CT_TcBorders_end
};
2023 for( size_t j
= 0; j
< SAL_N_ELEMENTS( borders
); ++j
)
2024 pBorderProps
->add( fakeNoBorder( borders
[ j
] ));
2025 OOXMLValue::Pointer_t
pValue( new OOXMLPropertySetValue( pBorderProps
));
2026 OOXMLProperty::Pointer_t pProp
2027 (new OOXMLPropertyImpl(NS_ooxml::LN_CT_TcPrBase_tcBorders
, pValue
, OOXMLPropertyImpl::SPRM
));
2028 pCellProps
->add(pProp
);
2029 mpParserState
->setCellProperties(pCellProps
);
2033 sendCellProperties();
2034 endParagraphGroup();
2038 OOXMLProperty::Pointer_t
OOXMLFastContextHandlerTextTableRow::fakeNoBorder( Id id
)
2040 OOXMLPropertySet::Pointer_t
pProps( new OOXMLPropertySetImpl());
2041 OOXMLValue::Pointer_t
pVal(new OOXMLIntegerValue(0));
2042 OOXMLProperty::Pointer_t pPropVal
2043 (new OOXMLPropertyImpl(NS_ooxml::LN_CT_Border_val
, pVal
, OOXMLPropertyImpl::ATTRIBUTE
));
2044 pProps
->add(pPropVal
);
2045 OOXMLValue::Pointer_t
pValue( new OOXMLPropertySetValue( pProps
));
2046 OOXMLProperty::Pointer_t pProp
2047 (new OOXMLPropertyImpl(id
, pValue
, OOXMLPropertyImpl::SPRM
));
2052 class OOXMLFastContextHandlerTextTable
2055 OOXMLFastContextHandlerTextTable::OOXMLFastContextHandlerTextTable
2056 (OOXMLFastContextHandler
* pContext
)
2057 : OOXMLFastContextHandler(pContext
)
2061 OOXMLFastContextHandlerTextTable::~OOXMLFastContextHandlerTextTable()
2066 void OOXMLFastContextHandlerTextTable::lcl_startFastElement
2068 const uno::Reference
< xml::sax::XFastAttributeList
> & /*Attribs*/)
2069 throw (uno::RuntimeException
, xml::sax::SAXException
)
2071 mpParserState
->startTable();
2074 boost::shared_ptr
<OOXMLPropertySet
> pProps( new OOXMLPropertySetImpl
);
2076 OOXMLValue::Pointer_t pVal
2077 (new OOXMLIntegerValue(mnTableDepth
));
2078 OOXMLProperty::Pointer_t pProp
2079 (new OOXMLPropertyImpl(NS_ooxml::LN_tblStart
, pVal
, OOXMLPropertyImpl::SPRM
));
2082 mpParserState
->setCharacterProperties(pProps
);
2084 startAction(Element
);
2087 void OOXMLFastContextHandlerTextTable::lcl_endFastElement
2089 throw (uno::RuntimeException
, xml::sax::SAXException
)
2093 boost::shared_ptr
<OOXMLPropertySet
> pProps( new OOXMLPropertySetImpl
);
2095 OOXMLValue::Pointer_t pVal
2096 (new OOXMLIntegerValue(mnTableDepth
));
2097 OOXMLProperty::Pointer_t pProp
2098 (new OOXMLPropertyImpl(NS_ooxml::LN_tblEnd
, pVal
, OOXMLPropertyImpl::SPRM
));
2101 mpParserState
->setCharacterProperties(pProps
);
2104 mpParserState
->endTable();
2108 class OOXMLFastContextHandlerShape
2111 OOXMLFastContextHandlerShape::OOXMLFastContextHandlerShape
2112 (OOXMLFastContextHandler
* pContext
)
2113 : OOXMLFastContextHandlerProperties(pContext
), m_bShapeSent( false ),
2114 m_bShapeStarted(false)
2116 mrShapeContext
.set( getDocument( )->getShapeContext( ) );
2117 if ( !mrShapeContext
.is( ) )
2119 // Define the shape context for the whole document
2120 mrShapeContext
= css::xml::sax::FastShapeContextHandler::create(
2121 getComponentContext());
2122 getDocument()->setShapeContext( mrShapeContext
);
2125 mrShapeContext
->setModel(getDocument()->getModel());
2126 mrShapeContext
->setDrawPage(getDocument()->getDrawPage());
2127 mrShapeContext
->setInputStream(getDocument()->getStorageStream());
2129 #ifdef DEBUG_ELEMENT
2130 debug_logger
->startElement("setRelationFragmentPath");
2131 debug_logger
->attribute("path", mpParserState
->getTarget());
2132 debug_logger
->endElement();
2134 mrShapeContext
->setRelationFragmentPath
2135 (mpParserState
->getTarget());
2138 OOXMLFastContextHandlerShape::~OOXMLFastContextHandlerShape()
2142 void OOXMLFastContextHandlerShape::lcl_startFastElement
2144 const uno::Reference
< xml::sax::XFastAttributeList
> & Attribs
)
2145 throw (uno::RuntimeException
, xml::sax::SAXException
)
2147 startAction(Element
);
2149 if (mrShapeContext
.is())
2151 mrShapeContext
->startFastElement(Element
, Attribs
);
2155 void SAL_CALL
OOXMLFastContextHandlerShape::startUnknownElement
2156 (const OUString
& Namespace
,
2157 const OUString
& Name
,
2158 const uno::Reference
< xml::sax::XFastAttributeList
> & Attribs
)
2159 throw (uno::RuntimeException
, xml::sax::SAXException
, std::exception
)
2161 if (mrShapeContext
.is())
2162 mrShapeContext
->startUnknownElement(Namespace
, Name
, Attribs
);
2165 void OOXMLFastContextHandlerShape::setToken(Token_t nToken
)
2167 OOXMLFastContextHandler::setToken(nToken
);
2169 if (mrShapeContext
.is())
2170 mrShapeContext
->setStartToken(nToken
);
2173 void OOXMLFastContextHandlerShape::sendShape( Token_t Element
)
2175 if ( mrShapeContext
.is() && !m_bShapeSent
)
2177 awt::Point
aPosition(writerfilter::dmapper::PositionHandler::getPositionOffset(false), writerfilter::dmapper::PositionHandler::getPositionOffset(true));
2178 mrShapeContext
->setPosition(aPosition
);
2179 uno::Reference
<drawing::XShape
> xShape(mrShapeContext
->getShape());
2182 OOXMLValue::Pointer_t
2183 pValue(new OOXMLShapeValue(xShape
));
2184 newProperty(NS_ooxml::LN_shape
, pValue
);
2185 m_bShapeSent
= true;
2187 bool bIsPicture
= Element
== ( NS_picture
| OOXML_pic
);
2189 // Notify the dmapper that the shape is ready to use
2192 mpStream
->startShape( xShape
);
2193 m_bShapeStarted
= true;
2199 void OOXMLFastContextHandlerShape::lcl_endFastElement
2201 throw (uno::RuntimeException
, xml::sax::SAXException
)
2203 if (mrShapeContext
.is())
2205 mrShapeContext
->endFastElement(Element
);
2206 sendShape( Element
);
2209 OOXMLFastContextHandlerProperties::lcl_endFastElement(Element
);
2211 // Ending the shape should be the last thing to do
2212 bool bIsPicture
= Element
== ( NS_picture
| OOXML_pic
);
2213 if ( !bIsPicture
&& m_bShapeStarted
)
2214 mpStream
->endShape( );
2217 void SAL_CALL
OOXMLFastContextHandlerShape::endUnknownElement
2218 (const OUString
& Namespace
,
2219 const OUString
& Name
)
2220 throw (uno::RuntimeException
, xml::sax::SAXException
, std::exception
)
2222 if (mrShapeContext
.is())
2223 mrShapeContext
->endUnknownElement(Namespace
, Name
);
2226 uno::Reference
< xml::sax::XFastContextHandler
>
2227 OOXMLFastContextHandlerShape::lcl_createFastChildContext
2229 const uno::Reference
< xml::sax::XFastAttributeList
> & Attribs
)
2230 throw (uno::RuntimeException
, xml::sax::SAXException
)
2232 uno::Reference
< xml::sax::XFastContextHandler
> xContextHandler
;
2234 bool bGroupShape
= Element
== Token_t(NS_vml
| OOXML_group
);
2235 // drawingML version also counts as a group shape.
2236 bGroupShape
|= mrShapeContext
->getStartToken() == Token_t(NS_wpg
| OOXML_wgp
);
2237 sal_uInt32 nNamespace
= Element
& 0xffff0000;
2241 case NS_wordprocessingml
:
2242 case NS_vml_wordprocessingDrawing
:
2245 xContextHandler
.set(OOXMLFactory::getInstance()->createFastChildContextFromStart(this, Element
));
2248 if (!xContextHandler
.is())
2250 if (mrShapeContext
.is())
2252 uno::Reference
<XFastContextHandler
> pChildContext
=
2253 mrShapeContext
->createFastChildContext(Element
, Attribs
);
2255 OOXMLFastContextHandlerWrapper
* pWrapper
=
2256 new OOXMLFastContextHandlerWrapper(this, pChildContext
);
2260 pWrapper
->addNamespace(NS_wordprocessingml
);
2261 pWrapper
->addNamespace(NS_vml_wordprocessingDrawing
);
2262 pWrapper
->addNamespace(NS_office
);
2263 pWrapper
->addToken( NS_vml
|OOXML_textbox
);
2266 xContextHandler
.set(pWrapper
);
2269 xContextHandler
.set(this);
2274 // VML import of shape text is already handled by
2275 // OOXMLFastContextHandlerWrapper::lcl_createFastChildContext(), here we
2276 // handle the WPS import of shape text, as there the parent context is a
2277 // Shape one, so a different situation.
2278 if (Element
== static_cast<sal_Int32
>(NS_wps
| OOXML_txbx
) ||
2279 Element
== static_cast<sal_Int32
>(NS_wps
| OOXML_linkedTxbx
) )
2282 return xContextHandler
;
2285 uno::Reference
< xml::sax::XFastContextHandler
> SAL_CALL
2286 OOXMLFastContextHandlerShape::createUnknownChildContext
2287 (const OUString
& Namespace
,
2288 const OUString
& Name
,
2289 const uno::Reference
< xml::sax::XFastAttributeList
> & Attribs
)
2290 throw (uno::RuntimeException
, xml::sax::SAXException
, std::exception
)
2292 uno::Reference
< xml::sax::XFastContextHandler
> xResult
;
2294 if (mrShapeContext
.is())
2295 xResult
.set(mrShapeContext
->createUnknownChildContext
2296 (Namespace
, Name
, Attribs
));
2301 void OOXMLFastContextHandlerShape::lcl_characters
2302 (const OUString
& aChars
)
2303 throw (uno::RuntimeException
, xml::sax::SAXException
)
2305 if (mrShapeContext
.is())
2306 mrShapeContext
->characters(aChars
);
2310 class OOXMLFastContextHandlerWrapper
2313 OOXMLFastContextHandlerWrapper::OOXMLFastContextHandlerWrapper
2314 (OOXMLFastContextHandler
* pParent
,
2315 uno::Reference
<XFastContextHandler
> xContext
)
2316 : OOXMLFastContextHandler(pParent
), mxContext(xContext
)
2318 setId(pParent
->getId());
2319 setToken(pParent
->getToken());
2320 setPropertySet(pParent
->getPropertySet());
2323 OOXMLFastContextHandlerWrapper::~OOXMLFastContextHandlerWrapper()
2327 void SAL_CALL
OOXMLFastContextHandlerWrapper::startUnknownElement
2328 (const OUString
& Namespace
,
2329 const OUString
& Name
,
2330 const uno::Reference
< xml::sax::XFastAttributeList
> & Attribs
)
2331 throw (uno::RuntimeException
, xml::sax::SAXException
, std::exception
)
2334 mxContext
->startUnknownElement(Namespace
, Name
, Attribs
);
2337 void SAL_CALL
OOXMLFastContextHandlerWrapper::endUnknownElement
2338 (const OUString
& Namespace
,
2339 const OUString
& Name
)
2340 throw (uno::RuntimeException
, xml::sax::SAXException
, std::exception
)
2343 mxContext
->endUnknownElement(Namespace
, Name
);
2346 uno::Reference
< xml::sax::XFastContextHandler
> SAL_CALL
2347 OOXMLFastContextHandlerWrapper::createUnknownChildContext
2348 (const OUString
& Namespace
,
2349 const OUString
& Name
,
2350 const uno::Reference
< xml::sax::XFastAttributeList
> & Attribs
)
2351 throw (uno::RuntimeException
, xml::sax::SAXException
, std::exception
)
2353 uno::Reference
< xml::sax::XFastContextHandler
> xResult
;
2356 xResult
= mxContext
->createUnknownChildContext
2357 (Namespace
, Name
, Attribs
);
2364 void OOXMLFastContextHandlerWrapper::attributes
2365 (const uno::Reference
< xml::sax::XFastAttributeList
> & Attribs
)
2366 throw (uno::RuntimeException
, xml::sax::SAXException
)
2370 OOXMLFastContextHandler
* pHandler
= getFastContextHandler();
2371 if (pHandler
!= NULL
)
2372 pHandler
->attributes(Attribs
);
2376 OOXMLFastContextHandler::ResourceEnum_t
2377 OOXMLFastContextHandlerWrapper::getResource() const
2382 void OOXMLFastContextHandlerWrapper::addNamespace(const Id
& nId
)
2384 mMyNamespaces
.insert(nId
);
2387 void OOXMLFastContextHandlerWrapper::addToken( Token_t Token
)
2389 mMyTokens
.insert( Token
);
2392 void OOXMLFastContextHandlerWrapper::lcl_startFastElement
2394 const uno::Reference
< xml::sax::XFastAttributeList
> & Attribs
)
2395 throw (uno::RuntimeException
, xml::sax::SAXException
)
2398 mxContext
->startFastElement(Element
, Attribs
);
2401 void OOXMLFastContextHandlerWrapper::lcl_endFastElement
2403 throw (uno::RuntimeException
, xml::sax::SAXException
)
2406 mxContext
->endFastElement(Element
);
2409 uno::Reference
< xml::sax::XFastContextHandler
>
2410 OOXMLFastContextHandlerWrapper::lcl_createFastChildContext
2412 const uno::Reference
< xml::sax::XFastAttributeList
> & Attribs
)
2413 throw (uno::RuntimeException
, xml::sax::SAXException
)
2415 uno::Reference
< xml::sax::XFastContextHandler
> xResult
;
2417 Id nNameSpace
= Element
& 0xffff0000;
2419 #ifdef DEBUG_ELEMENT
2420 debug_logger
->startElement("Wrapper-createChildContext");
2421 debug_logger
->attribute("token", fastTokenToId(Element
));
2423 const set
<Id
>::const_iterator
aEnd(mMyNamespaces
.end());
2424 for (set
<Id
>::const_iterator
aIt(mMyNamespaces
.begin());
2427 debug_logger
->startElement("namespace");
2428 debug_logger
->attribute("id", fastTokenToId(*aIt
));
2429 debug_logger
->endElement();
2432 debug_logger
->endElement();
2435 bool bInNamespaces
= mMyNamespaces
.find(nNameSpace
) != mMyNamespaces
.end();
2436 bool bInTokens
= mMyTokens
.find( Element
) != mMyTokens
.end( );
2438 OOXMLFastContextHandlerShape
* pShapeCtx
= (OOXMLFastContextHandlerShape
*)mpParent
;
2440 // We have methods to _add_ individual tokens or whole namespaces to be
2441 // processed by writerfilter (instead of oox), but we have no method to
2442 // filter out a single token. Just hardwire the wrap token here till we
2443 // need a more generic solution.
2444 bool bIsWrap
= Element
== static_cast<sal_Int32
>(NS_vml_wordprocessingDrawing
| OOXML_wrap
);
2445 if ( bInNamespaces
&& ((pShapeCtx
->isShapeSent() && bIsWrap
) || !bIsWrap
) )
2446 xResult
.set(OOXMLFactory::getInstance()->createFastChildContextFromStart(this, Element
));
2447 else if (mxContext
.is())
2449 OOXMLFastContextHandlerWrapper
* pWrapper
=
2450 new OOXMLFastContextHandlerWrapper
2451 (this, mxContext
->createFastChildContext(Element
, Attribs
));
2452 pWrapper
->mMyNamespaces
= mMyNamespaces
;
2453 pWrapper
->setPropertySet(getPropertySet());
2454 xResult
.set(pWrapper
);
2460 pShapeCtx
->sendShape( Element
);
2465 void OOXMLFastContextHandlerWrapper::lcl_characters
2466 (const OUString
& aChars
)
2467 throw (uno::RuntimeException
, xml::sax::SAXException
)
2470 mxContext
->characters(aChars
);
2473 OOXMLFastContextHandler
*
2474 OOXMLFastContextHandlerWrapper::getFastContextHandler() const
2477 return dynamic_cast<OOXMLFastContextHandler
*>(mxContext
.get());
2482 void OOXMLFastContextHandlerWrapper::newProperty
2483 (const Id
& rId
, OOXMLValue::Pointer_t pVal
)
2487 OOXMLFastContextHandler
* pHandler
= getFastContextHandler();
2488 if (pHandler
!= NULL
)
2489 pHandler
->newProperty(rId
, pVal
);
2493 void OOXMLFastContextHandlerWrapper::setPropertySet
2494 (OOXMLPropertySet::Pointer_t pPropertySet
)
2498 OOXMLFastContextHandler
* pHandler
= getFastContextHandler();
2499 if (pHandler
!= NULL
)
2500 pHandler
->setPropertySet(pPropertySet
);
2503 mpPropertySet
= pPropertySet
;
2506 OOXMLPropertySet::Pointer_t
OOXMLFastContextHandlerWrapper::getPropertySet()
2509 OOXMLPropertySet::Pointer_t
pResult(mpPropertySet
);
2513 OOXMLFastContextHandler
* pHandler
= getFastContextHandler();
2514 if (pHandler
!= NULL
)
2515 pResult
= pHandler
->getPropertySet();
2521 string
OOXMLFastContextHandlerWrapper::getType() const
2523 string sResult
= "Wrapper(";
2527 OOXMLFastContextHandler
* pHandler
= getFastContextHandler();
2528 if (pHandler
!= NULL
)
2529 sResult
+= pHandler
->getType();
2537 void OOXMLFastContextHandlerWrapper::setId(Id rId
)
2539 OOXMLFastContextHandler::setId(rId
);
2543 OOXMLFastContextHandler
* pHandler
= getFastContextHandler();
2544 if (pHandler
!= NULL
)
2545 pHandler
->setId(rId
);
2549 Id
OOXMLFastContextHandlerWrapper::getId() const
2551 Id nResult
= OOXMLFastContextHandler::getId();
2555 OOXMLFastContextHandler
* pHandler
= getFastContextHandler();
2556 if (pHandler
!= NULL
&& pHandler
->getId() != 0)
2557 nResult
= pHandler
->getId();
2563 void OOXMLFastContextHandlerWrapper::setToken(Token_t nToken
)
2565 OOXMLFastContextHandler::setToken(nToken
);
2569 OOXMLFastContextHandler
* pHandler
= getFastContextHandler();
2570 if (pHandler
!= NULL
)
2571 pHandler
->setToken(nToken
);
2575 Token_t
OOXMLFastContextHandlerWrapper::getToken() const
2577 Token_t nResult
= OOXMLFastContextHandler::getToken();
2581 OOXMLFastContextHandler
* pHandler
= getFastContextHandler();
2582 if (pHandler
!= NULL
)
2583 nResult
= pHandler
->getToken();
2591 class OOXMLFastContextHandlerLinear
2594 OOXMLFastContextHandlerLinear::OOXMLFastContextHandlerLinear(OOXMLFastContextHandler
* pContext
)
2595 : OOXMLFastContextHandlerProperties(pContext
)
2600 void OOXMLFastContextHandlerLinear::lcl_startFastElement(Token_t Element
,
2601 const uno::Reference
< xml::sax::XFastAttributeList
>& Attribs
)
2602 throw (uno::RuntimeException
, xml::sax::SAXException
)
2604 buffer
.appendOpeningTag( Element
, Attribs
);
2608 void OOXMLFastContextHandlerLinear::lcl_endFastElement(Token_t Element
)
2609 throw (uno::RuntimeException
, xml::sax::SAXException
)
2611 buffer
.appendClosingTag( Element
);
2612 if( --depthCount
== 0 )
2616 uno::Reference
< xml::sax::XFastContextHandler
>
2617 OOXMLFastContextHandlerLinear::lcl_createFastChildContext(Token_t
,
2618 const uno::Reference
< xml::sax::XFastAttributeList
>&)
2619 throw (uno::RuntimeException
, xml::sax::SAXException
)
2621 uno::Reference
< xml::sax::XFastContextHandler
> xContextHandler
;
2622 xContextHandler
.set( this );
2623 return xContextHandler
;
2626 void OOXMLFastContextHandlerLinear::lcl_characters(const OUString
& aChars
)
2627 throw (uno::RuntimeException
, xml::sax::SAXException
)
2629 buffer
.appendCharacters( aChars
);
2633 class OOXMLFastContextHandlerLinear
2636 OOXMLFastContextHandlerMath::OOXMLFastContextHandlerMath(OOXMLFastContextHandler
* pContext
)
2637 : OOXMLFastContextHandlerLinear(pContext
)
2641 void OOXMLFastContextHandlerMath::process()
2643 SvGlobalName
name( SO3_SM_CLASSID
);
2644 comphelper::EmbeddedObjectContainer container
;
2646 uno::Reference
< embed::XEmbeddedObject
> ref
= container
.CreateEmbeddedObject( name
.GetByteSequence(), aName
);
2650 uno::Reference
< uno::XInterface
> component( ref
->getComponent(), uno::UNO_QUERY
);
2651 // gcc4.4 (and 4.3 and possibly older) have a problem with dynamic_cast directly to the target class,
2652 // so help it with an intermediate cast. I'm not sure what exactly the problem is, seems to be unrelated
2653 // to RTLD_GLOBAL, so most probably a gcc bug.
2654 oox::FormulaImportBase
* import
= dynamic_cast< oox::FormulaImportBase
* >( dynamic_cast< SfxBaseModel
* >(component
.get()));
2655 assert( import
!= NULL
);
2658 import
->readFormulaOoxml( buffer
);
2659 if (isForwardEvents())
2661 OOXMLPropertySet
* pProps
= new OOXMLPropertySetImpl();
2662 OOXMLValue::Pointer_t
pVal( new OOXMLStarMathValue( ref
));
2663 OOXMLProperty::Pointer_t
pProp( new OOXMLPropertyImpl( NS_ooxml::LN_starmath
, pVal
, OOXMLPropertyImpl::ATTRIBUTE
));
2664 pProps
->add( pProp
);
2665 mpStream
->props( writerfilter::Reference
< Properties
>::Pointer_t( pProps
));
2671 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */