LibreOffice Module oox (master)  1
xmlfilterbase.hxx
Go to the documentation of this file.
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 #ifndef INCLUDED_OOX_CORE_XMLFILTERBASE_HXX
21 #define INCLUDED_OOX_CORE_XMLFILTERBASE_HXX
22 
23 #include <memory>
24 #include <string_view>
25 #include <vector>
26 
27 #include <com/sun/star/uno/Reference.hxx>
28 #include <oox/core/filterbase.hxx>
29 #include <oox/core/relations.hxx>
30 #include <oox/dllapi.h>
32 #include <rtl/ustring.hxx>
33 #include <sal/types.h>
34 
35 namespace com::sun::star {
36  namespace document { class XDocumentProperties; }
37  namespace io { class XInputStream; }
38  namespace io { class XOutputStream; }
39  namespace io { class XStream; }
40  namespace text { class XText; }
41  namespace text { class XTextCursor; }
42  namespace text { class XTextField; }
43  namespace uno { class XComponentContext; }
44  namespace xml::dom { class XDocument; }
45  namespace xml::sax { class XFastSAXSerializable; }
46 }
47 
48 namespace oox {
49  namespace drawingml { class Theme; }
50  namespace drawingml::chart { class ChartConverter; }
51  namespace drawingml::table {
52  class TableStyleList;
53  typedef std::shared_ptr< TableStyleList > TableStyleListPtr;
54  }
55  namespace vml { class Drawing; }
56 }
57 
58 namespace rtl { template <class reference_type> class Reference; }
59 
60 namespace sax_fastparser {
62 
63  typedef std::shared_ptr< FastSerializerHelper > FSHelperPtr;
64 }
65 
66 namespace utl { class MediaDescriptor; }
67 
68 namespace oox::drawingml
69 {
70 class Shape;
71 }
72 
73 namespace oox::core {
74 
75 class FragmentHandler;
76 class FastParser;
77 
78 struct TextField {
79  css::uno::Reference< css::text::XText > xText;
80  css::uno::Reference< css::text::XTextCursor > xTextCursor;
81  css::uno::Reference< css::text::XTextField > xTextField;
82 };
83 typedef std::vector< TextField > TextFieldStack;
84 
85 struct XmlFilterBaseImpl;
86 
87 using ShapePairs
88  = std::map<std::shared_ptr<drawingml::Shape>, css::uno::Reference<css::drawing::XShape>>;
89 using NamedShapePairs = std::map<OUString, ShapePairs>;
90 
92 {
93 public:
95  explicit XmlFilterBase(
96  const css::uno::Reference< css::uno::XComponentContext >& rxContext );
97 
98  virtual ~XmlFilterBase() override;
99 
101  virtual const ::oox::drawingml::Theme* getCurrentTheme() const = 0;
102 
104  virtual ::oox::vml::Drawing* getVmlDrawing() = 0;
105 
108  virtual ::oox::drawingml::chart::ChartConverter* getChartConverter() = 0;
109 
111  virtual void useInternalChartDataTable( bool /*bInternal*/ ) { }
112 
115 
116 
117  OUString getFragmentPathFromFirstTypeFromOfficeDoc( std::u16string_view rPart );
118 
124  bool importFragment( const rtl::Reference<FragmentHandler>& rxHandler );
125  bool importFragment( const rtl::Reference<FragmentHandler>& rxHandler, FastParser& rParser );
126 
134  css::uno::Reference< css::xml::dom::XDocument> importFragment( const OUString& rFragmentPath );
135 
147  bool importFragment( const ::rtl::Reference< FragmentHandler >& rxHandler,
148  const css::uno::Reference< css::xml::sax::XFastSAXSerializable >& rxSerializer );
149 
154  RelationsRef importRelations( const OUString& rFragmentPath );
155 
166  OUString addRelation( const OUString& rType, std::u16string_view rTarget );
167 
181  OUString addRelation( const css::uno::Reference< css::io::XOutputStream >& rOutputStream, const OUString& rType, std::u16string_view rTarget, bool bExternal = false );
182 
184  TextFieldStack& getTextFieldStack() const;
185 
200  css::uno::Reference< css::io::XOutputStream >
201  openFragmentStream(
202  const OUString& rStreamName,
203  const OUString& rMediaType );
204 
221  openFragmentStreamWithSerializer(
222  const OUString& rStreamName,
223  const OUString& rMediaType );
224 
229  sal_Int32 GetUniqueId() { return mnMaxDocId++; }
230 
235  void exportDocumentProperties( const css::uno::Reference< css::document::XDocumentProperties >& xProperties, bool bSecurityOptOpenReadOnly );
236 
238  void exportCustomFragments();
239 
241  void importDocumentProperties();
242 
243  static void putPropertiesToDocumentGrabBag(const css::uno::Reference<css::lang::XComponent>& xDstDoc,
244  const comphelper::SequenceAsHashMap& rProperties);
245 
246  static FastParser* createParser();
247 
248  bool isMSO2007Document() const;
249  bool isMSODocument() const;
250 
253  void setMissingExtDrawing();
254 
255  void setDiagramFontHeights(NamedShapePairs* pDiagramFontHeights);
256  NamedShapePairs* getDiagramFontHeights();
257 
258  void checkDocumentProperties(
259  const css::uno::Reference<css::document::XDocumentProperties>& xDocProps);
260 
261  OUString getNamespaceURL(sal_Int32 nNSID) const;
262 
263 protected:
264  virtual css::uno::Reference< css::io::XInputStream >
265  implGetInputStream( utl::MediaDescriptor& rMediaDesc ) const override;
266 
267  virtual css::uno::Reference< css::io::XStream >
268  implGetOutputStream( utl::MediaDescriptor& rMediaDesc ) const override;
269 
270  virtual bool implFinalizeExport( utl::MediaDescriptor& rMediaDescriptor ) override;
271 
272 private:
273  virtual StorageRef implCreateStorage(
274  const css::uno::Reference< css::io::XInputStream >& rxInStream ) const override;
275  virtual StorageRef implCreateStorage(
276  const css::uno::Reference< css::io::XStream >& rxOutStream ) const override;
277 
278  void importCustomFragments(css::uno::Reference<css::embed::XStorage> const & xDocumentStorage);
279 
280 private:
281  ::std::unique_ptr< XmlFilterBaseImpl > mxImpl;
282  sal_Int32 mnRelId;
283  sal_Int32 mnMaxDocId;
284  bool mbMSO2007;
285  bool mbMSO;
286 protected:
288 };
289 
290 } // namespace oox::core
291 
292 #endif
293 
294 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
std::shared_ptr< Relations > RelationsRef
Definition: relations.hxx:63
virtual void useInternalChartDataTable(bool)
Helper to switch chart data table - specifically for xlsx imports.
exports com.sun.star. io
std::map< OUString, ShapePairs > NamedShapePairs
std::shared_ptr< TableStyleList > TableStyleListPtr
Reference
css::uno::Reference< css::text::XTextField > xTextField
std::shared_ptr< StorageBase > StorageRef
Definition: storagebase.hxx:42
sal_Int32 GetUniqueId()
Returns new unique ID for exported document.
static void importFragment(core::XmlFilterBase &rFilter, const uno::Reference< xml::dom::XDocument > &rXDom, const OUString &rDocName, const DiagramPtr &pDiagram, const rtl::Reference< core::FragmentHandler > &rxHandler)
Definition: diagram.cxx:186
Shape
::std::unique_ptr< XmlFilterBaseImpl > mxImpl
exports com.sun.star. text
std::vector< TextField > TextFieldStack
std::shared_ptr< FastSerializerHelper > FSHelperPtr
std::map< std::shared_ptr< drawingml::Shape >, css::uno::Reference< css::drawing::XShape >> ShapePairs
exports com.sun.star. document
css::uno::Reference< css::text::XText > xText
#define OOX_DLLPUBLIC
Definition: dllapi.h:28
Wrapper for a fast SAX parser that works on automatically generated OOXML token and namespace identif...
Definition: fastparser.hxx:53
css::uno::Reference< css::text::XTextCursor > xTextCursor