LCOV - code coverage report
Current view: top level - writerfilter/source/ooxml - OOXMLFastContextHandler.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 870 975 89.2 %
Date: 2014-04-11 Functions: 192 215 89.3 %
Legend: Lines: hit not hit

          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             : #include <stdio.h>
      21             : #include <iostream>
      22             : #include <set>
      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"
      42             : 
      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;
      50             : 
      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;
      55             : 
      56             : namespace writerfilter {
      57             : namespace ooxml
      58             : {
      59             : using namespace ::com::sun::star;
      60             : using namespace ::std;
      61             : 
      62             : #if OSL_DEBUG_LEVEL > 1
      63             : static string resourceToString
      64             : (OOXMLFastContextHandler::ResourceEnum_t eResource)
      65             : {
      66             :     string sResult;
      67             : 
      68             :     switch (eResource)
      69             :     {
      70             :     case OOXMLFastContextHandler::STREAM:
      71             :         sResult = "Stream";
      72             :         break;
      73             :     case OOXMLFastContextHandler::PROPERTIES:
      74             :         sResult = "Properties";
      75             :         break;
      76             :     case OOXMLFastContextHandler::TABLE:
      77             :         sResult = "Table";
      78             :         break;
      79             :     case OOXMLFastContextHandler::SHAPE:
      80             :         sResult = "Shape";
      81             :         break;
      82             :     default:
      83             :         sResult = "??";
      84             :     }
      85             : 
      86             :     return sResult;
      87             : }
      88             : #endif
      89             : 
      90          14 : set<OOXMLFastContextHandler *> aSetContexts;
      91             : 
      92             : #if OSL_DEBUG_LEVEL > 1
      93             : class OOXMLIdToString : public IdToString
      94             : {
      95             : public:
      96             :     OOXMLIdToString() : IdToString() {}
      97             :     virtual ~OOXMLIdToString() {}
      98             : 
      99             :     virtual string toString(const Id & rId) const
     100             :     {
     101             :         string s((*QNameToString::Instance())(rId));
     102             : 
     103             :         if (s.empty())
     104             :             s = "(fasttoken)" + fastTokenToId(rId);
     105             :         else
     106             :             s = "(qname)" + s;
     107             : 
     108             :         return s;
     109             :     }
     110             : };
     111             : #endif
     112             : 
     113             : /*
     114             :   class OOXMLFastContextHandler
     115             :  */
     116             : 
     117             : sal_uInt32 OOXMLFastContextHandler::mnInstanceCount = 0;
     118             : 
     119        5380 : OOXMLFastContextHandler::OOXMLFastContextHandler
     120             : (uno::Reference< uno::XComponentContext > const & context)
     121             : : mpParent(NULL),
     122             :   mId(0),
     123             :   mnDefine(0),
     124             :   mnToken(OOXML_FAST_TOKENS_END),
     125             :   mpStream(NULL),
     126             :   mnTableDepth(0),
     127             :   mnInstanceNumber(mnInstanceCount),
     128             :   mnRefCount(0),
     129             :   inPositionV(false),
     130             :   m_xContext(context),
     131             :   m_bDiscardChildren(false),
     132        5380 :   m_bTookChoice(false)
     133             : {
     134        5380 :     mnInstanceCount++;
     135        5380 :     aSetContexts.insert(this);
     136             : 
     137        5380 :     if (mpParserState.get() == NULL)
     138        5380 :         mpParserState.reset(new OOXMLParserState());
     139             : 
     140        5380 :     mpParserState->incContextCount();
     141        5380 : }
     142             : 
     143     1157429 : OOXMLFastContextHandler::OOXMLFastContextHandler
     144             : (OOXMLFastContextHandler * pContext)
     145             : : cppu::WeakImplHelper1<com::sun::star::xml::sax::XFastContextHandler>(),
     146             :   mpParent(pContext),
     147             :   mId(0),
     148             :   mnDefine(0),
     149             :   mnToken(OOXML_FAST_TOKENS_END),
     150             :   mpStream(pContext->mpStream),
     151             :   mnTableDepth(pContext->mnTableDepth),
     152             :   mnInstanceNumber(mnInstanceCount),
     153             :   mnRefCount(0),
     154             :   inPositionV(pContext->inPositionV),
     155             :   m_xContext(pContext->m_xContext),
     156             :   m_bDiscardChildren(pContext->m_bDiscardChildren),
     157             :   m_bTookChoice(pContext->m_bTookChoice),
     158     1157429 :   m_aSavedAlternateStates(pContext->m_aSavedAlternateStates)
     159             : {
     160     1157429 :     mpParserState = pContext->mpParserState;
     161             : 
     162     1157429 :     if (mpParserState.get() == NULL)
     163           0 :         mpParserState.reset(new OOXMLParserState());
     164             : 
     165     1157429 :     mnInstanceCount++;
     166     1157429 :     aSetContexts.insert(this);
     167     1157429 :     mpParserState->incContextCount();
     168     1157429 : }
     169             : 
     170     2331460 : OOXMLFastContextHandler::~OOXMLFastContextHandler()
     171             : {
     172     1162963 :     aSetContexts.erase(this);
     173     1168497 : }
     174             : 
     175        1992 : bool OOXMLFastContextHandler::prepareMceContext(Token_t nElement, const uno::Reference<xml::sax::XFastAttributeList>& rAttribs)
     176             : {
     177        1992 :     switch (oox::getBaseToken(nElement))
     178             :     {
     179             :         case OOXML_AlternateContent:
     180             :             {
     181             :                 SavedAlternateState aState;
     182         664 :                 aState.m_bDiscardChildren = m_bDiscardChildren;
     183         664 :                 m_bDiscardChildren = false;
     184         664 :                 aState.m_bTookChoice = m_bTookChoice;
     185         664 :                 m_bTookChoice = false;
     186         664 :                 m_aSavedAlternateStates.push(aState);
     187             :             }
     188         664 :             break;
     189             :         case OOXML_Choice:
     190             :         {
     191         664 :             OUString aRequires = rAttribs->getOptionalValue(OOXML_Requires);
     192             :             static const char* aFeatures[] = {
     193             :                 "wps",
     194             :                 "wpg",
     195             :             };
     196         746 :             for (size_t i = 0; i < SAL_N_ELEMENTS(aFeatures); ++i)
     197             :             {
     198         726 :                 if (aRequires.equalsAscii(aFeatures[i]))
     199             :                 {
     200         644 :                     m_bTookChoice = true;
     201         644 :                     return false;
     202             :                 }
     203             :             }
     204          20 :             return true;
     205             :         }
     206             :             break;
     207             :         case OOXML_Fallback:
     208             :             // If Choice is already taken, then let's ignore the Fallback.
     209         664 :             return m_bTookChoice;
     210             :             break;
     211             :         default:
     212             :             SAL_WARN("writerfilter", "OOXMLFastContextHandler::prepareMceContext: unhandled element:" << oox::getBaseToken(nElement));
     213           0 :             break;
     214             :     }
     215         664 :     return false;
     216             : }
     217             : 
     218             : // ::com::sun::star::xml::sax::XFastContextHandler:
     219     1166682 : void SAL_CALL OOXMLFastContextHandler::startFastElement
     220             : (Token_t Element,
     221             :  const uno::Reference< xml::sax::XFastAttributeList > & Attribs)
     222             :     throw (uno::RuntimeException, xml::sax::SAXException, std::exception)
     223             : {
     224             : #ifdef DEBUG_CONTEXT_HANDLER
     225             :     debug_logger->startElement("contexthandler.element");
     226             :     string sToken = fastTokenToId(Element);
     227             :     mpParserState->getXPathLogger().startElement(sToken);
     228             :     debug_logger->attribute("token", sToken);
     229             :     debug_logger->attribute("type", getType());
     230             :     debug_logger->attribute("xpath", mpParserState->getXPathLogger().getXPath());
     231             :     debug_logger->startElement("at-start");
     232             :     dumpXml( debug_logger );
     233             :     debug_logger->endElement();
     234             : #endif
     235     1166682 :     if (oox::getNamespace(Element) == static_cast<sal_Int32>(NS_mce))
     236        1992 :         m_bDiscardChildren = prepareMceContext(Element, Attribs);
     237             : 
     238     1164690 :     else if (!m_bDiscardChildren)
     239             :     {
     240     1164690 :         attributes(Attribs);
     241     1164690 :         lcl_startFastElement(Element, Attribs);
     242             :     }
     243     1166682 : }
     244             : 
     245         154 : void SAL_CALL OOXMLFastContextHandler::startUnknownElement
     246             : (const OUString & Namespace, const OUString & Name,
     247             :  const uno::Reference< xml::sax::XFastAttributeList > & /*Attribs*/)
     248             : throw (uno::RuntimeException, xml::sax::SAXException, std::exception)
     249             : {
     250             : #ifdef DEBUG_CONTEXT_HANDLER
     251             :     debug_logger->startElement("contexthandler.unknown-element");
     252             :     debug_logger->attribute("namespace", Namespace);
     253             :     debug_logger->attribute("name", Name);
     254             :     mpParserState->getXPathLogger().startElement("unknown");
     255             : #else
     256             :     (void) Namespace;
     257             :     (void) Name;
     258             : #endif
     259         154 : }
     260             : 
     261     1166670 : void SAL_CALL OOXMLFastContextHandler::endFastElement(Token_t Element)
     262             : throw (uno::RuntimeException, xml::sax::SAXException, std::exception)
     263             : {
     264             : #ifdef DEBUG_CONTEXT_HANDLER
     265             :     string sToken = fastTokenToId(Element);
     266             :     (void) sToken;
     267             : #endif
     268             : 
     269     1166670 :     if (Element == (NS_mce | OOXML_Choice) || Element == (NS_mce | OOXML_Fallback))
     270        1328 :         m_bDiscardChildren = false;
     271     1165342 :     else if (Element == (NS_mce | OOXML_AlternateContent))
     272             :     {
     273         664 :         SavedAlternateState aState(m_aSavedAlternateStates.top());
     274         664 :         m_aSavedAlternateStates.pop();
     275         664 :         m_bDiscardChildren = aState.m_bDiscardChildren;
     276         664 :         m_bTookChoice = aState.m_bTookChoice;
     277             :     }
     278             : 
     279     1164678 :     else if (!m_bDiscardChildren)
     280     1164678 :         lcl_endFastElement(Element);
     281             : 
     282             : #ifdef DEBUG_CONTEXT_HANDLER
     283             :     debug_logger->startElement("at-end");
     284             :     dumpXml( debug_logger );
     285             :     debug_logger->endElement();
     286             :     debug_logger->endElement();
     287             :     mpParserState->getXPathLogger().endElement();
     288             : #endif
     289     1166670 : }
     290             : 
     291     1125004 : void OOXMLFastContextHandler::lcl_startFastElement
     292             : (Token_t Element,
     293             :  const uno::Reference< xml::sax::XFastAttributeList > & /*Attribs*/)
     294             :     throw (uno::RuntimeException, xml::sax::SAXException)
     295             : {
     296     1125004 :     OOXMLFactory::getInstance()->startAction(this, Element);
     297     1125004 :     if( Element == (NS_wordprocessingDrawing|OOXML_positionV) )
     298         608 :         inPositionV = true;
     299     1124396 :     else if( Element == (NS_wordprocessingDrawing|OOXML_positionH) )
     300         608 :         inPositionV = false;
     301             : 
     302     1125004 : }
     303             : 
     304      103893 : void OOXMLFastContextHandler::lcl_endFastElement
     305             : (Token_t Element)
     306             :     throw (uno::RuntimeException, xml::sax::SAXException)
     307             : {
     308      103893 :     OOXMLFactory::getInstance()->endAction(this, Element);
     309      103893 : }
     310             : 
     311         154 : void SAL_CALL OOXMLFastContextHandler::endUnknownElement
     312             : (const OUString & , const OUString & )
     313             : throw (uno::RuntimeException, xml::sax::SAXException, std::exception)
     314             : {
     315             : #ifdef DEBUG_CONTEXT_HANDLER
     316             :     debug_logger->endElement();
     317             :     mpParserState->getXPathLogger().endElement();
     318             : #endif
     319         154 : }
     320             : 
     321             : uno::Reference< xml::sax::XFastContextHandler > SAL_CALL
     322     1172215 :  OOXMLFastContextHandler::createFastChildContext
     323             : (Token_t Element,
     324             :  const uno::Reference< xml::sax::XFastAttributeList > & Attribs)
     325             :     throw (uno::RuntimeException, xml::sax::SAXException, std::exception)
     326             : {
     327             : #ifdef DEBUG_CONTEXT_HANDLER
     328             :     debug_logger->startElement("contexthandler.createFastChildContext");
     329             :     debug_logger->attribute("token", fastTokenToId(Element));
     330             :     debug_logger->attribute("type", getType());
     331             :     debug_logger->attribute("discard-children", OUString::number(m_bDiscardChildren));
     332             : #endif
     333             : 
     334     1172215 :     uno::Reference< xml::sax::XFastContextHandler > xResult;
     335     1172215 :     if ((Element & 0xffff0000) != NS_mce && !m_bDiscardChildren)
     336     1169559 :         xResult.set(lcl_createFastChildContext(Element, Attribs));
     337        2656 :     else if ((Element & 0xffff0000) == NS_mce)
     338        1992 :         xResult = this;
     339             : 
     340             : #ifdef DEBUG_CONTEXT_HANDLER
     341             :     debug_logger->endElement();
     342             : #endif
     343             : 
     344     1172215 :     return xResult;
     345             : }
     346             : 
     347             : uno::Reference< xml::sax::XFastContextHandler >
     348     1131361 :  OOXMLFastContextHandler::lcl_createFastChildContext
     349             : (Token_t Element,
     350             :  const uno::Reference< xml::sax::XFastAttributeList > & /*Attribs*/)
     351             :     throw (uno::RuntimeException, xml::sax::SAXException)
     352             : {
     353     1131361 :     return OOXMLFactory::getInstance()->createFastChildContext(this, Element);
     354             : }
     355             : 
     356             : uno::Reference< xml::sax::XFastContextHandler > SAL_CALL
     357         154 : OOXMLFastContextHandler::createUnknownChildContext
     358             : (const OUString & Namespace,
     359             :  const OUString & Name,
     360             :  const uno::Reference< xml::sax::XFastAttributeList > & /*Attribs*/)
     361             :     throw (uno::RuntimeException, xml::sax::SAXException, std::exception)
     362             : {
     363             : #ifdef DEBUG_CONTEXT_HANDLER
     364             :     debug_logger->startElement("contexthandler.createUnknownChildContext");
     365             :     debug_logger->attribute("namespace", Namespace);
     366             :     debug_logger->attribute("name", Name);
     367             :     debug_logger->endElement();
     368             : #else
     369             :     (void) Namespace;
     370             :     (void) Name;
     371             : #endif
     372             : 
     373             :     return uno::Reference< xml::sax::XFastContextHandler >
     374         154 :         (new OOXMLFastContextHandler(*const_cast<const OOXMLFastContextHandler *>(this)));
     375             : }
     376             : 
     377      105809 : void SAL_CALL OOXMLFastContextHandler::characters
     378             : (const OUString & aChars)
     379             :     throw (uno::RuntimeException, xml::sax::SAXException, std::exception)
     380             : {
     381      105809 :     lcl_characters(aChars);
     382      105809 : }
     383             : 
     384       94161 : void OOXMLFastContextHandler::lcl_characters
     385             : (const OUString & rString)
     386             : throw (uno::RuntimeException, xml::sax::SAXException)
     387             : {
     388       94161 :     if (!m_bDiscardChildren)
     389       94025 :         OOXMLFactory::getInstance()->characters(this, rString);
     390       94161 : }
     391             : 
     392             : namespace
     393             : {
     394             :     class theOOXMLFastContextHandlerUnoTunnelId : public rtl::Static< UnoTunnelIdInit, theOOXMLFastContextHandlerUnoTunnelId > {};
     395             : }
     396             : 
     397           0 : const uno::Sequence< sal_Int8 > & OOXMLFastContextHandler::getUnoTunnelId()
     398             : {
     399           0 :     return theOOXMLFastContextHandlerUnoTunnelId::get().getSeq();
     400             : }
     401             : 
     402           0 : sal_Int64 SAL_CALL OOXMLFastContextHandler::getSomething( const uno::Sequence< sal_Int8 >& rId )
     403             :     throw(uno::RuntimeException)
     404             : {
     405           0 :     if( rId.getLength() == 16
     406           0 :         && 0 == memcmp( getUnoTunnelId().getConstArray(),
     407           0 :                                         rId.getConstArray(), 16 ) )
     408             :     {
     409             :         return sal::static_int_cast<sal_Int64>
     410           0 :             (reinterpret_cast<sal_IntPtr>(this));
     411             :     }
     412             : 
     413           0 :     return 0x0;
     414             : }
     415             : 
     416        5380 : void OOXMLFastContextHandler::setStream(Stream * pStream)
     417             : {
     418        5380 :     mpStream = pStream;
     419        5380 : }
     420             : 
     421           0 : OOXMLValue::Pointer_t OOXMLFastContextHandler::getValue() const
     422             : {
     423           0 :     return OOXMLValue::Pointer_t();
     424             : }
     425             : 
     426     1132053 : void OOXMLFastContextHandler::attributes
     427             : (const uno::Reference< xml::sax::XFastAttributeList > & Attribs)
     428             :  throw (uno::RuntimeException, xml::sax::SAXException)
     429             : {
     430     1132053 :     OOXMLFactory::getInstance()->attributes(this, Attribs);
     431     1132053 : }
     432             : 
     433        1722 : void OOXMLFastContextHandler::startAction(Token_t Element)
     434             : {
     435             : #ifdef DEBUG_CONTEXT_HANDLER
     436             :     debug_logger->startElement("contexthandler.startAction");
     437             : #endif
     438        1722 :     lcl_startAction(Element);
     439             : #ifdef DEBUG_CONTEXT_HANDLER
     440             :     debug_logger->endElement();
     441             : #endif
     442        1722 : }
     443             : 
     444        1722 : void OOXMLFastContextHandler::lcl_startAction(Token_t Element)
     445             : {
     446        1722 :     OOXMLFactory::getInstance()->startAction(this, Element);
     447        1722 : }
     448             : 
     449     1020516 : void OOXMLFastContextHandler::endAction(Token_t Element)
     450             : {
     451             : #ifdef DEBUG_CONTEXT_HANDLER
     452             :     debug_logger->startElement("contexthandler.endAction");
     453             : #endif
     454     1020516 :     lcl_endAction(Element);
     455             : #ifdef DEBUG_CONTEXT_HANDLER
     456             :     debug_logger->endElement();
     457             : #endif
     458     1020516 : }
     459             : 
     460     1020516 : void OOXMLFastContextHandler::lcl_endAction(Token_t Element)
     461             : {
     462     1020516 :     OOXMLFactory::getInstance()->endAction(this, Element);
     463     1020516 : }
     464             : 
     465             : #if OSL_DEBUG_LEVEL > 1
     466             : void OOXMLFastContextHandler::dumpXml( const TagLogger::Pointer_t pLogger ) const
     467             : {
     468             :     pLogger->startElement("context");
     469             : 
     470             :     static char sBuffer[128];
     471             :     snprintf(sBuffer, sizeof(sBuffer), "%p", this);
     472             : 
     473             :     pLogger->attribute("parent", std::string(sBuffer));
     474             :     pLogger->attribute("type", getType());
     475             :     pLogger->attribute("resource", resourceToString(getResource()));
     476             :     pLogger->attribute("token", fastTokenToId(getToken()));
     477             :     pLogger->attribute("id", (*QNameToString::Instance())(getId()));
     478             : 
     479             :     OOXMLValue::Pointer_t pVal(getValue());
     480             : 
     481             :     if (pVal.get() != NULL)
     482             :         pLogger->attribute("value", pVal->toString());
     483             :     else
     484             :         pLogger->attribute("value", std::string("(null)"));
     485             : 
     486             :     pLogger->propertySet(getPropertySet(),
     487             :             IdToString::Pointer_t(new OOXMLIdToString()));
     488             : 
     489             :     mpParserState->dumpXml( pLogger );
     490             : 
     491             :     pLogger->endElement();
     492             : }
     493             : 
     494             : #endif
     495             : 
     496     1157429 : void OOXMLFastContextHandler::setId(Id rId)
     497             : {
     498             : #ifdef DEBUG_CONTEXT_HANDLER
     499             :     debug_logger->startElement("contexthandler.setId");
     500             : 
     501             :     static char sBuffer[256];
     502             :     snprintf(sBuffer, sizeof(sBuffer), "%" SAL_PRIuUINT32, rId);
     503             : 
     504             :     debug_logger->attribute("id", std::string(sBuffer));
     505             :     debug_logger->attribute("name", (*QNameToString::Instance())(rId));
     506             :     debug_logger->endElement();
     507             : #endif
     508             : 
     509     1157429 :     mId = rId;
     510     1157429 : }
     511             : 
     512      577281 : Id OOXMLFastContextHandler::getId() const
     513             : {
     514      577281 :     return mId;
     515             : }
     516             : 
     517     1126921 : void OOXMLFastContextHandler::setDefine(Id nDefine)
     518             : {
     519     1126921 :     mnDefine = nDefine;
     520     1126921 : }
     521             : 
     522     9374385 : Id OOXMLFastContextHandler::getDefine() const
     523             : {
     524     9374385 :     return mnDefine;
     525             : }
     526             : 
     527        1745 : OOXMLParserState::Pointer_t OOXMLFastContextHandler::getParserState() const
     528             : {
     529        1745 :     return mpParserState;
     530             : }
     531             : 
     532     1157429 : void OOXMLFastContextHandler::setToken(Token_t nToken)
     533             : {
     534     1157429 :     mnToken = nToken;
     535             : 
     536             : #ifdef DEBUG_CONTEXT_HANDLER
     537             :     msTokenString = fastTokenToId(mnToken);
     538             : #endif
     539     1157429 : }
     540             : 
     541       31450 : Token_t OOXMLFastContextHandler::getToken() const
     542             : {
     543       31450 :     return mnToken;
     544             : }
     545             : 
     546           0 : void OOXMLFastContextHandler::setParent
     547             : (OOXMLFastContextHandler * pParent)
     548             : {
     549           0 :     mpParent = pParent;
     550           0 : }
     551             : 
     552           0 : OOXMLPropertySet * OOXMLFastContextHandler::getPicturePropSet
     553             : (const OUString & rId)
     554             : {
     555           0 :     return mpParserState->getDocument()->getPicturePropSet(rId);
     556             : }
     557             : 
     558       18234 : void OOXMLFastContextHandler::sendTableDepth() const
     559             : {
     560             : #ifdef DEBUG_CONTEXT_HANDLER
     561             :     debug_logger->startElement("contexthandler.sendTableDepth");
     562             : #endif
     563             : 
     564       18234 :     if (mnTableDepth > 0)
     565             :     {
     566        7246 :         OOXMLPropertySet * pProps = new OOXMLPropertySetImpl();
     567             :         {
     568             :             OOXMLValue::Pointer_t pVal
     569        7246 :                 (new OOXMLIntegerValue(mnTableDepth));
     570             :             OOXMLProperty::Pointer_t pProp
     571       14492 :                 (new OOXMLPropertyImpl(NS_ooxml::LN_tblDepth, pVal, OOXMLPropertyImpl::SPRM));
     572       14492 :             pProps->add(pProp);
     573             :         }
     574             :         {
     575             :             OOXMLValue::Pointer_t pVal
     576        7246 :                 (new OOXMLIntegerValue(1));
     577             :             OOXMLProperty::Pointer_t pProp
     578       14492 :                 (new OOXMLPropertyImpl(NS_ooxml::LN_inTbl, pVal, OOXMLPropertyImpl::SPRM));
     579       14492 :             pProps->add(pProp);
     580             :         }
     581             : 
     582        7246 :         mpStream->props(writerfilter::Reference<Properties>::Pointer_t(pProps));
     583             :     }
     584             : #ifdef DEBUG_CONTEXT_HANDLER
     585             :     debug_logger->endElement();
     586             : #endif
     587       18234 : }
     588             : 
     589       18234 : void OOXMLFastContextHandler::setHandle()
     590             : {
     591       18234 :     mpParserState->setHandle();
     592       18234 :     mpStream->info(mpParserState->getHandle());
     593       18234 : }
     594             : 
     595       49773 : void OOXMLFastContextHandler::startCharacterGroup()
     596             : {
     597             : #ifdef DEBUG_CONTEXT_HANDLER
     598             :     debug_logger->element("contexthandler.startCharacterGroup");
     599             : #endif
     600             : 
     601       49773 :     if (isForwardEvents())
     602             :     {
     603       48579 :         if (mpParserState->isInCharacterGroup())
     604       22999 :             endCharacterGroup();
     605             : 
     606       48579 :         if (! mpParserState->isInParagraphGroup())
     607           1 :             startParagraphGroup();
     608             : 
     609       48579 :         if (! mpParserState->isInCharacterGroup())
     610             :         {
     611       48579 :             mpStream->startCharacterGroup();
     612       48579 :             mpParserState->setInCharacterGroup(true);
     613       48579 :             mpParserState->resolveCharacterProperties(*mpStream);
     614             :         }
     615             :     }
     616       49773 : }
     617             : 
     618       48597 : void OOXMLFastContextHandler::endCharacterGroup()
     619             : {
     620             : #ifdef DEBUG_CONTEXT_HANDLER
     621             :     debug_logger->element("contexthandler.endCharacterGroup");
     622             : #endif
     623             : 
     624       48597 :     if (isForwardEvents() && mpParserState->isInCharacterGroup())
     625             :     {
     626       48576 :         mpStream->endCharacterGroup();
     627       48576 :         mpParserState->setInCharacterGroup(false);
     628             :     }
     629       48597 : }
     630             : 
     631       20656 : void OOXMLFastContextHandler::startParagraphGroup()
     632             : {
     633             : #ifdef DEBUG_CONTEXT_HANDLER
     634             :     debug_logger->element("contexthandler.startParagraphGroup");
     635             : #endif
     636             : 
     637       20656 :     if (isForwardEvents())
     638             :     {
     639       20422 :         if (mpParserState->isInParagraphGroup())
     640        9676 :             endParagraphGroup();
     641             : 
     642       20422 :         if (! mpParserState->isInSectionGroup())
     643          60 :             startSectionGroup();
     644             : 
     645       20422 :         if (! mpParserState->isInParagraphGroup())
     646             :         {
     647       20422 :             mpStream->startParagraphGroup();
     648       20422 :             mpParserState->setInParagraphGroup(true);
     649             :         }
     650             :     }
     651       20656 : }
     652             : 
     653       20431 : void OOXMLFastContextHandler::endParagraphGroup()
     654             : {
     655             : #ifdef DEBUG_CONTEXT_HANDLER
     656             :     debug_logger->element("contexthandler.endParagraphGroup");
     657             : #endif
     658             : 
     659       20431 :     if (isForwardEvents())
     660             :     {
     661       20431 :         if (mpParserState->isInCharacterGroup())
     662       17099 :             endCharacterGroup();
     663             : 
     664       20431 :         if (mpParserState->isInParagraphGroup())
     665             :         {
     666       20419 :             mpStream->endParagraphGroup();
     667       20419 :             mpParserState->setInParagraphGroup(false);
     668             :         }
     669             :     }
     670       20431 : }
     671             : 
     672         194 : void OOXMLFastContextHandler::startSdt()
     673             : {
     674             : #ifdef DEBUG_CONTEXT_HANDLER
     675             :     debug_logger->element("contexthandler.startSdt");
     676             : #endif
     677             : 
     678         194 :     OOXMLPropertySet * pProps = new OOXMLPropertySetImpl();
     679         194 :     OOXMLValue::Pointer_t pVal(new OOXMLIntegerValue(1));
     680         388 :     OOXMLProperty::Pointer_t pProp(new OOXMLPropertyImpl(NS_ooxml::LN_CT_SdtBlock_sdtContent, pVal, OOXMLPropertyImpl::ATTRIBUTE));
     681         194 :     pProps->add(pProp);
     682         388 :     mpStream->props(writerfilter::Reference<Properties>::Pointer_t(pProps));
     683         194 : }
     684             : 
     685         194 : void OOXMLFastContextHandler::endSdt()
     686             : {
     687             : #ifdef DEBUG_CONTEXT_HANDLER
     688             :     debug_logger->element("contexthandler.endSdt");
     689             : #endif
     690             : 
     691         194 :     OOXMLPropertySet * pProps = new OOXMLPropertySetImpl();
     692         194 :     OOXMLValue::Pointer_t pVal(new OOXMLIntegerValue(1));
     693         388 :     OOXMLProperty::Pointer_t pProp(new OOXMLPropertyImpl(NS_ooxml::LN_CT_SdtBlock_sdtEndContent, pVal, OOXMLPropertyImpl::ATTRIBUTE));
     694         194 :     pProps->add(pProp);
     695         388 :     mpStream->props(writerfilter::Reference<Properties>::Pointer_t(pProps));
     696         194 : }
     697             : 
     698        1064 : void OOXMLFastContextHandler::startSectionGroup()
     699             : {
     700             : #ifdef DEBUG_CONTEXT_HANDLER
     701             :     debug_logger->element("contexthandler.startSectionGroup");
     702             : #endif
     703             : 
     704        1064 :     if (isForwardEvents())
     705             :     {
     706        1064 :         if (mpParserState->isInSectionGroup())
     707          89 :             endSectionGroup();
     708             : 
     709        1064 :         if (! mpParserState->isInSectionGroup())
     710             :         {
     711        1064 :             mpStream->info(mpParserState->getHandle());
     712        1064 :             mpStream->startSectionGroup();
     713        1064 :             mpParserState->setInSectionGroup(true);
     714             :         }
     715             :     }
     716        1064 : }
     717             : 
     718        1570 : void OOXMLFastContextHandler::endSectionGroup()
     719             : {
     720             : #ifdef DEBUG_CONTEXT_HANDLER
     721             :     debug_logger->element("contexthandler.endSectionGroup");
     722             : #endif
     723             : 
     724        1570 :     if (isForwardEvents())
     725             :     {
     726        1122 :         if (mpParserState->isInParagraphGroup())
     727         160 :             endParagraphGroup();
     728             : 
     729        1122 :         if (mpParserState->isInSectionGroup())
     730             :         {
     731        1062 :             mpStream->endSectionGroup();
     732        1062 :             mpParserState->setInSectionGroup(false);
     733             :         }
     734             :     }
     735        1570 : }
     736             : 
     737         999 : void OOXMLFastContextHandler::setLastParagraphInSection()
     738             : {
     739         999 :     mpParserState->setLastParagraphInSection(true);
     740         999 :     mpStream->markLastParagraphInSection( );
     741         999 : }
     742             : 
     743      293741 : void OOXMLFastContextHandler::newProperty
     744             : (const Id & /*nId*/, OOXMLValue::Pointer_t /*pVal*/)
     745             : {
     746      293741 : }
     747             : 
     748         258 : void OOXMLFastContextHandler::setPropertySet
     749             : (OOXMLPropertySet::Pointer_t /* pPropertySet */)
     750             : {
     751         258 : }
     752             : 
     753       34780 : OOXMLPropertySet::Pointer_t OOXMLFastContextHandler::getPropertySet() const
     754             : {
     755       34780 :     return OOXMLPropertySet::Pointer_t();
     756             : }
     757             : 
     758        1856 : void OOXMLFastContextHandler::startField()
     759             : {
     760             : #ifdef DEBUG_CONTEXT_HANDLER
     761             :     debug_logger->element("contexthandler.startField");
     762             : #endif
     763        1856 :     startCharacterGroup();
     764        1856 :     if (isForwardEvents())
     765        1850 :         mpStream->text(&cFieldStart, 1);
     766        1856 :     endCharacterGroup();
     767        1856 : }
     768             : 
     769        1750 : void OOXMLFastContextHandler::fieldSeparator()
     770             : {
     771             : #ifdef DEBUG_CONTEXT_HANDLER
     772             :     debug_logger->element("contexthandler.fieldSeparator");
     773             : #endif
     774        1750 :     startCharacterGroup();
     775        1750 :     if (isForwardEvents())
     776        1744 :         mpStream->text(&cFieldSep, 1);
     777        1750 :     endCharacterGroup();
     778        1750 : }
     779             : 
     780        1856 : void OOXMLFastContextHandler::endField()
     781             : {
     782             : #ifdef DEBUG_CONTEXT_HANDLER
     783             :     debug_logger->element("contexthandler.endField");
     784             : #endif
     785        1856 :     startCharacterGroup();
     786        1856 :     if (isForwardEvents())
     787        1850 :         mpStream->text(&cFieldEnd, 1);
     788        1856 :     endCharacterGroup();
     789        1856 : }
     790             : 
     791         224 : void OOXMLFastContextHandler::ftnednref()
     792             : {
     793             : #ifdef DEBUG_CONTEXT_HANDLER
     794             :     debug_logger->element("contexthandler.ftnednref");
     795             : #endif
     796         224 :     if (isForwardEvents())
     797          30 :         mpStream->utext((const sal_uInt8*)&uFtnEdnRef, 1);
     798         224 : }
     799             : 
     800          24 : void OOXMLFastContextHandler::ftnednsep()
     801             : {
     802             : #ifdef DEBUG_CONTEXT_HANDLER
     803             :     debug_logger->element("contexthandler.ftnednsep");
     804             : #endif
     805          24 :     if (isForwardEvents())
     806          24 :         mpStream->utext((const sal_uInt8*)&uFtnEdnSep, 1);
     807          24 : }
     808             : 
     809          30 : void OOXMLFastContextHandler::ftnedncont()
     810             : {
     811             : #ifdef DEBUG_CONTEXT_HANDLER
     812             :     debug_logger->element("contexthandler.ftnedncont");
     813             : #endif
     814          30 :     if (isForwardEvents())
     815           0 :         mpStream->text(&cFtnEdnCont, 1);
     816          30 : }
     817             : 
     818           0 : void OOXMLFastContextHandler::pgNum()
     819             : {
     820             : #ifdef DEBUG_CONTEXT_HANDLER
     821             :     debug_logger->element("contexthandler.pgNum");
     822             : #endif
     823           0 :     if (isForwardEvents())
     824           0 :         mpStream->utext((const sal_uInt8*)&uPgNum, 1);
     825           0 : }
     826             : 
     827        4436 : void OOXMLFastContextHandler::tab()
     828             : {
     829             : #ifdef DEBUG_CONTEXT_HANDLER
     830             :     debug_logger->element("contexthandler.tab");
     831             : #endif
     832        4436 :     if (isForwardEvents())
     833        4432 :         mpStream->utext((const sal_uInt8*)&uTab, 1);
     834        4436 : }
     835             : 
     836           0 : void OOXMLFastContextHandler::cr()
     837             : {
     838             : #ifdef DEBUG_CONTEXT_HANDLER
     839             :     debug_logger->element("contexthandler.cr");
     840             : #endif
     841           0 :     if (isForwardEvents())
     842           0 :         mpStream->utext((const sal_uInt8*)&uCR, 1);
     843           0 : }
     844             : 
     845           3 : void OOXMLFastContextHandler::noBreakHyphen()
     846             : {
     847             : #ifdef DEBUG_CONTEXT_HANDLER
     848             :     debug_logger->element("contexthandler.noBreakHyphen");
     849             : #endif
     850           3 :     if (isForwardEvents())
     851           3 :         mpStream->utext((const sal_uInt8*)&uNoBreakHyphen, 1);
     852           3 : }
     853             : 
     854          28 : void OOXMLFastContextHandler::softHyphen()
     855             : {
     856             : #ifdef DEBUG_CONTEXT_HANDLER
     857             :     debug_logger->element("contexthandler.softHyphen");
     858             : #endif
     859          28 :     if (isForwardEvents())
     860          28 :         mpStream->utext((const sal_uInt8*)&uSoftHyphen, 1);
     861          28 : }
     862             : 
     863       18234 : void OOXMLFastContextHandler::handleLastParagraphInSection()
     864             : {
     865             : #ifdef DEBUG_CONTEXT_HANDLER
     866             :     debug_logger->element("contexthandler.handleLastParagraphInSection");
     867             : #endif
     868             : 
     869       18234 :     if (mpParserState->isLastParagraphInSection())
     870             :     {
     871          89 :         mpParserState->setLastParagraphInSection(false);
     872          89 :         startSectionGroup();
     873             :     }
     874       18234 : }
     875             : 
     876       19290 : void OOXMLFastContextHandler::endOfParagraph()
     877             : {
     878             : #ifdef DEBUG_CONTEXT_HANDLER
     879             :     debug_logger->element("contexthandler.endOfParagraph");
     880             : #endif
     881       19290 :     if (! mpParserState->isInCharacterGroup())
     882        5573 :         startCharacterGroup();
     883       19290 :     if (isForwardEvents())
     884       19056 :         mpStream->utext((const sal_uInt8*)&uCR, 1);
     885             : 
     886       19290 :     mpParserState->getDocument()->incrementProgress();
     887       19290 : }
     888             : 
     889         319 : void OOXMLFastContextHandler::startTxbxContent()
     890             : {
     891             : #ifdef DEBUG_CONTEXT_HANDLER
     892             :     debug_logger->element("contexthandler.startTxbxContent");
     893             : #endif
     894             : /*
     895             :     This usually means there are recursive <w:p> elements, and the ones
     896             :     inside and outside of w:txbxContent should not interfere (e.g.
     897             :     the lastParagraphInSection setting). So save the whole state
     898             :     and possibly start new groups for the nested content (not section
     899             :     group though, as that'd cause the txbxContent to be moved onto
     900             :     another page, I'm not sure how that should work exactly).
     901             : */
     902         319 :     mpParserState->startTxbxContent();
     903         319 :     startParagraphGroup();
     904         319 : }
     905             : 
     906         319 : void OOXMLFastContextHandler::endTxbxContent()
     907             : {
     908             : #ifdef DEBUG_CONTEXT_HANDLER
     909             :     debug_logger->element("contexthandler.endTxbxContent");
     910             : #endif
     911         319 :     endParagraphGroup();
     912         319 :     mpParserState->endTxbxContent();
     913         319 : }
     914             : 
     915       29502 : void OOXMLFastContextHandler::text(const OUString & sText)
     916             : {
     917             : #ifdef DEBUG_CONTEXT_HANDLER
     918             :     debug_logger->startElement("contexthandler.text");
     919             :     debug_logger->chars(sText);
     920             :     debug_logger->endElement();
     921             : #endif
     922       29502 :     if (isForwardEvents())
     923             :         mpStream->utext(reinterpret_cast < const sal_uInt8 * >
     924       28798 :                         (sText.getStr()),
     925       57596 :                         sText.getLength());
     926       29502 : }
     927             : 
     928             : /*
     929             :  HACK. An ugly hack. The problem with wp:positionOffset, wp:alignV and wp:alignH
     930             :  is that they do not work in the usual OOXML way of <tag val="value"/> but instead
     931             :  it's <tag>value</tag>, which is otherwise used only things like <t>. And I really
     932             :  haven't managed to find out how to make this XML parsing monstrosity to handle this
     933             :  on its own, so the code is modelled after <t> handling and does it manually in a hackish
     934             :  way - it reads the value as text and converts itself, moreover the reading of the value
     935             :  is done sooner than lcl_sprms() actually results in processing the tags it is enclosed
     936             :  in, so the values are stored in PositionHandler for later use.
     937             : */
     938        1157 : void OOXMLFastContextHandler::positionOffset(const OUString & sText)
     939             : {
     940             : #ifdef DEBUG_ELEMENT
     941             :     debug_logger->startElement("positionOffset");
     942             :     debug_logger->chars(sText);
     943             :     debug_logger->endElement();
     944             : #endif
     945        1157 :     if (isForwardEvents())
     946        1157 :         ::writerfilter::dmapper::PositionHandler::setPositionOffset( sText, inPositionV );
     947        1157 : }
     948             : 
     949          38 : void OOXMLFastContextHandler::alignH(const OUString & sText)
     950             : {
     951             : #ifdef DEBUG_ELEMENT
     952             :     debug_logger->startElement("alignH");
     953             :     debug_logger->chars(sText);
     954             :     debug_logger->endElement();
     955             : #endif
     956          38 :     if (isForwardEvents())
     957          38 :         ::writerfilter::dmapper::PositionHandler::setAlignH( sText );
     958          38 : }
     959             : 
     960          21 : void OOXMLFastContextHandler::alignV(const OUString & sText)
     961             : {
     962             : #ifdef DEBUG_ELEMENT
     963             :     debug_logger->startElement("alignV");
     964             :     debug_logger->chars(sText);
     965             :     debug_logger->endElement();
     966             : #endif
     967          21 :     if (isForwardEvents())
     968          21 :         ::writerfilter::dmapper::PositionHandler::setAlignV( sText );
     969          21 : }
     970             : 
     971         637 : void OOXMLFastContextHandler::positivePercentage(const OUString& rText)
     972             : {
     973             : #ifdef DEBUG_ELEMENT
     974             :     debug_logger->startElement("positivePercentage");
     975             :     debug_logger->chars(rText);
     976             :     debug_logger->endElement();
     977             : #endif
     978         637 :     if (isForwardEvents())
     979         637 :         mpStream->positivePercentage(rText);
     980         637 : }
     981             : 
     982         284 : void OOXMLFastContextHandler::propagateCharacterProperties()
     983             : {
     984             : #ifdef DEBUG_CONTEXT_HANDLER
     985             :     debug_logger->startElement("contexthandler.propagateCharacterProperties");
     986             :     debug_logger->propertySet(getPropertySet(),
     987             :             IdToString::Pointer_t(new OOXMLIdToString()));
     988             :     debug_logger->endElement();
     989             : #endif
     990             : 
     991         284 :     mpParserState->setCharacterProperties(getPropertySet());
     992         284 : }
     993             : 
     994         950 : void OOXMLFastContextHandler::propagateCharacterPropertiesAsSet(const Id & rId)
     995             : {
     996             : #ifdef DEBUG_CONTEXT_HANDLER
     997             :     debug_logger->startElement("contexthandler.propagateCharacterPropertiesAsSet");
     998             :     debug_logger->propertySet(getPropertySet(),
     999             :             IdToString::Pointer_t(new OOXMLIdToString()));
    1000             :     debug_logger->endElement();
    1001             : #endif
    1002             : 
    1003         950 :     OOXMLValue::Pointer_t pValue(new OOXMLPropertySetValue(getPropertySet()));
    1004        1900 :     OOXMLPropertySet::Pointer_t pPropertySet(new OOXMLPropertySetImpl());
    1005             : 
    1006             :     OOXMLProperty::Pointer_t pProp
    1007        1900 :         (new OOXMLPropertyImpl(rId, pValue, OOXMLPropertyImpl::SPRM));
    1008             : 
    1009         950 :     pPropertySet->add(pProp);
    1010        1900 :     mpParserState->setCharacterProperties(pPropertySet);
    1011         950 : }
    1012             : 
    1013           0 : bool OOXMLFastContextHandler::propagatesProperties() const
    1014             : {
    1015           0 :     return false;
    1016             : }
    1017             : 
    1018        6449 : void OOXMLFastContextHandler::propagateCellProperties()
    1019             : {
    1020             : #ifdef DEBUG_CONTEXT_HANDLER
    1021             :     debug_logger->element("contexthandler.propagateCellProperties");
    1022             : #endif
    1023             : 
    1024        6449 :     mpParserState->setCellProperties(getPropertySet());
    1025        6449 : }
    1026             : 
    1027        1638 : void OOXMLFastContextHandler::propagateRowProperties()
    1028             : {
    1029             : #ifdef DEBUG_CONTEXT_HANDLER
    1030             :     debug_logger->element("contexthandler.propagateRowProperties");
    1031             : #endif
    1032             : 
    1033        1638 :     mpParserState->setRowProperties(getPropertySet());
    1034        1638 : }
    1035             : 
    1036         660 : void OOXMLFastContextHandler::propagateTableProperties()
    1037             : {
    1038         660 :     OOXMLPropertySet::Pointer_t pProps = getPropertySet();
    1039             : #ifdef DEBUG_CONTEXT_HANDLER
    1040             :     debug_logger->startElement("contexthandler.propagateTableProperties");
    1041             :     debug_logger->propertySet(getPropertySet(),
    1042             :             IdToString::Pointer_t(new OOXMLIdToString()));
    1043             :     debug_logger->endElement();
    1044             : #endif
    1045             : 
    1046         660 :     mpParserState->setTableProperties(pProps);
    1047         660 : }
    1048             : 
    1049        6472 : void OOXMLFastContextHandler::sendCellProperties()
    1050             : {
    1051             : #ifdef DEBUG_CONTEXT_HANDLER
    1052             :     debug_logger->startElement("contexthandler.sendCellProperties");
    1053             : #endif
    1054             : 
    1055        6472 :     mpParserState->resolveCellProperties(*mpStream);
    1056             : 
    1057             : #ifdef DEBUG_CONTEXT_HANDLER
    1058             :     debug_logger->endElement();
    1059             : #endif
    1060        6472 : }
    1061             : 
    1062        2102 : void OOXMLFastContextHandler::sendRowProperties()
    1063             : {
    1064             : #ifdef DEBUG_CONTEXT_HANDLER
    1065             :     debug_logger->startElement("contexthandler.sendRowProperties");
    1066             : #endif
    1067             : 
    1068        2102 :     mpParserState->resolveRowProperties(*mpStream);
    1069             : 
    1070             : #ifdef DEBUG_CONTEXT_HANDLER
    1071             :     debug_logger->endElement();
    1072             : #endif
    1073        2102 : }
    1074             : 
    1075        2102 : void OOXMLFastContextHandler::sendTableProperties()
    1076             : {
    1077             : #ifdef DEBUG_CONTEXT_HANDLER
    1078             :     debug_logger->startElement("contexthandler.sendTableProperties");
    1079             : #endif
    1080             : 
    1081        2102 :     mpParserState->resolveTableProperties(*mpStream);
    1082             : 
    1083             : #ifdef DEBUG_CONTEXT_HANDLER
    1084             :     debug_logger->endElement();
    1085             : #endif
    1086        2102 : }
    1087             : 
    1088         331 : void OOXMLFastContextHandler::clearTableProps()
    1089             : {
    1090             : #ifdef DEBUG_CONTEXT_HANDLER
    1091             :     debug_logger->element("contexthandler.clearTableProps");
    1092             : #endif
    1093             : 
    1094             :     mpParserState->setTableProperties(OOXMLPropertySet::Pointer_t
    1095         331 :                                      (new OOXMLPropertySetImpl()));
    1096         331 : }
    1097             : 
    1098         205 : void OOXMLFastContextHandler::sendPropertiesWithId(const Id & rId)
    1099             : {
    1100             : #ifdef DEBUG_CONTEXT_HANDLER
    1101             :     debug_logger->startElement("contexthandler.sendPropertiesWithId");
    1102             :     debug_logger->attribute("id", fastTokenToId(rId));
    1103             : #endif
    1104             : 
    1105         205 :     OOXMLValue::Pointer_t pValue(new OOXMLPropertySetValue(getPropertySet()));
    1106         410 :     OOXMLPropertySet::Pointer_t pPropertySet(new OOXMLPropertySetImpl());
    1107             : 
    1108             :     OOXMLProperty::Pointer_t pProp
    1109         410 :     (new OOXMLPropertyImpl(rId, pValue, OOXMLPropertyImpl::SPRM));
    1110             : 
    1111         205 :     pPropertySet->add(pProp);
    1112         410 :     mpStream->props(pPropertySet);
    1113             : 
    1114             : #ifdef DEBUG_CONTEXT_HANDLER
    1115             :     debug_logger->propertySet(getPropertySet(),
    1116             :             IdToString::Pointer_t(new OOXMLIdToString()));
    1117             :     debug_logger->endElement();
    1118             : #endif
    1119         205 : }
    1120             : 
    1121        9902 : void OOXMLFastContextHandler::clearProps()
    1122             : {
    1123             : #ifdef DEBUG_CONTEXT_HANDLER
    1124             :     debug_logger->element("contexthandler.clearProps");
    1125             : #endif
    1126             : 
    1127        9902 :     setPropertySet(OOXMLPropertySet::Pointer_t(new OOXMLPropertySetImpl()));
    1128        9902 : }
    1129             : 
    1130           0 : void OOXMLFastContextHandler::setDefaultBooleanValue()
    1131             : {
    1132           0 : }
    1133             : 
    1134           0 : void OOXMLFastContextHandler::setDefaultIntegerValue()
    1135             : {
    1136           0 : }
    1137             : 
    1138           0 : void OOXMLFastContextHandler::setDefaultHexValue()
    1139             : {
    1140           0 : }
    1141             : 
    1142           0 : void OOXMLFastContextHandler::setDefaultStringValue()
    1143             : {
    1144           0 : }
    1145             : 
    1146        5380 : void OOXMLFastContextHandler::setDocument(OOXMLDocumentImpl* pDocument)
    1147             : {
    1148        5380 :     mpParserState->setDocument(pDocument);
    1149        5380 : }
    1150             : 
    1151        4805 : OOXMLDocumentImpl* OOXMLFastContextHandler::getDocument()
    1152             : {
    1153        4805 :     return mpParserState->getDocument();
    1154             : }
    1155             : 
    1156        5986 : void OOXMLFastContextHandler::setForwardEvents(bool bForwardEvents)
    1157             : {
    1158             : #ifdef DEBUG_CONTEXT_HANDLER
    1159             :     debug_logger->startElement("contexthandler.setForwardEvents");
    1160             : 
    1161             :     if (bForwardEvents)
    1162             :         debug_logger->chars(std::string("true"));
    1163             :     else
    1164             :         debug_logger->chars(std::string("false"));
    1165             : 
    1166             :     debug_logger->endElement();
    1167             : #endif
    1168             : 
    1169        5986 :     mpParserState->setForwardEvents(bForwardEvents);
    1170        5986 : }
    1171             : 
    1172      275712 : bool OOXMLFastContextHandler::isForwardEvents() const
    1173             : {
    1174      275712 :     return mpParserState->isForwardEvents();
    1175             : }
    1176             : 
    1177        5380 : void OOXMLFastContextHandler::setXNoteId(const sal_Int32 nId)
    1178             : {
    1179        5380 :     mpParserState->setXNoteId(nId);
    1180        5380 : }
    1181             : 
    1182          30 : void OOXMLFastContextHandler::setXNoteId(OOXMLValue::Pointer_t pValue)
    1183             : {
    1184          30 :     mpParserState->setXNoteId(sal_Int32(pValue->getInt()));
    1185          30 : }
    1186             : 
    1187         303 : sal_Int32 OOXMLFastContextHandler::getXNoteId() const
    1188             : {
    1189         303 :     return mpParserState->getXNoteId();
    1190             : }
    1191             : 
    1192          24 : void OOXMLFastContextHandler::resolveFootnote
    1193             : (const sal_Int32 nId)
    1194             : {
    1195          24 :     mpParserState->getDocument()->resolveFootnote
    1196          24 :         (*mpStream, 0, nId);
    1197          24 : }
    1198             : 
    1199           6 : void OOXMLFastContextHandler::resolveEndnote(const sal_Int32 nId)
    1200             : {
    1201           6 :     mpParserState->getDocument()->resolveEndnote
    1202           6 :         (*mpStream, 0, nId);
    1203           6 : }
    1204             : 
    1205          11 : void OOXMLFastContextHandler::resolveComment(const sal_Int32 nId)
    1206             : {
    1207          11 :     mpParserState->getDocument()->resolveComment(*mpStream, nId);
    1208          11 : }
    1209             : 
    1210           0 : void OOXMLFastContextHandler::resolvePicture(const OUString & rId)
    1211             : {
    1212           0 :     mpParserState->getDocument()->resolvePicture(*mpStream, rId);
    1213           0 : }
    1214             : 
    1215         388 : void OOXMLFastContextHandler::resolveHeader
    1216             : (const sal_Int32 type, const OUString & rId)
    1217             : {
    1218         388 :     mpParserState->getDocument()->resolveHeader(*mpStream, type, rId);
    1219         388 : }
    1220             : 
    1221         412 : void OOXMLFastContextHandler::resolveFooter
    1222             : (const sal_Int32 type, const OUString & rId)
    1223             : {
    1224         412 :     mpParserState->getDocument()->resolveFooter(*mpStream, type, rId);
    1225         412 : }
    1226             : 
    1227             : // Add the data pointed to by the reference as another property.
    1228          22 : void OOXMLFastContextHandler::resolveData(const OUString & rId)
    1229             : {
    1230          22 :     OOXMLDocument * objDocument = getDocument();
    1231             :     SAL_WARN_IF(!objDocument, "writerfilter", "no document to resolveData");
    1232          22 :     if (!objDocument)
    1233          22 :         return;
    1234             : 
    1235             :     uno::Reference<io::XInputStream> xInputStream
    1236          22 :         (objDocument->getInputStreamForId(rId));
    1237             : 
    1238          44 :     OOXMLValue::Pointer_t aValue(new OOXMLInputStreamValue(xInputStream));
    1239             : 
    1240          44 :     newProperty(NS_ooxml::LN_inputstream, aValue);
    1241             : }
    1242             : 
    1243         593 : OUString OOXMLFastContextHandler::getTargetForId
    1244             : (const OUString & rId)
    1245             : {
    1246         593 :     return mpParserState->getDocument()->getTargetForId(rId);
    1247             : }
    1248             : 
    1249           0 : void OOXMLFastContextHandler::resolvePropertySetAttrs()
    1250             : {
    1251           0 : }
    1252             : 
    1253      378991 : void OOXMLFastContextHandler::sendPropertyToParent()
    1254             : {
    1255             : #ifdef DEBUG_CONTEXT_HANDLER
    1256             :     debug_logger->element("sendPropertyToParent");
    1257             : #endif
    1258             : 
    1259      378991 :     if (mpParent != NULL)
    1260             :     {
    1261      378991 :         OOXMLPropertySet::Pointer_t pProps(mpParent->getPropertySet());
    1262             : 
    1263      378991 :         if (pProps.get() != NULL)
    1264             :         {
    1265             :             OOXMLProperty::Pointer_t
    1266      378991 :                 pProp(new OOXMLPropertyImpl(mId, getValue(),
    1267      378991 :                                             OOXMLPropertyImpl::SPRM));
    1268      378991 :             pProps->add(pProp);
    1269      378991 :         }
    1270             :     }
    1271      378991 : }
    1272             : 
    1273      580887 : void OOXMLFastContextHandler::sendPropertiesToParent()
    1274             : {
    1275             : #ifdef DEBUG_CONTEXT_HANDLER
    1276             :     debug_logger->startElement("contexthandler.sendPropertiesToParent");
    1277             : #endif
    1278      580887 :     if (mpParent != NULL)
    1279             :     {
    1280      580887 :         OOXMLPropertySet::Pointer_t pParentProps(mpParent->getPropertySet());
    1281             : 
    1282      580887 :         if (pParentProps.get() != NULL)
    1283             :         {
    1284      546107 :             OOXMLPropertySet::Pointer_t pProps(getPropertySet());
    1285             : 
    1286      546107 :             if (pProps.get() != NULL)
    1287             :             {
    1288             :                 OOXMLValue::Pointer_t pValue
    1289      546107 :                 (new OOXMLPropertySetValue(getPropertySet()));
    1290             : 
    1291             :                 OOXMLProperty::Pointer_t pProp
    1292     1092214 :                 (new OOXMLPropertyImpl(getId(), pValue, OOXMLPropertyImpl::SPRM));
    1293             : 
    1294             : 
    1295     1092214 :                 pParentProps->add(pProp);
    1296             : 
    1297      546107 :             }
    1298      580887 :         }
    1299             :     }
    1300             : #ifdef DEBUG_CONTEXT_HANDLER
    1301             :     debug_logger->endElement();
    1302             : #endif
    1303      580887 : }
    1304             : 
    1305             : uno::Reference< uno::XComponentContext >
    1306         431 : OOXMLFastContextHandler::getComponentContext()
    1307             : {
    1308         431 :     return m_xContext;
    1309             : }
    1310             : 
    1311             : /*
    1312             :   class OOXMLFastContextHandlerStream
    1313             :  */
    1314             : 
    1315       95325 : OOXMLFastContextHandlerStream::OOXMLFastContextHandlerStream
    1316             : (OOXMLFastContextHandler * pContext)
    1317             : : OOXMLFastContextHandler(pContext),
    1318       95325 :   mpPropertySetAttrs(new OOXMLPropertySetImpl())
    1319             : {
    1320       95325 : }
    1321             : 
    1322      190650 : OOXMLFastContextHandlerStream::~OOXMLFastContextHandlerStream()
    1323             : {
    1324      190650 : }
    1325             : 
    1326       79641 : void OOXMLFastContextHandlerStream::newProperty(const Id & rId,
    1327             :                                                 OOXMLValue::Pointer_t pVal)
    1328             : {
    1329       79641 :     if (rId != 0x0)
    1330             :     {
    1331             :         OOXMLPropertyImpl::Pointer_t pProperty
    1332       14332 :             (new OOXMLPropertyImpl(rId, pVal, OOXMLPropertyImpl::ATTRIBUTE));
    1333             : 
    1334       14332 :         mpPropertySetAttrs->add(pProperty);
    1335             :     }
    1336       79641 : }
    1337             : 
    1338          33 : void OOXMLFastContextHandlerStream::sendProperty(Id nId)
    1339             : {
    1340             : #ifdef DEBUG_CONTEXT_HANDLER
    1341             :     debug_logger->startElement("contexthandler.sendProperty");
    1342             :     debug_logger->attribute("id", (*QNameToString::Instance())(nId));
    1343             :     debug_logger->chars(xmlify(getPropertySetAttrs()->toString()));
    1344             :     debug_logger->endElement();
    1345             : #endif
    1346             : 
    1347          33 :     OOXMLPropertySetEntryToString aHandler(nId);
    1348          33 :     getPropertySetAttrs()->resolve(aHandler);
    1349          33 :     const OUString & sText = aHandler.getString();
    1350             :     mpStream->utext(reinterpret_cast < const sal_uInt8 * >
    1351          33 :                     (sText.getStr()),
    1352          66 :                     sText.getLength());
    1353          33 : }
    1354             : 
    1355             : OOXMLPropertySet::Pointer_t
    1356        9284 : OOXMLFastContextHandlerStream::getPropertySetAttrs() const
    1357             : {
    1358        9284 :     return mpPropertySetAttrs;
    1359             : }
    1360             : 
    1361           0 : void OOXMLFastContextHandlerStream::resolvePropertySetAttrs()
    1362             : {
    1363             : #ifdef DEBUG_CONTEXT_HANDLER
    1364             :         debug_logger->startElement("contexthandler.resolvePropertySetAttrs");
    1365             :         debug_logger->chars(mpPropertySetAttrs->toString());
    1366             :         debug_logger->endElement();
    1367             : #endif
    1368           0 :     mpStream->props(mpPropertySetAttrs);
    1369           0 : }
    1370             : 
    1371         258 : OOXMLPropertySet::Pointer_t OOXMLFastContextHandlerStream::getPropertySet()
    1372             :     const
    1373             : {
    1374         258 :     return getPropertySetAttrs();
    1375             : }
    1376             : 
    1377         887 : void OOXMLFastContextHandlerStream::handleHyperlink()
    1378             : {
    1379         887 :     OOXMLHyperlinkHandler aHyperlinkHandler(this);
    1380         887 :     getPropertySetAttrs()->resolve(aHyperlinkHandler);
    1381         887 : }
    1382             : 
    1383             : /*
    1384             :   class OOXMLFastContextHandlerProperties
    1385             :  */
    1386      641086 : OOXMLFastContextHandlerProperties::OOXMLFastContextHandlerProperties
    1387             : (OOXMLFastContextHandler * pContext)
    1388           0 : : OOXMLFastContextHandler(pContext), mpPropertySet(new OOXMLPropertySetImpl()),
    1389      641086 :   mbResolve(false)
    1390             : {
    1391      641086 :     if (pContext->getResource() == STREAM)
    1392       60199 :         mbResolve = true;
    1393      641086 : }
    1394             : 
    1395     1279565 : OOXMLFastContextHandlerProperties::~OOXMLFastContextHandlerProperties()
    1396             : {
    1397     1279565 : }
    1398             : 
    1399      639870 : void OOXMLFastContextHandlerProperties::lcl_endFastElement
    1400             : (Token_t Element)
    1401             :     throw (uno::RuntimeException, xml::sax::SAXException)
    1402             : {
    1403      639870 :     endAction(Element);
    1404             : 
    1405      639870 :     if (mbResolve)
    1406             :     {
    1407       58983 :         if (isForwardEvents())
    1408             :         {
    1409       58107 :             mpStream->props(mpPropertySet);
    1410             :         }
    1411             :     }
    1412             :     else
    1413             :     {
    1414      580887 :         sendPropertiesToParent();
    1415             :     }
    1416      639870 : }
    1417             : 
    1418       34780 : OOXMLValue::Pointer_t OOXMLFastContextHandlerProperties::getValue() const
    1419             : {
    1420       34780 :     return OOXMLValue::Pointer_t(new OOXMLPropertySetValue(mpPropertySet));
    1421             : }
    1422             : 
    1423             : #if OSL_DEBUG_LEVEL > 1
    1424             : void OOXMLFastContextHandlerProperties::dumpXml( const TagLogger::Pointer_t pLogger) const
    1425             : {
    1426             :     pLogger->startElement("context");
    1427             : 
    1428             :     static char sBuffer[128];
    1429             :     snprintf(sBuffer, sizeof(sBuffer), "%p", this);
    1430             : 
    1431             :     pLogger->attribute("parent", std::string(sBuffer));
    1432             :     pLogger->attribute("type", getType());
    1433             :     pLogger->attribute("resource", resourceToString(getResource()));
    1434             :     pLogger->attribute("token", fastTokenToId(getToken()));
    1435             :     pLogger->attribute("id", (*QNameToString::Instance())(getId()));
    1436             : 
    1437             :     OOXMLValue::Pointer_t pVal(getValue());
    1438             : 
    1439             :     if (pVal.get() != NULL)
    1440             :         pLogger->attribute("value", pVal->toString());
    1441             :     else
    1442             :         pLogger->attribute("value", std::string("(null)"));
    1443             : 
    1444             :     pLogger->attribute("resolve", mbResolve ? "resolve" : "noResolve");
    1445             : 
    1446             :     pLogger->propertySet(getPropertySet(),
    1447             :             IdToString::Pointer_t(new OOXMLIdToString()));
    1448             : 
    1449             :     mpParserState->dumpXml( pLogger );
    1450             : 
    1451             :     pLogger->endElement();
    1452             : }
    1453             : #endif
    1454             : 
    1455     1144389 : void OOXMLFastContextHandlerProperties::newProperty
    1456             : (const Id & rId, OOXMLValue::Pointer_t pVal)
    1457             : {
    1458     1144389 :     if (rId != 0x0)
    1459             :     {
    1460             :         OOXMLPropertyImpl::Pointer_t pProperty
    1461     1129463 :             (new OOXMLPropertyImpl(rId, pVal, OOXMLPropertyImpl::ATTRIBUTE));
    1462             : 
    1463     1129463 :         mpPropertySet->add(pProperty);
    1464             :     }
    1465     1144389 : }
    1466             : 
    1467          30 : void OOXMLFastContextHandlerProperties::handleXNotes()
    1468             : {
    1469          30 :     switch (mnToken)
    1470             :     {
    1471             :     case NS_wordprocessingml|OOXML_footnoteReference:
    1472             :         {
    1473          24 :             OOXMLFootnoteHandler aFootnoteHandler(this);
    1474          24 :             mpPropertySet->resolve(aFootnoteHandler);
    1475             :         }
    1476          24 :         break;
    1477             :     case NS_wordprocessingml|OOXML_endnoteReference:
    1478             :         {
    1479           6 :             OOXMLEndnoteHandler aEndnoteHandler(this);
    1480           6 :             mpPropertySet->resolve(aEndnoteHandler);
    1481             :         }
    1482           6 :         break;
    1483             :     default:
    1484           0 :         break;
    1485             :     }
    1486          30 : }
    1487             : 
    1488         800 : void OOXMLFastContextHandlerProperties::handleHdrFtr()
    1489             : {
    1490         800 :     switch (mnToken)
    1491             :     {
    1492             :     case NS_wordprocessingml|OOXML_footerReference:
    1493             :         {
    1494         412 :             OOXMLFooterHandler aFooterHandler(this);
    1495         412 :             mpPropertySet->resolve(aFooterHandler);
    1496             :         }
    1497         412 :         break;
    1498             :     case NS_wordprocessingml|OOXML_headerReference:
    1499             :         {
    1500         388 :             OOXMLHeaderHandler aHeaderHandler(this);
    1501         388 :             mpPropertySet->resolve(aHeaderHandler);
    1502             :         }
    1503         388 :         break;
    1504             :     default:
    1505           0 :         break;
    1506             :     }
    1507         800 : }
    1508             : 
    1509          11 : void OOXMLFastContextHandlerProperties::handleComment()
    1510             : {
    1511             : #ifdef DEBUG_ELEMENT
    1512             :     debug_logger->element("handleComment");
    1513             : #endif
    1514             : 
    1515          11 :     OOXMLCommentHandler aCommentHandler(this);
    1516          11 :     getPropertySet()->resolve(aCommentHandler);
    1517          11 : }
    1518             : 
    1519         883 : void OOXMLFastContextHandlerProperties::handlePicture()
    1520             : {
    1521             : #ifdef DEBUG_ELEMENT
    1522             :     debug_logger->element("handlePicture");
    1523             : #endif
    1524             : 
    1525         883 :     OOXMLPictureHandler aPictureHandler(this);
    1526         883 :     getPropertySet()->resolve(aPictureHandler);
    1527         883 : }
    1528             : 
    1529         374 : void OOXMLFastContextHandlerProperties::handleBreak()
    1530             : {
    1531             : #ifdef DEBUG_ELEMENT
    1532             :     debug_logger->element("handleBreak");
    1533             : #endif
    1534             : 
    1535         374 :     OOXMLBreakHandler aBreakHandler(*mpStream);
    1536         374 :     getPropertySet()->resolve(aBreakHandler);
    1537         374 : }
    1538             : 
    1539          22 : void OOXMLFastContextHandlerProperties::handleOLE()
    1540             : {
    1541             : #ifdef DEBUG_ELEMENT
    1542             :     debug_logger->element("handleOLE");
    1543             : #endif
    1544             : 
    1545          22 :     OOXMLOLEHandler aOLEHandler(this);
    1546          22 :     getPropertySet()->resolve(aOLEHandler);
    1547          22 : }
    1548             : 
    1549           0 : void OOXMLFastContextHandlerProperties::handleFontRel()
    1550             : {
    1551           0 :     OOXMLEmbeddedFontHandler handler(this);
    1552           0 :     getPropertySet()->resolve(handler);
    1553           0 : }
    1554             : 
    1555           0 : void OOXMLFastContextHandlerProperties::setParent
    1556             : (OOXMLFastContextHandler * pParent)
    1557             : {
    1558             : #ifdef DEBUG_ELEMENT
    1559             :     debug_logger->startElement("setParent");
    1560             :     debug_logger->chars(std::string("OOXMLFastContextHandlerProperties"));
    1561             :     debug_logger->endElement();
    1562             : #endif
    1563             : 
    1564           0 :     OOXMLFastContextHandler::setParent(pParent);
    1565             : 
    1566           0 :     if (mpParent->getResource() == STREAM)
    1567           0 :         mbResolve = true;
    1568           0 : }
    1569             : 
    1570        9644 : void OOXMLFastContextHandlerProperties::setPropertySet
    1571             : (OOXMLPropertySet::Pointer_t pPropertySet)
    1572             : {
    1573        9644 :     if (pPropertySet.get() != NULL)
    1574        9644 :         mpPropertySet = pPropertySet;
    1575        9644 : }
    1576             : 
    1577             : OOXMLPropertySet::Pointer_t
    1578     2031852 : OOXMLFastContextHandlerProperties::getPropertySet() const
    1579             : {
    1580     2031852 :     return mpPropertySet;
    1581             : }
    1582             : 
    1583             : /*
    1584             :  * class OOXMLFasContextHandlerPropertyTable
    1585             :  */
    1586             : 
    1587        1021 : OOXMLFastContextHandlerPropertyTable::OOXMLFastContextHandlerPropertyTable
    1588             : (OOXMLFastContextHandler * pContext)
    1589        1021 : : OOXMLFastContextHandlerProperties(pContext)
    1590             : {
    1591        1021 : }
    1592             : 
    1593        2042 : OOXMLFastContextHandlerPropertyTable::~OOXMLFastContextHandlerPropertyTable()
    1594             : {
    1595        2042 : }
    1596             : 
    1597        1021 : void OOXMLFastContextHandlerPropertyTable::lcl_endFastElement
    1598             : (Token_t Element)
    1599             :     throw (uno::RuntimeException, xml::sax::SAXException)
    1600             : {
    1601        1021 :     OOXMLPropertySet::Pointer_t pPropSet(mpPropertySet->clone());
    1602             :     OOXMLTableImpl::ValuePointer_t pTmpVal
    1603        2042 :         (new OOXMLPropertySetValue(pPropSet));
    1604             : 
    1605        1021 :     mTable.add(pTmpVal);
    1606             : 
    1607        2042 :     writerfilter::Reference<Table>::Pointer_t pTable(mTable.clone());
    1608             : 
    1609             : #ifdef DEBUG_PROPERTIES
    1610             :     debug_logger->startElement("table");
    1611             :     debug_logger->attribute("id", (*QNameToString::Instance())(mId));
    1612             :     debug_logger->endElement();
    1613             : #endif
    1614             : 
    1615        1021 :     mpStream->table(mId, pTable);
    1616             : 
    1617        2042 :     endAction(Element);
    1618        1021 : }
    1619             : 
    1620             : /*
    1621             :  class OOXMLFastContextHandlerValue
    1622             : */
    1623             : 
    1624      378991 : OOXMLFastContextHandlerValue::OOXMLFastContextHandlerValue
    1625             : (OOXMLFastContextHandler * pContext)
    1626      378991 : : OOXMLFastContextHandler(pContext)
    1627             : {
    1628      378991 : }
    1629             : 
    1630      757982 : OOXMLFastContextHandlerValue::~OOXMLFastContextHandlerValue()
    1631             : {
    1632      757982 : }
    1633             : 
    1634      366712 : void OOXMLFastContextHandlerValue::setValue(OOXMLValue::Pointer_t pValue)
    1635             : {
    1636             : #ifdef DEBUG_CONTEXT_HANDLER
    1637             :     debug_logger->startElement("contexthandler.setValue");
    1638             :     debug_logger->attribute("value", pValue->toString());
    1639             : #endif
    1640             : 
    1641      366712 :     mpValue = pValue;
    1642             : 
    1643             : #ifdef DEBUG_CONTEXT_HANDLER
    1644             :     debug_logger->endElement();
    1645             : #endif
    1646      366712 : }
    1647             : 
    1648      378991 : OOXMLValue::Pointer_t OOXMLFastContextHandlerValue::getValue() const
    1649             : {
    1650      378991 :     return mpValue;
    1651             : }
    1652             : 
    1653      378991 : void OOXMLFastContextHandlerValue::lcl_endFastElement
    1654             : (Token_t Element)
    1655             : throw (uno::RuntimeException, xml::sax::SAXException)
    1656             : {
    1657      378991 :     sendPropertyToParent();
    1658             : 
    1659      378991 :     endAction(Element);
    1660      378991 : }
    1661             : 
    1662       88826 : void OOXMLFastContextHandlerValue::setDefaultBooleanValue()
    1663             : {
    1664             : #ifdef DEBUG_ELEMENT
    1665             :     debug_logger->element("setDefaultBooleanValue");
    1666             : #endif
    1667             : 
    1668       88826 :     if (mpValue.get() == NULL)
    1669             :     {
    1670       78168 :         OOXMLValue::Pointer_t pValue(new OOXMLBooleanValue(true));
    1671       78168 :         setValue(pValue);
    1672             :     }
    1673       88826 : }
    1674             : 
    1675      102377 : void OOXMLFastContextHandlerValue::setDefaultIntegerValue()
    1676             : {
    1677             : #ifdef DEBUG_ELEMENT
    1678             :     debug_logger->element("setDefaultIntegerValue");
    1679             : #endif
    1680             : 
    1681      102377 :     if (mpValue.get() == NULL)
    1682             :     {
    1683           0 :         OOXMLValue::Pointer_t pValue(new OOXMLIntegerValue(0));
    1684           0 :         setValue(pValue);
    1685             :     }
    1686      102377 : }
    1687             : 
    1688       66516 : void OOXMLFastContextHandlerValue::setDefaultHexValue()
    1689             : {
    1690             : #ifdef DEBUG_ELEMENT
    1691             :     debug_logger->element("setDefaultHexValue");
    1692             : #endif
    1693             : 
    1694       66516 :     if (mpValue.get() == NULL)
    1695             :     {
    1696           0 :         OOXMLValue::Pointer_t pValue(new OOXMLHexValue(0));
    1697           0 :         setValue(pValue);
    1698             :     }
    1699       66516 : }
    1700             : 
    1701       67980 : void OOXMLFastContextHandlerValue::setDefaultStringValue()
    1702             : {
    1703             : #ifdef DEBUG_ELEMENT
    1704             :     debug_logger->element("setDefaultStringValue");
    1705             : #endif
    1706             : 
    1707       67980 :     if (mpValue.get() == NULL)
    1708             :     {
    1709           3 :         OOXMLValue::Pointer_t pValue(new OOXMLStringValue(OUString()));
    1710           3 :         setValue(pValue);
    1711             :     }
    1712       67980 : }
    1713             : /*
    1714             :   class OOXMLFastContextHandlerTable
    1715             : */
    1716             : 
    1717        2614 : OOXMLFastContextHandlerTable::OOXMLFastContextHandlerTable
    1718             : (OOXMLFastContextHandler * pContext)
    1719        2614 : : OOXMLFastContextHandler(pContext)
    1720             : {
    1721        2614 : }
    1722             : 
    1723        5228 : OOXMLFastContextHandlerTable::~OOXMLFastContextHandlerTable()
    1724             : {
    1725        5228 : }
    1726             : 
    1727             : uno::Reference< xml::sax::XFastContextHandler > SAL_CALL
    1728       36542 : OOXMLFastContextHandlerTable::createFastChildContext
    1729             : (Token_t Element,
    1730             :  const uno::Reference< xml::sax::XFastAttributeList > & Attribs)
    1731             :     throw (uno::RuntimeException, xml::sax::SAXException, std::exception)
    1732             : {
    1733       36542 :     addCurrentChild();
    1734             : 
    1735             :     mCurrentChild.set
    1736       36542 :         (OOXMLFastContextHandler::createFastChildContext(Element, Attribs));
    1737             : 
    1738       36542 :     return mCurrentChild;
    1739             : }
    1740             : 
    1741        2614 : void OOXMLFastContextHandlerTable::lcl_endFastElement
    1742             : (Token_t /*Element*/)
    1743             :     throw (uno::RuntimeException, xml::sax::SAXException)
    1744             : {
    1745        2614 :     addCurrentChild();
    1746             : 
    1747        2614 :     writerfilter::Reference<Table>::Pointer_t pTable(mTable.clone());
    1748        2614 :     if (isForwardEvents() && mId != 0x0)
    1749             :     {
    1750             : #ifdef DEBUG_PROPERTIES
    1751             :         debug_logger->startElement("table");
    1752             :         string str = (*QNameToString::Instance())(mId);
    1753             :         debug_logger->attribute("id", str);
    1754             :         debug_logger->endElement();
    1755             : #endif
    1756             : 
    1757        2614 :         mpStream->table(mId, pTable);
    1758        2614 :     }
    1759        2614 : }
    1760             : 
    1761       39156 : void OOXMLFastContextHandlerTable::addCurrentChild()
    1762             : {
    1763       39156 :     OOXMLFastContextHandler * pHandler = mCurrentChild.getPointer();
    1764       39156 :     if ( pHandler != NULL)
    1765             :     {
    1766       34780 :         OOXMLValue::Pointer_t pValue(pHandler->getValue());
    1767             : 
    1768       34780 :         if (pValue.get() != NULL)
    1769             :         {
    1770       34780 :             OOXMLTableImpl::ValuePointer_t pTmpVal(pValue->clone());
    1771       34780 :             mTable.add(pTmpVal);
    1772       34780 :         }
    1773             :     }
    1774       39156 : }
    1775             : 
    1776           0 : void OOXMLFastContextHandlerTable::newPropertySet
    1777             : (OOXMLPropertySet::Pointer_t /*pPropertySet*/)
    1778             : {
    1779             : 
    1780           0 : }
    1781             : 
    1782             : /*
    1783             :   class OOXMLFastContextHandlerXNote
    1784             :  */
    1785             : 
    1786         303 : OOXMLFastContextHandlerXNote::OOXMLFastContextHandlerXNote
    1787             :     (OOXMLFastContextHandler * pContext)
    1788             :     : OOXMLFastContextHandlerProperties(pContext)
    1789             :     , mbForwardEventsSaved(false)
    1790             :     , mnMyXNoteId(0)
    1791         303 :     , mnMyXNoteType(0)
    1792             : {
    1793         303 : }
    1794             : 
    1795         606 : OOXMLFastContextHandlerXNote::~OOXMLFastContextHandlerXNote()
    1796             : {
    1797         606 : }
    1798             : 
    1799         303 : void OOXMLFastContextHandlerXNote::lcl_startFastElement
    1800             : (Token_t Element,
    1801             :  const uno::Reference< xml::sax::XFastAttributeList > & /*Attribs*/)
    1802             :     throw (uno::RuntimeException, xml::sax::SAXException)
    1803             : {
    1804         303 :     mbForwardEventsSaved = isForwardEvents();
    1805             : 
    1806             :     // If this is the note we're looking for or this is the footnote separator one.
    1807         303 :     if (mnMyXNoteId == getXNoteId() || static_cast<sal_uInt32>(mnMyXNoteType) == NS_ooxml::LN_Value_wordprocessingml_ST_FtnEdn_separator)
    1808          71 :         setForwardEvents(true);
    1809             :     else
    1810         232 :         setForwardEvents(false);
    1811             : 
    1812         303 :     startAction(Element);
    1813         303 : }
    1814             : 
    1815         303 : void OOXMLFastContextHandlerXNote::lcl_endFastElement
    1816             : (Token_t Element)
    1817             :     throw (uno::RuntimeException, xml::sax::SAXException)
    1818             : {
    1819         303 :     endAction(Element);
    1820             : 
    1821         303 :     OOXMLFastContextHandlerProperties::lcl_endFastElement(Element);
    1822             : 
    1823         303 :     setForwardEvents(mbForwardEventsSaved);
    1824         303 : }
    1825             : 
    1826         303 : void OOXMLFastContextHandlerXNote::checkId(OOXMLValue::Pointer_t pValue)
    1827             : {
    1828             : #ifdef DEBUG_ELEMENT
    1829             :     debug_logger->startElement("checkId");
    1830             :     debug_logger->attribute("myId", sal_Int32(pValue->getInt()));
    1831             :     debug_logger->attribute("id", getXNoteId());
    1832             :     debug_logger->endElement();
    1833             : #endif
    1834             : 
    1835         303 :     mnMyXNoteId = sal_Int32(pValue->getInt());
    1836         303 : }
    1837             : 
    1838          60 : void OOXMLFastContextHandlerXNote::checkType(OOXMLValue::Pointer_t pValue)
    1839             : {
    1840             : #ifdef DEBUG_ELEMENT
    1841             :     debug_logger->startElement("checkType");
    1842             :     debug_logger->attribute("myType", sal_Int32(pValue->getInt()));
    1843             :     debug_logger->endElement();
    1844             : #endif
    1845          60 :     mnMyXNoteType = pValue->getInt();
    1846          60 : }
    1847             : 
    1848             : /*
    1849             :   class OOXMLFastContextHandlerTextTableCell
    1850             :  */
    1851             : 
    1852        6472 : OOXMLFastContextHandlerTextTableCell::OOXMLFastContextHandlerTextTableCell
    1853             : (OOXMLFastContextHandler * pContext)
    1854        6472 : : OOXMLFastContextHandler(pContext)
    1855             : {
    1856        6472 : }
    1857             : 
    1858       12944 : OOXMLFastContextHandlerTextTableCell::~OOXMLFastContextHandlerTextTableCell()
    1859             : {
    1860       12944 : }
    1861             : 
    1862        6472 : void OOXMLFastContextHandlerTextTableCell::startCell()
    1863             : {
    1864        6472 : }
    1865             : 
    1866        6472 : void OOXMLFastContextHandlerTextTableCell::endCell()
    1867             : {
    1868        6472 :     if (isForwardEvents())
    1869             :     {
    1870        6472 :         OOXMLPropertySet * pProps = new OOXMLPropertySetImpl();
    1871             :         {
    1872             :             OOXMLValue::Pointer_t pVal
    1873        6472 :                 (new OOXMLIntegerValue(mnTableDepth));
    1874             :             OOXMLProperty::Pointer_t pProp
    1875       12944 :                 (new OOXMLPropertyImpl(NS_ooxml::LN_tblDepth, pVal, OOXMLPropertyImpl::SPRM));
    1876       12944 :             pProps->add(pProp);
    1877             :         }
    1878             :         {
    1879             :             OOXMLValue::Pointer_t pVal
    1880        6472 :                 (new OOXMLIntegerValue(1));
    1881             :             OOXMLProperty::Pointer_t pProp
    1882       12944 :                 (new OOXMLPropertyImpl(NS_ooxml::LN_inTbl, pVal, OOXMLPropertyImpl::SPRM));
    1883       12944 :             pProps->add(pProp);
    1884             :         }
    1885             :         {
    1886             :             OOXMLValue::Pointer_t pVal
    1887        6472 :                 (new OOXMLBooleanValue(mnTableDepth > 0));
    1888             :             OOXMLProperty::Pointer_t pProp
    1889       12944 :                 (new OOXMLPropertyImpl(NS_ooxml::LN_tblCell, pVal, OOXMLPropertyImpl::SPRM));
    1890       12944 :             pProps->add(pProp);
    1891             :         }
    1892             : 
    1893             : #ifdef DEBUG_PROPERTIES
    1894             :         debug_logger->startElement("endcell");
    1895             :         debug_logger->propertySet(OOXMLPropertySet::Pointer_t(pProps->clone()),
    1896             :                 IdToString::Pointer_t(new OOXMLIdToString()));
    1897             :         debug_logger->endElement();
    1898             : #endif
    1899        6472 :         mpStream->props(writerfilter::Reference<Properties>::Pointer_t(pProps));
    1900             :     }
    1901        6472 : }
    1902             : 
    1903             : /*
    1904             :   class OOXMLFastContextHandlerTextTableRow
    1905             :  */
    1906             : 
    1907        2102 : OOXMLFastContextHandlerTextTableRow::OOXMLFastContextHandlerTextTableRow
    1908             : (OOXMLFastContextHandler * pContext)
    1909        2102 : : OOXMLFastContextHandler(pContext)
    1910             : {
    1911        2102 : }
    1912             : 
    1913        4204 : OOXMLFastContextHandlerTextTableRow::~OOXMLFastContextHandlerTextTableRow()
    1914             : {
    1915        4204 : }
    1916             : 
    1917        2102 : void OOXMLFastContextHandlerTextTableRow::startRow()
    1918             : {
    1919        2102 : }
    1920             : 
    1921        2102 : void OOXMLFastContextHandlerTextTableRow::endRow()
    1922             : {
    1923        2102 :     startParagraphGroup();
    1924             : 
    1925        2102 :     if (isForwardEvents())
    1926             :     {
    1927        2102 :         OOXMLPropertySet * pProps = new OOXMLPropertySetImpl();
    1928             :         {
    1929             :             OOXMLValue::Pointer_t pVal
    1930        2102 :                 (new OOXMLIntegerValue(mnTableDepth));
    1931             :             OOXMLProperty::Pointer_t pProp
    1932        4204 :                 (new OOXMLPropertyImpl(NS_ooxml::LN_tblDepth, pVal, OOXMLPropertyImpl::SPRM));
    1933        4204 :             pProps->add(pProp);
    1934             :         }
    1935             :         {
    1936             :             OOXMLValue::Pointer_t pVal
    1937        2102 :                 (new OOXMLIntegerValue(1));
    1938             :             OOXMLProperty::Pointer_t pProp
    1939        4204 :                 (new OOXMLPropertyImpl(NS_ooxml::LN_inTbl, pVal, OOXMLPropertyImpl::SPRM));
    1940        4204 :             pProps->add(pProp);
    1941             :         }
    1942             :         {
    1943             :             OOXMLValue::Pointer_t pVal
    1944        2102 :                 (new OOXMLIntegerValue(1));
    1945             :             OOXMLProperty::Pointer_t pProp
    1946        4204 :                 (new OOXMLPropertyImpl(NS_ooxml::LN_tblRow, pVal, OOXMLPropertyImpl::SPRM));
    1947        4204 :             pProps->add(pProp);
    1948             :         }
    1949             : 
    1950             : #ifdef DEBUG_PROPERTIES
    1951             :         debug_logger->startElement("endrow");
    1952             :         debug_logger->propertySet(OOXMLPropertySet::Pointer_t(pProps->clone()),
    1953             :                 IdToString::Pointer_t(new OOXMLIdToString()));
    1954             :         debug_logger->endElement();
    1955             : #endif
    1956             : 
    1957        2102 :         mpStream->props(writerfilter::Reference<Properties>::Pointer_t(pProps));
    1958             :     }
    1959             : 
    1960        2102 :     startCharacterGroup();
    1961             : 
    1962        2102 :     if (isForwardEvents())
    1963        2102 :         mpStream->utext((const sal_uInt8*)&uCR, 1);
    1964             : 
    1965        2102 :     endCharacterGroup();
    1966        2102 :     endParagraphGroup();
    1967        2102 : }
    1968             : 
    1969             : /*
    1970             :   class OOXMLFastContextHandlerTextTable
    1971             :  */
    1972             : 
    1973         331 : OOXMLFastContextHandlerTextTable::OOXMLFastContextHandlerTextTable
    1974             : (OOXMLFastContextHandler * pContext)
    1975         331 : : OOXMLFastContextHandler(pContext)
    1976             : {
    1977         331 : }
    1978             : 
    1979         993 : OOXMLFastContextHandlerTextTable::~OOXMLFastContextHandlerTextTable()
    1980             : {
    1981         331 :     clearTableProps();
    1982         662 : }
    1983             : 
    1984         331 : void OOXMLFastContextHandlerTextTable::lcl_startFastElement
    1985             : (Token_t Element,
    1986             :  const uno::Reference< xml::sax::XFastAttributeList > & /*Attribs*/)
    1987             :     throw (uno::RuntimeException, xml::sax::SAXException)
    1988             : {
    1989         331 :     mpParserState->startTable();
    1990         331 :     mnTableDepth++;
    1991             : 
    1992         331 :     boost::shared_ptr<OOXMLPropertySet> pProps( new OOXMLPropertySetImpl );
    1993             :     {
    1994             :         OOXMLValue::Pointer_t pVal
    1995         331 :             (new OOXMLIntegerValue(mnTableDepth));
    1996             :         OOXMLProperty::Pointer_t pProp
    1997         662 :             (new OOXMLPropertyImpl(NS_ooxml::LN_tblStart, pVal, OOXMLPropertyImpl::SPRM));
    1998         662 :         pProps->add(pProp);
    1999             :     }
    2000         331 :     mpParserState->setCharacterProperties(pProps);
    2001             : 
    2002         331 :     startAction(Element);
    2003         331 : }
    2004             : 
    2005         331 : void OOXMLFastContextHandlerTextTable::lcl_endFastElement
    2006             : (Token_t Element)
    2007             :     throw (uno::RuntimeException, xml::sax::SAXException)
    2008             : {
    2009         331 :     endAction(Element);
    2010             : 
    2011         331 :     boost::shared_ptr<OOXMLPropertySet> pProps( new OOXMLPropertySetImpl );
    2012             :     {
    2013             :         OOXMLValue::Pointer_t pVal
    2014         331 :             (new OOXMLIntegerValue(mnTableDepth));
    2015             :         OOXMLProperty::Pointer_t pProp
    2016         662 :             (new OOXMLPropertyImpl(NS_ooxml::LN_tblEnd, pVal, OOXMLPropertyImpl::SPRM));
    2017         662 :         pProps->add(pProp);
    2018             :     }
    2019         331 :     mpParserState->setCharacterProperties(pProps);
    2020             : 
    2021         331 :     mnTableDepth--;
    2022         331 :     mpParserState->endTable();
    2023         331 : }
    2024             : 
    2025             : /*
    2026             :   class OOXMLFastContextHandlerShape
    2027             :  */
    2028             : 
    2029        1088 : OOXMLFastContextHandlerShape::OOXMLFastContextHandlerShape
    2030             : (OOXMLFastContextHandler * pContext)
    2031             : : OOXMLFastContextHandlerProperties(pContext), m_bShapeSent( false ),
    2032        1088 :     m_bShapeStarted(false)
    2033             : {
    2034        1088 :     mrShapeContext.set( getDocument( )->getShapeContext( ) );
    2035        1088 :     if ( !mrShapeContext.is( ) )
    2036             :     {
    2037             :         // Define the shape context for the whole document
    2038         862 :         mrShapeContext = css::xml::sax::FastShapeContextHandler::create(
    2039         431 :             getComponentContext());
    2040         431 :         getDocument()->setShapeContext( mrShapeContext );
    2041             :     }
    2042             : 
    2043        1088 :     mrShapeContext->setModel(getDocument()->getModel());
    2044        1088 :     mrShapeContext->setDrawPage(getDocument()->getDrawPage());
    2045        1088 :     mrShapeContext->setInputStream(getDocument()->getStorageStream());
    2046             : 
    2047             : #ifdef DEBUG_ELEMENT
    2048             :     debug_logger->startElement("setRelationFragmentPath");
    2049             :     debug_logger->attribute("path", mpParserState->getTarget());
    2050             :     debug_logger->endElement();
    2051             : #endif
    2052        1088 :     mrShapeContext->setRelationFragmentPath
    2053        1088 :         (mpParserState->getTarget());
    2054        1088 : }
    2055             : 
    2056        2176 : OOXMLFastContextHandlerShape::~OOXMLFastContextHandlerShape()
    2057             : {
    2058        2176 : }
    2059             : 
    2060        1088 : void OOXMLFastContextHandlerShape::lcl_startFastElement
    2061             : (Token_t Element,
    2062             :  const uno::Reference< xml::sax::XFastAttributeList > & Attribs)
    2063             :     throw (uno::RuntimeException, xml::sax::SAXException)
    2064             : {
    2065        1088 :     startAction(Element);
    2066             : 
    2067        1088 :     if (mrShapeContext.is())
    2068             :     {
    2069        1088 :         mrShapeContext->startFastElement(Element, Attribs);
    2070             :     }
    2071        1088 : }
    2072             : 
    2073           0 : void SAL_CALL OOXMLFastContextHandlerShape::startUnknownElement
    2074             : (const OUString & Namespace,
    2075             :  const OUString & Name,
    2076             :  const uno::Reference< xml::sax::XFastAttributeList > & Attribs)
    2077             :     throw (uno::RuntimeException, xml::sax::SAXException, std::exception)
    2078             : {
    2079           0 :     if (mrShapeContext.is())
    2080           0 :         mrShapeContext->startUnknownElement(Namespace, Name, Attribs);
    2081           0 : }
    2082             : 
    2083        1088 : void OOXMLFastContextHandlerShape::setToken(Token_t nToken)
    2084             : {
    2085        1088 :     OOXMLFastContextHandler::setToken(nToken);
    2086             : 
    2087        1088 :     if (mrShapeContext.is())
    2088        1088 :         mrShapeContext->setStartToken(nToken);
    2089        1088 : }
    2090             : 
    2091        1406 : void OOXMLFastContextHandlerShape::sendShape( Token_t Element )
    2092             : {
    2093        1406 :     if ( mrShapeContext.is() && !m_bShapeSent )
    2094             :     {
    2095        1088 :         awt::Point aPosition(writerfilter::dmapper::PositionHandler::getPositionOffset(false), writerfilter::dmapper::PositionHandler::getPositionOffset(true));
    2096        1088 :         mrShapeContext->setPosition(aPosition);
    2097        1088 :         uno::Reference<drawing::XShape> xShape(mrShapeContext->getShape());
    2098        1088 :         if (xShape.is())
    2099             :         {
    2100             :             OOXMLValue::Pointer_t
    2101        1086 :                 pValue(new OOXMLShapeValue(xShape));
    2102        1086 :             newProperty(NS_ooxml::LN_shape, pValue);
    2103        1086 :             m_bShapeSent = true;
    2104             : 
    2105        1086 :             bool bIsPicture = Element == ( NS_picture | OOXML_pic );
    2106             : 
    2107             :             // Notify the dmapper that the shape is ready to use
    2108        1086 :             if ( !bIsPicture )
    2109             :             {
    2110         928 :                 mpStream->startShape( xShape );
    2111         928 :                 m_bShapeStarted = true;
    2112        1086 :             }
    2113        1088 :         }
    2114             :     }
    2115        1406 : }
    2116             : 
    2117        1088 : void OOXMLFastContextHandlerShape::lcl_endFastElement
    2118             : (Token_t Element)
    2119             :     throw (uno::RuntimeException, xml::sax::SAXException)
    2120             : {
    2121        1088 :     if (mrShapeContext.is())
    2122             :     {
    2123        1088 :         mrShapeContext->endFastElement(Element);
    2124        1088 :         sendShape( Element );
    2125             :     }
    2126             : 
    2127        1088 :     OOXMLFastContextHandlerProperties::lcl_endFastElement(Element);
    2128             : 
    2129             :     // Ending the shape should be the last thing to do
    2130        1088 :     bool bIsPicture = Element == ( NS_picture | OOXML_pic );
    2131        1088 :     if ( !bIsPicture && m_bShapeStarted)
    2132         928 :         mpStream->endShape( );
    2133        1088 : }
    2134             : 
    2135           0 : void SAL_CALL OOXMLFastContextHandlerShape::endUnknownElement
    2136             : (const OUString & Namespace,
    2137             :  const OUString & Name)
    2138             :     throw (uno::RuntimeException, xml::sax::SAXException, std::exception)
    2139             : {
    2140           0 :     if (mrShapeContext.is())
    2141           0 :         mrShapeContext->endUnknownElement(Namespace, Name);
    2142           0 : }
    2143             : 
    2144             : uno::Reference< xml::sax::XFastContextHandler >
    2145        3431 : OOXMLFastContextHandlerShape::lcl_createFastChildContext
    2146             : (Token_t Element,
    2147             :  const uno::Reference< xml::sax::XFastAttributeList > & Attribs)
    2148             :     throw (uno::RuntimeException, xml::sax::SAXException)
    2149             : {
    2150        3431 :     uno::Reference< xml::sax::XFastContextHandler > xContextHandler;
    2151             : 
    2152        3431 :     bool bGroupShape = Element == Token_t(NS_vml | OOXML_group);
    2153             :     // drawingML version also counts as a group shape.
    2154        3431 :     bGroupShape |= mrShapeContext->getStartToken() == Token_t(NS_wpg | OOXML_wgp);
    2155        3431 :     sal_uInt32 nNamespace = Element & 0xffff0000;
    2156             : 
    2157        3431 :     switch (nNamespace)
    2158             :     {
    2159             :         case NS_wordprocessingml:
    2160             :         case NS_vml_wordprocessingDrawing:
    2161             :         case NS_office:
    2162          42 :             if (!bGroupShape)
    2163          42 :                 xContextHandler.set(OOXMLFactory::getInstance()->createFastChildContextFromStart(this, Element));
    2164             :         // no break;
    2165             :         default:
    2166        3431 :             if (!xContextHandler.is())
    2167             :             {
    2168        3389 :                 if (mrShapeContext.is())
    2169             :                 {
    2170             :                     uno::Reference<XFastContextHandler> pChildContext =
    2171        3389 :                         mrShapeContext->createFastChildContext(Element, Attribs);
    2172             : 
    2173             :                     OOXMLFastContextHandlerWrapper * pWrapper =
    2174        3389 :                         new OOXMLFastContextHandlerWrapper(this, pChildContext);
    2175             : 
    2176        3389 :                     if (!bGroupShape)
    2177             :                     {
    2178        3032 :                         pWrapper->addNamespace(NS_wordprocessingml);
    2179        3032 :                         pWrapper->addNamespace(NS_vml_wordprocessingDrawing);
    2180        3032 :                         pWrapper->addNamespace(NS_office);
    2181        3032 :                         pWrapper->addToken( NS_vml|OOXML_textbox );
    2182             :                     }
    2183             : 
    2184        3389 :                     xContextHandler.set(pWrapper);
    2185             :                 }
    2186             :                 else
    2187           0 :                     xContextHandler.set(this);
    2188             :             }
    2189        3431 :             break;
    2190             :     }
    2191             : 
    2192             :     // VML import of shape text is already handled by
    2193             :     // OOXMLFastContextHandlerWrapper::lcl_createFastChildContext(), here we
    2194             :     // handle the WPS import of shape text, as there the parent context is a
    2195             :     // Shape one, so a different situation.
    2196        3431 :     if (Element == static_cast<sal_Int32>(NS_wps | OOXML_txbx))
    2197         288 :         sendShape(Element);
    2198             : 
    2199        3431 :     return xContextHandler;
    2200             : }
    2201             : 
    2202             : uno::Reference< xml::sax::XFastContextHandler > SAL_CALL
    2203           0 : OOXMLFastContextHandlerShape::createUnknownChildContext
    2204             : (const OUString & Namespace,
    2205             :  const OUString & Name,
    2206             :  const uno::Reference< xml::sax::XFastAttributeList > & Attribs)
    2207             :     throw (uno::RuntimeException, xml::sax::SAXException, std::exception)
    2208             : {
    2209           0 :     uno::Reference< xml::sax::XFastContextHandler > xResult;
    2210             : 
    2211           0 :     if (mrShapeContext.is())
    2212           0 :         xResult.set(mrShapeContext->createUnknownChildContext
    2213           0 :             (Namespace, Name, Attribs));
    2214             : 
    2215           0 :     return xResult;
    2216             : }
    2217             : 
    2218         898 : void OOXMLFastContextHandlerShape::lcl_characters
    2219             : (const OUString & aChars)
    2220             :     throw (uno::RuntimeException, xml::sax::SAXException)
    2221             : {
    2222         898 :     if (mrShapeContext.is())
    2223         898 :         mrShapeContext->characters(aChars);
    2224         898 : }
    2225             : 
    2226             : /*
    2227             :   class OOXMLFastContextHandlerWrapper
    2228             : */
    2229             : 
    2230       30508 : OOXMLFastContextHandlerWrapper::OOXMLFastContextHandlerWrapper
    2231             : (OOXMLFastContextHandler * pParent,
    2232             :  uno::Reference<XFastContextHandler> xContext)
    2233       30508 : : OOXMLFastContextHandler(pParent), mxContext(xContext)
    2234             : {
    2235       30508 :     setId(pParent->getId());
    2236       30508 :     setToken(pParent->getToken());
    2237       30508 :     setPropertySet(pParent->getPropertySet());
    2238       30508 : }
    2239             : 
    2240       61016 : OOXMLFastContextHandlerWrapper::~OOXMLFastContextHandlerWrapper()
    2241             : {
    2242       61016 : }
    2243             : 
    2244         171 : void SAL_CALL OOXMLFastContextHandlerWrapper::startUnknownElement
    2245             : (const OUString & Namespace,
    2246             :  const OUString & Name,
    2247             :  const uno::Reference< xml::sax::XFastAttributeList > & Attribs)
    2248             :     throw (uno::RuntimeException, xml::sax::SAXException, std::exception)
    2249             : {
    2250         171 :     if (mxContext.is())
    2251           0 :         mxContext->startUnknownElement(Namespace, Name, Attribs);
    2252         171 : }
    2253             : 
    2254         171 : void SAL_CALL OOXMLFastContextHandlerWrapper::endUnknownElement
    2255             : (const OUString & Namespace,
    2256             :  const OUString & Name)
    2257             :     throw (uno::RuntimeException, xml::sax::SAXException, std::exception)
    2258             : {
    2259         171 :     if (mxContext.is())
    2260           0 :         mxContext->endUnknownElement(Namespace, Name);
    2261         171 : }
    2262             : 
    2263             : uno::Reference< xml::sax::XFastContextHandler > SAL_CALL
    2264         171 : OOXMLFastContextHandlerWrapper::createUnknownChildContext
    2265             : (const OUString & Namespace,
    2266             :  const OUString & Name,
    2267             :  const uno::Reference< xml::sax::XFastAttributeList > & Attribs)
    2268             :     throw (uno::RuntimeException, xml::sax::SAXException, std::exception)
    2269             : {
    2270         171 :     uno::Reference< xml::sax::XFastContextHandler > xResult;
    2271             : 
    2272         171 :     if (mxContext.is())
    2273           0 :         xResult = mxContext->createUnknownChildContext
    2274           0 :             (Namespace, Name, Attribs);
    2275             :     else
    2276         171 :         xResult.set(this);
    2277             : 
    2278         171 :     return xResult;
    2279             : }
    2280             : 
    2281       32637 : void OOXMLFastContextHandlerWrapper::attributes
    2282             : (const uno::Reference< xml::sax::XFastAttributeList > & Attribs)
    2283             : throw (uno::RuntimeException, xml::sax::SAXException)
    2284             : {
    2285       32637 :     if (mxContext.is())
    2286             :     {
    2287       22592 :         OOXMLFastContextHandler * pHandler = getFastContextHandler();
    2288       22592 :         if (pHandler != NULL)
    2289           0 :             pHandler->attributes(Attribs);
    2290             :     }
    2291       32637 : }
    2292             : 
    2293             : OOXMLFastContextHandler::ResourceEnum_t
    2294          10 : OOXMLFastContextHandlerWrapper::getResource() const
    2295             : {
    2296          10 :     return UNKNOWN;
    2297             : }
    2298             : 
    2299        9096 : void OOXMLFastContextHandlerWrapper::addNamespace(const Id & nId)
    2300             : {
    2301        9096 :     mMyNamespaces.insert(nId);
    2302        9096 : }
    2303             : 
    2304        3032 : void OOXMLFastContextHandlerWrapper::addToken( Token_t Token )
    2305             : {
    2306        3032 :     mMyTokens.insert( Token );
    2307        3032 : }
    2308             : 
    2309       32637 : void OOXMLFastContextHandlerWrapper::lcl_startFastElement
    2310             : (Token_t Element,
    2311             :  const uno::Reference< xml::sax::XFastAttributeList > & Attribs)
    2312             :     throw (uno::RuntimeException, xml::sax::SAXException)
    2313             : {
    2314       32637 :     if (mxContext.is())
    2315       22592 :         mxContext->startFastElement(Element, Attribs);
    2316       32637 : }
    2317             : 
    2318       32637 : void OOXMLFastContextHandlerWrapper::lcl_endFastElement
    2319             : (Token_t Element)
    2320             :     throw (uno::RuntimeException, xml::sax::SAXException)
    2321             : {
    2322       32637 :     if (mxContext.is())
    2323       22592 :         mxContext->endFastElement(Element);
    2324       32637 : }
    2325             : 
    2326             : uno::Reference< xml::sax::XFastContextHandler >
    2327       29635 : OOXMLFastContextHandlerWrapper::lcl_createFastChildContext
    2328             : (Token_t Element,
    2329             :  const uno::Reference< xml::sax::XFastAttributeList > & Attribs)
    2330             :     throw (uno::RuntimeException, xml::sax::SAXException)
    2331             : {
    2332       29635 :     uno::Reference< xml::sax::XFastContextHandler > xResult;
    2333             : 
    2334       29635 :     Id nNameSpace = Element & 0xffff0000;
    2335             : 
    2336             : #ifdef DEBUG_ELEMENT
    2337             :     debug_logger->startElement("Wrapper-createChildContext");
    2338             :     debug_logger->attribute("token", fastTokenToId(Element));
    2339             : 
    2340             :     const set<Id>::const_iterator aEnd(mMyNamespaces.end());
    2341             :     for (set<Id>::const_iterator aIt(mMyNamespaces.begin());
    2342             :          aIt != aEnd; ++aIt)
    2343             :     {
    2344             :         debug_logger->startElement("namespace");
    2345             :         debug_logger->attribute("id", fastTokenToId(*aIt));
    2346             :         debug_logger->endElement();
    2347             :     }
    2348             : 
    2349             :     debug_logger->endElement();
    2350             : #endif
    2351             : 
    2352       29635 :     bool bInNamespaces = mMyNamespaces.find(nNameSpace) != mMyNamespaces.end();
    2353       29635 :     bool bInTokens = mMyTokens.find( Element ) != mMyTokens.end( );
    2354             : 
    2355       29635 :     OOXMLFastContextHandlerShape* pShapeCtx = (OOXMLFastContextHandlerShape*)mpParent;
    2356             : 
    2357             :     // We have methods to _add_ individual tokens or whole namespaces to be
    2358             :     // processed by writerfilter (instead of oox), but we have no method to
    2359             :     // filter out a single token. Just hardwire the wrap token here till we
    2360             :     // need a more generic solution.
    2361       29635 :     bool bIsWrap = Element == static_cast<sal_Int32>(NS_vml_wordprocessingDrawing | OOXML_wrap);
    2362       29635 :     if ( bInNamespaces && ((pShapeCtx->isShapeSent() && bIsWrap) || !bIsWrap) )
    2363         387 :         xResult.set(OOXMLFactory::getInstance()->createFastChildContextFromStart(this, Element));
    2364       29248 :     else if (mxContext.is())
    2365             :     {
    2366             :         OOXMLFastContextHandlerWrapper * pWrapper =
    2367             :             new OOXMLFastContextHandlerWrapper
    2368       27119 :             (this, mxContext->createFastChildContext(Element, Attribs));
    2369       27119 :         pWrapper->mMyNamespaces = mMyNamespaces;
    2370       27119 :         pWrapper->setPropertySet(getPropertySet());
    2371       27119 :         xResult.set(pWrapper);
    2372             :     }
    2373             :     else
    2374        2129 :         xResult.set(this);
    2375             : 
    2376       29635 :     if ( bInTokens )
    2377          30 :         pShapeCtx->sendShape( Element );
    2378             : 
    2379       29635 :     return xResult;
    2380             : }
    2381             : 
    2382        9801 : void OOXMLFastContextHandlerWrapper::lcl_characters
    2383             : (const OUString & aChars)
    2384             :     throw (uno::RuntimeException, xml::sax::SAXException)
    2385             : {
    2386        9801 :     if (mxContext.is())
    2387        8343 :         mxContext->characters(aChars);
    2388        9801 : }
    2389             : 
    2390             : OOXMLFastContextHandler *
    2391      219390 : OOXMLFastContextHandlerWrapper::getFastContextHandler() const
    2392             : {
    2393      219390 :     if (mxContext.is())
    2394      219390 :         return dynamic_cast<OOXMLFastContextHandler *>(mxContext.get());
    2395             : 
    2396           0 :     return NULL;
    2397             : }
    2398             : 
    2399           0 : void OOXMLFastContextHandlerWrapper::newProperty
    2400             : (const Id & rId, OOXMLValue::Pointer_t pVal)
    2401             : {
    2402           0 :     if (mxContext.is())
    2403             :     {
    2404           0 :         OOXMLFastContextHandler * pHandler = getFastContextHandler();
    2405           0 :         if (pHandler != NULL)
    2406           0 :             pHandler->newProperty(rId, pVal);
    2407             :     }
    2408           0 : }
    2409             : 
    2410       57627 : void OOXMLFastContextHandlerWrapper::setPropertySet
    2411             : (OOXMLPropertySet::Pointer_t pPropertySet)
    2412             : {
    2413       57627 :     if (mxContext.is())
    2414             :     {
    2415       43071 :         OOXMLFastContextHandler * pHandler = getFastContextHandler();
    2416       43071 :         if (pHandler != NULL)
    2417           0 :             pHandler->setPropertySet(pPropertySet);
    2418             :     }
    2419             : 
    2420       57627 :     mpPropertySet = pPropertySet;
    2421       57627 : }
    2422             : 
    2423       54305 : OOXMLPropertySet::Pointer_t OOXMLFastContextHandlerWrapper::getPropertySet()
    2424             :     const
    2425             : {
    2426       54305 :     OOXMLPropertySet::Pointer_t pResult(mpPropertySet);
    2427             : 
    2428       54305 :     if (mxContext.is())
    2429             :     {
    2430       54305 :         OOXMLFastContextHandler * pHandler = getFastContextHandler();
    2431       54305 :         if (pHandler != NULL)
    2432           0 :             pResult = pHandler->getPropertySet();
    2433             :     }
    2434             : 
    2435       54305 :     return pResult;
    2436             : }
    2437             : 
    2438           0 : string OOXMLFastContextHandlerWrapper::getType() const
    2439             : {
    2440           0 :     string sResult = "Wrapper(";
    2441             : 
    2442           0 :     if (mxContext.is())
    2443             :     {
    2444           0 :         OOXMLFastContextHandler * pHandler = getFastContextHandler();
    2445           0 :         if (pHandler != NULL)
    2446           0 :             sResult += pHandler->getType();
    2447             :     }
    2448             : 
    2449           0 :     sResult += ")";
    2450             : 
    2451           0 :     return sResult;
    2452             : }
    2453             : 
    2454       30508 : void OOXMLFastContextHandlerWrapper::setId(Id rId)
    2455             : {
    2456       30508 :     OOXMLFastContextHandler::setId(rId);
    2457             : 
    2458       30508 :     if (mxContext.is())
    2459             :     {
    2460       22592 :         OOXMLFastContextHandler * pHandler = getFastContextHandler();
    2461       22592 :         if (pHandler != NULL)
    2462           0 :             pHandler->setId(rId);
    2463             :     }
    2464       30508 : }
    2465             : 
    2466       27119 : Id OOXMLFastContextHandlerWrapper::getId() const
    2467             : {
    2468       27119 :     Id nResult = OOXMLFastContextHandler::getId();
    2469             : 
    2470       27119 :     if (mxContext.is())
    2471             :     {
    2472       27119 :         OOXMLFastContextHandler * pHandler = getFastContextHandler();
    2473       27119 :         if (pHandler != NULL && pHandler->getId() != 0)
    2474           0 :             nResult = pHandler->getId();
    2475             :     }
    2476             : 
    2477       27119 :     return nResult;
    2478             : }
    2479             : 
    2480       30508 : void OOXMLFastContextHandlerWrapper::setToken(Token_t nToken)
    2481             : {
    2482       30508 :     OOXMLFastContextHandler::setToken(nToken);
    2483             : 
    2484       30508 :     if (mxContext.is())
    2485             :     {
    2486       22592 :         OOXMLFastContextHandler * pHandler = getFastContextHandler();
    2487       22592 :         if (pHandler != NULL)
    2488           0 :             pHandler->setToken(nToken);
    2489             :     }
    2490       30508 : }
    2491             : 
    2492       27119 : Token_t OOXMLFastContextHandlerWrapper::getToken() const
    2493             : {
    2494       27119 :     Token_t nResult = OOXMLFastContextHandler::getToken();
    2495             : 
    2496       27119 :     if (mxContext.is())
    2497             :     {
    2498       27119 :         OOXMLFastContextHandler * pHandler = getFastContextHandler();
    2499       27119 :         if (pHandler != NULL)
    2500           0 :             nResult = pHandler->getToken();
    2501             :     }
    2502             : 
    2503       27119 :     return nResult;
    2504             : }
    2505             : 
    2506             : 
    2507             : /*
    2508             :   class OOXMLFastContextHandlerLinear
    2509             :  */
    2510             : 
    2511         195 : OOXMLFastContextHandlerLinear::OOXMLFastContextHandlerLinear(OOXMLFastContextHandler* pContext)
    2512             :     : OOXMLFastContextHandlerProperties(pContext)
    2513         195 :     , depthCount( 0 )
    2514             : {
    2515         195 : }
    2516             : 
    2517        5327 : void OOXMLFastContextHandlerLinear::lcl_startFastElement(Token_t Element,
    2518             :     const uno::Reference< xml::sax::XFastAttributeList >& Attribs)
    2519             :     throw (uno::RuntimeException, xml::sax::SAXException)
    2520             : {
    2521        5327 :     buffer.appendOpeningTag( Element, Attribs );
    2522        5327 :     ++depthCount;
    2523        5327 : }
    2524             : 
    2525        5321 : void OOXMLFastContextHandlerLinear::lcl_endFastElement(Token_t Element)
    2526             :     throw (uno::RuntimeException, xml::sax::SAXException)
    2527             : {
    2528        5321 :     buffer.appendClosingTag( Element );
    2529        5321 :     if( --depthCount == 0 )
    2530         193 :         process();
    2531        5321 : }
    2532             : 
    2533             : uno::Reference< xml::sax::XFastContextHandler >
    2534        5132 : OOXMLFastContextHandlerLinear::lcl_createFastChildContext(Token_t,
    2535             :     const uno::Reference< xml::sax::XFastAttributeList >&)
    2536             :     throw (uno::RuntimeException, xml::sax::SAXException)
    2537             : {
    2538        5132 :     uno::Reference< xml::sax::XFastContextHandler > xContextHandler;
    2539        5132 :     xContextHandler.set( this );
    2540        5132 :     return xContextHandler;
    2541             : }
    2542             : 
    2543         949 : void OOXMLFastContextHandlerLinear::lcl_characters(const OUString& aChars)
    2544             :     throw (uno::RuntimeException, xml::sax::SAXException)
    2545             : {
    2546         949 :     buffer.appendCharacters( aChars );
    2547         949 : }
    2548             : 
    2549             : /*
    2550             :   class OOXMLFastContextHandlerLinear
    2551             :  */
    2552             : 
    2553         195 : OOXMLFastContextHandlerMath::OOXMLFastContextHandlerMath(OOXMLFastContextHandler* pContext)
    2554         195 :     : OOXMLFastContextHandlerLinear(pContext)
    2555             : {
    2556         195 : }
    2557             : 
    2558         193 : void OOXMLFastContextHandlerMath::process()
    2559             : {
    2560         193 :     SvGlobalName name( SO3_SM_CLASSID );
    2561         386 :     comphelper::EmbeddedObjectContainer container;
    2562         386 :     OUString aName;
    2563         386 :     uno::Reference< embed::XEmbeddedObject > ref = container.CreateEmbeddedObject( name.GetByteSequence(), aName );
    2564             :     assert(ref.is());
    2565         193 :     if (!ref.is())
    2566           0 :         return;
    2567         386 :     uno::Reference< uno::XInterface > component( ref->getComponent(), uno::UNO_QUERY );
    2568             : // gcc4.4 (and 4.3 and possibly older) have a problem with dynamic_cast directly to the target class,
    2569             : // so help it with an intermediate cast. I'm not sure what exactly the problem is, seems to be unrelated
    2570             : // to RTLD_GLOBAL, so most probably a gcc bug.
    2571         193 :     oox::FormulaImportBase* import = dynamic_cast< oox::FormulaImportBase* >( dynamic_cast< SfxBaseModel* >(component.get()));
    2572             :     assert( import != NULL );
    2573         193 :     if (!import)
    2574           0 :         return;
    2575         193 :     import->readFormulaOoxml( buffer );
    2576         193 :     if (isForwardEvents())
    2577             :     {
    2578         193 :         OOXMLPropertySet * pProps = new OOXMLPropertySetImpl();
    2579         193 :         OOXMLValue::Pointer_t pVal( new OOXMLStarMathValue( ref ));
    2580         386 :         OOXMLProperty::Pointer_t pProp( new OOXMLPropertyImpl( NS_ooxml::LN_starmath, pVal, OOXMLPropertyImpl::ATTRIBUTE ));
    2581         193 :         pProps->add( pProp );
    2582         386 :         mpStream->props( writerfilter::Reference< Properties >::Pointer_t( pProps ));
    2583         193 :     }
    2584             : }
    2585             : 
    2586          42 : }}
    2587             : 
    2588             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10