1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <xmloff/XMLPageExport.hxx>
21 #include <tools/debug.hxx>
22 #include "xmloff/xmlnmspe.hxx"
23 #include <xmloff/xmltoken.hxx>
24 #include <com/sun/star/style/XStyleFamiliesSupplier.hpp>
25 #include <com/sun/star/style/XStyle.hpp>
26 #include <com/sun/star/container/XNameContainer.hpp>
27 #include <com/sun/star/container/XIndexReplace.hpp>
28 #include <com/sun/star/beans/XPropertySet.hpp>
29 #include <xmloff/families.hxx>
30 #include <xmloff/xmlexp.hxx>
31 #include "PageMasterPropHdlFactory.hxx"
32 #include <xmloff/PageMasterStyleMap.hxx>
33 #include "PageMasterPropMapper.hxx"
34 #include "PageMasterExportPropMapper.hxx"
37 using namespace ::com::sun::star
;
38 using namespace ::com::sun::star::uno
;
39 using namespace ::com::sun::star::style
;
40 using namespace ::com::sun::star::container
;
41 using namespace ::com::sun::star::beans
;
42 using namespace ::xmloff::token
;
45 //______________________________________________________________________________
47 sal_Bool
XMLPageExport::findPageMasterName( const OUString
& rStyleName
, OUString
& rPMName
) const
49 for( ::std::vector
< XMLPageExportNameEntry
>::const_iterator pEntry
= aNameVector
.begin();
50 pEntry
!= aNameVector
.end(); ++pEntry
)
52 if( pEntry
->sStyleName
== rStyleName
)
54 rPMName
= pEntry
->sPageMasterName
;
61 void XMLPageExport::collectPageMasterAutoStyle(
62 const Reference
< XPropertySet
> & rPropSet
,
63 OUString
& rPageMasterName
)
65 DBG_ASSERT( xPageMasterPropSetMapper
.is(), "page master family/XMLPageMasterPropSetMapper not found" );
66 if( xPageMasterPropSetMapper
.is() )
68 ::std::vector
<XMLPropertyState
> xPropStates
= xPageMasterExportPropMapper
->Filter( rPropSet
);
69 if( !xPropStates
.empty())
72 rPageMasterName
= rExport
.GetAutoStylePool()->Find( XML_STYLE_FAMILY_PAGE_MASTER
, sParent
, xPropStates
);
73 if (rPageMasterName
.isEmpty())
74 rPageMasterName
= rExport
.GetAutoStylePool()->Add(XML_STYLE_FAMILY_PAGE_MASTER
, sParent
, xPropStates
);
79 void XMLPageExport::exportMasterPageContent(
80 const Reference
< XPropertySet
> &,
81 sal_Bool
/*bAutoStyles*/ )
86 sal_Bool
XMLPageExport::exportStyle(
87 const Reference
< XStyle
>& rStyle
,
88 sal_Bool bAutoStyles
)
90 Reference
< XPropertySet
> xPropSet( rStyle
, UNO_QUERY
);
91 Reference
< XPropertySetInfo
> xPropSetInfo
= xPropSet
->getPropertySetInfo();
93 // Don't export styles that aren't existing really. This may be the
94 // case for StarOffice Writer's pool styles.
95 if( xPropSetInfo
->hasPropertyByName( sIsPhysical
) )
97 Any aAny
= xPropSet
->getPropertyValue( sIsPhysical
);
98 if( !*(sal_Bool
*)aAny
.getValue() )
104 XMLPageExportNameEntry aEntry
;
105 collectPageMasterAutoStyle( xPropSet
, aEntry
.sPageMasterName
);
106 aEntry
.sStyleName
= rStyle
->getName();
107 aNameVector
.push_back( aEntry
);
109 exportMasterPageContent( xPropSet
, sal_True
);
113 OUString
sName( rStyle
->getName() );
114 sal_Bool bEncoded
= sal_False
;
115 GetExport().AddAttribute( XML_NAMESPACE_STYLE
, XML_NAME
,
116 GetExport().EncodeStyleName( sName
, &bEncoded
) );
118 if ( xPropSetInfo
->hasPropertyByName( "Hidden" ) )
120 uno::Any aValue
= xPropSet
->getPropertyValue( "Hidden" );
121 sal_Bool bHidden
= sal_False
;
122 if ( ( aValue
>>= bHidden
) && bHidden
&& GetExport( ).getDefaultVersion( ) == SvtSaveOptions::ODFVER_LATEST
)
123 GetExport( ).AddAttribute( XML_NAMESPACE_STYLE
, XML_HIDDEN
, "true" );
127 GetExport().AddAttribute( XML_NAMESPACE_STYLE
, XML_DISPLAY_NAME
,
131 if( findPageMasterName( sName
, sPMName
) )
132 GetExport().AddAttribute( XML_NAMESPACE_STYLE
, XML_PAGE_LAYOUT_NAME
, GetExport().EncodeStyleName( sPMName
) );
134 Reference
<XPropertySetInfo
> xInfo
= xPropSet
->getPropertySetInfo();
135 if ( xInfo
.is() && xInfo
->hasPropertyByName(sFollowStyle
) )
138 xPropSet
->getPropertyValue( sFollowStyle
) >>= sNextName
;
140 if( sName
!= sNextName
&& !sNextName
.isEmpty() )
142 GetExport().AddAttribute( XML_NAMESPACE_STYLE
, XML_NEXT_STYLE_NAME
,
143 GetExport().EncodeStyleName( sNextName
) );
147 SvXMLElementExport
aElem( GetExport(), XML_NAMESPACE_STYLE
,
148 XML_MASTER_PAGE
, sal_True
, sal_True
);
150 exportMasterPageContent( xPropSet
, sal_False
);
156 XMLPageExport::XMLPageExport( SvXMLExport
& rExp
) :
158 sIsPhysical( "IsPhysical" ),
159 sFollowStyle( "FollowStyle" )
161 xPageMasterPropHdlFactory
= new XMLPageMasterPropHdlFactory
;
162 xPageMasterPropSetMapper
= new XMLPageMasterPropSetMapper(
163 (XMLPropertyMapEntry
*) aXMLPageMasterStyleMap
,
164 xPageMasterPropHdlFactory
, true );
165 xPageMasterExportPropMapper
= new XMLPageMasterExportPropMapper(
166 xPageMasterPropSetMapper
, rExp
);
168 rExport
.GetAutoStylePool()->AddFamily( XML_STYLE_FAMILY_PAGE_MASTER
, OUString( XML_STYLE_FAMILY_PAGE_MASTER_NAME
),
169 xPageMasterExportPropMapper
, OUString( XML_STYLE_FAMILY_PAGE_MASTER_PREFIX
), sal_False
);
171 Reference
< XStyleFamiliesSupplier
> xFamiliesSupp( GetExport().GetModel(),
173 DBG_ASSERT( xFamiliesSupp
.is(),
174 "No XStyleFamiliesSupplier from XModel for export!" );
175 if( xFamiliesSupp
.is() )
177 Reference
< XNameAccess
> xFamilies( xFamiliesSupp
->getStyleFamilies() );
178 DBG_ASSERT( xFamiliesSupp
.is(),
179 "getStyleFamilies() from XModel failed for export!" );
182 const OUString
aPageStyleName("PageStyles");
184 if( xFamilies
->hasByName( aPageStyleName
) )
186 xPageStyles
.set(xFamilies
->getByName( aPageStyleName
),uno::UNO_QUERY
);
188 DBG_ASSERT( xPageStyles
.is(),
189 "Page Styles not found for export!" );
195 XMLPageExport::~XMLPageExport()
199 void XMLPageExport::exportStyles( sal_Bool bUsed
, sal_Bool bAutoStyles
)
201 if( xPageStyles
.is() )
203 uno::Sequence
< OUString
> aSeq
= xPageStyles
->getElementNames();
204 const OUString
* pIter
= aSeq
.getConstArray();
205 const OUString
* pEnd
= pIter
+ aSeq
.getLength();
206 for(;pIter
!= pEnd
;++pIter
)
208 Reference
< XStyle
> xStyle(xPageStyles
->getByName( *pIter
),uno::UNO_QUERY
);
209 if( !bUsed
|| xStyle
->isInUse() )
210 exportStyle( xStyle
, bAutoStyles
);
215 void XMLPageExport::exportAutoStyles()
217 rExport
.GetAutoStylePool()->exportXML(XML_STYLE_FAMILY_PAGE_MASTER
218 , rExport
.GetDocHandler(), rExport
.GetMM100UnitConverter(),
219 rExport
.GetNamespaceMap()
223 void XMLPageExport::exportDefaultStyle()
225 Reference
< lang::XMultiServiceFactory
> xFactory (GetExport().GetModel(), UNO_QUERY
);
228 OUString
sTextDefaults ( "com.sun.star.text.Defaults" );
229 Reference
< XPropertySet
> xPropSet (xFactory
->createInstance ( sTextDefaults
), UNO_QUERY
);
232 // <style:default-style ...>
233 GetExport().CheckAttrList();
235 ::std::vector
< XMLPropertyState
> xPropStates
=
236 xPageMasterExportPropMapper
->FilterDefaults( xPropSet
);
238 sal_Bool bExport
= sal_False
;
239 UniReference
< XMLPropertySetMapper
> aPropMapper(xPageMasterExportPropMapper
->getPropertySetMapper());
240 for( ::std::vector
< XMLPropertyState
>::iterator aIter
= xPropStates
.begin(); aIter
!= xPropStates
.end(); ++aIter
)
242 XMLPropertyState
*pProp
= &(*aIter
);
243 sal_Int16 nContextId
= aPropMapper
->GetEntryContextId( pProp
->mnIndex
);
244 if( nContextId
== CTF_PM_STANDARD_MODE
)
253 assert(GetExport().getDefaultVersion()
254 >= SvtSaveOptions::ODFVER_012
);
256 //<style:default-page-layout>
257 SvXMLElementExport
aElem( GetExport(), XML_NAMESPACE_STYLE
,
258 XML_DEFAULT_PAGE_LAYOUT
,
259 sal_True
, sal_True
);
261 xPageMasterExportPropMapper
->exportXML( GetExport(), xPropStates
,
262 XML_EXPORT_FLAG_IGN_WS
);
268 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */