LCOV - code coverage report
Current view: top level - libreoffice/xmloff/source/style - impastp4.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 140 171 81.9 %
Date: 2012-12-17 Functions: 9 11 81.8 %
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 <tools/debug.hxx>
      21             : #include <xmloff/xmlaustp.hxx>
      22             : #include <xmloff/xmltoken.hxx>
      23             : #include <xmloff/nmspmap.hxx>
      24             : #include "xmloff/xmlnmspe.hxx"
      25             : #include <xmloff/attrlist.hxx>
      26             : #include "impastpl.hxx"
      27             : #include <xmloff/xmlexppr.hxx>
      28             : #include <xmloff/xmlexp.hxx>
      29             : #include <xmloff/families.hxx>
      30             : #include <xmloff/PageMasterStyleMap.hxx>
      31             : 
      32             : using namespace ::std;
      33             : using ::rtl::OUString;
      34             : using ::rtl::OUStringBuffer;
      35             : 
      36             : using namespace ::com::sun::star;
      37             : using namespace ::xmloff::token;
      38             : 
      39             : //#############################################################################
      40             : //
      41             : // Class SvXMLAutoStylePool_Impl
      42             : //
      43             : 
      44             : ///////////////////////////////////////////////////////////////////////////////
      45             : //
      46             : // ctor/dtor class SvXMLAutoStylePool_Impl
      47             : //
      48             : 
      49          24 : SvXMLAutoStylePoolP_Impl::SvXMLAutoStylePoolP_Impl( SvXMLExport& rExp)
      50          24 :     :   rExport( rExp )
      51             : {
      52          24 : }
      53             : 
      54          24 : SvXMLAutoStylePoolP_Impl::~SvXMLAutoStylePoolP_Impl()
      55             : {
      56          24 : }
      57             : 
      58             : ///////////////////////////////////////////////////////////////////////////////
      59             : //
      60             : // Adds stylefamily-informations to sorted list
      61             : //
      62             : 
      63         240 : void SvXMLAutoStylePoolP_Impl::AddFamily(
      64             :         sal_Int32 nFamily,
      65             :         const OUString& rStrName,
      66             :         const UniReference < SvXMLExportPropertyMapper > & rMapper,
      67             :            const OUString& rStrPrefix,
      68             :         sal_Bool bAsFamily )
      69             : {
      70             :     // store family in a list if not already stored
      71         240 :     sal_uInt16 nExportFlags = GetExport().getExportFlags();
      72         240 :     sal_Bool bStylesOnly = (nExportFlags & EXPORT_STYLES) != 0 && (nExportFlags & EXPORT_CONTENT) == 0;
      73             : 
      74         240 :     OUString aPrefix( rStrPrefix );
      75         240 :     if( bStylesOnly )
      76             :     {
      77         104 :         aPrefix = OUString( 'M' );
      78         104 :         aPrefix += rStrPrefix;
      79             :     }
      80             : 
      81         240 :     XMLFamilyData_Impl *pFamily = new XMLFamilyData_Impl( nFamily, rStrName, rMapper, aPrefix, bAsFamily );
      82         240 :     maFamilyList.insert(pFamily);
      83         240 : }
      84             : 
      85           0 : void SvXMLAutoStylePoolP_Impl::SetFamilyPropSetMapper(
      86             :         sal_Int32 nFamily,
      87             :         const UniReference < SvXMLExportPropertyMapper > & rMapper )
      88             : {
      89             : 
      90           0 :     XMLFamilyData_Impl aTemporary( nFamily );
      91           0 :     XMLFamilyDataList_Impl::iterator aFind = maFamilyList.find(aTemporary);
      92           0 :     if (aFind != maFamilyList.end())
      93           0 :         aFind->mxMapper = rMapper;
      94           0 : }
      95             : ///////////////////////////////////////////////////////////////////////////////
      96             : //
      97             : // Adds a name to list
      98             : //
      99             : 
     100        1332 : void SvXMLAutoStylePoolP_Impl::RegisterName( sal_Int32 nFamily, const OUString& rName )
     101             : {
     102        1332 :     XMLFamilyData_Impl aTmp( nFamily );
     103        1332 :     XMLFamilyDataList_Impl::iterator aFind = maFamilyList.find(aTmp);
     104             :     DBG_ASSERT( aFind != maFamilyList.end(),
     105             :                 "SvXMLAutoStylePool_Impl::RegisterName: unknown family" );
     106        1332 :     if (aFind != maFamilyList.end())
     107        1332 :         aFind->mpNameList->insert(rName);
     108        1332 : }
     109             : 
     110             : ///////////////////////////////////////////////////////////////////////////////
     111             : //
     112             : // Retrieve the list of registered names
     113             : //
     114             : 
     115           8 : void SvXMLAutoStylePoolP_Impl::GetRegisteredNames(
     116             :     uno::Sequence<sal_Int32>& rFamilies,
     117             :     uno::Sequence<OUString>& rNames )
     118             : {
     119             :     // collect registered names + families
     120           8 :     vector<sal_Int32> aFamilies;
     121           8 :     vector<OUString> aNames;
     122             : 
     123             :     // iterate over families
     124          68 :     for(XMLFamilyDataList_Impl::iterator aJ = maFamilyList.begin(); aJ != maFamilyList.end(); ++aJ)
     125             :     {
     126          60 :         XMLFamilyData_Impl &rFamily = *aJ;
     127             : 
     128             :         // iterate over names
     129          60 :         SvXMLAutoStylePoolNamesP_Impl* pNames = rFamily.mpNameList;
     130          60 :         if (!pNames)
     131           0 :             continue;
     132         724 :         for (SvXMLAutoStylePoolNamesP_Impl::const_iterator aI = pNames->begin(); aI != pNames->end(); ++aI)
     133             :         {
     134         664 :             aFamilies.push_back( rFamily.mnFamily );
     135         664 :             aNames.push_back( *aI );
     136             :         }
     137             :     }
     138             : 
     139             :     // copy the families + names into the sequence types
     140             :     DBG_ASSERT( aFamilies.size() == aNames.size(), "families != names" );
     141             : 
     142           8 :     rFamilies.realloc( aFamilies.size() );
     143           8 :     std::copy( aFamilies.begin(), aFamilies.end(), rFamilies.getArray() );
     144             : 
     145           8 :     rNames.realloc( aNames.size() );
     146           8 :     std::copy( aNames.begin(), aNames.end(), rNames.getArray() );
     147           8 : }
     148             : 
     149             : ///////////////////////////////////////////////////////////////////////////////
     150             : //
     151             : // Adds a array of XMLPropertyState ( vector< XMLPropertyState > ) to list
     152             : // if not added, yet.
     153             : //
     154             : 
     155          34 : sal_Bool SvXMLAutoStylePoolP_Impl::Add(OUString& rName, sal_Int32 nFamily,
     156             :                 const OUString& rParent,
     157             :                 const ::std::vector< XMLPropertyState >& rProperties,
     158             :                 sal_Bool bCache,
     159             :                 bool bDontSeek )
     160             : {
     161          34 :     sal_Bool bRet(sal_False);
     162             : 
     163          34 :     XMLFamilyData_Impl aTemporary( nFamily );
     164          34 :     XMLFamilyDataList_Impl::iterator aFind = maFamilyList.find(aTemporary);
     165             :     DBG_ASSERT(aFind != maFamilyList.end(), "SvXMLAutoStylePool_Impl::Add: unknown family");
     166             : 
     167          34 :     if (aFind != maFamilyList.end())
     168             :     {
     169          34 :         XMLFamilyData_Impl &rFamily = *aFind;
     170             : 
     171          34 :         SvXMLAutoStylePoolParentP_Impl aTmp( rParent );
     172          34 :         SvXMLAutoStylePoolParentP_Impl *pParent = 0;
     173             : 
     174          34 :         SvXMLAutoStylePoolParentsP_Impl *pParents = rFamily.mpParentList;
     175             :         SvXMLAutoStylePoolParentsP_Impl::const_iterator const it2 =
     176          34 :             pParents->find(&aTmp);
     177          34 :         if (it2 != pParents->end())
     178             :         {
     179          10 :             pParent = *it2;
     180             :         }
     181             :         else
     182             :         {
     183          24 :             pParent = new SvXMLAutoStylePoolParentP_Impl( rParent );
     184          24 :             pParents->insert( pParent );
     185             :         }
     186             : 
     187          34 :         if( pParent->Add( rFamily, rProperties, rName, bDontSeek ) )
     188             :         {
     189          34 :             rFamily.mnCount++;
     190          34 :             bRet = sal_True;
     191             :         }
     192             : 
     193          34 :         if( bCache )
     194             :         {
     195           0 :             if( !rFamily.pCache )
     196           0 :                 rFamily.pCache = new SvXMLAutoStylePoolCache_Impl();
     197           0 :             if( rFamily.pCache->size() < MAX_CACHE_SIZE )
     198           0 :                 rFamily.pCache->push_back( new OUString( rName ) );
     199          34 :         }
     200             :     }
     201             : 
     202          34 :     return bRet;
     203             : }
     204             : 
     205           0 : sal_Bool SvXMLAutoStylePoolP_Impl::AddNamed(const OUString& rName, sal_Int32 nFamily,
     206             :                 const OUString& rParent, const ::std::vector< XMLPropertyState >& rProperties )
     207             : {
     208             :     // get family and parent the same way as in Add()
     209           0 :     sal_Bool bRet(sal_False);
     210             : 
     211           0 :     XMLFamilyData_Impl aTemporary( nFamily );
     212           0 :     XMLFamilyDataList_Impl::iterator aFind = maFamilyList.find(aTemporary);
     213             :     DBG_ASSERT(aFind != maFamilyList.end(), "SvXMLAutoStylePool_Impl::Add: unknown family");
     214             : 
     215           0 :     if (aFind != maFamilyList.end())
     216             :     {
     217           0 :         XMLFamilyData_Impl &rFamily = *aFind;
     218             : 
     219           0 :         SvXMLAutoStylePoolParentP_Impl aTmp( rParent );
     220           0 :         SvXMLAutoStylePoolParentP_Impl *pParent = 0;
     221             : 
     222           0 :         SvXMLAutoStylePoolParentsP_Impl *pParents = rFamily.mpParentList;
     223             :         SvXMLAutoStylePoolParentsP_Impl::const_iterator const it2 =
     224           0 :             pParents->find(&aTmp);
     225           0 :         if (it2 != pParents->end())
     226             :         {
     227           0 :             pParent = *it2;
     228             :         }
     229             :         else
     230             :         {
     231           0 :             pParent = new SvXMLAutoStylePoolParentP_Impl( rParent );
     232           0 :             pParents->insert( pParent );
     233             :         }
     234             : 
     235           0 :         if( pParent->AddNamed( rFamily, rProperties, rName ) )
     236             :         {
     237           0 :             rFamily.mnCount++;
     238           0 :             bRet = sal_True;
     239           0 :         }
     240             :     }
     241             : 
     242           0 :     return bRet;
     243             : }
     244             : 
     245             : ///////////////////////////////////////////////////////////////////////////////
     246             : //
     247             : // Search for a array of XMLPropertyState ( vector< XMLPropertyState > ) in list
     248             : //
     249             : 
     250          28 : OUString SvXMLAutoStylePoolP_Impl::Find( sal_Int32 nFamily,
     251             :                                          const OUString& rParent,
     252             :                                          const vector< XMLPropertyState >& rProperties ) const
     253             : {
     254          28 :     OUString sName;
     255             : 
     256          28 :     XMLFamilyData_Impl aTemporary( nFamily );
     257             :     XMLFamilyDataList_Impl::const_iterator const iter =
     258          28 :         maFamilyList.find(aTemporary);
     259             :     OSL_ENSURE(iter != maFamilyList.end(),
     260             :             "SvXMLAutoStylePool_Impl::Find: unknown family");
     261             : 
     262          28 :     if (iter != maFamilyList.end())
     263             :     {
     264          28 :         XMLFamilyData_Impl const& rFamily = *iter;
     265             :         const SvXMLAutoStylePoolParentsP_Impl* pParents =
     266          28 :             rFamily.mpParentList;
     267             : 
     268          28 :         SvXMLAutoStylePoolParentP_Impl aTmp( rParent );
     269             :         SvXMLAutoStylePoolParentsP_Impl::const_iterator const it2 =
     270          28 :             pParents->find(&aTmp);
     271          28 :         if (it2 != pParents->end())
     272             :         {
     273          20 :             sName = (*it2)->Find( rFamily, rProperties );
     274          28 :         }
     275             :     }
     276             : 
     277          28 :     return sName;
     278             : }
     279             : 
     280             : ///////////////////////////////////////////////////////////////////////////////
     281             : //
     282             : // export
     283             : //
     284             : 
     285         136 : void SvXMLAutoStylePoolP_Impl::exportXML(
     286             :            sal_Int32 nFamily,
     287             :         const uno::Reference< ::com::sun::star::xml::sax::XDocumentHandler > &,
     288             :         const SvXMLUnitConverter&,
     289             :         const SvXMLNamespaceMap&,
     290             :         const SvXMLAutoStylePoolP *pAntiImpl) const
     291             : {
     292             :     // Get list of parents for current family (nFamily)
     293         136 :     XMLFamilyData_Impl aTmp( nFamily );
     294         136 :     XMLFamilyDataList_Impl::const_iterator aFind = maFamilyList.find(aTmp);
     295             :     DBG_ASSERT( aFind != maFamilyList.end(),
     296             :                 "SvXMLAutoStylePool_Impl::exportXML: unknown family" );
     297         136 :     if (aFind == maFamilyList.end())
     298             :         return;
     299             : 
     300         136 :     const XMLFamilyData_Impl &rFamily = *aFind;
     301         136 :     sal_uInt32 nCount = rFamily.mnCount;
     302             : 
     303         136 :     if (!nCount)
     304             :         return;
     305             : 
     306             :     /////////////////////////////////////////////////////////////////////////////////////
     307             :     // create, initialize and fill helper-structure (SvXMLAutoStylePoolProperties_Impl)
     308             :     // wich contains a parent-name and a SvXMLAutoStylePoolProperties_Impl
     309             :     //
     310             :     const SvXMLAutoStylePoolParentsP_Impl *pParents =
     311          24 :         rFamily.mpParentList;
     312             : 
     313             :     SvXMLAutoStylePoolPExport_Impl* aExpStyles =
     314          24 :         new SvXMLAutoStylePoolPExport_Impl[nCount];
     315             : 
     316             :     sal_uInt32 i;
     317          58 :     for( i=0; i < nCount; i++ )
     318             :     {
     319          34 :         aExpStyles[i].mpParent = 0;
     320          34 :         aExpStyles[i].mpProperties = 0;
     321             :     }
     322             : 
     323          48 :     for (size_t k = 0; k < pParents->size(); k++)
     324             :     {
     325          24 :         const SvXMLAutoStylePoolParentP_Impl *const pParent = (*pParents)[k];
     326          24 :         size_t nProperties = pParent->GetPropertiesList().size();
     327          58 :         for( size_t j = 0; j < nProperties; j++ )
     328             :         {
     329             :             const SvXMLAutoStylePoolPropertiesP_Impl* pProperties =
     330          34 :                 pParent->GetPropertiesList()[ j ];
     331          34 :             sal_uLong nPos = pProperties->GetPos();
     332             :             DBG_ASSERT( nPos < nCount,
     333             :                     "SvXMLAutoStylePool_Impl::exportXML: wrong position" );
     334          34 :             if( nPos < nCount )
     335             :             {
     336             :                 DBG_ASSERT( !aExpStyles[nPos].mpProperties,
     337             :                     "SvXMLAutoStylePool_Impl::exportXML: double position" );
     338          34 :                 aExpStyles[nPos].mpProperties = pProperties;
     339          34 :                 aExpStyles[nPos].mpParent = &pParent->GetParent();
     340             :             }
     341             :         }
     342             :     }
     343             : 
     344             :     /////////////////////////////////////////////////////////////////////////////////////
     345             :     //
     346             :     // create string to export for each XML-style. That means for each property-list
     347             :     //
     348          24 :     OUString aStrFamilyName = rFamily.maStrFamilyName;
     349             : 
     350          58 :     for( i=0; i<nCount; i++ )
     351             :     {
     352             :         DBG_ASSERT( aExpStyles[i].mpProperties,
     353             :                     "SvXMLAutoStylePool_Impl::exportXML: empty position" );
     354             : 
     355          34 :         if( aExpStyles[i].mpProperties )
     356             :         {
     357          34 :             GetExport().AddAttribute(
     358             :                 XML_NAMESPACE_STYLE, XML_NAME,
     359          68 :                 aExpStyles[i].mpProperties->GetName() );
     360             : 
     361          34 :             if( rFamily.bAsFamily )
     362             :             {
     363          18 :                 GetExport().AddAttribute(
     364          18 :                     XML_NAMESPACE_STYLE, XML_FAMILY, aStrFamilyName );
     365             :             }
     366             : 
     367          34 :             if( !aExpStyles[i].mpParent->isEmpty() )
     368             :             {
     369           6 :                 GetExport().AddAttribute(
     370             :                     XML_NAMESPACE_STYLE, XML_PARENT_STYLE_NAME,
     371           6 :                     GetExport().EncodeStyleName(
     372          18 :                         *aExpStyles[i].mpParent ) );
     373             :             }
     374             : 
     375          34 :             OUString sName;
     376          34 :             if( rFamily.bAsFamily )
     377          18 :                 sName = GetXMLToken(XML_STYLE);
     378             :             else
     379          16 :                 sName = rFamily.maStrFamilyName;
     380             : 
     381             :             pAntiImpl->exportStyleAttributes(
     382          34 :                 GetExport().GetAttrList(),
     383             :                 nFamily,
     384          34 :                 aExpStyles[i].mpProperties->GetProperties(),
     385          34 :                 *rFamily.mxMapper.get()
     386          34 :                     , GetExport().GetMM100UnitConverter(),
     387          34 :                     GetExport().GetNamespaceMap()
     388          68 :                 );
     389             : 
     390          34 :             SvXMLElementExport aElem( GetExport(),
     391             :                                       XML_NAMESPACE_STYLE, sName,
     392          34 :                                       sal_True, sal_True );
     393             : 
     394          34 :             sal_Int32 nStart(-1);
     395          34 :             sal_Int32 nEnd(-1);
     396          34 :             if (nFamily == XML_STYLE_FAMILY_PAGE_MASTER)
     397             :             {
     398          16 :                 nStart = 0;
     399          16 :                 sal_Int32 nIndex = 0;
     400             :                 UniReference< XMLPropertySetMapper > aPropMapper =
     401          16 :                     rFamily.mxMapper->getPropertySetMapper();
     402             :                 sal_Int16 nContextID;
     403        1232 :                 while(nIndex < aPropMapper->GetEntryCount() && nEnd == -1)
     404             :                 {
     405        1200 :                     nContextID = aPropMapper->GetEntryContextId( nIndex );
     406        1200 :                     if (nContextID && ((nContextID & CTF_PM_FLAGMASK) != XML_PM_CTF_START))
     407          16 :                         nEnd = nIndex;
     408        1200 :                     nIndex++;
     409             :                 }
     410          16 :                 if (nEnd == -1)
     411           0 :                     nEnd = nIndex;
     412             :             }
     413             : 
     414             :             rFamily.mxMapper->exportXML(
     415          34 :                 GetExport(),
     416          34 :                 aExpStyles[i].mpProperties->GetProperties(),
     417          34 :                 nStart, nEnd, XML_EXPORT_FLAG_IGN_WS );
     418             : 
     419             :             pAntiImpl->exportStyleContent(
     420          34 :                 GetExport().GetDocHandler(),
     421             :                 nFamily,
     422          34 :                 aExpStyles[i].mpProperties->GetProperties(),
     423          34 :                 *rFamily.mxMapper.get(),
     424          34 :                 GetExport().GetMM100UnitConverter(),
     425          34 :                 GetExport().GetNamespaceMap()
     426          68 :                 );
     427             :         }
     428             :     }
     429             : 
     430          24 :     delete[] aExpStyles;
     431             : }
     432             : 
     433           4 : void SvXMLAutoStylePoolP_Impl::ClearEntries()
     434             : {
     435          20 :     for(XMLFamilyDataList_Impl::iterator aI = maFamilyList.begin(); aI != maFamilyList.end(); ++aI)
     436          16 :         aI->ClearEntries();
     437           4 : }
     438             : 
     439             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10