fdo#74697 Add Bluez 5 support for impress remote.
[LibreOffice.git] / sax / source / fastparser / fastparser.hxx
blobdab438f81422067aa84b075908022e0df3bda8b8
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 #ifndef _SAX_FASTPARSER_HXX_
21 #define _SAX_FASTPARSER_HXX_
23 #include <vector>
24 #include <stack>
25 #include <boost/unordered_map.hpp>
26 #include <boost/shared_ptr.hpp>
27 #include <rtl/ref.hxx>
28 #include <com/sun/star/xml/sax/XFastParser.hpp>
29 #include <com/sun/star/xml/sax/XFastTokenHandler.hpp>
30 #include <com/sun/star/xml/sax/XFastDocumentHandler.hpp>
31 #include <com/sun/star/lang/XServiceInfo.hpp>
32 #include <cppuhelper/implbase2.hxx>
34 #include <expat.h>
35 #include "xml2utf.hxx"
37 #include <sax/fastattribs.hxx>
39 #define PARSER_IMPLEMENTATION_NAME "com.sun.star.comp.extensions.xml.sax.FastParser"
40 #define PARSER_SERVICE_NAME "com.sun.star.xml.sax.FastParser"
42 namespace sax_fastparser {
44 class FastLocatorImpl;
45 struct NamespaceDefine;
46 struct SaxContextImpl;
48 typedef ::boost::shared_ptr< SaxContextImpl > SaxContextImplPtr;
49 typedef ::boost::shared_ptr< NamespaceDefine > NamespaceDefineRef;
51 typedef ::boost::unordered_map< OUString, sal_Int32,
52 OUStringHash, ::std::equal_to< OUString > > NamespaceMap;
54 // --------------------------------------------------------------------
56 struct ParserData
58 ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XFastDocumentHandler > mxDocumentHandler;
59 ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XFastTokenHandler > mxTokenHandler;
60 ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XErrorHandler > mxErrorHandler;
61 ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XEntityResolver > mxEntityResolver;
62 ::com::sun::star::lang::Locale maLocale;
64 ParserData();
65 ~ParserData();
68 // --------------------------------------------------------------------
70 // Entity binds all information needed for a single file
71 struct Entity : public ParserData
73 ::com::sun::star::xml::sax::InputSource maStructSource;
74 XML_Parser mpParser;
75 ::sax_expatwrap::XMLFile2UTFConverter maConverter;
76 ::rtl::Reference< FastAttributeList > mxAttributes;
78 // Exceptions cannot be thrown through the C-XmlParser (possible resource leaks),
79 // therefore the exception must be saved somewhere.
80 ::com::sun::star::uno::Any maSavedException;
82 ::std::stack< SaxContextImplPtr > maContextStack;
83 ::std::vector< NamespaceDefineRef > maNamespaceDefines;
85 explicit Entity( const ParserData& rData );
86 ~Entity();
89 // --------------------------------------------------------------------
91 // This class implements the external Parser interface
92 class FastSaxParser : public ::cppu::WeakImplHelper2< ::com::sun::star::xml::sax::XFastParser, ::com::sun::star::lang::XServiceInfo >
94 public:
95 FastSaxParser();
96 virtual ~FastSaxParser();
98 // The implementation details
99 static ::com::sun::star::uno::Sequence< OUString > getSupportedServiceNames_Static(void);
101 // XFastParser
102 virtual void SAL_CALL parseStream( const ::com::sun::star::xml::sax::InputSource& aInputSource ) throw (::com::sun::star::xml::sax::SAXException, ::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException);
103 virtual void SAL_CALL setFastDocumentHandler( const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XFastDocumentHandler >& Handler ) throw (::com::sun::star::uno::RuntimeException);
104 virtual void SAL_CALL setTokenHandler( const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XFastTokenHandler >& Handler ) throw (::com::sun::star::uno::RuntimeException);
105 virtual void SAL_CALL registerNamespace( const OUString& NamespaceURL, sal_Int32 NamespaceToken ) throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException);
106 virtual OUString SAL_CALL getNamespaceURL( const OUString& rPrefix ) throw(::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException);
107 virtual void SAL_CALL setErrorHandler( const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XErrorHandler >& Handler ) throw (::com::sun::star::uno::RuntimeException);
108 virtual void SAL_CALL setEntityResolver( const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XEntityResolver >& Resolver ) throw (::com::sun::star::uno::RuntimeException);
109 virtual void SAL_CALL setLocale( const ::com::sun::star::lang::Locale& rLocale ) throw (::com::sun::star::uno::RuntimeException);
111 // XServiceInfo
112 virtual OUString SAL_CALL getImplementationName( ) throw (::com::sun::star::uno::RuntimeException);
113 virtual sal_Bool SAL_CALL supportsService( const OUString& ServiceName ) throw (::com::sun::star::uno::RuntimeException);
114 virtual ::com::sun::star::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames( ) throw (::com::sun::star::uno::RuntimeException);
116 // called by the C callbacks of the expat parser
117 void callbackStartElement( const XML_Char* name, const XML_Char** atts );
118 void callbackEndElement( const XML_Char* name );
119 void callbackCharacters( const XML_Char* s, int nLen );
120 int callbackExternalEntityRef( XML_Parser parser, const XML_Char *openEntityNames, const XML_Char *base, const XML_Char *systemId, const XML_Char *publicId);
121 void callbackEntityDecl(const XML_Char *entityName, int is_parameter_entity,
122 const XML_Char *value, int value_length, const XML_Char *base,
123 const XML_Char *systemId, const XML_Char *publicId,
124 const XML_Char *notationName);
126 inline void pushEntity( const Entity& rEntity ) { maEntities.push( rEntity ); }
127 inline void popEntity() { maEntities.pop(); }
128 Entity& getEntity() { return maEntities.top(); }
130 private:
131 void parse();
133 sal_Int32 GetToken( const OString& rToken );
134 sal_Int32 GetToken( const sal_Char* pToken, sal_Int32 nTokenLen = 0 );
135 sal_Int32 GetTokenWithPrefix( const OString& rPrefix, const OString& rName ) throw (::com::sun::star::xml::sax::SAXException);
136 sal_Int32 GetTokenWithPrefix( const sal_Char*pPrefix, int nPrefixLen, const sal_Char* pName, int nNameLen ) throw (::com::sun::star::xml::sax::SAXException);
137 OUString GetNamespaceURL( const OString& rPrefix ) throw (::com::sun::star::xml::sax::SAXException);
138 OUString GetNamespaceURL( const sal_Char*pPrefix, int nPrefixLen ) throw (::com::sun::star::xml::sax::SAXException);
139 sal_Int32 GetNamespaceToken( const OUString& rNamespaceURL );
140 sal_Int32 GetTokenWithNamespaceURL( const OUString& rNamespaceURL, const sal_Char* pName, int nNameLen );
141 void DefineNamespace( const OString& rPrefix, const sal_Char* pNamespaceURL );
142 sal_Int32 CreateCustomToken( const sal_Char* pToken, int len = 0 );
144 void pushContext();
145 void popContext();
147 void splitName( const XML_Char *pwName, const XML_Char *&rpPrefix, sal_Int32 &rPrefixLen, const XML_Char *&rpName, sal_Int32 &rNameLen );
149 private:
150 ::osl::Mutex maMutex;
152 ::rtl::Reference< FastLocatorImpl > mxDocumentLocator;
153 NamespaceMap maNamespaceMap;
155 ParserData maData; /// Cached parser configuration for next call of parseStream().
156 ::std::stack< Entity > maEntities; /// Entity stack for each call of parseStream().
161 #endif // _SAX_FASTPARSER_HXX_
163 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */