Bump for 3.6-28
[LibreOffice.git] / xmloff / source / style / XMLPageExport.cxx
blob6d7f410107c1070687f35fbc0ed92c1006761b34
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * Copyright 2000, 2010 Oracle and/or its affiliates.
8 * OpenOffice.org - a multi-platform office productivity suite
10 * This file is part of OpenOffice.org.
12 * OpenOffice.org is free software: you can redistribute it and/or modify
13 * it under the terms of the GNU Lesser General Public License version 3
14 * only, as published by the Free Software Foundation.
16 * OpenOffice.org is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Lesser General Public License version 3 for more details
20 * (a copy is included in the LICENSE file that accompanied this code).
22 * You should have received a copy of the GNU Lesser General Public License
23 * version 3 along with OpenOffice.org. If not, see
24 * <http://www.openoffice.org/license.html>
25 * for a copy of the LGPLv3 License.
27 ************************************************************************/
29 #include <xmloff/XMLPageExport.hxx>
30 #include <tools/debug.hxx>
31 #include "xmloff/xmlnmspe.hxx"
32 #include <xmloff/xmltoken.hxx>
33 #include <com/sun/star/style/XStyleFamiliesSupplier.hpp>
34 #include <com/sun/star/style/XStyle.hpp>
35 #include <com/sun/star/container/XNameContainer.hpp>
36 #include <com/sun/star/container/XIndexReplace.hpp>
37 #include <com/sun/star/beans/XPropertySet.hpp>
38 #include <xmloff/families.hxx>
39 #include <xmloff/xmlexp.hxx>
40 #include "PageMasterPropHdlFactory.hxx"
41 #include <xmloff/PageMasterStyleMap.hxx>
42 #include "PageMasterPropMapper.hxx"
43 #include "PageMasterExportPropMapper.hxx"
45 using ::rtl::OUString;
46 using ::rtl::OUStringBuffer;
48 using namespace ::com::sun::star;
49 using namespace ::com::sun::star::uno;
50 using namespace ::com::sun::star::style;
51 using namespace ::com::sun::star::container;
52 using namespace ::com::sun::star::beans;
53 using namespace ::xmloff::token;
56 //______________________________________________________________________________
58 sal_Bool XMLPageExport::findPageMasterName( const OUString& rStyleName, OUString& rPMName ) const
60 for( ::std::vector< XMLPageExportNameEntry >::const_iterator pEntry = aNameVector.begin();
61 pEntry != aNameVector.end(); ++pEntry )
63 if( pEntry->sStyleName == rStyleName )
65 rPMName = pEntry->sPageMasterName;
66 return sal_True;
69 return sal_False;
72 void XMLPageExport::collectPageMasterAutoStyle(
73 const Reference < XPropertySet > & rPropSet,
74 OUString& rPageMasterName )
76 DBG_ASSERT( xPageMasterPropSetMapper.is(), "page master family/XMLPageMasterPropSetMapper not found" );
77 if( xPageMasterPropSetMapper.is() )
79 ::std::vector<XMLPropertyState> xPropStates = xPageMasterExportPropMapper->Filter( rPropSet );
80 if( !xPropStates.empty())
82 OUString sParent;
83 rPageMasterName = rExport.GetAutoStylePool()->Find( XML_STYLE_FAMILY_PAGE_MASTER, sParent, xPropStates );
84 if (rPageMasterName.isEmpty())
85 rPageMasterName = rExport.GetAutoStylePool()->Add(XML_STYLE_FAMILY_PAGE_MASTER, sParent, xPropStates);
90 void XMLPageExport::exportMasterPageContent(
91 const Reference < XPropertySet > &,
92 sal_Bool /*bAutoStyles*/ )
97 sal_Bool XMLPageExport::exportStyle(
98 const Reference< XStyle >& rStyle,
99 sal_Bool bAutoStyles )
101 Reference< XPropertySet > xPropSet( rStyle, UNO_QUERY );
102 Reference< XPropertySetInfo > xPropSetInfo = xPropSet->getPropertySetInfo();
104 // Don't export styles that aren't existing really. This may be the
105 // case for StarOffice Writer's pool styles.
106 if( xPropSetInfo->hasPropertyByName( sIsPhysical ) )
108 Any aAny = xPropSet->getPropertyValue( sIsPhysical );
109 if( !*(sal_Bool *)aAny.getValue() )
110 return sal_False;
113 if( bAutoStyles )
115 XMLPageExportNameEntry aEntry;
116 collectPageMasterAutoStyle( xPropSet, aEntry.sPageMasterName );
117 aEntry.sStyleName = rStyle->getName();
118 aNameVector.push_back( aEntry );
120 exportMasterPageContent( xPropSet, sal_True );
122 else
124 OUString sName( rStyle->getName() );
125 sal_Bool bEncoded = sal_False;
126 GetExport().AddAttribute( XML_NAMESPACE_STYLE, XML_NAME,
127 GetExport().EncodeStyleName( sName, &bEncoded ) );
129 if( bEncoded )
130 GetExport().AddAttribute( XML_NAMESPACE_STYLE, XML_DISPLAY_NAME,
131 sName);
133 OUString sPMName;
134 if( findPageMasterName( sName, sPMName ) )
135 GetExport().AddAttribute( XML_NAMESPACE_STYLE, XML_PAGE_LAYOUT_NAME, GetExport().EncodeStyleName( sPMName ) );
137 Reference<XPropertySetInfo> xInfo = xPropSet->getPropertySetInfo();
138 if ( xInfo.is() && xInfo->hasPropertyByName(sFollowStyle) )
140 OUString sNextName;
141 xPropSet->getPropertyValue( sFollowStyle ) >>= sNextName;
143 if( sName != sNextName && !sNextName.isEmpty() )
145 GetExport().AddAttribute( XML_NAMESPACE_STYLE, XML_NEXT_STYLE_NAME,
146 GetExport().EncodeStyleName( sNextName ) );
150 SvXMLElementExport aElem( GetExport(), XML_NAMESPACE_STYLE,
151 XML_MASTER_PAGE, sal_True, sal_True );
153 exportMasterPageContent( xPropSet, sal_False );
156 return sal_True;
159 XMLPageExport::XMLPageExport( SvXMLExport& rExp ) :
160 rExport( rExp ),
161 sIsPhysical( RTL_CONSTASCII_USTRINGPARAM( "IsPhysical" ) ),
162 sFollowStyle( RTL_CONSTASCII_USTRINGPARAM( "FollowStyle" ) )
164 xPageMasterPropHdlFactory = new XMLPageMasterPropHdlFactory;
165 xPageMasterPropSetMapper = new XMLPageMasterPropSetMapper(
166 (XMLPropertyMapEntry*) aXMLPageMasterStyleMap,
167 xPageMasterPropHdlFactory );
168 xPageMasterExportPropMapper = new XMLPageMasterExportPropMapper(
169 xPageMasterPropSetMapper, rExp);
171 rExport.GetAutoStylePool()->AddFamily( XML_STYLE_FAMILY_PAGE_MASTER, OUString( RTL_CONSTASCII_USTRINGPARAM( XML_STYLE_FAMILY_PAGE_MASTER_NAME ) ),
172 xPageMasterExportPropMapper, OUString( RTL_CONSTASCII_USTRINGPARAM( XML_STYLE_FAMILY_PAGE_MASTER_PREFIX ) ), sal_False );
174 Reference< XStyleFamiliesSupplier > xFamiliesSupp( GetExport().GetModel(),
175 UNO_QUERY );
176 DBG_ASSERT( xFamiliesSupp.is(),
177 "No XStyleFamiliesSupplier from XModel for export!" );
178 if( xFamiliesSupp.is() )
180 Reference< XNameAccess > xFamilies( xFamiliesSupp->getStyleFamilies() );
181 DBG_ASSERT( xFamiliesSupp.is(),
182 "getStyleFamilies() from XModel failed for export!" );
183 if( xFamilies.is() )
185 const OUString aPageStyleName(
186 RTL_CONSTASCII_USTRINGPARAM( "PageStyles" ));
188 if( xFamilies->hasByName( aPageStyleName ) )
190 xPageStyles.set(xFamilies->getByName( aPageStyleName ),uno::UNO_QUERY);
192 DBG_ASSERT( xPageStyles.is(),
193 "Page Styles not found for export!" );
199 XMLPageExport::~XMLPageExport()
203 void XMLPageExport::exportStyles( sal_Bool bUsed, sal_Bool bAutoStyles )
205 if( xPageStyles.is() )
207 uno::Sequence< ::rtl::OUString> aSeq = xPageStyles->getElementNames();
208 const ::rtl::OUString* pIter = aSeq.getConstArray();
209 const ::rtl::OUString* pEnd = pIter + aSeq.getLength();
210 for(;pIter != pEnd;++pIter)
212 Reference< XStyle > xStyle(xPageStyles->getByName( *pIter ),uno::UNO_QUERY);
213 if( !bUsed || xStyle->isInUse() )
214 exportStyle( xStyle, bAutoStyles );
219 void XMLPageExport::exportAutoStyles()
221 rExport.GetAutoStylePool()->exportXML(XML_STYLE_FAMILY_PAGE_MASTER
222 , rExport.GetDocHandler(), rExport.GetMM100UnitConverter(),
223 rExport.GetNamespaceMap()
227 void XMLPageExport::exportDefaultStyle()
229 Reference < lang::XMultiServiceFactory > xFactory (GetExport().GetModel(), UNO_QUERY);
230 if (xFactory.is())
232 OUString sTextDefaults ( RTL_CONSTASCII_USTRINGPARAM ( "com.sun.star.text.Defaults" ) );
233 Reference < XPropertySet > xPropSet (xFactory->createInstance ( sTextDefaults ), UNO_QUERY);
234 if (xPropSet.is())
236 // <style:default-style ...>
237 GetExport().CheckAttrList();
239 ::std::vector< XMLPropertyState > xPropStates =
240 xPageMasterExportPropMapper->FilterDefaults( xPropSet );
242 sal_Bool bExport = sal_False;
243 UniReference < XMLPropertySetMapper > aPropMapper(xPageMasterExportPropMapper->getPropertySetMapper());
244 for( ::std::vector< XMLPropertyState >::iterator aIter = xPropStates.begin(); aIter != xPropStates.end(); ++aIter )
246 XMLPropertyState *pProp = &(*aIter);
247 sal_Int16 nContextId = aPropMapper->GetEntryContextId( pProp->mnIndex );
248 if( nContextId == CTF_PM_STANDARD_MODE )
250 bExport = sal_True;
251 break;
255 if( bExport )
257 assert(GetExport().getDefaultVersion()
258 >= SvtSaveOptions::ODFVER_012);
260 //<style:default-page-layout>
261 SvXMLElementExport aElem( GetExport(), XML_NAMESPACE_STYLE,
262 XML_DEFAULT_PAGE_LAYOUT,
263 sal_True, sal_True );
265 xPageMasterExportPropMapper->exportXML( GetExport(), xPropStates,
266 XML_EXPORT_FLAG_IGN_WS );
272 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */