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 : #include <com/sun/star/container/XIndexAccess.hpp>
21 : #include <com/sun/star/document/PrinterIndependentLayout.hpp>
22 : #include <com/sun/star/drawing/XDrawPage.hpp>
23 : #include <com/sun/star/drawing/XDrawPageSupplier.hpp>
24 : #include <com/sun/star/i18n/XForbiddenCharacters.hpp>
25 : #include <com/sun/star/text/XTextDocument.hpp>
26 : #include <com/sun/star/text/XTextRange.hpp>
27 :
28 : #include <xmloff/xmlnmspe.hxx>
29 : #include <xmloff/xmltkmap.hxx>
30 : #include <xmloff/xmlictxt.hxx>
31 : #include <xmloff/txtimp.hxx>
32 : #include <xmloff/nmspmap.hxx>
33 : #include <xmloff/XMLTextShapeImportHelper.hxx>
34 : #include <xmloff/XMLFontStylesContext.hxx>
35 : #include <xmloff/ProgressBarHelper.hxx>
36 : #include <doc.hxx>
37 : #include <TextCursorHelper.hxx>
38 : #include <unotext.hxx>
39 : #include <unotextrange.hxx>
40 : #include "unocrsr.hxx"
41 : #include <poolfmt.hxx>
42 : #include <ndtxt.hxx>
43 : #include <editsh.hxx>
44 : #include "xmlimp.hxx"
45 : #include "xmltexti.hxx"
46 : #include <xmloff/DocumentSettingsContext.hxx>
47 : #include <docsh.hxx>
48 : #include <editeng/unolingu.hxx>
49 : #include <svx/svdmodel.hxx>
50 : #include <svx/xmlgrhlp.hxx>
51 : #include <svx/xmleohlp.hxx>
52 : #include <sfx2/printer.hxx>
53 : #include <xmloff/xmluconv.hxx>
54 : #include <unotools/saveopt.hxx>
55 : #include <tools/diagnose_ex.h>
56 : #include <boost/unordered_set.hpp>
57 :
58 : // for locking SolarMutex: svapp + mutex
59 : #include <vcl/svapp.hxx>
60 : #include <osl/mutex.hxx>
61 : #include <unotxdoc.hxx>
62 :
63 : #include <xmloff/xmlmetai.hxx>
64 : #include <xmloff/xformsimport.hxx>
65 : #include <comphelper/servicehelper.hxx>
66 : #include <comphelper/processfactory.hxx>
67 :
68 : using namespace ::com::sun::star;
69 : using namespace ::com::sun::star::uno;
70 : using namespace ::com::sun::star::text;
71 : using namespace ::com::sun::star::lang;
72 : using namespace ::com::sun::star::beans;
73 : using namespace ::com::sun::star::container;
74 : using namespace ::com::sun::star::i18n;
75 : using namespace ::com::sun::star::drawing;
76 : using namespace ::com::sun::star::xforms;
77 : using namespace ::xmloff::token;
78 : using namespace ::std;
79 :
80 : enum SwXMLDocTokens
81 : {
82 : XML_TOK_DOC_FONTDECLS,
83 : XML_TOK_DOC_STYLES,
84 : XML_TOK_DOC_AUTOSTYLES,
85 : XML_TOK_DOC_MASTERSTYLES,
86 : XML_TOK_DOC_META,
87 : XML_TOK_DOC_BODY,
88 : XML_TOK_DOC_SCRIPT,
89 : XML_TOK_DOC_SETTINGS,
90 : XML_TOK_DOC_XFORMS,
91 : XML_TOK_OFFICE_END=XML_TOK_UNKNOWN
92 : };
93 :
94 : static SvXMLTokenMapEntry aDocTokenMap[] =
95 : {
96 : { XML_NAMESPACE_OFFICE, XML_FONT_FACE_DECLS, XML_TOK_DOC_FONTDECLS },
97 : { XML_NAMESPACE_OFFICE, XML_STYLES, XML_TOK_DOC_STYLES },
98 : { XML_NAMESPACE_OFFICE, XML_AUTOMATIC_STYLES, XML_TOK_DOC_AUTOSTYLES },
99 : { XML_NAMESPACE_OFFICE, XML_MASTER_STYLES, XML_TOK_DOC_MASTERSTYLES },
100 : { XML_NAMESPACE_OFFICE, XML_META, XML_TOK_DOC_META },
101 : { XML_NAMESPACE_OFFICE, XML_BODY, XML_TOK_DOC_BODY },
102 : { XML_NAMESPACE_OFFICE, XML_SCRIPTS, XML_TOK_DOC_SCRIPT },
103 : { XML_NAMESPACE_OFFICE, XML_SETTINGS, XML_TOK_DOC_SETTINGS },
104 : { XML_NAMESPACE_XFORMS, XML_MODEL, XML_TOK_DOC_XFORMS },
105 : XML_TOKEN_MAP_END
106 : };
107 :
108 : class SwXMLBodyContext_Impl : public SvXMLImportContext
109 : {
110 : const SwXMLImport& GetSwImport() const
111 : { return (const SwXMLImport&)GetImport(); }
112 0 : SwXMLImport& GetSwImport() { return (SwXMLImport&)GetImport(); }
113 :
114 : public:
115 :
116 : SwXMLBodyContext_Impl( SwXMLImport& rImport, sal_uInt16 nPrfx,
117 : const OUString& rLName,
118 : const Reference< xml::sax::XAttributeList > & xAttrList );
119 : virtual ~SwXMLBodyContext_Impl();
120 :
121 : TYPEINFO_OVERRIDE();
122 :
123 : virtual SvXMLImportContext *CreateChildContext( sal_uInt16 nPrefix,
124 : const OUString& rLocalName,
125 : const Reference< xml::sax::XAttributeList > & xAttrList ) SAL_OVERRIDE;
126 : };
127 :
128 0 : SwXMLBodyContext_Impl::SwXMLBodyContext_Impl( SwXMLImport& rImport,
129 : sal_uInt16 nPrfx, const OUString& rLName,
130 : const Reference< xml::sax::XAttributeList > & /*xAttrList*/ ) :
131 0 : SvXMLImportContext( rImport, nPrfx, rLName )
132 : {
133 0 : }
134 :
135 0 : SwXMLBodyContext_Impl::~SwXMLBodyContext_Impl()
136 : {
137 0 : }
138 :
139 0 : TYPEINIT1( SwXMLBodyContext_Impl, SvXMLImportContext );
140 :
141 0 : SvXMLImportContext *SwXMLBodyContext_Impl::CreateChildContext(
142 : sal_uInt16 /*nPrefix*/,
143 : const OUString& rLocalName,
144 : const Reference< xml::sax::XAttributeList > & /*xAttrList*/ )
145 : {
146 0 : return GetSwImport().CreateBodyContentContext( rLocalName );
147 : }
148 :
149 : // #i69629#
150 : // enhance class <SwXMLDocContext_Impl> in order to be able to create subclasses
151 : // NB: virtually inherit so we can multiply inherit properly
152 : // in SwXMLOfficeDocContext_Impl
153 : class SwXMLDocContext_Impl : public virtual SvXMLImportContext
154 : {
155 :
156 : protected: // #i69629#
157 : const SwXMLImport& GetSwImport() const
158 : { return (const SwXMLImport&)GetImport(); }
159 0 : SwXMLImport& GetSwImport() { return (SwXMLImport&)GetImport(); }
160 :
161 : public:
162 :
163 : SwXMLDocContext_Impl( SwXMLImport& rImport, sal_uInt16 nPrfx,
164 : const OUString& rLName,
165 : const Reference< xml::sax::XAttributeList > & xAttrList );
166 : virtual ~SwXMLDocContext_Impl();
167 :
168 : TYPEINFO_OVERRIDE();
169 :
170 : virtual SvXMLImportContext *CreateChildContext( sal_uInt16 nPrefix,
171 : const OUString& rLocalName,
172 : const Reference< xml::sax::XAttributeList > & xAttrList ) SAL_OVERRIDE;
173 : };
174 :
175 0 : SwXMLDocContext_Impl::SwXMLDocContext_Impl( SwXMLImport& rImport,
176 : sal_uInt16 nPrfx, const OUString& rLName,
177 : const Reference< xml::sax::XAttributeList > & /*xAttrList*/ ) :
178 0 : SvXMLImportContext( rImport, nPrfx, rLName )
179 : {
180 0 : }
181 :
182 0 : SwXMLDocContext_Impl::~SwXMLDocContext_Impl()
183 : {
184 0 : }
185 :
186 0 : TYPEINIT1( SwXMLDocContext_Impl, SvXMLImportContext );
187 :
188 0 : SvXMLImportContext *SwXMLDocContext_Impl::CreateChildContext(
189 : sal_uInt16 nPrefix,
190 : const OUString& rLocalName,
191 : const Reference< xml::sax::XAttributeList > & xAttrList )
192 : {
193 0 : SvXMLImportContext *pContext = 0;
194 :
195 0 : const SvXMLTokenMap& rTokenMap = GetSwImport().GetDocElemTokenMap();
196 0 : switch( rTokenMap.Get( nPrefix, rLocalName ) )
197 : {
198 : case XML_TOK_DOC_FONTDECLS:
199 0 : pContext = GetSwImport().CreateFontDeclsContext( rLocalName,
200 0 : xAttrList );
201 0 : break;
202 : case XML_TOK_DOC_STYLES:
203 0 : GetSwImport().GetProgressBarHelper()->Increment( PROGRESS_BAR_STEP );
204 0 : pContext = GetSwImport().CreateStylesContext( rLocalName, xAttrList,
205 0 : sal_False );
206 0 : break;
207 : case XML_TOK_DOC_AUTOSTYLES:
208 : // don't use the autostyles from the styles-document for the progress
209 0 : if ( ! IsXMLToken( GetLocalName(), XML_DOCUMENT_STYLES ) )
210 0 : GetSwImport().GetProgressBarHelper()->Increment
211 0 : ( PROGRESS_BAR_STEP );
212 0 : pContext = GetSwImport().CreateStylesContext( rLocalName, xAttrList,
213 0 : sal_True );
214 0 : break;
215 :
216 : case XML_TOK_DOC_MASTERSTYLES:
217 0 : pContext = GetSwImport().CreateMasterStylesContext( rLocalName,
218 0 : xAttrList );
219 0 : break;
220 : case XML_TOK_DOC_META:
221 : OSL_FAIL("XML_TOK_DOC_META: should not have come here, maybe document is invalid?");
222 0 : break;
223 : case XML_TOK_DOC_SCRIPT:
224 0 : pContext = GetSwImport().CreateScriptContext( rLocalName );
225 0 : break;
226 : case XML_TOK_DOC_BODY:
227 0 : GetSwImport().GetProgressBarHelper()->Increment( PROGRESS_BAR_STEP );
228 : pContext = new SwXMLBodyContext_Impl( GetSwImport(), nPrefix,
229 0 : rLocalName, xAttrList );
230 0 : break;
231 : case XML_TOK_DOC_SETTINGS:
232 0 : pContext = new XMLDocumentSettingsContext( GetImport(), nPrefix, rLocalName, xAttrList );
233 0 : break;
234 : case XML_TOK_DOC_XFORMS:
235 0 : pContext = createXFormsModelContext(GetImport(), nPrefix, rLocalName);
236 0 : break;
237 : }
238 :
239 0 : if( !pContext )
240 0 : pContext = new SvXMLImportContext( GetImport(), nPrefix, rLocalName );
241 :
242 0 : return pContext;
243 : }
244 :
245 : // #i69629# - new subclass <SwXMLOfficeDocContext_Impl> of class <SwXMLDocContext_Impl>
246 : class SwXMLOfficeDocContext_Impl :
247 : public SwXMLDocContext_Impl, public SvXMLMetaDocumentContext
248 : {
249 : public:
250 :
251 : SwXMLOfficeDocContext_Impl( SwXMLImport& rImport,
252 : sal_uInt16 nPrfx,
253 : const OUString& rLName,
254 : const Reference< xml::sax::XAttributeList > & xAttrList,
255 : const Reference< document::XDocumentProperties >& xDocProps);
256 : virtual ~SwXMLOfficeDocContext_Impl();
257 :
258 : TYPEINFO_OVERRIDE();
259 :
260 : virtual SvXMLImportContext *CreateChildContext(
261 : sal_uInt16 nPrefix,
262 : const OUString& rLocalName,
263 : const Reference< xml::sax::XAttributeList > & xAttrList ) SAL_OVERRIDE;
264 : };
265 :
266 0 : SwXMLOfficeDocContext_Impl::SwXMLOfficeDocContext_Impl(
267 : SwXMLImport& rImport,
268 : sal_uInt16 nPrfx,
269 : const OUString& rLName,
270 : const Reference< xml::sax::XAttributeList > & xAttrList,
271 : const Reference< document::XDocumentProperties >& xDocProps) :
272 : SvXMLImportContext( rImport, nPrfx, rLName ),
273 : SwXMLDocContext_Impl( rImport, nPrfx, rLName, xAttrList ),
274 0 : SvXMLMetaDocumentContext( rImport, nPrfx, rLName, xDocProps)
275 : {
276 0 : }
277 :
278 0 : SwXMLOfficeDocContext_Impl::~SwXMLOfficeDocContext_Impl()
279 : {
280 0 : }
281 :
282 0 : TYPEINIT1( SwXMLOfficeDocContext_Impl, SwXMLDocContext_Impl );
283 :
284 0 : SvXMLImportContext* SwXMLOfficeDocContext_Impl::CreateChildContext(
285 : sal_uInt16 nPrefix,
286 : const OUString& rLocalName,
287 : const Reference< xml::sax::XAttributeList > & xAttrList )
288 : {
289 0 : const SvXMLTokenMap& rTokenMap = GetSwImport().GetDocElemTokenMap();
290 :
291 : // assign paragraph styles to list levels of outline style after all styles
292 : // are imported and finished. This is the case, when <office:body> starts
293 : // in flat OpenDocument file format.
294 : {
295 0 : if ( rTokenMap.Get( nPrefix, rLocalName ) == XML_TOK_DOC_BODY )
296 : {
297 0 : GetImport().GetTextImport()->SetOutlineStyles( true );
298 : }
299 : }
300 :
301 : // behave like meta base class iff we encounter office:meta
302 0 : if ( XML_TOK_DOC_META == rTokenMap.Get( nPrefix, rLocalName ) ) {
303 : return SvXMLMetaDocumentContext::CreateChildContext(
304 0 : nPrefix, rLocalName, xAttrList );
305 : } else {
306 : return SwXMLDocContext_Impl::CreateChildContext(
307 0 : nPrefix, rLocalName, xAttrList );
308 : }
309 : }
310 :
311 : // #i69629# - new subclass <SwXMLDocStylesContext_Impl> of class <SwXMLDocContext_Impl>
312 : class SwXMLDocStylesContext_Impl : public SwXMLDocContext_Impl
313 : {
314 : public:
315 :
316 : SwXMLDocStylesContext_Impl( SwXMLImport& rImport,
317 : sal_uInt16 nPrfx,
318 : const OUString& rLName,
319 : const Reference< xml::sax::XAttributeList > & xAttrList );
320 : virtual ~SwXMLDocStylesContext_Impl();
321 :
322 : TYPEINFO_OVERRIDE();
323 :
324 : virtual void EndElement() SAL_OVERRIDE;
325 : };
326 :
327 0 : SwXMLDocStylesContext_Impl::SwXMLDocStylesContext_Impl(
328 : SwXMLImport& rImport,
329 : sal_uInt16 nPrfx,
330 : const OUString& rLName,
331 : const Reference< xml::sax::XAttributeList > & xAttrList ) :
332 : SvXMLImportContext( rImport, nPrfx, rLName ),
333 0 : SwXMLDocContext_Impl( rImport, nPrfx, rLName, xAttrList )
334 : {
335 0 : }
336 :
337 0 : SwXMLDocStylesContext_Impl::~SwXMLDocStylesContext_Impl()
338 : {
339 0 : }
340 :
341 0 : TYPEINIT1( SwXMLDocStylesContext_Impl, SwXMLDocContext_Impl );
342 :
343 0 : void SwXMLDocStylesContext_Impl::EndElement()
344 : {
345 : // assign paragraph styles to list levels of outline style after all styles
346 : // are imported and finished.
347 0 : SwXMLImport& rSwImport = dynamic_cast<SwXMLImport&>( GetImport());
348 0 : GetImport().GetTextImport()->SetOutlineStyles(
349 0 : (rSwImport.GetStyleFamilyMask() & SFX_STYLE_FAMILY_PARA ) ? sal_True : sal_False);
350 0 : }
351 :
352 0 : const SvXMLTokenMap& SwXMLImport::GetDocElemTokenMap()
353 : {
354 0 : if( !pDocElemTokenMap )
355 0 : pDocElemTokenMap = new SvXMLTokenMap( aDocTokenMap );
356 :
357 0 : return *pDocElemTokenMap;
358 : }
359 :
360 0 : SvXMLImportContext *SwXMLImport::CreateContext(
361 : sal_uInt16 nPrefix,
362 : const OUString& rLocalName,
363 : const Reference< xml::sax::XAttributeList > & xAttrList )
364 : {
365 0 : SvXMLImportContext *pContext = 0;
366 :
367 : // #i69629# - own subclasses for <office:document> and <office:document-styles>
368 0 : if( XML_NAMESPACE_OFFICE==nPrefix &&
369 0 : ( IsXMLToken( rLocalName, XML_DOCUMENT_SETTINGS ) ||
370 0 : IsXMLToken( rLocalName, XML_DOCUMENT_CONTENT ) ))
371 0 : pContext = new SwXMLDocContext_Impl( *this, nPrefix, rLocalName,
372 0 : xAttrList );
373 0 : else if ( XML_NAMESPACE_OFFICE==nPrefix &&
374 0 : IsXMLToken( rLocalName, XML_DOCUMENT_META ) )
375 : {
376 0 : pContext = CreateMetaContext(rLocalName);
377 : }
378 0 : else if ( XML_NAMESPACE_OFFICE==nPrefix &&
379 0 : IsXMLToken( rLocalName, XML_DOCUMENT_STYLES ) )
380 : {
381 0 : pContext = new SwXMLDocStylesContext_Impl( *this, nPrefix, rLocalName,
382 0 : xAttrList );
383 : }
384 0 : else if ( XML_NAMESPACE_OFFICE==nPrefix &&
385 0 : IsXMLToken( rLocalName, XML_DOCUMENT ) )
386 : {
387 : uno::Reference<document::XDocumentProperties> const xDocProps(
388 0 : GetDocumentProperties());
389 : // flat OpenDocument file format
390 0 : pContext = new SwXMLOfficeDocContext_Impl( *this, nPrefix, rLocalName,
391 0 : xAttrList, xDocProps);
392 : }
393 : else
394 0 : pContext = SvXMLImport::CreateContext( nPrefix, rLocalName, xAttrList );
395 :
396 0 : return pContext;
397 : }
398 :
399 0 : SwXMLImport::SwXMLImport(
400 : const uno::Reference< uno::XComponentContext > xContext,
401 : OUString const & implementationName, sal_uInt16 nImportFlags)
402 : : SvXMLImport( xContext, implementationName, nImportFlags ),
403 : pSttNdIdx( 0 ),
404 : pTableItemMapper( 0 ),
405 : pDocElemTokenMap( 0 ),
406 : pTableElemTokenMap( 0 ),
407 : pTableCellAttrTokenMap( 0 ),
408 : pGraphicResolver( 0 ),
409 : pEmbeddedResolver( 0 ),
410 : nStyleFamilyMask( SFX_STYLE_FAMILY_ALL ),
411 : bLoadDoc( true ),
412 : bInsert( false ),
413 : bBlock( false ),
414 : bShowProgress( true ),
415 : bOrganizerMode( false ),
416 : bInititedXForms( false ),
417 : bPreserveRedlineMode( sal_True ),
418 0 : doc( NULL )
419 : {
420 0 : _InitItemImport();
421 :
422 0 : }
423 :
424 0 : SwXMLImport::~SwXMLImport() throw ()
425 : {
426 0 : delete pDocElemTokenMap;
427 0 : delete pTableElemTokenMap;
428 0 : delete pTableCellAttrTokenMap;
429 0 : _FinitItemImport();
430 0 : }
431 :
432 0 : void SwXMLImport::setTextInsertMode(
433 : const Reference< XTextRange > & rInsertPos )
434 : {
435 0 : bInsert = true;
436 :
437 0 : Reference < XText > xText = rInsertPos->getText();
438 : Reference < XTextCursor > xTextCursor =
439 0 : xText->createTextCursorByRange( rInsertPos );
440 0 : GetTextImport()->SetCursor( xTextCursor );
441 0 : }
442 :
443 0 : void SwXMLImport::setStyleInsertMode( sal_uInt16 nFamilies,
444 : sal_Bool bOverwrite )
445 : {
446 0 : bInsert = !bOverwrite;
447 0 : nStyleFamilyMask = nFamilies;
448 0 : bLoadDoc = false;
449 0 : }
450 :
451 0 : void SwXMLImport::setBlockMode( )
452 : {
453 0 : bBlock = true;
454 0 : }
455 :
456 0 : void SwXMLImport::setOrganizerMode( )
457 : {
458 0 : bOrganizerMode = true;
459 0 : }
460 :
461 : namespace
462 : {
463 : class theSwXMLImportUnoTunnelId : public rtl::Static< UnoTunnelIdInit, theSwXMLImportUnoTunnelId > {};
464 : }
465 :
466 0 : const Sequence< sal_Int8 > & SwXMLImport::getUnoTunnelId() throw()
467 : {
468 0 : return theSwXMLImportUnoTunnelId::get().getSeq();
469 : }
470 :
471 0 : sal_Int64 SAL_CALL SwXMLImport::getSomething( const Sequence< sal_Int8 >& rId )
472 : throw(RuntimeException, std::exception)
473 : {
474 0 : if( rId.getLength() == 16
475 0 : && 0 == memcmp( getUnoTunnelId().getConstArray(),
476 0 : rId.getConstArray(), 16 ) )
477 : {
478 0 : return sal::static_int_cast< sal_Int64 >( reinterpret_cast< sal_IntPtr >(this) );
479 : }
480 0 : return SvXMLImport::getSomething( rId );
481 : }
482 :
483 0 : static OTextCursorHelper *lcl_xml_GetSwXTextCursor( const Reference < XTextCursor >& rTextCursor )
484 : {
485 0 : Reference<XUnoTunnel> xCrsrTunnel( rTextCursor, UNO_QUERY );
486 : OSL_ENSURE( xCrsrTunnel.is(), "missing XUnoTunnel for Cursor" );
487 0 : if( !xCrsrTunnel.is() )
488 0 : return 0;
489 : OTextCursorHelper *pTxtCrsr = reinterpret_cast< OTextCursorHelper *>(
490 0 : sal::static_int_cast< sal_IntPtr >( xCrsrTunnel->getSomething( OTextCursorHelper::getUnoTunnelId() )));
491 : OSL_ENSURE( pTxtCrsr, "SwXTextCursor missing" );
492 0 : return pTxtCrsr;
493 : }
494 :
495 0 : void SwXMLImport::startDocument()
496 : throw (xml::sax::SAXException,
497 : uno::RuntimeException,
498 : std::exception)
499 : {
500 : // delegate to parent
501 0 : SvXMLImport::startDocument();
502 :
503 : OSL_ENSURE( GetModel().is(), "model is missing" );
504 0 : if( !GetModel().is() )
505 0 : return;
506 :
507 : // this method will modify the document directly -> lock SolarMutex
508 0 : SolarMutexGuard aGuard;
509 :
510 0 : Reference< XPropertySet > xImportInfo( getImportInfo() );
511 0 : Reference< XPropertySetInfo > xPropertySetInfo;
512 0 : if( xImportInfo.is() )
513 0 : xPropertySetInfo = xImportInfo->getPropertySetInfo();
514 0 : if( xPropertySetInfo.is() )
515 : {
516 0 : Any aAny;
517 : // insert style mode?
518 0 : OUString sStyleInsertModeFamilies("StyleInsertModeFamilies");
519 0 : if( xPropertySetInfo->hasPropertyByName(sStyleInsertModeFamilies) )
520 : {
521 0 : aAny = xImportInfo->getPropertyValue(sStyleInsertModeFamilies);
522 0 : Sequence< OUString> aFamiliesSeq;
523 0 : if( aAny >>= aFamiliesSeq )
524 : {
525 0 : OUString sFrameStyles( "FrameStyles" );
526 0 : OUString sPageStyles( "PageStyles" );
527 0 : OUString sCharacterStyles( "CharacterStyles" );
528 0 : OUString sParagraphStyles( "ParagraphStyles" );
529 0 : OUString sNumberingStyles( "NumberingStyles" );
530 0 : sal_uInt16 nFamilyMask = 0U;
531 0 : sal_Int32 nCount = aFamiliesSeq.getLength();
532 0 : const OUString *pSeq = aFamiliesSeq.getConstArray();
533 0 : for( sal_Int32 i=0; i < nCount; i++ )
534 : {
535 0 : const OUString& rFamily = pSeq[i];
536 0 : if( rFamily==sFrameStyles )
537 0 : nFamilyMask |= SFX_STYLE_FAMILY_FRAME;
538 0 : else if( rFamily==sPageStyles )
539 0 : nFamilyMask |= SFX_STYLE_FAMILY_PAGE;
540 0 : else if( rFamily==sCharacterStyles )
541 0 : nFamilyMask |= SFX_STYLE_FAMILY_CHAR;
542 0 : else if( rFamily==sParagraphStyles )
543 0 : nFamilyMask |= SFX_STYLE_FAMILY_PARA;
544 0 : else if( rFamily==sNumberingStyles )
545 0 : nFamilyMask |= SFX_STYLE_FAMILY_PSEUDO;
546 : }
547 :
548 0 : sal_Bool bOverwrite = sal_False;
549 0 : OUString sStyleInsertModeOverwrite("StyleInsertModeOverwrite");
550 0 : if( xPropertySetInfo->hasPropertyByName(sStyleInsertModeOverwrite) )
551 : {
552 0 : aAny = xImportInfo->getPropertyValue(sStyleInsertModeOverwrite);
553 0 : if( aAny.getValueType() == ::getBooleanCppuType() &&
554 0 : *static_cast<const sal_Bool*>(aAny.getValue()) )
555 0 : bOverwrite = sal_True;
556 : }
557 :
558 0 : setStyleInsertMode( nFamilyMask, bOverwrite );
559 0 : }
560 : }
561 :
562 : // text insert mode?
563 0 : OUString sTextInsertModeRange("TextInsertModeRange");
564 0 : if( xPropertySetInfo->hasPropertyByName(sTextInsertModeRange) )
565 : {
566 0 : aAny = xImportInfo->getPropertyValue(sTextInsertModeRange);
567 0 : Reference<XTextRange> xInsertTextRange;
568 0 : if( aAny >>= xInsertTextRange )
569 0 : setTextInsertMode( xInsertTextRange );
570 : }
571 :
572 : // auto text mode
573 0 : OUString sAutoTextMode("AutoTextMode");
574 0 : if( xPropertySetInfo->hasPropertyByName(sAutoTextMode) )
575 : {
576 0 : aAny = xImportInfo->getPropertyValue(sAutoTextMode);
577 0 : if( aAny.getValueType() == ::getBooleanCppuType() &&
578 0 : *static_cast<const sal_Bool*>(aAny.getValue()) )
579 0 : setBlockMode();
580 : }
581 :
582 : // organizer mode
583 0 : OUString sOrganizerMode("OrganizerMode");
584 0 : if( xPropertySetInfo->hasPropertyByName(sOrganizerMode) )
585 : {
586 0 : aAny = xImportInfo->getPropertyValue(sOrganizerMode);
587 0 : if( aAny.getValueType() == ::getBooleanCppuType() &&
588 0 : *static_cast<const sal_Bool*>(aAny.getValue()) )
589 0 : setOrganizerMode();
590 0 : }
591 : }
592 :
593 : // There only is a text cursor by now if we are in insert mode. In any
594 : // other case we have to create one at the start of the document.
595 : // We also might change into the insert mode later, so we have to make
596 : // sure to first set the insert mode and then create the text import
597 : // helper. Otherwise it won't have the insert flag set!
598 0 : OTextCursorHelper *pTxtCrsr = 0;
599 0 : Reference < XTextCursor > xTextCursor;
600 0 : if( HasTextImport() )
601 0 : xTextCursor = GetTextImport()->GetCursor();
602 0 : if( !xTextCursor.is() )
603 : {
604 0 : Reference < XTextDocument > xTextDoc( GetModel(), UNO_QUERY );
605 0 : Reference < XText > xText = xTextDoc->getText();
606 0 : xTextCursor = xText->createTextCursor();
607 0 : SwCrsrShell *pCrsrSh = 0;
608 0 : SwDoc *pDoc = 0;
609 0 : if( IMPORT_ALL == getImportFlags() )
610 : {
611 0 : pTxtCrsr = lcl_xml_GetSwXTextCursor( xTextCursor );
612 : OSL_ENSURE( pTxtCrsr, "SwXTextCursor missing" );
613 0 : if( !pTxtCrsr )
614 0 : return;
615 :
616 0 : pDoc = pTxtCrsr->GetDoc();
617 : OSL_ENSURE( pDoc, "SwDoc missing" );
618 0 : if( !pDoc )
619 0 : return;
620 :
621 : // Is there a edit shell. If yes, then we are currently inserting
622 : // a document. We then have to insert at the current edit shell's
623 : // cursor position. That not quite clean code, but there is no other
624 : // way currently.
625 0 : pCrsrSh = pDoc->GetEditShell();
626 : }
627 0 : if( pCrsrSh )
628 : {
629 : const uno::Reference<text::XTextRange> xInsertTextRange(
630 : SwXTextRange::CreateXTextRange(
631 0 : *pDoc, *pCrsrSh->GetCrsr()->GetPoint(), 0 ) );
632 0 : setTextInsertMode( xInsertTextRange );
633 0 : xTextCursor = GetTextImport()->GetCursor();
634 0 : pTxtCrsr = 0;
635 : }
636 : else
637 0 : GetTextImport()->SetCursor( xTextCursor );
638 : }
639 :
640 0 : if( (getImportFlags() & (IMPORT_CONTENT|IMPORT_MASTERSTYLES)) == 0 )
641 0 : return;
642 :
643 0 : if( !pTxtCrsr )
644 0 : pTxtCrsr = lcl_xml_GetSwXTextCursor( xTextCursor );
645 : OSL_ENSURE( pTxtCrsr, "SwXTextCursor missing" );
646 0 : if( !pTxtCrsr )
647 0 : return;
648 :
649 0 : SwDoc *pDoc = pTxtCrsr->GetDoc();
650 : OSL_ENSURE( pDoc, "SwDoc missing" );
651 0 : if( !pDoc )
652 0 : return;
653 :
654 0 : if( (getImportFlags() & IMPORT_CONTENT) != 0 && !IsStylesOnlyMode() )
655 : {
656 0 : pSttNdIdx = new SwNodeIndex( pDoc->GetNodes() );
657 0 : if( IsInsertMode() )
658 : {
659 0 : SwPaM *pPaM = pTxtCrsr->GetPaM();
660 0 : const SwPosition* pPos = pPaM->GetPoint();
661 :
662 : // Split once and remember the node that has been splitted.
663 0 : pDoc->SplitNode( *pPos, false );
664 0 : *pSttNdIdx = pPos->nNode.GetIndex()-1;
665 :
666 : // Split again.
667 0 : pDoc->SplitNode( *pPos, false );
668 :
669 : // Insert all content into the new node
670 0 : pPaM->Move( fnMoveBackward );
671 : pDoc->SetTxtFmtColl
672 0 : ( *pPaM, pDoc->GetTxtCollFromPool(RES_POOLCOLL_STANDARD, false ) );
673 : }
674 : }
675 :
676 : // We need a draw model to be able to set the z order
677 0 : pDoc->GetOrCreateDrawModel(); // #i52858# - method name changed
678 :
679 : // SJ: #i49801# locking the modell to disable repaints
680 0 : SdrModel* pDrawModel = pDoc->GetDrawModel();
681 0 : if ( pDrawModel )
682 0 : pDrawModel->setLock(true);
683 :
684 0 : if( !GetGraphicResolver().is() )
685 : {
686 0 : pGraphicResolver = SvXMLGraphicHelper::Create( GRAPHICHELPER_MODE_READ );
687 0 : Reference< document::XGraphicObjectResolver > xGraphicResolver( pGraphicResolver );
688 0 : SetGraphicResolver( xGraphicResolver );
689 : }
690 :
691 0 : if( !GetEmbeddedResolver().is() )
692 : {
693 0 : SfxObjectShell *pPersist = pDoc->GetPersist();
694 0 : if( pPersist )
695 : {
696 : pEmbeddedResolver = SvXMLEmbeddedObjectHelper::Create(
697 : *pPersist,
698 0 : EMBEDDEDOBJECTHELPER_MODE_READ );
699 0 : Reference< document::XEmbeddedObjectResolver > xEmbeddedResolver( pEmbeddedResolver );
700 0 : SetEmbeddedResolver( xEmbeddedResolver );
701 : }
702 0 : }
703 : }
704 :
705 0 : void SwXMLImport::endDocument( void )
706 : throw( xml::sax::SAXException, uno::RuntimeException, std::exception )
707 : {
708 : OSL_ENSURE( GetModel().is(), "model missing; maybe startDocument wasn't called?" );
709 0 : if( !GetModel().is() )
710 0 : return;
711 :
712 : // this method will modify the document directly -> lock SolarMutex
713 0 : SolarMutexGuard aGuard;
714 :
715 0 : if( pGraphicResolver )
716 0 : SvXMLGraphicHelper::Destroy( pGraphicResolver );
717 0 : if( pEmbeddedResolver )
718 0 : SvXMLEmbeddedObjectHelper::Destroy( pEmbeddedResolver );
719 : // Clear the shape import to sort the shapes (and not in the
720 : // destructor that might be called after the import has finished
721 : // for Java filters.
722 0 : if( HasShapeImport() )
723 0 : ClearShapeImport();
724 :
725 0 : SwDoc *pDoc = 0;
726 0 : if( (getImportFlags() & IMPORT_CONTENT) != 0 && !IsStylesOnlyMode() )
727 : {
728 0 : Reference<XUnoTunnel> xCrsrTunnel( GetTextImport()->GetCursor(),
729 0 : UNO_QUERY);
730 : OSL_ENSURE( xCrsrTunnel.is(), "missing XUnoTunnel for Cursor" );
731 : OTextCursorHelper *pTxtCrsr = reinterpret_cast< OTextCursorHelper *>(
732 0 : sal::static_int_cast< sal_IntPtr >( xCrsrTunnel->getSomething( OTextCursorHelper::getUnoTunnelId() )));
733 : OSL_ENSURE( pTxtCrsr, "SwXTextCursor missing" );
734 0 : SwPaM *pPaM = pTxtCrsr->GetPaM();
735 0 : if( IsInsertMode() && pSttNdIdx->GetIndex() )
736 : {
737 : // If we are in insert mode, join the splitted node that is in front
738 : // of the new content with the first new node. Or in other words:
739 : // Revert the first split node.
740 0 : SwTxtNode* pTxtNode = pSttNdIdx->GetNode().GetTxtNode();
741 0 : SwNodeIndex aNxtIdx( *pSttNdIdx );
742 0 : if( pTxtNode && pTxtNode->CanJoinNext( &aNxtIdx ) &&
743 0 : pSttNdIdx->GetIndex() + 1 == aNxtIdx.GetIndex() )
744 : {
745 : // If the PaM points to the first new node, move the PaM to the
746 : // end of the previous node.
747 0 : if( pPaM->GetPoint()->nNode == aNxtIdx )
748 : {
749 0 : pPaM->GetPoint()->nNode = *pSttNdIdx;
750 0 : pPaM->GetPoint()->nContent.Assign( pTxtNode,
751 0 : pTxtNode->GetTxt().getLength());
752 : }
753 :
754 : #if OSL_DEBUG_LEVEL > 0
755 : // !!! This should be impossible !!!!
756 : OSL_ENSURE( pSttNdIdx->GetIndex()+1 !=
757 : pPaM->GetBound( true ).nNode.GetIndex(),
758 : "PaM.Bound1 point to new node " );
759 : OSL_ENSURE( pSttNdIdx->GetIndex()+1 !=
760 : pPaM->GetBound( false ).nNode.GetIndex(),
761 : "PaM.Bound2 points to new node" );
762 :
763 : if( pSttNdIdx->GetIndex()+1 ==
764 : pPaM->GetBound( true ).nNode.GetIndex() )
765 : {
766 : const sal_Int32 nCntPos =
767 : pPaM->GetBound( true ).nContent.GetIndex();
768 : pPaM->GetBound( true ).nContent.Assign( pTxtNode,
769 : pTxtNode->GetTxt().getLength() + nCntPos );
770 : }
771 : if( pSttNdIdx->GetIndex()+1 ==
772 : pPaM->GetBound( false ).nNode.GetIndex() )
773 : {
774 : const sal_Int32 nCntPos =
775 : pPaM->GetBound( false ).nContent.GetIndex();
776 : pPaM->GetBound( false ).nContent.Assign( pTxtNode,
777 : pTxtNode->GetTxt().getLength() + nCntPos );
778 : }
779 : #endif
780 : // If the first new node isn't empty, convert the node's text
781 : // attributes into hints. Otherwise, set the new node's
782 : // paragraph style at the previous (empty) node.
783 0 : SwTxtNode* pDelNd = aNxtIdx.GetNode().GetTxtNode();
784 0 : if (!pTxtNode->GetTxt().isEmpty())
785 0 : pDelNd->FmtToTxtAttr( pTxtNode );
786 : else
787 0 : pTxtNode->ChgFmtColl( pDelNd->GetTxtColl() );
788 0 : pTxtNode->JoinNext();
789 0 : }
790 : }
791 :
792 0 : SwPosition* pPos = pPaM->GetPoint();
793 : OSL_ENSURE( !pPos->nContent.GetIndex(), "last paragraph isn't empty" );
794 0 : if( !pPos->nContent.GetIndex() )
795 : {
796 : SwTxtNode* pCurrNd;
797 0 : sal_uLong nNodeIdx = pPos->nNode.GetIndex();
798 0 : pDoc = pPaM->GetDoc();
799 :
800 : OSL_ENSURE( pPos->nNode.GetNode().IsCntntNode(),
801 : "insert position is not a content node" );
802 0 : if( !IsInsertMode() )
803 : {
804 : // If we're not in insert mode, the last node is deleted.
805 0 : const SwNode *pPrev = pDoc->GetNodes()[nNodeIdx -1];
806 0 : if( pPrev->IsCntntNode() ||
807 0 : ( pPrev->IsEndNode() &&
808 0 : pPrev->StartOfSectionNode()->IsSectionNode() ) )
809 : {
810 0 : SwCntntNode* pCNd = pPaM->GetCntntNode();
811 0 : if( pCNd && pCNd->StartOfSectionIndex()+2 <
812 0 : pCNd->EndOfSectionIndex() )
813 : {
814 0 : pPaM->GetBound(true).nContent.Assign( 0, 0 );
815 0 : pPaM->GetBound(false).nContent.Assign( 0, 0 );
816 0 : pDoc->GetNodes().Delete( pPaM->GetPoint()->nNode );
817 : }
818 : }
819 : }
820 0 : else if( 0 != (pCurrNd = pDoc->GetNodes()[nNodeIdx]->GetTxtNode()) )
821 : {
822 : // Id we're in insert mode, the empty node is joined with
823 : // the next and the previous one.
824 0 : if( pCurrNd->CanJoinNext( &pPos->nNode ))
825 : {
826 0 : SwTxtNode* pNextNd = pPos->nNode.GetNode().GetTxtNode();
827 0 : pPos->nContent.Assign( pNextNd, 0 );
828 0 : pPaM->SetMark(); pPaM->DeleteMark();
829 0 : pNextNd->JoinPrev();
830 :
831 : // Remove line break that has been inserted by the import,
832 : // but only if one has been inserted!
833 0 : if( pNextNd->CanJoinPrev(/* &pPos->nNode*/ ) &&
834 0 : *pSttNdIdx != pPos->nNode )
835 : {
836 0 : pNextNd->JoinPrev();
837 : }
838 : }
839 0 : else if (pCurrNd->GetTxt().isEmpty())
840 : {
841 0 : pPos->nContent.Assign( 0, 0 );
842 0 : pPaM->SetMark(); pPaM->DeleteMark();
843 0 : pDoc->GetNodes().Delete( pPos->nNode, 1 );
844 0 : pPaM->Move( fnMoveBackward );
845 : }
846 : }
847 0 : }
848 : }
849 :
850 : /* Was called too early. Moved from SwXMLBodyContext_Impl::EndElement */
851 :
852 0 : GetTextImport()->RedlineAdjustStartNodeCursor( false );
853 :
854 0 : if( (getImportFlags() & IMPORT_CONTENT) != 0 ||
855 0 : ((getImportFlags() & IMPORT_MASTERSTYLES) != 0 && IsStylesOnlyMode()) )
856 : {
857 : // pDoc might be 0. In this case UpdateTxtCollCondition is looking
858 : // for it itself.
859 0 : UpdateTxtCollConditions( pDoc );
860 : }
861 :
862 0 : GetTextImport()->ResetCursor();
863 :
864 0 : delete pSttNdIdx;
865 0 : pSttNdIdx = 0;
866 :
867 : // SJ: #i49801# -> now permitting repaints
868 0 : if ( pDoc )
869 : {
870 0 : if( (getImportFlags() == IMPORT_ALL ) )
871 : {
872 : // Notify math objects. If we are in the package filter this will
873 : // be done by the filter object itself
874 0 : if( IsInsertMode() )
875 0 : pDoc->PrtOLENotify( sal_False );
876 0 : else if ( pDoc->IsOLEPrtNotifyPending() )
877 0 : pDoc->PrtOLENotify( sal_True );
878 : }
879 :
880 0 : SdrModel* pDrawModel = pDoc->GetDrawModel();
881 0 : if ( pDrawModel )
882 0 : pDrawModel->setLock(false);
883 : }
884 :
885 : // #i90243#
886 0 : if ( bInititedXForms )
887 : {
888 0 : Reference< xforms::XFormsSupplier > xFormsSupp( GetModel(), UNO_QUERY );
889 0 : Reference< XNameAccess > xXForms;
890 0 : if ( xFormsSupp.is() )
891 0 : xXForms = xFormsSupp->getXForms().get();
892 :
893 0 : if ( xXForms.is() )
894 : {
895 : try
896 : {
897 0 : Sequence< beans::PropertyValue > aXFormsSettings;
898 :
899 0 : OUString sXFormsSettingsName( GetXMLToken( XML_XFORM_MODEL_SETTINGS ) );
900 0 : if ( xLateInitSettings.is() && xLateInitSettings->hasByName( sXFormsSettingsName ) )
901 : {
902 0 : OSL_VERIFY( xLateInitSettings->getByName( sXFormsSettingsName ) >>= aXFormsSettings );
903 0 : applyXFormsSettings( xXForms, aXFormsSettings );
904 0 : }
905 : }
906 0 : catch( const Exception& )
907 : {
908 : }
909 0 : }
910 : }
911 :
912 : // delegate to parent: takes care of error handling
913 0 : SvXMLImport::endDocument();
914 0 : ClearTextImport();
915 : }
916 :
917 : // Locally derive XMLTextShapeImportHelper, so we can take care of the
918 : // form import This is Writer, but not text specific, so it should go
919 : // here!
920 : class SvTextShapeImportHelper : public XMLTextShapeImportHelper
921 : {
922 : // hold own reference form import helper, because the SvxImport
923 : // stored in the superclass, from whom we originally got the
924 : // reference, is already destroyed when we want to use it in the
925 : // destructor
926 : UniReference< ::xmloff::OFormLayerXMLImport > rFormImport;
927 :
928 : // hold reference to the one page (if it exists) for calling startPage()
929 : // and endPage. If !xPage.is(), then this document doesn't have a
930 : // XDrawPage.
931 : Reference<drawing::XDrawPage> xPage;
932 :
933 : public:
934 : SvTextShapeImportHelper(SvXMLImport& rImp);
935 : virtual ~SvTextShapeImportHelper();
936 : };
937 :
938 0 : SvTextShapeImportHelper::SvTextShapeImportHelper(SvXMLImport& rImp) :
939 0 : XMLTextShapeImportHelper(rImp)
940 : {
941 0 : Reference<drawing::XDrawPageSupplier> xSupplier(rImp.GetModel(),UNO_QUERY);
942 0 : if (xSupplier.is())
943 : {
944 0 : if (rImp.GetFormImport().is())
945 : {
946 0 : rImp.GetFormImport()->startPage(xSupplier->getDrawPage());
947 0 : rFormImport = rImp.GetFormImport();
948 : }
949 :
950 0 : xPage = xSupplier->getDrawPage();
951 0 : Reference<XShapes> xShapes( xPage, UNO_QUERY );
952 0 : XMLShapeImportHelper::startPage( xShapes );
953 0 : }
954 0 : }
955 :
956 0 : SvTextShapeImportHelper::~SvTextShapeImportHelper()
957 : {
958 0 : rFormImport->endPage();
959 :
960 0 : if (xPage.is())
961 : {
962 0 : Reference<XShapes> xShapes( xPage, UNO_QUERY );
963 0 : XMLShapeImportHelper::endPage(xShapes);
964 : }
965 0 : }
966 :
967 0 : XMLTextImportHelper* SwXMLImport::CreateTextImport()
968 : {
969 0 : return new SwXMLTextImportHelper( GetModel(), *this, getImportInfo(),
970 0 : IsInsertMode(),
971 0 : IsStylesOnlyMode(), bShowProgress,
972 0 : IsBlockMode(), IsOrganizerMode(),
973 0 : bPreserveRedlineMode );
974 : }
975 :
976 0 : XMLShapeImportHelper* SwXMLImport::CreateShapeImport()
977 : {
978 0 : return new SvTextShapeImportHelper( *this );
979 : }
980 :
981 0 : SvXMLImportContext *SwXMLImport::CreateFontDeclsContext(
982 : const OUString& rLocalName,
983 : const Reference< xml::sax::XAttributeList > & xAttrList )
984 : {
985 : XMLFontStylesContext *pFSContext =
986 : new XMLFontStylesContext( *this, XML_NAMESPACE_OFFICE,
987 : rLocalName, xAttrList,
988 0 : osl_getThreadTextEncoding() );
989 0 : SetFontDecls( pFSContext );
990 0 : return pFSContext;
991 : }
992 0 : void SwXMLImport::SetViewSettings(const Sequence < PropertyValue > & aViewProps)
993 : {
994 0 : if (IsInsertMode() || IsStylesOnlyMode() || IsBlockMode() || IsOrganizerMode() || !GetModel().is() )
995 0 : return;
996 :
997 : // this method will modify the document directly -> lock SolarMutex
998 0 : SolarMutexGuard aGuard;
999 :
1000 0 : SwDoc *pDoc = getDoc();
1001 0 : Rectangle aRect;
1002 0 : if( pDoc->GetDocShell() )
1003 0 : aRect = pDoc->GetDocShell()->GetVisArea( ASPECT_CONTENT );
1004 : //TODO/LATER: why that cast?!
1005 : //aRect = ((SfxInPlaceObject *)pDoc->GetDocShell())->GetVisArea();
1006 :
1007 0 : sal_Int32 nCount = aViewProps.getLength();
1008 0 : const PropertyValue *pValue = aViewProps.getConstArray();
1009 :
1010 0 : sal_Int64 nTmp = 0;
1011 0 : sal_Bool bShowRedlineChanges = sal_False, bBrowseMode = sal_False;
1012 0 : sal_Bool bChangeShowRedline = sal_False, bChangeBrowseMode = sal_False;
1013 :
1014 : //TODO/LATER: why that cast?!
1015 0 : sal_Bool bTwip = pDoc->GetDocShell()->GetMapUnit ( ) == MAP_TWIP;
1016 : //sal_Bool bTwip = pDoc->GetDocShell()->SfxInPlaceObject::GetMapUnit ( ) == MAP_TWIP;
1017 :
1018 0 : for (sal_Int32 i = 0; i < nCount ; i++)
1019 : {
1020 0 : if ( pValue->Name == "ViewAreaTop" )
1021 : {
1022 0 : pValue->Value >>= nTmp;
1023 0 : aRect.setY( static_cast< long >(bTwip ? convertMm100ToTwip ( nTmp ) : nTmp) );
1024 : }
1025 0 : else if ( pValue->Name == "ViewAreaLeft" )
1026 : {
1027 0 : pValue->Value >>= nTmp;
1028 0 : aRect.setX( static_cast< long >(bTwip ? convertMm100ToTwip ( nTmp ) : nTmp) );
1029 : }
1030 0 : else if ( pValue->Name == "ViewAreaWidth" )
1031 : {
1032 0 : pValue->Value >>= nTmp;
1033 0 : Size aSize( aRect.GetSize() );
1034 0 : aSize.Width() = static_cast< long >(bTwip ? convertMm100ToTwip ( nTmp ) : nTmp);
1035 0 : aRect.SetSize( aSize );
1036 : }
1037 0 : else if ( pValue->Name == "ViewAreaHeight" )
1038 : {
1039 0 : pValue->Value >>= nTmp;
1040 0 : Size aSize( aRect.GetSize() );
1041 0 : aSize.Height() = static_cast< long >(bTwip ? convertMm100ToTwip ( nTmp ) : nTmp);
1042 0 : aRect.SetSize( aSize );
1043 : }
1044 0 : else if ( pValue->Name == "ShowRedlineChanges" )
1045 : {
1046 0 : bShowRedlineChanges = *(sal_Bool *)(pValue->Value.getValue());
1047 0 : bChangeShowRedline = sal_True;
1048 : }
1049 : // Headers and footers are not displayed in BrowseView anymore
1050 0 : else if ( pValue->Name == "InBrowseMode" )
1051 : {
1052 0 : bBrowseMode = *(sal_Bool *)(pValue->Value.getValue());
1053 0 : bChangeBrowseMode = sal_True;
1054 : }
1055 0 : pValue++;
1056 : }
1057 0 : if( pDoc->GetDocShell() )
1058 0 : pDoc->GetDocShell()->SetVisArea ( aRect );
1059 :
1060 0 : if (bChangeBrowseMode)
1061 0 : pDoc->set(IDocumentSettingAccess::BROWSE_MODE, bBrowseMode );
1062 :
1063 0 : if (bChangeShowRedline)
1064 0 : GetTextImport()->SetShowChanges( bShowRedlineChanges );
1065 : }
1066 :
1067 0 : void SwXMLImport::SetConfigurationSettings(const Sequence < PropertyValue > & aConfigProps)
1068 : {
1069 : // this method will modify the document directly -> lock SolarMutex
1070 0 : SolarMutexGuard aGuard;
1071 :
1072 0 : Reference< lang::XMultiServiceFactory > xFac( GetModel(), UNO_QUERY );
1073 0 : if( !xFac.is() )
1074 0 : return;
1075 :
1076 0 : Reference< XPropertySet > xProps( xFac->createInstance("com.sun.star.document.Settings"), UNO_QUERY );
1077 0 : if( !xProps.is() )
1078 0 : return;
1079 :
1080 0 : Reference< XPropertySetInfo > xInfo( xProps->getPropertySetInfo() );
1081 0 : if( !xInfo.is() )
1082 0 : return;
1083 :
1084 0 : boost::unordered_set< OUString, OUStringHash > aSet;
1085 0 : aSet.insert(OUString("ForbiddenCharacters"));
1086 0 : aSet.insert(OUString("IsKernAsianPunctuation"));
1087 0 : aSet.insert(OUString("CharacterCompressionType"));
1088 0 : aSet.insert(OUString("LinkUpdateMode"));
1089 0 : aSet.insert(OUString("FieldAutoUpdate"));
1090 0 : aSet.insert(OUString("ChartAutoUpdate"));
1091 0 : aSet.insert(OUString("AddParaTableSpacing"));
1092 0 : aSet.insert(OUString("AddParaTableSpacingAtStart"));
1093 0 : aSet.insert(OUString("PrintAnnotationMode"));
1094 0 : aSet.insert(OUString("PrintBlackFonts"));
1095 0 : aSet.insert(OUString("PrintControls"));
1096 0 : aSet.insert(OUString("PrintDrawings"));
1097 0 : aSet.insert(OUString("PrintGraphics"));
1098 0 : aSet.insert(OUString("PrintLeftPages"));
1099 0 : aSet.insert(OUString("PrintPageBackground"));
1100 0 : aSet.insert(OUString("PrintProspect"));
1101 0 : aSet.insert(OUString("PrintReversed"));
1102 0 : aSet.insert(OUString("PrintRightPages"));
1103 0 : aSet.insert(OUString("PrintFaxName"));
1104 0 : aSet.insert(OUString("PrintPaperFromSetup"));
1105 0 : aSet.insert(OUString("PrintTables"));
1106 0 : aSet.insert(OUString("PrintSingleJobs"));
1107 0 : aSet.insert(OUString("UpdateFromTemplate"));
1108 0 : aSet.insert(OUString("PrinterIndependentLayout"));
1109 0 : aSet.insert(OUString("PrintEmptyPages"));
1110 0 : aSet.insert(OUString("SmallCapsPercentage66"));
1111 0 : aSet.insert(OUString("TabOverflow"));
1112 0 : aSet.insert(OUString("UnbreakableNumberings"));
1113 0 : aSet.insert(OUString("ClippedPictures"));
1114 0 : aSet.insert(OUString("BackgroundParaOverDrawings"));
1115 0 : aSet.insert(OUString("TabOverMargin"));
1116 :
1117 0 : sal_Int32 nCount = aConfigProps.getLength();
1118 0 : const PropertyValue* pValues = aConfigProps.getConstArray();
1119 :
1120 0 : SvtSaveOptions aSaveOpt;
1121 0 : sal_Bool bIsUserSetting = aSaveOpt.IsLoadUserSettings(),
1122 0 : bSet = bIsUserSetting;
1123 :
1124 : // for some properties we don't want to use the application
1125 : // default if they're missing. So we watch for them in the loop
1126 : // below, and set them if not found
1127 0 : bool bPrinterIndependentLayout = false;
1128 0 : bool bUseOldNumbering = false;
1129 0 : bool bOutlineLevelYieldsOutlineRule = false;
1130 0 : bool bAddExternalLeading = false;
1131 0 : bool bAddParaSpacingToTableCells = false;
1132 0 : bool bUseFormerLineSpacing = false;
1133 0 : bool bUseFormerObjectPositioning = false;
1134 0 : bool bUseFormerTextWrapping = false;
1135 0 : bool bConsiderWrapOnObjPos = false;
1136 0 : bool bIgnoreFirstLineIndentInNumbering = false;
1137 0 : bool bDoNotJustifyLinesWithManualBreak = false;
1138 0 : bool bDoNotResetParaAttrsForNumFont = false;
1139 0 : bool bLoadReadonly = false;
1140 0 : bool bDoNotCaptureDrawObjsOnPage( false );
1141 0 : bool bClipAsCharacterAnchoredWriterFlyFrames( false );
1142 0 : bool bUnixForceZeroExtLeading = false;
1143 0 : bool bUseOldPrinterMetrics = false;
1144 0 : bool bSmallCapsPercentage66 = false;
1145 0 : bool bTabOverflow = false;
1146 0 : bool bUnbreakableNumberings = false;
1147 0 : bool bClippedPictures = false;
1148 0 : bool bBackgroundParaOverDrawings = false;
1149 0 : bool bTabOverMargin = false;
1150 :
1151 0 : OUString sRedlineProtectionKey( "RedlineProtectionKey" );
1152 :
1153 0 : const PropertyValue* currentDatabaseDataSource = NULL;
1154 0 : const PropertyValue* currentDatabaseCommand = NULL;
1155 0 : const PropertyValue* currentDatabaseCommandType = NULL;
1156 0 : OUString currentDatabaseDataSourceKey( "CurrentDatabaseDataSource" );
1157 0 : OUString currentDatabaseCommandKey( "CurrentDatabaseCommand" );
1158 0 : OUString currentDatabaseCommandTypeKey( "CurrentDatabaseCommandType" );
1159 :
1160 0 : while( nCount-- )
1161 : {
1162 0 : if( !bIsUserSetting )
1163 : {
1164 : // test over the hash value if the entry is in the table.
1165 0 : OUString aStr(pValues->Name);
1166 :
1167 0 : bSet = aSet.find(aStr) == aSet.end();
1168 : }
1169 :
1170 0 : if( bSet )
1171 : {
1172 : try
1173 : {
1174 0 : if( xInfo->hasPropertyByName( pValues->Name ) )
1175 : {
1176 0 : if( pValues->Name.equals( sRedlineProtectionKey ) )
1177 : {
1178 0 : Sequence<sal_Int8> aKey;
1179 0 : pValues->Value >>= aKey;
1180 0 : GetTextImport()->SetChangesProtectionKey( aKey );
1181 : }
1182 : else
1183 : {
1184 : // HACK: Setting these out of order does not work.
1185 0 : if( pValues->Name.equals( currentDatabaseDataSourceKey ))
1186 0 : currentDatabaseDataSource = pValues;
1187 0 : else if( pValues->Name.equals( currentDatabaseCommandKey ))
1188 0 : currentDatabaseCommand = pValues;
1189 0 : else if( pValues->Name.equals( currentDatabaseCommandTypeKey ))
1190 0 : currentDatabaseCommandType = pValues;
1191 : else
1192 0 : xProps->setPropertyValue( pValues->Name,
1193 0 : pValues->Value );
1194 : }
1195 : }
1196 :
1197 : // did we find any of the non-default cases?
1198 0 : if ( pValues->Name == "PrinterIndependentLayout" )
1199 0 : bPrinterIndependentLayout = true;
1200 0 : else if ( pValues->Name == "AddExternalLeading" )
1201 0 : bAddExternalLeading = true;
1202 0 : else if ( pValues->Name == "AddParaSpacingToTableCells" )
1203 0 : bAddParaSpacingToTableCells = true;
1204 0 : else if ( pValues->Name == "UseFormerLineSpacing" )
1205 0 : bUseFormerLineSpacing = true;
1206 0 : else if ( pValues->Name == "UseFormerObjectPositioning" )
1207 0 : bUseFormerObjectPositioning = true;
1208 0 : else if ( pValues->Name == "UseFormerTextWrapping" )
1209 0 : bUseFormerTextWrapping = true;
1210 0 : else if ( pValues->Name == "UseOldNumbering" )
1211 0 : bUseOldNumbering = true;
1212 0 : else if ( pValues->Name == "OutlineLevelYieldsNumbering" )
1213 0 : bOutlineLevelYieldsOutlineRule = true;
1214 0 : else if ( pValues->Name == "ConsiderTextWrapOnObjPos" )
1215 0 : bConsiderWrapOnObjPos = true;
1216 0 : else if ( pValues->Name == "IgnoreFirstLineIndentInNumbering" )
1217 0 : bIgnoreFirstLineIndentInNumbering = true;
1218 0 : else if ( pValues->Name == "DoNotJustifyLinesWithManualBreak" )
1219 0 : bDoNotJustifyLinesWithManualBreak = true;
1220 0 : else if ( pValues->Name == "DoNotResetParaAttrsForNumFont" )
1221 0 : bDoNotResetParaAttrsForNumFont = true;
1222 0 : else if ( pValues->Name == "LoadReadonly" )
1223 0 : bLoadReadonly = true;
1224 0 : else if ( pValues->Name == "DoNotCaptureDrawObjsOnPage" )
1225 0 : bDoNotCaptureDrawObjsOnPage = true;
1226 0 : else if ( pValues->Name == "ClipAsCharacterAnchoredWriterFlyFrames" )
1227 0 : bClipAsCharacterAnchoredWriterFlyFrames = true;
1228 0 : else if ( pValues->Name == "UnxForceZeroExtLeading" )
1229 0 : bUnixForceZeroExtLeading = true;
1230 0 : else if ( pValues->Name == "UseOldPrinterMetrics" )
1231 0 : bUseOldPrinterMetrics = true;
1232 0 : else if ( pValues->Name == "SmallCapsPercentage66" )
1233 0 : bSmallCapsPercentage66 = true;
1234 0 : else if ( pValues->Name == "TabOverflow" )
1235 0 : bTabOverflow = true;
1236 0 : else if ( pValues->Name == "UnbreakableNumberings" )
1237 0 : bUnbreakableNumberings = true;
1238 0 : else if ( pValues->Name == "ClippedPictures" )
1239 0 : bClippedPictures = true;
1240 0 : else if ( pValues->Name == "BackgroundParaOverDrawings" )
1241 0 : bBackgroundParaOverDrawings = true;
1242 0 : else if ( pValues->Name == "TabOverMargin" )
1243 0 : bTabOverMargin = true;
1244 : }
1245 0 : catch( Exception& )
1246 : {
1247 : OSL_FAIL( "SwXMLImport::SetConfigurationSettings: Exception!" );
1248 : }
1249 : }
1250 0 : pValues++;
1251 : }
1252 :
1253 : try
1254 : {
1255 0 : if( currentDatabaseDataSource != NULL )
1256 0 : xProps->setPropertyValue( currentDatabaseDataSource->Name, currentDatabaseDataSource->Value );
1257 0 : if( currentDatabaseCommand != NULL )
1258 0 : xProps->setPropertyValue( currentDatabaseCommand->Name, currentDatabaseCommand->Value );
1259 0 : if( currentDatabaseCommandType != NULL )
1260 0 : xProps->setPropertyValue( currentDatabaseCommandType->Name, currentDatabaseCommandType->Value );
1261 0 : } catch( Exception& )
1262 : {
1263 : OSL_FAIL( "SwXMLImport::SetConfigurationSettings: Exception!" );
1264 : }
1265 :
1266 : // finally, treat the non-default cases
1267 : // introduce boolean, that indicates a document, written by version prior SO8.
1268 0 : const bool bDocumentPriorSO8 = !bConsiderWrapOnObjPos;
1269 :
1270 0 : if( ! bPrinterIndependentLayout )
1271 : {
1272 0 : Any aAny;
1273 0 : sal_Int16 nTmp = document::PrinterIndependentLayout::DISABLED;
1274 0 : aAny <<= nTmp;
1275 0 : xProps->setPropertyValue(
1276 : OUString("PrinterIndependentLayout"),
1277 0 : aAny );
1278 : }
1279 :
1280 0 : if( ! bAddExternalLeading )
1281 : {
1282 0 : xProps->setPropertyValue(
1283 0 : OUString("AddExternalLeading"), makeAny( false ) );
1284 : }
1285 :
1286 0 : if( ! bUseFormerLineSpacing )
1287 : {
1288 0 : xProps->setPropertyValue(
1289 0 : OUString("UseFormerLineSpacing"), makeAny( true ) );
1290 : }
1291 :
1292 0 : if( !bUseFormerObjectPositioning )
1293 : {
1294 0 : xProps->setPropertyValue(
1295 0 : OUString("UseFormerObjectPositioning"), makeAny( true ) );
1296 : }
1297 :
1298 0 : if( !bUseOldNumbering )
1299 : {
1300 0 : Any aAny;
1301 0 : sal_Bool bOldNum = true;
1302 0 : aAny.setValue(&bOldNum, ::getBooleanCppuType());
1303 0 : xProps->setPropertyValue
1304 : (OUString("UseOldNumbering"),
1305 0 : aAny );
1306 : }
1307 :
1308 0 : if( !bOutlineLevelYieldsOutlineRule )
1309 : {
1310 0 : Any aAny;
1311 0 : sal_Bool bTmp = true;
1312 0 : aAny.setValue(&bTmp, ::getBooleanCppuType());
1313 0 : xProps->setPropertyValue
1314 : (OUString("OutlineLevelYieldsNumbering"),
1315 0 : aAny );
1316 : }
1317 :
1318 0 : if( !bAddParaSpacingToTableCells )
1319 : {
1320 0 : xProps->setPropertyValue(
1321 0 : OUString("AddParaSpacingToTableCells"), makeAny( false ) );
1322 : }
1323 :
1324 0 : if( !bUseFormerTextWrapping )
1325 : {
1326 0 : xProps->setPropertyValue(
1327 0 : OUString("UseFormerTextWrapping"), makeAny( true ) );
1328 : }
1329 :
1330 0 : if( !bConsiderWrapOnObjPos )
1331 : {
1332 0 : xProps->setPropertyValue(
1333 0 : OUString("ConsiderTextWrapOnObjPos"), makeAny( false ) );
1334 : }
1335 :
1336 : // #i47448#
1337 : // For SO7pp4, part of the 'new numbering' stuff has been backported from
1338 : // SO8. Unfortunately, only part of it and by using the same compatibility option
1339 : // like in SO8. Therefore documents generated with SO7pp4, containing
1340 : // numbered paragraphs with first line indent differ between SO7pp4 and
1341 : // SO8. In order to fix this for SO8pp1, I introduce a new compatiblity
1342 : // flag 'bIgnoreFirstLineIndentInNumbering'. This flag has to be set for all
1343 : // documents < SO8, but not for SO8. So if the property is not present, the
1344 : // flag will be set to 'true'. SO8 documents surely have the
1345 : // 'ConsiderWrapOnObjPos' property set (no matter if 'true' or 'false'),
1346 : // therefore the correct condition to set this flag is this:
1347 0 : if( !bIgnoreFirstLineIndentInNumbering && bDocumentPriorSO8 )
1348 : {
1349 0 : xProps->setPropertyValue(
1350 0 : OUString("IgnoreFirstLineIndentInNumbering"), makeAny( true ) );
1351 : }
1352 :
1353 : // This flag has to be set for all documents < SO8
1354 0 : if ( !bDoNotJustifyLinesWithManualBreak && bDocumentPriorSO8 )
1355 : {
1356 0 : xProps->setPropertyValue(
1357 0 : OUString("DoNotJustifyLinesWithManualBreak"), makeAny( true ) );
1358 : }
1359 :
1360 : // This flag has to be set for all documents < SO8
1361 0 : if ( !bDoNotResetParaAttrsForNumFont && bDocumentPriorSO8 )
1362 : {
1363 0 : xProps->setPropertyValue(
1364 0 : OUString("DoNotResetParaAttrsForNumFont"), makeAny( true ) );
1365 : }
1366 :
1367 0 : if ( !bLoadReadonly )
1368 : {
1369 0 : xProps->setPropertyValue(
1370 0 : OUString("LoadReadonly"), makeAny( false ) );
1371 : }
1372 :
1373 : // This flag has to be set for all documents < SO8
1374 0 : if ( !bDoNotCaptureDrawObjsOnPage && bDocumentPriorSO8 )
1375 : {
1376 0 : xProps->setPropertyValue(
1377 0 : OUString("DoNotCaptureDrawObjsOnPage"), makeAny( true ) );
1378 : }
1379 :
1380 : // This flag has to be set for all documents < SO8
1381 0 : if ( !bClipAsCharacterAnchoredWriterFlyFrames && bDocumentPriorSO8 )
1382 : {
1383 0 : xProps->setPropertyValue(
1384 0 : OUString("ClipAsCharacterAnchoredWriterFlyFrames"), makeAny( true ) );
1385 : }
1386 :
1387 0 : if ( !bUnixForceZeroExtLeading )
1388 : {
1389 0 : xProps->setPropertyValue(
1390 0 : OUString("UnxForceZeroExtLeading"), makeAny( true ) );
1391 : }
1392 :
1393 0 : if ( !bUseOldPrinterMetrics )
1394 : {
1395 0 : xProps->setPropertyValue(
1396 0 : OUString("UseOldPrinterMetrics"), makeAny( true ) );
1397 : }
1398 :
1399 : // Old LO versions had 66 as the value for small caps percentage, later changed to 80.
1400 : // In order to keep backwards compatibility, SmallCapsPercentage66 option is written to .odt
1401 : // files, and the default for new documents is 'false'. Files without this option
1402 : // are considered to be old files, so set the compatibility option too.
1403 0 : if ( !bSmallCapsPercentage66 )
1404 : {
1405 0 : xProps->setPropertyValue(
1406 0 : OUString("SmallCapsPercentage66"), makeAny( true ) );
1407 : }
1408 :
1409 0 : if ( !bTabOverflow )
1410 : {
1411 0 : xProps->setPropertyValue(
1412 0 : OUString("TabOverflow"), makeAny( false ) );
1413 : }
1414 :
1415 0 : if ( !bUnbreakableNumberings )
1416 : {
1417 0 : xProps->setPropertyValue(
1418 0 : OUString("UnbreakableNumberings"), makeAny( false ) );
1419 : }
1420 :
1421 0 : if ( !bClippedPictures )
1422 : {
1423 0 : xProps->setPropertyValue(
1424 0 : OUString("ClippedPictures"), makeAny( false ) );
1425 : }
1426 :
1427 0 : if ( !bBackgroundParaOverDrawings )
1428 0 : xProps->setPropertyValue("BackgroundParaOverDrawings", makeAny( false ) );
1429 :
1430 0 : if ( !bTabOverMargin )
1431 0 : xProps->setPropertyValue("TabOverMargin", makeAny( false ) );
1432 :
1433 0 : SwDoc *pDoc = getDoc();
1434 0 : SfxPrinter *pPrinter = pDoc->getPrinter( false );
1435 0 : if( pPrinter )
1436 : {
1437 : // If the printer is known, then the OLE objects will
1438 : // already have correct sizes, and we don't have to call
1439 : // PrtOLENotify again. Otherwise we have to call it.
1440 : // The flag might be set from setting the printer, so it
1441 : // it is required to clear it.
1442 0 : pDoc->SetOLEPrtNotifyPending( !pPrinter->IsKnown() );
1443 0 : }
1444 : }
1445 :
1446 0 : void SwXMLImport::SetDocumentSpecificSettings(
1447 : const OUString& _rSettingsGroupName,
1448 : const Sequence< PropertyValue>& _rSettings )
1449 : {
1450 : // the only doc-specific settings group we know so far are the XForms settings
1451 0 : if ( !IsXMLToken( _rSettingsGroupName, XML_XFORM_MODEL_SETTINGS ) )
1452 0 : return;
1453 :
1454 : // preserve the settings for a later iteration - we are currently reading the settings.xml,
1455 : // the content.xml will be read later, by another instance of SwXMLImport
1456 : OSL_ENSURE( xLateInitSettings.is(), "SwXMLImport::SetDocumentSpecificSettings: no storage for those settings!" );
1457 0 : if ( !xLateInitSettings.is() )
1458 0 : return;
1459 :
1460 : try
1461 : {
1462 0 : if ( xLateInitSettings->hasByName( _rSettingsGroupName ) )
1463 : {
1464 0 : xLateInitSettings->replaceByName( _rSettingsGroupName, makeAny( _rSettings ) );
1465 : OSL_FAIL( "SwXMLImport::SetDocumentSpecificSettings: already have settings for this model!" );
1466 : }
1467 : else
1468 0 : xLateInitSettings->insertByName( _rSettingsGroupName, makeAny( _rSettings ) );
1469 : }
1470 0 : catch( const Exception& )
1471 : {
1472 : }
1473 : }
1474 :
1475 0 : void SwXMLImport::initialize(
1476 : const Sequence<Any>& aArguments )
1477 : throw( uno::Exception, uno::RuntimeException, std::exception)
1478 : {
1479 : // delegate to super class
1480 0 : SvXMLImport::initialize(aArguments);
1481 :
1482 : // we are only looking for a PropertyValue "PreserveRedlineMode"
1483 0 : sal_Int32 nLength = aArguments.getLength();
1484 0 : for(sal_Int32 i = 0; i < nLength; i++)
1485 : {
1486 0 : beans::PropertyValue aValue;
1487 0 : if ( aArguments[i] >>= aValue )
1488 : {
1489 0 : if (aValue.Name == "PreserveRedlineMode")
1490 : {
1491 0 : OSL_VERIFY( aValue.Value >>= bPreserveRedlineMode );
1492 : }
1493 0 : continue;
1494 : }
1495 :
1496 0 : beans::NamedValue aNamedValue;
1497 0 : if ( aArguments[i] >>= aNamedValue )
1498 : {
1499 0 : if (aNamedValue.Name == "LateInitSettings")
1500 : {
1501 0 : OSL_VERIFY( aNamedValue.Value >>= xLateInitSettings );
1502 : }
1503 : }
1504 0 : }
1505 0 : }
1506 :
1507 : // UNO component registration helper functions
1508 0 : OUString SAL_CALL SwXMLImport_getImplementationName() throw()
1509 : {
1510 : return OUString(
1511 0 : "com.sun.star.comp.Writer.XMLOasisImporter" );
1512 : }
1513 :
1514 0 : uno::Sequence< OUString > SAL_CALL SwXMLImport_getSupportedServiceNames()
1515 : throw()
1516 : {
1517 0 : const OUString aServiceName( SwXMLImport_getImplementationName() );
1518 0 : const uno::Sequence< OUString > aSeq( &aServiceName, 1 );
1519 0 : return aSeq;
1520 : }
1521 :
1522 0 : uno::Reference< uno::XInterface > SAL_CALL SwXMLImport_createInstance(
1523 : const uno::Reference< lang::XMultiServiceFactory > & rSMgr)
1524 : throw( uno::Exception )
1525 : {
1526 0 : return (cppu::OWeakObject*)new SwXMLImport( comphelper::getComponentContext(rSMgr), SwXMLImport_getImplementationName(), IMPORT_ALL );
1527 : }
1528 :
1529 0 : OUString SAL_CALL SwXMLImportStyles_getImplementationName() throw()
1530 : {
1531 : return OUString(
1532 0 : "com.sun.star.comp.Writer.XMLOasisStylesImporter" );
1533 : }
1534 :
1535 0 : uno::Sequence< OUString > SAL_CALL SwXMLImportStyles_getSupportedServiceNames()
1536 : throw()
1537 : {
1538 0 : const OUString aServiceName( SwXMLImportStyles_getImplementationName() );
1539 0 : const uno::Sequence< OUString > aSeq( &aServiceName, 1 );
1540 0 : return aSeq;
1541 : }
1542 :
1543 0 : uno::Reference< uno::XInterface > SAL_CALL SwXMLImportStyles_createInstance(
1544 : const uno::Reference< lang::XMultiServiceFactory > & rSMgr)
1545 : throw( uno::Exception )
1546 : {
1547 : return (cppu::OWeakObject*)new SwXMLImport(
1548 : comphelper::getComponentContext(rSMgr),
1549 : SwXMLImportStyles_getImplementationName(),
1550 : IMPORT_STYLES | IMPORT_MASTERSTYLES | IMPORT_AUTOSTYLES |
1551 0 : IMPORT_FONTDECLS );
1552 : }
1553 :
1554 0 : OUString SAL_CALL SwXMLImportContent_getImplementationName() throw()
1555 : {
1556 : return OUString(
1557 0 : "com.sun.star.comp.Writer.XMLOasisContentImporter" );
1558 : }
1559 :
1560 0 : uno::Sequence< OUString > SAL_CALL SwXMLImportContent_getSupportedServiceNames()
1561 : throw()
1562 : {
1563 0 : const OUString aServiceName( SwXMLImportContent_getImplementationName() );
1564 0 : const uno::Sequence< OUString > aSeq( &aServiceName, 1 );
1565 0 : return aSeq;
1566 : }
1567 :
1568 0 : uno::Reference< uno::XInterface > SAL_CALL SwXMLImportContent_createInstance(
1569 : const uno::Reference< lang::XMultiServiceFactory > & rSMgr)
1570 : throw( uno::Exception )
1571 : {
1572 : return (cppu::OWeakObject*)new SwXMLImport(
1573 : comphelper::getComponentContext(rSMgr),
1574 : SwXMLImportContent_getImplementationName(),
1575 : IMPORT_AUTOSTYLES | IMPORT_CONTENT | IMPORT_SCRIPTS |
1576 0 : IMPORT_FONTDECLS );
1577 : }
1578 :
1579 0 : OUString SAL_CALL SwXMLImportMeta_getImplementationName() throw()
1580 : {
1581 : return OUString(
1582 0 : "com.sun.star.comp.Writer.XMLOasisMetaImporter" );
1583 : }
1584 :
1585 0 : uno::Sequence< OUString > SAL_CALL SwXMLImportMeta_getSupportedServiceNames()
1586 : throw()
1587 : {
1588 0 : const OUString aServiceName( SwXMLImportMeta_getImplementationName() );
1589 0 : const uno::Sequence< OUString > aSeq( &aServiceName, 1 );
1590 0 : return aSeq;
1591 : }
1592 :
1593 0 : uno::Reference< uno::XInterface > SAL_CALL SwXMLImportMeta_createInstance(
1594 : const uno::Reference< lang::XMultiServiceFactory > & rSMgr)
1595 : throw( uno::Exception )
1596 : {
1597 0 : return (cppu::OWeakObject*)new SwXMLImport( comphelper::getComponentContext(rSMgr), SwXMLImportMeta_getImplementationName(), IMPORT_META );
1598 : }
1599 :
1600 0 : OUString SAL_CALL SwXMLImportSettings_getImplementationName() throw()
1601 : {
1602 : return OUString(
1603 0 : "com.sun.star.comp.Writer.XMLOasisSettingsImporter" );
1604 : }
1605 :
1606 0 : uno::Sequence< OUString > SAL_CALL SwXMLImportSettings_getSupportedServiceNames()
1607 : throw()
1608 : {
1609 0 : const OUString aServiceName( SwXMLImportSettings_getImplementationName() );
1610 0 : const uno::Sequence< OUString > aSeq( &aServiceName, 1 );
1611 0 : return aSeq;
1612 : }
1613 :
1614 0 : uno::Reference< uno::XInterface > SAL_CALL SwXMLImportSettings_createInstance(
1615 : const uno::Reference< lang::XMultiServiceFactory > & rSMgr)
1616 : throw( uno::Exception )
1617 : {
1618 0 : return (cppu::OWeakObject*)new SwXMLImport( comphelper::getComponentContext(rSMgr), SwXMLImportSettings_getImplementationName(), IMPORT_SETTINGS );
1619 : }
1620 :
1621 0 : SwDoc* SwImport::GetDocFromXMLImport( SvXMLImport& rImport )
1622 : {
1623 0 : uno::Reference<lang::XUnoTunnel> xModelTunnel( rImport.GetModel(), uno::UNO_QUERY );
1624 : SwXTextDocument *pTxtDoc = reinterpret_cast< SwXTextDocument *>(
1625 0 : sal::static_int_cast< sal_IntPtr >( xModelTunnel->getSomething(SwXTextDocument::getUnoTunnelId() )));
1626 : OSL_ENSURE( pTxtDoc, "Where is my model?" );
1627 : OSL_ENSURE( pTxtDoc->GetDocShell(), "Where is my shell?" );
1628 0 : SwDoc* pDoc = pTxtDoc->GetDocShell()->GetDoc();
1629 : OSL_ENSURE( pDoc, "Where is my document?" );
1630 0 : return pDoc;
1631 : }
1632 :
1633 0 : void SwXMLImport::initXForms()
1634 : {
1635 : // obtain SwDoc
1636 0 : Reference<XUnoTunnel> xDocTunnel( GetModel(), UNO_QUERY );
1637 0 : if( ! xDocTunnel.is() )
1638 0 : return;
1639 : SwXTextDocument* pXTextDocument = reinterpret_cast<SwXTextDocument*>(
1640 0 : xDocTunnel->getSomething( SwXTextDocument::getUnoTunnelId() ) );
1641 0 : if( pXTextDocument == NULL )
1642 0 : return;
1643 :
1644 0 : SwDoc *pDoc = pXTextDocument->GetDocShell()->GetDoc();
1645 :
1646 : // init XForms (if not already done)
1647 : // (no default model, since we'll load the models)
1648 0 : if( ! pDoc->isXForms() )
1649 0 : pDoc->initXForms( false );
1650 :
1651 0 : bInititedXForms = true;
1652 : }
1653 :
1654 0 : SwDoc* SwXMLImport::getDoc()
1655 : {
1656 0 : if( doc != NULL )
1657 0 : return doc;
1658 0 : Reference < XTextDocument > xTextDoc( GetModel(), UNO_QUERY );
1659 0 : Reference < XText > xText = xTextDoc->getText();
1660 0 : Reference<XUnoTunnel> xTextTunnel( xText, UNO_QUERY);
1661 : assert( xTextTunnel.is());
1662 : SwXText *pText = reinterpret_cast< SwXText *>(
1663 0 : sal::static_int_cast< sal_IntPtr >( xTextTunnel->getSomething( SwXText::getUnoTunnelId() )));
1664 : assert( pText != NULL );
1665 0 : doc = pText->GetDoc();
1666 : assert( doc != NULL );
1667 0 : return doc;
1668 : }
1669 :
1670 0 : const SwDoc* SwXMLImport::getDoc() const
1671 : {
1672 0 : return const_cast< SwXMLImport* >( this )->getDoc();
1673 : }
1674 :
1675 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|