LCOV - code coverage report
Current view: top level - usr/local/src/libreoffice/writerfilter/source/ooxml - OOXMLDocumentImpl.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 125 167 74.9 %
Date: 2013-07-09 Functions: 27 34 79.4 %
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 <com/sun/star/xml/sax/XParser.hpp>
      21             : 
      22             : #include <com/sun/star/xml/sax/SAXException.hpp>
      23             : #include <doctok/resourceids.hxx>
      24             : #include <ooxml/resourceids.hxx>
      25             : #include "OOXMLDocumentImpl.hxx"
      26             : #include "OOXMLBinaryObjectReference.hxx"
      27             : #include "OOXMLFastDocumentHandler.hxx"
      28             : #include "OOXMLPropertySetImpl.hxx"
      29             : #include "ooxmlLoggers.hxx"
      30             : 
      31             : #include <iostream>
      32             : 
      33             : using ::com::sun::star::xml::sax::SAXException;
      34             : namespace writerfilter {
      35             : namespace ooxml
      36             : {
      37             : 
      38             : #if OSL_DEBUG_LEVEL > 1
      39             : TagLogger::Pointer_t debug_logger(TagLogger::getInstance("DEBUG"));
      40             : #endif
      41             : 
      42             : using namespace ::std;
      43             : 
      44         244 : OOXMLDocumentImpl::OOXMLDocumentImpl
      45             : (OOXMLStream::Pointer_t pStream)
      46         244 : : mpStream(pStream), mXNoteType(0), mbIsSubstream( false )
      47             : {
      48         244 : }
      49             : 
      50         488 : OOXMLDocumentImpl::~OOXMLDocumentImpl()
      51             : {
      52         488 : }
      53             : 
      54        1220 : void OOXMLDocumentImpl::resolveFastSubStream(Stream & rStreamHandler,
      55             :                                              OOXMLStream::StreamType_t nType)
      56             : {
      57             :     OOXMLStream::Pointer_t pStream
      58        1220 :         (OOXMLDocumentFactory::createStream(mpStream, nType));
      59        2440 :     OOXMLStream::Pointer_t savedStream = mpStream;
      60        1220 :     mpStream = pStream;
      61             : 
      62             :     uno::Reference< xml::sax::XFastParser > xParser
      63        2440 :         (mpStream->getFastParser());
      64             : 
      65        1220 :     if (xParser.is())
      66             :     {
      67        1220 :         uno::Reference<uno::XComponentContext> xContext(mpStream->getContext());
      68             :         OOXMLFastDocumentHandler * pDocHandler =
      69             :             new OOXMLFastDocumentHandler(
      70        1220 :                 xContext, &rStreamHandler, this, mnXNoteId );
      71             : 
      72             :         uno::Reference < xml::sax::XFastDocumentHandler > xDocumentHandler
      73        2440 :             (pDocHandler);
      74             :         uno::Reference < xml::sax::XFastTokenHandler > xTokenHandler
      75        2440 :             (mpStream->getFastTokenHandler(xContext));
      76             : 
      77        1220 :         xParser->setFastDocumentHandler(xDocumentHandler);
      78        1220 :         xParser->setTokenHandler(xTokenHandler);
      79             : 
      80             :         uno::Reference<io::XInputStream> xInputStream =
      81        2440 :             pStream->getDocumentStream();
      82             : 
      83        1220 :         if (xInputStream.is())
      84             :         {
      85         584 :             struct xml::sax::InputSource oInputSource;
      86         584 :             oInputSource.aInputStream = xInputStream;
      87         584 :             xParser->parseStream(oInputSource);
      88             : 
      89         584 :             xInputStream->closeInput();
      90        1220 :         }
      91             :     }
      92             : 
      93        2440 :     mpStream = savedStream;
      94        1220 : }
      95             : 
      96          81 : void OOXMLDocumentImpl::resolveFastSubStreamWithId(Stream & rStream,
      97             :                                       writerfilter::Reference<Stream>::Pointer_t pStream,
      98             :                       sal_uInt32 nId)
      99             : {
     100          81 :     rStream.substream(nId, pStream);
     101          81 : }
     102             : 
     103         830 : void OOXMLDocumentImpl::setXNoteId(const sal_Int32 nId)
     104             : {
     105         830 :     mnXNoteId = nId;
     106         830 : }
     107             : 
     108           2 : sal_Int32 OOXMLDocumentImpl::getXNoteId() const
     109             : {
     110           2 :     return mnXNoteId;
     111             : }
     112             : 
     113           2 : void OOXMLDocumentImpl::setXNoteType(const Id & nId)
     114             : {
     115           2 :     mXNoteType = nId;
     116           2 : }
     117             : 
     118           0 : const Id & OOXMLDocumentImpl::getXNoteType() const
     119             : {
     120           0 :     return mXNoteType;
     121             : }
     122             : 
     123          70 : const OUString & OOXMLDocumentImpl::getTarget() const
     124             : {
     125          70 :     return mpStream->getTarget();
     126             : }
     127             : 
     128             : writerfilter::Reference<Stream>::Pointer_t
     129          79 : OOXMLDocumentImpl::getSubStream(const OUString & rId)
     130             : {
     131             :     OOXMLStream::Pointer_t pStream
     132          79 :         (OOXMLDocumentFactory::createStream(mpStream, rId));
     133             : 
     134             :     OOXMLDocumentImpl * pTemp;
     135          79 :     writerfilter::Reference<Stream>::Pointer_t pRet( pTemp = new OOXMLDocumentImpl(pStream) );
     136          79 :     pTemp->setModel(mxModel);
     137          79 :     pTemp->setDrawPage(mxDrawPage);
     138          79 :     pTemp->setIsSubstream( true );
     139          79 :     return pRet;
     140             : }
     141             : 
     142             : writerfilter::Reference<Stream>::Pointer_t
     143           2 : OOXMLDocumentImpl::getXNoteStream(OOXMLStream::StreamType_t nType, const Id & rType,
     144             :                                   const sal_Int32 nId)
     145             : {
     146             : #ifdef DEBUG_ELEMENT
     147             :     debug_logger->startElement("getXNoteStream");
     148             :     debug_logger->attribute("id", nId);
     149             :     debug_logger->endElement();
     150             : #endif
     151             : 
     152             :     OOXMLStream::Pointer_t pStream =
     153           2 :         (OOXMLDocumentFactory::createStream(mpStream, nType));
     154           2 :     OOXMLDocumentImpl * pDocument = new OOXMLDocumentImpl(pStream);
     155           2 :     pDocument->setXNoteId(nId);
     156           2 :     pDocument->setXNoteType(rType);
     157             : 
     158           2 :     return writerfilter::Reference<Stream>::Pointer_t(pDocument);
     159             : }
     160             : 
     161           0 : void OOXMLDocumentImpl::resolveFootnote(Stream & rStream,
     162             :                                         const Id & rType,
     163             :                                         const sal_Int32 nNoteId)
     164             : {
     165             :     writerfilter::Reference<Stream>::Pointer_t pStream =
     166           0 :         getXNoteStream(OOXMLStream::FOOTNOTES, rType, nNoteId);
     167             : 
     168             :     Id nId;
     169           0 :     switch (rType)
     170             :     {
     171             :     case NS_ooxml::LN_Value_wordprocessingml_ST_FtnEdn_separator:
     172             :     case NS_ooxml::LN_Value_wordprocessingml_ST_FtnEdn_continuationSeparator:
     173           0 :         nId = rType;
     174           0 :         break;
     175             :     default:
     176           0 :         nId = NS_rtf::LN_footnote;
     177           0 :         break;
     178             :     }
     179             : 
     180           0 :     resolveFastSubStreamWithId(rStream, pStream, nId);
     181           0 : }
     182             : 
     183           0 : void OOXMLDocumentImpl::resolveEndnote(Stream & rStream,
     184             :                                        const Id & rType,
     185             :                                        const sal_Int32 nNoteId)
     186             : {
     187             :     writerfilter::Reference<Stream>::Pointer_t pStream =
     188           0 :         getXNoteStream(OOXMLStream::ENDNOTES, rType, nNoteId);
     189             : 
     190             :     Id nId;
     191           0 :     switch (rType)
     192             :     {
     193             :     case NS_ooxml::LN_Value_wordprocessingml_ST_FtnEdn_separator:
     194             :     case NS_ooxml::LN_Value_wordprocessingml_ST_FtnEdn_continuationSeparator:
     195           0 :         nId = rType;
     196           0 :         break;
     197             :     default:
     198           0 :         nId = NS_rtf::LN_endnote;
     199           0 :         break;
     200             :     }
     201             : 
     202           0 :     resolveFastSubStreamWithId(rStream, pStream, nId);
     203           0 : }
     204             : 
     205           2 : void OOXMLDocumentImpl::resolveComment(Stream & rStream,
     206             :                                        const sal_Int32 nId)
     207             : {
     208             :     writerfilter::Reference<Stream>::Pointer_t pStream =
     209           2 :         getXNoteStream(OOXMLStream::COMMENTS, 0, nId);
     210             : 
     211           2 :     resolveFastSubStreamWithId(rStream, pStream, NS_rtf::LN_annotation);
     212           2 : }
     213             : 
     214           0 : OOXMLPropertySet * OOXMLDocumentImpl::getPicturePropSet
     215             : (const OUString & rId)
     216             : {
     217             :     OOXMLStream::Pointer_t pStream
     218           0 :         (OOXMLDocumentFactory::createStream(mpStream, rId));
     219             : 
     220             :     writerfilter::Reference<BinaryObj>::Pointer_t pPicture
     221           0 :         (new OOXMLBinaryObjectReference(pStream));
     222             : 
     223           0 :     OOXMLValue::Pointer_t pPayloadValue(new OOXMLBinaryValue(pPicture));
     224             : 
     225             :     OOXMLProperty::Pointer_t pPayloadProperty
     226             :         (new OOXMLPropertyImpl(NS_rtf::LN_payload, pPayloadValue,
     227           0 :                                OOXMLPropertyImpl::ATTRIBUTE));
     228             : 
     229           0 :     OOXMLPropertySet::Pointer_t pBlipSet(new OOXMLPropertySetImpl());
     230             : 
     231           0 :     pBlipSet->add(pPayloadProperty);
     232             : 
     233           0 :     OOXMLValue::Pointer_t pBlipValue(new OOXMLPropertySetValue(pBlipSet));
     234             : 
     235             :     OOXMLProperty::Pointer_t pBlipProperty
     236             :         (new OOXMLPropertyImpl(NS_rtf::LN_blip, pBlipValue,
     237           0 :                                OOXMLPropertyImpl::ATTRIBUTE));
     238             : 
     239           0 :     OOXMLPropertySet * pProps = new OOXMLPropertySetImpl();
     240             : 
     241           0 :     pProps->add(pBlipProperty);
     242             : 
     243           0 :     return pProps;
     244             : }
     245             : 
     246           0 : void OOXMLDocumentImpl::resolvePicture(Stream & rStream,
     247             :                                        const OUString & rId)
     248             : {
     249           0 :     OOXMLPropertySet * pProps = getPicturePropSet(rId);
     250             : 
     251           0 :     rStream.props(writerfilter::Reference<Properties>::Pointer_t(pProps));
     252           0 : }
     253             : 
     254           2 : OUString OOXMLDocumentImpl::getTargetForId(const OUString & rId)
     255             : {
     256           2 :     return mpStream->getTargetForId(rId);
     257             : }
     258             : 
     259          38 : void OOXMLDocumentImpl::resolveHeader(Stream & rStream,
     260             :                                       const sal_Int32 type,
     261             :                                       const OUString & rId)
     262             : {
     263             :      writerfilter::Reference<Stream>::Pointer_t pStream =
     264          38 :          getSubStream(rId);
     265          38 :      switch (type)
     266             :      {
     267             :      case NS_ooxml::LN_Value_ST_HrdFtr_even:
     268           8 :          resolveFastSubStreamWithId(rStream, pStream, NS_rtf::LN_headerl);
     269           8 :         break;
     270             :      case NS_ooxml::LN_Value_ST_HrdFtr_default: // here we assume that default is right, but not necessarily true :-(
     271          21 :          resolveFastSubStreamWithId(rStream, pStream, NS_rtf::LN_headerr);
     272          21 :          break;
     273             :      case NS_ooxml::LN_Value_ST_HrdFtr_first:
     274           9 :          resolveFastSubStreamWithId(rStream, pStream, NS_rtf::LN_headerf);
     275           9 :          break;
     276             :      default:
     277           0 :          break;
     278          38 :      }
     279          38 : }
     280             : 
     281          41 : void OOXMLDocumentImpl::resolveFooter(Stream & rStream,
     282             :                                       const sal_Int32 type,
     283             :                                       const OUString & rId)
     284             : {
     285             :      writerfilter::Reference<Stream>::Pointer_t pStream =
     286          41 :          getSubStream(rId);
     287             : 
     288          41 :      switch (type)
     289             :      {
     290             :      case NS_ooxml::LN_Value_ST_HrdFtr_even:
     291          11 :          resolveFastSubStreamWithId(rStream, pStream, NS_rtf::LN_footerl);
     292          11 :          break;
     293             :      case NS_ooxml::LN_Value_ST_HrdFtr_default: // here we assume that default is right, but not necessarily true :-(
     294          21 :          resolveFastSubStreamWithId(rStream, pStream, NS_rtf::LN_footerr);
     295          21 :          break;
     296             :      case NS_ooxml::LN_Value_ST_HrdFtr_first:
     297           9 :          resolveFastSubStreamWithId(rStream, pStream, NS_rtf::LN_footerf);
     298           9 :          break;
     299             :      default:
     300           0 :          break;
     301          41 :      }
     302          41 : }
     303             : 
     304         244 : void OOXMLDocumentImpl::resolve(Stream & rStream)
     305             : {
     306             : #ifdef DEBUG_RESOLVE
     307             :     debug_logger->startElement("OOXMLDocumentImpl.resolve");
     308             : #endif
     309             : 
     310             :     uno::Reference< xml::sax::XFastParser > xParser
     311         244 :         (mpStream->getFastParser());
     312             : 
     313         244 :     if (xParser.is())
     314             :     {
     315         244 :         uno::Reference<uno::XComponentContext> xContext(mpStream->getContext());
     316             : 
     317             :         OOXMLFastDocumentHandler * pDocHandler =
     318             :             new OOXMLFastDocumentHandler(
     319         244 :                 xContext, &rStream, this, mnXNoteId );
     320         244 :         pDocHandler->setIsSubstream( mbIsSubstream );
     321             :         uno::Reference < xml::sax::XFastDocumentHandler > xDocumentHandler
     322         488 :             (pDocHandler);
     323             :         uno::Reference < xml::sax::XFastTokenHandler > xTokenHandler
     324         488 :             (mpStream->getFastTokenHandler(xContext));
     325             : 
     326         244 :         resolveFastSubStream(rStream, OOXMLStream::SETTINGS);
     327         244 :         resolveFastSubStream(rStream, OOXMLStream::THEME);
     328         244 :         resolveFastSubStream(rStream, OOXMLStream::FONTTABLE);
     329         244 :         resolveFastSubStream(rStream, OOXMLStream::STYLES);
     330         244 :         resolveFastSubStream(rStream, OOXMLStream::NUMBERING);
     331             : 
     332         244 :         xParser->setFastDocumentHandler( xDocumentHandler );
     333         244 :         xParser->setTokenHandler( xTokenHandler );
     334             : 
     335         488 :         xml::sax::InputSource aParserInput;
     336         244 :         aParserInput.aInputStream = mpStream->getDocumentStream();
     337             :         try
     338             :         {
     339         244 :             xParser->parseStream(aParserInput);
     340             :         }
     341           1 :         catch (...) {
     342             : #ifdef DEBUG_ELEMENT
     343             :             debug_logger->element("exception");
     344             : #endif
     345         244 :         }
     346         244 :     }
     347             : 
     348             : #ifdef DEBUG_RESOLVE
     349             :     debug_logger->endElement();
     350             : #endif
     351         244 : }
     352             : 
     353           5 : uno::Reference<io::XInputStream> OOXMLDocumentImpl::getInputStreamForId(const OUString & rId)
     354             : {
     355           5 :     OOXMLStream::Pointer_t pStream(OOXMLDocumentFactory::createStream(mpStream, rId));
     356             : 
     357           5 :     return pStream->getDocumentStream();
     358             : }
     359             : 
     360           0 : string OOXMLDocumentImpl::getType() const
     361             : {
     362           0 :     return "OOXMLDocumentImpl";
     363             : }
     364             : 
     365         242 : void OOXMLDocumentImpl::setModel(uno::Reference<frame::XModel> xModel)
     366             : {
     367         242 :     mxModel.set(xModel);
     368         242 : }
     369             : 
     370          70 : uno::Reference<frame::XModel> OOXMLDocumentImpl::getModel()
     371             : {
     372          70 :     return mxModel;
     373             : }
     374             : 
     375         242 : void OOXMLDocumentImpl::setDrawPage(uno::Reference<drawing::XDrawPage> xDrawPage)
     376             : {
     377         242 :     mxDrawPage.set(xDrawPage);
     378         242 : }
     379             : 
     380          70 : uno::Reference<drawing::XDrawPage> OOXMLDocumentImpl::getDrawPage()
     381             : {
     382          70 :     return mxDrawPage;
     383             : }
     384             : 
     385           0 : uno::Reference<io::XInputStream> OOXMLDocumentImpl::getInputStream()
     386             : {
     387           0 :     return mpStream->getDocumentStream();
     388             : }
     389             : 
     390          70 : uno::Reference<io::XInputStream> OOXMLDocumentImpl::getStorageStream()
     391             : {
     392          70 :     return mpStream->getStorageStream();
     393             : }
     394             : 
     395          45 : void OOXMLDocumentImpl::setShapeContext( uno::Reference<xml::sax::XFastShapeContextHandler> xContext )
     396             : {
     397          45 :     mxShapeContext = xContext;
     398          45 : }
     399             : 
     400          70 : uno::Reference<xml::sax::XFastShapeContextHandler> OOXMLDocumentImpl::getShapeContext( )
     401             : {
     402          70 :     return mxShapeContext;
     403             : }
     404             : 
     405             : OOXMLDocument *
     406         163 : OOXMLDocumentFactory::createDocument
     407             : (OOXMLStream::Pointer_t pStream)
     408             : {
     409         163 :     return new OOXMLDocumentImpl(pStream);
     410             : }
     411             : 
     412          24 : }}
     413             : 
     414             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10