LibreOffice Module sw (master)  1
xmlimp.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_SW_SOURCE_FILTER_XML_XMLIMP_HXX
21 #define INCLUDED_SW_SOURCE_FILTER_XML_XMLIMP_HXX
22 
23 #include <sal/config.h>
24 
25 #include <memory>
26 
27 #include <com/sun/star/document/XDocumentProperties.hpp>
28 
29 #include <sot/storage.hxx>
30 
31 #include <xmloff/xmlictxt.hxx>
32 #include <xmloff/xmlimp.hxx>
33 
34 #include "xmlitmap.hxx"
35 #include <o3tl/typed_flags_set.hxx>
36 
37 class SwDoc;
38 class SvXMLUnitConverter;
39 class SvXMLTokenMap;
41 class SfxItemSet;
42 class SwNodeIndex;
44 class SvXMLGraphicHelper;
46 enum class SfxStyleFamily;
47 
48 // define, how many steps ( = paragraphs ) the progress bar should advance
49 // for styles, autostyles and settings + meta
50 #define PROGRESS_BAR_STEP 20
51 
52 namespace SwImport {
54 }
55 
56 // we only need this scoped enum to be flags here, in sw
57 namespace o3tl
58 {
59  template<> struct typed_flags<SfxStyleFamily> : is_typed_flags<SfxStyleFamily, 0xffff> {};
60 }
61 
62 class SwXMLImport: public SvXMLImport
63 {
64  std::unique_ptr<SwNodeIndex> m_pSttNdIdx;
65 
66  std::unique_ptr<SvXMLUnitConverter> m_pTwipUnitConv;
67  std::unique_ptr<SvXMLImportItemMapper> m_pTableItemMapper;// paragraph item import
68  std::unique_ptr<SvXMLTokenMap> m_pDocElemTokenMap;
69  std::unique_ptr<SvXMLTokenMap> m_pTableElemTokenMap;
70  std::unique_ptr<SvXMLTokenMap> m_pTableCellAttrTokenMap;
71 
73 
75 
80  css::uno::Reference< css::container::XNameContainer >
82 
83  SfxStyleFamily m_nStyleFamilyMask;// Mask of styles to load
84  bool m_bLoadDoc : 1; // Load doc or styles only
85  bool m_bInsert : 1; // Insert mode. If styles are
86  // loaded only false means that
87  // existing styles will be
88  // overwritten.
89  bool m_bBlock : 1; // Load text block
90  bool m_bOrganizerMode : 1;
92 
93  SwDoc* m_pDoc; // cached for getDoc()
94 
95  void InitItemImport();
96  void FinitItemImport();
97  void UpdateTextCollConditions( SwDoc *pDoc );
98 
99  void setTextInsertMode(
100  const css::uno::Reference< css::text::XTextRange > & rInsertPos );
101  void setStyleInsertMode( SfxStyleFamily nFamilies,
102  bool bOverwrite );
103 
104 protected:
105 
106  virtual SvXMLImportContext *CreateDocumentContext( sal_uInt16 nPrefix,
107  const OUString& rLocalName,
108  const css::uno::Reference< css::xml::sax::XAttributeList > & xAttrList ) override;
109 
110  virtual SvXMLImportContext *CreateFastContext( sal_Int32 nElement,
111  const ::css::uno::Reference< ::css::xml::sax::XFastAttributeList >& xAttrList ) override;
112 
113  virtual XMLTextImportHelper* CreateTextImport() override;
114 
115  virtual XMLShapeImportHelper* CreateShapeImport() override;
116 
117 public:
118  SwXMLImport(
119  const css::uno::Reference< css::uno::XComponentContext >& rContext,
120  OUString const & implementationName, SvXMLImportFlags nImportFlags);
121 
122  virtual ~SwXMLImport() throw() override;
123 
124  // css::xml::sax::XDocumentHandler
125  virtual void SAL_CALL startDocument() override;
126  virtual void SAL_CALL endDocument() override;
127 
128  // XUnoTunnel
129  static const css::uno::Sequence< sal_Int8 > & getUnoTunnelId() throw();
130  virtual sal_Int64 SAL_CALL getSomething( const css::uno::Sequence< sal_Int8 >& aIdentifier ) override;
131 
132  // XInitialization
133  virtual void SAL_CALL initialize( const css::uno::Sequence< css::uno::Any >& aArguments ) override;
134 
135  void InsertStyles( bool bAuto );
136  void FinishStyles();
137 
138  // namespace office
139 
140  // NB: in contrast to other CreateFooContexts, this particular one handles
141  // the root element (i.e. office:document-meta)
142  SvXMLImportContext *CreateMetaContext( const sal_Int32 nElement );
143  SvXMLImportContext *CreateScriptContext( const OUString& rLocalName );
145  const OUString& rLocalName,
146  const css::uno::Reference< css::xml::sax::XAttributeList > & xAttrList,
147  bool bAuto );
149  const OUString& rLocalName,
150  const css::uno::Reference< css::xml::sax::XAttributeList > & xAttrList );
152  const OUString& rLocalName,
153  const css::uno::Reference< css::xml::sax::XAttributeList > & xAttrList );
154  SvXMLImportContext *CreateBodyContentContext( const OUString& rLocalName );
156  bool IsInsertMode() const { return m_bInsert; }
157  bool IsStylesOnlyMode() const { return !m_bLoadDoc; }
158  bool IsBlockMode() const { return m_bBlock; }
159 
160  inline const SvXMLImportItemMapper& GetTableItemMapper() const;
163  const OUString& rLocalName,
164  const css::uno::Reference< css::xml::sax::XAttributeList > & xAttrList,
165  sal_uInt16 nSubFamily, SfxItemSet& rItemSet );
166 
170 
171  bool FindAutomaticStyle( sal_uInt16 nFamily,
172  const OUString& rName,
173  const SfxItemSet **ppItemSet ) const;
175 
176  virtual void SetStatistics(
177  const css::uno::Sequence< css::beans::NamedValue> & i_rStats) override;
178  virtual void SetViewSettings(const css::uno::Sequence<css::beans::PropertyValue>& aViewProps) override;
179  virtual void SetConfigurationSettings(const css::uno::Sequence<css::beans::PropertyValue>& aConfigProps) override;
180  virtual void SetDocumentSpecificSettings(const OUString& _rSettingsGroupName,
181  const css::uno::Sequence<css::beans::PropertyValue>& _rSettings) override;
182 
183  // initialize XForms
184  virtual void initXForms() override;
185 
186  // get the document properties, but only if they actually need importing
187  css::uno::Reference<css::document::XDocumentProperties>
188  GetDocumentProperties() const;
189 
190  virtual void NotifyEmbeddedFontRead() override;
191 
192  const SwDoc* getDoc() const;
193  SwDoc* getDoc();
194 };
195 
197 {
198  return *m_pTableItemMapper;
199 }
200 
202 {
203  return *m_pTableItemMapper;
204 }
205 
206 #endif // _XMLIMP_HXX
207 
208 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
rtl::Reference< SvXMLEmbeddedObjectHelper > m_xEmbeddedResolver
Definition: xmlimp.hxx:74
const SvXMLTokenMap & GetTableElemTokenMap()
Definition: xmltbli.cxx:152
std::unique_ptr< SwNodeIndex > m_pSttNdIdx
Definition: xmlimp.hxx:64
std::unique_ptr< SvXMLUnitConverter > m_pTwipUnitConv
Definition: xmlimp.hxx:66
const SwDoc * getDoc() const
Definition: xmlimp.cxx:1777
virtual void SetConfigurationSettings(const css::uno::Sequence< css::beans::PropertyValue > &aConfigProps) override
Definition: xmlimp.cxx:1311
std::unique_ptr< SvXMLTokenMap > m_pTableCellAttrTokenMap
Definition: xmlimp.hxx:70
void FinishStyles()
Definition: xmlfmt.cxx:975
rtl::Reference< SvXMLGraphicHelper > m_xGraphicStorageHandler
Definition: xmlimp.hxx:72
bool m_bLoadDoc
Definition: xmlimp.hxx:84
signed char sal_Int8
SvXMLItemMapEntriesRef m_xTableCellItemMap
Definition: xmlimp.hxx:79
bool IsBlockMode() const
Definition: xmlimp.hxx:158
Definition: doc.hxx:185
virtual XMLShapeImportHelper * CreateShapeImport() override
Definition: xmlimp.cxx:1216
SvXMLImportContext * CreateBodyContentContext(const OUString &rLocalName)
Definition: xmltext.cxx:69
css::uno::Reference< css::container::XNameContainer > m_xLateInitSettings
Definition: xmlimp.hxx:81
void setStyleInsertMode(SfxStyleFamily nFamilies, bool bOverwrite)
Definition: xmlimp.cxx:454
SwXMLImport(const css::uno::Reference< css::uno::XComponentContext > &rContext, OUString const &implementationName, SvXMLImportFlags nImportFlags)
Definition: xmlimp.cxx:415
std::unique_ptr< SvXMLTokenMap > m_pTableElemTokenMap
Definition: xmlimp.hxx:69
const SvXMLImportItemMapper & GetTableItemMapper() const
Definition: xmlimp.hxx:196
SvXMLItemMapEntriesRef m_xTableRowItemMap
Definition: xmlimp.hxx:78
SvXMLImportContext * CreateScriptContext(const OUString &rLocalName)
Definition: xmlscript.cxx:29
bool m_bInsert
Definition: xmlimp.hxx:85
bool m_bInititedXForms
Definition: xmlimp.hxx:91
SvXMLImportContext * CreateMasterStylesContext(const OUString &rLocalName, const css::uno::Reference< css::xml::sax::XAttributeList > &xAttrList)
Definition: xmlfmt.cxx:956
const SvXMLTokenMap & GetDocElemTokenMap()
Definition: xmlimp.cxx:360
virtual void SAL_CALL initialize(const css::uno::Sequence< css::uno::Any > &aArguments) override
Definition: xmlimp.cxx:1707
SvXMLImportContext * CreateTableItemImportContext(sal_uInt16 nPrefix, const OUString &rLocalName, const css::uno::Reference< css::xml::sax::XAttributeList > &xAttrList, sal_uInt16 nSubFamily, SfxItemSet &rItemSet)
Definition: xmlitemi.cxx:339
bool IsStylesOnlyMode() const
Definition: xmlimp.hxx:157
SvXMLImportFlags
virtual void SAL_CALL startDocument() override
Definition: xmlimp.cxx:495
virtual SvXMLImportContext * CreateDocumentContext(sal_uInt16 nPrefix, const OUString &rLocalName, const css::uno::Reference< css::xml::sax::XAttributeList > &xAttrList) override
Definition: xmlimp.cxx:368
SvXMLItemMapEntriesRef m_xTableItemMap
Definition: xmlimp.hxx:76
SfxStyleFamily
bool m_bOrganizerMode
Definition: xmlimp.hxx:90
bool m_bBlock
Definition: xmlimp.hxx:89
virtual SvXMLImportContext * CreateFastContext(sal_Int32 nElement, const ::css::uno::Reference< ::css::xml::sax::XFastAttributeList > &xAttrList) override
Definition: xmlimp.cxx:391
std::unique_ptr< SvXMLImportItemMapper > m_pTableItemMapper
Definition: xmlimp.hxx:67
void FinitItemImport()
Definition: xmlitemi.cxx:333
bool FindAutomaticStyle(sal_uInt16 nFamily, const OUString &rName, const SfxItemSet **ppItemSet) const
Definition: xmlfmt.cxx:1019
void UpdateTextCollConditions(SwDoc *pDoc)
Definition: xmlfmt.cxx:981
Marks a node in the document model.
Definition: ndindex.hxx:31
void InsertStyles(bool bAuto)
Definition: xmlfmt.cxx:967
std::unique_ptr< SvXMLTokenMap > m_pDocElemTokenMap
Definition: xmlimp.hxx:68
virtual void NotifyEmbeddedFontRead() override
Definition: xmlfonte.cxx:84
virtual void SetStatistics(const css::uno::Sequence< css::beans::NamedValue > &i_rStats) override
Definition: xmlmeta.cxx:107
SfxStyleFamily GetStyleFamilyMask() const
Definition: xmlimp.hxx:155
SfxStyleFamily m_nStyleFamilyMask
Definition: xmlimp.hxx:83
virtual sal_Int64 SAL_CALL getSomething(const css::uno::Sequence< sal_Int8 > &aIdentifier) override
Definition: xmlimp.cxx:472
css::uno::Reference< css::document::XDocumentProperties > GetDocumentProperties() const
Definition: xmlmeta.cxx:45
void MergeListsAtDocumentInsertPosition(SwDoc *pDoc)
Definition: xmlimp.cxx:1026
void InitItemImport()
Definition: xmlitemi.cxx:320
const SvXMLTokenMap & GetTableCellAttrTokenMap()
Definition: xmltbli.cxx:160
SvXMLImportContext * CreateStylesContext(const OUString &rLocalName, const css::uno::Reference< css::xml::sax::XAttributeList > &xAttrList, bool bAuto)
Definition: xmlfmt.cxx:940
virtual void SetDocumentSpecificSettings(const OUString &_rSettingsGroupName, const css::uno::Sequence< css::beans::PropertyValue > &_rSettings) override
Definition: xmlimp.cxx:1678
virtual void SAL_CALL endDocument() override
Definition: xmlimp.cxx:735
virtual ~SwXMLImport() override
Definition: xmlimp.cxx:430
SvXMLItemMapEntriesRef m_xTableColItemMap
Definition: xmlimp.hxx:77
void setTextInsertMode(const css::uno::Reference< css::text::XTextRange > &rInsertPos)
Definition: xmlimp.cxx:443
SwDoc * m_pDoc
Definition: xmlimp.hxx:93
virtual void SetViewSettings(const css::uno::Sequence< css::beans::PropertyValue > &aViewProps) override
Definition: xmlimp.cxx:1233
static const css::uno::Sequence< sal_Int8 > & getUnoTunnelId()
Definition: xmlimp.cxx:467
SvXMLImportContext * CreateMetaContext(const sal_Int32 nElement)
Definition: xmlmeta.cxx:57
SwDoc * GetDocFromXMLImport(SvXMLImport const &)
Definition: xmlimp.cxx:1728
virtual XMLTextImportHelper * CreateTextImport() override
Definition: xmlimp.cxx:1208
SvXMLImportContext * CreateFontDeclsContext(const OUString &rLocalName, const css::uno::Reference< css::xml::sax::XAttributeList > &xAttrList)
Definition: xmlimp.cxx:1221
virtual void initXForms() override
Definition: xmlimp.cxx:1740
bool IsInsertMode() const
Definition: xmlimp.hxx:156