1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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>
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
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
{
77 enum StreamType_t
{ UNKNOWN
, DOCUMENT
, STYLES
, WEBSETTINGS
, FONTTABLE
, NUMBERING
,
78 FOOTNOTES
, ENDNOTES
, COMMENTS
, THEME
, CUSTOMXML
, CUSTOMXMLPROPS
, ACTIVEX
, ACTIVEXBIN
, GLOSSARY
, CHARTS
, EMBEDDINGS
, SETTINGS
, VBAPROJECT
, FOOTER
, HEADER
, SIGNATURE
};
79 typedef std::shared_ptr
<OOXMLStream
> Pointer_t
;
81 virtual ~OOXMLStream() {}
84 Returns parser for this stream.
86 virtual css::uno::Reference
<css::xml::sax::XParser
> getParser() = 0;
89 Returns fast parser for this stream.
91 virtual css::uno::Reference
<css::xml::sax::XFastParser
> getFastParser() = 0;
93 virtual css::uno::Reference
<css::io::XInputStream
> getDocumentStream() = 0;
95 virtual css::uno::Reference
<css::io::XInputStream
> getStorageStream() = 0;
98 Returns component context for this stream.
100 virtual css::uno::Reference
<css::uno::XComponentContext
> getContext() = 0;
103 Returns target URL from relationships for a given id.
105 @param rId the id to look for
107 @return the URL found or an empty string
109 virtual OUString
getTargetForId(const OUString
& rId
) = 0;
111 virtual const OUString
& getTarget() const = 0;
113 virtual css::uno::Reference
<css::xml::sax::XFastTokenHandler
>
114 getFastTokenHandler() = 0;
118 class OOXMLDocument
: public writerfilter::Reference
<Stream
>
122 Pointer to this stream.
124 typedef std::shared_ptr
<OOXMLDocument
> Pointer_t
;
126 virtual ~OOXMLDocument() {}
129 Resolves this document to a stream handler.
131 @param rStream stream handler to resolve this document to
133 virtual void resolve(Stream
& rStream
) SAL_OVERRIDE
= 0;
136 Resolves a footnote to a stream handler.
138 A footnote is resolved if either the note type or
141 @param rStream stream handler to resolve to
142 @param rNoteType type of footnote to resolve
143 @param rNoteId id of the footnote to resolve
145 virtual void resolveFootnote(Stream
& rStream
,
146 const Id
& rNoteType
,
147 const sal_Int32 nNoteId
) = 0;
149 Resolves an endnote to a stream handler.
151 An endnote is resolved if either the note type or
154 @param rStream stream handler to resolve to
155 @param rNoteType type of footnote to resolve
156 @param rNoteId id of the endnote to resolve
158 virtual void resolveEndnote(Stream
& rStream
,
159 const Id
& rNoteType
,
160 const sal_Int32 NoteId
) = 0;
163 Resolves a comment to a stream handler.
165 @param rStream stream handler to resolve to
166 @param rComment id of the comment to resolve
168 virtual void resolveComment(Stream
& rStream
,
169 const sal_Int32 nCommentId
) = 0;
172 Resolves a picture to a stream handler.
174 @param rStream stream handler to resolve to
175 @param rPictureId id of the picture to resolve
177 virtual void resolvePicture(Stream
& rStream
,
178 const OUString
& rPictureId
) = 0;
181 Resolves a header to a stream handler.
183 @param rStream stream handler to resolve to
184 @param type type of header to resolve:
185 NS_ooxml::LN_Value_ST_HrdFtr_even header on even page
186 NS_ooxml::LN_Value_ST_HrdFtr_default header on right page
187 NS_ooxml::LN_Value_ST_HrdFtr_first header on first page
189 @param rId id of the header
191 virtual void resolveHeader(Stream
& rStream
,
192 const sal_Int32 type
,
193 const OUString
& rId
) = 0;
196 Resolves a footer to a stream handler.
198 @param rStream stream handler to resolve to
199 @param type type of footer to resolve:
200 NS_ooxml::LN_Value_ST_HrdFtr_even header on even page
201 NS_ooxml::LN_Value_ST_HrdFtr_default header on right page
202 NS_ooxml::LN_Value_ST_HrdFtr_first header on first page
204 @param rId id of the header
206 virtual void resolveFooter(Stream
& rStream
,
207 const sal_Int32 type
,
208 const OUString
& rId
) = 0;
212 Returns target URL from relationships for a given id.
214 @param rId the id to look for
216 @return the URL found or an empty string
218 virtual OUString
getTargetForId(const OUString
& rId
) = 0;
220 virtual void setModel(css::uno::Reference
<css::frame::XModel
> xModel
) = 0;
221 virtual css::uno::Reference
<css::frame::XModel
> getModel() = 0;
222 virtual void setDrawPage(css::uno::Reference
<css::drawing::XDrawPage
> xDrawPage
) = 0;
223 virtual css::uno::Reference
<css::drawing::XDrawPage
> getDrawPage() = 0;
224 virtual css::uno::Reference
<css::io::XInputStream
> getInputStream() = 0;
225 virtual css::uno::Reference
<css::io::XInputStream
> getStorageStream() = 0;
226 virtual css::uno::Reference
<css::io::XInputStream
> getInputStreamForId(const OUString
& rId
) = 0;
227 virtual void setXNoteId(const sal_Int32 nId
) = 0;
228 virtual sal_Int32
getXNoteId() const = 0;
229 virtual void setXNoteType(const Id
& nId
) = 0;
230 virtual const Id
& getXNoteType() const = 0;
231 virtual const OUString
& getTarget() const = 0;
232 virtual css::uno::Reference
<css::xml::sax::XFastShapeContextHandler
> getShapeContext( ) = 0;
233 virtual void setShapeContext( css::uno::Reference
<css::xml::sax::XFastShapeContextHandler
> xContext
) = 0;
234 virtual css::uno::Reference
<css::xml::dom::XDocument
> getThemeDom( ) = 0;
235 virtual void setThemeDom( css::uno::Reference
<css::xml::dom::XDocument
> xThemeDom
) = 0;
236 virtual css::uno::Reference
<css::xml::dom::XDocument
> getGlossaryDocDom( ) = 0;
237 virtual css::uno::Sequence
<css::uno::Sequence
< css::uno::Any
> > getGlossaryDomList() = 0;
238 virtual css::uno::Sequence
<css::uno::Reference
<css::xml::dom::XDocument
> > getCustomXmlDomList( ) = 0;
239 virtual css::uno::Sequence
<css::uno::Reference
<css::xml::dom::XDocument
> > getCustomXmlDomPropsList( ) = 0;
240 virtual css::uno::Sequence
<css::uno::Reference
<css::xml::dom::XDocument
> > getActiveXDomList( ) = 0;
241 virtual css::uno::Sequence
<css::uno::Reference
<css::io::XInputStream
> > getActiveXBinList() = 0;
242 virtual css::uno::Sequence
<css::beans::PropertyValue
> getEmbeddingsList() = 0;
246 class OOXMLDocumentFactory
249 static OOXMLStream::Pointer_t
250 createStream(css::uno::Reference
<css::uno::XComponentContext
> rContext
,
251 css::uno::Reference
<css::io::XInputStream
> rStream
,
253 OOXMLStream::StreamType_t nStreamType
= OOXMLStream::DOCUMENT
);
255 static OOXMLStream::Pointer_t
256 createStream(OOXMLStream::Pointer_t pStream
,
257 OOXMLStream::StreamType_t nStreamType
= OOXMLStream::DOCUMENT
);
259 static OOXMLStream::Pointer_t
260 createStream(OOXMLStream::Pointer_t pStream
, const OUString
& rId
);
262 static OOXMLDocument
*
263 createDocument(OOXMLStream::Pointer_t pStream
,
264 const css::uno::Reference
<css::task::XStatusIndicator
>& xStatusIndicator
,
269 void ooxmlidsToXML(::std::iostream
& out
);
271 std::string
fastTokenToId(sal_uInt32 nToken
);
274 #endif // INCLUDED_WRITERFILTER_INC_OOXML_OOXMLDOCUMENT_HXX
276 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */