Bug Summary

File:home/maarten/src/libreoffice/core/include/tools/ref.hxx
Warning:line 56, column 30
Use of memory after it is freed

Annotated Source Code

Press '?' to see keyboard shortcuts

clang -cc1 -cc1 -triple x86_64-unknown-linux-gnu -analyze -disable-free -disable-llvm-verifier -discard-value-names -main-file-name OOXMLDocumentImpl.cxx -analyzer-store=region -analyzer-opt-analyze-nested-blocks -analyzer-checker=core -analyzer-checker=apiModeling -analyzer-checker=unix -analyzer-checker=deadcode -analyzer-checker=cplusplus -analyzer-checker=security.insecureAPI.UncheckedReturn -analyzer-checker=security.insecureAPI.getpw -analyzer-checker=security.insecureAPI.gets -analyzer-checker=security.insecureAPI.mktemp -analyzer-checker=security.insecureAPI.mkstemp -analyzer-checker=security.insecureAPI.vfork -analyzer-checker=nullability.NullPassedToNonnull -analyzer-checker=nullability.NullReturnedFromNonnull -analyzer-output plist -w -setup-static-analyzer -mrelocation-model pic -pic-level 2 -mframe-pointer=all -fmath-errno -fno-rounding-math -mconstructor-aliases -munwind-tables -target-cpu x86-64 -fno-split-dwarf-inlining -debugger-tuning=gdb -resource-dir /usr/lib64/clang/11.0.0 -isystem /usr/include/libxml2 -D BOOST_ERROR_CODE_HEADER_ONLY -D BOOST_SYSTEM_NO_DEPRECATED -D CPPU_ENV=gcc3 -D LINUX -D OSL_DEBUG_LEVEL=1 -D SAL_LOG_INFO -D SAL_LOG_WARN -D UNIX -D UNX -D X86_64 -D _PTHREADS -D _REENTRANT -D SYSTEM_LIBXML -D EXCEPTIONS_ON -D LIBO_INTERNAL_ONLY -I /home/maarten/src/libreoffice/core/workdir/UnpackedTarball/icu/source -I /home/maarten/src/libreoffice/core/workdir/UnpackedTarball/icu/source/i18n -I /home/maarten/src/libreoffice/core/workdir/UnpackedTarball/icu/source/common -I /home/maarten/src/libreoffice/core/external/boost/include -I /home/maarten/src/libreoffice/core/workdir/UnpackedTarball/boost -I /home/maarten/src/libreoffice/core/include -I /usr/lib/jvm/java-11-openjdk-11.0.9.10-0.0.ea.fc33.x86_64/include -I /usr/lib/jvm/java-11-openjdk-11.0.9.10-0.0.ea.fc33.x86_64/include/linux -I /home/maarten/src/libreoffice/core/config_host -I /home/maarten/src/libreoffice/core/workdir/CustomTarget/officecfg/registry -I /home/maarten/src/libreoffice/core/workdir/CustomTarget/oox/generated -I /home/maarten/src/libreoffice/core/workdir/CustomTarget/writerfilter/source -I /home/maarten/src/libreoffice/core/writerfilter/inc -I /home/maarten/src/libreoffice/core/writerfilter/source -I /home/maarten/src/libreoffice/core/workdir/UnoApiHeadersTarget/udkapi/normal -I /home/maarten/src/libreoffice/core/workdir/UnoApiHeadersTarget/offapi/normal -internal-isystem /usr/bin/../lib/gcc/x86_64-redhat-linux/10/../../../../include/c++/10 -internal-isystem /usr/bin/../lib/gcc/x86_64-redhat-linux/10/../../../../include/c++/10/x86_64-redhat-linux -internal-isystem /usr/bin/../lib/gcc/x86_64-redhat-linux/10/../../../../include/c++/10/backward -internal-isystem /usr/local/include -internal-isystem /usr/lib64/clang/11.0.0/include -internal-externc-isystem /include -internal-externc-isystem /usr/include -O0 -Wno-missing-braces -std=c++17 -fdeprecated-macro -fdebug-compilation-dir /home/maarten/src/libreoffice/core -ferror-limit 19 -fvisibility hidden -fvisibility-inlines-hidden -stack-protector 2 -fgnuc-version=4.2.1 -fcxx-exceptions -fexceptions -debug-info-kind=constructor -analyzer-output=html -faddrsig -o /home/maarten/tmp/wis/scan-build-libreoffice/output/report/2020-10-07-141433-9725-1 -x c++ /home/maarten/src/libreoffice/core/writerfilter/source/ooxml/OOXMLDocumentImpl.cxx

/home/maarten/src/libreoffice/core/writerfilter/source/ooxml/OOXMLDocumentImpl.cxx

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 <comphelper/sequenceashashmap.hxx>
21
22#include <com/sun/star/lang/WrappedTargetRuntimeException.hpp>
23#include <com/sun/star/document/XDocumentPropertiesSupplier.hpp>
24#include <com/sun/star/xml/sax/SAXException.hpp>
25#include <com/sun/star/xml/dom/DocumentBuilder.hpp>
26#include <com/sun/star/graphic/GraphicMapper.hpp>
27#include <ooxml/resourceids.hxx>
28#include "OOXMLStreamImpl.hxx"
29#include "OOXMLDocumentImpl.hxx"
30#include "OOXMLBinaryObjectReference.hxx"
31#include "OOXMLFastDocumentHandler.hxx"
32#include "OOXMLPropertySet.hxx"
33
34#include <sal/log.hxx>
35#include <tools/diagnose_ex.h>
36#include <svx/dialmgr.hxx>
37#include <svx/strings.hrc>
38#include <comphelper/sequence.hxx>
39#include <cppuhelper/exc_hlp.hxx>
40#include <unotools/mediadescriptor.hxx>
41
42#include <iostream>
43#include <sfx2/objsh.hxx>
44
45// this extern variable is declared in OOXMLStreamImpl.hxx
46OUString customTarget;
47OUString embeddingsTarget;
48using namespace ::com::sun::star;
49namespace writerfilter::ooxml
50{
51
52OOXMLDocumentImpl::OOXMLDocumentImpl(OOXMLStream::Pointer_t const & pStream, const uno::Reference<task::XStatusIndicator>& xStatusIndicator, bool bSkipImages, const uno::Sequence<beans::PropertyValue>& rDescriptor)
53 : mpStream(pStream)
54 , mxStatusIndicator(xStatusIndicator)
55 , mnXNoteId(0)
56 , mbIsSubstream(false)
57 , mbSkipImages(bSkipImages)
58 , mnPercentSize(0)
59 , mnProgressLastPos(0)
60 , mnProgressCurrentPos(0)
61 , mnProgressEndPos(0)
62 , m_rBaseURL(utl::MediaDescriptor(rDescriptor).getUnpackedValueOrDefault("DocumentBaseURL", OUString()))
63 , maMediaDescriptor(rDescriptor)
64 , mxGraphicMapper(graphic::GraphicMapper::create(mpStream->getContext()))
65{
66 pushShapeContext();
67}
68
69OOXMLDocumentImpl::~OOXMLDocumentImpl()
70{
71}
72
73void OOXMLDocumentImpl::resolveFastSubStream(Stream & rStreamHandler,
74 OOXMLStream::StreamType_t nType)
75{
76 OOXMLStream::Pointer_t pStream;
77 try
78 {
79 pStream = OOXMLDocumentFactory::createStream(mpStream, nType);
80 }
81 catch (uno::Exception const&)
82 {
83 TOOLS_INFO_EXCEPTION("writerfilter.ooxml", "resolveFastSubStream: exception while "do { css::uno::Any tools_warn_exception( DbgGetCaughtException
() ); do { if (true) { switch (sal_detail_log_report(::SAL_DETAIL_LOG_LEVEL_INFO
, "writerfilter.ooxml")) { case SAL_DETAIL_LOG_ACTION_IGNORE:
break; case SAL_DETAIL_LOG_ACTION_LOG: if (sizeof ::sal::detail
::getResult( ::sal::detail::StreamStart() << "resolveFastSubStream: exception while "
"resolving stream " << nType << " " << exceptionToString
(tools_warn_exception)) == 1) { ::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_INFO
), ("writerfilter.ooxml"), ("/home/maarten/src/libreoffice/core/writerfilter/source/ooxml/OOXMLDocumentImpl.cxx"
":" "84" ": "), ::sal::detail::unwrapStream( ::sal::detail::
StreamStart() << "resolveFastSubStream: exception while "
"resolving stream " << nType << " " << exceptionToString
(tools_warn_exception)), 0); } else { ::std::ostringstream sal_detail_stream
; sal_detail_stream << "resolveFastSubStream: exception while "
"resolving stream " << nType << " " << exceptionToString
(tools_warn_exception); ::sal::detail::log( (::SAL_DETAIL_LOG_LEVEL_INFO
), ("writerfilter.ooxml"), ("/home/maarten/src/libreoffice/core/writerfilter/source/ooxml/OOXMLDocumentImpl.cxx"
":" "84" ": "), sal_detail_stream, 0); }; break; case SAL_DETAIL_LOG_ACTION_FATAL
: if (sizeof ::sal::detail::getResult( ::sal::detail::StreamStart
() << "resolveFastSubStream: exception while " "resolving stream "
<< nType << " " << exceptionToString(tools_warn_exception
)) == 1) { ::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_INFO), (
"writerfilter.ooxml"), ("/home/maarten/src/libreoffice/core/writerfilter/source/ooxml/OOXMLDocumentImpl.cxx"
":" "84" ": "), ::sal::detail::unwrapStream( ::sal::detail::
StreamStart() << "resolveFastSubStream: exception while "
"resolving stream " << nType << " " << exceptionToString
(tools_warn_exception)), 0); } else { ::std::ostringstream sal_detail_stream
; sal_detail_stream << "resolveFastSubStream: exception while "
"resolving stream " << nType << " " << exceptionToString
(tools_warn_exception); ::sal::detail::log( (::SAL_DETAIL_LOG_LEVEL_INFO
), ("writerfilter.ooxml"), ("/home/maarten/src/libreoffice/core/writerfilter/source/ooxml/OOXMLDocumentImpl.cxx"
":" "84" ": "), sal_detail_stream, 0); }; std::abort(); break
; } } } while (false); } while (false)
84 "resolving stream " << nType)do { css::uno::Any tools_warn_exception( DbgGetCaughtException
() ); do { if (true) { switch (sal_detail_log_report(::SAL_DETAIL_LOG_LEVEL_INFO
, "writerfilter.ooxml")) { case SAL_DETAIL_LOG_ACTION_IGNORE:
break; case SAL_DETAIL_LOG_ACTION_LOG: if (sizeof ::sal::detail
::getResult( ::sal::detail::StreamStart() << "resolveFastSubStream: exception while "
"resolving stream " << nType << " " << exceptionToString
(tools_warn_exception)) == 1) { ::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_INFO
), ("writerfilter.ooxml"), ("/home/maarten/src/libreoffice/core/writerfilter/source/ooxml/OOXMLDocumentImpl.cxx"
":" "84" ": "), ::sal::detail::unwrapStream( ::sal::detail::
StreamStart() << "resolveFastSubStream: exception while "
"resolving stream " << nType << " " << exceptionToString
(tools_warn_exception)), 0); } else { ::std::ostringstream sal_detail_stream
; sal_detail_stream << "resolveFastSubStream: exception while "
"resolving stream " << nType << " " << exceptionToString
(tools_warn_exception); ::sal::detail::log( (::SAL_DETAIL_LOG_LEVEL_INFO
), ("writerfilter.ooxml"), ("/home/maarten/src/libreoffice/core/writerfilter/source/ooxml/OOXMLDocumentImpl.cxx"
":" "84" ": "), sal_detail_stream, 0); }; break; case SAL_DETAIL_LOG_ACTION_FATAL
: if (sizeof ::sal::detail::getResult( ::sal::detail::StreamStart
() << "resolveFastSubStream: exception while " "resolving stream "
<< nType << " " << exceptionToString(tools_warn_exception
)) == 1) { ::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_INFO), (
"writerfilter.ooxml"), ("/home/maarten/src/libreoffice/core/writerfilter/source/ooxml/OOXMLDocumentImpl.cxx"
":" "84" ": "), ::sal::detail::unwrapStream( ::sal::detail::
StreamStart() << "resolveFastSubStream: exception while "
"resolving stream " << nType << " " << exceptionToString
(tools_warn_exception)), 0); } else { ::std::ostringstream sal_detail_stream
; sal_detail_stream << "resolveFastSubStream: exception while "
"resolving stream " << nType << " " << exceptionToString
(tools_warn_exception); ::sal::detail::log( (::SAL_DETAIL_LOG_LEVEL_INFO
), ("writerfilter.ooxml"), ("/home/maarten/src/libreoffice/core/writerfilter/source/ooxml/OOXMLDocumentImpl.cxx"
":" "84" ": "), sal_detail_stream, 0); }; std::abort(); break
; } } } while (false); } while (false)
;
85 return;
86 }
87 OOXMLStream::Pointer_t savedStream = mpStream;
88 mpStream = pStream;
89
90 uno::Reference<xml::sax::XFastParser> xParser(mpStream->getFastParser());
91
92 if (xParser.is())
4
Taking false branch
93 {
94 uno::Reference<uno::XComponentContext> xContext(mpStream->getContext());
95 OOXMLFastDocumentHandler * pDocHandler =
96 new OOXMLFastDocumentHandler(xContext, &rStreamHandler, this, mnXNoteId);
97
98 uno::Reference<xml::sax::XFastDocumentHandler> xDocumentHandler(pDocHandler);
99 uno::Reference<xml::sax::XFastTokenHandler> xTokenHandler(mpStream->getFastTokenHandler());
100
101 xParser->setFastDocumentHandler(xDocumentHandler);
102 xParser->setTokenHandler(xTokenHandler);
103
104 uno::Reference<io::XInputStream> xInputStream = pStream->getDocumentStream();
105
106 if (xInputStream.is())
107 {
108 struct xml::sax::InputSource oInputSource;
109 oInputSource.aInputStream = xInputStream;
110 xParser->parseStream(oInputSource);
111
112 xInputStream->closeInput();
113 }
114 }
115
116 mpStream = savedStream;
5
Calling copy assignment operator for 'SvRef<writerfilter::ooxml::OOXMLStream>'
16
Returning; memory was released
117}
17
Calling '~SvRef'
118
119void OOXMLDocumentImpl::resolveFastSubStreamWithId(Stream & rStream,
120 const writerfilter::Reference<Stream>::Pointer_t& pStream,
121 sal_uInt32 nId)
122{
123 rStream.substream(nId, pStream);
124}
125
126uno::Reference<xml::dom::XDocument> OOXMLDocumentImpl::importSubStream(OOXMLStream::StreamType_t nType)
127{
128 uno::Reference<xml::dom::XDocument> xRet;
129
130 OOXMLStream::Pointer_t pStream;
131 try
132 {
133 pStream = OOXMLDocumentFactory::createStream(mpStream, nType);
134 }
135 catch (uno::Exception const&)
136 {
137 TOOLS_INFO_EXCEPTION("writerfilter.ooxml", "importSubStream: exception while "do { css::uno::Any tools_warn_exception( DbgGetCaughtException
() ); do { if (true) { switch (sal_detail_log_report(::SAL_DETAIL_LOG_LEVEL_INFO
, "writerfilter.ooxml")) { case SAL_DETAIL_LOG_ACTION_IGNORE:
break; case SAL_DETAIL_LOG_ACTION_LOG: if (sizeof ::sal::detail
::getResult( ::sal::detail::StreamStart() << "importSubStream: exception while "
"importing stream " << nType << " " << exceptionToString
(tools_warn_exception)) == 1) { ::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_INFO
), ("writerfilter.ooxml"), ("/home/maarten/src/libreoffice/core/writerfilter/source/ooxml/OOXMLDocumentImpl.cxx"
":" "138" ": "), ::sal::detail::unwrapStream( ::sal::detail::
StreamStart() << "importSubStream: exception while " "importing stream "
<< nType << " " << exceptionToString(tools_warn_exception
)), 0); } else { ::std::ostringstream sal_detail_stream; sal_detail_stream
<< "importSubStream: exception while " "importing stream "
<< nType << " " << exceptionToString(tools_warn_exception
); ::sal::detail::log( (::SAL_DETAIL_LOG_LEVEL_INFO), ("writerfilter.ooxml"
), ("/home/maarten/src/libreoffice/core/writerfilter/source/ooxml/OOXMLDocumentImpl.cxx"
":" "138" ": "), sal_detail_stream, 0); }; break; case SAL_DETAIL_LOG_ACTION_FATAL
: if (sizeof ::sal::detail::getResult( ::sal::detail::StreamStart
() << "importSubStream: exception while " "importing stream "
<< nType << " " << exceptionToString(tools_warn_exception
)) == 1) { ::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_INFO), (
"writerfilter.ooxml"), ("/home/maarten/src/libreoffice/core/writerfilter/source/ooxml/OOXMLDocumentImpl.cxx"
":" "138" ": "), ::sal::detail::unwrapStream( ::sal::detail::
StreamStart() << "importSubStream: exception while " "importing stream "
<< nType << " " << exceptionToString(tools_warn_exception
)), 0); } else { ::std::ostringstream sal_detail_stream; sal_detail_stream
<< "importSubStream: exception while " "importing stream "
<< nType << " " << exceptionToString(tools_warn_exception
); ::sal::detail::log( (::SAL_DETAIL_LOG_LEVEL_INFO), ("writerfilter.ooxml"
), ("/home/maarten/src/libreoffice/core/writerfilter/source/ooxml/OOXMLDocumentImpl.cxx"
":" "138" ": "), sal_detail_stream, 0); }; std::abort(); break
; } } } while (false); } while (false)
138 "importing stream " << nType)do { css::uno::Any tools_warn_exception( DbgGetCaughtException
() ); do { if (true) { switch (sal_detail_log_report(::SAL_DETAIL_LOG_LEVEL_INFO
, "writerfilter.ooxml")) { case SAL_DETAIL_LOG_ACTION_IGNORE:
break; case SAL_DETAIL_LOG_ACTION_LOG: if (sizeof ::sal::detail
::getResult( ::sal::detail::StreamStart() << "importSubStream: exception while "
"importing stream " << nType << " " << exceptionToString
(tools_warn_exception)) == 1) { ::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_INFO
), ("writerfilter.ooxml"), ("/home/maarten/src/libreoffice/core/writerfilter/source/ooxml/OOXMLDocumentImpl.cxx"
":" "138" ": "), ::sal::detail::unwrapStream( ::sal::detail::
StreamStart() << "importSubStream: exception while " "importing stream "
<< nType << " " << exceptionToString(tools_warn_exception
)), 0); } else { ::std::ostringstream sal_detail_stream; sal_detail_stream
<< "importSubStream: exception while " "importing stream "
<< nType << " " << exceptionToString(tools_warn_exception
); ::sal::detail::log( (::SAL_DETAIL_LOG_LEVEL_INFO), ("writerfilter.ooxml"
), ("/home/maarten/src/libreoffice/core/writerfilter/source/ooxml/OOXMLDocumentImpl.cxx"
":" "138" ": "), sal_detail_stream, 0); }; break; case SAL_DETAIL_LOG_ACTION_FATAL
: if (sizeof ::sal::detail::getResult( ::sal::detail::StreamStart
() << "importSubStream: exception while " "importing stream "
<< nType << " " << exceptionToString(tools_warn_exception
)) == 1) { ::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_INFO), (
"writerfilter.ooxml"), ("/home/maarten/src/libreoffice/core/writerfilter/source/ooxml/OOXMLDocumentImpl.cxx"
":" "138" ": "), ::sal::detail::unwrapStream( ::sal::detail::
StreamStart() << "importSubStream: exception while " "importing stream "
<< nType << " " << exceptionToString(tools_warn_exception
)), 0); } else { ::std::ostringstream sal_detail_stream; sal_detail_stream
<< "importSubStream: exception while " "importing stream "
<< nType << " " << exceptionToString(tools_warn_exception
); ::sal::detail::log( (::SAL_DETAIL_LOG_LEVEL_INFO), ("writerfilter.ooxml"
), ("/home/maarten/src/libreoffice/core/writerfilter/source/ooxml/OOXMLDocumentImpl.cxx"
":" "138" ": "), sal_detail_stream, 0); }; std::abort(); break
; } } } while (false); } while (false)
;
139 return xRet;
140 }
141
142 uno::Reference<io::XInputStream> xInputStream = pStream->getDocumentStream();
143 if (xInputStream.is())
144 {
145 try
146 {
147 uno::Reference<uno::XComponentContext> xContext(mpStream->getContext());
148 uno::Reference<xml::dom::XDocumentBuilder> xDomBuilder(xml::dom::DocumentBuilder::create(xContext));
149 xRet = xDomBuilder->parse(xInputStream);
150 }
151 catch (uno::Exception const&)
152 {
153 TOOLS_INFO_EXCEPTION("writerfilter.ooxml", "importSubStream: exception while "do { css::uno::Any tools_warn_exception( DbgGetCaughtException
() ); do { if (true) { switch (sal_detail_log_report(::SAL_DETAIL_LOG_LEVEL_INFO
, "writerfilter.ooxml")) { case SAL_DETAIL_LOG_ACTION_IGNORE:
break; case SAL_DETAIL_LOG_ACTION_LOG: if (sizeof ::sal::detail
::getResult( ::sal::detail::StreamStart() << "importSubStream: exception while "
"parsing stream " << nType << " " << exceptionToString
(tools_warn_exception)) == 1) { ::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_INFO
), ("writerfilter.ooxml"), ("/home/maarten/src/libreoffice/core/writerfilter/source/ooxml/OOXMLDocumentImpl.cxx"
":" "154" ": "), ::sal::detail::unwrapStream( ::sal::detail::
StreamStart() << "importSubStream: exception while " "parsing stream "
<< nType << " " << exceptionToString(tools_warn_exception
)), 0); } else { ::std::ostringstream sal_detail_stream; sal_detail_stream
<< "importSubStream: exception while " "parsing stream "
<< nType << " " << exceptionToString(tools_warn_exception
); ::sal::detail::log( (::SAL_DETAIL_LOG_LEVEL_INFO), ("writerfilter.ooxml"
), ("/home/maarten/src/libreoffice/core/writerfilter/source/ooxml/OOXMLDocumentImpl.cxx"
":" "154" ": "), sal_detail_stream, 0); }; break; case SAL_DETAIL_LOG_ACTION_FATAL
: if (sizeof ::sal::detail::getResult( ::sal::detail::StreamStart
() << "importSubStream: exception while " "parsing stream "
<< nType << " " << exceptionToString(tools_warn_exception
)) == 1) { ::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_INFO), (
"writerfilter.ooxml"), ("/home/maarten/src/libreoffice/core/writerfilter/source/ooxml/OOXMLDocumentImpl.cxx"
":" "154" ": "), ::sal::detail::unwrapStream( ::sal::detail::
StreamStart() << "importSubStream: exception while " "parsing stream "
<< nType << " " << exceptionToString(tools_warn_exception
)), 0); } else { ::std::ostringstream sal_detail_stream; sal_detail_stream
<< "importSubStream: exception while " "parsing stream "
<< nType << " " << exceptionToString(tools_warn_exception
); ::sal::detail::log( (::SAL_DETAIL_LOG_LEVEL_INFO), ("writerfilter.ooxml"
), ("/home/maarten/src/libreoffice/core/writerfilter/source/ooxml/OOXMLDocumentImpl.cxx"
":" "154" ": "), sal_detail_stream, 0); }; std::abort(); break
; } } } while (false); } while (false)
154 "parsing stream " << nType)do { css::uno::Any tools_warn_exception( DbgGetCaughtException
() ); do { if (true) { switch (sal_detail_log_report(::SAL_DETAIL_LOG_LEVEL_INFO
, "writerfilter.ooxml")) { case SAL_DETAIL_LOG_ACTION_IGNORE:
break; case SAL_DETAIL_LOG_ACTION_LOG: if (sizeof ::sal::detail
::getResult( ::sal::detail::StreamStart() << "importSubStream: exception while "
"parsing stream " << nType << " " << exceptionToString
(tools_warn_exception)) == 1) { ::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_INFO
), ("writerfilter.ooxml"), ("/home/maarten/src/libreoffice/core/writerfilter/source/ooxml/OOXMLDocumentImpl.cxx"
":" "154" ": "), ::sal::detail::unwrapStream( ::sal::detail::
StreamStart() << "importSubStream: exception while " "parsing stream "
<< nType << " " << exceptionToString(tools_warn_exception
)), 0); } else { ::std::ostringstream sal_detail_stream; sal_detail_stream
<< "importSubStream: exception while " "parsing stream "
<< nType << " " << exceptionToString(tools_warn_exception
); ::sal::detail::log( (::SAL_DETAIL_LOG_LEVEL_INFO), ("writerfilter.ooxml"
), ("/home/maarten/src/libreoffice/core/writerfilter/source/ooxml/OOXMLDocumentImpl.cxx"
":" "154" ": "), sal_detail_stream, 0); }; break; case SAL_DETAIL_LOG_ACTION_FATAL
: if (sizeof ::sal::detail::getResult( ::sal::detail::StreamStart
() << "importSubStream: exception while " "parsing stream "
<< nType << " " << exceptionToString(tools_warn_exception
)) == 1) { ::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_INFO), (
"writerfilter.ooxml"), ("/home/maarten/src/libreoffice/core/writerfilter/source/ooxml/OOXMLDocumentImpl.cxx"
":" "154" ": "), ::sal::detail::unwrapStream( ::sal::detail::
StreamStart() << "importSubStream: exception while " "parsing stream "
<< nType << " " << exceptionToString(tools_warn_exception
)), 0); } else { ::std::ostringstream sal_detail_stream; sal_detail_stream
<< "importSubStream: exception while " "parsing stream "
<< nType << " " << exceptionToString(tools_warn_exception
); ::sal::detail::log( (::SAL_DETAIL_LOG_LEVEL_INFO), ("writerfilter.ooxml"
), ("/home/maarten/src/libreoffice/core/writerfilter/source/ooxml/OOXMLDocumentImpl.cxx"
":" "154" ": "), sal_detail_stream, 0); }; std::abort(); break
; } } } while (false); } while (false)
;
155 return xRet;
156 }
157 }
158
159 if (OOXMLStream::CUSTOMXML == nType)
160 {
161 importSubStreamRelations(pStream, OOXMLStream::CUSTOMXMLPROPS);
162 }
163 else if (OOXMLStream::CHARTS == nType)
164 {
165 importSubStreamRelations(pStream, OOXMLStream::EMBEDDINGS);
166 }
167
168 return xRet;
169}
170
171
172void OOXMLDocumentImpl::importSubStreamRelations(const OOXMLStream::Pointer_t& pStream, OOXMLStream::StreamType_t nType)
173{
174 uno::Reference<xml::dom::XDocument> xRelation;
175 OOXMLStream::Pointer_t cStream;
176 try
177 {
178 cStream = OOXMLDocumentFactory::createStream(pStream, nType);
179 }
180 catch (uno::Exception const&)
181 {
182 TOOLS_WARN_EXCEPTION("writerfilter.ooxml", "importSubStreamRelations: exception while "do { css::uno::Any tools_warn_exception( DbgGetCaughtException
() ); do { if (true) { switch (sal_detail_log_report(::SAL_DETAIL_LOG_LEVEL_WARN
, "writerfilter.ooxml")) { case SAL_DETAIL_LOG_ACTION_IGNORE:
break; case SAL_DETAIL_LOG_ACTION_LOG: if (sizeof ::sal::detail
::getResult( ::sal::detail::StreamStart() << "importSubStreamRelations: exception while "
"importing stream " << nType << " " << exceptionToString
(tools_warn_exception)) == 1) { ::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_WARN
), ("writerfilter.ooxml"), ("/home/maarten/src/libreoffice/core/writerfilter/source/ooxml/OOXMLDocumentImpl.cxx"
":" "183" ": "), ::sal::detail::unwrapStream( ::sal::detail::
StreamStart() << "importSubStreamRelations: exception while "
"importing stream " << nType << " " << exceptionToString
(tools_warn_exception)), 0); } else { ::std::ostringstream sal_detail_stream
; sal_detail_stream << "importSubStreamRelations: exception while "
"importing stream " << nType << " " << exceptionToString
(tools_warn_exception); ::sal::detail::log( (::SAL_DETAIL_LOG_LEVEL_WARN
), ("writerfilter.ooxml"), ("/home/maarten/src/libreoffice/core/writerfilter/source/ooxml/OOXMLDocumentImpl.cxx"
":" "183" ": "), sal_detail_stream, 0); }; break; case SAL_DETAIL_LOG_ACTION_FATAL
: if (sizeof ::sal::detail::getResult( ::sal::detail::StreamStart
() << "importSubStreamRelations: exception while " "importing stream "
<< nType << " " << exceptionToString(tools_warn_exception
)) == 1) { ::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_WARN), (
"writerfilter.ooxml"), ("/home/maarten/src/libreoffice/core/writerfilter/source/ooxml/OOXMLDocumentImpl.cxx"
":" "183" ": "), ::sal::detail::unwrapStream( ::sal::detail::
StreamStart() << "importSubStreamRelations: exception while "
"importing stream " << nType << " " << exceptionToString
(tools_warn_exception)), 0); } else { ::std::ostringstream sal_detail_stream
; sal_detail_stream << "importSubStreamRelations: exception while "
"importing stream " << nType << " " << exceptionToString
(tools_warn_exception); ::sal::detail::log( (::SAL_DETAIL_LOG_LEVEL_WARN
), ("writerfilter.ooxml"), ("/home/maarten/src/libreoffice/core/writerfilter/source/ooxml/OOXMLDocumentImpl.cxx"
":" "183" ": "), sal_detail_stream, 0); }; std::abort(); break
; } } } while (false); } while (false)
183 "importing stream " << nType)do { css::uno::Any tools_warn_exception( DbgGetCaughtException
() ); do { if (true) { switch (sal_detail_log_report(::SAL_DETAIL_LOG_LEVEL_WARN
, "writerfilter.ooxml")) { case SAL_DETAIL_LOG_ACTION_IGNORE:
break; case SAL_DETAIL_LOG_ACTION_LOG: if (sizeof ::sal::detail
::getResult( ::sal::detail::StreamStart() << "importSubStreamRelations: exception while "
"importing stream " << nType << " " << exceptionToString
(tools_warn_exception)) == 1) { ::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_WARN
), ("writerfilter.ooxml"), ("/home/maarten/src/libreoffice/core/writerfilter/source/ooxml/OOXMLDocumentImpl.cxx"
":" "183" ": "), ::sal::detail::unwrapStream( ::sal::detail::
StreamStart() << "importSubStreamRelations: exception while "
"importing stream " << nType << " " << exceptionToString
(tools_warn_exception)), 0); } else { ::std::ostringstream sal_detail_stream
; sal_detail_stream << "importSubStreamRelations: exception while "
"importing stream " << nType << " " << exceptionToString
(tools_warn_exception); ::sal::detail::log( (::SAL_DETAIL_LOG_LEVEL_WARN
), ("writerfilter.ooxml"), ("/home/maarten/src/libreoffice/core/writerfilter/source/ooxml/OOXMLDocumentImpl.cxx"
":" "183" ": "), sal_detail_stream, 0); }; break; case SAL_DETAIL_LOG_ACTION_FATAL
: if (sizeof ::sal::detail::getResult( ::sal::detail::StreamStart
() << "importSubStreamRelations: exception while " "importing stream "
<< nType << " " << exceptionToString(tools_warn_exception
)) == 1) { ::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_WARN), (
"writerfilter.ooxml"), ("/home/maarten/src/libreoffice/core/writerfilter/source/ooxml/OOXMLDocumentImpl.cxx"
":" "183" ": "), ::sal::detail::unwrapStream( ::sal::detail::
StreamStart() << "importSubStreamRelations: exception while "
"importing stream " << nType << " " << exceptionToString
(tools_warn_exception)), 0); } else { ::std::ostringstream sal_detail_stream
; sal_detail_stream << "importSubStreamRelations: exception while "
"importing stream " << nType << " " << exceptionToString
(tools_warn_exception); ::sal::detail::log( (::SAL_DETAIL_LOG_LEVEL_WARN
), ("writerfilter.ooxml"), ("/home/maarten/src/libreoffice/core/writerfilter/source/ooxml/OOXMLDocumentImpl.cxx"
":" "183" ": "), sal_detail_stream, 0); }; std::abort(); break
; } } } while (false); } while (false)
;
184 return;
185 }
186
187 uno::Reference<io::XInputStream> xcpInputStream = cStream->getDocumentStream();
188
189 if (!xcpInputStream.is())
190 return;
191
192 // importing itemprops files for item.xml from customXml.
193 if (OOXMLStream::CUSTOMXMLPROPS == nType)
194 {
195 try
196 {
197 uno::Reference<uno::XComponentContext> xcpContext(pStream->getContext());
198 uno::Reference<xml::dom::XDocumentBuilder> xDomBuilder(xml::dom::DocumentBuilder::create(xcpContext));
199 xRelation = xDomBuilder->parse(xcpInputStream);
200 }
201 catch (uno::Exception const&)
202 {
203 TOOLS_WARN_EXCEPTION("writerfilter.ooxml", "importSubStream: exception while "do { css::uno::Any tools_warn_exception( DbgGetCaughtException
() ); do { if (true) { switch (sal_detail_log_report(::SAL_DETAIL_LOG_LEVEL_WARN
, "writerfilter.ooxml")) { case SAL_DETAIL_LOG_ACTION_IGNORE:
break; case SAL_DETAIL_LOG_ACTION_LOG: if (sizeof ::sal::detail
::getResult( ::sal::detail::StreamStart() << "importSubStream: exception while "
"parsing stream " << nType << " " << exceptionToString
(tools_warn_exception)) == 1) { ::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_WARN
), ("writerfilter.ooxml"), ("/home/maarten/src/libreoffice/core/writerfilter/source/ooxml/OOXMLDocumentImpl.cxx"
":" "204" ": "), ::sal::detail::unwrapStream( ::sal::detail::
StreamStart() << "importSubStream: exception while " "parsing stream "
<< nType << " " << exceptionToString(tools_warn_exception
)), 0); } else { ::std::ostringstream sal_detail_stream; sal_detail_stream
<< "importSubStream: exception while " "parsing stream "
<< nType << " " << exceptionToString(tools_warn_exception
); ::sal::detail::log( (::SAL_DETAIL_LOG_LEVEL_WARN), ("writerfilter.ooxml"
), ("/home/maarten/src/libreoffice/core/writerfilter/source/ooxml/OOXMLDocumentImpl.cxx"
":" "204" ": "), sal_detail_stream, 0); }; break; case SAL_DETAIL_LOG_ACTION_FATAL
: if (sizeof ::sal::detail::getResult( ::sal::detail::StreamStart
() << "importSubStream: exception while " "parsing stream "
<< nType << " " << exceptionToString(tools_warn_exception
)) == 1) { ::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_WARN), (
"writerfilter.ooxml"), ("/home/maarten/src/libreoffice/core/writerfilter/source/ooxml/OOXMLDocumentImpl.cxx"
":" "204" ": "), ::sal::detail::unwrapStream( ::sal::detail::
StreamStart() << "importSubStream: exception while " "parsing stream "
<< nType << " " << exceptionToString(tools_warn_exception
)), 0); } else { ::std::ostringstream sal_detail_stream; sal_detail_stream
<< "importSubStream: exception while " "parsing stream "
<< nType << " " << exceptionToString(tools_warn_exception
); ::sal::detail::log( (::SAL_DETAIL_LOG_LEVEL_WARN), ("writerfilter.ooxml"
), ("/home/maarten/src/libreoffice/core/writerfilter/source/ooxml/OOXMLDocumentImpl.cxx"
":" "204" ": "), sal_detail_stream, 0); }; std::abort(); break
; } } } while (false); } while (false)
204 "parsing stream " << nType)do { css::uno::Any tools_warn_exception( DbgGetCaughtException
() ); do { if (true) { switch (sal_detail_log_report(::SAL_DETAIL_LOG_LEVEL_WARN
, "writerfilter.ooxml")) { case SAL_DETAIL_LOG_ACTION_IGNORE:
break; case SAL_DETAIL_LOG_ACTION_LOG: if (sizeof ::sal::detail
::getResult( ::sal::detail::StreamStart() << "importSubStream: exception while "
"parsing stream " << nType << " " << exceptionToString
(tools_warn_exception)) == 1) { ::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_WARN
), ("writerfilter.ooxml"), ("/home/maarten/src/libreoffice/core/writerfilter/source/ooxml/OOXMLDocumentImpl.cxx"
":" "204" ": "), ::sal::detail::unwrapStream( ::sal::detail::
StreamStart() << "importSubStream: exception while " "parsing stream "
<< nType << " " << exceptionToString(tools_warn_exception
)), 0); } else { ::std::ostringstream sal_detail_stream; sal_detail_stream
<< "importSubStream: exception while " "parsing stream "
<< nType << " " << exceptionToString(tools_warn_exception
); ::sal::detail::log( (::SAL_DETAIL_LOG_LEVEL_WARN), ("writerfilter.ooxml"
), ("/home/maarten/src/libreoffice/core/writerfilter/source/ooxml/OOXMLDocumentImpl.cxx"
":" "204" ": "), sal_detail_stream, 0); }; break; case SAL_DETAIL_LOG_ACTION_FATAL
: if (sizeof ::sal::detail::getResult( ::sal::detail::StreamStart
() << "importSubStream: exception while " "parsing stream "
<< nType << " " << exceptionToString(tools_warn_exception
)) == 1) { ::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_WARN), (
"writerfilter.ooxml"), ("/home/maarten/src/libreoffice/core/writerfilter/source/ooxml/OOXMLDocumentImpl.cxx"
":" "204" ": "), ::sal::detail::unwrapStream( ::sal::detail::
StreamStart() << "importSubStream: exception while " "parsing stream "
<< nType << " " << exceptionToString(tools_warn_exception
)), 0); } else { ::std::ostringstream sal_detail_stream; sal_detail_stream
<< "importSubStream: exception while " "parsing stream "
<< nType << " " << exceptionToString(tools_warn_exception
); ::sal::detail::log( (::SAL_DETAIL_LOG_LEVEL_WARN), ("writerfilter.ooxml"
), ("/home/maarten/src/libreoffice/core/writerfilter/source/ooxml/OOXMLDocumentImpl.cxx"
":" "204" ": "), sal_detail_stream, 0); }; std::abort(); break
; } } } while (false); } while (false)
;
205 mxCustomXmlProsDom = xRelation;
206 }
207
208 if(xRelation.is())
209 {
210 mxCustomXmlProsDom = xRelation;
211 }
212 }
213 else if(OOXMLStream::EMBEDDINGS == nType)
214 {
215 mxEmbeddings = xcpInputStream;
216 }
217 else if(OOXMLStream::CHARTS == nType)
218 {
219 importSubStreamRelations(cStream, OOXMLStream::EMBEDDINGS);
220 }
221
222
223}
224
225void OOXMLDocumentImpl::setXNoteId(const sal_Int32 nId)
226{
227 mnXNoteId = nId;
228}
229
230sal_Int32 OOXMLDocumentImpl::getXNoteId() const
231{
232 return mnXNoteId;
233}
234
235const OUString & OOXMLDocumentImpl::getTarget() const
236{
237 return mpStream->getTarget();
238}
239
240writerfilter::Reference<Stream>::Pointer_t
241OOXMLDocumentImpl::getSubStream(const OUString & rId)
242{
243 OOXMLStream::Pointer_t pStream
244 (OOXMLDocumentFactory::createStream(mpStream, rId));
245
246 OOXMLDocumentImpl * pTemp;
247 // Do not pass status indicator to sub-streams: they are typically marginal in size, so we just track the main document for now.
248 writerfilter::Reference<Stream>::Pointer_t pRet( pTemp = new OOXMLDocumentImpl(pStream, uno::Reference<task::XStatusIndicator>(), mbSkipImages, maMediaDescriptor));
249 pTemp->setModel(mxModel);
250 pTemp->setDrawPage(mxDrawPage);
251 pTemp->mbIsSubstream = true;
252 return pRet;
253}
254
255writerfilter::Reference<Stream>::Pointer_t
256OOXMLDocumentImpl::getXNoteStream(OOXMLStream::StreamType_t nType, const sal_Int32 nId)
257{
258 OOXMLStream::Pointer_t pStream =
259 OOXMLDocumentFactory::createStream(mpStream, nType);
260 // See above, no status indicator for the note stream, either.
261 OOXMLDocumentImpl * pDocument = new OOXMLDocumentImpl(pStream, uno::Reference<task::XStatusIndicator>(), mbSkipImages, maMediaDescriptor);
262 pDocument->setXNoteId(nId);
263 pDocument->setModel(getModel());
264 pDocument->setDrawPage(getDrawPage());
265
266 return writerfilter::Reference<Stream>::Pointer_t(pDocument);
267}
268
269void OOXMLDocumentImpl::resolveFootnote(Stream & rStream,
270 Id aType,
271 const sal_Int32 nNoteId)
272{
273 writerfilter::Reference<Stream>::Pointer_t pStream =
274 getXNoteStream(OOXMLStream::FOOTNOTES, nNoteId);
275
276 Id nId;
277 switch (aType)
278 {
279 case NS_ooxml::LN_Value_doc_ST_FtnEdn_separator:
280 case NS_ooxml::LN_Value_doc_ST_FtnEdn_continuationSeparator:
281 nId = aType;
282 break;
283 default:
284 nId = NS_ooxml::LN_footnote;
285 break;
286 }
287
288 resolveFastSubStreamWithId(rStream, pStream, nId);
289}
290
291void OOXMLDocumentImpl::resolveEndnote(Stream & rStream,
292 Id aType,
293 const sal_Int32 nNoteId)
294{
295 writerfilter::Reference<Stream>::Pointer_t pStream =
296 getXNoteStream(OOXMLStream::ENDNOTES, nNoteId);
297
298 Id nId;
299 switch (aType)
300 {
301 case NS_ooxml::LN_Value_doc_ST_FtnEdn_separator:
302 case NS_ooxml::LN_Value_doc_ST_FtnEdn_continuationSeparator:
303 nId = aType;
304 break;
305 default:
306 nId = NS_ooxml::LN_endnote;
307 break;
308 }
309
310 resolveFastSubStreamWithId(rStream, pStream, nId);
311}
312
313void OOXMLDocumentImpl::resolveComment(Stream & rStream,
314 const sal_Int32 nId)
315{
316 writerfilter::Reference<Stream>::Pointer_t pStream =
317 getXNoteStream(OOXMLStream::COMMENTS, nId);
318
319 resolveFastSubStreamWithId(rStream, pStream, NS_ooxml::LN_annotation);
320}
321
322OOXMLPropertySet * OOXMLDocumentImpl::getPicturePropSet
323(const OUString & rId)
324{
325 OOXMLStream::Pointer_t pStream
326 (OOXMLDocumentFactory::createStream(mpStream, rId));
327
328 writerfilter::Reference<BinaryObj>::Pointer_t pPicture
329 (new OOXMLBinaryObjectReference(pStream));
330
331 OOXMLValue::Pointer_t pPayloadValue(new OOXMLBinaryValue(pPicture));
332
333 OOXMLPropertySet::Pointer_t pBlipSet(new OOXMLPropertySet);
334
335 pBlipSet->add(NS_ooxml::LN_payload, pPayloadValue, OOXMLProperty::ATTRIBUTE);
336
337 OOXMLValue::Pointer_t pBlipValue(new OOXMLPropertySetValue(pBlipSet));
338
339 OOXMLPropertySet * pProps = new OOXMLPropertySet;
340
341 pProps->add(NS_ooxml::LN_blip, pBlipValue, OOXMLProperty::ATTRIBUTE);
342
343 return pProps;
344}
345
346void OOXMLDocumentImpl::resolvePicture(Stream & rStream,
347 const OUString & rId)
348{
349 OOXMLPropertySet::Pointer_t pProps(getPicturePropSet(rId));
350
351 rStream.props(pProps.get());
352}
353
354OUString OOXMLDocumentImpl::getTargetForId(const OUString & rId)
355{
356 return mpStream->getTargetForId(rId);
357}
358
359void OOXMLDocumentImpl::resolveHeader(Stream & rStream,
360 const sal_Int32 type,
361 const OUString & rId)
362{
363 writerfilter::Reference<Stream>::Pointer_t pStream =
364 getSubStream(rId);
365 switch (type)
366 {
367 case NS_ooxml::LN_Value_ST_HdrFtr_even:
368 resolveFastSubStreamWithId(rStream, pStream, NS_ooxml::LN_headerl);
369 break;
370 case NS_ooxml::LN_Value_ST_HdrFtr_default: // here we assume that default is right, but not necessarily true :-(
371 resolveFastSubStreamWithId(rStream, pStream, NS_ooxml::LN_headerr);
372 break;
373 case NS_ooxml::LN_Value_ST_HdrFtr_first:
374 resolveFastSubStreamWithId(rStream, pStream, NS_ooxml::LN_headerf);
375 break;
376 default:
377 break;
378 }
379}
380
381void OOXMLDocumentImpl::resolveFooter(Stream & rStream,
382 const sal_Int32 type,
383 const OUString & rId)
384{
385 writerfilter::Reference<Stream>::Pointer_t pStream =
386 getSubStream(rId);
387
388 switch (type)
389 {
390 case NS_ooxml::LN_Value_ST_HdrFtr_even:
391 resolveFastSubStreamWithId(rStream, pStream, NS_ooxml::LN_footerl);
392 break;
393 case NS_ooxml::LN_Value_ST_HdrFtr_default: // here we assume that default is right, but not necessarily true :-(
394 resolveFastSubStreamWithId(rStream, pStream, NS_ooxml::LN_footerr);
395 break;
396 case NS_ooxml::LN_Value_ST_HdrFtr_first:
397 resolveFastSubStreamWithId(rStream, pStream, NS_ooxml::LN_footerf);
398 break;
399 default:
400 break;
401 }
402}
403
404namespace {
405// Ensures that the indicator is reset after exiting OOXMLDocumentImpl::resolve
406class StatusIndicatorGuard{
407public:
408 explicit StatusIndicatorGuard(css::uno::Reference<css::task::XStatusIndicator> const & xStatusIndicator)
409 :mxStatusIndicator(xStatusIndicator)
410 {
411 }
412
413 ~StatusIndicatorGuard()
414 {
415 if (mxStatusIndicator.is())
416 mxStatusIndicator->end();
417 }
418
419private:
420 css::uno::Reference<css::task::XStatusIndicator> mxStatusIndicator;
421};
422}
423
424void OOXMLDocumentImpl::resolve(Stream & rStream)
425{
426 StatusIndicatorGuard aStatusIndicatorGuard(mxStatusIndicator);
427
428 if (utl::MediaDescriptor(maMediaDescriptor).getUnpackedValueOrDefault("ReadGlossaries", false))
1
Assuming the condition is true
2
Taking true branch
429 {
430 resolveFastSubStream(rStream, OOXMLStream::GLOSSARY);
3
Calling 'OOXMLDocumentImpl::resolveFastSubStream'
431 return;
432 }
433
434 uno::Reference<xml::sax::XFastParser> xParser(mpStream->getFastParser());
435
436 if (mxModel.is())
437 {
438 uno::Reference<document::XDocumentPropertiesSupplier> xDocumentPropertiesSupplier(mxModel, uno::UNO_QUERY);
439 uno::Reference<document::XDocumentProperties> xDocumentProperties = xDocumentPropertiesSupplier->getDocumentProperties();
440 comphelper::SequenceAsHashMap aMap(xDocumentProperties->getDocumentStatistics());
441 if (aMap.find("ParagraphCount") != aMap.end())
442 {
443 sal_Int32 nValue;
444 if (aMap["ParagraphCount"] >>= nValue)
445 {
446 if (mxStatusIndicator.is())
447 {
448 // We want to care about the progress if we know the estimated paragraph count and we have given a status indicator as well.
449 // Set the end position only here, so later it's enough to check if that is non-zero in incrementProgress().
450 mnProgressEndPos = nValue;
451 OUString aDocLoad(SvxResId(RID_SVXSTR_DOC_LOADreinterpret_cast<char const *>("RID_SVXSTR_DOC_LOAD" "\004"
u8"Loading document...")
));
452 mxStatusIndicator->start(aDocLoad, mnProgressEndPos);
453 mnPercentSize = mnProgressEndPos / 100;
454 }
455 }
456 }
457 }
458
459 if (!xParser.is())
460 return;
461
462 uno::Reference<uno::XComponentContext> xContext(mpStream->getContext());
463
464 OOXMLFastDocumentHandler * pDocHandler =
465 new OOXMLFastDocumentHandler(xContext, &rStream, this, mnXNoteId);
466 pDocHandler->setIsSubstream( mbIsSubstream );
467 uno::Reference < xml::sax::XFastDocumentHandler > xDocumentHandler(pDocHandler);
468 uno::Reference < xml::sax::XFastTokenHandler > xTokenHandler(mpStream->getFastTokenHandler());
469
470 resolveFastSubStream(rStream, OOXMLStream::SETTINGS);
471 mxThemeDom = importSubStream(OOXMLStream::THEME);
472 resolveFastSubStream(rStream, OOXMLStream::THEME);
473 mxGlossaryDocDom = importSubStream(OOXMLStream::GLOSSARY);
474 if (mxGlossaryDocDom.is())
475 resolveGlossaryStream(rStream);
476
477 resolveEmbeddingsStream(mpStream);
478
479 // Custom xml's are handled as part of grab bag.
480 resolveCustomXmlStream(rStream);
481
482 resolveFastSubStream(rStream, OOXMLStream::FONTTABLE);
483 resolveFastSubStream(rStream, OOXMLStream::STYLES);
484 resolveFastSubStream(rStream, OOXMLStream::NUMBERING);
485
486 xParser->setFastDocumentHandler( xDocumentHandler );
487 xParser->setTokenHandler( xTokenHandler );
488
489 xml::sax::InputSource aParserInput;
490 aParserInput.sSystemId = mpStream->getTarget();
491 aParserInput.aInputStream = mpStream->getDocumentStream();
492 try
493 {
494 xParser->parseStream(aParserInput);
495 }
496 catch (xml::sax::SAXException const& rErr)
497 {
498 // don't silently swallow these - handlers may not have been executed,
499 // and the domain mapper is likely in an inconsistent state
500 // In case user chooses to try to continue loading, don't ask again for this file
501 SfxObjectShell* rShell = SfxObjectShell::GetShellFromComponent(mxModel);
502 if (!rShell || !rShell->IsContinueImportOnFilterExceptions("SAXException: " + rErr.Message))
503 throw;
504 }
505 catch (uno::RuntimeException const&)
506 {
507 throw;
508 }
509 // note: cannot throw anything other than SAXException out of here?
510 catch (uno::Exception const&)
511 {
512 css::uno::Any anyEx = cppu::getCaughtException();
513 SAL_WARN("writerfilter.ooxml", "OOXMLDocumentImpl::resolve(): " << exceptionToString(anyEx))do { if (true) { switch (sal_detail_log_report(::SAL_DETAIL_LOG_LEVEL_WARN
, "writerfilter.ooxml")) { case SAL_DETAIL_LOG_ACTION_IGNORE:
break; case SAL_DETAIL_LOG_ACTION_LOG: if (sizeof ::sal::detail
::getResult( ::sal::detail::StreamStart() << "OOXMLDocumentImpl::resolve(): "
<< exceptionToString(anyEx)) == 1) { ::sal_detail_log(
(::SAL_DETAIL_LOG_LEVEL_WARN), ("writerfilter.ooxml"), ("/home/maarten/src/libreoffice/core/writerfilter/source/ooxml/OOXMLDocumentImpl.cxx"
":" "513" ": "), ::sal::detail::unwrapStream( ::sal::detail::
StreamStart() << "OOXMLDocumentImpl::resolve(): " <<
exceptionToString(anyEx)), 0); } else { ::std::ostringstream
sal_detail_stream; sal_detail_stream << "OOXMLDocumentImpl::resolve(): "
<< exceptionToString(anyEx); ::sal::detail::log( (::SAL_DETAIL_LOG_LEVEL_WARN
), ("writerfilter.ooxml"), ("/home/maarten/src/libreoffice/core/writerfilter/source/ooxml/OOXMLDocumentImpl.cxx"
":" "513" ": "), sal_detail_stream, 0); }; break; case SAL_DETAIL_LOG_ACTION_FATAL
: if (sizeof ::sal::detail::getResult( ::sal::detail::StreamStart
() << "OOXMLDocumentImpl::resolve(): " << exceptionToString
(anyEx)) == 1) { ::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_WARN
), ("writerfilter.ooxml"), ("/home/maarten/src/libreoffice/core/writerfilter/source/ooxml/OOXMLDocumentImpl.cxx"
":" "513" ": "), ::sal::detail::unwrapStream( ::sal::detail::
StreamStart() << "OOXMLDocumentImpl::resolve(): " <<
exceptionToString(anyEx)), 0); } else { ::std::ostringstream
sal_detail_stream; sal_detail_stream << "OOXMLDocumentImpl::resolve(): "
<< exceptionToString(anyEx); ::sal::detail::log( (::SAL_DETAIL_LOG_LEVEL_WARN
), ("writerfilter.ooxml"), ("/home/maarten/src/libreoffice/core/writerfilter/source/ooxml/OOXMLDocumentImpl.cxx"
":" "513" ": "), sal_detail_stream, 0); }; std::abort(); break
; } } } while (false)
;
514 throw lang::WrappedTargetRuntimeException("", nullptr, anyEx);
515 }
516 catch (...)
517 {
518 SAL_WARN("writerfilter.ooxml",do { if (true) { switch (sal_detail_log_report(::SAL_DETAIL_LOG_LEVEL_WARN
, "writerfilter.ooxml")) { case SAL_DETAIL_LOG_ACTION_IGNORE:
break; case SAL_DETAIL_LOG_ACTION_LOG: if (sizeof ::sal::detail
::getResult( ::sal::detail::StreamStart() << "OOXMLDocumentImpl::resolve(): non-UNO exception"
) == 1) { ::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_WARN), ("writerfilter.ooxml"
), ("/home/maarten/src/libreoffice/core/writerfilter/source/ooxml/OOXMLDocumentImpl.cxx"
":" "519" ": "), ::sal::detail::unwrapStream( ::sal::detail::
StreamStart() << "OOXMLDocumentImpl::resolve(): non-UNO exception"
), 0); } else { ::std::ostringstream sal_detail_stream; sal_detail_stream
<< "OOXMLDocumentImpl::resolve(): non-UNO exception"; ::
sal::detail::log( (::SAL_DETAIL_LOG_LEVEL_WARN), ("writerfilter.ooxml"
), ("/home/maarten/src/libreoffice/core/writerfilter/source/ooxml/OOXMLDocumentImpl.cxx"
":" "519" ": "), sal_detail_stream, 0); }; break; case SAL_DETAIL_LOG_ACTION_FATAL
: if (sizeof ::sal::detail::getResult( ::sal::detail::StreamStart
() << "OOXMLDocumentImpl::resolve(): non-UNO exception"
) == 1) { ::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_WARN), ("writerfilter.ooxml"
), ("/home/maarten/src/libreoffice/core/writerfilter/source/ooxml/OOXMLDocumentImpl.cxx"
":" "519" ": "), ::sal::detail::unwrapStream( ::sal::detail::
StreamStart() << "OOXMLDocumentImpl::resolve(): non-UNO exception"
), 0); } else { ::std::ostringstream sal_detail_stream; sal_detail_stream
<< "OOXMLDocumentImpl::resolve(): non-UNO exception"; ::
sal::detail::log( (::SAL_DETAIL_LOG_LEVEL_WARN), ("writerfilter.ooxml"
), ("/home/maarten/src/libreoffice/core/writerfilter/source/ooxml/OOXMLDocumentImpl.cxx"
":" "519" ": "), sal_detail_stream, 0); }; std::abort(); break
; } } } while (false)
519 "OOXMLDocumentImpl::resolve(): non-UNO exception")do { if (true) { switch (sal_detail_log_report(::SAL_DETAIL_LOG_LEVEL_WARN
, "writerfilter.ooxml")) { case SAL_DETAIL_LOG_ACTION_IGNORE:
break; case SAL_DETAIL_LOG_ACTION_LOG: if (sizeof ::sal::detail
::getResult( ::sal::detail::StreamStart() << "OOXMLDocumentImpl::resolve(): non-UNO exception"
) == 1) { ::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_WARN), ("writerfilter.ooxml"
), ("/home/maarten/src/libreoffice/core/writerfilter/source/ooxml/OOXMLDocumentImpl.cxx"
":" "519" ": "), ::sal::detail::unwrapStream( ::sal::detail::
StreamStart() << "OOXMLDocumentImpl::resolve(): non-UNO exception"
), 0); } else { ::std::ostringstream sal_detail_stream; sal_detail_stream
<< "OOXMLDocumentImpl::resolve(): non-UNO exception"; ::
sal::detail::log( (::SAL_DETAIL_LOG_LEVEL_WARN), ("writerfilter.ooxml"
), ("/home/maarten/src/libreoffice/core/writerfilter/source/ooxml/OOXMLDocumentImpl.cxx"
":" "519" ": "), sal_detail_stream, 0); }; break; case SAL_DETAIL_LOG_ACTION_FATAL
: if (sizeof ::sal::detail::getResult( ::sal::detail::StreamStart
() << "OOXMLDocumentImpl::resolve(): non-UNO exception"
) == 1) { ::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_WARN), ("writerfilter.ooxml"
), ("/home/maarten/src/libreoffice/core/writerfilter/source/ooxml/OOXMLDocumentImpl.cxx"
":" "519" ": "), ::sal::detail::unwrapStream( ::sal::detail::
StreamStart() << "OOXMLDocumentImpl::resolve(): non-UNO exception"
), 0); } else { ::std::ostringstream sal_detail_stream; sal_detail_stream
<< "OOXMLDocumentImpl::resolve(): non-UNO exception"; ::
sal::detail::log( (::SAL_DETAIL_LOG_LEVEL_WARN), ("writerfilter.ooxml"
), ("/home/maarten/src/libreoffice/core/writerfilter/source/ooxml/OOXMLDocumentImpl.cxx"
":" "519" ": "), sal_detail_stream, 0); }; std::abort(); break
; } } } while (false)
;
520 }
521}
522
523void OOXMLDocumentImpl::incrementProgress()
524{
525 mnProgressCurrentPos++;
526 // 1) If we know the end
527 // 2) We progressed enough that updating makes sense
528 // 3) We did not reach the end yet (possible in case the doc stat is misleading)
529 if (mnProgressEndPos && mnProgressCurrentPos > (mnProgressLastPos + mnPercentSize) && mnProgressLastPos < mnProgressEndPos)
530 {
531 mnProgressLastPos = mnProgressCurrentPos;
532 if (mxStatusIndicator.is())
533 mxStatusIndicator->setValue(mnProgressLastPos);
534 }
535}
536
537void OOXMLDocumentImpl::resolveCustomXmlStream(Stream & rStream)
538{
539 // Resolving all item[n].xml files from CustomXml folder.
540 uno::Reference<embed::XRelationshipAccess> xRelationshipAccess;
541 xRelationshipAccess.set(dynamic_cast<OOXMLStreamImpl&>(*mpStream).accessDocumentStream(), uno::UNO_QUERY);
542 if (!xRelationshipAccess.is())
543 return;
544
545 static const char sCustomType[] = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/customXml";
546 static const char sCustomTypeStrict[] = "http://purl.oclc.org/ooxml/officeDocument/relationships/customXml";
547 bool bFound = false;
548 const uno::Sequence<uno::Sequence< beans::StringPair>> aSeqs = xRelationshipAccess->getAllRelationships();
549 std::vector<uno::Reference<xml::dom::XDocument>> aCustomXmlDomList;
550 std::vector<uno::Reference<xml::dom::XDocument>> aCustomXmlDomPropsList;
551 for (const uno::Sequence<beans::StringPair>& aSeq : aSeqs)
552 {
553 for (const beans::StringPair& aPair : aSeq)
554 {
555 // Need to resolve only customxml files from document relationships.
556 // Skipping other files.
557 if (aPair.Second == sCustomType ||
558 aPair.Second == sCustomTypeStrict)
559 bFound = true;
560 else if (aPair.First == "Target" && bFound)
561 {
562 // Adding value to extern variable customTarget. It will be used in ooxmlstreamimpl
563 // to ensure customxml target is visited in lcl_getTarget.
564 customTarget = aPair.Second;
565 }
566 }
567
568 if (bFound)
569 {
570 uno::Reference<xml::dom::XDocument> customXmlTemp = importSubStream(OOXMLStream::CUSTOMXML);
571 // This will add all item[n].xml with its relationship file i.e itemprops.xml to
572 // grabbag list.
573 if (mxCustomXmlProsDom.is() && customXmlTemp.is())
574 {
575 aCustomXmlDomList.push_back(customXmlTemp);
576 aCustomXmlDomPropsList.push_back(mxCustomXmlProsDom);
577 resolveFastSubStream(rStream, OOXMLStream::CUSTOMXML);
578 }
579
580 bFound = false;
581 }
582 }
583
584 mxCustomXmlDomList = comphelper::containerToSequence(aCustomXmlDomList);
585 mxCustomXmlDomPropsList = comphelper::containerToSequence(aCustomXmlDomPropsList);
586}
587
588void OOXMLDocumentImpl::resolveGlossaryStream(Stream & /*rStream*/)
589{
590 static const char sSettingsType[] = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/settings";
591 static const char sStylesType[] = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/styles";
592 static const char sFonttableType[] = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/fontTable";
593 static const char sWebSettings[] = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/webSettings";
594 static const char sSettingsTypeStrict[] = "http://purl.oclc.org/ooxml/officeDocument/relationships/settings";
595 static const char sStylesTypeStrict[] = "http://purl.oclc.org/ooxml/officeDocument/relationships/styles";
596 static const char sFonttableTypeStrict[] = "http://purl.oclc.org/ooxml/officeDocument/relationships/fontTable";
597 static const char sWebSettingsStrict[] = "http://purl.oclc.org/ooxml/officeDocument/relationships/webSettings";
598
599 OOXMLStream::Pointer_t pStream;
600 try
601 {
602 pStream = OOXMLDocumentFactory::createStream(mpStream, OOXMLStream::GLOSSARY);
603 }
604 catch (uno::Exception const&)
605 {
606 TOOLS_INFO_EXCEPTION("writerfilter.ooxml", "resolveGlossaryStream: exception while "do { css::uno::Any tools_warn_exception( DbgGetCaughtException
() ); do { if (true) { switch (sal_detail_log_report(::SAL_DETAIL_LOG_LEVEL_INFO
, "writerfilter.ooxml")) { case SAL_DETAIL_LOG_ACTION_IGNORE:
break; case SAL_DETAIL_LOG_ACTION_LOG: if (sizeof ::sal::detail
::getResult( ::sal::detail::StreamStart() << "resolveGlossaryStream: exception while "
"createStream for glossary" << OOXMLStream::GLOSSARY <<
" " << exceptionToString(tools_warn_exception)) == 1) {
::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_INFO), ("writerfilter.ooxml"
), ("/home/maarten/src/libreoffice/core/writerfilter/source/ooxml/OOXMLDocumentImpl.cxx"
":" "607" ": "), ::sal::detail::unwrapStream( ::sal::detail::
StreamStart() << "resolveGlossaryStream: exception while "
"createStream for glossary" << OOXMLStream::GLOSSARY <<
" " << exceptionToString(tools_warn_exception)), 0); }
else { ::std::ostringstream sal_detail_stream; sal_detail_stream
<< "resolveGlossaryStream: exception while " "createStream for glossary"
<< OOXMLStream::GLOSSARY << " " << exceptionToString
(tools_warn_exception); ::sal::detail::log( (::SAL_DETAIL_LOG_LEVEL_INFO
), ("writerfilter.ooxml"), ("/home/maarten/src/libreoffice/core/writerfilter/source/ooxml/OOXMLDocumentImpl.cxx"
":" "607" ": "), sal_detail_stream, 0); }; break; case SAL_DETAIL_LOG_ACTION_FATAL
: if (sizeof ::sal::detail::getResult( ::sal::detail::StreamStart
() << "resolveGlossaryStream: exception while " "createStream for glossary"
<< OOXMLStream::GLOSSARY << " " << exceptionToString
(tools_warn_exception)) == 1) { ::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_INFO
), ("writerfilter.ooxml"), ("/home/maarten/src/libreoffice/core/writerfilter/source/ooxml/OOXMLDocumentImpl.cxx"
":" "607" ": "), ::sal::detail::unwrapStream( ::sal::detail::
StreamStart() << "resolveGlossaryStream: exception while "
"createStream for glossary" << OOXMLStream::GLOSSARY <<
" " << exceptionToString(tools_warn_exception)), 0); }
else { ::std::ostringstream sal_detail_stream; sal_detail_stream
<< "resolveGlossaryStream: exception while " "createStream for glossary"
<< OOXMLStream::GLOSSARY << " " << exceptionToString
(tools_warn_exception); ::sal::detail::log( (::SAL_DETAIL_LOG_LEVEL_INFO
), ("writerfilter.ooxml"), ("/home/maarten/src/libreoffice/core/writerfilter/source/ooxml/OOXMLDocumentImpl.cxx"
":" "607" ": "), sal_detail_stream, 0); }; std::abort(); break
; } } } while (false); } while (false)
607 "createStream for glossary" << OOXMLStream::GLOSSARY)do { css::uno::Any tools_warn_exception( DbgGetCaughtException
() ); do { if (true) { switch (sal_detail_log_report(::SAL_DETAIL_LOG_LEVEL_INFO
, "writerfilter.ooxml")) { case SAL_DETAIL_LOG_ACTION_IGNORE:
break; case SAL_DETAIL_LOG_ACTION_LOG: if (sizeof ::sal::detail
::getResult( ::sal::detail::StreamStart() << "resolveGlossaryStream: exception while "
"createStream for glossary" << OOXMLStream::GLOSSARY <<
" " << exceptionToString(tools_warn_exception)) == 1) {
::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_INFO), ("writerfilter.ooxml"
), ("/home/maarten/src/libreoffice/core/writerfilter/source/ooxml/OOXMLDocumentImpl.cxx"
":" "607" ": "), ::sal::detail::unwrapStream( ::sal::detail::
StreamStart() << "resolveGlossaryStream: exception while "
"createStream for glossary" << OOXMLStream::GLOSSARY <<
" " << exceptionToString(tools_warn_exception)), 0); }
else { ::std::ostringstream sal_detail_stream; sal_detail_stream
<< "resolveGlossaryStream: exception while " "createStream for glossary"
<< OOXMLStream::GLOSSARY << " " << exceptionToString
(tools_warn_exception); ::sal::detail::log( (::SAL_DETAIL_LOG_LEVEL_INFO
), ("writerfilter.ooxml"), ("/home/maarten/src/libreoffice/core/writerfilter/source/ooxml/OOXMLDocumentImpl.cxx"
":" "607" ": "), sal_detail_stream, 0); }; break; case SAL_DETAIL_LOG_ACTION_FATAL
: if (sizeof ::sal::detail::getResult( ::sal::detail::StreamStart
() << "resolveGlossaryStream: exception while " "createStream for glossary"
<< OOXMLStream::GLOSSARY << " " << exceptionToString
(tools_warn_exception)) == 1) { ::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_INFO
), ("writerfilter.ooxml"), ("/home/maarten/src/libreoffice/core/writerfilter/source/ooxml/OOXMLDocumentImpl.cxx"
":" "607" ": "), ::sal::detail::unwrapStream( ::sal::detail::
StreamStart() << "resolveGlossaryStream: exception while "
"createStream for glossary" << OOXMLStream::GLOSSARY <<
" " << exceptionToString(tools_warn_exception)), 0); }
else { ::std::ostringstream sal_detail_stream; sal_detail_stream
<< "resolveGlossaryStream: exception while " "createStream for glossary"
<< OOXMLStream::GLOSSARY << " " << exceptionToString
(tools_warn_exception); ::sal::detail::log( (::SAL_DETAIL_LOG_LEVEL_INFO
), ("writerfilter.ooxml"), ("/home/maarten/src/libreoffice/core/writerfilter/source/ooxml/OOXMLDocumentImpl.cxx"
":" "607" ": "), sal_detail_stream, 0); }; std::abort(); break
; } } } while (false); } while (false)
;
608 return;
609 }
610 uno::Reference<embed::XRelationshipAccess> xRelationshipAccess;
611 xRelationshipAccess.set(dynamic_cast<OOXMLStreamImpl&>(*pStream).accessDocumentStream(), uno::UNO_QUERY);
612 if (!xRelationshipAccess.is())
613 return;
614
615
616 const uno::Sequence< uno::Sequence< beans::StringPair > >aSeqs = xRelationshipAccess->getAllRelationships();
617 std::vector< uno::Sequence<uno::Any> > aGlossaryDomList;
618 for (const uno::Sequence< beans::StringPair >& aSeq : aSeqs)
619 {
620 OOXMLStream::Pointer_t gStream;
621 //Follows following aSeq[0] is Id, aSeq[1] is Type, aSeq[2] is Target
622 if (aSeq.getLength() < 3)
623 {
624 SAL_WARN("writerfilter.ooxml", "too short sequence")do { if (true) { switch (sal_detail_log_report(::SAL_DETAIL_LOG_LEVEL_WARN
, "writerfilter.ooxml")) { case SAL_DETAIL_LOG_ACTION_IGNORE:
break; case SAL_DETAIL_LOG_ACTION_LOG: if (sizeof ::sal::detail
::getResult( ::sal::detail::StreamStart() << "too short sequence"
) == 1) { ::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_WARN), ("writerfilter.ooxml"
), ("/home/maarten/src/libreoffice/core/writerfilter/source/ooxml/OOXMLDocumentImpl.cxx"
":" "624" ": "), ::sal::detail::unwrapStream( ::sal::detail::
StreamStart() << "too short sequence"), 0); } else { ::
std::ostringstream sal_detail_stream; sal_detail_stream <<
"too short sequence"; ::sal::detail::log( (::SAL_DETAIL_LOG_LEVEL_WARN
), ("writerfilter.ooxml"), ("/home/maarten/src/libreoffice/core/writerfilter/source/ooxml/OOXMLDocumentImpl.cxx"
":" "624" ": "), sal_detail_stream, 0); }; break; case SAL_DETAIL_LOG_ACTION_FATAL
: if (sizeof ::sal::detail::getResult( ::sal::detail::StreamStart
() << "too short sequence") == 1) { ::sal_detail_log( (
::SAL_DETAIL_LOG_LEVEL_WARN), ("writerfilter.ooxml"), ("/home/maarten/src/libreoffice/core/writerfilter/source/ooxml/OOXMLDocumentImpl.cxx"
":" "624" ": "), ::sal::detail::unwrapStream( ::sal::detail::
StreamStart() << "too short sequence"), 0); } else { ::
std::ostringstream sal_detail_stream; sal_detail_stream <<
"too short sequence"; ::sal::detail::log( (::SAL_DETAIL_LOG_LEVEL_WARN
), ("writerfilter.ooxml"), ("/home/maarten/src/libreoffice/core/writerfilter/source/ooxml/OOXMLDocumentImpl.cxx"
":" "624" ": "), sal_detail_stream, 0); }; std::abort(); break
; } } } while (false)
;
625 continue;
626 }
627
628 OUString gId(aSeq[0].Second);
629 OUString gType(aSeq[1].Second);
630 OUString gTarget(aSeq[2].Second);
631 OUString contentType;
632
633 OOXMLStream::StreamType_t nType(OOXMLStream::UNKNOWN);
634 bool bFound = true;
635 if(gType == sSettingsType ||
636 gType == sSettingsTypeStrict)
637 {
638 nType = OOXMLStream::SETTINGS;
639 contentType = "application/vnd.openxmlformats-officedocument.wordprocessingml.settings+xml";
640 }
641 else if(gType == sStylesType ||
642 gType == sStylesTypeStrict)
643 {
644 nType = OOXMLStream::STYLES;
645 contentType = "application/vnd.openxmlformats-officedocument.wordprocessingml.styles+xml";
646 }
647 else if(gType == sWebSettings ||
648 gType == sWebSettingsStrict)
649 {
650 nType = OOXMLStream::WEBSETTINGS;
651 contentType = "application/vnd.openxmlformats-officedocument.wordprocessingml.webSettings+xml";
652 }
653 else if(gType == sFonttableType ||
654 gType == sFonttableTypeStrict)
655 {
656 nType = OOXMLStream::FONTTABLE;
657 contentType = "application/vnd.openxmlformats-officedocument.wordprocessingml.fontTable+xml";
658 }
659 else
660 {
661 bFound = false;
662 //"Unhandled content-type while grab bagging Glossary Folder");
663 }
664
665 if (bFound)
666 {
667 uno::Reference<xml::dom::XDocument> xDom;
668 try
669 {
670 gStream = OOXMLDocumentFactory::createStream(pStream, nType);
671 uno::Reference<io::XInputStream> xInputStream = gStream->getDocumentStream();
672 uno::Reference<uno::XComponentContext> xContext(pStream->getContext());
673 uno::Reference<xml::dom::XDocumentBuilder> xDomBuilder(xml::dom::DocumentBuilder::create(xContext));
674 xDom = xDomBuilder->parse(xInputStream);
675 }
676 catch (uno::Exception const&)
677 {
678 TOOLS_INFO_EXCEPTION("writerfilter.ooxml", "importSubStream: exception while "do { css::uno::Any tools_warn_exception( DbgGetCaughtException
() ); do { if (true) { switch (sal_detail_log_report(::SAL_DETAIL_LOG_LEVEL_INFO
, "writerfilter.ooxml")) { case SAL_DETAIL_LOG_ACTION_IGNORE:
break; case SAL_DETAIL_LOG_ACTION_LOG: if (sizeof ::sal::detail
::getResult( ::sal::detail::StreamStart() << "importSubStream: exception while "
"parsing stream of Type" << nType << " " <<
exceptionToString(tools_warn_exception)) == 1) { ::sal_detail_log
( (::SAL_DETAIL_LOG_LEVEL_INFO), ("writerfilter.ooxml"), ("/home/maarten/src/libreoffice/core/writerfilter/source/ooxml/OOXMLDocumentImpl.cxx"
":" "679" ": "), ::sal::detail::unwrapStream( ::sal::detail::
StreamStart() << "importSubStream: exception while " "parsing stream of Type"
<< nType << " " << exceptionToString(tools_warn_exception
)), 0); } else { ::std::ostringstream sal_detail_stream; sal_detail_stream
<< "importSubStream: exception while " "parsing stream of Type"
<< nType << " " << exceptionToString(tools_warn_exception
); ::sal::detail::log( (::SAL_DETAIL_LOG_LEVEL_INFO), ("writerfilter.ooxml"
), ("/home/maarten/src/libreoffice/core/writerfilter/source/ooxml/OOXMLDocumentImpl.cxx"
":" "679" ": "), sal_detail_stream, 0); }; break; case SAL_DETAIL_LOG_ACTION_FATAL
: if (sizeof ::sal::detail::getResult( ::sal::detail::StreamStart
() << "importSubStream: exception while " "parsing stream of Type"
<< nType << " " << exceptionToString(tools_warn_exception
)) == 1) { ::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_INFO), (
"writerfilter.ooxml"), ("/home/maarten/src/libreoffice/core/writerfilter/source/ooxml/OOXMLDocumentImpl.cxx"
":" "679" ": "), ::sal::detail::unwrapStream( ::sal::detail::
StreamStart() << "importSubStream: exception while " "parsing stream of Type"
<< nType << " " << exceptionToString(tools_warn_exception
)), 0); } else { ::std::ostringstream sal_detail_stream; sal_detail_stream
<< "importSubStream: exception while " "parsing stream of Type"
<< nType << " " << exceptionToString(tools_warn_exception
); ::sal::detail::log( (::SAL_DETAIL_LOG_LEVEL_INFO), ("writerfilter.ooxml"
), ("/home/maarten/src/libreoffice/core/writerfilter/source/ooxml/OOXMLDocumentImpl.cxx"
":" "679" ": "), sal_detail_stream, 0); }; std::abort(); break
; } } } while (false); } while (false)
679 "parsing stream of Type" << nType)do { css::uno::Any tools_warn_exception( DbgGetCaughtException
() ); do { if (true) { switch (sal_detail_log_report(::SAL_DETAIL_LOG_LEVEL_INFO
, "writerfilter.ooxml")) { case SAL_DETAIL_LOG_ACTION_IGNORE:
break; case SAL_DETAIL_LOG_ACTION_LOG: if (sizeof ::sal::detail
::getResult( ::sal::detail::StreamStart() << "importSubStream: exception while "
"parsing stream of Type" << nType << " " <<
exceptionToString(tools_warn_exception)) == 1) { ::sal_detail_log
( (::SAL_DETAIL_LOG_LEVEL_INFO), ("writerfilter.ooxml"), ("/home/maarten/src/libreoffice/core/writerfilter/source/ooxml/OOXMLDocumentImpl.cxx"
":" "679" ": "), ::sal::detail::unwrapStream( ::sal::detail::
StreamStart() << "importSubStream: exception while " "parsing stream of Type"
<< nType << " " << exceptionToString(tools_warn_exception
)), 0); } else { ::std::ostringstream sal_detail_stream; sal_detail_stream
<< "importSubStream: exception while " "parsing stream of Type"
<< nType << " " << exceptionToString(tools_warn_exception
); ::sal::detail::log( (::SAL_DETAIL_LOG_LEVEL_INFO), ("writerfilter.ooxml"
), ("/home/maarten/src/libreoffice/core/writerfilter/source/ooxml/OOXMLDocumentImpl.cxx"
":" "679" ": "), sal_detail_stream, 0); }; break; case SAL_DETAIL_LOG_ACTION_FATAL
: if (sizeof ::sal::detail::getResult( ::sal::detail::StreamStart
() << "importSubStream: exception while " "parsing stream of Type"
<< nType << " " << exceptionToString(tools_warn_exception
)) == 1) { ::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_INFO), (
"writerfilter.ooxml"), ("/home/maarten/src/libreoffice/core/writerfilter/source/ooxml/OOXMLDocumentImpl.cxx"
":" "679" ": "), ::sal::detail::unwrapStream( ::sal::detail::
StreamStart() << "importSubStream: exception while " "parsing stream of Type"
<< nType << " " << exceptionToString(tools_warn_exception
)), 0); } else { ::std::ostringstream sal_detail_stream; sal_detail_stream
<< "importSubStream: exception while " "parsing stream of Type"
<< nType << " " << exceptionToString(tools_warn_exception
); ::sal::detail::log( (::SAL_DETAIL_LOG_LEVEL_INFO), ("writerfilter.ooxml"
), ("/home/maarten/src/libreoffice/core/writerfilter/source/ooxml/OOXMLDocumentImpl.cxx"
":" "679" ": "), sal_detail_stream, 0); }; std::abort(); break
; } } } while (false); } while (false)
;
680 return;
681 }
682
683 if (xDom.is())
684 {
685 uno::Sequence< uno::Any > glossaryTuple (5);
686 glossaryTuple[0] <<= xDom;
687 glossaryTuple[1] <<= gId;
688 glossaryTuple[2] <<= gType;
689 glossaryTuple[3] <<= gTarget;
690 glossaryTuple[4] <<= contentType;
691 aGlossaryDomList.push_back(glossaryTuple);
692 }
693 }
694 }
695 mxGlossaryDomList = comphelper::containerToSequence(aGlossaryDomList);
696}
697
698void OOXMLDocumentImpl::resolveEmbeddingsStream(const OOXMLStream::Pointer_t& pStream)
699{
700 uno::Reference<embed::XRelationshipAccess> xRelationshipAccess;
701 xRelationshipAccess.set(dynamic_cast<OOXMLStreamImpl&>(*pStream).accessDocumentStream(), uno::UNO_QUERY);
702 if (xRelationshipAccess.is())
703 {
704 OUString const sChartType("http://schemas.openxmlformats.org/officeDocument/2006/relationships/chart");
705 OUString const sChartTypeStrict("http://purl.oclc.org/ooxml/officeDocument/relationships/chart");
706 OUString const sFootersType("http://schemas.openxmlformats.org/officeDocument/2006/relationships/footer");
707 OUString const sFootersTypeStrict("http://purl.oclc.org/ooxml/officeDocument/relationships/footer");
708 OUString const sHeaderType("http://schemas.openxmlformats.org/officeDocument/2006/relationships/header");
709 OUString const sHeaderTypeStrict("http://purl.oclc.org/ooxml/officeDocument/relationships/header");
710
711 bool bFound = false;
712 bool bHeaderFooterFound = false;
713 OOXMLStream::StreamType_t streamType = OOXMLStream::UNKNOWN;
714 const uno::Sequence< uno::Sequence< beans::StringPair > >aSeqs = xRelationshipAccess->getAllRelationships();
715 for (const uno::Sequence< beans::StringPair >& aSeq : aSeqs)
716 {
717 for (const beans::StringPair& aPair : aSeq)
718 {
719 if (aPair.Second == sChartType ||
720 aPair.Second == sChartTypeStrict)
721 {
722 bFound = true;
723 }
724 else if(aPair.Second == sFootersType ||
725 aPair.Second == sFootersTypeStrict)
726 {
727 bHeaderFooterFound = true;
728 streamType = OOXMLStream::FOOTER;
729 }
730 else if(aPair.Second == sHeaderType ||
731 aPair.Second == sHeaderTypeStrict)
732 {
733 bHeaderFooterFound = true;
734 streamType = OOXMLStream::HEADER;
735 }
736 else if(aPair.First == "Target" && ( bFound || bHeaderFooterFound ))
737 {
738 // Adding value to extern variable customTarget. It will be used in ooxmlstreamimpl
739 // to ensure chart.xml target is visited in lcl_getTarget.
740 customTarget = aPair.Second;
741 }
742 }
743 if( bFound || bHeaderFooterFound)
744 {
745 if(bFound)
746 {
747 importSubStreamRelations(pStream, OOXMLStream::CHARTS);
748 }
749 if(bHeaderFooterFound)
750 {
751 try
752 {
753 OOXMLStream::Pointer_t Stream = OOXMLDocumentFactory::createStream(pStream, streamType);
754 if (Stream)
755 resolveEmbeddingsStream(Stream);
756 }
757 catch (uno::Exception const&)
758 {
759 TOOLS_INFO_EXCEPTION("writerfilter.ooxml", "resolveEmbeddingsStream: can't find header/footer whilst "do { css::uno::Any tools_warn_exception( DbgGetCaughtException
() ); do { if (true) { switch (sal_detail_log_report(::SAL_DETAIL_LOG_LEVEL_INFO
, "writerfilter.ooxml")) { case SAL_DETAIL_LOG_ACTION_IGNORE:
break; case SAL_DETAIL_LOG_ACTION_LOG: if (sizeof ::sal::detail
::getResult( ::sal::detail::StreamStart() << "resolveEmbeddingsStream: can't find header/footer whilst "
"resolving stream " << streamType << " " <<
exceptionToString(tools_warn_exception)) == 1) { ::sal_detail_log
( (::SAL_DETAIL_LOG_LEVEL_INFO), ("writerfilter.ooxml"), ("/home/maarten/src/libreoffice/core/writerfilter/source/ooxml/OOXMLDocumentImpl.cxx"
":" "760" ": "), ::sal::detail::unwrapStream( ::sal::detail::
StreamStart() << "resolveEmbeddingsStream: can't find header/footer whilst "
"resolving stream " << streamType << " " <<
exceptionToString(tools_warn_exception)), 0); } else { ::std
::ostringstream sal_detail_stream; sal_detail_stream <<
"resolveEmbeddingsStream: can't find header/footer whilst " "resolving stream "
<< streamType << " " << exceptionToString(
tools_warn_exception); ::sal::detail::log( (::SAL_DETAIL_LOG_LEVEL_INFO
), ("writerfilter.ooxml"), ("/home/maarten/src/libreoffice/core/writerfilter/source/ooxml/OOXMLDocumentImpl.cxx"
":" "760" ": "), sal_detail_stream, 0); }; break; case SAL_DETAIL_LOG_ACTION_FATAL
: if (sizeof ::sal::detail::getResult( ::sal::detail::StreamStart
() << "resolveEmbeddingsStream: can't find header/footer whilst "
"resolving stream " << streamType << " " <<
exceptionToString(tools_warn_exception)) == 1) { ::sal_detail_log
( (::SAL_DETAIL_LOG_LEVEL_INFO), ("writerfilter.ooxml"), ("/home/maarten/src/libreoffice/core/writerfilter/source/ooxml/OOXMLDocumentImpl.cxx"
":" "760" ": "), ::sal::detail::unwrapStream( ::sal::detail::
StreamStart() << "resolveEmbeddingsStream: can't find header/footer whilst "
"resolving stream " << streamType << " " <<
exceptionToString(tools_warn_exception)), 0); } else { ::std
::ostringstream sal_detail_stream; sal_detail_stream <<
"resolveEmbeddingsStream: can't find header/footer whilst " "resolving stream "
<< streamType << " " << exceptionToString(
tools_warn_exception); ::sal::detail::log( (::SAL_DETAIL_LOG_LEVEL_INFO
), ("writerfilter.ooxml"), ("/home/maarten/src/libreoffice/core/writerfilter/source/ooxml/OOXMLDocumentImpl.cxx"
":" "760" ": "), sal_detail_stream, 0); }; std::abort(); break
; } } } while (false); } while (false)
760 "resolving stream " << streamType)do { css::uno::Any tools_warn_exception( DbgGetCaughtException
() ); do { if (true) { switch (sal_detail_log_report(::SAL_DETAIL_LOG_LEVEL_INFO
, "writerfilter.ooxml")) { case SAL_DETAIL_LOG_ACTION_IGNORE:
break; case SAL_DETAIL_LOG_ACTION_LOG: if (sizeof ::sal::detail
::getResult( ::sal::detail::StreamStart() << "resolveEmbeddingsStream: can't find header/footer whilst "
"resolving stream " << streamType << " " <<
exceptionToString(tools_warn_exception)) == 1) { ::sal_detail_log
( (::SAL_DETAIL_LOG_LEVEL_INFO), ("writerfilter.ooxml"), ("/home/maarten/src/libreoffice/core/writerfilter/source/ooxml/OOXMLDocumentImpl.cxx"
":" "760" ": "), ::sal::detail::unwrapStream( ::sal::detail::
StreamStart() << "resolveEmbeddingsStream: can't find header/footer whilst "
"resolving stream " << streamType << " " <<
exceptionToString(tools_warn_exception)), 0); } else { ::std
::ostringstream sal_detail_stream; sal_detail_stream <<
"resolveEmbeddingsStream: can't find header/footer whilst " "resolving stream "
<< streamType << " " << exceptionToString(
tools_warn_exception); ::sal::detail::log( (::SAL_DETAIL_LOG_LEVEL_INFO
), ("writerfilter.ooxml"), ("/home/maarten/src/libreoffice/core/writerfilter/source/ooxml/OOXMLDocumentImpl.cxx"
":" "760" ": "), sal_detail_stream, 0); }; break; case SAL_DETAIL_LOG_ACTION_FATAL
: if (sizeof ::sal::detail::getResult( ::sal::detail::StreamStart
() << "resolveEmbeddingsStream: can't find header/footer whilst "
"resolving stream " << streamType << " " <<
exceptionToString(tools_warn_exception)) == 1) { ::sal_detail_log
( (::SAL_DETAIL_LOG_LEVEL_INFO), ("writerfilter.ooxml"), ("/home/maarten/src/libreoffice/core/writerfilter/source/ooxml/OOXMLDocumentImpl.cxx"
":" "760" ": "), ::sal::detail::unwrapStream( ::sal::detail::
StreamStart() << "resolveEmbeddingsStream: can't find header/footer whilst "
"resolving stream " << streamType << " " <<
exceptionToString(tools_warn_exception)), 0); } else { ::std
::ostringstream sal_detail_stream; sal_detail_stream <<
"resolveEmbeddingsStream: can't find header/footer whilst " "resolving stream "
<< streamType << " " << exceptionToString(
tools_warn_exception); ::sal::detail::log( (::SAL_DETAIL_LOG_LEVEL_INFO
), ("writerfilter.ooxml"), ("/home/maarten/src/libreoffice/core/writerfilter/source/ooxml/OOXMLDocumentImpl.cxx"
":" "760" ": "), sal_detail_stream, 0); }; std::abort(); break
; } } } while (false); } while (false)
;
761 return;
762 }
763 }
764
765 beans::PropertyValue embeddingsTemp;
766 // This will add all .xlsx and .bin to grabbag list.
767 if(bFound && mxEmbeddings.is())
768 {
769 embeddingsTemp.Name = embeddingsTarget;
770 embeddingsTemp.Value <<= mxEmbeddings;
771 aEmbeddings.push_back(embeddingsTemp);
772 mxEmbeddings.clear();
773 }
774 bFound = false;
775 bHeaderFooterFound = false;
776 }
777 }
778 }
779 if (!aEmbeddings.empty())
780 mxEmbeddingsList = comphelper::containerToSequence(aEmbeddings);
781}
782
783uno::Reference<xml::dom::XDocument> OOXMLDocumentImpl::getGlossaryDocDom( )
784{
785 return mxGlossaryDocDom;
786}
787
788uno::Sequence<uno::Sequence< uno::Any> > OOXMLDocumentImpl::getGlossaryDomList()
789{
790 return mxGlossaryDomList;
791}
792
793uno::Reference<io::XInputStream> OOXMLDocumentImpl::getInputStreamForId(const OUString & rId)
794{
795 OOXMLStream::Pointer_t pStream(OOXMLDocumentFactory::createStream(mpStream, rId));
796
797 return pStream->getDocumentStream();
798}
799
800void OOXMLDocumentImpl::setModel(uno::Reference<frame::XModel> xModel)
801{
802 mxModel.set(xModel);
803}
804
805uno::Reference<frame::XModel> OOXMLDocumentImpl::getModel()
806{
807 return mxModel;
808}
809
810void OOXMLDocumentImpl::setDrawPage(uno::Reference<drawing::XDrawPage> xDrawPage)
811{
812 mxDrawPage.set(xDrawPage);
813}
814
815uno::Reference<drawing::XDrawPage> OOXMLDocumentImpl::getDrawPage()
816{
817 return mxDrawPage;
818}
819
820const uno::Sequence<beans::PropertyValue>& OOXMLDocumentImpl::getMediaDescriptor() const
821{
822 return maMediaDescriptor;
823}
824
825void OOXMLDocumentImpl::setShapeContext( uno::Reference<xml::sax::XFastShapeContextHandler> xContext )
826{
827 if (!maShapeContexts.empty())
828 maShapeContexts.top() = xContext;
829}
830
831uno::Reference<xml::sax::XFastShapeContextHandler> OOXMLDocumentImpl::getShapeContext( )
832{
833 if (!maShapeContexts.empty())
834 return maShapeContexts.top();
835 else
836 return uno::Reference<xml::sax::XFastShapeContextHandler>();
837}
838
839void OOXMLDocumentImpl::pushShapeContext()
840{
841 maShapeContexts.push(uno::Reference<xml::sax::XFastShapeContextHandler>());
842}
843
844void OOXMLDocumentImpl::popShapeContext()
845{
846 if (!maShapeContexts.empty())
847 maShapeContexts.pop();
848}
849
850uno::Reference<xml::dom::XDocument> OOXMLDocumentImpl::getThemeDom( )
851{
852 return mxThemeDom;
853}
854
855uno::Sequence<uno::Reference<xml::dom::XDocument> > OOXMLDocumentImpl::getCustomXmlDomList( )
856{
857 return mxCustomXmlDomList;
858}
859
860uno::Sequence<uno::Reference<xml::dom::XDocument> > OOXMLDocumentImpl::getCustomXmlDomPropsList( )
861{
862 return mxCustomXmlDomPropsList;
863}
864
865uno::Sequence<beans::PropertyValue > OOXMLDocumentImpl::getEmbeddingsList( )
866{
867 return mxEmbeddingsList;
868}
869
870OOXMLDocument *
871OOXMLDocumentFactory::createDocument
872(const OOXMLStream::Pointer_t& pStream,
873 const uno::Reference<task::XStatusIndicator>& xStatusIndicator,
874 bool mbSkipImages, const uno::Sequence<beans::PropertyValue>& rDescriptor)
875{
876 return new OOXMLDocumentImpl(pStream, xStatusIndicator, mbSkipImages, rDescriptor);
877}
878
879}
880
881/* vim:set shiftwidth=4 softtabstop=4 expandtab: */

/home/maarten/src/libreoffice/core/include/tools/ref.hxx

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#ifndef INCLUDED_TOOLS_REF_HXX
20#define INCLUDED_TOOLS_REF_HXX
21
22#include <sal/config.h>
23#include <cassert>
24#include <tools/toolsdllapi.h>
25#include <utility>
26
27/**
28 This implements similar functionality to boost::intrusive_ptr
29*/
30
31namespace tools {
32
33/** T must be a class that extends SvRefBase */
34template<typename T> class SAL_DLLPUBLIC_RTTI__attribute__ ((type_visibility("default"))) SvRef final {
35public:
36 SvRef(): pObj(nullptr) {}
37
38 SvRef(SvRef&& rObj) noexcept
39 {
40 pObj = rObj.pObj;
41 rObj.pObj = nullptr;
42 }
43
44 SvRef(SvRef const & rObj): pObj(rObj.pObj)
45 {
46 if (pObj != nullptr) pObj->AddNextRef();
47 }
48
49 SvRef(T * pObjP): pObj(pObjP)
50 {
51 if (pObj != nullptr) pObj->AddFirstRef();
52 }
53
54 ~SvRef()
55 {
56 if (pObj != nullptr) pObj->ReleaseRef();
18
Taking true branch
19
Use of memory after it is freed
57 }
58
59 void clear()
60 {
61 if (pObj != nullptr) {
62 T * pRefObj = pObj;
63 pObj = nullptr;
64 pRefObj->ReleaseRef();
65 }
66 }
67
68 SvRef & operator =(SvRef const & rObj)
69 {
70 if (rObj.pObj != nullptr) {
6
Taking false branch
71 rObj.pObj->AddNextRef();
72 }
73 T * pRefObj = pObj;
74 pObj = rObj.pObj;
75 if (pRefObj != nullptr) {
7
Taking true branch
76 pRefObj->ReleaseRef();
8
Calling 'SvRefBase::ReleaseRef'
15
Returning; memory was released
77 }
78 return *this;
79 }
80
81 SvRef & operator =(SvRef && rObj)
82 {
83 if (pObj != nullptr) {
84 pObj->ReleaseRef();
85 }
86 pObj = rObj.pObj;
87 rObj.pObj = nullptr;
88 return *this;
89 }
90
91 bool is() const { return pObj != nullptr; }
92
93 explicit operator bool() const { return is(); }
94
95 T * get() const { return pObj; }
96
97 T * operator ->() const { assert(pObj != nullptr)(static_cast <bool> (pObj != nullptr) ? void (0) : __assert_fail
("pObj != nullptr", "/home/maarten/src/libreoffice/core/include/tools/ref.hxx"
, 97, __extension__ __PRETTY_FUNCTION__))
; return pObj; }
98
99 T & operator *() const { assert(pObj != nullptr)(static_cast <bool> (pObj != nullptr) ? void (0) : __assert_fail
("pObj != nullptr", "/home/maarten/src/libreoffice/core/include/tools/ref.hxx"
, 99, __extension__ __PRETTY_FUNCTION__))
; return *pObj; }
100
101 bool operator ==(const SvRef<T> &rhs) const { return pObj == rhs.pObj; }
102 bool operator !=(const SvRef<T> &rhs) const { return !(*this == rhs); }
103
104private:
105 T * pObj;
106};
107
108/**
109 * This implements similar functionality to std::make_shared.
110 */
111template<typename T, typename... Args>
112SvRef<T> make_ref(Args&& ... args)
113{
114 return SvRef<T>(new T(std::forward<Args>(args)...));
115}
116
117}
118
119/** Classes that want to be referenced-counted via SvRef<T>, should extend this base class */
120class TOOLS_DLLPUBLIC__attribute__ ((visibility("default"))) SvRefBase
121{
122 // work around a clang 3.5 optimization bug: if the bNoDelete is *first*
123 // it mis-compiles "if (--nRefCount == 0)" and never deletes any object
124 unsigned int nRefCount : 31;
125 // the only reason this is not bool is because MSVC cannot handle mixed type bitfields
126 unsigned int bNoDelete : 1;
127
128protected:
129 virtual ~SvRefBase() COVERITY_NOEXCEPT_FALSE;
130
131public:
132 SvRefBase() : nRefCount(0), bNoDelete(1) {}
133 SvRefBase(const SvRefBase &) : nRefCount(0), bNoDelete(1) {}
134
135 SvRefBase & operator=(const SvRefBase &) { return *this; }
136
137 void RestoreNoDelete()
138 { bNoDelete = 1; }
139
140 void AddNextRef()
141 {
142 assert( nRefCount < (1 << 30) && "Do not add refs to dead objects" )(static_cast <bool> (nRefCount < (1 << 30) &&
"Do not add refs to dead objects") ? void (0) : __assert_fail
("nRefCount < (1 << 30) && \"Do not add refs to dead objects\""
, "/home/maarten/src/libreoffice/core/include/tools/ref.hxx",
142, __extension__ __PRETTY_FUNCTION__))
;
143 ++nRefCount;
144 }
145
146 void AddFirstRef()
147 {
148 assert( nRefCount < (1 << 30) && "Do not add refs to dead objects" )(static_cast <bool> (nRefCount < (1 << 30) &&
"Do not add refs to dead objects") ? void (0) : __assert_fail
("nRefCount < (1 << 30) && \"Do not add refs to dead objects\""
, "/home/maarten/src/libreoffice/core/include/tools/ref.hxx",
148, __extension__ __PRETTY_FUNCTION__))
;
149 if( bNoDelete )
150 bNoDelete = 0;
151 ++nRefCount;
152 }
153
154 void ReleaseRef()
155 {
156 assert( nRefCount >= 1)(static_cast <bool> (nRefCount >= 1) ? void (0) : __assert_fail
("nRefCount >= 1", "/home/maarten/src/libreoffice/core/include/tools/ref.hxx"
, 156, __extension__ __PRETTY_FUNCTION__))
;
9
Assuming field 'nRefCount' is >= 1
10
'?' condition is true
157 if( --nRefCount == 0 && !bNoDelete)
11
Assuming the condition is true
12
Assuming field 'bNoDelete' is 0
13
Taking true branch
158 {
159 // I'm not sure about the original purpose of this line, but right now
160 // it serves the purpose that anything that attempts to do an AddRef()
161 // after an object is deleted will trip an assert.
162 nRefCount = 1 << 30;
163 delete this;
14
Memory is released
164 }
165 }
166
167 unsigned int GetRefCount() const
168 { return nRefCount; }
169};
170
171template<typename T>
172class SvCompatWeakBase;
173
174/** SvCompatWeakHdl acts as an intermediary between SvCompatWeakRef<T> and T.
175*/
176template<typename T>
177class SvCompatWeakHdl final : public SvRefBase
178{
179 friend class SvCompatWeakBase<T>;
180 T* _pObj;
181
182 SvCompatWeakHdl( T* pObj ) : _pObj( pObj ) {}
183
184public:
185 void ResetWeakBase( ) { _pObj = nullptr; }
186 T* GetObj() { return _pObj; }
187};
188
189/** We only have one place that extends this, in include/sfx2/frame.hxx, class SfxFrame.
190 Its function is to notify the SvCompatWeakHdl when an SfxFrame object is deleted.
191*/
192template<typename T>
193class SvCompatWeakBase
194{
195 tools::SvRef< SvCompatWeakHdl<T> > _xHdl;
196
197public:
198 /** Does not use initializer due to compiler warnings,
199 because the lifetime of the _xHdl object can exceed the lifetime of this class.
200 */
201 SvCompatWeakBase( T* pObj ) { _xHdl = new SvCompatWeakHdl<T>( pObj ); }
202
203 ~SvCompatWeakBase() { _xHdl->ResetWeakBase(); }
204
205 SvCompatWeakHdl<T>* GetHdl() { return _xHdl.get(); }
206};
207
208/** We only have one weak reference in LO, in include/sfx2/frame.hxx, class SfxFrameWeak.
209*/
210template<typename T>
211class SAL_WARN_UNUSED__attribute__((warn_unused)) SvCompatWeakRef
212{
213 tools::SvRef< SvCompatWeakHdl<T> > _xHdl;
214public:
215 SvCompatWeakRef( ) {}
216 SvCompatWeakRef( T* pObj )
217 { if( pObj ) _xHdl = pObj->GetHdl(); }
218#if defined(__COVERITY__)
219 ~SvCompatWeakRef() COVERITY_NOEXCEPT_FALSE {}
220#endif
221 SvCompatWeakRef& operator = ( T * pObj )
222 { _xHdl = pObj ? pObj->GetHdl() : nullptr; return *this; }
223 bool is() const
224 { return _xHdl.is() && _xHdl->GetObj(); }
225 explicit operator bool() const { return is(); }
226 T* operator -> () const
227 { return _xHdl.is() ? _xHdl->GetObj() : nullptr; }
228 operator T* () const
229 { return _xHdl.is() ? _xHdl->GetObj() : nullptr; }
230};
231
232#endif
233
234/* vim:set shiftwidth=4 softtabstop=4 expandtab: */