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