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