xref: /AOO41X/main/xmloff/source/style/styleexp.cxx (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
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 <tools/debug.hxx>
31*cdf0e10cSrcweir #ifndef _SVSTDARR_STRINGSSORTDTOR_DECL
32*cdf0e10cSrcweir #define _SVSTDARR_STRINGSSORTDTOR
33*cdf0e10cSrcweir #include <svl/svstdarr.hxx>
34*cdf0e10cSrcweir #endif
35*cdf0e10cSrcweir #include <xmloff/nmspmap.hxx>
36*cdf0e10cSrcweir #include "xmloff/xmlnmspe.hxx"
37*cdf0e10cSrcweir #include <xmloff/xmltoken.hxx>
38*cdf0e10cSrcweir #ifndef _XMLOFF_XMLITMAP_HXX
39*cdf0e10cSrcweir //#include "xmlitmap.hxx"
40*cdf0e10cSrcweir #endif
41*cdf0e10cSrcweir #include <xmloff/xmluconv.hxx>
42*cdf0e10cSrcweir #include <xmloff/attrlist.hxx>
43*cdf0e10cSrcweir #include <xmloff/xmlprmap.hxx>
44*cdf0e10cSrcweir #include <xmloff/xmlexppr.hxx>
45*cdf0e10cSrcweir #include <com/sun/star/xml/sax/XExtendedDocumentHandler.hpp>
46*cdf0e10cSrcweir #include <com/sun/star/frame/XModel.hpp>
47*cdf0e10cSrcweir #include <com/sun/star/style/XStyleFamiliesSupplier.hpp>
48*cdf0e10cSrcweir #include <com/sun/star/style/XStyle.hpp>
49*cdf0e10cSrcweir #include <com/sun/star/container/XNameContainer.hpp>
50*cdf0e10cSrcweir #include <com/sun/star/beans/XPropertySet.hpp>
51*cdf0e10cSrcweir #include <com/sun/star/beans/XPropertyState.hpp>
52*cdf0e10cSrcweir #ifndef _COM_SUN_STAR_DOCUMENT_XEVENTSSUPPLIER_HPP
53*cdf0e10cSrcweir #include <com/sun/star/document/XEventsSupplier.hpp>
54*cdf0e10cSrcweir #endif
55*cdf0e10cSrcweir #include <com/sun/star/text/XChapterNumberingSupplier.hpp>
56*cdf0e10cSrcweir #include <xmloff/xmlaustp.hxx>
57*cdf0e10cSrcweir #ifndef _XMLOFF_STYLEEXP_HXX
58*cdf0e10cSrcweir #include <xmloff/styleexp.hxx>
59*cdf0e10cSrcweir #endif
60*cdf0e10cSrcweir #include <xmloff/xmlexp.hxx>
61*cdf0e10cSrcweir #include <xmloff/XMLEventExport.hxx>
62*cdf0e10cSrcweir 
63*cdf0e10cSrcweir using ::rtl::OUString;
64*cdf0e10cSrcweir using ::rtl::OUStringBuffer;
65*cdf0e10cSrcweir 
66*cdf0e10cSrcweir using namespace ::com::sun::star;
67*cdf0e10cSrcweir using namespace ::com::sun::star::uno;
68*cdf0e10cSrcweir using namespace ::com::sun::star::style;
69*cdf0e10cSrcweir using namespace ::com::sun::star::container;
70*cdf0e10cSrcweir using namespace ::com::sun::star::beans;
71*cdf0e10cSrcweir using namespace ::com::sun::star::text;
72*cdf0e10cSrcweir using namespace ::xmloff::token;
73*cdf0e10cSrcweir 
74*cdf0e10cSrcweir using ::com::sun::star::document::XEventsSupplier;
75*cdf0e10cSrcweir 
76*cdf0e10cSrcweir XMLStyleExport::XMLStyleExport(
77*cdf0e10cSrcweir 		SvXMLExport& rExp,
78*cdf0e10cSrcweir 		const ::rtl::OUString& rPoolStyleName,
79*cdf0e10cSrcweir 		SvXMLAutoStylePoolP *pAutoStyleP ) :
80*cdf0e10cSrcweir 	rExport( rExp ),
81*cdf0e10cSrcweir 	sIsPhysical( RTL_CONSTASCII_USTRINGPARAM( "IsPhysical" ) ),
82*cdf0e10cSrcweir 	sIsAutoUpdate( RTL_CONSTASCII_USTRINGPARAM( "IsAutoUpdate" ) ),
83*cdf0e10cSrcweir 	sFollowStyle( RTL_CONSTASCII_USTRINGPARAM( "FollowStyle" ) ),
84*cdf0e10cSrcweir 	sNumberingStyleName( RTL_CONSTASCII_USTRINGPARAM( "NumberingStyleName" ) ),
85*cdf0e10cSrcweir 	sOutlineLevel( RTL_CONSTASCII_USTRINGPARAM( "OutlineLevel" ) ),//#outline level,add by zhaojianwei
86*cdf0e10cSrcweir 	sPoolStyleName( rPoolStyleName ),
87*cdf0e10cSrcweir 	pAutoStylePool( pAutoStyleP  )
88*cdf0e10cSrcweir {
89*cdf0e10cSrcweir }
90*cdf0e10cSrcweir 
91*cdf0e10cSrcweir XMLStyleExport::~XMLStyleExport()
92*cdf0e10cSrcweir {
93*cdf0e10cSrcweir }
94*cdf0e10cSrcweir 
95*cdf0e10cSrcweir void XMLStyleExport::exportStyleAttributes( const Reference< XStyle >& )
96*cdf0e10cSrcweir {
97*cdf0e10cSrcweir }
98*cdf0e10cSrcweir 
99*cdf0e10cSrcweir void XMLStyleExport::exportStyleContent( const Reference< XStyle >& )
100*cdf0e10cSrcweir {
101*cdf0e10cSrcweir }
102*cdf0e10cSrcweir 
103*cdf0e10cSrcweir sal_Bool XMLStyleExport::exportStyle(
104*cdf0e10cSrcweir 		const Reference< XStyle >& rStyle,
105*cdf0e10cSrcweir 	  	const OUString& rXMLFamily,
106*cdf0e10cSrcweir 		const UniReference < SvXMLExportPropertyMapper >& rPropMapper,
107*cdf0e10cSrcweir 		const Reference< XNameAccess >& xStyles,		//#outline level,add by zhaojianwei
108*cdf0e10cSrcweir 		const OUString* pPrefix )
109*cdf0e10cSrcweir {
110*cdf0e10cSrcweir 	Reference< XPropertySet > xPropSet( rStyle, UNO_QUERY );
111*cdf0e10cSrcweir 	Reference< XPropertySetInfo > xPropSetInfo =
112*cdf0e10cSrcweir 			xPropSet->getPropertySetInfo();
113*cdf0e10cSrcweir 	Any aAny;
114*cdf0e10cSrcweir 
115*cdf0e10cSrcweir 	// Don't export styles that aren't existing really. This may be the
116*cdf0e10cSrcweir 	// case for StarOffice Writer's pool styles.
117*cdf0e10cSrcweir 	if( xPropSetInfo->hasPropertyByName( sIsPhysical ) )
118*cdf0e10cSrcweir 	{
119*cdf0e10cSrcweir 		aAny = xPropSet->getPropertyValue( sIsPhysical );
120*cdf0e10cSrcweir 		if( !*(sal_Bool *)aAny.getValue() )
121*cdf0e10cSrcweir 			return sal_False;
122*cdf0e10cSrcweir 	}
123*cdf0e10cSrcweir 
124*cdf0e10cSrcweir 	// <style:style ...>
125*cdf0e10cSrcweir 	GetExport().CheckAttrList();
126*cdf0e10cSrcweir 
127*cdf0e10cSrcweir 	// style:name="..."
128*cdf0e10cSrcweir 	OUString sName;
129*cdf0e10cSrcweir 
130*cdf0e10cSrcweir 	if(pPrefix)
131*cdf0e10cSrcweir 		sName = *pPrefix;
132*cdf0e10cSrcweir 	sName += rStyle->getName();
133*cdf0e10cSrcweir 
134*cdf0e10cSrcweir 	sal_Bool bEncoded = sal_False;
135*cdf0e10cSrcweir 	const OUString sEncodedStyleName(GetExport().EncodeStyleName( sName, &bEncoded ));
136*cdf0e10cSrcweir 	GetExport().AddAttribute( XML_NAMESPACE_STYLE, XML_NAME, sEncodedStyleName );
137*cdf0e10cSrcweir 
138*cdf0e10cSrcweir 	if( bEncoded )
139*cdf0e10cSrcweir 		GetExport().AddAttribute( XML_NAMESPACE_STYLE, XML_DISPLAY_NAME,
140*cdf0e10cSrcweir 							  	 sName);
141*cdf0e10cSrcweir 
142*cdf0e10cSrcweir 	// style:family="..."
143*cdf0e10cSrcweir 	if( rXMLFamily.getLength() > 0 )
144*cdf0e10cSrcweir 		GetExport().AddAttribute( XML_NAMESPACE_STYLE, XML_FAMILY, rXMLFamily);
145*cdf0e10cSrcweir 
146*cdf0e10cSrcweir 	// style:parent-style-name="..."
147*cdf0e10cSrcweir 	OUString sParentString(rStyle->getParentStyle());
148*cdf0e10cSrcweir 	OUString sParent;
149*cdf0e10cSrcweir 
150*cdf0e10cSrcweir 	if(sParentString.getLength())
151*cdf0e10cSrcweir 	{
152*cdf0e10cSrcweir 		if(pPrefix)
153*cdf0e10cSrcweir 			sParent = *pPrefix;
154*cdf0e10cSrcweir 		sParent += sParentString;
155*cdf0e10cSrcweir 	}
156*cdf0e10cSrcweir 	else
157*cdf0e10cSrcweir 		sParent = sPoolStyleName;
158*cdf0e10cSrcweir 
159*cdf0e10cSrcweir 	if( sParent.getLength() )
160*cdf0e10cSrcweir 		GetExport().AddAttribute( XML_NAMESPACE_STYLE, XML_PARENT_STYLE_NAME,
161*cdf0e10cSrcweir 					  			  GetExport().EncodeStyleName( sParent ) );
162*cdf0e10cSrcweir 
163*cdf0e10cSrcweir 	// style:next-style-name="..." (paragraph styles only)
164*cdf0e10cSrcweir 	if( xPropSetInfo->hasPropertyByName( sFollowStyle ) )
165*cdf0e10cSrcweir 	{
166*cdf0e10cSrcweir 		aAny = xPropSet->getPropertyValue( sFollowStyle );
167*cdf0e10cSrcweir 		OUString sNextName;
168*cdf0e10cSrcweir 		aAny >>= sNextName;
169*cdf0e10cSrcweir 		if( sName != sNextName )
170*cdf0e10cSrcweir 		{
171*cdf0e10cSrcweir 			GetExport().AddAttribute( XML_NAMESPACE_STYLE, XML_NEXT_STYLE_NAME,
172*cdf0e10cSrcweir 						  GetExport().EncodeStyleName( sNextName ) );
173*cdf0e10cSrcweir 		}
174*cdf0e10cSrcweir 	}
175*cdf0e10cSrcweir 
176*cdf0e10cSrcweir 	// style:auto-update="..." (SW only)
177*cdf0e10cSrcweir 	if( xPropSetInfo->hasPropertyByName( sIsAutoUpdate ) )
178*cdf0e10cSrcweir 	{
179*cdf0e10cSrcweir 		aAny = xPropSet->getPropertyValue( sIsAutoUpdate );
180*cdf0e10cSrcweir 		if( *(sal_Bool *)aAny.getValue() )
181*cdf0e10cSrcweir 			GetExport().AddAttribute( XML_NAMESPACE_STYLE, XML_AUTO_UPDATE,
182*cdf0e10cSrcweir                                       XML_TRUE );
183*cdf0e10cSrcweir 	}
184*cdf0e10cSrcweir 
185*cdf0e10cSrcweir 	// style:default-outline-level"..." //#outline level, add by zhaojianwei.0802
186*cdf0e10cSrcweir 	sal_Int32 nOutlineLevel = 0;
187*cdf0e10cSrcweir 	if( xPropSetInfo->hasPropertyByName( sOutlineLevel ) )
188*cdf0e10cSrcweir 	{
189*cdf0e10cSrcweir 		Reference< XPropertyState > xPropState( xPropSet, uno::UNO_QUERY );
190*cdf0e10cSrcweir 		if( PropertyState_DIRECT_VALUE == xPropState->getPropertyState( sOutlineLevel ) )
191*cdf0e10cSrcweir 		{
192*cdf0e10cSrcweir 			aAny = xPropSet->getPropertyValue( sOutlineLevel );
193*cdf0e10cSrcweir 			aAny >>= nOutlineLevel;
194*cdf0e10cSrcweir 			if( nOutlineLevel > 0 )
195*cdf0e10cSrcweir 			{
196*cdf0e10cSrcweir 				OUStringBuffer sTmp;
197*cdf0e10cSrcweir 				sTmp.append( static_cast<sal_Int32>(nOutlineLevel));
198*cdf0e10cSrcweir 				GetExport().AddAttribute( XML_NAMESPACE_STYLE,
199*cdf0e10cSrcweir                                           XML_DEFAULT_OUTLINE_LEVEL,
200*cdf0e10cSrcweir                                           sTmp.makeStringAndClear() );
201*cdf0e10cSrcweir 			}
202*cdf0e10cSrcweir 			else
203*cdf0e10cSrcweir 			{
204*cdf0e10cSrcweir                 // --> OD 2009-12-29 #i104889#
205*cdf0e10cSrcweir                 // empty value for style:default-outline-level does exist
206*cdf0e10cSrcweir                 // since ODF 1.2. Thus, suppress its export for former versions.
207*cdf0e10cSrcweir                 if ( ( GetExport().getExportFlags() & EXPORT_OASIS ) != 0 &&
208*cdf0e10cSrcweir                      GetExport().getDefaultVersion() >= SvtSaveOptions::ODFVER_012 )
209*cdf0e10cSrcweir                 // <--
210*cdf0e10cSrcweir                 {
211*cdf0e10cSrcweir                     GetExport().AddAttribute( XML_NAMESPACE_STYLE,
212*cdf0e10cSrcweir                                               XML_DEFAULT_OUTLINE_LEVEL,
213*cdf0e10cSrcweir                                               OUString( RTL_CONSTASCII_USTRINGPARAM( "" )));
214*cdf0e10cSrcweir                 }
215*cdf0e10cSrcweir 			}
216*cdf0e10cSrcweir 		}
217*cdf0e10cSrcweir 	}//<-end,zhaojianwei
218*cdf0e10cSrcweir 
219*cdf0e10cSrcweir 	// style:list-style-name="..." (SW paragarph styles only)
220*cdf0e10cSrcweir 	if( xPropSetInfo->hasPropertyByName( sNumberingStyleName ) )
221*cdf0e10cSrcweir 	{
222*cdf0e10cSrcweir 		Reference< XPropertyState > xPropState( xPropSet, uno::UNO_QUERY );
223*cdf0e10cSrcweir 		if( PropertyState_DIRECT_VALUE ==
224*cdf0e10cSrcweir 				xPropState->getPropertyState( sNumberingStyleName  ) )
225*cdf0e10cSrcweir 		{
226*cdf0e10cSrcweir 			aAny = xPropSet->getPropertyValue( sNumberingStyleName );
227*cdf0e10cSrcweir 			if( aAny.hasValue() )
228*cdf0e10cSrcweir 			{
229*cdf0e10cSrcweir 				OUString sListName;
230*cdf0e10cSrcweir 				aAny >>= sListName;
231*cdf0e10cSrcweir 
232*cdf0e10cSrcweir                 // --> OD 2006-09-21 #i69523#
233*cdf0e10cSrcweir                 // An direct set empty list style has to be written. Otherwise,
234*cdf0e10cSrcweir                 // this information is lost and causes an error, if the parent
235*cdf0e10cSrcweir                 // style has a list style set.
236*cdf0e10cSrcweir                 if ( !sListName.getLength() )
237*cdf0e10cSrcweir                 {
238*cdf0e10cSrcweir                     GetExport().AddAttribute( XML_NAMESPACE_STYLE,
239*cdf0e10cSrcweir                                               XML_LIST_STYLE_NAME,
240*cdf0e10cSrcweir                                               sListName /* empty string */);
241*cdf0e10cSrcweir                 }
242*cdf0e10cSrcweir                 else
243*cdf0e10cSrcweir                 {
244*cdf0e10cSrcweir                     // --> OD 2006-09-27 #i69627#
245*cdf0e10cSrcweir                     bool bSuppressListStyle( false );
246*cdf0e10cSrcweir                     {
247*cdf0e10cSrcweir                         if ( !GetExport().writeOutlineStyleAsNormalListStyle() )
248*cdf0e10cSrcweir                         {
249*cdf0e10cSrcweir                             Reference< XChapterNumberingSupplier > xCNSupplier
250*cdf0e10cSrcweir                                 (GetExport().GetModel(), UNO_QUERY);
251*cdf0e10cSrcweir 
252*cdf0e10cSrcweir                             OUString sOutlineName;
253*cdf0e10cSrcweir                             if (xCNSupplier.is())
254*cdf0e10cSrcweir                             {
255*cdf0e10cSrcweir                                 Reference< XIndexReplace > xNumRule
256*cdf0e10cSrcweir                                     ( xCNSupplier->getChapterNumberingRules() );
257*cdf0e10cSrcweir                                 DBG_ASSERT( xNumRule.is(), "no chapter numbering rules" );
258*cdf0e10cSrcweir 
259*cdf0e10cSrcweir                                 if (xNumRule.is())
260*cdf0e10cSrcweir                                 {
261*cdf0e10cSrcweir                                     Reference< XPropertySet > xNumRulePropSet
262*cdf0e10cSrcweir                                         (xNumRule, UNO_QUERY);
263*cdf0e10cSrcweir                                     xNumRulePropSet->getPropertyValue(
264*cdf0e10cSrcweir                                         OUString(RTL_CONSTASCII_USTRINGPARAM("Name")) )
265*cdf0e10cSrcweir                                         >>= sOutlineName;
266*cdf0e10cSrcweir                                     bSuppressListStyle = ( sListName == sOutlineName );
267*cdf0e10cSrcweir                                 }
268*cdf0e10cSrcweir                             }
269*cdf0e10cSrcweir                         }
270*cdf0e10cSrcweir                     }
271*cdf0e10cSrcweir 
272*cdf0e10cSrcweir                     if ( sListName.getLength() && !bSuppressListStyle )
273*cdf0e10cSrcweir                     // <--
274*cdf0e10cSrcweir                     {
275*cdf0e10cSrcweir                         GetExport().AddAttribute( XML_NAMESPACE_STYLE,
276*cdf0e10cSrcweir                                                   XML_LIST_STYLE_NAME,
277*cdf0e10cSrcweir                                   GetExport().EncodeStyleName( sListName ) );
278*cdf0e10cSrcweir                     }
279*cdf0e10cSrcweir                 }
280*cdf0e10cSrcweir                 // <--
281*cdf0e10cSrcweir 			}
282*cdf0e10cSrcweir 		}
283*cdf0e10cSrcweir 		//#outline level, add by zhaojianwei.0802
284*cdf0e10cSrcweir 		else if( nOutlineLevel > 0 )
285*cdf0e10cSrcweir 		{
286*cdf0e10cSrcweir 
287*cdf0e10cSrcweir 			bool bNoInheritedListStyle( true );
288*cdf0e10cSrcweir 
289*cdf0e10cSrcweir 			/////////////////////////////////////////////////
290*cdf0e10cSrcweir 			Reference<XStyle> xStyle( xPropState, UNO_QUERY );
291*cdf0e10cSrcweir 			while ( xStyle.is() )
292*cdf0e10cSrcweir 			{
293*cdf0e10cSrcweir 				OUString aParentStyle( xStyle->getParentStyle() );
294*cdf0e10cSrcweir 				if ( aParentStyle.getLength() == 0 ||
295*cdf0e10cSrcweir 					!xStyles->hasByName( aParentStyle ) )
296*cdf0e10cSrcweir 				{
297*cdf0e10cSrcweir 					break;
298*cdf0e10cSrcweir 				}
299*cdf0e10cSrcweir 				else
300*cdf0e10cSrcweir 				{
301*cdf0e10cSrcweir 					xPropState = Reference< XPropertyState >( xStyles->getByName( aParentStyle ), UNO_QUERY );
302*cdf0e10cSrcweir 					if ( !xPropState.is() )
303*cdf0e10cSrcweir 					{
304*cdf0e10cSrcweir 						break;
305*cdf0e10cSrcweir 					}
306*cdf0e10cSrcweir 					if ( xPropState->getPropertyState( sNumberingStyleName ) == PropertyState_DIRECT_VALUE )
307*cdf0e10cSrcweir 					{
308*cdf0e10cSrcweir 						bNoInheritedListStyle = false;
309*cdf0e10cSrcweir 						break;
310*cdf0e10cSrcweir 					}
311*cdf0e10cSrcweir 					else
312*cdf0e10cSrcweir 					{
313*cdf0e10cSrcweir 						xStyle = Reference<XStyle>( xPropState, UNO_QUERY );
314*cdf0e10cSrcweir 					}
315*cdf0e10cSrcweir 				}
316*cdf0e10cSrcweir 			}
317*cdf0e10cSrcweir 			/////////////////////////////////////////////////
318*cdf0e10cSrcweir 			if ( bNoInheritedListStyle )
319*cdf0e10cSrcweir                 GetExport().AddAttribute( XML_NAMESPACE_STYLE,
320*cdf0e10cSrcweir                                           XML_LIST_STYLE_NAME,
321*cdf0e10cSrcweir                                           OUString( RTL_CONSTASCII_USTRINGPARAM( "" )));
322*cdf0e10cSrcweir 		}
323*cdf0e10cSrcweir 		//<-end,zhaojianwei
324*cdf0e10cSrcweir 	}
325*cdf0e10cSrcweir 
326*cdf0e10cSrcweir 
327*cdf0e10cSrcweir 	// style:pool-id="..." is not required any longer since we use
328*cdf0e10cSrcweir 	// english style names only
329*cdf0e10cSrcweir 	exportStyleAttributes( rStyle );
330*cdf0e10cSrcweir 
331*cdf0e10cSrcweir 	// TODO: style:help-file-name="..." and style:help-id="..." can neither
332*cdf0e10cSrcweir 	// be modified by UI nor by API and that for, have not to be exported
333*cdf0e10cSrcweir 	// currently.
334*cdf0e10cSrcweir 
335*cdf0e10cSrcweir 	{
336*cdf0e10cSrcweir 		// <style:style>
337*cdf0e10cSrcweir 		SvXMLElementExport aElem( GetExport(), XML_NAMESPACE_STYLE, XML_STYLE,
338*cdf0e10cSrcweir 								  sal_True, sal_True );
339*cdf0e10cSrcweir 
340*cdf0e10cSrcweir 		rPropMapper->SetStyleName( sName );
341*cdf0e10cSrcweir 
342*cdf0e10cSrcweir 		// <style:properties>
343*cdf0e10cSrcweir 		::std::vector< XMLPropertyState > xPropStates =
344*cdf0e10cSrcweir 			rPropMapper->Filter( xPropSet );
345*cdf0e10cSrcweir 		rPropMapper->exportXML( GetExport(), xPropStates,
346*cdf0e10cSrcweir                                 XML_EXPORT_FLAG_IGN_WS );
347*cdf0e10cSrcweir 
348*cdf0e10cSrcweir 		rPropMapper->SetStyleName( OUString() );
349*cdf0e10cSrcweir 
350*cdf0e10cSrcweir 		exportStyleContent( rStyle );
351*cdf0e10cSrcweir 
352*cdf0e10cSrcweir 		// <script:events>, if they are supported by this style
353*cdf0e10cSrcweir 		Reference<XEventsSupplier> xEventsSupp(rStyle, UNO_QUERY);
354*cdf0e10cSrcweir 		GetExport().GetEventExport().Export(xEventsSupp);
355*cdf0e10cSrcweir 	}
356*cdf0e10cSrcweir 	return sal_True;
357*cdf0e10cSrcweir }
358*cdf0e10cSrcweir 
359*cdf0e10cSrcweir sal_Bool XMLStyleExport::exportDefaultStyle(
360*cdf0e10cSrcweir 		const Reference< XPropertySet >& xPropSet,
361*cdf0e10cSrcweir 	  	const OUString& rXMLFamily,
362*cdf0e10cSrcweir 		const UniReference < SvXMLExportPropertyMapper >& rPropMapper )
363*cdf0e10cSrcweir {
364*cdf0e10cSrcweir 	Reference< XPropertySetInfo > xPropSetInfo =
365*cdf0e10cSrcweir 			xPropSet->getPropertySetInfo();
366*cdf0e10cSrcweir 
367*cdf0e10cSrcweir 	Any aAny;
368*cdf0e10cSrcweir 
369*cdf0e10cSrcweir 	// <style:default-style ...>
370*cdf0e10cSrcweir 	GetExport().CheckAttrList();
371*cdf0e10cSrcweir 
372*cdf0e10cSrcweir 	{
373*cdf0e10cSrcweir 		// style:family="..."
374*cdf0e10cSrcweir 		if( rXMLFamily.getLength() > 0 )
375*cdf0e10cSrcweir 			GetExport().AddAttribute( XML_NAMESPACE_STYLE, XML_FAMILY,
376*cdf0e10cSrcweir                                       rXMLFamily );
377*cdf0e10cSrcweir 		// <style:style>
378*cdf0e10cSrcweir 		SvXMLElementExport aElem( GetExport(), XML_NAMESPACE_STYLE,
379*cdf0e10cSrcweir 								  XML_DEFAULT_STYLE,
380*cdf0e10cSrcweir 								  sal_True, sal_True );
381*cdf0e10cSrcweir 		// <style:properties>
382*cdf0e10cSrcweir 		//::std::vector< XMLPropertyState > xPropStates =
383*cdf0e10cSrcweir 		//	rPropMapper->FilterDefaults( xPropSet );
384*cdf0e10cSrcweir 		::std::vector< XMLPropertyState > xPropStates =
385*cdf0e10cSrcweir 			rPropMapper->FilterDefaults( xPropSet );
386*cdf0e10cSrcweir 		rPropMapper->exportXML( GetExport(), xPropStates,
387*cdf0e10cSrcweir 							   	  XML_EXPORT_FLAG_IGN_WS );
388*cdf0e10cSrcweir //		exportStyleContent( rStyle );
389*cdf0e10cSrcweir 	}
390*cdf0e10cSrcweir 	return sal_True;
391*cdf0e10cSrcweir }
392*cdf0e10cSrcweir 
393*cdf0e10cSrcweir #if 0
394*cdf0e10cSrcweir void XMLStyleExport::exportStyleFamily(
395*cdf0e10cSrcweir 	const sal_Char *pFamily,
396*cdf0e10cSrcweir 	const OUString& rXMLFamily,
397*cdf0e10cSrcweir 	const UniReference < XMLPropertySetMapper >& rPropMapper,
398*cdf0e10cSrcweir 	sal_Bool bUsed, sal_uInt16 nFamily, const OUString* pPrefix)
399*cdf0e10cSrcweir {
400*cdf0e10cSrcweir 	const OUString sFamily(OUString::createFromAscii(pFamily ));
401*cdf0e10cSrcweir 	UniReference < SvXMLExportPropertyMapper > xExpPropMapper =
402*cdf0e10cSrcweir 		new SvXMLExportPropertyMapper( rPropMapper );
403*cdf0e10cSrcweir 	exportStyleFamily( sFamily, rXMLFamily, xExpPropMapper, bUsed, nFamily,
404*cdf0e10cSrcweir 					   pPrefix);
405*cdf0e10cSrcweir }
406*cdf0e10cSrcweir 
407*cdf0e10cSrcweir void XMLStyleExport::exportStyleFamily(
408*cdf0e10cSrcweir 	const OUString& rFamily, const OUString& rXMLFamily,
409*cdf0e10cSrcweir 	const UniReference < XMLPropertySetMapper >& rPropMapper,
410*cdf0e10cSrcweir 	sal_Bool bUsed, sal_uInt16 nFamily, const OUString* pPrefix)
411*cdf0e10cSrcweir {
412*cdf0e10cSrcweir 	UniReference < SvXMLExportPropertyMapper > xExpPropMapper =
413*cdf0e10cSrcweir 		new SvXMLExportPropertyMapper( rPropMapper );
414*cdf0e10cSrcweir 	exportStyleFamily( rFamily, rXMLFamily, xExpPropMapper, bUsed, nFamily,
415*cdf0e10cSrcweir 					   pPrefix);
416*cdf0e10cSrcweir }
417*cdf0e10cSrcweir #endif
418*cdf0e10cSrcweir 
419*cdf0e10cSrcweir void XMLStyleExport::exportStyleFamily(
420*cdf0e10cSrcweir 	const sal_Char *pFamily,
421*cdf0e10cSrcweir 	const OUString& rXMLFamily,
422*cdf0e10cSrcweir 	const UniReference < SvXMLExportPropertyMapper >& rPropMapper,
423*cdf0e10cSrcweir 	sal_Bool bUsed, sal_uInt16 nFamily, const OUString* pPrefix)
424*cdf0e10cSrcweir {
425*cdf0e10cSrcweir 	const OUString sFamily(OUString::createFromAscii(pFamily ));
426*cdf0e10cSrcweir 	exportStyleFamily( sFamily, rXMLFamily, rPropMapper, bUsed, nFamily,
427*cdf0e10cSrcweir 					   pPrefix);
428*cdf0e10cSrcweir }
429*cdf0e10cSrcweir 
430*cdf0e10cSrcweir void XMLStyleExport::exportStyleFamily(
431*cdf0e10cSrcweir 	const OUString& rFamily, const OUString& rXMLFamily,
432*cdf0e10cSrcweir 	const UniReference < SvXMLExportPropertyMapper >& rPropMapper,
433*cdf0e10cSrcweir 	sal_Bool bUsed, sal_uInt16 nFamily, const OUString* pPrefix)
434*cdf0e10cSrcweir {
435*cdf0e10cSrcweir 	DBG_ASSERT( GetExport().GetModel().is(), "There is the model?" );
436*cdf0e10cSrcweir 	Reference< XStyleFamiliesSupplier > xFamiliesSupp( GetExport().GetModel(), UNO_QUERY );
437*cdf0e10cSrcweir 	if( !xFamiliesSupp.is() )
438*cdf0e10cSrcweir 		return; // family not available in current model
439*cdf0e10cSrcweir 
440*cdf0e10cSrcweir 	Reference< XNameAccess > xStyleCont;
441*cdf0e10cSrcweir 
442*cdf0e10cSrcweir 	Reference< XNameAccess > xFamilies( xFamiliesSupp->getStyleFamilies() );
443*cdf0e10cSrcweir 	if( xFamilies->hasByName( rFamily ) )
444*cdf0e10cSrcweir 		xFamilies->getByName( rFamily ) >>= xStyleCont;
445*cdf0e10cSrcweir 
446*cdf0e10cSrcweir 	if( !xStyleCont.is() )
447*cdf0e10cSrcweir 		return;
448*cdf0e10cSrcweir 
449*cdf0e10cSrcweir 	Reference< XNameAccess > xStyles( xStyleCont, UNO_QUERY );
450*cdf0e10cSrcweir    	// If next styles are supported and used styles should be exported only,
451*cdf0e10cSrcweir 	// the next style may be unused but has to be exported, too. In this case
452*cdf0e10cSrcweir 	// the names of all exported styles are remembered.
453*cdf0e10cSrcweir 	SvStringsSortDtor *pExportedStyles = 0;
454*cdf0e10cSrcweir 	sal_Bool bFirstStyle = sal_True;
455*cdf0e10cSrcweir 
456*cdf0e10cSrcweir     const uno::Sequence< ::rtl::OUString> aSeq = xStyles->getElementNames();
457*cdf0e10cSrcweir     const ::rtl::OUString* pIter = aSeq.getConstArray();
458*cdf0e10cSrcweir     const ::rtl::OUString* pEnd	  = pIter + aSeq.getLength();
459*cdf0e10cSrcweir     for(;pIter != pEnd;++pIter)
460*cdf0e10cSrcweir     {
461*cdf0e10cSrcweir 		Reference< XStyle > xStyle;
462*cdf0e10cSrcweir 		try
463*cdf0e10cSrcweir 		{
464*cdf0e10cSrcweir 			xStyles->getByName( *pIter ) >>= xStyle;
465*cdf0e10cSrcweir 		}
466*cdf0e10cSrcweir 		catch( lang::IndexOutOfBoundsException )
467*cdf0e10cSrcweir 		{
468*cdf0e10cSrcweir 			// due to bugs in prior versions it is possible that
469*cdf0e10cSrcweir 			// a binary file is missing some critical styles.
470*cdf0e10cSrcweir 			// The only possible way to deal with this is to
471*cdf0e10cSrcweir 			// not export them here and remain silent.
472*cdf0e10cSrcweir 			continue;
473*cdf0e10cSrcweir 		}
474*cdf0e10cSrcweir 
475*cdf0e10cSrcweir 		DBG_ASSERT( xStyle.is(), "Style not found for export!" );
476*cdf0e10cSrcweir 		if( xStyle.is() )
477*cdf0e10cSrcweir 		{
478*cdf0e10cSrcweir 			if( !bUsed || xStyle->isInUse() )
479*cdf0e10cSrcweir 			{
480*cdf0e10cSrcweir 				sal_Bool bExported = exportStyle( xStyle, rXMLFamily, rPropMapper,
481*cdf0e10cSrcweir 											  xStyles,pPrefix );
482*cdf0e10cSrcweir 				if( bUsed && bFirstStyle && bExported  )
483*cdf0e10cSrcweir 				{
484*cdf0e10cSrcweir 					// If this is the first style, find out wether next styles
485*cdf0e10cSrcweir 					// are supported.
486*cdf0e10cSrcweir 					Reference< XPropertySet > xPropSet( xStyle, UNO_QUERY );
487*cdf0e10cSrcweir 					Reference< XPropertySetInfo > xPropSetInfo =
488*cdf0e10cSrcweir 						xPropSet->getPropertySetInfo();
489*cdf0e10cSrcweir 
490*cdf0e10cSrcweir 					if( xPropSetInfo->hasPropertyByName( sFollowStyle ) )
491*cdf0e10cSrcweir 						pExportedStyles = new SvStringsSortDtor;
492*cdf0e10cSrcweir 					bFirstStyle = sal_False;
493*cdf0e10cSrcweir 				}
494*cdf0e10cSrcweir 
495*cdf0e10cSrcweir 				if( pExportedStyles && bExported )
496*cdf0e10cSrcweir 				{
497*cdf0e10cSrcweir 					// If next styles are supported, remember this style's name.
498*cdf0e10cSrcweir 					String *pTmp = new String( xStyle->getName() );
499*cdf0e10cSrcweir 					if( !pExportedStyles->Insert( pTmp ) )
500*cdf0e10cSrcweir 						delete pTmp;
501*cdf0e10cSrcweir 				}
502*cdf0e10cSrcweir 			}
503*cdf0e10cSrcweir 
504*cdf0e10cSrcweir 			// if an auto style pool is given, remember this style's name as a
505*cdf0e10cSrcweir 			// style name that must not be used by automatic styles.
506*cdf0e10cSrcweir 			if( pAutoStylePool )
507*cdf0e10cSrcweir 				pAutoStylePool->RegisterName( nFamily, xStyle->getName() );
508*cdf0e10cSrcweir 		}
509*cdf0e10cSrcweir 	}
510*cdf0e10cSrcweir 
511*cdf0e10cSrcweir 	if( pExportedStyles )
512*cdf0e10cSrcweir 	{
513*cdf0e10cSrcweir 		// if next styles are supported, export all next styles that are
514*cdf0e10cSrcweir 		// unused and that for, haven't been exported in the first loop.
515*cdf0e10cSrcweir         pIter = aSeq.getConstArray();
516*cdf0e10cSrcweir 		for(;pIter != pEnd;++pIter)
517*cdf0e10cSrcweir 		{
518*cdf0e10cSrcweir 			Reference< XStyle > xStyle;
519*cdf0e10cSrcweir 			xStyles->getByName( *pIter ) >>= xStyle;
520*cdf0e10cSrcweir 
521*cdf0e10cSrcweir 			DBG_ASSERT( xStyle.is(), "Style not found for export!" );
522*cdf0e10cSrcweir 			if( xStyle.is() )
523*cdf0e10cSrcweir 			{
524*cdf0e10cSrcweir 				Reference< XPropertySet > xPropSet( xStyle, UNO_QUERY );
525*cdf0e10cSrcweir 				Reference< XPropertySetInfo > xPropSetInfo( xPropSet->getPropertySetInfo() );
526*cdf0e10cSrcweir 
527*cdf0e10cSrcweir 				// styles that aren't existing realy are ignored.
528*cdf0e10cSrcweir 				if( xPropSetInfo->hasPropertyByName( sIsPhysical ) )
529*cdf0e10cSrcweir 				{
530*cdf0e10cSrcweir 					Any aAny( xPropSet->getPropertyValue( sIsPhysical ) );
531*cdf0e10cSrcweir 					if( !*(sal_Bool *)aAny.getValue() )
532*cdf0e10cSrcweir 						continue;
533*cdf0e10cSrcweir 				}
534*cdf0e10cSrcweir 
535*cdf0e10cSrcweir 				if( !xStyle->isInUse() )
536*cdf0e10cSrcweir 					continue;
537*cdf0e10cSrcweir 
538*cdf0e10cSrcweir 				if( !xPropSetInfo->hasPropertyByName( sFollowStyle ) )
539*cdf0e10cSrcweir 				{
540*cdf0e10cSrcweir 					DBG_ASSERT( 0==sFollowStyle.getLength(),
541*cdf0e10cSrcweir 								"no follow style???" );
542*cdf0e10cSrcweir 					continue;
543*cdf0e10cSrcweir 				}
544*cdf0e10cSrcweir 
545*cdf0e10cSrcweir 				OUString sNextName;
546*cdf0e10cSrcweir 				xPropSet->getPropertyValue( sFollowStyle ) >>= sNextName;
547*cdf0e10cSrcweir 				String sTmp( sNextName );
548*cdf0e10cSrcweir 				// if the next style hasn't been exported by now, export it now
549*cdf0e10cSrcweir 				// and remember its name.
550*cdf0e10cSrcweir 				if( xStyle->getName() != sNextName &&
551*cdf0e10cSrcweir 					!pExportedStyles->Seek_Entry( &sTmp ) )
552*cdf0e10cSrcweir 				{
553*cdf0e10cSrcweir 					xStyleCont->getByName( sNextName ) >>= xStyle;
554*cdf0e10cSrcweir 					DBG_ASSERT( xStyle.is(), "Style not found for export!" );
555*cdf0e10cSrcweir 
556*cdf0e10cSrcweir 					if( xStyle.is() && exportStyle( xStyle, rXMLFamily, rPropMapper, xStyles,pPrefix ) )
557*cdf0e10cSrcweir 						pExportedStyles->Insert( new String( sTmp ) );
558*cdf0e10cSrcweir 				}
559*cdf0e10cSrcweir 			}
560*cdf0e10cSrcweir 		}
561*cdf0e10cSrcweir 	}
562*cdf0e10cSrcweir 
563*cdf0e10cSrcweir 	delete pExportedStyles;
564*cdf0e10cSrcweir }
565*cdf0e10cSrcweir 
566*cdf0e10cSrcweir 
567