LCOV - code coverage report
Current view: top level - reportdesign/source/filter/xml - xmlExportDocumentHandler.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 2 255 0.8 %
Date: 2012-08-25 Functions: 1 27 3.7 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 0 628 0.0 %

           Branch data     Line data    Source code
       1                 :            : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2                 :            : /*************************************************************************
       3                 :            :  *
       4                 :            :  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
       5                 :            :  *
       6                 :            :  * Copyright 2000, 2010 Oracle and/or its affiliates.
       7                 :            :  *
       8                 :            :  * OpenOffice.org - a multi-platform office productivity suite
       9                 :            :  *
      10                 :            :  * This file is part of OpenOffice.org.
      11                 :            :  *
      12                 :            :  * OpenOffice.org is free software: you can redistribute it and/or modify
      13                 :            :  * it under the terms of the GNU Lesser General Public License version 3
      14                 :            :  * only, as published by the Free Software Foundation.
      15                 :            :  *
      16                 :            :  * OpenOffice.org is distributed in the hope that it will be useful,
      17                 :            :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      18                 :            :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      19                 :            :  * GNU Lesser General Public License version 3 for more details
      20                 :            :  * (a copy is included in the LICENSE file that accompanied this code).
      21                 :            :  *
      22                 :            :  * You should have received a copy of the GNU Lesser General Public License
      23                 :            :  * version 3 along with OpenOffice.org.  If not, see
      24                 :            :  * <http://www.openoffice.org/license.html>
      25                 :            :  * for a copy of the LGPLv3 License.
      26                 :            :  *
      27                 :            :  ************************************************************************/
      28                 :            : 
      29                 :            : #include "xmlExportDocumentHandler.hxx"
      30                 :            : #include <com/sun/star/sdb/CommandType.hpp>
      31                 :            : #include <com/sun/star/chart2/data/XDatabaseDataProvider.hpp>
      32                 :            : #include <com/sun/star/chart/XComplexDescriptionAccess.hpp>
      33                 :            : #include <com/sun/star/reflection/XProxyFactory.hpp>
      34                 :            : #include <com/sun/star/sdb/CommandType.hpp>
      35                 :            : #include <comphelper/sequence.hxx>
      36                 :            : #include <comphelper/sequenceashashmap.hxx>
      37                 :            : #include <comphelper/documentconstants.hxx>
      38                 :            : #include <xmloff/attrlist.hxx>
      39                 :            : #include <xmloff/xmltoken.hxx>
      40                 :            : #include <xmloff/xmlement.hxx>
      41                 :            : #include <xmloff/xmluconv.hxx>
      42                 :            : #include <unotools/saveopt.hxx>
      43                 :            : #include <rtl/ustrbuf.hxx>
      44                 :            : #include <connectivity/dbtools.hxx>
      45                 :            : #include <rtl/ustrbuf.hxx>
      46                 :            : 
      47                 :            : namespace rptxml
      48                 :            : {
      49                 :            : using namespace ::com::sun::star;
      50                 :            : using namespace ::xmloff::token;
      51                 :            : 
      52                 :          0 : void lcl_exportPrettyPrinting(const uno::Reference< xml::sax::XDocumentHandler >& _xDelegatee)
      53                 :            : {
      54         [ #  # ]:          0 :     SvtSaveOptions aSaveOpt;
      55 [ #  # ][ #  # ]:          0 :     if ( aSaveOpt.IsPrettyPrinting() )
      56                 :            :     {
      57 [ #  # ][ #  # ]:          0 :         static const ::rtl::OUString s_sWhitespaces(RTL_CONSTASCII_USTRINGPARAM(" "));
         [ #  # ][ #  # ]
      58 [ #  # ][ #  # ]:          0 :         _xDelegatee->ignorableWhitespace(s_sWhitespaces);
      59         [ #  # ]:          0 :     }
      60                 :          0 : }
      61                 :            : 
      62                 :          0 : ::rtl::OUString lcl_createAttribute(const xmloff::token::XMLTokenEnum& _eNamespace,const xmloff::token::XMLTokenEnum& _eAttribute)
      63                 :            : {
      64                 :          0 :     ::rtl::OUStringBuffer sQName;
      65                 :            :     // ...if it's in our map, make the prefix
      66 [ #  # ][ #  # ]:          0 :     sQName.append ( xmloff::token::GetXMLToken(_eNamespace) );
      67         [ #  # ]:          0 :     sQName.append ( sal_Unicode(':') );
      68 [ #  # ][ #  # ]:          0 :     sQName.append ( xmloff::token::GetXMLToken(_eAttribute) );
      69         [ #  # ]:          0 :     return sQName.makeStringAndClear();
      70                 :            : }
      71                 :            : 
      72                 :          0 : void lcl_correctCellAddress(const ::rtl::OUString & _sName, const uno::Reference< xml::sax::XAttributeList > & xAttribs)
      73                 :            : {
      74                 :          0 :     SvXMLAttributeList* pList = SvXMLAttributeList::getImplementation(xAttribs);
      75         [ #  # ]:          0 :     ::rtl::OUString sCellAddress = pList->getValueByName(_sName);
      76                 :          0 :     const sal_Int32 nPos = sCellAddress.lastIndexOf('$');
      77         [ #  # ]:          0 :     if ( nPos != -1 )
      78                 :            :     {
      79                 :          0 :         sCellAddress = sCellAddress.copy(0,nPos);
      80         [ #  # ]:          0 :         sCellAddress += ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("$65535"));
      81         [ #  # ]:          0 :         pList->RemoveAttribute(_sName);
      82         [ #  # ]:          0 :         pList->AddAttribute(_sName,sCellAddress);
      83                 :          0 :     }
      84                 :          0 : }
      85                 :            : 
      86                 :          0 : ExportDocumentHandler::ExportDocumentHandler(uno::Reference< uno::XComponentContext > const & context) :
      87                 :            :     m_xContext(context)
      88                 :            :     ,m_nCurrentCellIndex(0)
      89                 :            :     ,m_nColumnCount(0)
      90                 :            :     ,m_bTableRowsStarted(false)
      91                 :            :     ,m_bFirstRowExported(false)
      92                 :            :     ,m_bExportChar(false)
      93 [ #  # ][ #  # ]:          0 :     ,m_bCountColumnHeader(false)
      94                 :            : {
      95                 :          0 : }
      96                 :            : // -----------------------------------------------------------------------------
      97 [ #  # ][ #  # ]:          0 : ExportDocumentHandler::~ExportDocumentHandler()
      98                 :            : {
      99         [ #  # ]:          0 :     if ( m_xProxy.is() )
     100                 :            :     {
     101 [ #  # ][ #  # ]:          0 :         m_xProxy->setDelegator( NULL );
                 [ #  # ]
     102                 :          0 :         m_xProxy.clear();
     103                 :            :     }
     104         [ #  # ]:          0 : }
     105                 :          0 : IMPLEMENT_GET_IMPLEMENTATION_ID(ExportDocumentHandler)
     106                 :          0 : IMPLEMENT_FORWARD_REFCOUNT( ExportDocumentHandler, ExportDocumentHandler_BASE )
     107                 :            : //------------------------------------------------------------------------
     108                 :          0 : ::rtl::OUString SAL_CALL ExportDocumentHandler::getImplementationName(  ) throw(uno::RuntimeException)
     109                 :            : {
     110                 :          0 :     return getImplementationName_Static();
     111                 :            : }
     112                 :            : 
     113                 :            : //------------------------------------------------------------------------
     114                 :          0 : sal_Bool SAL_CALL ExportDocumentHandler::supportsService( const ::rtl::OUString& ServiceName ) throw(uno::RuntimeException)
     115                 :            : {
     116         [ #  # ]:          0 :     return ::comphelper::existsValue(ServiceName,getSupportedServiceNames_static());
     117                 :            : }
     118                 :            : 
     119                 :            : //------------------------------------------------------------------------
     120                 :          0 : uno::Sequence< ::rtl::OUString > SAL_CALL ExportDocumentHandler::getSupportedServiceNames(  ) throw(uno::RuntimeException)
     121                 :            : {
     122         [ #  # ]:          0 :     uno::Sequence< ::rtl::OUString > aSupported;
     123         [ #  # ]:          0 :     if ( m_xServiceInfo.is() )
     124 [ #  # ][ #  # ]:          0 :         aSupported = m_xServiceInfo->getSupportedServiceNames();
         [ #  # ][ #  # ]
     125 [ #  # ][ #  # ]:          0 :     return ::comphelper::concatSequences(getSupportedServiceNames_static(),aSupported);
         [ #  # ][ #  # ]
     126                 :            : }
     127                 :            : 
     128                 :            : //------------------------------------------------------------------------
     129                 :          6 : ::rtl::OUString ExportDocumentHandler::getImplementationName_Static(  ) throw(uno::RuntimeException)
     130                 :            : {
     131                 :          6 :     return ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.comp.report.ExportDocumentHandler"));
     132                 :            : }
     133                 :            : 
     134                 :            : //------------------------------------------------------------------------
     135                 :          0 : uno::Sequence< ::rtl::OUString > ExportDocumentHandler::getSupportedServiceNames_static(  ) throw(uno::RuntimeException)
     136                 :            : {
     137                 :          0 :     uno::Sequence< ::rtl::OUString > aSupported(1);
     138 [ #  # ][ #  # ]:          0 :     aSupported[0] = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.report.ExportDocumentHandler"));
     139                 :          0 :     return aSupported;
     140                 :            : }
     141                 :            : 
     142                 :            : //------------------------------------------------------------------------
     143                 :          0 : uno::Reference< uno::XInterface > SAL_CALL ExportDocumentHandler::create( const uno::Reference< uno::XComponentContext >& _rxContext )
     144                 :            : {
     145         [ #  # ]:          0 :     return *(new ExportDocumentHandler( _rxContext ));
     146                 :            : }
     147                 :            : // xml::sax::XDocumentHandler:
     148                 :          0 : void SAL_CALL ExportDocumentHandler::startDocument() throw (uno::RuntimeException, xml::sax::SAXException)
     149                 :            : {
     150                 :          0 :     m_xDelegatee->startDocument();
     151                 :          0 : }
     152                 :            : 
     153                 :          0 : void SAL_CALL ExportDocumentHandler::endDocument() throw (uno::RuntimeException, xml::sax::SAXException)
     154                 :            : {
     155                 :          0 :     m_xDelegatee->endDocument();
     156                 :          0 : }
     157                 :            : 
     158                 :          0 : void SAL_CALL ExportDocumentHandler::startElement(const ::rtl::OUString & _sName, const uno::Reference< xml::sax::XAttributeList > & xAttribs) throw (uno::RuntimeException, xml::sax::SAXException)
     159                 :            : {
     160                 :          0 :     bool bExport = true;
     161         [ #  # ]:          0 :     if ( _sName == "office:chart" )
     162                 :            :     {
     163         [ #  # ]:          0 :         SvXMLAttributeList* pList = new SvXMLAttributeList();
     164 [ #  # ][ #  # ]:          0 :         uno::Reference< xml::sax::XAttributeList > xNewAttribs = pList;
     165                 :          0 :         ::rtl::OUStringBuffer sValue;
     166                 :            :         static SvXMLEnumMapEntry aXML_CommnadTypeEnumMap[] =
     167                 :            :         {
     168                 :            :             { XML_TABLE, sdb::CommandType::TABLE },
     169                 :            :             { XML_QUERY, sdb::CommandType::QUERY },
     170                 :            :             { XML_TOKEN_INVALID, 0 }
     171                 :            :         };
     172 [ #  # ][ #  # ]:          0 :         if ( SvXMLUnitConverter::convertEnum( sValue, static_cast<sal_uInt16>(m_xDatabaseDataProvider->getCommandType()),aXML_CommnadTypeEnumMap ) )
         [ #  # ][ #  # ]
     173                 :            :         {
     174 [ #  # ][ #  # ]:          0 :             pList->AddAttribute(lcl_createAttribute(XML_NP_RPT,XML_COMMAND_TYPE),sValue.makeStringAndClear());
                 [ #  # ]
     175                 :            :         }
     176 [ #  # ][ #  # ]:          0 :         const ::rtl::OUString sComamnd = m_xDatabaseDataProvider->getCommand();
     177         [ #  # ]:          0 :         if ( !sComamnd.isEmpty() )
     178 [ #  # ][ #  # ]:          0 :             pList->AddAttribute(lcl_createAttribute(XML_NP_RPT,XML_COMMAND),sComamnd);
     179                 :            : 
     180 [ #  # ][ #  # ]:          0 :         const ::rtl::OUString sFilter( m_xDatabaseDataProvider->getFilter() );
     181         [ #  # ]:          0 :         if ( !sFilter.isEmpty() )
     182 [ #  # ][ #  # ]:          0 :             pList->AddAttribute(lcl_createAttribute(XML_NP_RPT,XML_FILTER),sFilter);
     183                 :            : 
     184 [ #  # ][ #  # ]:          0 :         const sal_Bool bEscapeProcessing( m_xDatabaseDataProvider->getEscapeProcessing() );
     185         [ #  # ]:          0 :         if ( !bEscapeProcessing )
     186 [ #  # ][ #  # ]:          0 :             pList->AddAttribute(lcl_createAttribute(XML_NP_RPT,XML_ESCAPE_PROCESSING),::xmloff::token::GetXMLToken( XML_FALSE ));
                 [ #  # ]
     187                 :            : 
     188 [ #  # ][ #  # ]:          0 :         pList->AddAttribute(lcl_createAttribute(XML_NP_OFFICE,XML_MIMETYPE),MIMETYPE_OASIS_OPENDOCUMENT_CHART);
                 [ #  # ]
     189                 :            : 
     190 [ #  # ][ #  # ]:          0 :         m_xDelegatee->startElement(lcl_createAttribute(XML_NP_OFFICE,XML_REPORT),xNewAttribs);
                 [ #  # ]
     191                 :            : 
     192         [ #  # ]:          0 :         const ::rtl::OUString sTableCalc = lcl_createAttribute(XML_NP_TABLE,XML_CALCULATION_SETTINGS);
     193 [ #  # ][ #  # ]:          0 :         m_xDelegatee->startElement(sTableCalc,NULL);
                 [ #  # ]
     194         [ #  # ]:          0 :         pList = new SvXMLAttributeList();
     195 [ #  # ][ #  # ]:          0 :         uno::Reference< xml::sax::XAttributeList > xNullAttr = pList;
     196 [ #  # ][ #  # ]:          0 :         pList->AddAttribute(lcl_createAttribute(XML_NP_TABLE,XML_DATE_VALUE),::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("1900-01-01")));
                 [ #  # ]
     197                 :            : 
     198         [ #  # ]:          0 :         const ::rtl::OUString sNullDate = lcl_createAttribute(XML_NP_TABLE,XML_NULL_DATE);
     199 [ #  # ][ #  # ]:          0 :         m_xDelegatee->startElement(sNullDate,xNullAttr);
     200 [ #  # ][ #  # ]:          0 :         m_xDelegatee->endElement(sNullDate);
     201 [ #  # ][ #  # ]:          0 :         m_xDelegatee->endElement(sTableCalc);
     202                 :          0 :         bExport = false;
     203                 :            :     }
     204         [ #  # ]:          0 :     else if ( _sName == "table:table" )
     205                 :            :     {
     206 [ #  # ][ #  # ]:          0 :         m_xDelegatee->startElement(lcl_createAttribute(XML_NP_RPT,XML_DETAIL),NULL);
     207                 :          0 :         lcl_exportPrettyPrinting(m_xDelegatee);
     208                 :            :     }
     209         [ #  # ]:          0 :     else if ( _sName == "table:table-header-rows" )
     210                 :            :     {
     211                 :          0 :         m_bCountColumnHeader = true;
     212                 :            :     }
     213 [ #  # ][ #  # ]:          0 :     else if ( m_bCountColumnHeader && _sName.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("table:table-cell")) )
                 [ #  # ]
     214                 :            :     {
     215                 :          0 :         ++m_nColumnCount;
     216                 :            :     }
     217         [ #  # ]:          0 :     else if ( _sName == "table:table-rows" )
     218                 :            :     {
     219                 :          0 :         m_xDelegatee->startElement(_sName,xAttribs);
     220                 :          0 :         exportTableRows();
     221                 :          0 :         bExport = false;
     222                 :          0 :         m_bTableRowsStarted = true;
     223                 :          0 :         m_bFirstRowExported = true;
     224                 :            :     }
     225 [ #  # ][ #  # ]:          0 :     else if ( m_bTableRowsStarted && m_bFirstRowExported && (_sName.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("table:table-row")) || _sName.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("table:table-cell"))) )
         [ #  # ][ #  # ]
                 [ #  # ]
     226                 :          0 :         bExport = false;
     227         [ #  # ]:          0 :     else if ( _sName == "chart:plot-area" )
     228                 :            :     {
     229                 :          0 :         SvXMLAttributeList* pList = SvXMLAttributeList::getImplementation(xAttribs);
     230         [ #  # ]:          0 :         pList->RemoveAttribute(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("table:cell-range-address")));
     231                 :            :     }
     232         [ #  # ]:          0 :     else if ( _sName == "chart:categories" )
     233                 :            :     {
     234 [ #  # ][ #  # ]:          0 :         static ::rtl::OUString s_sCellAddress(lcl_createAttribute(XML_NP_TABLE,XML_CELL_RANGE_ADDRESS));
         [ #  # ][ #  # ]
     235                 :          0 :         lcl_correctCellAddress(s_sCellAddress,xAttribs);
     236                 :            :     }
     237         [ #  # ]:          0 :     else if ( _sName == "chart:series" )
     238                 :            :     {
     239 [ #  # ][ #  # ]:          0 :         static ::rtl::OUString s_sCellAddress(lcl_createAttribute(XML_NP_CHART,XML_VALUES_CELL_RANGE_ADDRESS));
         [ #  # ][ #  # ]
     240                 :          0 :         lcl_correctCellAddress(s_sCellAddress,xAttribs);
     241                 :            :     }
     242 [ #  # ][ #  # ]:          0 :     else if ( m_bTableRowsStarted && !m_bFirstRowExported && _sName.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("table:table-cell")) )
         [ #  # ][ #  # ]
     243                 :            :     {
     244                 :          0 :         SvXMLAttributeList* pList = SvXMLAttributeList::getImplementation(xAttribs);
     245 [ #  # ][ #  # ]:          0 :         static ::rtl::OUString s_sValue(lcl_createAttribute(XML_NP_OFFICE,XML_VALUE));
         [ #  # ][ #  # ]
     246         [ #  # ]:          0 :         pList->RemoveAttribute(s_sValue);
     247                 :            :     }
     248 [ #  # ][ #  # ]:          0 :     else if ( m_bTableRowsStarted && _sName.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("text:p")) )
                 [ #  # ]
     249                 :            :     {
     250                 :          0 :         bExport = false;
     251                 :            :     }
     252         [ #  # ]:          0 :     if ( bExport )
     253                 :          0 :         m_xDelegatee->startElement(_sName,xAttribs);
     254                 :          0 : }
     255                 :            : // -----------------------------------------------------------------------------
     256                 :          0 : void SAL_CALL ExportDocumentHandler::endElement(const ::rtl::OUString & _sName) throw (uno::RuntimeException, xml::sax::SAXException)
     257                 :            : {
     258                 :          0 :     bool bExport = true;
     259                 :          0 :     ::rtl::OUString sNewName = _sName;
     260         [ #  # ]:          0 :     if ( _sName == "office:chart" )
     261                 :            :     {
     262         [ #  # ]:          0 :         sNewName = lcl_createAttribute(XML_NP_OFFICE,XML_REPORT);
     263                 :            :     }
     264         [ #  # ]:          0 :     else if ( _sName == "table:table" )
     265                 :            :     {
     266 [ #  # ][ #  # ]:          0 :         m_xDelegatee->endElement(_sName);
     267         [ #  # ]:          0 :         lcl_exportPrettyPrinting(m_xDelegatee);
     268         [ #  # ]:          0 :         sNewName = lcl_createAttribute(XML_NP_RPT,XML_DETAIL);
     269                 :            :     }
     270         [ #  # ]:          0 :     else if ( _sName == "table:table-header-rows" )
     271                 :            :     {
     272                 :          0 :         m_bCountColumnHeader = false;
     273                 :            :     }
     274         [ #  # ]:          0 :     else if ( _sName == "table:table-rows" )
     275                 :          0 :         m_bTableRowsStarted = false;
     276 [ #  # ][ #  # ]:          0 :     else if ( m_bTableRowsStarted && m_bFirstRowExported && (_sName.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("table:table-row")) || _sName.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("table:table-cell"))) )
         [ #  # ][ #  # ]
                 [ #  # ]
     277                 :          0 :         bExport = false;
     278 [ #  # ][ #  # ]:          0 :     else if ( m_bTableRowsStarted && _sName.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("table:table-row")) )
                 [ #  # ]
     279                 :          0 :         m_bFirstRowExported = true;
     280 [ #  # ][ #  # ]:          0 :     else if ( m_bTableRowsStarted && _sName.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("text:p")) )
                 [ #  # ]
     281                 :            :     {
     282                 :          0 :         bExport = !m_bFirstRowExported;
     283                 :            :     }
     284                 :            : 
     285         [ #  # ]:          0 :     if ( bExport )
     286 [ #  # ][ #  # ]:          0 :         m_xDelegatee->endElement(sNewName);
     287                 :          0 : }
     288                 :            : 
     289                 :          0 : void SAL_CALL ExportDocumentHandler::characters(const ::rtl::OUString & aChars) throw (uno::RuntimeException, xml::sax::SAXException)
     290                 :            : {
     291 [ #  # ][ #  # ]:          0 :     if ( !(m_bTableRowsStarted || m_bFirstRowExported) )
     292                 :            :     {
     293                 :          0 :         m_xDelegatee->characters(aChars);
     294                 :            :     }
     295         [ #  # ]:          0 :     else if ( m_bExportChar )
     296                 :            :     {
     297 [ #  # ][ #  # ]:          0 :         static const ::rtl::OUString s_sZero(RTL_CONSTASCII_USTRINGPARAM("0"));
         [ #  # ][ #  # ]
     298                 :          0 :         m_xDelegatee->characters(s_sZero);
     299                 :            :     }
     300                 :          0 : }
     301                 :            : 
     302                 :          0 : void SAL_CALL ExportDocumentHandler::ignorableWhitespace(const ::rtl::OUString & aWhitespaces) throw (uno::RuntimeException, xml::sax::SAXException)
     303                 :            : {
     304                 :          0 :     m_xDelegatee->ignorableWhitespace(aWhitespaces);
     305                 :          0 : }
     306                 :            : 
     307                 :          0 : void SAL_CALL ExportDocumentHandler::processingInstruction(const ::rtl::OUString & aTarget, const ::rtl::OUString & aData) throw (uno::RuntimeException, xml::sax::SAXException)
     308                 :            : {
     309                 :          0 :     m_xDelegatee->processingInstruction(aTarget,aData);
     310                 :          0 : }
     311                 :            : 
     312                 :          0 : void SAL_CALL ExportDocumentHandler::setDocumentLocator(const uno::Reference< xml::sax::XLocator > & xLocator) throw (uno::RuntimeException, xml::sax::SAXException)
     313                 :            : {
     314                 :          0 :     m_xDelegatee->setDocumentLocator(xLocator);
     315                 :          0 : }
     316                 :          0 : void SAL_CALL ExportDocumentHandler::initialize( const uno::Sequence< uno::Any >& _aArguments ) throw (uno::Exception, uno::RuntimeException)
     317                 :            : {
     318         [ #  # ]:          0 :     ::osl::MutexGuard aGuard(m_aMutex);
     319         [ #  # ]:          0 :     comphelper::SequenceAsHashMap aArgs(_aArguments);
     320 [ #  # ][ #  # ]:          0 :     m_xDelegatee = aArgs.getUnpackedValueOrDefault(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("DocumentHandler")),m_xDelegatee);
                 [ #  # ]
     321 [ #  # ][ #  # ]:          0 :     m_xModel = aArgs.getUnpackedValueOrDefault(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Model")),m_xModel);
                 [ #  # ]
     322                 :            : 
     323                 :            :     OSL_ENSURE(m_xDelegatee.is(),"No document handler avialable!");
     324 [ #  # ][ #  # ]:          0 :     if ( !m_xDelegatee.is() || !m_xModel.is() )
                 [ #  # ]
     325         [ #  # ]:          0 :         throw uno::Exception();
     326                 :            : 
     327 [ #  # ][ #  # ]:          0 :     m_xDatabaseDataProvider.set(m_xModel->getDataProvider(),uno::UNO_QUERY);
                 [ #  # ]
     328 [ #  # ][ #  # ]:          0 :     if ( !m_xDatabaseDataProvider.is() || !m_xDatabaseDataProvider->getActiveConnection().is() )
         [ #  # ][ #  # ]
           [ #  #  #  # ]
                 [ #  # ]
     329         [ #  # ]:          0 :         throw uno::Exception();
     330                 :            : 
     331 [ #  # ][ #  # ]:          0 :     uno::Reference< reflection::XProxyFactory > xProxyFactory( m_xContext->getServiceManager()->createInstanceWithContext(
                 [ #  # ]
     332                 :          0 :         ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.reflection.ProxyFactory")),m_xContext),
     333 [ #  # ][ #  # ]:          0 :         uno::UNO_QUERY);
                 [ #  # ]
     334 [ #  # ][ #  # ]:          0 :     m_xProxy = xProxyFactory->createProxy(m_xDelegatee.get());
         [ #  # ][ #  # ]
                 [ #  # ]
     335         [ #  # ]:          0 :     ::comphelper::query_aggregation(m_xProxy,m_xDelegatee);
     336         [ #  # ]:          0 :     m_xTypeProvider.set(m_xDelegatee,uno::UNO_QUERY);
     337         [ #  # ]:          0 :     m_xServiceInfo.set(m_xDelegatee,uno::UNO_QUERY);
     338                 :            : 
     339                 :            :     // set ourself as delegator
     340 [ #  # ][ #  # ]:          0 :     m_xProxy->setDelegator( *this );
                 [ #  # ]
     341 [ #  # ][ #  # ]:          0 :     const ::rtl::OUString sCommand = m_xDatabaseDataProvider->getCommand();
     342         [ #  # ]:          0 :     if ( !sCommand.isEmpty() )
     343         [ #  # ]:          0 :         m_aColumns = ::dbtools::getFieldNamesByCommandDescriptor(m_xDatabaseDataProvider->getActiveConnection()
     344         [ #  # ]:          0 :                     ,m_xDatabaseDataProvider->getCommandType()
     345 [ #  # ][ #  # ]:          0 :                     ,sCommand);
         [ #  # ][ #  # ]
                 [ #  # ]
     346                 :            : 
     347         [ #  # ]:          0 :     uno::Reference< chart::XComplexDescriptionAccess > xDataProvider(m_xDatabaseDataProvider,uno::UNO_QUERY);
     348         [ #  # ]:          0 :     if ( xDataProvider.is() )
     349                 :            :     {
     350         [ #  # ]:          0 :         m_aColumns.realloc(1);
     351 [ #  # ][ #  # ]:          0 :         uno::Sequence< ::rtl::OUString > aColumnNames = xDataProvider->getColumnDescriptions();
     352         [ #  # ]:          0 :         for(sal_Int32 i = 0 ; i < aColumnNames.getLength();++i)
     353                 :            :         {
     354 [ #  # ][ #  # ]:          0 :             if ( !aColumnNames[i].isEmpty() )
     355                 :            :             {
     356                 :          0 :                 sal_Int32 nCount = m_aColumns.getLength();
     357         [ #  # ]:          0 :                 m_aColumns.realloc(nCount+1);
     358 [ #  # ][ #  # ]:          0 :                 m_aColumns[nCount] = aColumnNames[i];
     359                 :            :             }
     360         [ #  # ]:          0 :         }
     361 [ #  # ][ #  # ]:          0 :     }
     362                 :          0 : }
     363                 :            : // --------------------------------------------------------------------------------
     364                 :          0 : uno::Any SAL_CALL ExportDocumentHandler::queryInterface( const uno::Type& _rType ) throw (uno::RuntimeException)
     365                 :            : {
     366         [ #  # ]:          0 :     uno::Any aReturn = ExportDocumentHandler_BASE::queryInterface(_rType);
     367 [ #  # ][ #  # ]:          0 :     return aReturn.hasValue() ? aReturn : (m_xProxy.is() ? m_xProxy->queryAggregation(_rType) : aReturn);
         [ #  # ][ #  # ]
     368                 :            : }
     369                 :            : // --------------------------------------------------------------------------------
     370                 :          0 : uno::Sequence< uno::Type > SAL_CALL ExportDocumentHandler::getTypes(  ) throw (uno::RuntimeException)
     371                 :            : {
     372         [ #  # ]:          0 :     if ( m_xTypeProvider.is() )
     373                 :            :         return ::comphelper::concatSequences(
     374                 :            :             ExportDocumentHandler_BASE::getTypes(),
     375                 :          0 :             m_xTypeProvider->getTypes()
     376 [ #  # ][ #  # ]:          0 :         );
                 [ #  # ]
     377                 :          0 :     return ExportDocumentHandler_BASE::getTypes();
     378                 :            : }
     379                 :            : // -----------------------------------------------------------------------------
     380                 :          0 : void ExportDocumentHandler::exportTableRows()
     381                 :            : {
     382         [ #  # ]:          0 :     const ::rtl::OUString sRow( lcl_createAttribute(XML_NP_TABLE, XML_TABLE_ROW) );
     383 [ #  # ][ #  # ]:          0 :     m_xDelegatee->startElement(sRow,NULL);
                 [ #  # ]
     384                 :            : 
     385         [ #  # ]:          0 :     const ::rtl::OUString sValueType( lcl_createAttribute(XML_NP_OFFICE, XML_VALUE_TYPE) );
     386                 :            : 
     387 [ #  # ][ #  # ]:          0 :     const static ::rtl::OUString s_sFieldPrefix(RTL_CONSTASCII_USTRINGPARAM("field:["));
         [ #  # ][ #  # ]
     388 [ #  # ][ #  # ]:          0 :     const static ::rtl::OUString s_sFieldPostfix(RTL_CONSTASCII_USTRINGPARAM("]"));
         [ #  # ][ #  # ]
     389         [ #  # ]:          0 :     const ::rtl::OUString sCell( lcl_createAttribute(XML_NP_TABLE, XML_TABLE_CELL) );
     390         [ #  # ]:          0 :     const ::rtl::OUString sP( lcl_createAttribute(XML_NP_TEXT, XML_P) );
     391         [ #  # ]:          0 :     const ::rtl::OUString sFtext(lcl_createAttribute(XML_NP_RPT,XML_FORMATTED_TEXT) );
     392         [ #  # ]:          0 :     const ::rtl::OUString sRElement(lcl_createAttribute(XML_NP_RPT,XML_REPORT_ELEMENT) );
     393         [ #  # ]:          0 :     const ::rtl::OUString sRComponent( lcl_createAttribute(XML_NP_RPT,XML_REPORT_COMPONENT) ) ;
     394         [ #  # ]:          0 :     const ::rtl::OUString sFormulaAttrib( lcl_createAttribute(XML_NP_RPT,XML_FORMULA) );
     395 [ #  # ][ #  # ]:          0 :     const static ::rtl::OUString s_sString(RTL_CONSTASCII_USTRINGPARAM("string"));
         [ #  # ][ #  # ]
     396 [ #  # ][ #  # ]:          0 :     const static ::rtl::OUString s_sFloat(RTL_CONSTASCII_USTRINGPARAM("float"));
         [ #  # ][ #  # ]
     397                 :            : 
     398         [ #  # ]:          0 :     SvXMLAttributeList* pCellAtt = new SvXMLAttributeList();
     399 [ #  # ][ #  # ]:          0 :     uno::Reference< xml::sax::XAttributeList > xCellAtt = pCellAtt;
     400         [ #  # ]:          0 :     pCellAtt->AddAttribute(sValueType,s_sString);
     401                 :            : 
     402                 :          0 :     bool bRemoveString = true;
     403                 :          0 :     ::rtl::OUString sFormula;
     404                 :          0 :     const sal_Int32 nCount = m_aColumns.getLength();
     405         [ #  # ]:          0 :     if ( m_nColumnCount > nCount )
     406                 :            :     {
     407                 :          0 :         const sal_Int32 nEmptyCellCount = m_nColumnCount - nCount;
     408         [ #  # ]:          0 :         for(sal_Int32 i = 0; i < nEmptyCellCount ; ++i)
     409                 :            :         {
     410 [ #  # ][ #  # ]:          0 :             m_xDelegatee->startElement(sCell,xCellAtt);
     411         [ #  # ]:          0 :             if ( bRemoveString )
     412                 :            :             {
     413                 :          0 :                 bRemoveString = false;
     414         [ #  # ]:          0 :                 pCellAtt->RemoveAttribute(sValueType);
     415         [ #  # ]:          0 :                 pCellAtt->AddAttribute(sValueType,s_sFloat);
     416                 :            :             }
     417 [ #  # ][ #  # ]:          0 :             m_xDelegatee->startElement(sP,NULL);
                 [ #  # ]
     418 [ #  # ][ #  # ]:          0 :             m_xDelegatee->endElement(sP);
     419 [ #  # ][ #  # ]:          0 :             m_xDelegatee->endElement(sCell);
     420                 :            :         }
     421                 :            :     }
     422         [ #  # ]:          0 :     for(sal_Int32 i = 0; i < nCount ; ++i)
     423                 :            :     {
     424                 :          0 :         sFormula = s_sFieldPrefix;
     425         [ #  # ]:          0 :         sFormula += m_aColumns[i];
     426                 :          0 :         sFormula += s_sFieldPostfix;
     427         [ #  # ]:          0 :         SvXMLAttributeList* pList = new SvXMLAttributeList();
     428 [ #  # ][ #  # ]:          0 :         uno::Reference< xml::sax::XAttributeList > xAttribs = pList;
     429         [ #  # ]:          0 :         pList->AddAttribute(sFormulaAttrib,sFormula);
     430                 :            : 
     431 [ #  # ][ #  # ]:          0 :         m_xDelegatee->startElement(sCell,xCellAtt);
     432         [ #  # ]:          0 :         if ( bRemoveString )
     433                 :            :         {
     434                 :          0 :             bRemoveString = false;
     435         [ #  # ]:          0 :             pCellAtt->RemoveAttribute(sValueType);
     436         [ #  # ]:          0 :             pCellAtt->AddAttribute(sValueType,s_sFloat);
     437                 :            :         }
     438 [ #  # ][ #  # ]:          0 :         m_xDelegatee->startElement(sP,NULL);
                 [ #  # ]
     439 [ #  # ][ #  # ]:          0 :         m_xDelegatee->startElement(sFtext,xAttribs);
     440 [ #  # ][ #  # ]:          0 :         m_xDelegatee->startElement(sRElement,NULL);
                 [ #  # ]
     441 [ #  # ][ #  # ]:          0 :         m_xDelegatee->startElement(sRComponent,NULL);
                 [ #  # ]
     442                 :            : 
     443 [ #  # ][ #  # ]:          0 :         m_xDelegatee->endElement(sRComponent);
     444 [ #  # ][ #  # ]:          0 :         m_xDelegatee->endElement(sRElement);
     445 [ #  # ][ #  # ]:          0 :         m_xDelegatee->endElement(sFtext);
     446 [ #  # ][ #  # ]:          0 :         m_xDelegatee->endElement(sP);
     447 [ #  # ][ #  # ]:          0 :         m_xDelegatee->endElement(sCell);
     448                 :          0 :     }
     449                 :            : 
     450 [ #  # ][ #  # ]:          0 :     m_xDelegatee->endElement(sRow);
     451                 :          0 : }
     452                 :            : // -----------------------------------------------------------------------------
     453                 :            : } // namespace rptxml
     454                 :            : // -----------------------------------------------------------------------------
     455                 :            : 
     456                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10