1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir  *
5*cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir  *
7*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
10*cdf0e10cSrcweir  *
11*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir  *
15*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir  *
26*cdf0e10cSrcweir  ************************************************************************/
27*cdf0e10cSrcweir 
28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
29*cdf0e10cSrcweir #include "precompiled_unotools.hxx"
30*cdf0e10cSrcweir 
31*cdf0e10cSrcweir #include <unotools/xmlaccelcfg.hxx>
32*cdf0e10cSrcweir 
33*cdf0e10cSrcweir #include <vector>
34*cdf0e10cSrcweir #include <com/sun/star/xml/sax/XAttributeList.hpp>
35*cdf0e10cSrcweir #include <cppuhelper/implbase1.hxx>
36*cdf0e10cSrcweir 
37*cdf0e10cSrcweir using namespace rtl;
38*cdf0e10cSrcweir using namespace com::sun::star::uno;
39*cdf0e10cSrcweir using namespace com::sun::star::xml::sax;
40*cdf0e10cSrcweir 
41*cdf0e10cSrcweir #define	ELEMENT_ACCELERATORLIST		"acceleratorlist"
42*cdf0e10cSrcweir #define ELEMENT_ACCELERATORITEM		"item"
43*cdf0e10cSrcweir 
44*cdf0e10cSrcweir #define ATTRIBUTE_KEYCODE			"code"
45*cdf0e10cSrcweir #define ATTRIBUTE_MODIFIER			"modifier"
46*cdf0e10cSrcweir #define ATTRIBUTE_URL				"url"
47*cdf0e10cSrcweir 
48*cdf0e10cSrcweir #define ATTRIBUTE_TYPE_CDATA		"CDATA"
49*cdf0e10cSrcweir 
50*cdf0e10cSrcweir // ------------------------------------------------------------------
51*cdf0e10cSrcweir 
52*cdf0e10cSrcweir struct AttributeListImpl_impl;
53*cdf0e10cSrcweir class AttributeListImpl : public ::cppu::WeakImplHelper1< ::com::sun::star::xml::sax::XAttributeList >
54*cdf0e10cSrcweir {
55*cdf0e10cSrcweir protected:
56*cdf0e10cSrcweir 	~AttributeListImpl();
57*cdf0e10cSrcweir 
58*cdf0e10cSrcweir public:
59*cdf0e10cSrcweir 	AttributeListImpl();
60*cdf0e10cSrcweir 	AttributeListImpl( const AttributeListImpl & );
61*cdf0e10cSrcweir 
62*cdf0e10cSrcweir public:
63*cdf0e10cSrcweir     virtual sal_Int16 SAL_CALL getLength(void) throw (::com::sun::star::uno::RuntimeException);
64*cdf0e10cSrcweir     virtual ::rtl::OUString  SAL_CALL getNameByIndex(sal_Int16 i) throw (::com::sun::star::uno::RuntimeException);
65*cdf0e10cSrcweir     virtual ::rtl::OUString  SAL_CALL getTypeByIndex(sal_Int16 i) throw (::com::sun::star::uno::RuntimeException);
66*cdf0e10cSrcweir     virtual ::rtl::OUString  SAL_CALL getTypeByName(const ::rtl::OUString& aName) throw (::com::sun::star::uno::RuntimeException);
67*cdf0e10cSrcweir     virtual ::rtl::OUString  SAL_CALL getValueByIndex(sal_Int16 i) throw (::com::sun::star::uno::RuntimeException);
68*cdf0e10cSrcweir     virtual ::rtl::OUString  SAL_CALL getValueByName(const ::rtl::OUString& aName) throw (::com::sun::star::uno::RuntimeException);
69*cdf0e10cSrcweir 
70*cdf0e10cSrcweir public:
71*cdf0e10cSrcweir 	void addAttribute( const ::rtl::OUString &sName , const ::rtl::OUString &sType , const ::rtl::OUString &sValue );
72*cdf0e10cSrcweir 	void clear();
73*cdf0e10cSrcweir 
74*cdf0e10cSrcweir private:
75*cdf0e10cSrcweir 	struct AttributeListImpl_impl *m_pImpl;
76*cdf0e10cSrcweir };
77*cdf0e10cSrcweir 
78*cdf0e10cSrcweir struct TagAttribute
79*cdf0e10cSrcweir {
80*cdf0e10cSrcweir 	TagAttribute(){}
81*cdf0e10cSrcweir 	TagAttribute( const OUString &aName, const OUString &aType , const OUString &aValue )
82*cdf0e10cSrcweir 	{
83*cdf0e10cSrcweir 		sName 	= aName;
84*cdf0e10cSrcweir 		sType 	= aType;
85*cdf0e10cSrcweir 		sValue 	= aValue;
86*cdf0e10cSrcweir 	}
87*cdf0e10cSrcweir 
88*cdf0e10cSrcweir 	OUString sName;
89*cdf0e10cSrcweir 	OUString sType;
90*cdf0e10cSrcweir 	OUString sValue;
91*cdf0e10cSrcweir };
92*cdf0e10cSrcweir 
93*cdf0e10cSrcweir struct AttributeListImpl_impl
94*cdf0e10cSrcweir {
95*cdf0e10cSrcweir 	AttributeListImpl_impl()
96*cdf0e10cSrcweir 	{
97*cdf0e10cSrcweir 		// performance improvement during adding
98*cdf0e10cSrcweir 		vecAttribute.reserve(20);
99*cdf0e10cSrcweir 	}
100*cdf0e10cSrcweir 	::std::vector<struct TagAttribute> vecAttribute;
101*cdf0e10cSrcweir };
102*cdf0e10cSrcweir 
103*cdf0e10cSrcweir 
104*cdf0e10cSrcweir 
105*cdf0e10cSrcweir sal_Int16 SAL_CALL AttributeListImpl::getLength(void) throw (RuntimeException)
106*cdf0e10cSrcweir {
107*cdf0e10cSrcweir 	return sal::static_int_cast< sal_Int16 >(m_pImpl->vecAttribute.size());
108*cdf0e10cSrcweir }
109*cdf0e10cSrcweir 
110*cdf0e10cSrcweir 
111*cdf0e10cSrcweir AttributeListImpl::AttributeListImpl( const AttributeListImpl &r ) :
112*cdf0e10cSrcweir     cppu::WeakImplHelper1<com::sun::star::xml::sax::XAttributeList>(r)
113*cdf0e10cSrcweir {
114*cdf0e10cSrcweir 	m_pImpl = new AttributeListImpl_impl;
115*cdf0e10cSrcweir 	*m_pImpl = *(r.m_pImpl);
116*cdf0e10cSrcweir }
117*cdf0e10cSrcweir 
118*cdf0e10cSrcweir OUString AttributeListImpl::getNameByIndex(sal_Int16 i) throw (RuntimeException)
119*cdf0e10cSrcweir {
120*cdf0e10cSrcweir 	if( i < sal::static_int_cast<sal_Int16>(m_pImpl->vecAttribute.size()) ) {
121*cdf0e10cSrcweir 		return m_pImpl->vecAttribute[i].sName;
122*cdf0e10cSrcweir 	}
123*cdf0e10cSrcweir 	return OUString();
124*cdf0e10cSrcweir }
125*cdf0e10cSrcweir 
126*cdf0e10cSrcweir 
127*cdf0e10cSrcweir OUString AttributeListImpl::getTypeByIndex(sal_Int16 i) throw (RuntimeException)
128*cdf0e10cSrcweir {
129*cdf0e10cSrcweir 	if( i < sal::static_int_cast<sal_Int16>(m_pImpl->vecAttribute.size()) ) {
130*cdf0e10cSrcweir 		return m_pImpl->vecAttribute[i].sType;
131*cdf0e10cSrcweir 	}
132*cdf0e10cSrcweir 	return OUString();
133*cdf0e10cSrcweir }
134*cdf0e10cSrcweir 
135*cdf0e10cSrcweir OUString AttributeListImpl::getValueByIndex(sal_Int16 i) throw (RuntimeException)
136*cdf0e10cSrcweir {
137*cdf0e10cSrcweir 	if( i < sal::static_int_cast<sal_Int16>(m_pImpl->vecAttribute.size()) ) {
138*cdf0e10cSrcweir 		return m_pImpl->vecAttribute[i].sValue;
139*cdf0e10cSrcweir 	}
140*cdf0e10cSrcweir 	return OUString();
141*cdf0e10cSrcweir 
142*cdf0e10cSrcweir }
143*cdf0e10cSrcweir 
144*cdf0e10cSrcweir OUString AttributeListImpl::getTypeByName( const OUString& sName ) throw (RuntimeException)
145*cdf0e10cSrcweir {
146*cdf0e10cSrcweir 	::std::vector<struct TagAttribute>::iterator ii = m_pImpl->vecAttribute.begin();
147*cdf0e10cSrcweir 
148*cdf0e10cSrcweir 	for( ; ii != m_pImpl->vecAttribute.end() ; ii ++ ) {
149*cdf0e10cSrcweir 		if( (*ii).sName == sName ) {
150*cdf0e10cSrcweir 			return (*ii).sType;
151*cdf0e10cSrcweir 		}
152*cdf0e10cSrcweir 	}
153*cdf0e10cSrcweir 	return OUString();
154*cdf0e10cSrcweir }
155*cdf0e10cSrcweir 
156*cdf0e10cSrcweir OUString AttributeListImpl::getValueByName(const OUString& sName) throw (RuntimeException)
157*cdf0e10cSrcweir {
158*cdf0e10cSrcweir 	::std::vector<struct TagAttribute>::iterator ii = m_pImpl->vecAttribute.begin();
159*cdf0e10cSrcweir 
160*cdf0e10cSrcweir 	for( ; ii != m_pImpl->vecAttribute.end() ; ii ++ ) {
161*cdf0e10cSrcweir 		if( (*ii).sName == sName ) {
162*cdf0e10cSrcweir 			return (*ii).sValue;
163*cdf0e10cSrcweir 		}
164*cdf0e10cSrcweir 	}
165*cdf0e10cSrcweir 	return OUString();
166*cdf0e10cSrcweir }
167*cdf0e10cSrcweir 
168*cdf0e10cSrcweir 
169*cdf0e10cSrcweir AttributeListImpl::AttributeListImpl()
170*cdf0e10cSrcweir {
171*cdf0e10cSrcweir 	m_pImpl = new AttributeListImpl_impl;
172*cdf0e10cSrcweir }
173*cdf0e10cSrcweir 
174*cdf0e10cSrcweir 
175*cdf0e10cSrcweir 
176*cdf0e10cSrcweir AttributeListImpl::~AttributeListImpl()
177*cdf0e10cSrcweir {
178*cdf0e10cSrcweir 	delete m_pImpl;
179*cdf0e10cSrcweir }
180*cdf0e10cSrcweir 
181*cdf0e10cSrcweir 
182*cdf0e10cSrcweir void AttributeListImpl::addAttribute( 	const OUString &sName ,
183*cdf0e10cSrcweir 										const OUString &sType ,
184*cdf0e10cSrcweir 										const OUString &sValue )
185*cdf0e10cSrcweir {
186*cdf0e10cSrcweir 	m_pImpl->vecAttribute.push_back( TagAttribute( sName , sType , sValue ) );
187*cdf0e10cSrcweir }
188*cdf0e10cSrcweir 
189*cdf0e10cSrcweir void AttributeListImpl::clear()
190*cdf0e10cSrcweir {
191*cdf0e10cSrcweir 	::std::vector<struct TagAttribute> dummy;
192*cdf0e10cSrcweir 	m_pImpl->vecAttribute.swap( dummy );
193*cdf0e10cSrcweir 
194*cdf0e10cSrcweir 	OSL_ASSERT( ! getLength() );
195*cdf0e10cSrcweir }
196*cdf0e10cSrcweir 
197*cdf0e10cSrcweir // ------------------------------------------------------------------
198*cdf0e10cSrcweir 
199*cdf0e10cSrcweir Any SAL_CALL OReadAccelatorDocumentHandler::queryInterface( const Type & rType ) throw( RuntimeException )
200*cdf0e10cSrcweir {
201*cdf0e10cSrcweir 	Any a = ::cppu::queryInterface( rType ,SAL_STATIC_CAST( XDocumentHandler*, this ));
202*cdf0e10cSrcweir 	if ( a.hasValue() )
203*cdf0e10cSrcweir 		return a;
204*cdf0e10cSrcweir 	else
205*cdf0e10cSrcweir 		return OWeakObject::queryInterface( rType );
206*cdf0e10cSrcweir }
207*cdf0e10cSrcweir 
208*cdf0e10cSrcweir void SAL_CALL OReadAccelatorDocumentHandler::ignorableWhitespace(
209*cdf0e10cSrcweir 	const OUString& )
210*cdf0e10cSrcweir throw( SAXException, RuntimeException )
211*cdf0e10cSrcweir {
212*cdf0e10cSrcweir }
213*cdf0e10cSrcweir 
214*cdf0e10cSrcweir void SAL_CALL OReadAccelatorDocumentHandler::processingInstruction(
215*cdf0e10cSrcweir 	const OUString&, const OUString& )
216*cdf0e10cSrcweir throw( SAXException, RuntimeException )
217*cdf0e10cSrcweir {
218*cdf0e10cSrcweir }
219*cdf0e10cSrcweir 
220*cdf0e10cSrcweir void SAL_CALL OReadAccelatorDocumentHandler::setDocumentLocator(
221*cdf0e10cSrcweir 	const Reference< XLocator > &xLocator)
222*cdf0e10cSrcweir throw(	SAXException, RuntimeException )
223*cdf0e10cSrcweir {
224*cdf0e10cSrcweir 	m_xLocator = xLocator;
225*cdf0e10cSrcweir }
226*cdf0e10cSrcweir 
227*cdf0e10cSrcweir ::rtl::OUString OReadAccelatorDocumentHandler::getErrorLineString()
228*cdf0e10cSrcweir {
229*cdf0e10cSrcweir 	char buffer[32];
230*cdf0e10cSrcweir 
231*cdf0e10cSrcweir 	if ( m_xLocator.is() )
232*cdf0e10cSrcweir 	{
233*cdf0e10cSrcweir 		return OUString::createFromAscii( buffer );
234*cdf0e10cSrcweir 	}
235*cdf0e10cSrcweir 	else
236*cdf0e10cSrcweir 		return OUString();
237*cdf0e10cSrcweir }
238*cdf0e10cSrcweir 
239*cdf0e10cSrcweir void SAL_CALL OReadAccelatorDocumentHandler::startDocument(void)
240*cdf0e10cSrcweir 	throw ( SAXException, RuntimeException )
241*cdf0e10cSrcweir {
242*cdf0e10cSrcweir }
243*cdf0e10cSrcweir 
244*cdf0e10cSrcweir void SAL_CALL OReadAccelatorDocumentHandler::endDocument(void)
245*cdf0e10cSrcweir 	throw( SAXException, RuntimeException )
246*cdf0e10cSrcweir {
247*cdf0e10cSrcweir 	if ( m_nElementDepth > 0 )
248*cdf0e10cSrcweir 	{
249*cdf0e10cSrcweir 		OUString aErrorMessage = getErrorLineString();
250*cdf0e10cSrcweir 		aErrorMessage += OUString( RTL_CONSTASCII_USTRINGPARAM( "A closing element is missing!" ));
251*cdf0e10cSrcweir 		throw SAXException( aErrorMessage, Reference< XInterface >(), Any() );
252*cdf0e10cSrcweir 	}
253*cdf0e10cSrcweir }
254*cdf0e10cSrcweir 
255*cdf0e10cSrcweir 
256*cdf0e10cSrcweir void SAL_CALL OReadAccelatorDocumentHandler::startElement(
257*cdf0e10cSrcweir 	const OUString& aElementName, const Reference< XAttributeList > &xAttrList )
258*cdf0e10cSrcweir throw( SAXException, RuntimeException )
259*cdf0e10cSrcweir {
260*cdf0e10cSrcweir 	m_nElementDepth++;
261*cdf0e10cSrcweir 
262*cdf0e10cSrcweir 	if ( aElementName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( ELEMENT_ACCELERATORLIST )))
263*cdf0e10cSrcweir 	{
264*cdf0e10cSrcweir 		// acceleratorlist
265*cdf0e10cSrcweir 		if ( m_bAcceleratorMode )
266*cdf0e10cSrcweir 		{
267*cdf0e10cSrcweir 			OUString aErrorMessage = getErrorLineString();
268*cdf0e10cSrcweir 			aErrorMessage += OUString( RTL_CONSTASCII_USTRINGPARAM( "Accelerator list used twice!" ));
269*cdf0e10cSrcweir 			throw SAXException( aErrorMessage, Reference< XInterface >(), Any() );
270*cdf0e10cSrcweir 		}
271*cdf0e10cSrcweir 		else
272*cdf0e10cSrcweir 			m_bAcceleratorMode = sal_True;
273*cdf0e10cSrcweir 	}
274*cdf0e10cSrcweir 	else if ( aElementName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( ELEMENT_ACCELERATORITEM )))
275*cdf0e10cSrcweir 	{
276*cdf0e10cSrcweir 		// accelerator item
277*cdf0e10cSrcweir 		if ( !m_bAcceleratorMode )
278*cdf0e10cSrcweir 		{
279*cdf0e10cSrcweir 			OUString aErrorMessage = getErrorLineString();
280*cdf0e10cSrcweir 			aErrorMessage += OUString( RTL_CONSTASCII_USTRINGPARAM( "Accelerator list element has to be used before!" ));
281*cdf0e10cSrcweir 			throw SAXException( aErrorMessage, Reference< XInterface >(), Any() );
282*cdf0e10cSrcweir 		}
283*cdf0e10cSrcweir 		else
284*cdf0e10cSrcweir 		{
285*cdf0e10cSrcweir 			// read accelerator item
286*cdf0e10cSrcweir 			m_bItemCloseExpected = sal_True;
287*cdf0e10cSrcweir 
288*cdf0e10cSrcweir 			SvtAcceleratorConfigItem aItem;
289*cdf0e10cSrcweir 
290*cdf0e10cSrcweir 			// read attributes for accelerator
291*cdf0e10cSrcweir 			for ( sal_Int16 i=0; i< xAttrList->getLength(); i++ )
292*cdf0e10cSrcweir 			{
293*cdf0e10cSrcweir 				OUString aName = xAttrList->getNameByIndex( i );
294*cdf0e10cSrcweir 				OUString aValue = xAttrList->getValueByIndex( i );
295*cdf0e10cSrcweir 
296*cdf0e10cSrcweir 				if ( aName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( ATTRIBUTE_URL )))
297*cdf0e10cSrcweir                     aItem.aCommand = aValue;
298*cdf0e10cSrcweir 				else if ( aName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( ATTRIBUTE_MODIFIER )))
299*cdf0e10cSrcweir 					aItem.nModifier = (sal_uInt16)aValue.toInt32();
300*cdf0e10cSrcweir 				else if ( aName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( ATTRIBUTE_KEYCODE )))
301*cdf0e10cSrcweir 					aItem.nCode = (sal_uInt16)aValue.toInt32();
302*cdf0e10cSrcweir 			}
303*cdf0e10cSrcweir 
304*cdf0e10cSrcweir 			m_aReadAcceleratorList.push_back( aItem );
305*cdf0e10cSrcweir 		}
306*cdf0e10cSrcweir 	}
307*cdf0e10cSrcweir 	else
308*cdf0e10cSrcweir 	{
309*cdf0e10cSrcweir 		OUString aErrorMessage = getErrorLineString();
310*cdf0e10cSrcweir 		aErrorMessage += OUString( RTL_CONSTASCII_USTRINGPARAM( "Unknown element found!" ));
311*cdf0e10cSrcweir 		throw SAXException( aErrorMessage, Reference< XInterface >(), Any() );
312*cdf0e10cSrcweir 	}
313*cdf0e10cSrcweir }
314*cdf0e10cSrcweir 
315*cdf0e10cSrcweir 
316*cdf0e10cSrcweir void SAL_CALL OReadAccelatorDocumentHandler::characters(const rtl::OUString&)
317*cdf0e10cSrcweir throw(	SAXException, RuntimeException )
318*cdf0e10cSrcweir {
319*cdf0e10cSrcweir }
320*cdf0e10cSrcweir 
321*cdf0e10cSrcweir 
322*cdf0e10cSrcweir void SAL_CALL OReadAccelatorDocumentHandler::endElement( const OUString& aName )
323*cdf0e10cSrcweir 	throw( SAXException, RuntimeException )
324*cdf0e10cSrcweir {
325*cdf0e10cSrcweir 	m_nElementDepth--;
326*cdf0e10cSrcweir 
327*cdf0e10cSrcweir 	if ( aName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( ELEMENT_ACCELERATORLIST )))
328*cdf0e10cSrcweir 	{
329*cdf0e10cSrcweir 		// acceleratorlist
330*cdf0e10cSrcweir 		if ( !m_bAcceleratorMode )
331*cdf0e10cSrcweir 		{
332*cdf0e10cSrcweir 			OUString aErrorMessage = getErrorLineString();
333*cdf0e10cSrcweir 			aErrorMessage += OUString( RTL_CONSTASCII_USTRINGPARAM( "Accelerator list used twice!" ));
334*cdf0e10cSrcweir 			throw SAXException( aErrorMessage, Reference< XInterface >(), Any() );
335*cdf0e10cSrcweir 		}
336*cdf0e10cSrcweir 	}
337*cdf0e10cSrcweir 	else if ( aName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( ELEMENT_ACCELERATORITEM )))
338*cdf0e10cSrcweir 	{
339*cdf0e10cSrcweir 		if ( !m_bItemCloseExpected )
340*cdf0e10cSrcweir 		{
341*cdf0e10cSrcweir 			OUString aErrorMessage = getErrorLineString();
342*cdf0e10cSrcweir 			aErrorMessage += OUString( RTL_CONSTASCII_USTRINGPARAM( "Closing accelerator item element expected!" ));
343*cdf0e10cSrcweir 			throw SAXException( aErrorMessage, Reference< XInterface >(), Any() );
344*cdf0e10cSrcweir 		}
345*cdf0e10cSrcweir 	}
346*cdf0e10cSrcweir 	else
347*cdf0e10cSrcweir 	{
348*cdf0e10cSrcweir 		OUString aErrorMessage = getErrorLineString();
349*cdf0e10cSrcweir 		aErrorMessage += OUString( RTL_CONSTASCII_USTRINGPARAM( "Unknown closing element found!" ));
350*cdf0e10cSrcweir 		throw SAXException( aErrorMessage, Reference< XInterface >(), Any() );
351*cdf0e10cSrcweir 	}
352*cdf0e10cSrcweir }
353*cdf0e10cSrcweir 
354*cdf0e10cSrcweir // ------------------------------------------------------------------
355*cdf0e10cSrcweir 
356*cdf0e10cSrcweir OWriteAccelatorDocumentHandler::OWriteAccelatorDocumentHandler(
357*cdf0e10cSrcweir 	const SvtAcceleratorItemList& aWriteAcceleratorList, Reference< XDocumentHandler > xDocumentHandler ) :
358*cdf0e10cSrcweir 	m_xWriteDocumentHandler( xDocumentHandler ),
359*cdf0e10cSrcweir 	m_aWriteAcceleratorList( aWriteAcceleratorList )
360*cdf0e10cSrcweir {
361*cdf0e10cSrcweir 	m_aAttributeType = OUString( RTL_CONSTASCII_USTRINGPARAM( ATTRIBUTE_TYPE_CDATA ));
362*cdf0e10cSrcweir }
363*cdf0e10cSrcweir 
364*cdf0e10cSrcweir OWriteAccelatorDocumentHandler::~OWriteAccelatorDocumentHandler()
365*cdf0e10cSrcweir {
366*cdf0e10cSrcweir }
367*cdf0e10cSrcweir 
368*cdf0e10cSrcweir void OWriteAccelatorDocumentHandler::WriteAcceleratorDocument()
369*cdf0e10cSrcweir 	throw ( SAXException, RuntimeException )
370*cdf0e10cSrcweir {
371*cdf0e10cSrcweir 	AttributeListImpl* pList = new AttributeListImpl;
372*cdf0e10cSrcweir 	Reference< XAttributeList > rList( (XAttributeList *)pList , UNO_QUERY );
373*cdf0e10cSrcweir 
374*cdf0e10cSrcweir 	m_xWriteDocumentHandler->startDocument();
375*cdf0e10cSrcweir 	m_xWriteDocumentHandler->startElement( OUString( RTL_CONSTASCII_USTRINGPARAM( ELEMENT_ACCELERATORLIST )), rList );
376*cdf0e10cSrcweir 	m_xWriteDocumentHandler->ignorableWhitespace( OUString() );
377*cdf0e10cSrcweir 
378*cdf0e10cSrcweir 	std::list< SvtAcceleratorConfigItem>::const_iterator p;
379*cdf0e10cSrcweir 	for ( p = m_aWriteAcceleratorList.begin(); p != m_aWriteAcceleratorList.end(); p++ )
380*cdf0e10cSrcweir 		WriteAcceleratorItem( *p );
381*cdf0e10cSrcweir 
382*cdf0e10cSrcweir 	m_xWriteDocumentHandler->endElement( OUString( RTL_CONSTASCII_USTRINGPARAM( ELEMENT_ACCELERATORLIST )) );
383*cdf0e10cSrcweir 	m_xWriteDocumentHandler->endDocument();
384*cdf0e10cSrcweir }
385*cdf0e10cSrcweir 
386*cdf0e10cSrcweir void OWriteAccelatorDocumentHandler::WriteAcceleratorItem(
387*cdf0e10cSrcweir 	const SvtAcceleratorConfigItem& aAcceleratorItem )
388*cdf0e10cSrcweir 	throw( SAXException, RuntimeException )
389*cdf0e10cSrcweir {
390*cdf0e10cSrcweir 	AttributeListImpl* pAcceleratorAttributes = new AttributeListImpl;
391*cdf0e10cSrcweir 	Reference< XAttributeList > xAcceleratorAttrList( (XAttributeList *)pAcceleratorAttributes , UNO_QUERY );
392*cdf0e10cSrcweir 
393*cdf0e10cSrcweir 	// set attributes
394*cdf0e10cSrcweir 	pAcceleratorAttributes->addAttribute(
395*cdf0e10cSrcweir 		OUString( RTL_CONSTASCII_USTRINGPARAM( ATTRIBUTE_KEYCODE )),
396*cdf0e10cSrcweir 		m_aAttributeType,
397*cdf0e10cSrcweir 		OUString::valueOf( aAcceleratorItem.nCode ));
398*cdf0e10cSrcweir 
399*cdf0e10cSrcweir 	pAcceleratorAttributes->addAttribute(
400*cdf0e10cSrcweir 		OUString( RTL_CONSTASCII_USTRINGPARAM( ATTRIBUTE_MODIFIER )),
401*cdf0e10cSrcweir 		m_aAttributeType,
402*cdf0e10cSrcweir 		OUString::valueOf( aAcceleratorItem.nModifier ));
403*cdf0e10cSrcweir 
404*cdf0e10cSrcweir 	pAcceleratorAttributes->addAttribute(
405*cdf0e10cSrcweir 		OUString( RTL_CONSTASCII_USTRINGPARAM( ATTRIBUTE_URL )),
406*cdf0e10cSrcweir 		m_aAttributeType,
407*cdf0e10cSrcweir         aAcceleratorItem.aCommand );
408*cdf0e10cSrcweir 
409*cdf0e10cSrcweir 	// write start element
410*cdf0e10cSrcweir 	m_xWriteDocumentHandler->startElement(
411*cdf0e10cSrcweir 		OUString( RTL_CONSTASCII_USTRINGPARAM( ELEMENT_ACCELERATORITEM )),
412*cdf0e10cSrcweir 		xAcceleratorAttrList );
413*cdf0e10cSrcweir 	m_xWriteDocumentHandler->ignorableWhitespace( OUString() );
414*cdf0e10cSrcweir 	m_xWriteDocumentHandler->endElement( OUString( RTL_CONSTASCII_USTRINGPARAM( ELEMENT_ACCELERATORITEM )) );
415*cdf0e10cSrcweir }
416