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