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

Generated by: LCOV version 1.10