Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : : #include <xmloff/XMLPageExport.hxx>
30 : : #include <tools/debug.hxx>
31 : : #include "xmloff/xmlnmspe.hxx"
32 : : #include <xmloff/xmltoken.hxx>
33 : : #include <com/sun/star/style/XStyleFamiliesSupplier.hpp>
34 : : #include <com/sun/star/style/XStyle.hpp>
35 : : #include <com/sun/star/container/XNameContainer.hpp>
36 : : #include <com/sun/star/container/XIndexReplace.hpp>
37 : : #include <com/sun/star/beans/XPropertySet.hpp>
38 : : #include <xmloff/families.hxx>
39 : : #include <xmloff/xmlexp.hxx>
40 : : #include "PageMasterPropHdlFactory.hxx"
41 : : #include <xmloff/PageMasterStyleMap.hxx>
42 : : #include "PageMasterPropMapper.hxx"
43 : : #include "PageMasterExportPropMapper.hxx"
44 : :
45 : : using ::rtl::OUString;
46 : : using ::rtl::OUStringBuffer;
47 : :
48 : : using namespace ::com::sun::star;
49 : : using namespace ::com::sun::star::uno;
50 : : using namespace ::com::sun::star::style;
51 : : using namespace ::com::sun::star::container;
52 : : using namespace ::com::sun::star::beans;
53 : : using namespace ::xmloff::token;
54 : :
55 : :
56 : : //______________________________________________________________________________
57 : :
58 : 32 : sal_Bool XMLPageExport::findPageMasterName( const OUString& rStyleName, OUString& rPMName ) const
59 : : {
60 [ + - ][ + - ]: 78 : for( ::std::vector< XMLPageExportNameEntry >::const_iterator pEntry = aNameVector.begin();
61 : 39 : pEntry != aNameVector.end(); ++pEntry )
62 : : {
63 [ + + ]: 39 : if( pEntry->sStyleName == rStyleName )
64 : : {
65 : 32 : rPMName = pEntry->sPageMasterName;
66 : 32 : return sal_True;
67 : : }
68 : : }
69 : 32 : return sal_False;
70 : : }
71 : :
72 : 32 : void XMLPageExport::collectPageMasterAutoStyle(
73 : : const Reference < XPropertySet > & rPropSet,
74 : : OUString& rPageMasterName )
75 : : {
76 : : DBG_ASSERT( xPageMasterPropSetMapper.is(), "page master family/XMLPageMasterPropSetMapper not found" );
77 [ + - ]: 32 : if( xPageMasterPropSetMapper.is() )
78 : : {
79 [ + - ][ + - ]: 32 : ::std::vector<XMLPropertyState> xPropStates = xPageMasterExportPropMapper->Filter( rPropSet );
80 [ + - ]: 32 : if( !xPropStates.empty())
81 : : {
82 : 32 : OUString sParent;
83 [ + - ][ + - ]: 32 : rPageMasterName = rExport.GetAutoStylePool()->Find( XML_STYLE_FAMILY_PAGE_MASTER, sParent, xPropStates );
[ + - ][ + - ]
84 [ + - ]: 32 : if (rPageMasterName.isEmpty())
85 [ + - ][ + - ]: 32 : rPageMasterName = rExport.GetAutoStylePool()->Add(XML_STYLE_FAMILY_PAGE_MASTER, sParent, xPropStates);
[ + - ][ + - ]
86 : 32 : }
87 : : }
88 : 32 : }
89 : :
90 : 0 : void XMLPageExport::exportMasterPageContent(
91 : : const Reference < XPropertySet > &,
92 : : sal_Bool /*bAutoStyles*/ )
93 : : {
94 : :
95 : 0 : }
96 : :
97 : 442 : sal_Bool XMLPageExport::exportStyle(
98 : : const Reference< XStyle >& rStyle,
99 : : sal_Bool bAutoStyles )
100 : : {
101 [ + - ]: 442 : Reference< XPropertySet > xPropSet( rStyle, UNO_QUERY );
102 [ + - ][ + - ]: 442 : Reference< XPropertySetInfo > xPropSetInfo = xPropSet->getPropertySetInfo();
103 : :
104 : : // Don't export styles that aren't existing really. This may be the
105 : : // case for StarOffice Writer's pool styles.
106 [ + - ][ + - ]: 442 : if( xPropSetInfo->hasPropertyByName( sIsPhysical ) )
[ + + ]
107 : : {
108 [ + - ][ + - ]: 426 : Any aAny = xPropSet->getPropertyValue( sIsPhysical );
109 [ + + ]: 426 : if( !*(sal_Bool *)aAny.getValue() )
110 [ + + ]: 426 : return sal_False;
111 : : }
112 : :
113 [ + + ]: 64 : if( bAutoStyles )
114 : : {
115 : 32 : XMLPageExportNameEntry aEntry;
116 [ + - ]: 32 : collectPageMasterAutoStyle( xPropSet, aEntry.sPageMasterName );
117 [ + - ][ + - ]: 32 : aEntry.sStyleName = rStyle->getName();
118 [ + - ]: 32 : aNameVector.push_back( aEntry );
119 : :
120 [ + - ]: 32 : exportMasterPageContent( xPropSet, sal_True );
121 : : }
122 : : else
123 : : {
124 [ + - ][ + - ]: 32 : OUString sName( rStyle->getName() );
125 : 32 : sal_Bool bEncoded = sal_False;
126 : 32 : GetExport().AddAttribute( XML_NAMESPACE_STYLE, XML_NAME,
127 [ + - + - ]: 64 : GetExport().EncodeStyleName( sName, &bEncoded ) );
128 : :
129 [ - + ]: 32 : if( bEncoded )
130 : 0 : GetExport().AddAttribute( XML_NAMESPACE_STYLE, XML_DISPLAY_NAME,
131 [ # # ]: 0 : sName);
132 : :
133 : 32 : OUString sPMName;
134 [ + - ][ + - ]: 32 : if( findPageMasterName( sName, sPMName ) )
135 [ + - ][ + - ]: 32 : GetExport().AddAttribute( XML_NAMESPACE_STYLE, XML_PAGE_LAYOUT_NAME, GetExport().EncodeStyleName( sPMName ) );
136 : :
137 [ + - ][ + - ]: 32 : Reference<XPropertySetInfo> xInfo = xPropSet->getPropertySetInfo();
138 [ + - ][ + - ]: 32 : if ( xInfo.is() && xInfo->hasPropertyByName(sFollowStyle) )
[ + - ][ + + ]
[ + + ]
139 : : {
140 : 24 : OUString sNextName;
141 [ + - ][ + - ]: 24 : xPropSet->getPropertyValue( sFollowStyle ) >>= sNextName;
142 : :
143 [ # # ][ - + ]: 24 : if( sName != sNextName && !sNextName.isEmpty() )
[ - + ]
144 : : {
145 : 0 : GetExport().AddAttribute( XML_NAMESPACE_STYLE, XML_NEXT_STYLE_NAME,
146 [ # # # # ]: 0 : GetExport().EncodeStyleName( sNextName ) );
147 : 24 : }
148 : : }
149 : :
150 : 32 : SvXMLElementExport aElem( GetExport(), XML_NAMESPACE_STYLE,
151 [ + - ]: 32 : XML_MASTER_PAGE, sal_True, sal_True );
152 : :
153 [ + - ][ + - ]: 32 : exportMasterPageContent( xPropSet, sal_False );
154 : : }
155 : :
156 : 442 : return sal_True;
157 : : }
158 : :
159 : 25 : XMLPageExport::XMLPageExport( SvXMLExport& rExp ) :
160 : : rExport( rExp ),
161 : : sIsPhysical( RTL_CONSTASCII_USTRINGPARAM( "IsPhysical" ) ),
162 [ + - ][ + - ]: 25 : sFollowStyle( RTL_CONSTASCII_USTRINGPARAM( "FollowStyle" ) )
[ + - ]
163 : : {
164 [ + - ][ + - ]: 25 : xPageMasterPropHdlFactory = new XMLPageMasterPropHdlFactory;
[ + - ]
165 : : xPageMasterPropSetMapper = new XMLPageMasterPropSetMapper(
166 : : (XMLPropertyMapEntry*) aXMLPageMasterStyleMap,
167 [ + - ][ + - ]: 25 : xPageMasterPropHdlFactory );
[ + - ]
168 : : xPageMasterExportPropMapper = new XMLPageMasterExportPropMapper(
169 [ + - ][ + - ]: 25 : xPageMasterPropSetMapper, rExp);
[ + - ]
170 : :
171 : : rExport.GetAutoStylePool()->AddFamily( XML_STYLE_FAMILY_PAGE_MASTER, OUString( RTL_CONSTASCII_USTRINGPARAM( XML_STYLE_FAMILY_PAGE_MASTER_NAME ) ),
172 [ + - ][ + - ]: 25 : xPageMasterExportPropMapper, OUString( RTL_CONSTASCII_USTRINGPARAM( XML_STYLE_FAMILY_PAGE_MASTER_PREFIX ) ), sal_False );
[ + - ][ + - ]
[ + - ][ + - ]
173 : :
174 : 25 : Reference< XStyleFamiliesSupplier > xFamiliesSupp( GetExport().GetModel(),
175 [ + - ]: 25 : UNO_QUERY );
176 : : DBG_ASSERT( xFamiliesSupp.is(),
177 : : "No XStyleFamiliesSupplier from XModel for export!" );
178 [ + - ]: 25 : if( xFamiliesSupp.is() )
179 : : {
180 [ + - ][ + - ]: 25 : Reference< XNameAccess > xFamilies( xFamiliesSupp->getStyleFamilies() );
181 : : DBG_ASSERT( xFamiliesSupp.is(),
182 : : "getStyleFamilies() from XModel failed for export!" );
183 [ + - ]: 25 : if( xFamilies.is() )
184 : : {
185 : : const OUString aPageStyleName(
186 [ + - ]: 25 : RTL_CONSTASCII_USTRINGPARAM( "PageStyles" ));
187 : :
188 [ + - ][ + - ]: 25 : if( xFamilies->hasByName( aPageStyleName ) )
[ + - ]
189 : : {
190 [ + - ][ + - ]: 25 : xPageStyles.set(xFamilies->getByName( aPageStyleName ),uno::UNO_QUERY);
[ + - ]
191 : :
192 : : DBG_ASSERT( xPageStyles.is(),
193 : : "Page Styles not found for export!" );
194 : 25 : }
195 : 25 : }
196 : 25 : }
197 : 25 : }
198 : :
199 [ + - ][ + - ]: 25 : XMLPageExport::~XMLPageExport()
[ + - ]
200 : : {
201 [ - + ]: 25 : }
202 : :
203 : 50 : void XMLPageExport::exportStyles( sal_Bool bUsed, sal_Bool bAutoStyles )
204 : : {
205 [ + - ]: 50 : if( xPageStyles.is() )
206 : : {
207 [ + - ][ + - ]: 50 : uno::Sequence< ::rtl::OUString> aSeq = xPageStyles->getElementNames();
208 : 50 : const ::rtl::OUString* pIter = aSeq.getConstArray();
209 : 50 : const ::rtl::OUString* pEnd = pIter + aSeq.getLength();
210 [ + + ]: 492 : for(;pIter != pEnd;++pIter)
211 : : {
212 [ + - ][ + - ]: 442 : Reference< XStyle > xStyle(xPageStyles->getByName( *pIter ),uno::UNO_QUERY);
[ + - ]
213 [ + - ][ + - ]: 442 : if( !bUsed || xStyle->isInUse() )
[ + - ][ + - ]
[ + + ]
214 [ + - ]: 442 : exportStyle( xStyle, bAutoStyles );
215 [ + - ]: 492 : }
216 : : }
217 : 50 : }
218 : :
219 : 25 : void XMLPageExport::exportAutoStyles()
220 : : {
221 : : rExport.GetAutoStylePool()->exportXML(XML_STYLE_FAMILY_PAGE_MASTER
222 : 25 : , rExport.GetDocHandler(), rExport.GetMM100UnitConverter(),
223 : 25 : rExport.GetNamespaceMap()
224 [ + - ][ + - ]: 25 : );
225 : 25 : }
226 : :
227 : 21 : void XMLPageExport::exportDefaultStyle()
228 : : {
229 [ + - ]: 21 : Reference < lang::XMultiServiceFactory > xFactory (GetExport().GetModel(), UNO_QUERY);
230 [ + - ]: 21 : if (xFactory.is())
231 : : {
232 [ + - ]: 21 : OUString sTextDefaults ( RTL_CONSTASCII_USTRINGPARAM ( "com.sun.star.text.Defaults" ) );
233 [ + - ][ + - ]: 21 : Reference < XPropertySet > xPropSet (xFactory->createInstance ( sTextDefaults ), UNO_QUERY);
[ + - ]
234 [ + - ]: 21 : if (xPropSet.is())
235 : : {
236 : : // <style:default-style ...>
237 : 21 : GetExport().CheckAttrList();
238 : :
239 : : ::std::vector< XMLPropertyState > xPropStates =
240 [ + - ][ + - ]: 21 : xPageMasterExportPropMapper->FilterDefaults( xPropSet );
241 : :
242 : 21 : sal_Bool bExport = sal_False;
243 [ + - ][ + - ]: 21 : UniReference < XMLPropertySetMapper > aPropMapper(xPageMasterExportPropMapper->getPropertySetMapper());
244 [ + - ][ + + ]: 51 : for( ::std::vector< XMLPropertyState >::iterator aIter = xPropStates.begin(); aIter != xPropStates.end(); ++aIter )
245 : : {
246 : 30 : XMLPropertyState *pProp = &(*aIter);
247 [ + - ][ + - ]: 30 : sal_Int16 nContextId = aPropMapper->GetEntryContextId( pProp->mnIndex );
248 [ - + ]: 30 : if( nContextId == CTF_PM_STANDARD_MODE )
249 : : {
250 : 0 : bExport = sal_True;
251 : 0 : break;
252 : : }
253 : : }
254 : :
255 [ - + ]: 21 : if( bExport )
256 : : {
257 : : assert(GetExport().getDefaultVersion()
258 : : >= SvtSaveOptions::ODFVER_012);
259 : :
260 : : //<style:default-page-layout>
261 : 0 : SvXMLElementExport aElem( GetExport(), XML_NAMESPACE_STYLE,
262 : : XML_DEFAULT_PAGE_LAYOUT,
263 [ # # ]: 0 : sal_True, sal_True );
264 : :
265 : 0 : xPageMasterExportPropMapper->exportXML( GetExport(), xPropStates,
266 [ # # ][ # # ]: 0 : XML_EXPORT_FLAG_IGN_WS );
[ # # ]
267 [ + - ]: 21 : }
268 : 21 : }
269 : 21 : }
270 : 21 : }
271 : :
272 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|