xref: /aoo4110/main/oox/inc/oox/core/fastparser.hxx (revision b1cdbd2c)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 #ifndef OOX_CORE_FASTPARSER_HXX
25 #define OOX_CORE_FASTPARSER_HXX
26 
27 #include <com/sun/star/uno/XComponentContext.hpp>
28 #include <com/sun/star/xml/sax/XFastParser.hpp>
29 
30 namespace oox {
31     struct NamespaceMap;
32     class StorageBase;
33 }
34 
35 namespace oox {
36 namespace core {
37 
38 // ============================================================================
39 
40 /** Wrapper for a fast SAX parser that works on automatically generated OOXML
41     token and namespace identifiers.
42  */
43 class FastParser
44 {
45 public:
46     explicit            FastParser(
47                             const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >& rxContext )
48                             throw( ::com::sun::star::uno::RuntimeException );
49 
50     virtual             ~FastParser();
51 
52     /** Registers an OOXML namespace at the parser. */
53     void                registerNamespace( sal_Int32 nNamespaceId )
54     		                throw( ::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException );
55 
56     /** Sets the passed document handler that will receive the SAX parser events. */
57     void                setDocumentHandler(
58                             const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XFastDocumentHandler >& rxDocHandler )
59     		                throw( ::com::sun::star::uno::RuntimeException );
60 
61     /** Parses the passed SAX input source.
62         @param bCloseStream  True = closes the stream in the input source after parsing. */
63     void                parseStream( const ::com::sun::star::xml::sax::InputSource& rInputSource, bool bCloseStream = false )
64                             throw( ::com::sun::star::xml::sax::SAXException, ::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException );
65 
66     /** Parses the passed input stream.
67         @param bCloseStream  True = closes the passed stream after parsing. */
68     void                parseStream(
69                             const ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream >& rxInStream,
70                             const ::rtl::OUString& rStreamName, bool bCloseStream = false )
71                             throw( ::com::sun::star::xml::sax::SAXException, ::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException );
72 
73     /** Parses a stream from the passed storage with the specified name.
74         @param bCloseStream  True = closes the stream after parsing. */
75     void                parseStream( StorageBase& rStorage, const ::rtl::OUString& rStreamName, bool bCloseStream = false )
76                             throw( ::com::sun::star::xml::sax::SAXException, ::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException );
77 
78 private:
79     ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XFastParser >
80                         mxParser;
81     const NamespaceMap& mrNamespaceMap;
82 };
83 
84 // ============================================================================
85 
86 } // namespace core
87 } // namespace oox
88 
89 #endif
90