LCOV - code coverage report
Current view: top level - xmloff/source/style - XMLPageExport.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 116 122 95.1 %
Date: 2014-04-11 Functions: 8 10 80.0 %
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 <xmloff/XMLPageExport.hxx>
      21             : #include <tools/debug.hxx>
      22             : #include <xmloff/xmlnmspe.hxx>
      23             : #include <xmloff/xmltoken.hxx>
      24             : #include <com/sun/star/style/XStyleFamiliesSupplier.hpp>
      25             : #include <com/sun/star/style/XStyle.hpp>
      26             : #include <com/sun/star/container/XNameContainer.hpp>
      27             : #include <com/sun/star/container/XIndexReplace.hpp>
      28             : #include <com/sun/star/beans/XPropertySet.hpp>
      29             : #include <xmloff/families.hxx>
      30             : #include <xmloff/xmlexp.hxx>
      31             : #include "PageMasterPropHdlFactory.hxx"
      32             : #include <xmloff/PageMasterStyleMap.hxx>
      33             : #include "PageMasterPropMapper.hxx"
      34             : #include "PageMasterExportPropMapper.hxx"
      35             : 
      36             : using namespace ::com::sun::star;
      37             : using namespace ::com::sun::star::uno;
      38             : using namespace ::com::sun::star::style;
      39             : using namespace ::com::sun::star::container;
      40             : using namespace ::com::sun::star::beans;
      41             : using namespace ::xmloff::token;
      42             : 
      43          61 : bool XMLPageExport::findPageMasterName( const OUString& rStyleName, OUString& rPMName ) const
      44             : {
      45         252 :     for( ::std::vector< XMLPageExportNameEntry >::const_iterator pEntry = aNameVector.begin();
      46         168 :             pEntry != aNameVector.end(); ++pEntry )
      47             :     {
      48          84 :         if( pEntry->sStyleName == rStyleName )
      49             :         {
      50          61 :             rPMName = pEntry->sPageMasterName;
      51          61 :             return true;
      52             :         }
      53             :     }
      54           0 :     return false;
      55             : }
      56             : 
      57          61 : void XMLPageExport::collectPageMasterAutoStyle(
      58             :         const Reference < XPropertySet > & rPropSet,
      59             :         OUString& rPageMasterName )
      60             : {
      61             :     DBG_ASSERT( xPageMasterPropSetMapper.is(), "page master family/XMLPageMasterPropSetMapper not found" );
      62          61 :     if( xPageMasterPropSetMapper.is() )
      63             :     {
      64          61 :         ::std::vector<XMLPropertyState> xPropStates = xPageMasterExportPropMapper->Filter( rPropSet );
      65          61 :         if( !xPropStates.empty())
      66             :         {
      67          61 :             OUString sParent;
      68          61 :             rPageMasterName = rExport.GetAutoStylePool()->Find( XML_STYLE_FAMILY_PAGE_MASTER, sParent, xPropStates );
      69          61 :             if (rPageMasterName.isEmpty())
      70          61 :                 rPageMasterName = rExport.GetAutoStylePool()->Add(XML_STYLE_FAMILY_PAGE_MASTER, sParent, xPropStates);
      71          61 :         }
      72             :     }
      73          61 : }
      74             : 
      75           0 : void XMLPageExport::exportMasterPageContent(
      76             :                 const Reference < XPropertySet > &,
      77             :                 bool /*bAutoStyles*/ )
      78             : {
      79             : 
      80           0 : }
      81             : 
      82         500 : bool XMLPageExport::exportStyle(
      83             :             const Reference< XStyle >& rStyle,
      84             :             bool bAutoStyles )
      85             : {
      86         500 :     Reference< XPropertySet > xPropSet( rStyle, UNO_QUERY );
      87        1000 :     Reference< XPropertySetInfo > xPropSetInfo = xPropSet->getPropertySetInfo();
      88             : 
      89             :     // Don't export styles that aren't existing really. This may be the
      90             :     // case for StarOffice Writer's pool styles.
      91         500 :     if( xPropSetInfo->hasPropertyByName( sIsPhysical ) )
      92             :     {
      93         426 :         Any aAny = xPropSet->getPropertyValue( sIsPhysical );
      94         426 :         if( !*(sal_Bool *)aAny.getValue() )
      95         378 :             return false;
      96             :     }
      97             : 
      98         122 :     if( bAutoStyles )
      99             :     {
     100          61 :         XMLPageExportNameEntry aEntry;
     101          61 :         collectPageMasterAutoStyle( xPropSet, aEntry.sPageMasterName );
     102          61 :         aEntry.sStyleName = rStyle->getName();
     103          61 :         aNameVector.push_back( aEntry );
     104             : 
     105          61 :         exportMasterPageContent( xPropSet, true );
     106             :     }
     107             :     else
     108             :     {
     109          61 :         OUString sName( rStyle->getName() );
     110          61 :         bool bEncoded = false;
     111          61 :         GetExport().AddAttribute( XML_NAMESPACE_STYLE, XML_NAME,
     112         122 :                           GetExport().EncodeStyleName( sName, &bEncoded ) );
     113             : 
     114          61 :         if ( xPropSetInfo->hasPropertyByName( "Hidden" ) )
     115             :         {
     116          61 :             uno::Any aValue = xPropSet->getPropertyValue( "Hidden" );
     117          61 :             sal_Bool bHidden = sal_False;
     118          61 :             if ( ( aValue >>= bHidden ) && bHidden && GetExport( ).getDefaultVersion( ) == SvtSaveOptions::ODFVER_LATEST )
     119           0 :                 GetExport( ).AddAttribute( XML_NAMESPACE_STYLE, XML_HIDDEN, "true" );
     120             :         }
     121             : 
     122          61 :         if( bEncoded )
     123           1 :             GetExport().AddAttribute( XML_NAMESPACE_STYLE, XML_DISPLAY_NAME,
     124           1 :                                    sName);
     125             : 
     126         122 :         OUString sPMName;
     127          61 :         if( findPageMasterName( sName, sPMName ) )
     128          61 :             GetExport().AddAttribute( XML_NAMESPACE_STYLE, XML_PAGE_LAYOUT_NAME, GetExport().EncodeStyleName( sPMName ) );
     129             : 
     130         122 :         Reference<XPropertySetInfo> xInfo = xPropSet->getPropertySetInfo();
     131          61 :         if ( xInfo.is() && xInfo->hasPropertyByName(sFollowStyle) )
     132             :         {
     133          24 :             OUString sNextName;
     134          24 :             xPropSet->getPropertyValue( sFollowStyle ) >>= sNextName;
     135             : 
     136          24 :             if( sName != sNextName && !sNextName.isEmpty() )
     137             :             {
     138           0 :                 GetExport().AddAttribute( XML_NAMESPACE_STYLE, XML_NEXT_STYLE_NAME,
     139           0 :                     GetExport().EncodeStyleName( sNextName ) );
     140          24 :             }
     141             :         }
     142             : 
     143          61 :         SvXMLElementExport aElem( GetExport(), XML_NAMESPACE_STYLE,
     144         122 :                                   XML_MASTER_PAGE, true, true );
     145             : 
     146         122 :         exportMasterPageContent( xPropSet, false );
     147             :     }
     148             : 
     149         622 :     return true;
     150             : }
     151             : 
     152          39 : XMLPageExport::XMLPageExport( SvXMLExport& rExp ) :
     153             :     rExport( rExp ),
     154             :     sIsPhysical( "IsPhysical" ),
     155          39 :     sFollowStyle( "FollowStyle" )
     156             : {
     157          39 :     xPageMasterPropHdlFactory = new XMLPageMasterPropHdlFactory;
     158          78 :     xPageMasterPropSetMapper = new XMLPageMasterPropSetMapper(
     159             :                                 (XMLPropertyMapEntry*) aXMLPageMasterStyleMap,
     160          78 :                                 xPageMasterPropHdlFactory, true );
     161          78 :     xPageMasterExportPropMapper = new XMLPageMasterExportPropMapper(
     162          78 :                                     xPageMasterPropSetMapper, rExp);
     163             : 
     164             :     rExport.GetAutoStylePool()->AddFamily( XML_STYLE_FAMILY_PAGE_MASTER, OUString( XML_STYLE_FAMILY_PAGE_MASTER_NAME ),
     165          39 :         xPageMasterExportPropMapper, OUString( XML_STYLE_FAMILY_PAGE_MASTER_PREFIX ), false );
     166             : 
     167          39 :     Reference< XStyleFamiliesSupplier > xFamiliesSupp( GetExport().GetModel(),
     168          39 :                                                        UNO_QUERY );
     169             :     DBG_ASSERT( xFamiliesSupp.is(),
     170             :                 "No XStyleFamiliesSupplier from XModel for export!" );
     171          39 :     if( xFamiliesSupp.is() )
     172             :     {
     173          39 :         Reference< XNameAccess > xFamilies( xFamiliesSupp->getStyleFamilies() );
     174             :         DBG_ASSERT( xFamiliesSupp.is(),
     175             :                     "getStyleFamilies() from XModel failed for export!" );
     176          39 :         if( xFamilies.is() )
     177             :         {
     178          39 :             const OUString aPageStyleName("PageStyles");
     179             : 
     180          39 :             if( xFamilies->hasByName( aPageStyleName ) )
     181             :             {
     182          39 :                 xPageStyles.set(xFamilies->getByName( aPageStyleName ),uno::UNO_QUERY);
     183             : 
     184             :                 DBG_ASSERT( xPageStyles.is(),
     185             :                             "Page Styles not found for export!" );
     186          39 :             }
     187          39 :         }
     188          39 :     }
     189          39 : }
     190             : 
     191          39 : XMLPageExport::~XMLPageExport()
     192             : {
     193          39 : }
     194             : 
     195          78 : void XMLPageExport::exportStyles( bool bUsed, bool bAutoStyles )
     196             : {
     197          78 :     if( xPageStyles.is() )
     198             :     {
     199          78 :         uno::Sequence< OUString> aSeq = xPageStyles->getElementNames();
     200          78 :         const OUString* pIter = aSeq.getConstArray();
     201          78 :         const OUString* pEnd   = pIter + aSeq.getLength();
     202         578 :         for(;pIter != pEnd;++pIter)
     203             :         {
     204         500 :             Reference< XStyle > xStyle(xPageStyles->getByName( *pIter ),uno::UNO_QUERY);
     205         500 :             if( !bUsed || xStyle->isInUse() )
     206         500 :                 exportStyle( xStyle, bAutoStyles );
     207         578 :         }
     208             :     }
     209          78 : }
     210             : 
     211          39 : void XMLPageExport::exportAutoStyles()
     212             : {
     213             :     rExport.GetAutoStylePool()->exportXML(XML_STYLE_FAMILY_PAGE_MASTER
     214          39 :         , rExport.GetDocHandler(), rExport.GetMM100UnitConverter(),
     215          39 :         rExport.GetNamespaceMap()
     216          39 :         );
     217          39 : }
     218             : 
     219          21 : void XMLPageExport::exportDefaultStyle()
     220             : {
     221          21 :     Reference < lang::XMultiServiceFactory > xFactory (GetExport().GetModel(), UNO_QUERY);
     222          21 :     if (xFactory.is())
     223             :     {
     224          21 :         OUString sTextDefaults ( "com.sun.star.text.Defaults" );
     225          42 :         Reference < XPropertySet > xPropSet (xFactory->createInstance ( sTextDefaults ), UNO_QUERY);
     226          21 :         if (xPropSet.is())
     227             :         {
     228             :             // <style:default-style ...>
     229          21 :             GetExport().CheckAttrList();
     230             : 
     231             :             ::std::vector< XMLPropertyState > xPropStates =
     232          21 :                 xPageMasterExportPropMapper->FilterDefaults( xPropSet );
     233             : 
     234          21 :             sal_Bool bExport = sal_False;
     235          42 :             UniReference < XMLPropertySetMapper > aPropMapper(xPageMasterExportPropMapper->getPropertySetMapper());
     236          50 :             for( ::std::vector< XMLPropertyState >::iterator aIter = xPropStates.begin(); aIter != xPropStates.end(); ++aIter )
     237             :             {
     238          36 :                 XMLPropertyState *pProp = &(*aIter);
     239          36 :                 sal_Int16 nContextId    = aPropMapper->GetEntryContextId( pProp->mnIndex );
     240          36 :                 if( nContextId == CTF_PM_STANDARD_MODE )
     241             :                 {
     242           7 :                     bExport = sal_True;
     243           7 :                     break;
     244             :                 }
     245             :             }
     246             : 
     247          21 :             if( bExport )
     248             :             {
     249             :                 assert(GetExport().getDefaultVersion()
     250             :                         >= SvtSaveOptions::ODFVER_012);
     251             : 
     252             :                 //<style:default-page-layout>
     253           7 :                 SvXMLElementExport aElem( GetExport(), XML_NAMESPACE_STYLE,
     254             :                                           XML_DEFAULT_PAGE_LAYOUT,
     255           7 :                                           true, true );
     256             : 
     257           7 :                 xPageMasterExportPropMapper->exportXML( GetExport(), xPropStates,
     258           7 :                                              XML_EXPORT_FLAG_IGN_WS );
     259          21 :             }
     260          21 :         }
     261          21 :     }
     262          21 : }
     263             : 
     264             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10