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 : #ifdef DEBUG_ELEMENT
23 : #include "ooxmlLoggers.hxx"
24 : #include <resourcemodel/Protocol.hxx>
25 : #endif
26 : #include "OOXMLFastDocumentHandler.hxx"
27 : #include "OOXMLFastContextHandler.hxx"
28 : #include "ooxml/OOXMLFastTokens.hxx"
29 : #include "OOXMLFactory.hxx"
30 :
31 : namespace writerfilter {
32 : namespace ooxml
33 : {
34 : using namespace ::com::sun::star;
35 : using namespace ::std;
36 :
37 :
38 1464 : OOXMLFastDocumentHandler::OOXMLFastDocumentHandler(
39 : uno::Reference< uno::XComponentContext > const & context,
40 : Stream* pStream,
41 : OOXMLDocument* pDocument,
42 : sal_Int32 nXNoteId )
43 : : m_xContext(context)
44 : , mpStream( pStream )
45 : #ifdef DEBUG_ELEMENT
46 : , mpTmpStream()
47 : #endif
48 : , mpDocument( pDocument )
49 : , mnXNoteId( nXNoteId )
50 1464 : , mpContextHandler()
51 : {
52 : #ifdef DEBUG_PROTOCOL
53 : if ( pStream )
54 : {
55 : mpTmpStream.reset( new StreamProtocol( pStream, debug_logger ) );
56 : mpStream = mpTmpStream.get();
57 : }
58 : #endif
59 1464 : }
60 :
61 : // ::com::sun::star::xml::sax::XFastContextHandler:
62 0 : void SAL_CALL OOXMLFastDocumentHandler::startFastElement
63 : (::sal_Int32
64 : #ifdef DEBUG_CONTEXT_STACK
65 : Element
66 : #endif
67 : , const uno::Reference< xml::sax::XFastAttributeList > & /*Attribs*/)
68 : throw (uno::RuntimeException, xml::sax::SAXException)
69 : {
70 : #ifdef DEBUG_CONTEXT_STACK
71 : clog << this << ":start element:"
72 : << fastTokenToId(Element)
73 : << endl;
74 : #endif
75 0 : }
76 :
77 0 : void SAL_CALL OOXMLFastDocumentHandler::startUnknownElement
78 : (const OUString &
79 : #ifdef DEBUG_CONTEXT_STACK
80 : Namespace
81 : #endif
82 : , const OUString &
83 : #ifdef DEBUG_CONTEXT_STACK
84 : Name
85 : #endif
86 : ,
87 : const uno::Reference< xml::sax::XFastAttributeList > & /*Attribs*/)
88 : throw (uno::RuntimeException, xml::sax::SAXException)
89 : {
90 : #ifdef DEBUG_CONTEXT_STACK
91 : clog << this << ":start unknown element:"
92 : << OUStringToOString(Namespace, RTL_TEXTENCODING_ASCII_US).getStr()
93 : << ":"
94 : << OUStringToOString(Name, RTL_TEXTENCODING_ASCII_US).getStr()
95 : << endl;
96 : #endif
97 0 : }
98 :
99 0 : void SAL_CALL OOXMLFastDocumentHandler::endFastElement(::sal_Int32
100 : #ifdef DEBUG_CONTEXT_STACK
101 : Element
102 : #endif
103 : )
104 : throw (uno::RuntimeException, xml::sax::SAXException)
105 : {
106 : #ifdef DEBUG_CONTEXT_STACK
107 : clog << this << ":end element:"
108 : << fastTokenToId(Element)
109 : << endl;
110 : #endif
111 0 : }
112 :
113 0 : void SAL_CALL OOXMLFastDocumentHandler::endUnknownElement
114 : (const OUString &
115 : #ifdef DEBUG_CONTEXT_STACK
116 : Namespace
117 : #endif
118 : , const OUString &
119 : #ifdef DEBUG_CONTEXT_STACK
120 : Name
121 : #endif
122 : )
123 : throw (uno::RuntimeException, xml::sax::SAXException)
124 : {
125 : #ifdef DEBUG_CONTEXT_STACK
126 : clog << this << ":end unknown element:"
127 : << OUStringToOString(Namespace, RTL_TEXTENCODING_ASCII_US).getStr()
128 : << ":"
129 : << OUStringToOString(Name, RTL_TEXTENCODING_ASCII_US).getStr()
130 : << endl;
131 : #endif
132 0 : }
133 :
134 : OOXMLFastContextHandler::Pointer_t
135 1072 : OOXMLFastDocumentHandler::getContextHandler() const
136 : {
137 1072 : if (mpContextHandler == OOXMLFastContextHandler::Pointer_t())
138 : {
139 : mpContextHandler.reset
140 828 : (new OOXMLFastContextHandler(m_xContext));
141 828 : mpContextHandler->setStream(mpStream);
142 828 : mpContextHandler->setDocument(mpDocument);
143 828 : mpContextHandler->setXNoteId(mnXNoteId);
144 828 : mpContextHandler->setForwardEvents(true);
145 : }
146 :
147 1072 : return mpContextHandler;
148 : }
149 :
150 : uno::Reference< xml::sax::XFastContextHandler > SAL_CALL
151 828 : OOXMLFastDocumentHandler::createFastChildContext
152 : (::sal_Int32 Element,
153 : const uno::Reference< xml::sax::XFastAttributeList > & /*Attribs*/)
154 : throw (uno::RuntimeException, xml::sax::SAXException)
155 : {
156 : #ifdef DEBUG_CONTEXT_STACK
157 : clog << this << ":createFastChildContext:"
158 : << fastTokenToId(Element)
159 : << endl;
160 : #endif
161 :
162 828 : if ( mpStream == 0 && mpDocument == 0 )
163 : {
164 : // document handler has been created as unknown child - see <OOXMLFastDocumentHandler::createUnknownChildContext(..)>
165 : // --> do not provide a child context
166 0 : return NULL;
167 : }
168 :
169 828 : return OOXMLFactory::getInstance()->createFastChildContextFromStart(getContextHandler().get(), Element);
170 : }
171 :
172 : uno::Reference< xml::sax::XFastContextHandler > SAL_CALL
173 0 : OOXMLFastDocumentHandler::createUnknownChildContext
174 : (const OUString &
175 : #ifdef DEBUG_CONTEXT_STACK
176 : Namespace
177 : #endif
178 : ,
179 : const OUString &
180 : #ifdef DEBUG_CONTEXT_STACK
181 : Name
182 : #endif
183 : , const uno::Reference< xml::sax::XFastAttributeList > & /*Attribs*/)
184 : throw (uno::RuntimeException, xml::sax::SAXException)
185 : {
186 : #ifdef DEBUG_CONTEXT_STACK
187 : clog << this << ":createUnknownChildContext:"
188 : << OUStringToOString(Namespace, RTL_TEXTENCODING_ASCII_US).getStr()
189 : << ":"
190 : << OUStringToOString(Name, RTL_TEXTENCODING_ASCII_US).getStr()
191 : << endl;
192 : #endif
193 :
194 : return uno::Reference< xml::sax::XFastContextHandler >
195 0 : ( new OOXMLFastDocumentHandler( m_xContext, 0, 0, 0 ) );
196 : }
197 :
198 0 : void SAL_CALL OOXMLFastDocumentHandler::characters(const OUString & /*aChars*/)
199 : throw (uno::RuntimeException, xml::sax::SAXException)
200 : {
201 0 : }
202 :
203 : // ::com::sun::star::xml::sax::XFastDocumentHandler:
204 828 : void SAL_CALL OOXMLFastDocumentHandler::startDocument()
205 : throw (uno::RuntimeException, xml::sax::SAXException)
206 : {
207 828 : }
208 :
209 827 : void SAL_CALL OOXMLFastDocumentHandler::endDocument()
210 : throw (uno::RuntimeException, xml::sax::SAXException)
211 : {
212 827 : }
213 :
214 828 : void SAL_CALL OOXMLFastDocumentHandler::setDocumentLocator
215 : (const uno::Reference< xml::sax::XLocator > & /*xLocator*/)
216 : throw (uno::RuntimeException, xml::sax::SAXException)
217 : {
218 828 : }
219 :
220 244 : void OOXMLFastDocumentHandler::setIsSubstream( bool bSubstream )
221 : {
222 244 : if ( mpStream != 0 && mpDocument != 0 )
223 : {
224 244 : getContextHandler( )->getParserState( )->setInSectionGroup( bSubstream );
225 : }
226 244 : }
227 :
228 24 : }}
229 :
230 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|