1*cdf0e10cSrcweir /************************************************************************* 2*cdf0e10cSrcweir * 3*cdf0e10cSrcweir * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4*cdf0e10cSrcweir * 5*cdf0e10cSrcweir * Copyright 2000, 2010 Oracle and/or its affiliates. 6*cdf0e10cSrcweir * 7*cdf0e10cSrcweir * OpenOffice.org - a multi-platform office productivity suite 8*cdf0e10cSrcweir * 9*cdf0e10cSrcweir * This file is part of OpenOffice.org. 10*cdf0e10cSrcweir * 11*cdf0e10cSrcweir * OpenOffice.org is free software: you can redistribute it and/or modify 12*cdf0e10cSrcweir * it under the terms of the GNU Lesser General Public License version 3 13*cdf0e10cSrcweir * only, as published by the Free Software Foundation. 14*cdf0e10cSrcweir * 15*cdf0e10cSrcweir * OpenOffice.org is distributed in the hope that it will be useful, 16*cdf0e10cSrcweir * but WITHOUT ANY WARRANTY; without even the implied warranty of 17*cdf0e10cSrcweir * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18*cdf0e10cSrcweir * GNU Lesser General Public License version 3 for more details 19*cdf0e10cSrcweir * (a copy is included in the LICENSE file that accompanied this code). 20*cdf0e10cSrcweir * 21*cdf0e10cSrcweir * You should have received a copy of the GNU Lesser General Public License 22*cdf0e10cSrcweir * version 3 along with OpenOffice.org. If not, see 23*cdf0e10cSrcweir * <http://www.openoffice.org/license.html> 24*cdf0e10cSrcweir * for a copy of the LGPLv3 License. 25*cdf0e10cSrcweir * 26*cdf0e10cSrcweir ************************************************************************/ 27*cdf0e10cSrcweir 28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 29*cdf0e10cSrcweir #include "precompiled_xmloff.hxx" 30*cdf0e10cSrcweir #include <xmloff/XMLPageExport.hxx> 31*cdf0e10cSrcweir #include <tools/debug.hxx> 32*cdf0e10cSrcweir #include "xmloff/xmlnmspe.hxx" 33*cdf0e10cSrcweir #include <xmloff/xmltoken.hxx> 34*cdf0e10cSrcweir #include <com/sun/star/style/XStyleFamiliesSupplier.hpp> 35*cdf0e10cSrcweir #include <com/sun/star/style/XStyle.hpp> 36*cdf0e10cSrcweir #include <com/sun/star/container/XNameContainer.hpp> 37*cdf0e10cSrcweir #include <com/sun/star/container/XIndexReplace.hpp> 38*cdf0e10cSrcweir #include <com/sun/star/beans/XPropertySet.hpp> 39*cdf0e10cSrcweir #include <xmloff/families.hxx> 40*cdf0e10cSrcweir #include <xmloff/xmlexp.hxx> 41*cdf0e10cSrcweir #include "PageMasterPropHdlFactory.hxx" 42*cdf0e10cSrcweir #ifndef _XMLOFF_PAGEMASTERSTYLEMAP_HXX 43*cdf0e10cSrcweir #include <xmloff/PageMasterStyleMap.hxx> 44*cdf0e10cSrcweir #endif 45*cdf0e10cSrcweir #ifndef _XMLOFF_PAGEMASTERPROPMAPPER_HXX 46*cdf0e10cSrcweir #include "PageMasterPropMapper.hxx" 47*cdf0e10cSrcweir #endif 48*cdf0e10cSrcweir #include "PageMasterExportPropMapper.hxx" 49*cdf0e10cSrcweir #include "PageMasterExportPropMapper.hxx" 50*cdf0e10cSrcweir 51*cdf0e10cSrcweir using ::rtl::OUString; 52*cdf0e10cSrcweir using ::rtl::OUStringBuffer; 53*cdf0e10cSrcweir 54*cdf0e10cSrcweir using namespace ::com::sun::star; 55*cdf0e10cSrcweir using namespace ::com::sun::star::uno; 56*cdf0e10cSrcweir using namespace ::com::sun::star::style; 57*cdf0e10cSrcweir using namespace ::com::sun::star::container; 58*cdf0e10cSrcweir using namespace ::com::sun::star::beans; 59*cdf0e10cSrcweir using namespace ::xmloff::token; 60*cdf0e10cSrcweir 61*cdf0e10cSrcweir 62*cdf0e10cSrcweir //______________________________________________________________________________ 63*cdf0e10cSrcweir 64*cdf0e10cSrcweir sal_Bool XMLPageExport::findPageMasterName( const OUString& rStyleName, OUString& rPMName ) const 65*cdf0e10cSrcweir { 66*cdf0e10cSrcweir for( ::std::vector< XMLPageExportNameEntry >::const_iterator pEntry = aNameVector.begin(); 67*cdf0e10cSrcweir pEntry != aNameVector.end(); pEntry++ ) 68*cdf0e10cSrcweir { 69*cdf0e10cSrcweir if( pEntry->sStyleName == rStyleName ) 70*cdf0e10cSrcweir { 71*cdf0e10cSrcweir rPMName = pEntry->sPageMasterName; 72*cdf0e10cSrcweir return sal_True; 73*cdf0e10cSrcweir } 74*cdf0e10cSrcweir } 75*cdf0e10cSrcweir return sal_False; 76*cdf0e10cSrcweir } 77*cdf0e10cSrcweir 78*cdf0e10cSrcweir void XMLPageExport::collectPageMasterAutoStyle( 79*cdf0e10cSrcweir const Reference < XPropertySet > & rPropSet, 80*cdf0e10cSrcweir OUString& rPageMasterName ) 81*cdf0e10cSrcweir { 82*cdf0e10cSrcweir DBG_ASSERT( xPageMasterPropSetMapper.is(), "page master family/XMLPageMasterPropSetMapper not found" ); 83*cdf0e10cSrcweir if( xPageMasterPropSetMapper.is() ) 84*cdf0e10cSrcweir { 85*cdf0e10cSrcweir ::std::vector<XMLPropertyState> xPropStates = xPageMasterExportPropMapper->Filter( rPropSet ); 86*cdf0e10cSrcweir if( !xPropStates.empty()) 87*cdf0e10cSrcweir { 88*cdf0e10cSrcweir OUString sParent; 89*cdf0e10cSrcweir rPageMasterName = rExport.GetAutoStylePool()->Find( XML_STYLE_FAMILY_PAGE_MASTER, sParent, xPropStates ); 90*cdf0e10cSrcweir if (!rPageMasterName.getLength()) 91*cdf0e10cSrcweir rPageMasterName = rExport.GetAutoStylePool()->Add(XML_STYLE_FAMILY_PAGE_MASTER, sParent, xPropStates); 92*cdf0e10cSrcweir } 93*cdf0e10cSrcweir } 94*cdf0e10cSrcweir } 95*cdf0e10cSrcweir 96*cdf0e10cSrcweir void XMLPageExport::exportMasterPageContent( 97*cdf0e10cSrcweir const Reference < XPropertySet > &, 98*cdf0e10cSrcweir sal_Bool /*bAutoStyles*/ ) 99*cdf0e10cSrcweir { 100*cdf0e10cSrcweir 101*cdf0e10cSrcweir } 102*cdf0e10cSrcweir 103*cdf0e10cSrcweir sal_Bool XMLPageExport::exportStyle( 104*cdf0e10cSrcweir const Reference< XStyle >& rStyle, 105*cdf0e10cSrcweir sal_Bool bAutoStyles ) 106*cdf0e10cSrcweir { 107*cdf0e10cSrcweir Reference< XPropertySet > xPropSet( rStyle, UNO_QUERY ); 108*cdf0e10cSrcweir Reference< XPropertySetInfo > xPropSetInfo = xPropSet->getPropertySetInfo(); 109*cdf0e10cSrcweir 110*cdf0e10cSrcweir // Don't export styles that aren't existing really. This may be the 111*cdf0e10cSrcweir // case for StarOffice Writer's pool styles. 112*cdf0e10cSrcweir if( xPropSetInfo->hasPropertyByName( sIsPhysical ) ) 113*cdf0e10cSrcweir { 114*cdf0e10cSrcweir Any aAny = xPropSet->getPropertyValue( sIsPhysical ); 115*cdf0e10cSrcweir if( !*(sal_Bool *)aAny.getValue() ) 116*cdf0e10cSrcweir return sal_False; 117*cdf0e10cSrcweir } 118*cdf0e10cSrcweir 119*cdf0e10cSrcweir if( bAutoStyles ) 120*cdf0e10cSrcweir { 121*cdf0e10cSrcweir XMLPageExportNameEntry aEntry; 122*cdf0e10cSrcweir collectPageMasterAutoStyle( xPropSet, aEntry.sPageMasterName ); 123*cdf0e10cSrcweir aEntry.sStyleName = rStyle->getName(); 124*cdf0e10cSrcweir aNameVector.push_back( aEntry ); 125*cdf0e10cSrcweir 126*cdf0e10cSrcweir exportMasterPageContent( xPropSet, sal_True ); 127*cdf0e10cSrcweir } 128*cdf0e10cSrcweir else 129*cdf0e10cSrcweir { 130*cdf0e10cSrcweir OUString sName( rStyle->getName() ); 131*cdf0e10cSrcweir sal_Bool bEncoded = sal_False; 132*cdf0e10cSrcweir GetExport().AddAttribute( XML_NAMESPACE_STYLE, XML_NAME, 133*cdf0e10cSrcweir GetExport().EncodeStyleName( sName, &bEncoded ) ); 134*cdf0e10cSrcweir 135*cdf0e10cSrcweir if( bEncoded ) 136*cdf0e10cSrcweir GetExport().AddAttribute( XML_NAMESPACE_STYLE, XML_DISPLAY_NAME, 137*cdf0e10cSrcweir sName); 138*cdf0e10cSrcweir 139*cdf0e10cSrcweir OUString sPMName; 140*cdf0e10cSrcweir if( findPageMasterName( sName, sPMName ) ) 141*cdf0e10cSrcweir GetExport().AddAttribute( XML_NAMESPACE_STYLE, XML_PAGE_LAYOUT_NAME, GetExport().EncodeStyleName( sPMName ) ); 142*cdf0e10cSrcweir 143*cdf0e10cSrcweir Reference<XPropertySetInfo> xInfo = xPropSet->getPropertySetInfo(); 144*cdf0e10cSrcweir if ( xInfo.is() && xInfo->hasPropertyByName(sFollowStyle) ) 145*cdf0e10cSrcweir { 146*cdf0e10cSrcweir OUString sNextName; 147*cdf0e10cSrcweir xPropSet->getPropertyValue( sFollowStyle ) >>= sNextName; 148*cdf0e10cSrcweir 149*cdf0e10cSrcweir if( sName != sNextName && sNextName.getLength() ) 150*cdf0e10cSrcweir { 151*cdf0e10cSrcweir GetExport().AddAttribute( XML_NAMESPACE_STYLE, XML_NEXT_STYLE_NAME, 152*cdf0e10cSrcweir GetExport().EncodeStyleName( sNextName ) ); 153*cdf0e10cSrcweir } 154*cdf0e10cSrcweir } 155*cdf0e10cSrcweir // OUString sPageMaster = GetExport().GetAutoStylePool()->Find( 156*cdf0e10cSrcweir // XML_STYLE_FAMILY_PAGE_MASTER, 157*cdf0e10cSrcweir // xPropSet ); 158*cdf0e10cSrcweir // if( sPageMaster.getLength() ) 159*cdf0e10cSrcweir // GetExport().AddAttribute( XML_NAMESPACE_STYLE, 160*cdf0e10cSrcweir // XML_PAGE_MASTER_NAME, 161*cdf0e10cSrcweir // sPageMaster ); 162*cdf0e10cSrcweir 163*cdf0e10cSrcweir SvXMLElementExport aElem( GetExport(), XML_NAMESPACE_STYLE, 164*cdf0e10cSrcweir XML_MASTER_PAGE, sal_True, sal_True ); 165*cdf0e10cSrcweir 166*cdf0e10cSrcweir exportMasterPageContent( xPropSet, sal_False ); 167*cdf0e10cSrcweir } 168*cdf0e10cSrcweir 169*cdf0e10cSrcweir return sal_True; 170*cdf0e10cSrcweir } 171*cdf0e10cSrcweir 172*cdf0e10cSrcweir XMLPageExport::XMLPageExport( SvXMLExport& rExp ) : 173*cdf0e10cSrcweir rExport( rExp ), 174*cdf0e10cSrcweir sIsPhysical( RTL_CONSTASCII_USTRINGPARAM( "IsPhysical" ) ), 175*cdf0e10cSrcweir sFollowStyle( RTL_CONSTASCII_USTRINGPARAM( "FollowStyle" ) ) 176*cdf0e10cSrcweir { 177*cdf0e10cSrcweir xPageMasterPropHdlFactory = new XMLPageMasterPropHdlFactory; 178*cdf0e10cSrcweir xPageMasterPropSetMapper = new XMLPageMasterPropSetMapper( 179*cdf0e10cSrcweir (XMLPropertyMapEntry*) aXMLPageMasterStyleMap, 180*cdf0e10cSrcweir xPageMasterPropHdlFactory ); 181*cdf0e10cSrcweir xPageMasterExportPropMapper = new XMLPageMasterExportPropMapper( 182*cdf0e10cSrcweir xPageMasterPropSetMapper, rExp); 183*cdf0e10cSrcweir 184*cdf0e10cSrcweir rExport.GetAutoStylePool()->AddFamily( XML_STYLE_FAMILY_PAGE_MASTER, OUString( RTL_CONSTASCII_USTRINGPARAM( XML_STYLE_FAMILY_PAGE_MASTER_NAME ) ), 185*cdf0e10cSrcweir xPageMasterExportPropMapper, OUString( RTL_CONSTASCII_USTRINGPARAM( XML_STYLE_FAMILY_PAGE_MASTER_PREFIX ) ), sal_False ); 186*cdf0e10cSrcweir 187*cdf0e10cSrcweir Reference< XStyleFamiliesSupplier > xFamiliesSupp( GetExport().GetModel(), 188*cdf0e10cSrcweir UNO_QUERY ); 189*cdf0e10cSrcweir DBG_ASSERT( xFamiliesSupp.is(), 190*cdf0e10cSrcweir "No XStyleFamiliesSupplier from XModel for export!" ); 191*cdf0e10cSrcweir if( xFamiliesSupp.is() ) 192*cdf0e10cSrcweir { 193*cdf0e10cSrcweir Reference< XNameAccess > xFamilies( xFamiliesSupp->getStyleFamilies() ); 194*cdf0e10cSrcweir DBG_ASSERT( xFamiliesSupp.is(), 195*cdf0e10cSrcweir "getStyleFamilies() from XModel failed for export!" ); 196*cdf0e10cSrcweir if( xFamilies.is() ) 197*cdf0e10cSrcweir { 198*cdf0e10cSrcweir const OUString aPageStyleName( 199*cdf0e10cSrcweir RTL_CONSTASCII_USTRINGPARAM( "PageStyles" )); 200*cdf0e10cSrcweir 201*cdf0e10cSrcweir if( xFamilies->hasByName( aPageStyleName ) ) 202*cdf0e10cSrcweir { 203*cdf0e10cSrcweir xPageStyles.set(xFamilies->getByName( aPageStyleName ),uno::UNO_QUERY); 204*cdf0e10cSrcweir 205*cdf0e10cSrcweir DBG_ASSERT( xPageStyles.is(), 206*cdf0e10cSrcweir "Page Styles not found for export!" ); 207*cdf0e10cSrcweir } 208*cdf0e10cSrcweir } 209*cdf0e10cSrcweir } 210*cdf0e10cSrcweir } 211*cdf0e10cSrcweir 212*cdf0e10cSrcweir XMLPageExport::~XMLPageExport() 213*cdf0e10cSrcweir { 214*cdf0e10cSrcweir } 215*cdf0e10cSrcweir 216*cdf0e10cSrcweir void XMLPageExport::exportStyles( sal_Bool bUsed, sal_Bool bAutoStyles ) 217*cdf0e10cSrcweir { 218*cdf0e10cSrcweir if( xPageStyles.is() ) 219*cdf0e10cSrcweir { 220*cdf0e10cSrcweir uno::Sequence< ::rtl::OUString> aSeq = xPageStyles->getElementNames(); 221*cdf0e10cSrcweir const ::rtl::OUString* pIter = aSeq.getConstArray(); 222*cdf0e10cSrcweir const ::rtl::OUString* pEnd = pIter + aSeq.getLength(); 223*cdf0e10cSrcweir for(;pIter != pEnd;++pIter) 224*cdf0e10cSrcweir { 225*cdf0e10cSrcweir Reference< XStyle > xStyle(xPageStyles->getByName( *pIter ),uno::UNO_QUERY); 226*cdf0e10cSrcweir if( !bUsed || xStyle->isInUse() ) 227*cdf0e10cSrcweir exportStyle( xStyle, bAutoStyles ); 228*cdf0e10cSrcweir } 229*cdf0e10cSrcweir } 230*cdf0e10cSrcweir } 231*cdf0e10cSrcweir 232*cdf0e10cSrcweir void XMLPageExport::exportAutoStyles() 233*cdf0e10cSrcweir { 234*cdf0e10cSrcweir rExport.GetAutoStylePool()->exportXML(XML_STYLE_FAMILY_PAGE_MASTER 235*cdf0e10cSrcweir , rExport.GetDocHandler(), rExport.GetMM100UnitConverter(), 236*cdf0e10cSrcweir rExport.GetNamespaceMap() 237*cdf0e10cSrcweir ); 238*cdf0e10cSrcweir } 239*cdf0e10cSrcweir 240*cdf0e10cSrcweir void XMLPageExport::exportDefaultStyle() 241*cdf0e10cSrcweir { 242*cdf0e10cSrcweir Reference < lang::XMultiServiceFactory > xFactory (GetExport().GetModel(), UNO_QUERY); 243*cdf0e10cSrcweir if (xFactory.is()) 244*cdf0e10cSrcweir { 245*cdf0e10cSrcweir OUString sTextDefaults ( RTL_CONSTASCII_USTRINGPARAM ( "com.sun.star.text.Defaults" ) ); 246*cdf0e10cSrcweir Reference < XPropertySet > xPropSet (xFactory->createInstance ( sTextDefaults ), UNO_QUERY); 247*cdf0e10cSrcweir if (xPropSet.is()) 248*cdf0e10cSrcweir { 249*cdf0e10cSrcweir // <style:default-style ...> 250*cdf0e10cSrcweir GetExport().CheckAttrList(); 251*cdf0e10cSrcweir 252*cdf0e10cSrcweir ::std::vector< XMLPropertyState > xPropStates = 253*cdf0e10cSrcweir xPageMasterExportPropMapper->FilterDefaults( xPropSet ); 254*cdf0e10cSrcweir 255*cdf0e10cSrcweir sal_Bool bExport = sal_False; 256*cdf0e10cSrcweir UniReference < XMLPropertySetMapper > aPropMapper(xPageMasterExportPropMapper->getPropertySetMapper()); 257*cdf0e10cSrcweir for( ::std::vector< XMLPropertyState >::iterator aIter = xPropStates.begin(); aIter != xPropStates.end(); ++aIter ) 258*cdf0e10cSrcweir { 259*cdf0e10cSrcweir XMLPropertyState *pProp = &(*aIter); 260*cdf0e10cSrcweir sal_Int16 nContextId = aPropMapper->GetEntryContextId( pProp->mnIndex ); 261*cdf0e10cSrcweir if( nContextId == CTF_PM_STANDARD_MODE ) 262*cdf0e10cSrcweir { 263*cdf0e10cSrcweir bExport = sal_True; 264*cdf0e10cSrcweir break; 265*cdf0e10cSrcweir } 266*cdf0e10cSrcweir } 267*cdf0e10cSrcweir 268*cdf0e10cSrcweir // if ( xPropStates.size() != 0 && 269*cdf0e10cSrcweir // ( xPropStates.size() != 1 || xPropStates[0].mnIndex != -1 ) ) 270*cdf0e10cSrcweir if( bExport ) 271*cdf0e10cSrcweir { 272*cdf0e10cSrcweir //<style:default-page-layout> 273*cdf0e10cSrcweir SvXMLElementExport aElem( GetExport(), XML_NAMESPACE_STYLE, 274*cdf0e10cSrcweir XML_DEFAULT_PAGE_LAYOUT, 275*cdf0e10cSrcweir sal_True, sal_True ); 276*cdf0e10cSrcweir 277*cdf0e10cSrcweir xPageMasterExportPropMapper->exportXML( GetExport(), xPropStates, 278*cdf0e10cSrcweir XML_EXPORT_FLAG_IGN_WS ); 279*cdf0e10cSrcweir } 280*cdf0e10cSrcweir } 281*cdf0e10cSrcweir } 282*cdf0e10cSrcweir } 283