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
27
28 #include <com/sun/star/container/XIndexReplace.hpp>
29 #include <tools/debug.hxx>
30 #include "impastpl.hxx"
31 #include <xmloff/xmlaustp.hxx>
32 #include <xmloff/families.hxx>
33 #include "xmloff/xmlnmspe.hxx"
34 #include <xmloff/xmltoken.hxx>
35 #include <xmloff/xmlexp.hxx>
36 #include "xmloff/XMLTextListAutoStylePool.hxx"
37
38 #ifndef _XMLOFF_PAGEMASTERSTYLEMAP_HXX
39 #include <xmloff/PageMasterStyleMap.hxx>
40 #endif
41 #include "PageMasterExportPropMapper.hxx"
42 #include "XMLBackgroundImageExport.hxx"
43
44
45 using namespace ::std;
46 using ::rtl::OUString;
47 using ::rtl::OUStringBuffer;
48
49 using namespace ::com::sun::star;
50 using namespace ::xmloff::token;
51
52
53 namespace
54 {
lcl_exportDataStyle(SvXMLExport & _rExport,const UniReference<XMLPropertySetMapper> & _rxMapper,const XMLPropertyState & _rProperty)55 static void lcl_exportDataStyle( SvXMLExport& _rExport, const UniReference< XMLPropertySetMapper >& _rxMapper,
56 const XMLPropertyState& _rProperty )
57 {
58 DBG_ASSERT( _rxMapper.is(), "xmloff::lcl_exportDataStyle: invalid property mapper!" );
59 // obtain the data style name
60 ::rtl::OUString sDataStyleName;
61 _rProperty.maValue >>= sDataStyleName;
62 DBG_ASSERT( sDataStyleName.getLength(), "xmloff::lcl_exportDataStyle: invalid property value for the data style name!" );
63
64 // add the attribute
65 _rExport.AddAttribute(
66 _rxMapper->GetEntryNameSpace( _rProperty.mnIndex ),
67 _rxMapper->GetEntryXMLName( _rProperty.mnIndex ),
68 sDataStyleName );
69 }
70 }
71
exportStyleAttributes(SvXMLAttributeList &,sal_Int32 nFamily,const vector<XMLPropertyState> & rProperties,const SvXMLExportPropertyMapper & rPropExp,const SvXMLUnitConverter &,const SvXMLNamespaceMap &) const72 void SvXMLAutoStylePoolP::exportStyleAttributes(
73 SvXMLAttributeList&,
74 sal_Int32 nFamily,
75 const vector< XMLPropertyState >& rProperties,
76 const SvXMLExportPropertyMapper& rPropExp,
77 const SvXMLUnitConverter&,
78 const SvXMLNamespaceMap&
79 ) const
80 {
81 if ( XML_STYLE_FAMILY_CONTROL_ID == nFamily )
82 { // it's a control-related style
83 UniReference< XMLPropertySetMapper > aPropertyMapper = rPropExp.getPropertySetMapper();
84
85 for ( vector< XMLPropertyState >::const_iterator pProp = rProperties.begin();
86 pProp != rProperties.end();
87 ++pProp
88 )
89 {
90 if ( ( pProp->mnIndex > -1 )
91 && ( CTF_FORMS_DATA_STYLE == aPropertyMapper->GetEntryContextId( pProp->mnIndex ) )
92 )
93 { // it's the data-style for a grid column
94 lcl_exportDataStyle( GetExport(), aPropertyMapper, *pProp );
95 }
96 }
97 }
98
99 if( (XML_STYLE_FAMILY_SD_GRAPHICS_ID == nFamily) || (XML_STYLE_FAMILY_SD_PRESENTATION_ID == nFamily) )
100 { // it's a graphics style
101 UniReference< XMLPropertySetMapper > aPropertyMapper = rPropExp.getPropertySetMapper();
102 DBG_ASSERT(aPropertyMapper.is(), "SvXMLAutoStylePoolP::exportStyleAttributes: invalid property set mapper!");
103
104 sal_Bool bFoundControlShapeDataStyle = sal_False;
105 sal_Bool bFoundNumberingRulesName = sal_False;
106
107 for ( vector< XMLPropertyState >::const_iterator pProp = rProperties.begin();
108 pProp != rProperties.end();
109 ++pProp
110 )
111 {
112 if (pProp->mnIndex > -1)
113 { // it's a valid property
114 switch( aPropertyMapper->GetEntryContextId(pProp->mnIndex) )
115 {
116 case CTF_SD_CONTROL_SHAPE_DATA_STYLE:
117 { // it's the control shape data style property
118
119 if (bFoundControlShapeDataStyle)
120 {
121 DBG_ERROR("SvXMLAutoStylePoolP::exportStyleAttributes: found two properties with the ControlShapeDataStyle context id!");
122 // already added the attribute for the first occurence
123 break;
124 }
125
126 lcl_exportDataStyle( GetExport(), aPropertyMapper, *pProp );
127
128 // check if there is another property with the special context id we're handling here
129 bFoundControlShapeDataStyle = sal_True;
130 break;
131 }
132 case CTF_SD_NUMBERINGRULES_NAME:
133 {
134 if (bFoundNumberingRulesName)
135 {
136 DBG_ERROR("SvXMLAutoStylePoolP::exportStyleAttributes: found two properties with the numbering rules name context id!");
137 // already added the attribute for the first occurence
138 break;
139 }
140
141 uno::Reference< container::XIndexReplace > xNumRule;
142 pProp->maValue >>= xNumRule;
143 if( xNumRule.is() && (xNumRule->getCount() > 0 ) )
144 {
145 const OUString sName(((XMLTextListAutoStylePool*)&GetExport().GetTextParagraphExport()->GetListAutoStylePool())->Add( xNumRule ));
146
147 GetExport().AddAttribute( XML_NAMESPACE_STYLE, XML_LIST_STYLE_NAME, GetExport().EncodeStyleName( sName ) );
148 }
149
150 bFoundNumberingRulesName = sal_True;
151 break;
152 }
153 }
154 }
155 }
156 }
157
158 if( nFamily == XML_STYLE_FAMILY_PAGE_MASTER )
159 {
160 for( vector< XMLPropertyState >::const_iterator pProp = rProperties.begin(); pProp != rProperties.end(); pProp++ )
161 {
162 if (pProp->mnIndex > -1)
163 {
164 UniReference< XMLPropertySetMapper > aPropMapper = rPropExp.getPropertySetMapper();
165 sal_Int32 nIndex = pProp->mnIndex;
166 sal_Int16 nContextID = aPropMapper->GetEntryContextId( nIndex );
167 switch( nContextID )
168 {
169 case CTF_PM_PAGEUSAGE:
170 {
171 OUString sValue;
172 const XMLPropertyHandler* pPropHdl = aPropMapper->GetPropertyHandler( nIndex );
173 if( pPropHdl &&
174 pPropHdl->exportXML( sValue, pProp->maValue,
175 GetExport().GetMM100UnitConverter() ) &&
176 ( ! IsXMLToken( sValue, XML_ALL ) ) )
177 {
178 GetExport().AddAttribute( aPropMapper->GetEntryNameSpace( nIndex ), aPropMapper->GetEntryXMLName( nIndex ), sValue );
179 }
180 }
181 break;
182 }
183 }
184 }
185 }
186 }
187
exportStyleContent(const::com::sun::star::uno::Reference<::com::sun::star::xml::sax::XDocumentHandler> &,sal_Int32 nFamily,const vector<XMLPropertyState> & rProperties,const SvXMLExportPropertyMapper & rPropExp,const SvXMLUnitConverter &,const SvXMLNamespaceMap &) const188 void SvXMLAutoStylePoolP::exportStyleContent(
189 const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XDocumentHandler > &,
190 sal_Int32 nFamily,
191 const vector< XMLPropertyState >& rProperties,
192 const SvXMLExportPropertyMapper& rPropExp,
193 const SvXMLUnitConverter&,
194 const SvXMLNamespaceMap&
195 ) const
196 {
197 if( nFamily == XML_STYLE_FAMILY_PAGE_MASTER )
198 {
199 OUString sWS( GetXMLToken(XML_WS) );
200
201 sal_Int32 nHeaderStartIndex(-1);
202 sal_Int32 nHeaderEndIndex(-1);
203 sal_Int32 nFooterStartIndex(-1);
204 sal_Int32 nFooterEndIndex(-1);
205 sal_Bool bHeaderStartIndex(sal_False);
206 sal_Bool bHeaderEndIndex(sal_False);
207 sal_Bool bFooterStartIndex(sal_False);
208 sal_Bool bFooterEndIndex(sal_False);
209
210 UniReference< XMLPropertySetMapper > aPropMapper = rPropExp.getPropertySetMapper();
211
212 sal_Int32 nIndex(0);
213 while(nIndex < aPropMapper->GetEntryCount())
214 {
215 switch( aPropMapper->GetEntryContextId( nIndex ) & CTF_PM_FLAGMASK )
216 {
217 case CTF_PM_HEADERFLAG:
218 {
219 if (!bHeaderStartIndex)
220 {
221 nHeaderStartIndex = nIndex;
222 bHeaderStartIndex = sal_True;
223 }
224 if (bFooterStartIndex && !bFooterEndIndex)
225 {
226 nFooterEndIndex = nIndex;
227 bFooterEndIndex = sal_True;
228 }
229 }
230 break;
231 case CTF_PM_FOOTERFLAG:
232 {
233 if (!bFooterStartIndex)
234 {
235 nFooterStartIndex = nIndex;
236 bFooterStartIndex = sal_True;
237 }
238 if (bHeaderStartIndex && !bHeaderEndIndex)
239 {
240 nHeaderEndIndex = nIndex;
241 bHeaderEndIndex = sal_True;
242 }
243 }
244 break;
245 }
246 nIndex++;
247 }
248 if (!bHeaderEndIndex)
249 nHeaderEndIndex = nIndex;
250 if (!bFooterEndIndex)
251 nFooterEndIndex = nIndex;
252
253 // export header style element
254 {
255 SvXMLElementExport aElem(
256 GetExport(), XML_NAMESPACE_STYLE, XML_HEADER_STYLE,
257 sal_True, sal_True );
258
259 rPropExp.exportXML(
260 GetExport(), rProperties,
261 nHeaderStartIndex, nHeaderEndIndex, XML_EXPORT_FLAG_IGN_WS);
262 }
263
264 // export footer style
265 {
266 SvXMLElementExport aElem(
267 GetExport(), XML_NAMESPACE_STYLE, XML_FOOTER_STYLE,
268 sal_True, sal_True );
269
270 rPropExp.exportXML(
271 GetExport(), rProperties,
272 nFooterStartIndex, nFooterEndIndex, XML_EXPORT_FLAG_IGN_WS);
273 }
274 }
275 }
276
SvXMLAutoStylePoolP()277 SvXMLAutoStylePoolP::SvXMLAutoStylePoolP()
278 {
279 DBG_ERROR("This constuctor is obsoleted and should not be used!");
280 pImpl = NULL;
281 }
282
SvXMLAutoStylePoolP(SvXMLExport & rExport)283 SvXMLAutoStylePoolP::SvXMLAutoStylePoolP( SvXMLExport& rExport )
284 {
285 pImpl = new SvXMLAutoStylePoolP_Impl( rExport );
286 }
287
~SvXMLAutoStylePoolP()288 SvXMLAutoStylePoolP::~SvXMLAutoStylePoolP()
289 {
290 delete pImpl;
291 }
292
GetExport() const293 SvXMLExport& SvXMLAutoStylePoolP::GetExport() const
294 {
295 return pImpl->GetExport();
296 }
297
298 // TODO: romove this
AddFamily(sal_Int32 nFamily,const OUString & rStrName,SvXMLExportPropertyMapper * pMapper,OUString aStrPrefix,sal_Bool bAsFamily)299 void SvXMLAutoStylePoolP::AddFamily(
300 sal_Int32 nFamily,
301 const OUString& rStrName,
302 SvXMLExportPropertyMapper* pMapper,
303 OUString aStrPrefix,
304 sal_Bool bAsFamily )
305 {
306 UniReference <SvXMLExportPropertyMapper> xTmp = pMapper;
307 AddFamily( nFamily, rStrName, xTmp, aStrPrefix, bAsFamily );
308 }
309
AddFamily(sal_Int32 nFamily,const OUString & rStrName,const UniReference<SvXMLExportPropertyMapper> & rMapper,const OUString & rStrPrefix,sal_Bool bAsFamily)310 void SvXMLAutoStylePoolP::AddFamily(
311 sal_Int32 nFamily,
312 const OUString& rStrName,
313 const UniReference < SvXMLExportPropertyMapper > & rMapper,
314 const OUString& rStrPrefix,
315 sal_Bool bAsFamily )
316 {
317 pImpl->AddFamily( nFamily, rStrName, rMapper, rStrPrefix, bAsFamily );
318 }
319
RegisterName(sal_Int32 nFamily,const OUString & rName)320 void SvXMLAutoStylePoolP::RegisterName( sal_Int32 nFamily,
321 const OUString& rName )
322 {
323 pImpl->RegisterName( nFamily, rName );
324 }
325
GetRegisteredNames(uno::Sequence<sal_Int32> & rFamilies,uno::Sequence<OUString> & rNames)326 void SvXMLAutoStylePoolP::GetRegisteredNames(
327 uno::Sequence<sal_Int32>& rFamilies,
328 uno::Sequence<OUString>& rNames )
329 {
330 pImpl->GetRegisteredNames( rFamilies, rNames );
331 }
332
RegisterNames(uno::Sequence<sal_Int32> & aFamilies,uno::Sequence<OUString> & aNames)333 void SvXMLAutoStylePoolP::RegisterNames(
334 uno::Sequence<sal_Int32>& aFamilies,
335 uno::Sequence<OUString>& aNames )
336 {
337 DBG_ASSERT( aFamilies.getLength() == aNames.getLength(),
338 "aFamilies != aNames" );
339
340 // iterate over sequence(s) and call RegisterName(..) for each pair
341 const sal_Int32* pFamilies = aFamilies.getConstArray();
342 const OUString* pNames = aNames.getConstArray();
343 sal_Int32 nCount = min( aFamilies.getLength(), aNames.getLength() );
344 for( sal_Int32 n = 0; n < nCount; n++ )
345 RegisterName( pFamilies[n], pNames[n] );
346 }
347
Add(sal_Int32 nFamily,const vector<XMLPropertyState> & rProperties)348 OUString SvXMLAutoStylePoolP::Add( sal_Int32 nFamily,
349 const vector< XMLPropertyState >& rProperties )
350 {
351 OUString sEmpty;
352 OUString sName;
353 pImpl->Add(sName, nFamily, sEmpty, rProperties );
354 return sName;
355 }
356
Add(sal_Int32 nFamily,const OUString & rParent,const vector<XMLPropertyState> & rProperties,bool bDontSeek)357 OUString SvXMLAutoStylePoolP::Add( sal_Int32 nFamily,
358 const OUString& rParent,
359 const vector< XMLPropertyState >& rProperties, bool bDontSeek )
360 {
361 OUString sName;
362 pImpl->Add(sName, nFamily, rParent, rProperties, sal_False, bDontSeek );
363 return sName;
364 }
365
Add(OUString & rName,sal_Int32 nFamily,const::std::vector<XMLPropertyState> & rProperties)366 sal_Bool SvXMLAutoStylePoolP::Add(OUString& rName, sal_Int32 nFamily, const ::std::vector< XMLPropertyState >& rProperties )
367 {
368 OUString sEmpty;
369 return pImpl->Add(rName, nFamily, sEmpty, rProperties);
370 }
371
Add(OUString & rName,sal_Int32 nFamily,const OUString & rParent,const::std::vector<XMLPropertyState> & rProperties)372 sal_Bool SvXMLAutoStylePoolP::Add(OUString& rName, sal_Int32 nFamily, const OUString& rParent, const ::std::vector< XMLPropertyState >& rProperties )
373 {
374 return pImpl->Add(rName, nFamily, rParent, rProperties);
375 }
376
AddNamed(const OUString & rName,sal_Int32 nFamily,const OUString & rParent,const::std::vector<XMLPropertyState> & rProperties)377 sal_Bool SvXMLAutoStylePoolP::AddNamed( const OUString& rName, sal_Int32 nFamily, const OUString& rParent,
378 const ::std::vector< XMLPropertyState >& rProperties )
379
380 {
381 return pImpl->AddNamed(rName, nFamily, rParent, rProperties);
382 }
383
AddAndCache(sal_Int32 nFamily,const vector<XMLPropertyState> & rProperties)384 OUString SvXMLAutoStylePoolP::AddAndCache( sal_Int32 nFamily,
385 const vector< XMLPropertyState >& rProperties )
386 {
387 OUString sEmpty;
388 OUString sName;
389 pImpl->Add(sName, nFamily, sEmpty, rProperties, sal_True );
390 return sName;
391 }
392
AddAndCache(sal_Int32 nFamily,const OUString & rParent,const vector<XMLPropertyState> & rProperties)393 OUString SvXMLAutoStylePoolP::AddAndCache( sal_Int32 nFamily,
394 const OUString& rParent,
395 const vector< XMLPropertyState >& rProperties )
396 {
397 OUString sName;
398 pImpl->Add(sName, nFamily, rParent, rProperties, sal_True );
399 return sName;
400 }
401
AddAndCache(sal_Int32 nFamily,const OUString & rParent)402 OUString SvXMLAutoStylePoolP::AddAndCache( sal_Int32 nFamily,
403 const OUString& rParent )
404 {
405 return pImpl->AddToCache( nFamily, rParent );
406 }
407
Find(sal_Int32 nFamily,const vector<XMLPropertyState> & rProperties) const408 OUString SvXMLAutoStylePoolP::Find( sal_Int32 nFamily,
409 const vector< XMLPropertyState >& rProperties ) const
410 {
411 OUString sEmpty;
412 return pImpl->Find( nFamily, sEmpty, rProperties );
413 }
414
Find(sal_Int32 nFamily,const OUString & rParent,const vector<XMLPropertyState> & rProperties) const415 OUString SvXMLAutoStylePoolP::Find( sal_Int32 nFamily,
416 const OUString& rParent,
417 const vector< XMLPropertyState >& rProperties ) const
418 {
419 return pImpl->Find( nFamily, rParent, rProperties );
420 }
421
FindAndRemoveCached(sal_Int32 nFamily) const422 OUString SvXMLAutoStylePoolP::FindAndRemoveCached( sal_Int32 nFamily ) const
423 {
424 return pImpl->FindAndRemoveCached( nFamily );
425 }
426
427
exportXML(sal_Int32 nFamily,const uno::Reference<::com::sun::star::xml::sax::XDocumentHandler> &,const SvXMLUnitConverter &,const SvXMLNamespaceMap &) const428 void SvXMLAutoStylePoolP::exportXML( sal_Int32 nFamily,
429 const uno::Reference< ::com::sun::star::xml::sax::XDocumentHandler > &,
430 const SvXMLUnitConverter&,
431 const SvXMLNamespaceMap&
432 ) const
433 {
434 pImpl->exportXML( nFamily,
435 GetExport().GetDocHandler(),
436 GetExport().GetMM100UnitConverter(),
437 GetExport().GetNamespaceMap(),
438 this);
439 }
440
ClearEntries()441 void SvXMLAutoStylePoolP::ClearEntries()
442 {
443 pImpl->ClearEntries();
444 }
445