Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
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 .
18 : */
19 :
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"
35 :
36 :
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;
43 :
44 :
45 : //______________________________________________________________________________
46 :
47 36 : sal_Bool XMLPageExport::findPageMasterName( const OUString& rStyleName, OUString& rPMName ) const
48 : {
49 147 : for( ::std::vector< XMLPageExportNameEntry >::const_iterator pEntry = aNameVector.begin();
50 98 : pEntry != aNameVector.end(); ++pEntry )
51 : {
52 49 : if( pEntry->sStyleName == rStyleName )
53 : {
54 36 : rPMName = pEntry->sPageMasterName;
55 36 : return sal_True;
56 : }
57 : }
58 0 : return sal_False;
59 : }
60 :
61 36 : void XMLPageExport::collectPageMasterAutoStyle(
62 : const Reference < XPropertySet > & rPropSet,
63 : OUString& rPageMasterName )
64 : {
65 : DBG_ASSERT( xPageMasterPropSetMapper.is(), "page master family/XMLPageMasterPropSetMapper not found" );
66 36 : if( xPageMasterPropSetMapper.is() )
67 : {
68 36 : ::std::vector<XMLPropertyState> xPropStates = xPageMasterExportPropMapper->Filter( rPropSet );
69 36 : if( !xPropStates.empty())
70 : {
71 36 : OUString sParent;
72 36 : rPageMasterName = rExport.GetAutoStylePool()->Find( XML_STYLE_FAMILY_PAGE_MASTER, sParent, xPropStates );
73 36 : if (rPageMasterName.isEmpty())
74 36 : rPageMasterName = rExport.GetAutoStylePool()->Add(XML_STYLE_FAMILY_PAGE_MASTER, sParent, xPropStates);
75 36 : }
76 : }
77 36 : }
78 :
79 0 : void XMLPageExport::exportMasterPageContent(
80 : const Reference < XPropertySet > &,
81 : sal_Bool /*bAutoStyles*/ )
82 : {
83 :
84 0 : }
85 :
86 360 : sal_Bool XMLPageExport::exportStyle(
87 : const Reference< XStyle >& rStyle,
88 : sal_Bool bAutoStyles )
89 : {
90 360 : Reference< XPropertySet > xPropSet( rStyle, UNO_QUERY );
91 720 : Reference< XPropertySetInfo > xPropSetInfo = xPropSet->getPropertySetInfo();
92 :
93 : // Don't export styles that aren't existing really. This may be the
94 : // case for StarOffice Writer's pool styles.
95 360 : if( xPropSetInfo->hasPropertyByName( sIsPhysical ) )
96 : {
97 326 : Any aAny = xPropSet->getPropertyValue( sIsPhysical );
98 326 : if( !*(sal_Bool *)aAny.getValue() )
99 288 : return sal_False;
100 : }
101 :
102 72 : if( bAutoStyles )
103 : {
104 36 : XMLPageExportNameEntry aEntry;
105 36 : collectPageMasterAutoStyle( xPropSet, aEntry.sPageMasterName );
106 36 : aEntry.sStyleName = rStyle->getName();
107 36 : aNameVector.push_back( aEntry );
108 :
109 36 : exportMasterPageContent( xPropSet, sal_True );
110 : }
111 : else
112 : {
113 36 : OUString sName( rStyle->getName() );
114 36 : sal_Bool bEncoded = sal_False;
115 36 : GetExport().AddAttribute( XML_NAMESPACE_STYLE, XML_NAME,
116 72 : GetExport().EncodeStyleName( sName, &bEncoded ) );
117 :
118 36 : if ( xPropSetInfo->hasPropertyByName( "Hidden" ) )
119 : {
120 36 : uno::Any aValue = xPropSet->getPropertyValue( "Hidden" );
121 36 : sal_Bool bHidden = sal_False;
122 36 : if ( ( aValue >>= bHidden ) && bHidden && GetExport( ).getDefaultVersion( ) == SvtSaveOptions::ODFVER_LATEST )
123 0 : GetExport( ).AddAttribute( XML_NAMESPACE_STYLE, XML_HIDDEN, "true" );
124 : }
125 :
126 36 : if( bEncoded )
127 1 : GetExport().AddAttribute( XML_NAMESPACE_STYLE, XML_DISPLAY_NAME,
128 1 : sName);
129 :
130 72 : OUString sPMName;
131 36 : if( findPageMasterName( sName, sPMName ) )
132 36 : GetExport().AddAttribute( XML_NAMESPACE_STYLE, XML_PAGE_LAYOUT_NAME, GetExport().EncodeStyleName( sPMName ) );
133 :
134 72 : Reference<XPropertySetInfo> xInfo = xPropSet->getPropertySetInfo();
135 36 : if ( xInfo.is() && xInfo->hasPropertyByName(sFollowStyle) )
136 : {
137 19 : OUString sNextName;
138 19 : xPropSet->getPropertyValue( sFollowStyle ) >>= sNextName;
139 :
140 19 : if( sName != sNextName && !sNextName.isEmpty() )
141 : {
142 0 : GetExport().AddAttribute( XML_NAMESPACE_STYLE, XML_NEXT_STYLE_NAME,
143 0 : GetExport().EncodeStyleName( sNextName ) );
144 19 : }
145 : }
146 :
147 36 : SvXMLElementExport aElem( GetExport(), XML_NAMESPACE_STYLE,
148 72 : XML_MASTER_PAGE, sal_True, sal_True );
149 :
150 72 : exportMasterPageContent( xPropSet, sal_False );
151 : }
152 :
153 432 : return sal_True;
154 : }
155 :
156 24 : XMLPageExport::XMLPageExport( SvXMLExport& rExp ) :
157 : rExport( rExp ),
158 : sIsPhysical( "IsPhysical" ),
159 24 : sFollowStyle( "FollowStyle" )
160 : {
161 24 : xPageMasterPropHdlFactory = new XMLPageMasterPropHdlFactory;
162 48 : xPageMasterPropSetMapper = new XMLPageMasterPropSetMapper(
163 : (XMLPropertyMapEntry*) aXMLPageMasterStyleMap,
164 48 : xPageMasterPropHdlFactory );
165 48 : xPageMasterExportPropMapper = new XMLPageMasterExportPropMapper(
166 48 : xPageMasterPropSetMapper, rExp);
167 :
168 : rExport.GetAutoStylePool()->AddFamily( XML_STYLE_FAMILY_PAGE_MASTER, OUString( XML_STYLE_FAMILY_PAGE_MASTER_NAME ),
169 24 : xPageMasterExportPropMapper, OUString( XML_STYLE_FAMILY_PAGE_MASTER_PREFIX ), sal_False );
170 :
171 24 : Reference< XStyleFamiliesSupplier > xFamiliesSupp( GetExport().GetModel(),
172 24 : UNO_QUERY );
173 : DBG_ASSERT( xFamiliesSupp.is(),
174 : "No XStyleFamiliesSupplier from XModel for export!" );
175 24 : if( xFamiliesSupp.is() )
176 : {
177 24 : Reference< XNameAccess > xFamilies( xFamiliesSupp->getStyleFamilies() );
178 : DBG_ASSERT( xFamiliesSupp.is(),
179 : "getStyleFamilies() from XModel failed for export!" );
180 24 : if( xFamilies.is() )
181 : {
182 24 : const OUString aPageStyleName("PageStyles");
183 :
184 24 : if( xFamilies->hasByName( aPageStyleName ) )
185 : {
186 24 : xPageStyles.set(xFamilies->getByName( aPageStyleName ),uno::UNO_QUERY);
187 :
188 : DBG_ASSERT( xPageStyles.is(),
189 : "Page Styles not found for export!" );
190 24 : }
191 24 : }
192 24 : }
193 24 : }
194 :
195 24 : XMLPageExport::~XMLPageExport()
196 : {
197 24 : }
198 :
199 48 : void XMLPageExport::exportStyles( sal_Bool bUsed, sal_Bool bAutoStyles )
200 : {
201 48 : if( xPageStyles.is() )
202 : {
203 48 : uno::Sequence< OUString> aSeq = xPageStyles->getElementNames();
204 48 : const OUString* pIter = aSeq.getConstArray();
205 48 : const OUString* pEnd = pIter + aSeq.getLength();
206 408 : for(;pIter != pEnd;++pIter)
207 : {
208 360 : Reference< XStyle > xStyle(xPageStyles->getByName( *pIter ),uno::UNO_QUERY);
209 360 : if( !bUsed || xStyle->isInUse() )
210 360 : exportStyle( xStyle, bAutoStyles );
211 408 : }
212 : }
213 48 : }
214 :
215 24 : void XMLPageExport::exportAutoStyles()
216 : {
217 : rExport.GetAutoStylePool()->exportXML(XML_STYLE_FAMILY_PAGE_MASTER
218 24 : , rExport.GetDocHandler(), rExport.GetMM100UnitConverter(),
219 24 : rExport.GetNamespaceMap()
220 24 : );
221 24 : }
222 :
223 16 : void XMLPageExport::exportDefaultStyle()
224 : {
225 16 : Reference < lang::XMultiServiceFactory > xFactory (GetExport().GetModel(), UNO_QUERY);
226 16 : if (xFactory.is())
227 : {
228 16 : OUString sTextDefaults ( "com.sun.star.text.Defaults" );
229 32 : Reference < XPropertySet > xPropSet (xFactory->createInstance ( sTextDefaults ), UNO_QUERY);
230 16 : if (xPropSet.is())
231 : {
232 : // <style:default-style ...>
233 16 : GetExport().CheckAttrList();
234 :
235 : ::std::vector< XMLPropertyState > xPropStates =
236 16 : xPageMasterExportPropMapper->FilterDefaults( xPropSet );
237 :
238 16 : sal_Bool bExport = sal_False;
239 32 : UniReference < XMLPropertySetMapper > aPropMapper(xPageMasterExportPropMapper->getPropertySetMapper());
240 38 : for( ::std::vector< XMLPropertyState >::iterator aIter = xPropStates.begin(); aIter != xPropStates.end(); ++aIter )
241 : {
242 24 : XMLPropertyState *pProp = &(*aIter);
243 24 : sal_Int16 nContextId = aPropMapper->GetEntryContextId( pProp->mnIndex );
244 24 : if( nContextId == CTF_PM_STANDARD_MODE )
245 : {
246 2 : bExport = sal_True;
247 2 : break;
248 : }
249 : }
250 :
251 16 : if( bExport )
252 : {
253 : assert(GetExport().getDefaultVersion()
254 : >= SvtSaveOptions::ODFVER_012);
255 :
256 : //<style:default-page-layout>
257 2 : SvXMLElementExport aElem( GetExport(), XML_NAMESPACE_STYLE,
258 : XML_DEFAULT_PAGE_LAYOUT,
259 2 : sal_True, sal_True );
260 :
261 2 : xPageMasterExportPropMapper->exportXML( GetExport(), xPropStates,
262 2 : XML_EXPORT_FLAG_IGN_WS );
263 16 : }
264 16 : }
265 16 : }
266 16 : }
267 :
268 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|