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