Line data Source code
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 SW_XMLIMP_HXX
21 : #define SW_XMLIMP_HXX
22 :
23 : #include <com/sun/star/document/XDocumentProperties.hpp>
24 :
25 : #include <sot/storage.hxx>
26 :
27 : #include <xmloff/xmlictxt.hxx>
28 : #include <xmloff/xmlimp.hxx>
29 :
30 : #include "xmlitmap.hxx"
31 :
32 : class SwDoc;
33 : class SvXMLUnitConverter;
34 : class SvXMLTokenMap;
35 : class SvXMLImportItemMapper;
36 : class SfxItemSet;
37 : class SwNodeIndex;
38 : class XMLTextImportHelper;
39 : class SvXMLGraphicHelper;
40 : class SvXMLEmbeddedObjectHelper;
41 :
42 : // define, how many steps ( = paragraphs ) the progress bar should advance
43 : // for styles, autostyles and settings + meta
44 : #define PROGRESS_BAR_STEP 20
45 :
46 : namespace SwImport {
47 : SwDoc* GetDocFromXMLImport( SvXMLImport& );
48 : }
49 :
50 : class SwXMLImport: public SvXMLImport
51 : {
52 : SwNodeIndex *pSttNdIdx;
53 :
54 : SvXMLUnitConverter *pTwipUnitConv;
55 : SvXMLImportItemMapper *pTableItemMapper;// paragraph item import
56 : SvXMLTokenMap *pDocElemTokenMap;
57 : SvXMLTokenMap *pTableElemTokenMap;
58 : SvXMLTokenMap *pTableCellAttrTokenMap;
59 : SvXMLGraphicHelper *pGraphicResolver;
60 : SvXMLEmbeddedObjectHelper *pEmbeddedResolver;
61 :
62 : SvXMLItemMapEntriesRef xTableItemMap;
63 : SvXMLItemMapEntriesRef xTableColItemMap;
64 : SvXMLItemMapEntriesRef xTableRowItemMap;
65 : SvXMLItemMapEntriesRef xTableCellItemMap;
66 : SvStorageRef xPackage;
67 : ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameContainer >
68 : xLateInitSettings;
69 :
70 : sal_uInt16 nStyleFamilyMask;// Mask of styles to load
71 : bool bLoadDoc : 1; // Load doc or styles only
72 : bool bInsert : 1; // Insert mode. If styles are
73 : // loaded only sal_False means that
74 : // existing styles will be
75 : // overwritten.
76 : bool bBlock : 1; // Load text block
77 : bool bShowProgress : 1;
78 : bool bOrganizerMode : 1;
79 : bool bInititedXForms : 1;
80 : sal_Bool bPreserveRedlineMode;
81 :
82 : SwDoc* doc; // cached for getDoc()
83 :
84 : void _InitItemImport();
85 : void _FinitItemImport();
86 : void UpdateTxtCollConditions( SwDoc *pDoc );
87 :
88 : void setTextInsertMode(
89 : const ::com::sun::star::uno::Reference<
90 : ::com::sun::star::text::XTextRange > & rInsertPos );
91 : void setStyleInsertMode( sal_uInt16 nFamilies,
92 : sal_Bool bOverwrite );
93 : void setBlockMode();
94 : void setOrganizerMode();
95 :
96 :
97 : protected:
98 :
99 : // This method is called after the namespace map has been updated, but
100 : // before a context for the current element has been pushed.
101 : virtual SvXMLImportContext *CreateContext( sal_uInt16 nPrefix,
102 : const OUString& rLocalName,
103 : const ::com::sun::star::uno::Reference<
104 : ::com::sun::star::xml::sax::XAttributeList > & xAttrList );
105 :
106 : virtual XMLTextImportHelper* CreateTextImport();
107 :
108 : virtual XMLShapeImportHelper* CreateShapeImport();
109 :
110 : public:
111 : SwXMLImport(
112 : const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext > xContext,
113 : sal_uInt16 nImportFlags = IMPORT_ALL);
114 :
115 : ~SwXMLImport() throw();
116 :
117 : // ::com::sun::star::xml::sax::XDocumentHandler
118 : virtual void SAL_CALL startDocument(void)
119 : throw( ::com::sun::star::xml::sax::SAXException, ::com::sun::star::uno::RuntimeException );
120 : virtual void SAL_CALL endDocument(void)
121 : throw( ::com::sun::star::xml::sax::SAXException, ::com::sun::star::uno::RuntimeException );
122 :
123 : // XUnoTunnel
124 : static const ::com::sun::star::uno::Sequence< sal_Int8 > & getUnoTunnelId() throw();
125 : virtual sal_Int64 SAL_CALL getSomething( const ::com::sun::star::uno::Sequence< sal_Int8 >& aIdentifier ) throw(::com::sun::star::uno::RuntimeException);
126 :
127 : // XInitialization
128 : 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);
129 :
130 : // XServiceInfo (override parent method)
131 : OUString SAL_CALL getImplementationName()
132 : throw( ::com::sun::star::uno::RuntimeException );
133 :
134 : void InsertStyles( sal_Bool bAuto );
135 : void FinishStyles();
136 :
137 : // namespace office
138 :
139 : // NB: in contrast to other CreateFooContexts, this particular one handles
140 : // the root element (i.e. office:document-meta)
141 : SvXMLImportContext *CreateMetaContext( const OUString& rLocalName );
142 : SvXMLImportContext *CreateScriptContext( const OUString& rLocalName );
143 : SvXMLImportContext *CreateStylesContext(
144 : const OUString& rLocalName,
145 : const ::com::sun::star::uno::Reference<
146 : ::com::sun::star::xml::sax::XAttributeList > & xAttrList,
147 : sal_Bool bAuto );
148 : SvXMLImportContext *CreateMasterStylesContext(
149 : const OUString& rLocalName,
150 : const ::com::sun::star::uno::Reference<
151 : ::com::sun::star::xml::sax::XAttributeList > & xAttrList );
152 : SvXMLImportContext *CreateFontDeclsContext(
153 : const OUString& rLocalName,
154 : const ::com::sun::star::uno::Reference<
155 : ::com::sun::star::xml::sax::XAttributeList > & xAttrList );
156 : SvXMLImportContext *CreateBodyContentContext( const OUString& rLocalName );
157 2565 : sal_uInt16 GetStyleFamilyMask() const { return nStyleFamilyMask; }
158 1341 : bool IsInsertMode() const { return bInsert; }
159 1236 : bool IsStylesOnlyMode() const { return !bLoadDoc; }
160 927 : bool IsBlockMode() const { return bBlock; }
161 310 : bool IsOrganizerMode() const { return bOrganizerMode; }
162 :
163 : inline const SvXMLUnitConverter& GetTwipUnitConverter() const;
164 : inline const SvXMLImportItemMapper& GetTableItemMapper() const;
165 : inline SvXMLImportItemMapper& GetTableItemMapper();
166 : SvXMLImportContext *CreateTableItemImportContext( sal_uInt16 nPrefix,
167 : const OUString& rLocalName,
168 : const ::com::sun::star::uno::Reference<
169 : ::com::sun::star::xml::sax::XAttributeList > & xAttrList,
170 : sal_uInt16 nSubFamily, SfxItemSet& rItemSet );
171 :
172 : const SvXMLTokenMap& GetDocElemTokenMap();
173 : const SvXMLTokenMap& GetTableElemTokenMap();
174 : const SvXMLTokenMap& GetTableCellAttrTokenMap();
175 :
176 : bool FindAutomaticStyle( sal_uInt16 nFamily,
177 : const OUString& rName,
178 : const SfxItemSet **ppItemSet=0,
179 : OUString *pParent=0 ) const;
180 :
181 : virtual void SetStatistics(
182 : const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::NamedValue> & i_rStats);
183 : virtual void SetViewSettings(const com::sun::star::uno::Sequence<com::sun::star::beans::PropertyValue>& aViewProps);
184 : virtual void SetConfigurationSettings(const com::sun::star::uno::Sequence<com::sun::star::beans::PropertyValue>& aConfigProps);
185 : virtual void SetDocumentSpecificSettings(const OUString& _rSettingsGroupName,
186 : const com::sun::star::uno::Sequence<com::sun::star::beans::PropertyValue>& _rSettings);
187 :
188 : SvStorage *GetPackage() { return &xPackage; }
189 :
190 : void SetProgressValue( sal_Int32 nValue );
191 :
192 : // initialize XForms
193 : virtual void initXForms();
194 :
195 : // get the document properties, but only if they actually need importing
196 : ::com::sun::star::uno::Reference<
197 : ::com::sun::star::document::XDocumentProperties>
198 : GetDocumentProperties() const;
199 :
200 : virtual void NotifyEmbeddedFontRead() SAL_OVERRIDE;
201 :
202 : const SwDoc* getDoc() const;
203 : SwDoc* getDoc();
204 : };
205 :
206 53 : inline const SvXMLUnitConverter& SwXMLImport::GetTwipUnitConverter() const
207 : {
208 53 : return *pTwipUnitConv;
209 : }
210 :
211 : inline const SvXMLImportItemMapper& SwXMLImport::GetTableItemMapper() const
212 : {
213 : return *pTableItemMapper;
214 : }
215 :
216 53 : inline SvXMLImportItemMapper& SwXMLImport::GetTableItemMapper()
217 : {
218 53 : return *pTableItemMapper;
219 : }
220 :
221 : inline void SwXMLImport::SetProgressValue( sal_Int32 nValue )
222 : {
223 : if ( bShowProgress )
224 : GetProgressBarHelper()->SetValue(nValue);
225 : }
226 :
227 : #endif // _XMLIMP_HXX
228 :
229 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|