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-27 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          12 : SvXMLAutoStylePoolP_Impl::SvXMLAutoStylePoolP_Impl( SvXMLExport& rExp)
      50          12 :     :   rExport( rExp )
      51             : {
      52          12 : }
      53             : 
      54          12 : SvXMLAutoStylePoolP_Impl::~SvXMLAutoStylePoolP_Impl()
      55             : {
      56          12 : }
      57             : 
      58             : ///////////////////////////////////////////////////////////////////////////////
      59             : //
      60             : // Adds stylefamily-informations to sorted list
      61             : //
      62             : 
      63         120 : 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         120 :     sal_uInt16 nExportFlags = GetExport().getExportFlags();
      72         120 :     sal_Bool bStylesOnly = (nExportFlags & EXPORT_STYLES) != 0 && (nExportFlags & EXPORT_CONTENT) == 0;
      73             : 
      74         120 :     OUString aPrefix( rStrPrefix );
      75         120 :     if( bStylesOnly )
      76             :     {
      77          52 :         aPrefix = OUString( 'M' );
      78          52 :         aPrefix += rStrPrefix;
      79             :     }
      80             : 
      81         120 :     XMLFamilyData_Impl *pFamily = new XMLFamilyData_Impl( nFamily, rStrName, rMapper, aPrefix, bAsFamily );
      82         120 :     maFamilyList.insert(pFamily);
      83         120 : }
      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         666 : void SvXMLAutoStylePoolP_Impl::RegisterName( sal_Int32 nFamily, const OUString& rName )
     101             : {
     102         666 :     XMLFamilyData_Impl aTmp( nFamily );
     103         666 :     XMLFamilyDataList_Impl::iterator aFind = maFamilyList.find(aTmp);
     104             :     DBG_ASSERT( aFind != maFamilyList.end(),
     105             :                 "SvXMLAutoStylePool_Impl::RegisterName: unknown family" );
     106         666 :     if (aFind != maFamilyList.end())
     107         666 :         aFind->mpNameList->insert(rName);
     108         666 : }
     109             : 
     110             : ///////////////////////////////////////////////////////////////////////////////
     111             : //
     112             : // Retrieve the list of registered names
     113             : //
     114             : 
     115           4 : void SvXMLAutoStylePoolP_Impl::GetRegisteredNames(
     116             :     uno::Sequence<sal_Int32>& rFamilies,
     117             :     uno::Sequence<OUString>& rNames )
     118             : {
     119             :     // collect registered names + families
     120           4 :     vector<sal_Int32> aFamilies;
     121           4 :     vector<OUString> aNames;
     122             : 
     123             :     // iterate over families
     124          34 :     for(XMLFamilyDataList_Impl::iterator aJ = maFamilyList.begin(); aJ != maFamilyList.end(); ++aJ)
     125             :     {
     126          30 :         XMLFamilyData_Impl &rFamily = *aJ;
     127             : 
     128             :         // iterate over names
     129          30 :         SvXMLAutoStylePoolNamesP_Impl* pNames = rFamily.mpNameList;
     130          30 :         if (!pNames)
     131           0 :             continue;
     132         362 :         for (SvXMLAutoStylePoolNamesP_Impl::const_iterator aI = pNames->begin(); aI != pNames->end(); ++aI)
     133             :         {
     134         332 :             aFamilies.push_back( rFamily.mnFamily );
     135         332 :             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           4 :     rFamilies.realloc( aFamilies.size() );
     143           4 :     std::copy( aFamilies.begin(), aFamilies.end(), rFamilies.getArray() );
     144             : 
     145           4 :     rNames.realloc( aNames.size() );
     146           4 :     std::copy( aNames.begin(), aNames.end(), rNames.getArray() );
     147           4 : }
     148             : 
     149             : ///////////////////////////////////////////////////////////////////////////////
     150             : //
     151             : // Adds a array of XMLPropertyState ( vector< XMLPropertyState > ) to list
     152             : // if not added, yet.
     153             : //
     154             : 
     155          17 : 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          17 :     sal_Bool bRet(sal_False);
     162             : 
     163          17 :     XMLFamilyData_Impl aTemporary( nFamily );
     164          17 :     XMLFamilyDataList_Impl::iterator aFind = maFamilyList.find(aTemporary);
     165             :     DBG_ASSERT(aFind != maFamilyList.end(), "SvXMLAutoStylePool_Impl::Add: unknown family");
     166             : 
     167          17 :     if (aFind != maFamilyList.end())
     168             :     {
     169          17 :         XMLFamilyData_Impl &rFamily = *aFind;
     170             : 
     171          17 :         SvXMLAutoStylePoolParentP_Impl aTmp( rParent );
     172          17 :         SvXMLAutoStylePoolParentP_Impl *pParent = 0;
     173             : 
     174          17 :         SvXMLAutoStylePoolParentsP_Impl *pParents = rFamily.mpParentList;
     175             :         SvXMLAutoStylePoolParentsP_Impl::const_iterator const it2 =
     176          17 :             pParents->find(&aTmp);
     177          17 :         if (it2 != pParents->end())
     178             :         {
     179           5 :             pParent = *it2;
     180             :         }
     181             :         else
     182             :         {
     183          12 :             pParent = new SvXMLAutoStylePoolParentP_Impl( rParent );
     184          12 :             pParents->insert( pParent );
     185             :         }
     186             : 
     187          17 :         if( pParent->Add( rFamily, rProperties, rName, bDontSeek ) )
     188             :         {
     189          17 :             rFamily.mnCount++;
     190          17 :             bRet = sal_True;
     191             :         }
     192             : 
     193          17 :         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          17 :         }
     200             :     }
     201             : 
     202          17 :     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          14 : OUString SvXMLAutoStylePoolP_Impl::Find( sal_Int32 nFamily,
     251             :                                          const OUString& rParent,
     252             :                                          const vector< XMLPropertyState >& rProperties ) const
     253             : {
     254          14 :     OUString sName;
     255             : 
     256          14 :     XMLFamilyData_Impl aTemporary( nFamily );
     257             :     XMLFamilyDataList_Impl::const_iterator const iter =
     258          14 :         maFamilyList.find(aTemporary);
     259             :     OSL_ENSURE(iter != maFamilyList.end(),
     260             :             "SvXMLAutoStylePool_Impl::Find: unknown family");
     261             : 
     262          14 :     if (iter != maFamilyList.end())
     263             :     {
     264          14 :         XMLFamilyData_Impl const& rFamily = *iter;
     265             :         const SvXMLAutoStylePoolParentsP_Impl* pParents =
     266          14 :             rFamily.mpParentList;
     267             : 
     268          14 :         SvXMLAutoStylePoolParentP_Impl aTmp( rParent );
     269             :         SvXMLAutoStylePoolParentsP_Impl::const_iterator const it2 =
     270          14 :             pParents->find(&aTmp);
     271          14 :         if (it2 != pParents->end())
     272             :         {
     273          10 :             sName = (*it2)->Find( rFamily, rProperties );
     274          14 :         }
     275             :     }
     276             : 
     277          14 :     return sName;
     278             : }
     279             : 
     280             : ///////////////////////////////////////////////////////////////////////////////
     281             : //
     282             : // export
     283             : //
     284             : 
     285          68 : 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          68 :     XMLFamilyData_Impl aTmp( nFamily );
     294          68 :     XMLFamilyDataList_Impl::const_iterator aFind = maFamilyList.find(aTmp);
     295             :     DBG_ASSERT( aFind != maFamilyList.end(),
     296             :                 "SvXMLAutoStylePool_Impl::exportXML: unknown family" );
     297          68 :     if (aFind == maFamilyList.end())
     298             :         return;
     299             : 
     300          68 :     const XMLFamilyData_Impl &rFamily = *aFind;
     301          68 :     sal_uInt32 nCount = rFamily.mnCount;
     302             : 
     303          68 :     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          12 :         rFamily.mpParentList;
     312             : 
     313             :     SvXMLAutoStylePoolPExport_Impl* aExpStyles =
     314          12 :         new SvXMLAutoStylePoolPExport_Impl[nCount];
     315             : 
     316             :     sal_uInt32 i;
     317          29 :     for( i=0; i < nCount; i++ )
     318             :     {
     319          17 :         aExpStyles[i].mpParent = 0;
     320          17 :         aExpStyles[i].mpProperties = 0;
     321             :     }
     322             : 
     323          24 :     for (size_t k = 0; k < pParents->size(); k++)
     324             :     {
     325          12 :         const SvXMLAutoStylePoolParentP_Impl *const pParent = (*pParents)[k];
     326          12 :         size_t nProperties = pParent->GetPropertiesList().size();
     327          29 :         for( size_t j = 0; j < nProperties; j++ )
     328             :         {
     329             :             const SvXMLAutoStylePoolPropertiesP_Impl* pProperties =
     330          17 :                 pParent->GetPropertiesList()[ j ];
     331          17 :             sal_uLong nPos = pProperties->GetPos();
     332             :             DBG_ASSERT( nPos < nCount,
     333             :                     "SvXMLAutoStylePool_Impl::exportXML: wrong position" );
     334          17 :             if( nPos < nCount )
     335             :             {
     336             :                 DBG_ASSERT( !aExpStyles[nPos].mpProperties,
     337             :                     "SvXMLAutoStylePool_Impl::exportXML: double position" );
     338          17 :                 aExpStyles[nPos].mpProperties = pProperties;
     339          17 :                 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          12 :     OUString aStrFamilyName = rFamily.maStrFamilyName;
     349             : 
     350          29 :     for( i=0; i<nCount; i++ )
     351             :     {
     352             :         DBG_ASSERT( aExpStyles[i].mpProperties,
     353             :                     "SvXMLAutoStylePool_Impl::exportXML: empty position" );
     354             : 
     355          17 :         if( aExpStyles[i].mpProperties )
     356             :         {
     357          17 :             GetExport().AddAttribute(
     358             :                 XML_NAMESPACE_STYLE, XML_NAME,
     359          34 :                 aExpStyles[i].mpProperties->GetName() );
     360             : 
     361          17 :             if( rFamily.bAsFamily )
     362             :             {
     363           9 :                 GetExport().AddAttribute(
     364           9 :                     XML_NAMESPACE_STYLE, XML_FAMILY, aStrFamilyName );
     365             :             }
     366             : 
     367          17 :             if( !aExpStyles[i].mpParent->isEmpty() )
     368             :             {
     369           3 :                 GetExport().AddAttribute(
     370             :                     XML_NAMESPACE_STYLE, XML_PARENT_STYLE_NAME,
     371           3 :                     GetExport().EncodeStyleName(
     372           9 :                         *aExpStyles[i].mpParent ) );
     373             :             }
     374             : 
     375          17 :             OUString sName;
     376          17 :             if( rFamily.bAsFamily )
     377           9 :                 sName = GetXMLToken(XML_STYLE);
     378             :             else
     379           8 :                 sName = rFamily.maStrFamilyName;
     380             : 
     381             :             pAntiImpl->exportStyleAttributes(
     382          17 :                 GetExport().GetAttrList(),
     383             :                 nFamily,
     384          17 :                 aExpStyles[i].mpProperties->GetProperties(),
     385          17 :                 *rFamily.mxMapper.get()
     386          17 :                     , GetExport().GetMM100UnitConverter(),
     387          17 :                     GetExport().GetNamespaceMap()
     388          34 :                 );
     389             : 
     390          17 :             SvXMLElementExport aElem( GetExport(),
     391             :                                       XML_NAMESPACE_STYLE, sName,
     392          17 :                                       sal_True, sal_True );
     393             : 
     394          17 :             sal_Int32 nStart(-1);
     395          17 :             sal_Int32 nEnd(-1);
     396          17 :             if (nFamily == XML_STYLE_FAMILY_PAGE_MASTER)
     397             :             {
     398           8 :                 nStart = 0;
     399           8 :                 sal_Int32 nIndex = 0;
     400             :                 UniReference< XMLPropertySetMapper > aPropMapper =
     401           8 :                     rFamily.mxMapper->getPropertySetMapper();
     402             :                 sal_Int16 nContextID;
     403         616 :                 while(nIndex < aPropMapper->GetEntryCount() && nEnd == -1)
     404             :                 {
     405         600 :                     nContextID = aPropMapper->GetEntryContextId( nIndex );
     406         600 :                     if (nContextID && ((nContextID & CTF_PM_FLAGMASK) != XML_PM_CTF_START))
     407           8 :                         nEnd = nIndex;
     408         600 :                     nIndex++;
     409             :                 }
     410           8 :                 if (nEnd == -1)
     411           0 :                     nEnd = nIndex;
     412             :             }
     413             : 
     414             :             rFamily.mxMapper->exportXML(
     415          17 :                 GetExport(),
     416          17 :                 aExpStyles[i].mpProperties->GetProperties(),
     417          17 :                 nStart, nEnd, XML_EXPORT_FLAG_IGN_WS );
     418             : 
     419             :             pAntiImpl->exportStyleContent(
     420          17 :                 GetExport().GetDocHandler(),
     421             :                 nFamily,
     422          17 :                 aExpStyles[i].mpProperties->GetProperties(),
     423          17 :                 *rFamily.mxMapper.get(),
     424          17 :                 GetExport().GetMM100UnitConverter(),
     425          17 :                 GetExport().GetNamespaceMap()
     426          34 :                 );
     427             :         }
     428             :     }
     429             : 
     430          12 :     delete[] aExpStyles;
     431             : }
     432             : 
     433           2 : void SvXMLAutoStylePoolP_Impl::ClearEntries()
     434             : {
     435          10 :     for(XMLFamilyDataList_Impl::iterator aI = maFamilyList.begin(); aI != maFamilyList.end(); ++aI)
     436           8 :         aI->ClearEntries();
     437           2 : }
     438             : 
     439             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10