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/SettingsExportHelper.hxx>
27 #include "xmloff/xmlnmspe.hxx"
28 #include <xmloff/xmltoken.hxx>
29 #include <xmloff/xmluconv.hxx>
30 #include <tools/debug.hxx>
31 #include <tools/diagnose_ex.h>
32 #include <comphelper/extract.hxx>
33 
34 #include <com/sun/star/linguistic2/XSupportedLocales.hpp>
35 #include <com/sun/star/i18n/XForbiddenCharacters.hpp>
36 #include <com/sun/star/container/XNameAccess.hpp>
37 #include <com/sun/star/container/XNameContainer.hpp>
38 #include <com/sun/star/container/XIndexContainer.hpp>
39 #include <com/sun/star/util/DateTime.hpp>
40 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
41 #include <com/sun/star/container/XIndexContainer.hpp>
42 #include <com/sun/star/formula/SymbolDescriptor.hpp>
43 #include <com/sun/star/document/PrinterIndependentLayout.hpp>
44 #include <xmloff/XMLSettingsExportContext.hxx>
45 #include <xmlenums.hxx>
46 
47 using namespace ::com::sun::star;
48 using namespace ::xmloff::token;
49 
XMLSettingsExportHelper(::xmloff::XMLSettingsExportContext & i_rContext)50 XMLSettingsExportHelper::XMLSettingsExportHelper( ::xmloff::XMLSettingsExportContext& i_rContext )
51 : m_rContext( i_rContext )
52 , msPrinterIndependentLayout( RTL_CONSTASCII_USTRINGPARAM( "PrinterIndependentLayout" ) )
53 , msColorTableURL( RTL_CONSTASCII_USTRINGPARAM( "ColorTableURL" ) )
54 , msLineEndTableURL( RTL_CONSTASCII_USTRINGPARAM( "LineEndTableURL" ) )
55 , msHatchTableURL( RTL_CONSTASCII_USTRINGPARAM( "HatchTableURL" ) )
56 , msDashTableURL( RTL_CONSTASCII_USTRINGPARAM( "DashTableURL" ) )
57 , msGradientTableURL( RTL_CONSTASCII_USTRINGPARAM( "GradientTableURL" ) )
58 , msBitmapTableURL( RTL_CONSTASCII_USTRINGPARAM( "BitmapTableURL" ) )
59 {
60 }
61 
~XMLSettingsExportHelper()62 XMLSettingsExportHelper::~XMLSettingsExportHelper()
63 {
64 }
65 
CallTypeFunction(const uno::Any & rAny,const rtl::OUString & rName) const66 void XMLSettingsExportHelper::CallTypeFunction(const uno::Any& rAny,
67 											const rtl::OUString& rName) const
68 {
69     uno::Any aAny( rAny );
70     ManipulateSetting( aAny, rName );
71 
72 	uno::TypeClass eClass = aAny.getValueTypeClass();
73 	switch (eClass)
74 	{
75 		case uno::TypeClass_VOID:
76 		{
77 			/*
78 			 * This assertion pops up when exporting values which are set to:
79 			 * PropertyAttribute::MAYBEVOID, and thus are _supposed_ to have
80 			 * a VOID value...so I'm removing it ...mtg
81 			 * DBG_ERROR("no type");
82 			 */
83 		}
84 		break;
85 		case uno::TypeClass_BOOLEAN:
86 		{
87 			exportBool(::cppu::any2bool(aAny), rName);
88 		}
89 		break;
90 		case uno::TypeClass_BYTE:
91 		{
92 			sal_Int8 nInt8 = 0;
93 			aAny >>= nInt8;
94 			exportByte(nInt8, rName);
95 		}
96 		break;
97 		case uno::TypeClass_SHORT:
98 		{
99 			sal_Int16 nInt16 = 0;
100 			aAny >>= nInt16;
101 			exportShort(nInt16, rName);
102 		}
103 		break;
104 		case uno::TypeClass_LONG:
105 		{
106 			sal_Int32 nInt32 = 0;
107 			aAny >>= nInt32;
108 			exportInt(nInt32, rName);
109 		}
110 		break;
111 		case uno::TypeClass_HYPER:
112 		{
113 			sal_Int64 nInt64 = 0;
114 			aAny >>= nInt64;
115 			exportLong(nInt64, rName);
116 		}
117 		break;
118 		case uno::TypeClass_DOUBLE:
119 		{
120 			double fDouble = 0.0;
121 			aAny >>= fDouble;
122 			exportDouble(fDouble, rName);
123 		}
124 		break;
125 		case uno::TypeClass_STRING:
126 		{
127 			rtl::OUString sString;
128 			aAny >>= sString;
129 			exportString(sString, rName);
130 		}
131 		break;
132 		default:
133 		{
134 			uno::Type aType = aAny.getValueType();
135 			if (aType.equals(getCppuType( (uno::Sequence<beans::PropertyValue> *)0 ) ) )
136 			{
137 				uno::Sequence< beans::PropertyValue> aProps;
138 				aAny >>= aProps;
139 				exportSequencePropertyValue(aProps, rName);
140 			}
141 			else if( aType.equals(getCppuType( (uno::Sequence<sal_Int8> *)0 ) ) )
142 			{
143 				uno::Sequence< sal_Int8 > aProps;
144 				aAny >>= aProps;
145 				exportbase64Binary(aProps, rName);
146 			}
147 			else if (aType.equals(getCppuType( (uno::Reference<container::XNameContainer> *)0 ) ) ||
148 					aType.equals(getCppuType( (uno::Reference<container::XNameAccess> *)0 ) ))
149 			{
150 				uno::Reference< container::XNameAccess> aNamed;
151 				aAny >>= aNamed;
152 				exportNameAccess(aNamed, rName);
153 			}
154 			else if (aType.equals(getCppuType( (uno::Reference<container::XIndexAccess> *)0 ) ) ||
155 					aType.equals(getCppuType( (uno::Reference<container::XIndexContainer> *)0 ) ) )
156 			{
157 				uno::Reference<container::XIndexAccess> aIndexed;
158 				aAny >>= aIndexed;
159 				exportIndexAccess(aIndexed, rName);
160 			}
161 			else if (aType.equals(getCppuType( (util::DateTime *)0 ) ) )
162 			{
163 				util::DateTime aDateTime;
164 				aAny >>= aDateTime;
165 				exportDateTime(aDateTime, rName);
166 			}
167 			else if( aType.equals(getCppuType( (uno::Reference<i18n::XForbiddenCharacters> *)0 ) ) )
168 			{
169 				exportForbiddenCharacters( aAny, rName );
170 			}
171 			else if( aType.equals(getCppuType( (uno::Sequence<formula::SymbolDescriptor> *)0 ) ) )
172 			{
173 				uno::Sequence< formula::SymbolDescriptor > aProps;
174 				aAny >>= aProps;
175 				exportSymbolDescriptors(aProps, rName);
176 			}
177 			else {
178 				DBG_ERROR("this type is not implemented now");
179             }
180 		}
181 		break;
182 	}
183 }
184 
exportBool(const sal_Bool bValue,const rtl::OUString & rName) const185 void XMLSettingsExportHelper::exportBool(const sal_Bool bValue, const rtl::OUString& rName) const
186 {
187 	DBG_ASSERT(rName.getLength(), "no name");
188 	m_rContext.AddAttribute( XML_NAME, rName );
189 	m_rContext.AddAttribute( XML_TYPE, XML_BOOLEAN );
190     m_rContext.StartElement( XML_CONFIG_ITEM, sal_True );
191 	rtl::OUString sValue;
192 	if (bValue)
193 		sValue = GetXMLToken(XML_TRUE);
194 	else
195 		sValue = GetXMLToken(XML_FALSE);
196 	m_rContext.Characters( sValue );
197     m_rContext.EndElement( sal_False );
198 }
199 
exportByte(const sal_Int8 nValue,const rtl::OUString & rName) const200 void XMLSettingsExportHelper::exportByte(const sal_Int8 nValue, const rtl::OUString& rName) const
201 {
202 #if 0
203 	DBG_ASSERT(rName.getLength(), "no name");
204 	m_rContext.AddAttribute( XML_NAME, rName );
205 	m_rContext.AddAttribute( XML_TYPE, XML_BYTE );
206     m_rContext.StartElement( XML_CONFIG_ITEM, sal_True );
207 	rtl::OUStringBuffer sBuffer;
208 	SvXMLUnitConverter::convertNumber(sBuffer, sal_Int32(nValue));
209 	m_rContext.Characters( sBuffer.makeStringAndClear() );
210     m_rContext.EndElement( sal_False );
211 #else
212     (void) nValue; (void) rName;
213     OSL_ENSURE(false, "XMLSettingsExportHelper::exportByte(): #i114162#:\n"
214         "config-items of type \"byte\" are not valid ODF, "
215         "so storing them is disabled!\n"
216         "Use a different type instead (e.g. \"short\").");
217 #endif
218 }
exportShort(const sal_Int16 nValue,const rtl::OUString & rName) const219 void XMLSettingsExportHelper::exportShort(const sal_Int16 nValue, const rtl::OUString& rName) const
220 {
221 	DBG_ASSERT(rName.getLength(), "no name");
222 	m_rContext.AddAttribute( XML_NAME, rName );
223 	m_rContext.AddAttribute( XML_TYPE, XML_SHORT );
224     m_rContext.StartElement( XML_CONFIG_ITEM, sal_True );
225 	rtl::OUStringBuffer sBuffer;
226 	SvXMLUnitConverter::convertNumber(sBuffer, sal_Int32(nValue));
227 	m_rContext.Characters( sBuffer.makeStringAndClear() );
228     m_rContext.EndElement( sal_False );
229 }
230 
exportInt(const sal_Int32 nValue,const rtl::OUString & rName) const231 void XMLSettingsExportHelper::exportInt(const sal_Int32 nValue, const rtl::OUString& rName) const
232 {
233 	DBG_ASSERT(rName.getLength(), "no name");
234 	m_rContext.AddAttribute( XML_NAME, rName );
235 	m_rContext.AddAttribute( XML_TYPE, XML_INT );
236     m_rContext.StartElement( XML_CONFIG_ITEM, sal_True );
237 	rtl::OUStringBuffer sBuffer;
238 	SvXMLUnitConverter::convertNumber(sBuffer, nValue);
239 	m_rContext.Characters( sBuffer.makeStringAndClear() );
240     m_rContext.EndElement( sal_False );
241 }
242 
exportLong(const sal_Int64 nValue,const rtl::OUString & rName) const243 void XMLSettingsExportHelper::exportLong(const sal_Int64 nValue, const rtl::OUString& rName) const
244 {
245 	DBG_ASSERT(rName.getLength(), "no name");
246 	m_rContext.AddAttribute( XML_NAME, rName );
247 	m_rContext.AddAttribute( XML_TYPE, XML_LONG );
248     m_rContext.StartElement( XML_CONFIG_ITEM, sal_True );
249 	rtl::OUString sValue(rtl::OUString::valueOf(nValue));
250 	m_rContext.Characters( sValue );
251     m_rContext.EndElement( sal_False );
252 }
253 
exportDouble(const double fValue,const rtl::OUString & rName) const254 void XMLSettingsExportHelper::exportDouble(const double fValue, const rtl::OUString& rName) const
255 {
256 	DBG_ASSERT(rName.getLength(), "no name");
257 	m_rContext.AddAttribute( XML_NAME, rName );
258 	m_rContext.AddAttribute( XML_TYPE, XML_DOUBLE );
259     m_rContext.StartElement( XML_CONFIG_ITEM, sal_True );
260 	rtl::OUStringBuffer sBuffer;
261 	SvXMLUnitConverter::convertDouble(sBuffer, fValue);
262 	m_rContext.Characters( sBuffer.makeStringAndClear() );
263     m_rContext.EndElement( sal_False );
264 }
265 
exportString(const rtl::OUString & sValue,const rtl::OUString & rName) const266 void XMLSettingsExportHelper::exportString(const rtl::OUString& sValue, const rtl::OUString& rName) const
267 {
268 	DBG_ASSERT(rName.getLength(), "no name");
269 	m_rContext.AddAttribute( XML_NAME, rName );
270 	m_rContext.AddAttribute( XML_TYPE, XML_STRING );
271     m_rContext.StartElement( XML_CONFIG_ITEM, sal_True );
272 	if (sValue.getLength())
273 		m_rContext.Characters( sValue );
274     m_rContext.EndElement( sal_False );
275 }
276 
exportDateTime(const util::DateTime & aValue,const rtl::OUString & rName) const277 void XMLSettingsExportHelper::exportDateTime(const util::DateTime& aValue, const rtl::OUString& rName) const
278 {
279 	DBG_ASSERT(rName.getLength(), "no name");
280 	m_rContext.AddAttribute( XML_NAME, rName );
281 	m_rContext.AddAttribute( XML_TYPE, XML_DATETIME );
282 	rtl::OUStringBuffer sBuffer;
283 	SvXMLUnitConverter::convertDateTime(sBuffer, aValue);
284     m_rContext.StartElement( XML_CONFIG_ITEM, sal_True );
285 	m_rContext.Characters( sBuffer.makeStringAndClear() );
286     m_rContext.EndElement( sal_False );
287 }
288 
exportSequencePropertyValue(const uno::Sequence<beans::PropertyValue> & aProps,const rtl::OUString & rName) const289 void XMLSettingsExportHelper::exportSequencePropertyValue(
290 					const uno::Sequence<beans::PropertyValue>& aProps,
291 					const rtl::OUString& rName) const
292 {
293 	DBG_ASSERT(rName.getLength(), "no name");
294 	sal_Int32 nLength(aProps.getLength());
295 	if(nLength)
296 	{
297 		m_rContext.AddAttribute( XML_NAME, rName );
298         m_rContext.StartElement( XML_CONFIG_ITEM_SET, sal_True );
299 		for (sal_Int32 i = 0; i < nLength; i++)
300 			CallTypeFunction(aProps[i].Value, aProps[i].Name);
301         m_rContext.EndElement( sal_True );
302 	}
303 }
exportSymbolDescriptors(const uno::Sequence<formula::SymbolDescriptor> & rProps,const rtl::OUString rName) const304 void XMLSettingsExportHelper::exportSymbolDescriptors(
305 					const uno::Sequence < formula::SymbolDescriptor > &rProps,
306 					const rtl::OUString rName) const
307 {
308 	// #110680#
309 	// uno::Reference< lang::XMultiServiceFactory > xServiceFactory( comphelper::getProcessServiceFactory() );
310 	uno::Reference< lang::XMultiServiceFactory > xServiceFactory( m_rContext.GetServiceFactory() );
311 	DBG_ASSERT( xServiceFactory.is(), "XMLSettingsExportHelper::exportSymbolDescriptors: got no service manager" );
312 
313 	if( xServiceFactory.is() )
314 	{
315 		uno::Reference< container::XIndexContainer > xBox(xServiceFactory->createInstance(rtl::OUString( RTL_CONSTASCII_USTRINGPARAM ("com.sun.star.document.IndexedPropertyValues") ) ), uno::UNO_QUERY);
316 		DBG_ASSERT( xBox.is(), "could not create service com.sun.star.document.IndexedPropertyValues" );
317 		if (xBox.is() )
318 		{
319 			const rtl::OUString sName     ( RTL_CONSTASCII_USTRINGPARAM ( "Name" ) );
320 			const rtl::OUString sExportName ( RTL_CONSTASCII_USTRINGPARAM ( "ExportName" ) );
321 			const rtl::OUString sSymbolSet ( RTL_CONSTASCII_USTRINGPARAM ( "SymbolSet" ) );
322 			const rtl::OUString sCharacter ( RTL_CONSTASCII_USTRINGPARAM ( "Character" ) );
323 			const rtl::OUString sFontName ( RTL_CONSTASCII_USTRINGPARAM ( "FontName" ) );
324 			const rtl::OUString sCharSet  ( RTL_CONSTASCII_USTRINGPARAM ( "CharSet" ) );
325 			const rtl::OUString sFamily   ( RTL_CONSTASCII_USTRINGPARAM ( "Family" ) );
326 			const rtl::OUString sPitch    ( RTL_CONSTASCII_USTRINGPARAM ( "Pitch" ) );
327 			const rtl::OUString sWeight   ( RTL_CONSTASCII_USTRINGPARAM ( "Weight" ) );
328 			const rtl::OUString sItalic   ( RTL_CONSTASCII_USTRINGPARAM ( "Italic" ) );
329 
330 			sal_Int32 nCount = rProps.getLength();
331 			const formula::SymbolDescriptor *pDescriptor = rProps.getConstArray();
332 
333 			for( sal_Int32 nIndex = 0; nIndex < nCount; nIndex++, pDescriptor++ )
334 			{
335 				uno::Sequence < beans::PropertyValue > aSequence ( XML_SYMBOL_DESCRIPTOR_MAX );
336 				beans::PropertyValue *pSymbol = aSequence.getArray();
337 
338 				pSymbol[XML_SYMBOL_DESCRIPTOR_NAME].Name         = sName;
339 				pSymbol[XML_SYMBOL_DESCRIPTOR_NAME].Value	    <<= pDescriptor->sName;
340 				pSymbol[XML_SYMBOL_DESCRIPTOR_EXPORT_NAME].Name  = sExportName;
341 				pSymbol[XML_SYMBOL_DESCRIPTOR_EXPORT_NAME].Value<<= pDescriptor->sExportName;
342 				pSymbol[XML_SYMBOL_DESCRIPTOR_FONT_NAME].Name    = sFontName;
343 				pSymbol[XML_SYMBOL_DESCRIPTOR_FONT_NAME].Value	<<= pDescriptor->sFontName;
344 				pSymbol[XML_SYMBOL_DESCRIPTOR_CHAR_SET].Name      = sCharSet;
345 				pSymbol[XML_SYMBOL_DESCRIPTOR_CHAR_SET].Value	<<= pDescriptor->nCharSet;
346 				pSymbol[XML_SYMBOL_DESCRIPTOR_FAMILY].Name       = sFamily;
347 				pSymbol[XML_SYMBOL_DESCRIPTOR_FAMILY].Value	<<= pDescriptor->nFamily;
348 				pSymbol[XML_SYMBOL_DESCRIPTOR_PITCH].Name        = sPitch;
349 				pSymbol[XML_SYMBOL_DESCRIPTOR_PITCH].Value	    <<= pDescriptor->nPitch;
350 				pSymbol[XML_SYMBOL_DESCRIPTOR_WEIGHT].Name       = sWeight;
351 				pSymbol[XML_SYMBOL_DESCRIPTOR_WEIGHT].Value	<<= pDescriptor->nWeight;
352 				pSymbol[XML_SYMBOL_DESCRIPTOR_ITALIC].Name       = sItalic;
353 				pSymbol[XML_SYMBOL_DESCRIPTOR_ITALIC].Value	<<= pDescriptor->nItalic;
354 				pSymbol[XML_SYMBOL_DESCRIPTOR_SYMBOL_SET].Name       = sSymbolSet;
355 				pSymbol[XML_SYMBOL_DESCRIPTOR_SYMBOL_SET].Value	<<= pDescriptor->sSymbolSet;
356 				pSymbol[XML_SYMBOL_DESCRIPTOR_CHARACTER].Name       = sCharacter;
357 				pSymbol[XML_SYMBOL_DESCRIPTOR_CHARACTER].Value	<<= pDescriptor->nCharacter;
358 
359 				xBox->insertByIndex(nIndex, uno::makeAny( aSequence ));
360 			}
361 
362 			uno::Reference< container::XIndexAccess > xIA( xBox, uno::UNO_QUERY );
363 			exportIndexAccess( xIA, rName );
364 		}
365 	}
366 }
exportbase64Binary(const uno::Sequence<sal_Int8> & aProps,const rtl::OUString & rName) const367 void XMLSettingsExportHelper::exportbase64Binary(
368 					const uno::Sequence<sal_Int8>& aProps,
369 					const rtl::OUString& rName) const
370 {
371 	DBG_ASSERT(rName.getLength(), "no name");
372 	sal_Int32 nLength(aProps.getLength());
373 	m_rContext.AddAttribute( XML_NAME, rName );
374 	m_rContext.AddAttribute( XML_TYPE, XML_BASE64BINARY );
375     m_rContext.StartElement( XML_CONFIG_ITEM, sal_True );
376 	if(nLength)
377 	{
378 		rtl::OUStringBuffer sBuffer;
379 		SvXMLUnitConverter::encodeBase64(sBuffer, aProps);
380 		m_rContext.Characters( sBuffer.makeStringAndClear() );
381 	}
382     m_rContext.EndElement( sal_False );
383 }
384 
exportMapEntry(const uno::Any & rAny,const rtl::OUString & rName,const sal_Bool bNameAccess) const385 void XMLSettingsExportHelper::exportMapEntry(const uno::Any& rAny,
386 										const rtl::OUString& rName,
387 										const sal_Bool bNameAccess) const
388 {
389 	DBG_ASSERT((bNameAccess && rName.getLength()) || !bNameAccess, "no name");
390 	uno::Sequence<beans::PropertyValue> aProps;
391 	rAny >>= aProps;
392 	sal_Int32 nLength = aProps.getLength();
393 	if (nLength)
394 	{
395 		if (bNameAccess)
396 			m_rContext.AddAttribute( XML_NAME, rName );
397         m_rContext.StartElement( XML_CONFIG_ITEM_MAP_ENTRY, sal_True );
398 		for (sal_Int32 i = 0; i < nLength; i++)
399 			CallTypeFunction(aProps[i].Value, aProps[i].Name);
400         m_rContext.EndElement( sal_True );
401 	}
402 }
403 
exportNameAccess(const uno::Reference<container::XNameAccess> & aNamed,const rtl::OUString & rName) const404 void XMLSettingsExportHelper::exportNameAccess(
405 					const uno::Reference<container::XNameAccess>& aNamed,
406 					const rtl::OUString& rName) const
407 {
408 	DBG_ASSERT(rName.getLength(), "no name");
409 	DBG_ASSERT(aNamed->getElementType().equals(getCppuType( (uno::Sequence<beans::PropertyValue> *)0 ) ),
410 				"wrong NameAccess" );
411 	if(aNamed->hasElements())
412 	{
413 		m_rContext.AddAttribute( XML_NAME, rName );
414         m_rContext.StartElement( XML_CONFIG_ITEM_MAP_NAMED, sal_True );
415 		uno::Sequence< rtl::OUString > aNames(aNamed->getElementNames());
416 		for (sal_Int32 i = 0; i < aNames.getLength(); i++)
417 			exportMapEntry(aNamed->getByName(aNames[i]), aNames[i], sal_True);
418         m_rContext.EndElement( sal_True );
419 	}
420 }
421 
exportIndexAccess(const uno::Reference<container::XIndexAccess> aIndexed,const rtl::OUString rName) const422 void XMLSettingsExportHelper::exportIndexAccess(
423 					const uno::Reference<container::XIndexAccess> aIndexed,
424 					const rtl::OUString rName) const
425 {
426 	DBG_ASSERT(rName.getLength(), "no name");
427 	DBG_ASSERT(aIndexed->getElementType().equals(getCppuType( (uno::Sequence<beans::PropertyValue> *)0 ) ),
428 				"wrong IndexAccess" );
429 	rtl::OUString sEmpty;// ( RTLCONSTASCII_USTRINGPARAM( "View" ) );
430 	if(aIndexed->hasElements())
431 	{
432 		m_rContext.AddAttribute( XML_NAME, rName );
433         m_rContext.StartElement( XML_CONFIG_ITEM_MAP_INDEXED, sal_True );
434 		sal_Int32 nCount = aIndexed->getCount();
435 		for (sal_Int32 i = 0; i < nCount; i++)
436 		{
437 			exportMapEntry(aIndexed->getByIndex(i), sEmpty, sal_False);
438 		}
439         m_rContext.EndElement( sal_True );
440 	}
441 }
442 
exportForbiddenCharacters(const uno::Any & rAny,const rtl::OUString rName) const443 void XMLSettingsExportHelper::exportForbiddenCharacters(
444 					const uno::Any &rAny,
445 					const rtl::OUString rName) const
446 {
447 	uno::Reference<i18n::XForbiddenCharacters> xForbChars;
448 	uno::Reference<linguistic2::XSupportedLocales> xLocales;
449 
450 	rAny >>= xForbChars;
451 	rAny >>= xLocales;
452 
453 	DBG_ASSERT( xForbChars.is() && xLocales.is(),"XMLSettingsExportHelper::exportForbiddenCharacters: got illegal forbidden characters!" );
454 
455 	if( !xForbChars.is() || !xLocales.is() )
456 		return;
457 
458 	// #110680#
459 	// uno::Reference< lang::XMultiServiceFactory > xServiceFactory( comphelper::getProcessServiceFactory() );
460 	uno::Reference< lang::XMultiServiceFactory > xServiceFactory( m_rContext.GetServiceFactory() );
461 	DBG_ASSERT( xServiceFactory.is(), "XMLSettingsExportHelper::exportForbiddenCharacters: got no service manager" );
462 
463 	if( xServiceFactory.is() )
464 	{
465 		uno::Reference< container::XIndexContainer > xBox(xServiceFactory->createInstance(rtl::OUString( RTL_CONSTASCII_USTRINGPARAM ("com.sun.star.document.IndexedPropertyValues") ) ), uno::UNO_QUERY);
466 		DBG_ASSERT( xBox.is(), "could not create service com.sun.star.document.IndexedPropertyValues" );
467 		if (xBox.is() )
468 		{
469 			const uno::Sequence< lang::Locale > aLocales( xLocales->getLocales() );
470 			const lang::Locale* pLocales = aLocales.getConstArray();
471 
472 			const sal_Int32 nCount = aLocales.getLength();
473 
474 			const rtl::OUString sLanguage  ( RTL_CONSTASCII_USTRINGPARAM ( "Language" ) );
475 			const rtl::OUString sCountry   ( RTL_CONSTASCII_USTRINGPARAM ( "Country" ) );
476 			const rtl::OUString sVariant   ( RTL_CONSTASCII_USTRINGPARAM ( "Variant" ) );
477 			const rtl::OUString sBeginLine ( RTL_CONSTASCII_USTRINGPARAM ( "BeginLine" ) );
478 			const rtl::OUString sEndLine   ( RTL_CONSTASCII_USTRINGPARAM ( "EndLine" ) );
479 
480 			sal_Int32 nPos = 0;
481 			for( sal_Int32 nIndex = 0; nIndex < nCount; nIndex++, pLocales++ )
482 			{
483 				if( xForbChars->hasForbiddenCharacters( *pLocales ) )
484 				{
485 					const i18n::ForbiddenCharacters aChars( xForbChars->getForbiddenCharacters( *pLocales ) );
486 
487 
488 					uno::Sequence < beans::PropertyValue > aSequence ( XML_FORBIDDEN_CHARACTER_MAX );
489 					beans::PropertyValue *pForChar = aSequence.getArray();
490 
491 					pForChar[XML_FORBIDDEN_CHARACTER_LANGUAGE].Name    = sLanguage;
492 					pForChar[XML_FORBIDDEN_CHARACTER_LANGUAGE].Value <<= pLocales->Language;
493 					pForChar[XML_FORBIDDEN_CHARACTER_COUNTRY].Name    = sCountry;
494 					pForChar[XML_FORBIDDEN_CHARACTER_COUNTRY].Value <<= pLocales->Country;
495 					pForChar[XML_FORBIDDEN_CHARACTER_VARIANT].Name    = sVariant;
496 					pForChar[XML_FORBIDDEN_CHARACTER_VARIANT].Value <<= pLocales->Variant;
497 					pForChar[XML_FORBIDDEN_CHARACTER_BEGIN_LINE].Name    = sBeginLine;
498 					pForChar[XML_FORBIDDEN_CHARACTER_BEGIN_LINE].Value <<= aChars.beginLine;
499 					pForChar[XML_FORBIDDEN_CHARACTER_END_LINE].Name    = sEndLine;
500 					pForChar[XML_FORBIDDEN_CHARACTER_END_LINE].Value <<= aChars.endLine;
501 					xBox->insertByIndex(nPos++, uno::makeAny( aSequence ));
502 				}
503 			}
504 
505 			uno::Reference< container::XIndexAccess > xIA( xBox, uno::UNO_QUERY );
506 			exportIndexAccess( xIA, rName );
507 		}
508 	}
509 }
510 
exportAllSettings(const uno::Sequence<beans::PropertyValue> & aProps,const rtl::OUString & rName) const511 void XMLSettingsExportHelper::exportAllSettings(
512 					const uno::Sequence<beans::PropertyValue>& aProps,
513 					const rtl::OUString& rName) const
514 {
515 	DBG_ASSERT(rName.getLength(), "no name");
516 	exportSequencePropertyValue(aProps, rName);
517 }
518 
519 
520 /** For some settings we may want to change their API representation
521  * from their XML settings representation. This is your chance to do
522  * so!
523  */
ManipulateSetting(uno::Any & rAny,const rtl::OUString & rName) const524 void XMLSettingsExportHelper::ManipulateSetting( uno::Any& rAny, const rtl::OUString& rName ) const
525 {
526     if( rName == msPrinterIndependentLayout )
527     {
528         sal_Int16 nTmp = sal_Int16();
529         if( rAny >>= nTmp )
530         {
531             if( nTmp == document::PrinterIndependentLayout::LOW_RESOLUTION )
532                 rAny <<= rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("low-resolution"));
533             else if( nTmp == document::PrinterIndependentLayout::DISABLED )
534                 rAny <<= rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("disabled"));
535             else if( nTmp == document::PrinterIndependentLayout::HIGH_RESOLUTION )
536                 rAny <<= rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("high-resolution"));
537         }
538     }
539 	else if( (rName == msColorTableURL) || (rName == msLineEndTableURL) || (rName == msHatchTableURL) ||
540 			 (rName == msDashTableURL) || (rName == msGradientTableURL) || (rName == msBitmapTableURL ) )
541 	{
542 		if( !mxStringSubsitution.is() )
543 		{
544 			if( m_rContext.GetServiceFactory().is() ) try
545 			{
546 				const_cast< XMLSettingsExportHelper* >(this)->mxStringSubsitution =
547 					uno::Reference< util::XStringSubstitution >::query(
548 						m_rContext.GetServiceFactory()->
549 							createInstance(::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.util.PathSubstitution" ) ) ) );
550 			}
551 			catch( uno::Exception& )
552 			{
553                 DBG_UNHANDLED_EXCEPTION();
554 			}
555 		}
556 
557 		if( mxStringSubsitution.is() )
558 		{
559 			::rtl::OUString aURL;
560 			rAny >>= aURL;
561 			aURL = mxStringSubsitution->reSubstituteVariables( aURL );
562 			rAny <<= aURL;
563 		}
564 	}
565 }
566