1 /**************************************************************
2 *
3 * Licensed to the Apache Software Foundation (ASF) under one
4 * or more contributor license agreements. See the NOTICE file
5 * distributed with this work for additional information
6 * regarding copyright ownership. The ASF licenses this file
7 * to you under the Apache License, Version 2.0 (the
8 * "License"); you may not use this file except in compliance
9 * with the License. You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing,
14 * software distributed under the License is distributed on an
15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 * KIND, either express or implied. See the License for the
17 * specific language governing permissions and limitations
18 * under the License.
19 *
20 *************************************************************/
21
22
23
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_xmloff.hxx"
26 #include <xmloff/XMLPageExport.hxx>
27 #include <tools/debug.hxx>
28 #include "xmloff/xmlnmspe.hxx"
29 #include <xmloff/xmltoken.hxx>
30 #include <com/sun/star/style/XStyleFamiliesSupplier.hpp>
31 #include <com/sun/star/style/XStyle.hpp>
32 #include <com/sun/star/container/XNameContainer.hpp>
33 #include <com/sun/star/container/XIndexReplace.hpp>
34 #include <com/sun/star/beans/XPropertySet.hpp>
35 #include <xmloff/families.hxx>
36 #include <xmloff/xmlexp.hxx>
37 #include "PageMasterPropHdlFactory.hxx"
38 #ifndef _XMLOFF_PAGEMASTERSTYLEMAP_HXX
39 #include <xmloff/PageMasterStyleMap.hxx>
40 #endif
41 #ifndef _XMLOFF_PAGEMASTERPROPMAPPER_HXX
42 #include "PageMasterPropMapper.hxx"
43 #endif
44 #include "PageMasterExportPropMapper.hxx"
45 #include "PageMasterExportPropMapper.hxx"
46
47 using ::rtl::OUString;
48 using ::rtl::OUStringBuffer;
49
50 using namespace ::com::sun::star;
51 using namespace ::com::sun::star::uno;
52 using namespace ::com::sun::star::style;
53 using namespace ::com::sun::star::container;
54 using namespace ::com::sun::star::beans;
55 using namespace ::xmloff::token;
56
57
58 //______________________________________________________________________________
59
findPageMasterName(const OUString & rStyleName,OUString & rPMName) const60 sal_Bool XMLPageExport::findPageMasterName( const OUString& rStyleName, OUString& rPMName ) const
61 {
62 for( ::std::vector< XMLPageExportNameEntry >::const_iterator pEntry = aNameVector.begin();
63 pEntry != aNameVector.end(); pEntry++ )
64 {
65 if( pEntry->sStyleName == rStyleName )
66 {
67 rPMName = pEntry->sPageMasterName;
68 return sal_True;
69 }
70 }
71 return sal_False;
72 }
73
collectPageMasterAutoStyle(const Reference<XPropertySet> & rPropSet,OUString & rPageMasterName)74 void XMLPageExport::collectPageMasterAutoStyle(
75 const Reference < XPropertySet > & rPropSet,
76 OUString& rPageMasterName )
77 {
78 DBG_ASSERT( xPageMasterPropSetMapper.is(), "page master family/XMLPageMasterPropSetMapper not found" );
79 if( xPageMasterPropSetMapper.is() )
80 {
81 ::std::vector<XMLPropertyState> xPropStates = xPageMasterExportPropMapper->Filter( rPropSet );
82 if( !xPropStates.empty())
83 {
84 OUString sParent;
85 rPageMasterName = rExport.GetAutoStylePool()->Find( XML_STYLE_FAMILY_PAGE_MASTER, sParent, xPropStates );
86 if (!rPageMasterName.getLength())
87 rPageMasterName = rExport.GetAutoStylePool()->Add(XML_STYLE_FAMILY_PAGE_MASTER, sParent, xPropStates);
88 }
89 }
90 }
91
exportMasterPageContent(const Reference<XPropertySet> &,sal_Bool)92 void XMLPageExport::exportMasterPageContent(
93 const Reference < XPropertySet > &,
94 sal_Bool /*bAutoStyles*/ )
95 {
96
97 }
98
exportStyle(const Reference<XStyle> & rStyle,sal_Bool bAutoStyles)99 sal_Bool XMLPageExport::exportStyle(
100 const Reference< XStyle >& rStyle,
101 sal_Bool bAutoStyles )
102 {
103 Reference< XPropertySet > xPropSet( rStyle, UNO_QUERY );
104 Reference< XPropertySetInfo > xPropSetInfo = xPropSet->getPropertySetInfo();
105
106 // Don't export styles that aren't existing really. This may be the
107 // case for StarOffice Writer's pool styles.
108 if( xPropSetInfo->hasPropertyByName( sIsPhysical ) )
109 {
110 Any aAny = xPropSet->getPropertyValue( sIsPhysical );
111 if( !*(sal_Bool *)aAny.getValue() )
112 return sal_False;
113 }
114
115 if( bAutoStyles )
116 {
117 XMLPageExportNameEntry aEntry;
118 collectPageMasterAutoStyle( xPropSet, aEntry.sPageMasterName );
119 aEntry.sStyleName = rStyle->getName();
120 aNameVector.push_back( aEntry );
121
122 exportMasterPageContent( xPropSet, sal_True );
123 }
124 else
125 {
126 OUString sName( rStyle->getName() );
127 sal_Bool bEncoded = sal_False;
128 GetExport().AddAttribute( XML_NAMESPACE_STYLE, XML_NAME,
129 GetExport().EncodeStyleName( sName, &bEncoded ) );
130
131 if( bEncoded )
132 GetExport().AddAttribute( XML_NAMESPACE_STYLE, XML_DISPLAY_NAME,
133 sName);
134
135 OUString sPMName;
136 if( findPageMasterName( sName, sPMName ) )
137 GetExport().AddAttribute( XML_NAMESPACE_STYLE, XML_PAGE_LAYOUT_NAME, GetExport().EncodeStyleName( sPMName ) );
138
139 Reference<XPropertySetInfo> xInfo = xPropSet->getPropertySetInfo();
140 if ( xInfo.is() && xInfo->hasPropertyByName(sFollowStyle) )
141 {
142 OUString sNextName;
143 xPropSet->getPropertyValue( sFollowStyle ) >>= sNextName;
144
145 if( sName != sNextName && sNextName.getLength() )
146 {
147 GetExport().AddAttribute( XML_NAMESPACE_STYLE, XML_NEXT_STYLE_NAME,
148 GetExport().EncodeStyleName( sNextName ) );
149 }
150 }
151 // OUString sPageMaster = GetExport().GetAutoStylePool()->Find(
152 // XML_STYLE_FAMILY_PAGE_MASTER,
153 // xPropSet );
154 // if( sPageMaster.getLength() )
155 // GetExport().AddAttribute( XML_NAMESPACE_STYLE,
156 // XML_PAGE_MASTER_NAME,
157 // sPageMaster );
158
159 SvXMLElementExport aElem( GetExport(), XML_NAMESPACE_STYLE,
160 XML_MASTER_PAGE, sal_True, sal_True );
161
162 exportMasterPageContent( xPropSet, sal_False );
163 }
164
165 return sal_True;
166 }
167
XMLPageExport(SvXMLExport & rExp)168 XMLPageExport::XMLPageExport( SvXMLExport& rExp ) :
169 rExport( rExp ),
170 sIsPhysical( RTL_CONSTASCII_USTRINGPARAM( "IsPhysical" ) ),
171 sFollowStyle( RTL_CONSTASCII_USTRINGPARAM( "FollowStyle" ) )
172 {
173 xPageMasterPropHdlFactory = new XMLPageMasterPropHdlFactory;
174 xPageMasterPropSetMapper = new XMLPageMasterPropSetMapper(
175 (XMLPropertyMapEntry*) aXMLPageMasterStyleMap,
176 xPageMasterPropHdlFactory );
177 xPageMasterExportPropMapper = new XMLPageMasterExportPropMapper(
178 xPageMasterPropSetMapper, rExp);
179
180 rExport.GetAutoStylePool()->AddFamily( XML_STYLE_FAMILY_PAGE_MASTER, OUString( RTL_CONSTASCII_USTRINGPARAM( XML_STYLE_FAMILY_PAGE_MASTER_NAME ) ),
181 xPageMasterExportPropMapper, OUString( RTL_CONSTASCII_USTRINGPARAM( XML_STYLE_FAMILY_PAGE_MASTER_PREFIX ) ), sal_False );
182
183 Reference< XStyleFamiliesSupplier > xFamiliesSupp( GetExport().GetModel(),
184 UNO_QUERY );
185 DBG_ASSERT( xFamiliesSupp.is(),
186 "No XStyleFamiliesSupplier from XModel for export!" );
187 if( xFamiliesSupp.is() )
188 {
189 Reference< XNameAccess > xFamilies( xFamiliesSupp->getStyleFamilies() );
190 DBG_ASSERT( xFamiliesSupp.is(),
191 "getStyleFamilies() from XModel failed for export!" );
192 if( xFamilies.is() )
193 {
194 const OUString aPageStyleName(
195 RTL_CONSTASCII_USTRINGPARAM( "PageStyles" ));
196
197 if( xFamilies->hasByName( aPageStyleName ) )
198 {
199 xPageStyles.set(xFamilies->getByName( aPageStyleName ),uno::UNO_QUERY);
200
201 DBG_ASSERT( xPageStyles.is(),
202 "Page Styles not found for export!" );
203 }
204 }
205 }
206 }
207
~XMLPageExport()208 XMLPageExport::~XMLPageExport()
209 {
210 }
211
exportStyles(sal_Bool bUsed,sal_Bool bAutoStyles)212 void XMLPageExport::exportStyles( sal_Bool bUsed, sal_Bool bAutoStyles )
213 {
214 if( xPageStyles.is() )
215 {
216 uno::Sequence< ::rtl::OUString> aSeq = xPageStyles->getElementNames();
217 const ::rtl::OUString* pIter = aSeq.getConstArray();
218 const ::rtl::OUString* pEnd = pIter + aSeq.getLength();
219 for(;pIter != pEnd;++pIter)
220 {
221 Reference< XStyle > xStyle(xPageStyles->getByName( *pIter ),uno::UNO_QUERY);
222 if( !bUsed || xStyle->isInUse() )
223 exportStyle( xStyle, bAutoStyles );
224 }
225 }
226 }
227
exportAutoStyles()228 void XMLPageExport::exportAutoStyles()
229 {
230 rExport.GetAutoStylePool()->exportXML(XML_STYLE_FAMILY_PAGE_MASTER
231 , rExport.GetDocHandler(), rExport.GetMM100UnitConverter(),
232 rExport.GetNamespaceMap()
233 );
234 }
235
exportDefaultStyle()236 void XMLPageExport::exportDefaultStyle()
237 {
238 Reference < lang::XMultiServiceFactory > xFactory (GetExport().GetModel(), UNO_QUERY);
239 if (xFactory.is())
240 {
241 OUString sTextDefaults ( RTL_CONSTASCII_USTRINGPARAM ( "com.sun.star.text.Defaults" ) );
242 Reference < XPropertySet > xPropSet (xFactory->createInstance ( sTextDefaults ), UNO_QUERY);
243 if (xPropSet.is())
244 {
245 // <style:default-style ...>
246 GetExport().CheckAttrList();
247
248 ::std::vector< XMLPropertyState > xPropStates =
249 xPageMasterExportPropMapper->FilterDefaults( xPropSet );
250
251 sal_Bool bExport = sal_False;
252 UniReference < XMLPropertySetMapper > aPropMapper(xPageMasterExportPropMapper->getPropertySetMapper());
253 for( ::std::vector< XMLPropertyState >::iterator aIter = xPropStates.begin(); aIter != xPropStates.end(); ++aIter )
254 {
255 XMLPropertyState *pProp = &(*aIter);
256 sal_Int16 nContextId = aPropMapper->GetEntryContextId( pProp->mnIndex );
257 if( nContextId == CTF_PM_STANDARD_MODE )
258 {
259 bExport = sal_True;
260 break;
261 }
262 }
263
264 // if ( xPropStates.size() != 0 &&
265 // ( xPropStates.size() != 1 || xPropStates[0].mnIndex != -1 ) )
266 if( bExport )
267 {
268 //<style:default-page-layout>
269 SvXMLElementExport aElem( GetExport(), XML_NAMESPACE_STYLE,
270 XML_DEFAULT_PAGE_LAYOUT,
271 sal_True, sal_True );
272
273 xPageMasterExportPropMapper->exportXML( GetExport(), xPropStates,
274 XML_EXPORT_FLAG_IGN_WS );
275 }
276 }
277 }
278 }
279