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