1 /**************************************************************
2 *
3 * Licensed to the Apache Software Foundation (ASF) under one
4 * or more contributor license agreements. See the NOTICE file
5 * distributed with this work for additional information
6 * regarding copyright ownership. The ASF licenses this file
7 * to you under the Apache License, Version 2.0 (the
8 * "License"); you may not use this file except in compliance
9 * with the License. You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing,
14 * software distributed under the License is distributed on an
15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 * KIND, either express or implied. See the License for the
17 * specific language governing permissions and limitations
18 * under the License.
19 *
20 *************************************************************/
21
22
23
24 #ifndef SW_XMLIMP_HXX
25 #define SW_XMLIMP_HXX
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
36 class SwDoc;
37 class SwPaM;
38 class SvXMLUnitConverter;
39 class SvXMLTokenMap;
40 class SvXMLImportItemMapper;
41 class SfxItemSet;
42 class SwNodeIndex;
43 class XMLTextImportHelper;
44 class SvXMLGraphicHelper;
45 class SvXMLEmbeddedObjectHelper;
46
47 // define, how many steps ( = paragraphs ) the progress bar should advance
48 // for styles, autostyles and settings + meta
49 #define PROGRESS_BAR_STEP 20
50
51 namespace SwImport {
52 SwDoc* GetDocFromXMLImport( SvXMLImport& );
53 }
54
55 class SwXMLImport: public SvXMLImport
56 {
57 SwNodeIndex *pSttNdIdx;
58
59 SvXMLUnitConverter *pTwipUnitConv;
60 SvXMLImportItemMapper *pTableItemMapper;// paragraph item import
61 SvXMLTokenMap *pDocElemTokenMap;
62 SvXMLTokenMap *pTableElemTokenMap;
63 SvXMLTokenMap *pTableCellAttrTokenMap;
64 SvXMLGraphicHelper *pGraphicResolver;
65 SvXMLEmbeddedObjectHelper *pEmbeddedResolver;
66
67 SvXMLItemMapEntriesRef xTableItemMap;
68 SvXMLItemMapEntriesRef xTableColItemMap;
69 SvXMLItemMapEntriesRef xTableRowItemMap;
70 SvXMLItemMapEntriesRef xTableCellItemMap;
71 SvStorageRef xPackage;
72 ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameContainer >
73 xLateInitSettings;
74
75 sal_uInt16 nStyleFamilyMask;// Mask of styles to load
76 sal_Bool bLoadDoc : 1; // Load doc or styles only
77 sal_Bool bInsert : 1; // Insert mode. If styles are
78 // loaded only sal_False means that
79 // existing styles will be
80 // overwritten.
81 sal_Bool bBlock : 1; // Load text block
82 sal_Bool bAutoStylesValid : 1;
83 sal_Bool bShowProgress : 1;
84 sal_Bool bOrganizerMode : 1;
85 sal_Bool bInititedXForms : 1;
86 sal_Bool bPreserveRedlineMode;
87
88 void _InitItemImport();
89 void _FinitItemImport();
90 void UpdateTxtCollConditions( SwDoc *pDoc );
91
92 void setTextInsertMode(
93 const ::com::sun::star::uno::Reference<
94 ::com::sun::star::text::XTextRange > & rInsertPos );
95 void setStyleInsertMode( sal_uInt16 nFamilies,
96 sal_Bool bOverwrite );
97 void setBlockMode();
98 void setOrganizerMode();
99
100
101 protected:
102
103 // This method is called after the namespace map has been updated, but
104 // before a context for the current element has been pushed.
105 virtual SvXMLImportContext *CreateContext( sal_uInt16 nPrefix,
106 const ::rtl::OUString& rLocalName,
107 const ::com::sun::star::uno::Reference<
108 ::com::sun::star::xml::sax::XAttributeList > & xAttrList );
109
110 virtual XMLTextImportHelper* CreateTextImport();
111
112 virtual XMLShapeImportHelper* CreateShapeImport();
113
114 public:
115
116 // #110680#
117 SwXMLImport(
118 const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > xServiceFactory,
119 sal_uInt16 nImportFlags = IMPORT_ALL);
120
121 #ifdef XML_CORE_API
122 // #110680#
123 SwXMLImport(
124 const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > xServiceFactory,
125 SwDoc& rDoc,
126 const SwPaM& rPaM,
127 sal_Bool bLoadDoc,
128 sal_Bool bInsertMode,
129 sal_uInt16 nStyleFamMask,
130 const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XModel > & rModel,
131 const ::com::sun::star::uno::Reference< ::com::sun::star::document::XGraphicObjectResolver > &,
132 SvStorage *pPkg );
133 #endif
134
135 ~SwXMLImport() throw();
136
137 // ::com::sun::star::xml::sax::XDocumentHandler
138 virtual void SAL_CALL startDocument(void)
139 throw( ::com::sun::star::xml::sax::SAXException, ::com::sun::star::uno::RuntimeException );
140 virtual void SAL_CALL endDocument(void)
141 throw( ::com::sun::star::xml::sax::SAXException, ::com::sun::star::uno::RuntimeException );
142
143 // XUnoTunnel
144 static const ::com::sun::star::uno::Sequence< sal_Int8 > & getUnoTunnelId() throw();
145 virtual sal_Int64 SAL_CALL getSomething( const ::com::sun::star::uno::Sequence< sal_Int8 >& aIdentifier ) throw(::com::sun::star::uno::RuntimeException);
146
147 // XInitialization
148 virtual void SAL_CALL initialize( const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any >& aArguments ) throw(::com::sun::star::uno::Exception, ::com::sun::star::uno::RuntimeException);
149
150 // XServiceInfo (override parent method)
151 ::rtl::OUString SAL_CALL getImplementationName()
152 throw( ::com::sun::star::uno::RuntimeException );
153
154 void InsertStyles( sal_Bool bAuto );
155 void FinishStyles();
156
157 // namespace office
158
159 // NB: in contrast to other CreateFooContexts, this particular one handles
160 // the root element (i.e. office:document-meta)
161 SvXMLImportContext *CreateMetaContext( const ::rtl::OUString& rLocalName );
162 SvXMLImportContext *CreateScriptContext( const ::rtl::OUString& rLocalName );
163 SvXMLImportContext *CreateStylesContext(
164 const ::rtl::OUString& rLocalName,
165 const ::com::sun::star::uno::Reference<
166 ::com::sun::star::xml::sax::XAttributeList > & xAttrList,
167 sal_Bool bAuto );
168 SvXMLImportContext *CreateMasterStylesContext(
169 const ::rtl::OUString& rLocalName,
170 const ::com::sun::star::uno::Reference<
171 ::com::sun::star::xml::sax::XAttributeList > & xAttrList );
172 SvXMLImportContext *CreateFontDeclsContext(
173 const ::rtl::OUString& rLocalName,
174 const ::com::sun::star::uno::Reference<
175 ::com::sun::star::xml::sax::XAttributeList > & xAttrList );
176 SvXMLImportContext *CreateBodyContentContext( const ::rtl::OUString& rLocalName );
GetStyleFamilyMask() const177 sal_uInt16 GetStyleFamilyMask() const { return nStyleFamilyMask; }
IsInsertMode() const178 sal_Bool IsInsertMode() const { return bInsert; }
IsStylesOnlyMode() const179 sal_Bool IsStylesOnlyMode() const { return !bLoadDoc; }
IsBlockMode() const180 sal_Bool IsBlockMode() const { return bBlock; }
IsOrganizerMode() const181 sal_Bool IsOrganizerMode() const { return bOrganizerMode; }
182
183 inline const SvXMLUnitConverter& GetTwipUnitConverter() const;
184 inline const SvXMLImportItemMapper& GetTableItemMapper() const;
185 inline SvXMLImportItemMapper& GetTableItemMapper();
186 SvXMLImportContext *CreateTableItemImportContext( sal_uInt16 nPrefix,
187 const ::rtl::OUString& rLocalName,
188 const ::com::sun::star::uno::Reference<
189 ::com::sun::star::xml::sax::XAttributeList > & xAttrList,
190 sal_uInt16 nSubFamily, SfxItemSet& rItemSet );
191
192 const SvXMLTokenMap& GetDocElemTokenMap();
193 const SvXMLTokenMap& GetTableElemTokenMap();
194 const SvXMLTokenMap& GetTableCellAttrTokenMap();
195
196 sal_Bool FindAutomaticStyle( sal_uInt16 nFamily,
197 const ::rtl::OUString& rName,
198 const SfxItemSet **ppItemSet=0,
199 ::rtl::OUString *pParent=0 ) const;
200
201 virtual void SetStatistics(
202 const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::NamedValue> & i_rStats);
203 virtual void SetViewSettings(const com::sun::star::uno::Sequence<com::sun::star::beans::PropertyValue>& aViewProps);
204 virtual void SetConfigurationSettings(const com::sun::star::uno::Sequence<com::sun::star::beans::PropertyValue>& aConfigProps);
205 virtual void SetDocumentSpecificSettings(const ::rtl::OUString& _rSettingsGroupName,
206 const com::sun::star::uno::Sequence<com::sun::star::beans::PropertyValue>& _rSettings);
207
GetPackage()208 SvStorage *GetPackage() { return &xPackage; }
209
210 void SetProgressValue( sal_Int32 nValue );
211
212 // initialize XForms
213 virtual void initXForms();
214
215 // get the document properties, but only if they actually need importing
216 ::com::sun::star::uno::Reference<
217 ::com::sun::star::document::XDocumentProperties>
218 GetDocumentProperties() const;
219 };
220
GetTwipUnitConverter() const221 inline const SvXMLUnitConverter& SwXMLImport::GetTwipUnitConverter() const
222 {
223 return *pTwipUnitConv;
224 }
225
GetTableItemMapper() const226 inline const SvXMLImportItemMapper& SwXMLImport::GetTableItemMapper() const
227 {
228 return *pTableItemMapper;
229 }
230
GetTableItemMapper()231 inline SvXMLImportItemMapper& SwXMLImport::GetTableItemMapper()
232 {
233 return *pTableItemMapper;
234 }
235
SetProgressValue(sal_Int32 nValue)236 inline void SwXMLImport::SetProgressValue( sal_Int32 nValue )
237 {
238 if ( bShowProgress )
239 GetProgressBarHelper()->SetValue(nValue);
240 }
241
242 #endif // _XMLIMP_HXX
243