1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <unotools/xmlaccelcfg.hxx>
23 #include <com/sun/star/xml/sax/XAttributeList.hpp>
24 #include <cppuhelper/implbase1.hxx>
26 using namespace com::sun::star::uno
;
27 using namespace com::sun::star::xml::sax
;
29 #define ELEMENT_ACCELERATORLIST "acceleratorlist"
30 #define ELEMENT_ACCELERATORITEM "item"
32 #define ATTRIBUTE_KEYCODE "code"
33 #define ATTRIBUTE_MODIFIER "modifier"
34 #define ATTRIBUTE_URL "url"
36 Any SAL_CALL
OReadAccelatorDocumentHandler::queryInterface( const Type
& rType
) throw( RuntimeException
, std::exception
)
38 Any a
= ::cppu::queryInterface( rType
,(static_cast< XDocumentHandler
* >(this)));
42 return OWeakObject::queryInterface( rType
);
45 void SAL_CALL
OReadAccelatorDocumentHandler::ignorableWhitespace(
47 throw( SAXException
, RuntimeException
, std::exception
)
51 void SAL_CALL
OReadAccelatorDocumentHandler::processingInstruction(
52 const OUString
&, const OUString
& )
53 throw( SAXException
, RuntimeException
, std::exception
)
57 void SAL_CALL
OReadAccelatorDocumentHandler::setDocumentLocator(
58 const Reference
< XLocator
> &xLocator
)
59 throw( SAXException
, RuntimeException
, std::exception
)
61 m_xLocator
= xLocator
;
64 OUString
OReadAccelatorDocumentHandler::getErrorLineString()
68 if ( m_xLocator
.is() )
70 return OUString::createFromAscii( buffer
);
76 void SAL_CALL
OReadAccelatorDocumentHandler::startDocument(void)
77 throw ( SAXException
, RuntimeException
, std::exception
)
81 void SAL_CALL
OReadAccelatorDocumentHandler::endDocument(void)
82 throw( SAXException
, RuntimeException
, std::exception
)
84 if ( m_nElementDepth
> 0 )
86 OUString aErrorMessage
= getErrorLineString();
87 aErrorMessage
+= "A closing element is missing!";
88 throw SAXException( aErrorMessage
, Reference
< XInterface
>(), Any() );
92 void SAL_CALL
OReadAccelatorDocumentHandler::startElement(
93 const OUString
& aElementName
, const Reference
< XAttributeList
> &xAttrList
)
94 throw( SAXException
, RuntimeException
, std::exception
)
98 if ( aElementName
== ELEMENT_ACCELERATORLIST
)
101 if ( m_bAcceleratorMode
)
103 OUString aErrorMessage
= getErrorLineString();
104 aErrorMessage
+= "Accelerator list used twice!";
105 throw SAXException( aErrorMessage
, Reference
< XInterface
>(), Any() );
108 m_bAcceleratorMode
= true;
110 else if ( aElementName
== ELEMENT_ACCELERATORITEM
)
113 if ( !m_bAcceleratorMode
)
115 OUString aErrorMessage
= getErrorLineString();
116 aErrorMessage
+= "Accelerator list element has to be used before!";
117 throw SAXException( aErrorMessage
, Reference
< XInterface
>(), Any() );
121 // read accelerator item
122 m_bItemCloseExpected
= true;
124 SvtAcceleratorConfigItem aItem
;
126 // read attributes for accelerator
127 for ( sal_Int16 i
=0; i
< xAttrList
->getLength(); i
++ )
129 OUString aName
= xAttrList
->getNameByIndex( i
);
130 OUString aValue
= xAttrList
->getValueByIndex( i
);
132 if ( aName
== ATTRIBUTE_URL
)
133 aItem
.aCommand
= aValue
;
134 else if ( aName
== ATTRIBUTE_MODIFIER
)
135 aItem
.nModifier
= (sal_uInt16
)aValue
.toInt32();
136 else if ( aName
== ATTRIBUTE_KEYCODE
)
137 aItem
.nCode
= (sal_uInt16
)aValue
.toInt32();
140 m_aReadAcceleratorList
.push_back( aItem
);
145 OUString aErrorMessage
= getErrorLineString();
146 aErrorMessage
+= "Unknown element found!";
147 throw SAXException( aErrorMessage
, Reference
< XInterface
>(), Any() );
151 void SAL_CALL
OReadAccelatorDocumentHandler::characters(const OUString
&)
152 throw( SAXException
, RuntimeException
, std::exception
)
156 void SAL_CALL
OReadAccelatorDocumentHandler::endElement( const OUString
& aName
)
157 throw( SAXException
, RuntimeException
, std::exception
)
161 if ( aName
== ELEMENT_ACCELERATORLIST
)
164 if ( !m_bAcceleratorMode
)
166 OUString aErrorMessage
= getErrorLineString();
167 aErrorMessage
+= "Accelerator list used twice!";
168 throw SAXException( aErrorMessage
, Reference
< XInterface
>(), Any() );
171 else if ( aName
== ELEMENT_ACCELERATORITEM
)
173 if ( !m_bItemCloseExpected
)
175 OUString aErrorMessage
= getErrorLineString();
176 aErrorMessage
+= "Closing accelerator item element expected!";
177 throw SAXException( aErrorMessage
, Reference
< XInterface
>(), Any() );
182 OUString aErrorMessage
= getErrorLineString();
183 aErrorMessage
+= "Unknown closing element found!";
184 throw SAXException( aErrorMessage
, Reference
< XInterface
>(), Any() );
188 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */