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