Version 6.4.0.3, tag libreoffice-6.4.0.3
[LibreOffice.git] / writerfilter / inc / ooxml / OOXMLDocument.hxx
blob7856a6a4dcedd7eb93c4d59eda2f04c04b712499
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
19 #ifndef INCLUDED_WRITERFILTER_INC_OOXML_OOXMLDOCUMENT_HXX
20 #define INCLUDED_WRITERFILTER_INC_OOXML_OOXMLDOCUMENT_HXX
22 #include <sal/types.h>
23 #include <com/sun/star/uno/Reference.hxx>
24 #include <com/sun/star/io/XInputStream.hpp>
25 #include <com/sun/star/uno/XComponentContext.hpp>
26 #include <dmapper/resourcemodel.hxx>
27 #include <com/sun/star/task/XStatusIndicator.hpp>
28 #include <com/sun/star/xml/sax/XParser.hpp>
29 #include <com/sun/star/xml/sax/XFastParser.hpp>
30 #include <com/sun/star/xml/sax/XFastTokenHandler.hpp>
31 #include <com/sun/star/xml/sax/XFastShapeContextHandler.hpp>
32 #include <com/sun/star/xml/dom/XDocument.hpp>
33 #include <com/sun/star/frame/XModel.hpp>
34 #include <com/sun/star/drawing/XDrawPage.hpp>
36 /**
37 @file OOXMLDocument.hxx
39 <h1>Import of OOXML WordprocessingML Documents</h1>
41 The following picture shows the classes involved in importing OOXML
42 WordprocessingML documents.
44 @image html ooxmlimportchain.png
46 The DOCX consists of parts. Each part is an XML document. The
47 OOXMLDocument opens the DOCX and creates a SAX parser for the part
48 containing the main document content. The OOXMLDocument creates a
49 SAX handler, too. This handler is set as the handler for the events
50 created by the parser. Finally the OOXMLDocument initiates the
51 parsing process.
53 The SAX handler hosts a stack of contexts. Each context is an
54 instance of a class derived from OOXMLContext. There is a context
55 class for each <define> in the model.xml.
57 For a detailed information about how the contexts are handled see
58 the documentation for OOXMLContext.
60 The contexts know how to convert an element in OOXML to the
61 intermediate format that the domain mapper understands. They
62 enumerate the according entity in OOXML by sending the according
63 events to the domain mapper.
65 The domain mapper knows how to convert the intermediate format to
66 API calls. It takes the events sent by the contexts and uses the
67 core API to insert the according elements to the core.
70 namespace writerfilter {
71 namespace ooxml
74 class OOXMLStream : public virtual SvRefBase
76 public:
77 enum StreamType_t { UNKNOWN, DOCUMENT, STYLES, WEBSETTINGS, FONTTABLE, NUMBERING,
78 FOOTNOTES, ENDNOTES, COMMENTS, THEME, CUSTOMXML, CUSTOMXMLPROPS, GLOSSARY, CHARTS, EMBEDDINGS, SETTINGS, VBAPROJECT, FOOTER, HEADER, VBADATA };
79 typedef tools::SvRef<OOXMLStream> Pointer_t;
81 /**
82 Returns fast parser for this stream.
84 virtual css::uno::Reference<css::xml::sax::XFastParser> getFastParser() = 0;
86 virtual css::uno::Reference<css::io::XInputStream> getDocumentStream() = 0;
88 /**
89 Returns component context for this stream.
91 virtual css::uno::Reference<css::uno::XComponentContext> getContext() = 0;
93 /**
94 Returns target URL from relationships for a given id.
96 @param rId the id to look for
98 @return the URL found or an empty string
100 virtual OUString getTargetForId(const OUString & rId) = 0;
102 virtual const OUString & getTarget() const = 0;
104 virtual css::uno::Reference<css::xml::sax::XFastTokenHandler>
105 getFastTokenHandler() = 0;
109 class OOXMLDocument : public writerfilter::Reference<Stream>
111 public:
113 Pointer to this stream.
115 typedef tools::SvRef<OOXMLDocument> Pointer_t;
118 Resolves this document to a stream handler.
120 @param rStream stream handler to resolve this document to
122 virtual void resolve(Stream & rStream) override = 0;
125 Resolves a footnote to a stream handler.
127 A footnote is resolved if either the note type or
128 note id matches.
130 @param rStream stream handler to resolve to
131 @param rNoteType type of footnote to resolve
132 @param rNoteId id of the footnote to resolve
134 virtual void resolveFootnote(Stream & rStream,
135 Id aNoteType,
136 const sal_Int32 nNoteId) = 0;
138 Resolves an endnote to a stream handler.
140 An endnote is resolved if either the note type or
141 note id matches.
143 @param rStream stream handler to resolve to
144 @param rNoteType type of footnote to resolve
145 @param rNoteId id of the endnote to resolve
147 virtual void resolveEndnote(Stream & rStream,
148 Id aNoteType,
149 const sal_Int32 NoteId) = 0;
152 Resolves a comment to a stream handler.
154 @param rStream stream handler to resolve to
155 @param rComment id of the comment to resolve
157 virtual void resolveComment(Stream & rStream,
158 const sal_Int32 nCommentId) = 0;
161 Resolves a picture to a stream handler.
163 @param rStream stream handler to resolve to
164 @param rPictureId id of the picture to resolve
166 virtual void resolvePicture(Stream & rStream,
167 const OUString & rPictureId) = 0;
170 Resolves a header to a stream handler.
172 @param rStream stream handler to resolve to
173 @param type type of header to resolve:
174 NS_ooxml::LN_Value_ST_HrdFtr_even header on even page
175 NS_ooxml::LN_Value_ST_HrdFtr_default header on right page
176 NS_ooxml::LN_Value_ST_HrdFtr_first header on first page
178 @param rId id of the header
180 virtual void resolveHeader(Stream & rStream,
181 const sal_Int32 type,
182 const OUString & rId) = 0;
185 Resolves a footer to a stream handler.
187 @param rStream stream handler to resolve to
188 @param type type of footer to resolve:
189 NS_ooxml::LN_Value_ST_HrdFtr_even header on even page
190 NS_ooxml::LN_Value_ST_HrdFtr_default header on right page
191 NS_ooxml::LN_Value_ST_HrdFtr_first header on first page
193 @param rId id of the header
195 virtual void resolveFooter(Stream & rStream,
196 const sal_Int32 type,
197 const OUString & rId) = 0;
201 Returns target URL from relationships for a given id.
203 @param rId the id to look for
205 @return the URL found or an empty string
207 virtual OUString getTargetForId(const OUString & rId) = 0;
209 virtual void setModel(css::uno::Reference<css::frame::XModel> xModel) = 0;
210 virtual css::uno::Reference<css::frame::XModel> getModel() = 0;
211 virtual void setDrawPage(css::uno::Reference<css::drawing::XDrawPage> xDrawPage) = 0;
212 virtual css::uno::Reference<css::drawing::XDrawPage> getDrawPage() = 0;
213 virtual css::uno::Reference<css::io::XInputStream> getInputStreamForId(const OUString & rId) = 0;
214 virtual void setXNoteId(const sal_Int32 nId) = 0;
215 virtual sal_Int32 getXNoteId() const = 0;
216 virtual const OUString & getTarget() const = 0;
217 virtual css::uno::Reference<css::xml::sax::XFastShapeContextHandler> getShapeContext( ) = 0;
218 virtual void setShapeContext( css::uno::Reference<css::xml::sax::XFastShapeContextHandler> xContext ) = 0;
219 /// Push context of drawingML shapes, so nested shapes are handled separately.
220 virtual void pushShapeContext() = 0;
221 /// Pop context of a previously pushed drawingML shape.
222 virtual void popShapeContext() = 0;
223 virtual css::uno::Reference<css::xml::dom::XDocument> getThemeDom( ) = 0;
224 virtual css::uno::Reference<css::xml::dom::XDocument> getGlossaryDocDom( ) = 0;
225 virtual css::uno::Sequence<css::uno::Sequence< css::uno::Any> > getGlossaryDomList() = 0;
226 virtual css::uno::Sequence<css::uno::Reference<css::xml::dom::XDocument> > getCustomXmlDomList( ) = 0;
227 virtual css::uno::Sequence<css::uno::Reference<css::xml::dom::XDocument> > getCustomXmlDomPropsList( ) = 0;
228 virtual css::uno::Sequence<css::beans::PropertyValue > getEmbeddingsList() = 0;
232 class OOXMLDocumentFactory
234 public:
235 static OOXMLStream::Pointer_t
236 createStream(const css::uno::Reference<css::uno::XComponentContext>& rContext,
237 const css::uno::Reference<css::io::XInputStream>& rStream,
238 bool bRepairStorage);
240 static OOXMLStream::Pointer_t
241 createStream(const OOXMLStream::Pointer_t& pStream,
242 OOXMLStream::StreamType_t nStreamType);
244 static OOXMLStream::Pointer_t
245 createStream(const OOXMLStream::Pointer_t& pStream, const OUString & rId);
247 static OOXMLDocument *
248 createDocument(const OOXMLStream::Pointer_t& pStream,
249 const css::uno::Reference<css::task::XStatusIndicator>& xStatusIndicator,
250 bool bSkipImage, const css::uno::Sequence<css::beans::PropertyValue>& rDescriptor);
254 std::string fastTokenToId(sal_uInt32 nToken);
257 #endif // INCLUDED_WRITERFILTER_INC_OOXML_OOXMLDOCUMENT_HXX
259 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */