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 _SDXMLIMP_IMPL_HXX
25 #define _SDXMLIMP_IMPL_HXX
26 
27 #include <com/sun/star/drawing/XDrawPage.hpp>
28 #include <com/sun/star/frame/XModel.hpp>
29 #include <com/sun/star/task/XStatusIndicator.hpp>
30 #include <xmloff/xmltkmap.hxx>
31 #include <com/sun/star/container/XNameAccess.hpp>
32 
33 #ifndef __SGI_STL_VECTOR
34 #include <vector>
35 #endif
36 #include <xmloff/xmlimp.hxx>
37 
38 //////////////////////////////////////////////////////////////////////////////
39 
40 enum SdXMLDocElemTokenMap
41 {
42 	XML_TOK_DOC_FONTDECLS,
43 	XML_TOK_DOC_STYLES,
44 	XML_TOK_DOC_AUTOSTYLES,
45 	XML_TOK_DOC_MASTERSTYLES,
46 	XML_TOK_DOC_META,
47 	XML_TOK_DOC_BODY,
48 	XML_TOK_DOC_SCRIPT,
49 	XML_TOK_DOC_SETTINGS,
50 	XML_TOK_OFFICE_END = XML_TOK_UNKNOWN
51 };
52 
53 enum SdXMLBodyElemTokenMap
54 {
55 	XML_TOK_BODY_PAGE,
56 	XML_TOK_BODY_SETTINGS,
57 	XML_TOK_BODY_HEADER_DECL,
58 	XML_TOK_BODY_FOOTER_DECL,
59 	XML_TOK_BODY_DATE_TIME_DECL
60 };
61 
62 enum SdXMLStylesElemTokenMap
63 {
64 	XML_TOK_STYLES_MASTER_PAGE,
65 	XML_TOK_STYLES_STYLE,
66 	XML_TOK_STYLES_PAGE_MASTER,
67 	XML_TOK_STYLES_PRESENTATION_PAGE_LAYOUT
68 };
69 
70 enum SdXMLAutoStylesElemTokenMap
71 {
72 	XML_TOK_AUTOSTYLES_STYLE
73 };
74 
75 enum SdXMLMasterPageElemTokenMap
76 {
77 	XML_TOK_MASTERPAGE_STYLE,
78 	XML_TOK_MASTERPAGE_NOTES
79 };
80 
81 enum SdXMLMasterPageAttrTokenMap
82 {
83 	XML_TOK_MASTERPAGE_NAME,
84 	XML_TOK_MASTERPAGE_DISPLAY_NAME,
85 	XML_TOK_MASTERPAGE_PAGE_MASTER_NAME,
86 	XML_TOK_MASTERPAGE_STYLE_NAME,
87 	XML_TOK_MASTERPAGE_PAGE_LAYOUT_NAME,
88 	XML_TOK_MASTERPAGE_USE_HEADER_NAME,
89 	XML_TOK_MASTERPAGE_USE_FOOTER_NAME,
90 	XML_TOK_MASTERPAGE_USE_DATE_TIME_NAME
91 };
92 
93 enum SdXMLPageMasterAttrTokenMap
94 {
95 	XML_TOK_PAGEMASTER_NAME
96 };
97 
98 enum SdXMLPageMasterStyleAttrTokenMap
99 {
100 	XML_TOK_PAGEMASTERSTYLE_MARGIN_TOP,
101 	XML_TOK_PAGEMASTERSTYLE_MARGIN_BOTTOM,
102 	XML_TOK_PAGEMASTERSTYLE_MARGIN_LEFT,
103 	XML_TOK_PAGEMASTERSTYLE_MARGIN_RIGHT,
104 	XML_TOK_PAGEMASTERSTYLE_PAGE_WIDTH,
105 	XML_TOK_PAGEMASTERSTYLE_PAGE_HEIGHT,
106 	XML_TOK_PAGEMASTERSTYLE_PAGE_ORIENTATION
107 };
108 
109 enum SdXMLDocStyleAttrTokenMap
110 {
111 	XML_TOK_DOCSTYLE_NAME,
112 	XML_TOK_DOCSTYLE_FAMILY,
113 	XML_TOK_DOCSTYLE_PARENT_STYLE_NAME,
114 	XML_TOK_DOCSTYLE_AUTOMATIC
115 };
116 
117 enum SdXMLDocStyleElemTokenMap
118 {
119 	XML_TOK_DOCSTYLE_PROPERTIES,
120 	XML_TOK_DOCSTYLE_PRESENTATION_PLACEHOLDER
121 };
122 
123 enum SdXMLDrawPageAttrTokenMap
124 {
125 	XML_TOK_DRAWPAGE_NAME,
126 	XML_TOK_DRAWPAGE_STYLE_NAME,
127 	XML_TOK_DRAWPAGE_MASTER_PAGE_NAME,
128 	XML_TOK_DRAWPAGE_PAGE_LAYOUT_NAME,
129     XML_TOK_DRAWPAGE_DRAWID,
130     XML_TOK_DRAWPAGE_XMLID,
131 	XML_TOK_DRAWPAGE_HREF,
132 	XML_TOK_DRAWPAGE_USE_HEADER_NAME,
133 	XML_TOK_DRAWPAGE_USE_FOOTER_NAME,
134 	XML_TOK_DRAWPAGE_USE_DATE_TIME_NAME
135 };
136 
137 enum SdXMLDrawPageElemTokenMap
138 {
139 	XML_TOK_DRAWPAGE_NOTES,
140 	XML_TOK_DRAWPAGE_PAR,
141 	XML_TOK_DRAWPAGE_SEQ
142 };
143 
144 enum SdXMLPresentationPlaceholderAttrTokenMap
145 {
146 	XML_TOK_PRESENTATIONPLACEHOLDER_OBJECTNAME,
147 	XML_TOK_PRESENTATIONPLACEHOLDER_X,
148 	XML_TOK_PRESENTATIONPLACEHOLDER_Y,
149 	XML_TOK_PRESENTATIONPLACEHOLDER_WIDTH,
150 	XML_TOK_PRESENTATIONPLACEHOLDER_HEIGHT
151 };
152 
153 //////////////////////////////////////////////////////////////////////////////
154 
155 struct SdXMLltXDrawPageId
156 {
operator ()SdXMLltXDrawPageId157   bool operator()(sal_Int32 nId1, sal_Int32 nId2 ) const
158   {
159     return nId1 < nId2;
160   }
161 };
162 
163 typedef std::map< sal_Int32, com::sun::star::uno::Reference< com::sun::star::drawing::XDrawPage >, SdXMLltXDrawPageId > DrawPageIdMap;
164 
165 //////////////////////////////////////////////////////////////////////////////
166 
167 class SvXMLUnitConverter;
168 class SvXMLTokenMap;
169 class XMLSdPropHdlFactory;
170 class XMLPropertySetMapper;
171 class XMLPropStyleContext;
172 class SdXMLStylesContext;
173 class SdXMLMasterStylesContext;
174 
175 //////////////////////////////////////////////////////////////////////////////
176 
177 struct DateTimeDeclContextImpl
178 {
179 	rtl::OUString maStrText;
180 	sal_Bool mbFixed;
181 	rtl::OUString maStrDateTimeFormat;
182 
DateTimeDeclContextImplDateTimeDeclContextImpl183 	DateTimeDeclContextImpl() : mbFixed(sal_True) {}
184 };
185 
186 DECLARE_STL_USTRINGACCESS_MAP( ::rtl::OUString, HeaderFooterDeclMap );
187 DECLARE_STL_USTRINGACCESS_MAP( DateTimeDeclContextImpl, DateTimeDeclMap );
188 
189 //////////////////////////////////////////////////////////////////////////////
190 
191 class SdXMLImport: public SvXMLImport
192 {
193 	com::sun::star::uno::Reference< com::sun::star::container::XNameAccess > mxDocStyleFamilies;
194 	com::sun::star::uno::Reference< com::sun::star::container::XIndexAccess > mxDocMasterPages;
195 	com::sun::star::uno::Reference< com::sun::star::container::XIndexAccess > mxDocDrawPages;
196 	com::sun::star::uno::Reference< com::sun::star::container::XNameAccess > mxPageLayouts;
197 
198 	// contexts for Style and AutoStyle import
199 	SdXMLMasterStylesContext*	mpMasterStylesContext;
200 
201 	// token map lists
202 	SvXMLTokenMap*				mpDocElemTokenMap;
203 	SvXMLTokenMap*				mpBodyElemTokenMap;
204 	SvXMLTokenMap*				mpStylesElemTokenMap;
205 	SvXMLTokenMap*				mpAutoStylesElemTokenMap;
206 	SvXMLTokenMap*				mpMasterPageElemTokenMap;
207 	SvXMLTokenMap*				mpMasterPageAttrTokenMap;
208 	SvXMLTokenMap*				mpPageMasterAttrTokenMap;
209 	SvXMLTokenMap*				mpPageMasterStyleAttrTokenMap;
210 	SvXMLTokenMap*				mpDocStyleAttrTokenMap;
211 	SvXMLTokenMap*				mpDocStyleElemTokenMap;
212 	SvXMLTokenMap*				mpDrawPageAttrTokenMap;
213 	SvXMLTokenMap*				mpDrawPageElemTokenMap;
214 	SvXMLTokenMap*				mpPresentationPlaceholderAttrTokenMap;
215 
216 	sal_uInt16					mnStyleFamilyMask;
217 
218 	sal_Int32					mnNewPageCount;
219 	sal_Int32					mnNewMasterPageCount;
220 
221 	sal_Bool					mbIsDraw;
222 	sal_Bool					mbLoadDoc;
223 	sal_Bool					mbPreview;
224 
225 	DrawPageIdMap				maDrawPageIds;
226 
227 	::rtl::OUString				msPageLayouts;
228 	::rtl::OUString				msPreview;
229 
230 	HeaderFooterDeclMap			maHeaderDeclsMap;
231 	HeaderFooterDeclMap			maFooterDeclsMap;
232 	DateTimeDeclMap				maDateTimeDeclsMap;
233 
234 protected:
235 	// This method is called after the namespace map has been updated, but
236 	// before a context for the current element has been pushed.
237 	virtual SvXMLImportContext *CreateContext(sal_uInt16 nPrefix,
238 	  const rtl::OUString& rLocalName,
239 	  const com::sun::star::uno::Reference<
240 		com::sun::star::xml::sax::XAttributeList>& xAttrList);
241 
242 public:
243 	// #110680#
244 	SdXMLImport(
245 		const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& xServiceFactory,
246 		sal_Bool bIsDraw, sal_uInt16 nImportFlags = IMPORT_ALL );
247 	~SdXMLImport() throw ();
248 
249 	// XImporter
250 	virtual void SAL_CALL setTargetDocument( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XComponent >& xDoc ) throw(::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException);
251 
252 	// XInitialization
253     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);
254 
255 	void SetProgress(sal_Int32 nProg);
256 
257 	virtual void SetViewSettings(const com::sun::star::uno::Sequence<com::sun::star::beans::PropertyValue>& aViewProps);
258 	virtual void SetConfigurationSettings(const com::sun::star::uno::Sequence<com::sun::star::beans::PropertyValue>& aConfigProps);
259 
260 	// namespace office
261     // NB: in contrast to other CreateFooContexts, this particular one handles
262     //     the root element (i.e. office:document-meta)
263 	SvXMLImportContext* CreateMetaContext(const rtl::OUString& rLocalName,
264 		const com::sun::star::uno::Reference< com::sun::star::xml::sax::XAttributeList >& xAttrList);
265 	SvXMLImportContext* CreateScriptContext( const ::rtl::OUString& rLocalName );
266 	SvXMLImportContext* CreateBodyContext(const rtl::OUString& rLocalName,
267 		const com::sun::star::uno::Reference< com::sun::star::xml::sax::XAttributeList >& xAttrList);
268 	SvXMLStylesContext* CreateStylesContext(const rtl::OUString& rLocalName,
269 		const com::sun::star::uno::Reference< com::sun::star::xml::sax::XAttributeList >& xAttrList);
270 	SvXMLStylesContext* CreateAutoStylesContext(const rtl::OUString& rLocalName,
271 		const com::sun::star::uno::Reference< com::sun::star::xml::sax::XAttributeList >& xAttrList);
272 	SvXMLImportContext* CreateMasterStylesContext(const rtl::OUString& rLocalName,
273 		const com::sun::star::uno::Reference< com::sun::star::xml::sax::XAttributeList >& xAttrList);
274 	SvXMLImportContext *CreateFontDeclsContext(const ::rtl::OUString& rLocalName,
275 		const ::com::sun::star::uno::Reference<	::com::sun::star::xml::sax::XAttributeList > & xAttrList );
276 
277 	// Styles and AutoStyles contexts
GetMasterStylesContext() const278 	const SdXMLMasterStylesContext* GetMasterStylesContext() const { return mpMasterStylesContext; }
279 
GetStyleFamilyMask() const280 	sal_uInt16 GetStyleFamilyMask() const { return mnStyleFamilyMask; }
IsStylesOnlyMode() const281 	sal_Bool IsStylesOnlyMode() const { return !mbLoadDoc; }
282 
283 	const SvXMLTokenMap& GetDocElemTokenMap();
284 	const SvXMLTokenMap& GetBodyElemTokenMap();
285 	const SvXMLTokenMap& GetStylesElemTokenMap();
286 	const SvXMLTokenMap& GetMasterPageElemTokenMap();
287 	const SvXMLTokenMap& GetMasterPageAttrTokenMap();
288 	const SvXMLTokenMap& GetPageMasterAttrTokenMap();
289 	const SvXMLTokenMap& GetPageMasterStyleAttrTokenMap();
290 	const SvXMLTokenMap& GetDrawPageAttrTokenMap();
291 	const SvXMLTokenMap& GetDrawPageElemTokenMap();
292 	const SvXMLTokenMap& GetPresentationPlaceholderAttrTokenMap();
293 
294 	// export local parameters concerning page access and similar
295 	const com::sun::star::uno::Reference<
GetLocalDocStyleFamilies() const296 		com::sun::star::container::XNameAccess >& GetLocalDocStyleFamilies() const { return mxDocStyleFamilies; }
297 	const com::sun::star::uno::Reference<
GetLocalMasterPages() const298 		com::sun::star::container::XIndexAccess >& GetLocalMasterPages() const { return mxDocMasterPages; }
299 	const com::sun::star::uno::Reference<
GetLocalDrawPages() const300 		com::sun::star::container::XIndexAccess >& GetLocalDrawPages() const { return mxDocDrawPages; }
301 
GetNewPageCount() const302 	sal_Int32 GetNewPageCount() const { return mnNewPageCount; }
IncrementNewPageCount()303 	void IncrementNewPageCount() { mnNewPageCount++; }
GetNewMasterPageCount() const304 	sal_Int32 GetNewMasterPageCount() const { return mnNewMasterPageCount; }
IncrementNewMasterPageCount()305 	void IncrementNewMasterPageCount() { mnNewMasterPageCount++; }
306 
getPageLayouts() const307 	com::sun::star::uno::Reference< com::sun::star::container::XNameAccess > getPageLayouts() const { return mxPageLayouts; }
308 
IsDraw() const309 	sal_Bool IsDraw() const { return mbIsDraw; }
IsImpress() const310 	sal_Bool IsImpress() const { return !mbIsDraw; }
311 
312 	// import pool defaults. Parameter contains pool defaults read
313 	// from input data. These data needs to be set at the model.
314 	void ImportPoolDefaults(const XMLPropStyleContext* pPool);
315 
316 	// #80365#
317     virtual void SetStatistics(
318         const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::NamedValue> & i_rStats);
319 
IsPreview() const320 	sal_Bool IsPreview() const { return mbPreview; }
321 
322     // XServiceInfo ( : SvXMLExport )
323     virtual ::rtl::OUString SAL_CALL getImplementationName() throw( ::com::sun::star::uno::RuntimeException );
324 
325 	void AddHeaderDecl( const ::rtl::OUString& rName, const ::rtl::OUString& rText );
326 	void AddFooterDecl( const ::rtl::OUString& rName, const ::rtl::OUString& rText );
327 	void AddDateTimeDecl( const ::rtl::OUString& rName, const ::rtl::OUString& rText, sal_Bool bFixed, const ::rtl::OUString& rDateTimeFormat );
328 
329 	::rtl::OUString GetHeaderDecl( const ::rtl::OUString& rName ) const;
330 	::rtl::OUString GetFooterDecl( const ::rtl::OUString& rName ) const;
331 	::rtl::OUString GetDateTimeDecl( const ::rtl::OUString& rName, sal_Bool& rbFixed, ::rtl::OUString& rDateTimeFormat );
332 
333 };
334 
335 #endif	//  _SDXMLIMP_HXX
336