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