1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: OOXMLFastDocumentHandler.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
32 #include <boost/shared_ptr.hpp>
33 #include "OOXMLFastDocumentHandler.hxx"
34 #include "OOXMLFastContextHandler.hxx"
35 #include "OOXMLFastTokens.hxx"
37 namespace writerfilter
{
40 using namespace ::com::sun::star
;
41 using namespace ::std
;
44 OOXMLFastDocumentHandler::OOXMLFastDocumentHandler
45 (uno::Reference
< uno::XComponentContext
> const & context
)
49 // ::com::sun::star::xml::sax::XFastContextHandler:
50 void SAL_CALL
OOXMLFastDocumentHandler::startFastElement
52 #ifdef DEBUG_CONTEXT_STACK
55 , const uno::Reference
< xml::sax::XFastAttributeList
> & /*Attribs*/)
56 throw (uno::RuntimeException
, xml::sax::SAXException
)
58 #ifdef DEBUG_CONTEXT_STACK
59 clog
<< this << ":start element:"
60 << fastTokenToId(Element
)
65 void SAL_CALL
OOXMLFastDocumentHandler::startUnknownElement
66 (const ::rtl::OUString
&
67 #ifdef DEBUG_CONTEXT_STACK
70 , const ::rtl::OUString
&
71 #ifdef DEBUG_CONTEXT_STACK
75 const uno::Reference
< xml::sax::XFastAttributeList
> & /*Attribs*/)
76 throw (uno::RuntimeException
, xml::sax::SAXException
)
78 #ifdef DEBUG_CONTEXT_STACK
79 clog
<< this << ":start unknown element:"
80 << OUStringToOString(Namespace
, RTL_TEXTENCODING_ASCII_US
).getStr()
82 << OUStringToOString(Name
, RTL_TEXTENCODING_ASCII_US
).getStr()
87 void SAL_CALL
OOXMLFastDocumentHandler::endFastElement(::sal_Int32
88 #ifdef DEBUG_CONTEXT_STACK
92 throw (uno::RuntimeException
, xml::sax::SAXException
)
94 #ifdef DEBUG_CONTEXT_STACK
95 clog
<< this << ":end element:"
96 << fastTokenToId(Element
)
101 void SAL_CALL
OOXMLFastDocumentHandler::endUnknownElement
102 (const ::rtl::OUString
&
103 #ifdef DEBUG_CONTEXT_STACK
106 , const ::rtl::OUString
&
107 #ifdef DEBUG_CONTEXT_STACK
111 throw (uno::RuntimeException
, xml::sax::SAXException
)
113 #ifdef DEBUG_CONTEXT_STACK
114 clog
<< this << ":end unknown element:"
115 << OUStringToOString(Namespace
, RTL_TEXTENCODING_ASCII_US
).getStr()
117 << OUStringToOString(Name
, RTL_TEXTENCODING_ASCII_US
).getStr()
122 OOXMLFastContextHandler::Pointer_t
123 OOXMLFastDocumentHandler::getContextHandler() const
125 if (mpContextHandler
== OOXMLFastContextHandler::Pointer_t())
127 mpContextHandler
.reset
128 (new OOXMLFastContextHandler(m_xContext
));
129 mpContextHandler
->setStream(mpStream
);
130 mpContextHandler
->setDocument(mpDocument
);
131 mpContextHandler
->setXNoteId(msXNoteId
);
132 mpContextHandler
->setForwardEvents(true);
135 return mpContextHandler
;
138 uno::Reference
< xml::sax::XFastContextHandler
> SAL_CALL
139 OOXMLFastDocumentHandler::createFastChildContext
140 (::sal_Int32 Element
,
141 const uno::Reference
< xml::sax::XFastAttributeList
> & Attribs
)
142 throw (uno::RuntimeException
, xml::sax::SAXException
)
144 #ifdef DEBUG_CONTEXT_STACK
145 clog
<< this << ":createFastChildContext:"
146 << fastTokenToId(Element
)
150 return getContextHandler()->createFromStart(Element
, Attribs
);
153 OOXMLParserState::Pointer_t
OOXMLFastDocumentHandler::getParserState() const
155 OOXMLParserState::Pointer_t pParserState
;
157 return getContextHandler()->getParserState();
160 uno::Reference
< xml::sax::XFastContextHandler
> SAL_CALL
161 OOXMLFastDocumentHandler::createUnknownChildContext
162 (const ::rtl::OUString
&
163 #ifdef DEBUG_CONTEXT_STACK
167 const ::rtl::OUString
&
168 #ifdef DEBUG_CONTEXT_STACK
171 , const uno::Reference
< xml::sax::XFastAttributeList
> & /*Attribs*/)
172 throw (uno::RuntimeException
, xml::sax::SAXException
)
174 #ifdef DEBUG_CONTEXT_STACK
175 clog
<< this << ":createUnknownChildContext:"
176 << OUStringToOString(Namespace
, RTL_TEXTENCODING_ASCII_US
).getStr()
178 << OUStringToOString(Name
, RTL_TEXTENCODING_ASCII_US
).getStr()
182 return uno::Reference
< xml::sax::XFastContextHandler
>
183 (new OOXMLFastDocumentHandler(m_xContext
));
186 void SAL_CALL
OOXMLFastDocumentHandler::characters(const ::rtl::OUString
& /*aChars*/)
187 throw (uno::RuntimeException
, xml::sax::SAXException
)
189 // TODO: Insert your implementation for "characters" here.
192 // ::com::sun::star::xml::sax::XFastDocumentHandler:
193 void SAL_CALL
OOXMLFastDocumentHandler::startDocument()
194 throw (uno::RuntimeException
, xml::sax::SAXException
)
198 void SAL_CALL
OOXMLFastDocumentHandler::endDocument()
199 throw (uno::RuntimeException
, xml::sax::SAXException
)
201 #ifdef DEBUG_CONTEXT_STACK
202 OOXMLFastContextHandler::dumpOpenContexts();
206 void SAL_CALL
OOXMLFastDocumentHandler::setDocumentLocator
207 (const uno::Reference
< xml::sax::XLocator
> & /*xLocator*/)
208 throw (uno::RuntimeException
, xml::sax::SAXException
)
210 // TODO: Insert your implementation for "setDocumentLocator" here.
213 void OOXMLFastDocumentHandler::setStream(Stream
* pStream
)
218 void OOXMLFastDocumentHandler::setDocument(OOXMLDocument
* pDocument
)
220 mpDocument
= pDocument
;
223 void OOXMLFastDocumentHandler::setXNoteId(const ::rtl::OUString
& rXNoteId
)
225 msXNoteId
= rXNoteId
;
228 void OOXMLFastDocumentHandler::setIsSubstream( bool bSubstream
)
230 getContextHandler( )->getParserState( )->setInSectionGroup( bSubstream
);