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

Generated by: LCOV version 1.10