Branch data 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 <com/sun/star/xml/sax/XParser.hpp>
21 : :
22 : : #include <com/sun/star/xml/sax/SAXException.hpp>
23 : : #include <doctok/resourceids.hxx>
24 : : #include <ooxml/resourceids.hxx>
25 : : #include "OOXMLDocumentImpl.hxx"
26 : : #include "OOXMLBinaryObjectReference.hxx"
27 : : #include "OOXMLFastDocumentHandler.hxx"
28 : : #include "OOXMLPropertySetImpl.hxx"
29 : : #include "ooxmlLoggers.hxx"
30 : :
31 : : #include <iostream>
32 : :
33 : : using ::com::sun::star::xml::sax::SAXException;
34 : : namespace writerfilter {
35 : : namespace ooxml
36 : : {
37 : :
38 : : #if OSL_DEBUG_LEVEL > 1
39 : : TagLogger::Pointer_t debug_logger(TagLogger::getInstance("DEBUG"));
40 : : #endif
41 : :
42 : : using namespace ::std;
43 : :
44 : 227 : OOXMLDocumentImpl::OOXMLDocumentImpl
45 : : (OOXMLStream::Pointer_t pStream)
46 [ + - ]: 227 : : mpStream(pStream), mXNoteType(0), mbIsSubstream( false )
47 : : {
48 : 227 : }
49 : :
50 [ + - ]: 227 : OOXMLDocumentImpl::~OOXMLDocumentImpl()
51 : : {
52 [ - + ]: 454 : }
53 : :
54 : 1135 : void OOXMLDocumentImpl::resolveFastSubStream(Stream & rStreamHandler,
55 : : OOXMLStream::StreamType_t nType)
56 : : {
57 : : OOXMLStream::Pointer_t pStream
58 [ + - ][ + - ]: 1135 : (OOXMLDocumentFactory::createStream(mpStream, nType));
[ + - ]
59 : :
60 : : uno::Reference< xml::sax::XFastParser > xParser
61 [ + - ]: 1135 : (mpStream->getFastParser());
62 : :
63 [ + - ]: 1135 : if (xParser.is())
64 : : {
65 [ + - ]: 1135 : uno::Reference<uno::XComponentContext> xContext(mpStream->getContext());
66 : : OOXMLFastDocumentHandler * pDocHandler =
67 [ + - ]: 1135 : new OOXMLFastDocumentHandler(xContext);
68 [ + - ]: 1135 : pDocHandler->setStream(&rStreamHandler);
69 [ + - ]: 1135 : pDocHandler->setDocument(this);
70 [ + - ]: 1135 : pDocHandler->setXNoteId(mnXNoteId);
71 : :
72 : : uno::Reference < xml::sax::XFastDocumentHandler > xDocumentHandler
73 [ + - ][ + - ]: 1135 : (pDocHandler);
74 : : uno::Reference < xml::sax::XFastTokenHandler > xTokenHandler
75 [ + - ]: 1135 : (mpStream->getFastTokenHandler(xContext));
76 : :
77 [ + - ][ + - ]: 1135 : xParser->setFastDocumentHandler(xDocumentHandler);
78 [ + - ][ + - ]: 1135 : xParser->setTokenHandler(xTokenHandler);
79 : :
80 : : uno::Reference<io::XInputStream> xInputStream =
81 [ + - ]: 1135 : pStream->getDocumentStream();
82 : :
83 [ + + ]: 1135 : if (xInputStream.is())
84 : : {
85 [ + - ]: 632 : struct xml::sax::InputSource oInputSource;
86 [ + - ]: 632 : oInputSource.aInputStream = xInputStream;
87 [ + - ][ + - ]: 632 : xParser->parseStream(oInputSource);
88 : :
89 [ + - ][ + - ]: 632 : xInputStream->closeInput();
[ + - ]
90 : 1135 : }
91 [ + - ]: 1135 : }
92 : 1135 : }
93 : :
94 : 36 : void OOXMLDocumentImpl::resolveFastSubStreamWithId(Stream & rStream,
95 : : writerfilter::Reference<Stream>::Pointer_t pStream,
96 : : sal_uInt32 nId)
97 : : {
98 [ + - ]: 36 : rStream.substream(nId, pStream);
99 : 36 : }
100 : :
101 : 865 : void OOXMLDocumentImpl::setXNoteId(const sal_Int32 nId)
102 : : {
103 : 865 : mnXNoteId = nId;
104 : 865 : }
105 : :
106 : 6 : sal_Int32 OOXMLDocumentImpl::getXNoteId() const
107 : : {
108 : 6 : return mnXNoteId;
109 : : }
110 : :
111 : 6 : void OOXMLDocumentImpl::setXNoteType(const Id & nId)
112 : : {
113 : 6 : mXNoteType = nId;
114 : 6 : }
115 : :
116 : 0 : const Id & OOXMLDocumentImpl::getXNoteType() const
117 : : {
118 : 0 : return mXNoteType;
119 : : }
120 : :
121 : 57 : const OUString & OOXMLDocumentImpl::getTarget() const
122 : : {
123 : 57 : return mpStream->getTarget();
124 : : }
125 : :
126 : : writerfilter::Reference<Stream>::Pointer_t
127 : 30 : OOXMLDocumentImpl::getSubStream(const OUString & rId)
128 : : {
129 : : OOXMLStream::Pointer_t pStream
130 [ + - ][ + - ]: 30 : (OOXMLDocumentFactory::createStream(mpStream, rId));
[ + - ]
131 : :
132 : : OOXMLDocumentImpl * pTemp;
133 [ + - ][ + - ]: 30 : writerfilter::Reference<Stream>::Pointer_t pRet( pTemp = new OOXMLDocumentImpl(pStream) );
[ + - ][ + - ]
[ + - ]
134 [ + - ]: 30 : pTemp->setModel(mxModel);
135 [ + - ]: 30 : pTemp->setDrawPage(mxDrawPage);
136 : 30 : pTemp->setIsSubstream( true );
137 [ + - ]: 30 : return pRet;
138 : : }
139 : :
140 : : writerfilter::Reference<Stream>::Pointer_t
141 : 6 : OOXMLDocumentImpl::getXNoteStream(OOXMLStream::StreamType_t nType, const Id & rType,
142 : : const sal_Int32 nId)
143 : : {
144 : : #ifdef DEBUG_ELEMENT
145 : : debug_logger->startElement("getXNoteStream");
146 : : debug_logger->attribute("id", nId);
147 : : debug_logger->endElement();
148 : : #endif
149 : :
150 : : OOXMLStream::Pointer_t pStream =
151 [ + - ][ + - ]: 6 : (OOXMLDocumentFactory::createStream(mpStream, nType));
[ + - ]
152 [ + - ][ + - ]: 6 : OOXMLDocumentImpl * pDocument = new OOXMLDocumentImpl(pStream);
[ + - ][ + - ]
153 [ + - ]: 6 : pDocument->setXNoteId(nId);
154 [ + - ]: 6 : pDocument->setXNoteType(rType);
155 : :
156 [ + - ][ + - ]: 6 : return writerfilter::Reference<Stream>::Pointer_t(pDocument);
157 : : }
158 : :
159 : 0 : void OOXMLDocumentImpl::resolveFootnote(Stream & rStream,
160 : : const Id & rType,
161 : : const sal_Int32 nNoteId)
162 : : {
163 : : writerfilter::Reference<Stream>::Pointer_t pStream =
164 [ # # ]: 0 : getXNoteStream(OOXMLStream::FOOTNOTES, rType, nNoteId);
165 : :
166 : : Id nId;
167 [ # # ]: 0 : switch (rType)
168 : : {
169 : : case NS_ooxml::LN_Value_wordprocessingml_ST_FtnEdn_separator:
170 : : case NS_ooxml::LN_Value_wordprocessingml_ST_FtnEdn_continuationSeparator:
171 : 0 : nId = rType;
172 : 0 : break;
173 : : default:
174 : 0 : nId = NS_rtf::LN_footnote;
175 : 0 : break;
176 : : }
177 : :
178 [ # # ][ # # ]: 0 : resolveFastSubStreamWithId(rStream, pStream, nId);
[ # # ][ # # ]
179 : 0 : }
180 : :
181 : 0 : void OOXMLDocumentImpl::resolveEndnote(Stream & rStream,
182 : : const Id & rType,
183 : : const sal_Int32 nNoteId)
184 : : {
185 : : writerfilter::Reference<Stream>::Pointer_t pStream =
186 [ # # ]: 0 : getXNoteStream(OOXMLStream::ENDNOTES, rType, nNoteId);
187 : :
188 : : Id nId;
189 [ # # ]: 0 : switch (rType)
190 : : {
191 : : case NS_ooxml::LN_Value_wordprocessingml_ST_FtnEdn_separator:
192 : : case NS_ooxml::LN_Value_wordprocessingml_ST_FtnEdn_continuationSeparator:
193 : 0 : nId = rType;
194 : 0 : break;
195 : : default:
196 : 0 : nId = NS_rtf::LN_endnote;
197 : 0 : break;
198 : : }
199 : :
200 [ # # ][ # # ]: 0 : resolveFastSubStreamWithId(rStream, pStream, nId);
[ # # ][ # # ]
201 : 0 : }
202 : :
203 : 6 : void OOXMLDocumentImpl::resolveComment(Stream & rStream,
204 : : const sal_Int32 nId)
205 : : {
206 : : writerfilter::Reference<Stream>::Pointer_t pStream =
207 [ + - ]: 6 : getXNoteStream(OOXMLStream::COMMENTS, 0, nId);
208 : :
209 [ + - ][ + - ]: 6 : resolveFastSubStreamWithId(rStream, pStream, NS_rtf::LN_annotation);
[ + - ][ + - ]
210 : 6 : }
211 : :
212 : 0 : OOXMLPropertySet * OOXMLDocumentImpl::getPicturePropSet
213 : : (const OUString & rId)
214 : : {
215 : : OOXMLStream::Pointer_t pStream
216 [ # # ][ # # ]: 0 : (OOXMLDocumentFactory::createStream(mpStream, rId));
[ # # ]
217 : :
218 : : writerfilter::Reference<BinaryObj>::Pointer_t pPicture
219 [ # # ][ # # ]: 0 : (new OOXMLBinaryObjectReference(pStream));
[ # # ][ # # ]
[ # # ]
220 : :
221 [ # # ][ # # ]: 0 : OOXMLValue::Pointer_t pPayloadValue(new OOXMLBinaryValue(pPicture));
[ # # ][ # # ]
[ # # ]
222 : :
223 : : OOXMLProperty::Pointer_t pPayloadProperty
224 : : (new OOXMLPropertyImpl(NS_rtf::LN_payload, pPayloadValue,
225 [ # # ][ # # ]: 0 : OOXMLPropertyImpl::ATTRIBUTE));
[ # # ][ # # ]
[ # # ]
226 : :
227 [ # # ][ # # ]: 0 : OOXMLPropertySet::Pointer_t pBlipSet(new OOXMLPropertySetImpl());
[ # # ]
228 : :
229 [ # # ][ # # ]: 0 : pBlipSet->add(pPayloadProperty);
[ # # ]
230 : :
231 [ # # ][ # # ]: 0 : OOXMLValue::Pointer_t pBlipValue(new OOXMLPropertySetValue(pBlipSet));
[ # # ][ # # ]
[ # # ]
232 : :
233 : : OOXMLProperty::Pointer_t pBlipProperty
234 : : (new OOXMLPropertyImpl(NS_rtf::LN_blip, pBlipValue,
235 [ # # ][ # # ]: 0 : OOXMLPropertyImpl::ATTRIBUTE));
[ # # ][ # # ]
[ # # ]
236 : :
237 [ # # ][ # # ]: 0 : OOXMLPropertySet * pProps = new OOXMLPropertySetImpl();
238 : :
239 [ # # ][ # # ]: 0 : pProps->add(pBlipProperty);
[ # # ]
240 : :
241 [ # # ][ # # ]: 0 : return pProps;
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ]
242 : : }
243 : :
244 : 0 : void OOXMLDocumentImpl::resolvePicture(Stream & rStream,
245 : : const OUString & rId)
246 : : {
247 : 0 : OOXMLPropertySet * pProps = getPicturePropSet(rId);
248 : :
249 [ # # ]: 0 : rStream.props(writerfilter::Reference<Properties>::Pointer_t(pProps));
250 : 0 : }
251 : :
252 : 0 : OUString OOXMLDocumentImpl::getTargetForId(const OUString & rId)
253 : : {
254 : 0 : return mpStream->getTargetForId(rId);
255 : : }
256 : :
257 : 21 : void OOXMLDocumentImpl::resolveHeader(Stream & rStream,
258 : : const sal_Int32 type,
259 : : const OUString & rId)
260 : : {
261 : : writerfilter::Reference<Stream>::Pointer_t pStream =
262 [ + - ]: 21 : getSubStream(rId);
263 [ + + + - ]: 21 : switch (type)
264 : : {
265 : : case NS_ooxml::LN_Value_ST_HrdFtr_even:
266 [ + - ][ + - ]: 3 : resolveFastSubStreamWithId(rStream, pStream, NS_rtf::LN_headerl);
[ + - ]
267 : 3 : break;
268 : : case NS_ooxml::LN_Value_ST_HrdFtr_default: // here we assume that default is right, but not necessarily true :-(
269 [ + - ][ + - ]: 15 : resolveFastSubStreamWithId(rStream, pStream, NS_rtf::LN_headerr);
[ + - ]
270 : 15 : break;
271 : : case NS_ooxml::LN_Value_ST_HrdFtr_first:
272 [ + - ][ + - ]: 3 : resolveFastSubStreamWithId(rStream, pStream, NS_rtf::LN_headerf);
[ + - ]
273 : 3 : break;
274 : : default:
275 : 0 : break;
276 [ + - ]: 21 : }
277 : 21 : }
278 : :
279 : 9 : void OOXMLDocumentImpl::resolveFooter(Stream & rStream,
280 : : const sal_Int32 type,
281 : : const OUString & rId)
282 : : {
283 : : writerfilter::Reference<Stream>::Pointer_t pStream =
284 [ + - ]: 9 : getSubStream(rId);
285 : :
286 [ + + + - ]: 9 : switch (type)
287 : : {
288 : : case NS_ooxml::LN_Value_ST_HrdFtr_even:
289 [ + - ][ + - ]: 3 : resolveFastSubStreamWithId(rStream, pStream, NS_rtf::LN_footerl);
[ + - ]
290 : 3 : break;
291 : : case NS_ooxml::LN_Value_ST_HrdFtr_default: // here we assume that default is right, but not necessarily true :-(
292 [ + - ][ + - ]: 3 : resolveFastSubStreamWithId(rStream, pStream, NS_rtf::LN_footerr);
[ + - ]
293 : 3 : break;
294 : : case NS_ooxml::LN_Value_ST_HrdFtr_first:
295 [ + - ][ + - ]: 3 : resolveFastSubStreamWithId(rStream, pStream, NS_rtf::LN_footerf);
[ + - ]
296 : 3 : break;
297 : : default:
298 : 0 : break;
299 [ + - ]: 9 : }
300 : 9 : }
301 : :
302 : 227 : void OOXMLDocumentImpl::resolve(Stream & rStream)
303 : : {
304 : : #ifdef DEBUG_RESOLVE
305 : : debug_logger->startElement("OOXMLDocumentImpl.resolve");
306 : : #endif
307 : :
308 : : uno::Reference< xml::sax::XFastParser > xParser
309 [ + - ]: 227 : (mpStream->getFastParser());
310 : :
311 [ + - ]: 227 : if (xParser.is())
312 : : {
313 [ + - ]: 227 : uno::Reference<uno::XComponentContext> xContext(mpStream->getContext());
314 : :
315 : : OOXMLFastDocumentHandler * pDocHandler =
316 [ + - ]: 227 : new OOXMLFastDocumentHandler(xContext);
317 [ + - ]: 227 : pDocHandler->setStream(&rStream);
318 [ + - ]: 227 : pDocHandler->setDocument(this);
319 [ + - ]: 227 : pDocHandler->setXNoteId(mnXNoteId);
320 [ + - ]: 227 : pDocHandler->setIsSubstream( mbIsSubstream );
321 : : uno::Reference < xml::sax::XFastDocumentHandler > xDocumentHandler
322 [ + - ][ + - ]: 227 : (pDocHandler);
323 : : uno::Reference < xml::sax::XFastTokenHandler > xTokenHandler
324 [ + - ]: 227 : (mpStream->getFastTokenHandler(xContext));
325 : :
326 [ + - ]: 227 : resolveFastSubStream(rStream, OOXMLStream::SETTINGS);
327 [ + - ]: 227 : resolveFastSubStream(rStream, OOXMLStream::THEME);
328 [ + - ]: 227 : resolveFastSubStream(rStream, OOXMLStream::FONTTABLE);
329 [ + - ]: 227 : resolveFastSubStream(rStream, OOXMLStream::STYLES);
330 [ + - ]: 227 : resolveFastSubStream(rStream, OOXMLStream::NUMBERING);
331 : :
332 [ + - ][ + - ]: 227 : xParser->setFastDocumentHandler( xDocumentHandler );
333 [ + - ][ + - ]: 227 : xParser->setTokenHandler( xTokenHandler );
334 : :
335 [ + - ]: 227 : xml::sax::InputSource aParserInput;
336 [ + - ][ + - ]: 230 : aParserInput.aInputStream = mpStream->getDocumentStream();
337 : : try
338 : : {
339 [ + + ][ + - ]: 227 : xParser->parseStream(aParserInput);
340 : : }
341 [ + - ]: 3 : catch (...) {
342 : : #ifdef DEBUG_ELEMENT
343 : : debug_logger->element("exception");
344 : : #endif
345 [ + - ]: 227 : }
346 : 227 : }
347 : :
348 : : #ifdef DEBUG_RESOLVE
349 : : debug_logger->endElement();
350 : : #endif
351 : 227 : }
352 : :
353 : 0 : uno::Reference<io::XInputStream> OOXMLDocumentImpl::getInputStreamForId(const OUString & rId)
354 : : {
355 [ # # ][ # # ]: 0 : OOXMLStream::Pointer_t pStream(OOXMLDocumentFactory::createStream(mpStream, rId));
[ # # ]
356 : :
357 [ # # ][ # # ]: 0 : return pStream->getDocumentStream();
358 : : }
359 : :
360 : 0 : string OOXMLDocumentImpl::getType() const
361 : : {
362 [ # # ]: 0 : return "OOXMLDocumentImpl";
363 : : }
364 : :
365 : 221 : void OOXMLDocumentImpl::setModel(uno::Reference<frame::XModel> xModel)
366 : : {
367 : 221 : mxModel.set(xModel);
368 : 221 : }
369 : :
370 : 57 : uno::Reference<frame::XModel> OOXMLDocumentImpl::getModel()
371 : : {
372 : 57 : return mxModel;
373 : : }
374 : :
375 : 221 : void OOXMLDocumentImpl::setDrawPage(uno::Reference<drawing::XDrawPage> xDrawPage)
376 : : {
377 : 221 : mxDrawPage.set(xDrawPage);
378 : 221 : }
379 : :
380 : 57 : uno::Reference<drawing::XDrawPage> OOXMLDocumentImpl::getDrawPage()
381 : : {
382 : 57 : return mxDrawPage;
383 : : }
384 : :
385 : 0 : uno::Reference<io::XInputStream> OOXMLDocumentImpl::getInputStream()
386 : : {
387 : 0 : return mpStream->getDocumentStream();
388 : : }
389 : :
390 : 57 : uno::Reference<io::XInputStream> OOXMLDocumentImpl::getStorageStream()
391 : : {
392 : 57 : return mpStream->getStorageStream();
393 : : }
394 : :
395 : 33 : void OOXMLDocumentImpl::setShapeContext( uno::Reference<xml::sax::XFastShapeContextHandler> xContext )
396 : : {
397 : 33 : mxShapeContext = xContext;
398 : 33 : }
399 : :
400 : 57 : uno::Reference<xml::sax::XFastShapeContextHandler> OOXMLDocumentImpl::getShapeContext( )
401 : : {
402 : 57 : return mxShapeContext;
403 : : }
404 : :
405 : : OOXMLDocument *
406 : 191 : OOXMLDocumentFactory::createDocument
407 : : (OOXMLStream::Pointer_t pStream)
408 : : {
409 [ + - ][ + - ]: 191 : return new OOXMLDocumentImpl(pStream);
410 : : }
411 : :
412 [ + - ][ + - ]: 60 : }}
413 : :
414 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|