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