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 #include <iostream>
25 #include <boost/shared_ptr.hpp>
26 #ifdef DEBUG_CONTEXT_HANDLER
27 #include "ooxmlLoggers.hxx"
28 #endif
29 #ifdef DEBUG_PROTOCOL
30 #include <resourcemodel/Protocol.hxx>
31 #endif
32 #include "OOXMLFastDocumentHandler.hxx"
33 #include "OOXMLFastContextHandler.hxx"
34 #include "OOXMLFastTokens.hxx"
35 #include "OOXMLFactory.hxx"
36
37 namespace writerfilter {
38 namespace ooxml
39 {
40 using namespace ::com::sun::star;
41 using namespace ::std;
42
43
OOXMLFastDocumentHandler(uno::Reference<uno::XComponentContext> const & context,Stream * pStream,OOXMLDocument * pDocument)44 OOXMLFastDocumentHandler::OOXMLFastDocumentHandler(
45 uno::Reference< uno::XComponentContext > const & context,
46 Stream* pStream,
47 OOXMLDocument* pDocument )
48 : m_xContext(context)
49 , mpStream( pStream )
50 #ifdef DEBUG_ELEMENT
51 , mpTmpStream()
52 #endif
53 , mpDocument( pDocument )
54 , mpContextHandler()
55 {
56 #ifdef DEBUG_PROTOCOL
57 if ( pStream )
58 {
59 mpTmpStream.reset( new StreamProtocol( pStream, debug_logger ) );
60 mpStream = mpTmpStream.get();
61 }
62 #endif
63 }
64
65 // ::com::sun::star::xml::sax::XFastContextHandler:
startFastElement(::sal_Int32,const uno::Reference<xml::sax::XFastAttributeList> &)66 void SAL_CALL OOXMLFastDocumentHandler::startFastElement
67 (::sal_Int32 /*Element*/, const uno::Reference< xml::sax::XFastAttributeList > & /*Attribs*/)
68 throw (uno::RuntimeException, xml::sax::SAXException)
69 {
70 }
71
startUnknownElement(const::rtl::OUString &,const::rtl::OUString &,const uno::Reference<xml::sax::XFastAttributeList> &)72 void SAL_CALL OOXMLFastDocumentHandler::startUnknownElement
73 (const ::rtl::OUString & /*Namespace*/, const ::rtl::OUString & /*Name*/,
74 const uno::Reference< xml::sax::XFastAttributeList > & /*Attribs*/)
75 throw (uno::RuntimeException, xml::sax::SAXException)
76 {
77 }
78
endFastElement(::sal_Int32)79 void SAL_CALL OOXMLFastDocumentHandler::endFastElement(::sal_Int32 /*Element*/)
80 throw (uno::RuntimeException, xml::sax::SAXException)
81 {
82 }
83
endUnknownElement(const::rtl::OUString &,const::rtl::OUString &)84 void SAL_CALL OOXMLFastDocumentHandler::endUnknownElement
85 (const ::rtl::OUString & /*Namespace*/, const ::rtl::OUString & /*Name*/)
86 throw (uno::RuntimeException, xml::sax::SAXException)
87 {
88 }
89
90 OOXMLFastContextHandler::Pointer_t
getContextHandler() const91 OOXMLFastDocumentHandler::getContextHandler() const
92 {
93 if (mpContextHandler == OOXMLFastContextHandler::Pointer_t())
94 {
95 mpContextHandler.reset(
96 new OOXMLFastContextHandler(m_xContext) );
97 mpContextHandler->setStream(mpStream);
98 mpContextHandler->setDocument(mpDocument);
99 mpContextHandler->setForwardEvents(true);
100 }
101
102 return mpContextHandler;
103 }
104
105 uno::Reference< xml::sax::XFastContextHandler > SAL_CALL
createFastChildContext(::sal_Int32 Element,const uno::Reference<xml::sax::XFastAttributeList> &)106 OOXMLFastDocumentHandler::createFastChildContext
107 (::sal_Int32 Element,
108 const uno::Reference< xml::sax::XFastAttributeList > & /*Attribs*/)
109 throw (uno::RuntimeException, xml::sax::SAXException)
110 {
111
112 if ( mpStream == 0 && mpDocument == 0 )
113 {
114 // document handler has been created as unknown child - see <OOXMLFastDocumentHandler::createUnknownChildContext(..)>
115 // --> do not provide a child context
116 return NULL;
117 }
118
119 return OOXMLFactory::getInstance()->createFastChildContextFromStart(getContextHandler().get(), Element);
120 }
121
122 uno::Reference< xml::sax::XFastContextHandler > SAL_CALL
createUnknownChildContext(const::rtl::OUString &,const::rtl::OUString &,const uno::Reference<xml::sax::XFastAttributeList> &)123 OOXMLFastDocumentHandler::createUnknownChildContext
124 (const ::rtl::OUString & /*Namespace*/,
125 const ::rtl::OUString & /*Name*/,
126 const uno::Reference< xml::sax::XFastAttributeList > & /*Attribs*/)
127 throw (uno::RuntimeException, xml::sax::SAXException)
128 {
129 return uno::Reference< xml::sax::XFastContextHandler >
130 ( new OOXMLFastDocumentHandler( m_xContext, 0, 0 ) );
131 }
132
characters(const::rtl::OUString &)133 void SAL_CALL OOXMLFastDocumentHandler::characters(const ::rtl::OUString & /*aChars*/)
134 throw (uno::RuntimeException, xml::sax::SAXException)
135 {
136 }
137
138 // ::com::sun::star::xml::sax::XFastDocumentHandler:
startDocument()139 void SAL_CALL OOXMLFastDocumentHandler::startDocument()
140 throw (uno::RuntimeException, xml::sax::SAXException)
141 {
142 }
143
endDocument()144 void SAL_CALL OOXMLFastDocumentHandler::endDocument()
145 throw (uno::RuntimeException, xml::sax::SAXException)
146 {
147 }
148
setDocumentLocator(const uno::Reference<xml::sax::XLocator> &)149 void SAL_CALL OOXMLFastDocumentHandler::setDocumentLocator
150 (const uno::Reference< xml::sax::XLocator > & /*xLocator*/)
151 throw (uno::RuntimeException, xml::sax::SAXException)
152 {
153 }
154
setIsSubstream(bool bSubstream)155 void OOXMLFastDocumentHandler::setIsSubstream( bool bSubstream )
156 {
157 if ( mpStream != 0 && mpDocument != 0 )
158 {
159 getContextHandler( )->getParserState( )->setInSectionGroup( bSubstream );
160 }
161 }
162
163 }}
164