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 .
21 #include <boost/shared_ptr.hpp>
23 #include "ooxmlLoggers.hxx"
24 #include <resourcemodel/Protocol.hxx>
26 #include "OOXMLFastDocumentHandler.hxx"
27 #include "OOXMLFastContextHandler.hxx"
28 #include "ooxml/OOXMLFastTokens.hxx"
29 #include "OOXMLFactory.hxx"
31 namespace writerfilter
{
34 using namespace ::com::sun::star
;
35 using namespace ::std
;
38 OOXMLFastDocumentHandler::OOXMLFastDocumentHandler
39 (uno::Reference
< uno::XComponentContext
> const & context
)
40 : m_xContext(context
), mpStream(0), mpDocument(0)
43 // ::com::sun::star::xml::sax::XFastContextHandler:
44 void SAL_CALL
OOXMLFastDocumentHandler::startFastElement
46 #ifdef DEBUG_CONTEXT_STACK
49 , const uno::Reference
< xml::sax::XFastAttributeList
> & /*Attribs*/)
50 throw (uno::RuntimeException
, xml::sax::SAXException
)
52 #ifdef DEBUG_CONTEXT_STACK
53 clog
<< this << ":start element:"
54 << fastTokenToId(Element
)
59 void SAL_CALL
OOXMLFastDocumentHandler::startUnknownElement
61 #ifdef DEBUG_CONTEXT_STACK
65 #ifdef DEBUG_CONTEXT_STACK
69 const uno::Reference
< xml::sax::XFastAttributeList
> & /*Attribs*/)
70 throw (uno::RuntimeException
, xml::sax::SAXException
)
72 #ifdef DEBUG_CONTEXT_STACK
73 clog
<< this << ":start unknown element:"
74 << OUStringToOString(Namespace
, RTL_TEXTENCODING_ASCII_US
).getStr()
76 << OUStringToOString(Name
, RTL_TEXTENCODING_ASCII_US
).getStr()
81 void SAL_CALL
OOXMLFastDocumentHandler::endFastElement(::sal_Int32
82 #ifdef DEBUG_CONTEXT_STACK
86 throw (uno::RuntimeException
, xml::sax::SAXException
)
88 #ifdef DEBUG_CONTEXT_STACK
89 clog
<< this << ":end element:"
90 << fastTokenToId(Element
)
95 void SAL_CALL
OOXMLFastDocumentHandler::endUnknownElement
97 #ifdef DEBUG_CONTEXT_STACK
101 #ifdef DEBUG_CONTEXT_STACK
105 throw (uno::RuntimeException
, xml::sax::SAXException
)
107 #ifdef DEBUG_CONTEXT_STACK
108 clog
<< this << ":end unknown element:"
109 << OUStringToOString(Namespace
, RTL_TEXTENCODING_ASCII_US
).getStr()
111 << OUStringToOString(Name
, RTL_TEXTENCODING_ASCII_US
).getStr()
116 OOXMLFastContextHandler::Pointer_t
117 OOXMLFastDocumentHandler::getContextHandler() const
119 if (mpContextHandler
== OOXMLFastContextHandler::Pointer_t())
121 mpContextHandler
.reset
122 (new OOXMLFastContextHandler(m_xContext
));
123 mpContextHandler
->setStream(mpStream
);
124 mpContextHandler
->setDocument(mpDocument
);
125 mpContextHandler
->setXNoteId(mnXNoteId
);
126 mpContextHandler
->setForwardEvents(true);
129 return mpContextHandler
;
132 uno::Reference
< xml::sax::XFastContextHandler
> SAL_CALL
133 OOXMLFastDocumentHandler::createFastChildContext
134 (::sal_Int32 Element
,
135 const uno::Reference
< xml::sax::XFastAttributeList
> & /*Attribs*/)
136 throw (uno::RuntimeException
, xml::sax::SAXException
)
138 #ifdef DEBUG_CONTEXT_STACK
139 clog
<< this << ":createFastChildContext:"
140 << fastTokenToId(Element
)
144 return OOXMLFactory::getInstance()->createFastChildContextFromStart(getContextHandler().get(), Element
);
147 uno::Reference
< xml::sax::XFastContextHandler
> SAL_CALL
148 OOXMLFastDocumentHandler::createUnknownChildContext
150 #ifdef DEBUG_CONTEXT_STACK
155 #ifdef DEBUG_CONTEXT_STACK
158 , const uno::Reference
< xml::sax::XFastAttributeList
> & /*Attribs*/)
159 throw (uno::RuntimeException
, xml::sax::SAXException
)
161 #ifdef DEBUG_CONTEXT_STACK
162 clog
<< this << ":createUnknownChildContext:"
163 << OUStringToOString(Namespace
, RTL_TEXTENCODING_ASCII_US
).getStr()
165 << OUStringToOString(Name
, RTL_TEXTENCODING_ASCII_US
).getStr()
169 return uno::Reference
< xml::sax::XFastContextHandler
>
170 (new OOXMLFastDocumentHandler(m_xContext
));
173 void SAL_CALL
OOXMLFastDocumentHandler::characters(const OUString
& /*aChars*/)
174 throw (uno::RuntimeException
, xml::sax::SAXException
)
176 // TODO: Insert your implementation for "characters" here.
179 // ::com::sun::star::xml::sax::XFastDocumentHandler:
180 void SAL_CALL
OOXMLFastDocumentHandler::startDocument()
181 throw (uno::RuntimeException
, xml::sax::SAXException
)
185 void SAL_CALL
OOXMLFastDocumentHandler::endDocument()
186 throw (uno::RuntimeException
, xml::sax::SAXException
)
190 void SAL_CALL
OOXMLFastDocumentHandler::setDocumentLocator
191 (const uno::Reference
< xml::sax::XLocator
> & /*xLocator*/)
192 throw (uno::RuntimeException
, xml::sax::SAXException
)
194 // TODO: Insert your implementation for "setDocumentLocator" here.
197 void OOXMLFastDocumentHandler::setStream(Stream
* pStream
)
199 #ifdef DEBUG_PROTOCOL
200 mpTmpStream
.reset(new StreamProtocol(pStream
, debug_logger
));
201 mpStream
= mpTmpStream
.get();
207 void OOXMLFastDocumentHandler::setDocument(OOXMLDocument
* pDocument
)
209 mpDocument
= pDocument
;
212 void OOXMLFastDocumentHandler::setXNoteId(const sal_Int32 nXNoteId
)
214 mnXNoteId
= nXNoteId
;
217 void OOXMLFastDocumentHandler::setIsSubstream( bool bSubstream
)
219 getContextHandler( )->getParserState( )->setInSectionGroup( bSubstream
);
224 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */