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>
39#include <svx/strings.hrc>
57 : mpStream(
std::move(pStream))
60 , mbIsSubstream(false)
61 , mbSkipImages(bSkipImages)
63 , mnProgressLastPos(0)
64 , mnProgressCurrentPos(0)
66 , m_rBaseURL(
utl::MediaDescriptor(rDescriptor).getUnpackedValueOrDefault(
"DocumentBaseURL", OUString()))
67 , maMediaDescriptor(rDescriptor)
68 , mxGraphicMapper(graphic::GraphicMapper::
create(mpStream->getContext()))
85 catch (uno::Exception
const&)
88 "resolving stream " <<
nType);
104 xParser->setFastDocumentHandler(pDocHandler);
105 xParser->setTokenHandler(xTokenHandler);
109 if (xInputStream.is())
111 struct xml::sax::InputSource oInputSource;
112 oInputSource.aInputStream = xInputStream;
113 xParser->parseStream(oInputSource);
115 xInputStream->closeInput();
138 catch (uno::Exception
const&)
141 "importing stream " <<
nType);
146 if (xInputStream.is())
152 xRet = xDomBuilder->parse(xInputStream);
154 catch (uno::Exception
const&)
157 "parsing stream " <<
nType);
183 catch (uno::Exception
const&)
186 "importing stream " <<
nType);
192 if (!xcpInputStream.is())
202 xRelation = xDomBuilder->parse(xcpInputStream);
204 catch (uno::Exception
const&)
207 "parsing stream " <<
nType);
274 const sal_Int32 nNoteId)
282 case NS_ooxml::LN_Value_doc_ST_FtnEdn_separator:
283 case NS_ooxml::LN_Value_doc_ST_FtnEdn_continuationSeparator:
287 nId = NS_ooxml::LN_footnote;
296 const sal_Int32 nNoteId)
304 case NS_ooxml::LN_Value_doc_ST_FtnEdn_separator:
305 case NS_ooxml::LN_Value_doc_ST_FtnEdn_continuationSeparator:
309 nId = NS_ooxml::LN_endnote;
337(
const OUString & rId)
361 const OUString & rId)
370 return mpStream->getTargetForId(rId);
374 const sal_Int32 type,
375 const OUString & rId)
381 case NS_ooxml::LN_Value_ST_HdrFtr_even:
384 case NS_ooxml::LN_Value_ST_HdrFtr_default:
387 case NS_ooxml::LN_Value_ST_HdrFtr_first:
396 const sal_Int32 type,
397 const OUString & rId)
404 case NS_ooxml::LN_Value_ST_HdrFtr_even:
407 case NS_ooxml::LN_Value_ST_HdrFtr_default:
410 case NS_ooxml::LN_Value_ST_HdrFtr_first:
420class StatusIndicatorGuard{
422 explicit StatusIndicatorGuard(css::uno::Reference<css::task::XStatusIndicator> xStatusIndicator)
427 ~StatusIndicatorGuard()
455 if (
aMap.find(
"ParagraphCount") !=
aMap.end())
465 OUString aDocLoad(
SvxResId(RID_SVXSTR_DOC_LOAD));
507 xParser->setFastDocumentHandler( pDocHandler );
508 xParser->setTokenHandler( xTokenHandler );
510 xml::sax::InputSource aParserInput;
511 aParserInput.sSystemId =
mpStream->getTarget();
512 aParserInput.aInputStream =
mpStream->getDocumentStream();
515 xParser->parseStream(aParserInput);
517 catch (xml::sax::SAXException
const& rErr)
525 Concat2View(
"SAXException: " + rErr.Message)))
528 catch (uno::RuntimeException
const&)
533 catch (uno::Exception
const&)
537 throw lang::WrappedTargetRuntimeException(
"",
nullptr, anyEx);
542 "OOXMLDocumentImpl::resolve(): non-UNO exception");
565 if (!xRelationshipAccess.is())
568 static const char sCustomType[] =
"http://schemas.openxmlformats.org/officeDocument/2006/relationships/customXml";
569 static const char sCustomTypeStrict[] =
"http://purl.oclc.org/ooxml/officeDocument/relationships/customXml";
572 std::vector<uno::Reference<xml::dom::XDocument>> aCustomXmlDomList;
573 std::vector<uno::Reference<xml::dom::XDocument>> aCustomXmlDomPropsList;
576 for (
const beans::StringPair& aPair :
aSeq)
580 if (aPair.Second == sCustomType ||
581 aPair.Second == sCustomTypeStrict)
583 else if (aPair.First ==
"Target" && bFound)
598 aCustomXmlDomList.push_back(customXmlTemp);
613const char sSettingsType[] =
"http://schemas.openxmlformats.org/officeDocument/2006/relationships/settings";
614const char sStylesType[] =
"http://schemas.openxmlformats.org/officeDocument/2006/relationships/styles";
615const char sFonttableType[] =
"http://schemas.openxmlformats.org/officeDocument/2006/relationships/fontTable";
616const char sWebSettings[] =
"http://schemas.openxmlformats.org/officeDocument/2006/relationships/webSettings";
617const char sSettingsTypeStrict[] =
"http://purl.oclc.org/ooxml/officeDocument/relationships/settings";
618const char sStylesTypeStrict[] =
"http://purl.oclc.org/ooxml/officeDocument/relationships/styles";
619const char sFonttableTypeStrict[] =
"http://purl.oclc.org/ooxml/officeDocument/relationships/fontTable";
620const char sWebSettingsStrict[] =
"http://purl.oclc.org/ooxml/officeDocument/relationships/webSettings";
622constexpr OUStringLiteral
sId =
u"Id";
623constexpr OUStringLiteral
sType =
u"Type";
624constexpr OUStringLiteral sTarget =
u"Target";
625constexpr OUStringLiteral sTargetMode =
u"TargetMode";
626constexpr OUStringLiteral sContentType =
u"_contentType";
627constexpr OUStringLiteral sRelDom =
u"_relDom";
628constexpr OUStringLiteral sSettingsContentType =
u"application/vnd.openxmlformats-officedocument.wordprocessingml.settings+xml";
629constexpr OUStringLiteral sStylesContentType =
u"application/vnd.openxmlformats-officedocument.wordprocessingml.styles+xml";
630constexpr OUStringLiteral sWebsettingsContentType =
u"application/vnd.openxmlformats-officedocument.wordprocessingml.webSettings+xml";
631constexpr OUStringLiteral sFonttableContentType =
u"application/vnd.openxmlformats-officedocument.wordprocessingml.fontTable+xml";
642 catch (uno::Exception
const&)
650 if (!xRelationshipAccess.is())
655 std::vector< uno::Sequence<beans::NamedValue> > aGlossaryDomList;
664 if (gType == sSettingsType || gType == sSettingsTypeStrict)
667 aRelDefinition.
put(sContentType, sSettingsContentType);
669 else if (gType == sStylesType || gType == sStylesTypeStrict)
672 aRelDefinition.
put(sContentType, sStylesContentType);
674 else if (gType == sWebSettings || gType == sWebSettingsStrict)
677 aRelDefinition.
put(sContentType, sWebsettingsContentType);
679 else if (gType == sFonttableType || gType == sFonttableTypeStrict)
682 aRelDefinition.
put(sContentType, sFonttableContentType);
684 else if (aRelDefinition.
getOrDefault(sTargetMode, OUString{}) !=
"External")
687 SAL_WARN(
"writerfilter.ooxml",
"Unknown type of glossary internal relation: "
689 "Type=\"" + gType +
"\" "
690 "Target=\"" + aRelDefinition.
getOrDefault<OUString>(sTarget, {}) +
"\"");
701 uno::Reference xDomBuilder(xml::dom::DocumentBuilder::create(xContext));
703 aRelDefinition.
put(sRelDom, xDom);
705 catch (uno::Exception
const&)
708 "parsing stream of Type" <<
nType);
720 if (xRelationshipAccess.is())
722 static constexpr OUStringLiteral sChartType(
u"http://schemas.openxmlformats.org/officeDocument/2006/relationships/chart");
723 static constexpr OUStringLiteral sChartTypeStrict(
u"http://purl.oclc.org/ooxml/officeDocument/relationships/chart");
724 static constexpr OUStringLiteral sFootersType(
u"http://schemas.openxmlformats.org/officeDocument/2006/relationships/footer");
725 static constexpr OUStringLiteral sFootersTypeStrict(
u"http://purl.oclc.org/ooxml/officeDocument/relationships/footer");
726 static constexpr OUStringLiteral sHeaderType(
u"http://schemas.openxmlformats.org/officeDocument/2006/relationships/header");
727 static constexpr OUStringLiteral sHeaderTypeStrict(
u"http://purl.oclc.org/ooxml/officeDocument/relationships/header");
730 bool bHeaderFooterFound =
false;
735 for (
const beans::StringPair& aPair :
aSeq)
737 if (aPair.Second == sChartType ||
738 aPair.Second == sChartTypeStrict)
742 else if(aPair.Second == sFootersType ||
743 aPair.Second == sFootersTypeStrict)
745 bHeaderFooterFound =
true;
748 else if(aPair.Second == sHeaderType ||
749 aPair.Second == sHeaderTypeStrict)
751 bHeaderFooterFound =
true;
754 else if(aPair.First ==
"Target" && ( bFound || bHeaderFooterFound ))
761 if( bFound || bHeaderFooterFound)
767 if(bHeaderFooterFound)
775 catch (uno::Exception
const&)
777 TOOLS_INFO_EXCEPTION(
"writerfilter.ooxml",
"resolveEmbeddingsStream: can't find header/footer whilst "
778 "resolving stream " << streamType);
783 beans::PropertyValue embeddingsTemp;
793 bHeaderFooterFound =
false;
815 return pStream->getDocumentStream();
908 return new OOXMLDocumentImpl(pStream, xStatusIndicator, mbSkipImages, rDescriptor);
css::uno::Reference< css::task::XStatusIndicator > mxStatusIndicator
OUString embeddingsTarget
bool IsContinueImportOnFilterExceptions(std::u16string_view aErrMessage)
static SfxObjectShell * GetShellFromComponent(const css::uno::Reference< css::uno::XInterface > &xComp)
bool put(const OUString &_rValueName, const VALUE_TYPE &_rValue)
css::uno::Sequence< css::beans::NamedValue > getNamedValues() const
VALUE_TYPE getOrDefault(const OUString &_rValueName, const VALUE_TYPE &_rDefault) const
tools::SvRef< Reference< T > > Pointer_t
Pointer to reference.
virtual void props(writerfilter::Reference< Properties >::Pointer_t ref)=0
Receives properties of the current run of text.
virtual void setDocumentReference(writerfilter::ooxml::OOXMLDocument *pDocument)=0
virtual void substream(Id name, writerfilter::Reference< Stream >::Pointer_t ref)=0
Receives a substream.
static OOXMLStream::Pointer_t createStream(const css::uno::Reference< css::uno::XComponentContext > &rContext, const css::uno::Reference< css::io::XInputStream > &rStream, bool bRepairStorage)
static OOXMLDocument * createDocument(const OOXMLStream::Pointer_t &pStream, const css::uno::Reference< css::task::XStatusIndicator > &xStatusIndicator, bool bSkipImage, const css::uno::Sequence< css::beans::PropertyValue > &rDescriptor)
virtual css::uno::Reference< css::frame::XModel > getModel() override
void resolveCustomXmlStream(Stream &rStream)
rtl::Reference< oox::drawingml::ThemeFilterBase > mxThemeFilterBase
css::uno::Reference< css::io::XInputStream > mxEmbeddings
css::uno::Sequence< css::uno::Sequence< css::beans::NamedValue > > mxGlossaryDomList
writerfilter::Reference< Stream >::Pointer_t getXNoteStream(OOXMLStream::StreamType_t nType, const sal_Int32 nNoteId)
css::uno::Reference< css::frame::XModel > mxModel
virtual void resolveFootnote(Stream &rStream, Id aType, const sal_Int32 nNoteId) override
Resolves a footnote to a stream handler.
virtual void setShapeContext(rtl::Reference< oox::shape::ShapeContextHandler > xContext) override
virtual void resolvePicture(Stream &rStream, const OUString &rId) override
Resolves a picture to a stream handler.
writerfilter::Reference< Stream >::Pointer_t mpXFootnoteStream
virtual void resolveHeader(Stream &rStream, const sal_Int32 type, const OUString &rId) override
Resolves a header to a stream handler.
writerfilter::Reference< Stream >::Pointer_t getSubStream(const OUString &rId)
const css::uno::Sequence< css::beans::PropertyValue > & getMediaDescriptor() const
OOXMLStream::Pointer_t mpStream
virtual void resolveEndnote(Stream &rStream, Id aType, const sal_Int32 nNoteId) override
Resolves an endnote to a stream handler.
virtual css::uno::Sequence< css::beans::PropertyValue > getEmbeddingsList() override
OOXMLPropertySet * getPicturePropSet(const OUString &rId)
virtual rtl::Reference< oox::shape::ShapeContextHandler > getShapeContext() override
virtual sal_Int32 getXNoteId() const override
css::uno::Reference< css::xml::dom::XDocument > importSubStream(OOXMLStream::StreamType_t nType)
virtual css::uno::Reference< css::io::XInputStream > getInputStreamForId(const OUString &rId) override
static void resolveFastSubStreamWithId(Stream &rStream, const writerfilter::Reference< Stream >::Pointer_t &pStream, sal_uInt32 nId)
void popShapeContext() override
Pop context of a previously pushed drawingML shape.
css::uno::Reference< css::xml::dom::XDocument > mxGlossaryDocDom
sal_Int32 mnProgressLastPos
Position progress when it was last updated, possibly not after every paragraph in case of large docum...
virtual css::uno::Sequence< css::uno::Reference< css::xml::dom::XDocument > > getCustomXmlDomPropsList() override
css::uno::Sequence< css::beans::PropertyValue > maMediaDescriptor
virtual void setDrawPage(css::uno::Reference< css::drawing::XDrawPage > xDrawPage) override
virtual OUString getTargetForId(const OUString &rId) override
Returns target URL from relationships for a given id.
virtual void resolve(Stream &rStream) override
Resolves this document to a stream handler.
css::uno::Sequence< css::uno::Reference< css::xml::dom::XDocument > > mxCustomXmlDomPropsList
virtual const oox::drawingml::ThemePtr & getTheme() const override
void resolveGlossaryStream(Stream &rStream)
const rtl::Reference< oox::shape::ShapeFilterBase > & getShapeFilterBase()
bool mbCommentsExtendedResolved
sal_Int32 mnProgressEndPos
End position, i.e. the estimated number of paragraphs.
virtual void resolveFooter(Stream &rStream, const sal_Int32 type, const OUString &rId) override
Resolves a footer to a stream handler.
virtual css::uno::Sequence< css::uno::Reference< css::xml::dom::XDocument > > getCustomXmlDomList() override
css::uno::Reference< css::drawing::XDrawPage > mxDrawPage
OOXMLDocumentImpl(OOXMLStream::Pointer_t pStream, css::uno::Reference< css::task::XStatusIndicator > xStatusIndicator, bool bSkipImages, const css::uno::Sequence< css::beans::PropertyValue > &rDescriptor)
virtual void setXNoteId(const sal_Int32 nId) override
void resolveFastSubStream(Stream &rStream, OOXMLStream::StreamType_t nType)
void importSubStreamRelations(const OOXMLStream::Pointer_t &pStream, OOXMLStream::StreamType_t nType)
sal_Int32 mnProgressCurrentPos
Current position progress, updated after every paragraph.
virtual void setModel(css::uno::Reference< css::frame::XModel > xModel) override
void resolveCommentsExtendedStream(Stream &rStream)
writerfilter::Reference< Stream >::Pointer_t mpXEndnoteStream
std::vector< css::beans::PropertyValue > m_aEmbeddings
css::uno::Reference< css::xml::dom::XDocument > mxCustomXmlProsDom
const rtl::Reference< oox::drawingml::ThemeFilterBase > & getThemeFilterBase()
virtual css::uno::Sequence< css::uno::Sequence< css::beans::NamedValue > > getGlossaryDomList() override
sal_Int32 mnPercentSize
How many paragraphs equal to 1 percent?
virtual css::uno::Reference< css::drawing::XDrawPage > getDrawPage() override
css::uno::Reference< css::task::XStatusIndicator > mxStatusIndicator
css::uno::Sequence< css::uno::Reference< css::xml::dom::XDocument > > mxCustomXmlDomList
void pushShapeContext() override
Push context of drawingML shapes, so nested shapes are handled separately.
virtual css::uno::Reference< css::xml::dom::XDocument > getThemeDom() override
virtual const OUString & getTarget() const override
css::uno::Sequence< css::beans::PropertyValue > mxEmbeddingsList
virtual void resolveComment(Stream &rStream, const sal_Int32 nId) override
Resolves a comment to a stream handler.
virtual ~OOXMLDocumentImpl() override
std::stack< rtl::Reference< oox::shape::ShapeContextHandler > > maShapeContexts
Stack of shape contexts, 1 element for VML, 1 element / nesting level for drawingML.
void resolveEmbeddingsStream(const OOXMLStream::Pointer_t &pStream)
css::uno::Reference< css::xml::dom::XDocument > mxThemeDom
rtl::Reference< oox::shape::ShapeFilterBase > mxShapeFilterBase
virtual css::uno::Reference< css::xml::dom::XDocument > getGlossaryDocDom() override
void add(const OOXMLProperty::Pointer_t &pProperty)
const css::uno::Reference< css::io::XStream > & accessDocumentStream()
OString exceptionToString(const css::uno::Any &caught)
#define TOOLS_WARN_EXCEPTION(area, stream)
#define TOOLS_INFO_EXCEPTION(area, stream)
SVXCORE_DLLPUBLIC OUString SvxResId(TranslateId aId)
Sequence< sal_Int8 > aSeq
#define SAL_WARN(area, stream)
css::uno::Sequence< DstElementType > containerToSequence(const SrcType &i_Container)
Any SAL_CALL getCaughtException()
css::uno::Reference< css::deployment::XPackageRegistry > create(css::uno::Reference< css::deployment::XPackageRegistry > const &xRootRegistry, OUString const &context, OUString const &cachePath, css::uno::Reference< css::uno::XComponentContext > const &xComponentContext)
HashMap_OWString_Interface aMap
Reference< XModel > xModel