Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
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 .
18 : */
19 :
20 : #include <iostream>
21 : #include <boost/shared_ptr.hpp>
22 : #include "OOXMLFastDocumentHandler.hxx"
23 : #include "OOXMLFastContextHandler.hxx"
24 : #include "oox/token/tokens.hxx"
25 : #include "OOXMLFactory.hxx"
26 :
27 : namespace writerfilter {
28 : namespace ooxml
29 : {
30 : using namespace ::com::sun::star;
31 : using namespace ::std;
32 :
33 :
34 47846 : OOXMLFastDocumentHandler::OOXMLFastDocumentHandler(
35 : uno::Reference< uno::XComponentContext > const & context,
36 : Stream* pStream,
37 : OOXMLDocumentImpl* pDocument,
38 : sal_Int32 nXNoteId )
39 : : m_xContext(context)
40 : , mpStream( pStream )
41 : #ifdef DEBUG_WRITERFILTER
42 : , mpTmpStream()
43 : #endif
44 : , mpDocument( pDocument )
45 : , mnXNoteId( nXNoteId )
46 47846 : , mpContextHandler()
47 : {
48 47846 : }
49 :
50 : // ::com::sun::star::xml::sax::XFastContextHandler:
51 0 : void SAL_CALL OOXMLFastDocumentHandler::startFastElement
52 : (::sal_Int32
53 : #ifdef DEBUG_WRITERFILTER
54 : Element
55 : #endif
56 : , const uno::Reference< xml::sax::XFastAttributeList > & /*Attribs*/)
57 : throw (uno::RuntimeException, xml::sax::SAXException, std::exception)
58 : {
59 : #ifdef DEBUG_WRITERFILTER
60 : clog << this << ":start element:"
61 : << fastTokenToId(Element)
62 : << endl;
63 : #endif
64 0 : }
65 :
66 11202 : void SAL_CALL OOXMLFastDocumentHandler::startUnknownElement
67 : (const OUString &
68 : #ifdef DEBUG_WRITERFILTER
69 : Namespace
70 : #endif
71 : , const OUString &
72 : #ifdef DEBUG_WRITERFILTER
73 : Name
74 : #endif
75 : ,
76 : const uno::Reference< xml::sax::XFastAttributeList > & /*Attribs*/)
77 : throw (uno::RuntimeException, xml::sax::SAXException, std::exception)
78 : {
79 : #ifdef DEBUG_WRITERFILTER
80 : clog << this << ":start unknown element:"
81 : << OUStringToOString(Namespace, RTL_TEXTENCODING_ASCII_US).getStr()
82 : << ":"
83 : << OUStringToOString(Name, RTL_TEXTENCODING_ASCII_US).getStr()
84 : << endl;
85 : #endif
86 11202 : }
87 :
88 0 : void SAL_CALL OOXMLFastDocumentHandler::endFastElement(::sal_Int32
89 : #ifdef DEBUG_WRITERFILTER
90 : Element
91 : #endif
92 : )
93 : throw (uno::RuntimeException, xml::sax::SAXException, std::exception)
94 : {
95 : #ifdef DEBUG_WRITERFILTER
96 : clog << this << ":end element:"
97 : << fastTokenToId(Element)
98 : << endl;
99 : #endif
100 0 : }
101 :
102 11202 : void SAL_CALL OOXMLFastDocumentHandler::endUnknownElement
103 : (const OUString &
104 : #ifdef DEBUG_WRITERFILTER
105 : Namespace
106 : #endif
107 : , const OUString &
108 : #ifdef DEBUG_WRITERFILTER
109 : Name
110 : #endif
111 : )
112 : throw (uno::RuntimeException, xml::sax::SAXException, std::exception)
113 : {
114 : #ifdef DEBUG_WRITERFILTER
115 : clog << this << ":end unknown element:"
116 : << OUStringToOString(Namespace, RTL_TEXTENCODING_ASCII_US).getStr()
117 : << ":"
118 : << OUStringToOString(Name, RTL_TEXTENCODING_ASCII_US).getStr()
119 : << endl;
120 : #endif
121 11202 : }
122 :
123 : OOXMLFastContextHandler::Pointer_t
124 25186 : OOXMLFastDocumentHandler::getContextHandler() const
125 : {
126 25186 : if (mpContextHandler == OOXMLFastContextHandler::Pointer_t())
127 : {
128 : mpContextHandler.reset
129 19704 : (new OOXMLFastContextHandler(m_xContext));
130 19704 : mpContextHandler->setStream(mpStream);
131 19704 : mpContextHandler->setDocument(mpDocument);
132 19704 : mpContextHandler->setXNoteId(mnXNoteId);
133 19704 : mpContextHandler->setForwardEvents(true);
134 : }
135 :
136 25186 : return mpContextHandler;
137 : }
138 :
139 : uno::Reference< xml::sax::XFastContextHandler > SAL_CALL
140 19704 : OOXMLFastDocumentHandler::createFastChildContext
141 : (::sal_Int32 Element,
142 : const uno::Reference< xml::sax::XFastAttributeList > & /*Attribs*/)
143 : throw (uno::RuntimeException, xml::sax::SAXException, std::exception)
144 : {
145 : #ifdef DEBUG_WRITERFILTER
146 : clog << this << ":createFastChildContext:"
147 : << fastTokenToId(Element)
148 : << endl;
149 : #endif
150 :
151 19704 : if ( mpStream == nullptr && mpDocument == nullptr )
152 : {
153 : // document handler has been created as unknown child - see <OOXMLFastDocumentHandler::createUnknownChildContext(..)>
154 : // --> do not provide a child context
155 0 : return nullptr;
156 : }
157 :
158 19704 : return OOXMLFactory::getInstance()->createFastChildContextFromStart(getContextHandler().get(), Element);
159 : }
160 :
161 : uno::Reference< xml::sax::XFastContextHandler > SAL_CALL
162 11202 : OOXMLFastDocumentHandler::createUnknownChildContext
163 : (const OUString &
164 : #ifdef DEBUG_WRITERFILTER
165 : Namespace
166 : #endif
167 : ,
168 : const OUString &
169 : #ifdef DEBUG_WRITERFILTER
170 : Name
171 : #endif
172 : , const uno::Reference< xml::sax::XFastAttributeList > & /*Attribs*/)
173 : throw (uno::RuntimeException, xml::sax::SAXException, std::exception)
174 : {
175 : #ifdef DEBUG_WRITERFILTER
176 : clog << this << ":createUnknownChildContext:"
177 : << OUStringToOString(Namespace, RTL_TEXTENCODING_ASCII_US).getStr()
178 : << ":"
179 : << OUStringToOString(Name, RTL_TEXTENCODING_ASCII_US).getStr()
180 : << endl;
181 : #endif
182 :
183 : return uno::Reference< xml::sax::XFastContextHandler >
184 11202 : ( new OOXMLFastDocumentHandler( m_xContext, nullptr, nullptr, 0 ) );
185 : }
186 :
187 9306 : void SAL_CALL OOXMLFastDocumentHandler::characters(const OUString & /*aChars*/)
188 : throw (uno::RuntimeException, xml::sax::SAXException, std::exception)
189 : {
190 9306 : }
191 :
192 : // ::com::sun::star::xml::sax::XFastDocumentHandler:
193 20678 : void SAL_CALL OOXMLFastDocumentHandler::startDocument()
194 : throw (uno::RuntimeException, xml::sax::SAXException, std::exception)
195 : {
196 20678 : }
197 :
198 20668 : void SAL_CALL OOXMLFastDocumentHandler::endDocument()
199 : throw (uno::RuntimeException, xml::sax::SAXException, std::exception)
200 : {
201 20668 : }
202 :
203 20678 : void SAL_CALL OOXMLFastDocumentHandler::setDocumentLocator
204 : (const uno::Reference< xml::sax::XLocator > & /*xLocator*/)
205 : throw (uno::RuntimeException, xml::sax::SAXException, std::exception)
206 : {
207 20678 : }
208 :
209 5482 : void OOXMLFastDocumentHandler::setIsSubstream( bool bSubstream )
210 : {
211 5482 : if ( mpStream != nullptr && mpDocument != nullptr )
212 : {
213 5482 : getContextHandler( )->getParserState( )->setInSectionGroup( bSubstream );
214 : }
215 5482 : }
216 :
217 114 : }}
218 :
219 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|