1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * Copyright 2000, 2010 Oracle and/or its affiliates.
8 * OpenOffice.org - a multi-platform office productivity suite
10 * This file is part of OpenOffice.org.
12 * OpenOffice.org is free software: you can redistribute it and/or modify
13 * it under the terms of the GNU Lesser General Public License version 3
14 * only, as published by the Free Software Foundation.
16 * OpenOffice.org is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Lesser General Public License version 3 for more details
20 * (a copy is included in the LICENSE file that accompanied this code).
22 * You should have received a copy of the GNU Lesser General Public License
23 * version 3 along with OpenOffice.org. If not, see
24 * <http://www.openoffice.org/license.html>
25 * for a copy of the LGPLv3 License.
27 ************************************************************************/
29 // MARKER(update_precomp.py): autogen include statement, do not remove
30 #include "precompiled_filter.hxx"
31 #include <com/sun/star/frame/XConfigManager.hpp>
32 #include <com/sun/star/xml/sax/XDocumentHandler.hpp>
33 #include <com/sun/star/document/XGraphicObjectResolver.hpp>
34 #include <com/sun/star/document/XEmbeddedObjectResolver.hpp>
35 #include <com/sun/star/xml/XImportFilter.hpp>
36 #include <com/sun/star/xml/XExportFilter.hpp>
37 #include <com/sun/star/io/XActiveDataSource.hpp>
38 #include <com/sun/star/document/XDocumentPropertiesSupplier.hpp>
39 #include <com/sun/star/frame/XComponentLoader.hpp>
40 #include <com/sun/star/frame/XStorable.hpp>
41 #include <com/sun/star/beans/XPropertySet.hpp>
42 #include <com/sun/star/frame/XDesktop.hpp>
43 #include <com/sun/star/document/XFilter.hpp>
44 #include <comphelper/oslfile2streamwrap.hxx>
45 #include <com/sun/star/document/XExporter.hpp>
46 #include <com/sun/star/task/XInteractionHandler.hpp>
48 #include "com/sun/star/ui/dialogs/TemplateDescription.hpp"
49 #include <vcl/svapp.hxx>
50 #include <osl/mutex.hxx>
51 #include <sfx2/filedlghelper.hxx>
52 #include <osl/file.hxx>
53 #include <unotools/tempfile.hxx>
54 #include <tools/urlobj.hxx>
56 #include "xmlfilterdialogstrings.hrc"
57 #include "xmlfiltersettingsdialog.hxx"
58 #include "xmlfiltertestdialog.hxx"
59 #include "xmlfiltertestdialog.hrc"
60 #include "xmlfileview.hxx"
66 using namespace comphelper
;
67 using namespace com::sun::star::lang
;
68 using namespace com::sun::star::beans
;
69 using namespace com::sun::star::container
;
70 using namespace com::sun::star::document
;
71 using namespace com::sun::star::frame
;
72 using namespace com::sun::star::task
;
73 using namespace com::sun::star::uno
;
74 using namespace com::sun::star::io
;
75 using namespace com::sun::star::xml
;
76 using namespace com::sun::star::xml::sax
;
78 class GlobalEventListenerImpl
: public ::cppu::WeakImplHelper1
< com::sun::star::document::XEventListener
>
81 GlobalEventListenerImpl( XMLFilterTestDialog
* pDialog
);
84 virtual void SAL_CALL
notifyEvent( const com::sun::star::document::EventObject
& Event
) throw (RuntimeException
);
86 // lang::XEventListener
87 virtual void SAL_CALL
disposing( const com::sun::star::lang::EventObject
& Source
) throw (RuntimeException
);
89 XMLFilterTestDialog
* mpDialog
;
92 GlobalEventListenerImpl::GlobalEventListenerImpl( XMLFilterTestDialog
* pDialog
)
97 void SAL_CALL
GlobalEventListenerImpl::notifyEvent( const com::sun::star::document::EventObject
& Event
) throw (RuntimeException
)
99 ::SolarMutexGuard aGuard
;
100 if( (Event
.EventName
.compareToAscii( RTL_CONSTASCII_STRINGPARAM("OnFocus") ) == 0) ||
101 (Event
.EventName
.compareToAscii( RTL_CONSTASCII_STRINGPARAM("OnUnload") ) == 0) )
103 Reference
< XComponent
> xComp( Event
.Source
, UNO_QUERY
);
104 mpDialog
->updateCurrentDocumentButtonState( &xComp
);
108 void SAL_CALL
GlobalEventListenerImpl::disposing( const com::sun::star::lang::EventObject
& /* Source */ ) throw (RuntimeException
)
112 /** returns true if the given component supports the given service */
113 static bool checkComponent( Reference
< XComponent
>& rxComponent
, const OUString
& rServiceName
)
117 Reference
< XServiceInfo
> xInfo( rxComponent
, UNO_QUERY
);
120 if( xInfo
->supportsService( rServiceName
) )
122 // special case for impress documents which supports same service as draw documents
123 if( rServiceName
.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "com.sun.star.drawing.DrawingDocument" ) ) )
125 // so if we want a draw we need to check if its not an impress
126 if( !xInfo
->supportsService( OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.presentation.PresentationDocument") ) ) )
138 DBG_ERROR( "checkComponent exception catched!" );
144 XMLFilterTestDialog::XMLFilterTestDialog( Window
* pParent
, ResMgr
& rResMgr
, const com::sun::star::uno::Reference
< com::sun::star::lang::XMultiServiceFactory
>& rxMSF
) :
145 ModalDialog( pParent
, ResId( DLG_XML_FILTER_TEST_DIALOG
, rResMgr
) ),
149 maFLExport( this, ResId( FL_EXPORT
, rResMgr
) ),
150 maFTExportXSLT( this, ResId( FT_EXPORT_XSLT
, rResMgr
) ),
151 maFTExportXSLTFile( this, ResId( FT_EXPORT_XSLT_FILE
, rResMgr
) ),
152 maFTTransformDocument( this, ResId( FT_TRANSFORM_DOCUMENT
, rResMgr
) ),
153 maPBExportBrowse( this, ResId( PB_EXPORT_BROWSE
, rResMgr
) ),
154 maPBCurrentDocument( this, ResId( PB_CURRENT_DOCUMENT
, rResMgr
) ),
155 maFTNameOfCurentFile( this, ResId( FT_NAME_OF_CURRENT_FILE
, rResMgr
) ),
156 maFLImport( this, ResId( FL_IMPORT
, rResMgr
) ),
157 maFTImportXSLT( this, ResId( FT_IMPORT_XSLT
, rResMgr
) ),
158 maFTImportXSLTFile( this, ResId( FT_IMPORT_XSLT_FILE
, rResMgr
) ),
159 maFTImportTemplate( this, ResId( FT_IMPORT_TEMPLATE
, rResMgr
) ),
160 maFTImportTemplateFile( this, ResId( FT_IMPORT_TEMPLATE_FILE
, rResMgr
) ),
161 maFTTransformFile( this, ResId( FT_TRANSFORM_FILE
, rResMgr
) ),
162 maCBXDisplaySource( this, ResId( CBX_DISPLAY_SOURCE
, rResMgr
) ),
163 maPBImportBrowse( this, ResId( PB_IMPORT_BROWSE
, rResMgr
) ),
164 maPBRecentDocument( this, ResId( PB_RECENT_DOCUMENT
, rResMgr
) ),
165 maFTNameOfRecentFile( this, ResId( FT_NAME_OF_RECENT_FILE
, rResMgr
) ),
166 maPBClose( this, ResId( PB_CLOSE
, rResMgr
) ),
167 maPBHelp( this, ResId( PB_HELP
, rResMgr
) ),
169 mpFilterInfo( NULL
),
170 sDTDPath( RTL_CONSTASCII_USTRINGPARAM( "$(inst)/share/dtd/officedocument/1_0/office.dtd" ) )
174 maPBExportBrowse
.SetClickHdl(LINK( this, XMLFilterTestDialog
, ClickHdl_Impl
) );
175 maPBCurrentDocument
.SetClickHdl(LINK( this, XMLFilterTestDialog
, ClickHdl_Impl
) );
176 maPBImportBrowse
.SetClickHdl(LINK( this, XMLFilterTestDialog
, ClickHdl_Impl
) );
177 maPBRecentDocument
.SetClickHdl(LINK( this, XMLFilterTestDialog
, ClickHdl_Impl
) );
178 maPBClose
.SetClickHdl(LINK( this, XMLFilterTestDialog
, ClickHdl_Impl
) );
180 maDialogTitle
= GetText();
184 Reference
< XConfigManager
> xCfgMgr( mxMSF
->createInstance( OUString::createFromAscii("com.sun.star.config.SpecialConfigManager")), UNO_QUERY
);
186 sDTDPath
= xCfgMgr
->substituteVariables( sDTDPath
);
188 mxGlobalBroadcaster
= Reference
< XEventBroadcaster
>::query( mxMSF
->createInstance(::rtl::OUString::createFromAscii("com.sun.star.frame.GlobalEventBroadcaster") ) );
189 if ( mxGlobalBroadcaster
.is() )
191 mxGlobalEventListener
= new GlobalEventListenerImpl( this );
192 mxGlobalBroadcaster
->addEventListener( mxGlobalEventListener
);
197 DBG_ERROR( "XMLFilterTestDialog::XMLFilterTestDialog exception catched!" );
201 XMLFilterTestDialog::~XMLFilterTestDialog()
205 if( mxGlobalBroadcaster
.is() )
206 mxGlobalBroadcaster
->removeEventListener( mxGlobalEventListener
);
210 DBG_ERROR( "XMLFilterTestDialog::~XMLFilterTestDialog exception catched!" );
217 void XMLFilterTestDialog::test( const filter_info_impl
& rFilterInfo
)
220 mpFilterInfo
= new filter_info_impl( rFilterInfo
);
222 maImportRecentFile
= OUString();
229 static OUString
getFileNameFromURL( OUString
& rURL
)
231 INetURLObject
aURL( rURL
);
232 OUString
aName( aURL
.getName(INetURLObject::LAST_SEGMENT
, sal_True
, INetURLObject::DECODE_WITH_CHARSET
) );
236 void XMLFilterTestDialog::updateCurrentDocumentButtonState( Reference
< XComponent
> * pRef
/* = NULL */ )
238 if( pRef
&& pRef
->is() )
240 if( checkComponent( *pRef
, mpFilterInfo
->maDocumentService
) )
241 mxLastFocusModel
= *pRef
;
244 bool bExport
= (mpFilterInfo
->maFlags
& 2) == 2;
245 Reference
< XComponent
> xCurrentDocument
;
247 xCurrentDocument
= getFrontMostDocument( mpFilterInfo
->maDocumentService
);
248 maPBCurrentDocument
.Enable( bExport
&& xCurrentDocument
.is() );
249 maFTNameOfCurentFile
.Enable( bExport
&& xCurrentDocument
.is() );
251 if( xCurrentDocument
.is() )
254 Reference
< XDocumentPropertiesSupplier
> xDPS( xCurrentDocument
, UNO_QUERY
);
257 Reference
< XDocumentProperties
> xProps( xDPS
->getDocumentProperties() );
260 aTitle
= xProps
->getTitle();
264 if( 0 == aTitle
.getLength() )
266 Reference
< XStorable
> xStorable( xCurrentDocument
, UNO_QUERY
);
269 if( xStorable
->hasLocation() )
271 OUString
aURL( xStorable
->getLocation() );
272 aTitle
= getFileNameFromURL( aURL
);
277 maFTNameOfCurentFile
.SetText( aTitle
);
281 void XMLFilterTestDialog::initDialog()
283 DBG_ASSERT( mpFilterInfo
, "i need a filter I can test!" );
284 if( NULL
== mpFilterInfo
)
287 String
aTitle( maDialogTitle
);
288 aTitle
.SearchAndReplace( String( RTL_CONSTASCII_USTRINGPARAM("%s") ), mpFilterInfo
->maFilterName
);
292 bool bImport
= (mpFilterInfo
->maFlags
& 1) == 1;
293 bool bExport
= (mpFilterInfo
->maFlags
& 2) == 2;
295 updateCurrentDocumentButtonState();
297 maFLExport
.Enable( bExport
);
298 maFTExportXSLT
.Enable( bExport
);
299 maFTExportXSLTFile
.Enable( bExport
);
300 maFTTransformDocument
.Enable( bExport
);
301 maPBExportBrowse
.Enable( bExport
);
303 maFTExportXSLTFile
.SetText( getFileNameFromURL( mpFilterInfo
->maExportXSLT
) );
307 maFLImport
.Enable( bImport
);
308 maFTImportXSLT
.Enable( bImport
);
309 maFTImportXSLTFile
.Enable( bImport
);
310 maFTImportTemplate
.Enable( bImport
&& mpFilterInfo
->maImportTemplate
.getLength() );
311 maFTImportTemplateFile
.Enable( bImport
&& mpFilterInfo
->maImportTemplate
.getLength() );
312 maFTTransformFile
.Enable( bImport
);
313 maCBXDisplaySource
.Enable( bImport
);
314 maPBImportBrowse
.Enable( bImport
);
315 maPBRecentDocument
.Enable( bImport
&& maImportRecentFile
.getLength() );
316 maFTNameOfRecentFile
.Enable( bImport
&& maImportRecentFile
.getLength() );
318 maFTImportXSLTFile
.SetText( getFileNameFromURL( mpFilterInfo
->maImportXSLT
) );
319 maFTImportTemplateFile
.SetText( getFileNameFromURL( mpFilterInfo
->maImportTemplate
) );
320 maFTNameOfRecentFile
.SetText( getFileNameFromURL( maImportRecentFile
) );
323 void XMLFilterTestDialog::onExportBrowse()
327 // Open Fileopen-Dialog
328 ::sfx2::FileDialogHelper
aDlg(
329 com::sun::star::ui::dialogs::TemplateDescription::FILEOPEN_SIMPLE
,
332 Reference
< XNameAccess
> xFilterContainer( mxMSF
->createInstance( OUString::createFromAscii("com.sun.star.document.FilterFactory" ) ), UNO_QUERY
);
333 Reference
< XNameAccess
> xTypeDetection( mxMSF
->createInstance( OUString::createFromAscii("com.sun.star.document.TypeDetection" ) ), UNO_QUERY
);
334 if( xFilterContainer
.is() && xTypeDetection
.is() )
336 Sequence
< OUString
> aFilterNames( xFilterContainer
->getElementNames() );
337 OUString
* pFilterName
= aFilterNames
.getArray();
339 for( sal_Int32 nFilter
= 0; nFilter
< aFilterNames
.getLength(); nFilter
++, pFilterName
++ )
341 Sequence
< PropertyValue
> aValues
;
343 Any
aAny( xFilterContainer
->getByName( *pFilterName
) );
344 if( !(aAny
>>= aValues
) )
347 OUString aInterfaceName
;
348 PropertyValue
* pValues
= aValues
.getArray();
349 OUString aType
, aService
;
350 sal_Int32
nFlags( 0 );
354 for( sal_Int32 nValue
= 0; (nValue
< aValues
.getLength()) && (nFound
!= 15); nValue
++, pValues
++ )
356 if( pValues
->Name
.equalsAscii( "Type" ) )
358 pValues
->Value
>>= aType
;
361 else if( pValues
->Name
.equalsAscii( "DocumentService" ) )
363 pValues
->Value
>>= aService
;
366 else if( pValues
->Name
.equalsAscii( "Flags" ) )
368 pValues
->Value
>>= nFlags
;
371 if( pValues
->Name
.equalsAscii( "UIName" ) )
373 pValues
->Value
>>= aInterfaceName
;
379 if( (nFound
== 15) && (aType
.getLength() && aService
== mpFilterInfo
->maDocumentService
) )
381 // see if this filter is not supressed in dialog
382 if( (nFlags
& 0x1000) == 0 )
384 aAny
= xTypeDetection
->getByName( aType
);
385 Sequence
< PropertyValue
> aValues2
;
387 if( aAny
>>= aValues2
)
389 PropertyValue
* pValues2
= aValues2
.getArray();
393 for( nValue
= 0; nValue
< aValues2
.getLength(); nValue
++, pValues2
++ )
395 if( pValues2
->Name
.equalsAscii( "Extensions" ) )
397 Sequence
< OUString
> aExtensions
;
398 if( pValues2
->Value
>>= aExtensions
)
400 const sal_Int32
nCount( aExtensions
.getLength() );
401 OUString
* pExtensions
= aExtensions
.getArray();
403 for( n
= 0; n
< nCount
; n
++ )
406 aExtension
+= OUString( sal_Unicode(';') );
407 aExtension
+= OUString::createFromAscii("*.");
408 aExtension
+= (*pExtensions
++);
414 String
aExtensions( aExtension
);
415 String
aFilterName( aInterfaceName
);
416 aFilterName
+= String( RTL_CONSTASCII_USTRINGPARAM(" (") );
417 aFilterName
+= aExtensions
;
418 aFilterName
+= sal_Unicode(')');
420 aDlg
.AddFilter( aFilterName
, aExtensions
);
422 if( (nFlags
& 0x100) == 0x100 )
423 aDlg
.SetCurrentFilter( aFilterName
);
431 aDlg
.SetDisplayDirectory( maExportRecentFile
);
433 if ( aDlg
.Execute() == ERRCODE_NONE
)
435 maExportRecentFile
= aDlg
.GetPath();
437 Reference
< XComponentLoader
> xLoader( mxMSF
->createInstance( OUString::createFromAscii( "com.sun.star.frame.Desktop" ) ), UNO_QUERY
);
438 Reference
< XInteractionHandler
> xInter( mxMSF
->createInstance( OUString::createFromAscii( "com.sun.star.task.InteractionHandler" ) ), UNO_QUERY
);
439 if( xLoader
.is() && xInter
.is() )
441 OUString
aFrame( RTL_CONSTASCII_USTRINGPARAM( "_default" ) );
442 Sequence
< PropertyValue
> aArguments(1);
443 aArguments
[0].Name
= OUString::createFromAscii( "InteractionHandler" );
444 aArguments
[0].Value
<<= xInter
;
445 Reference
< XComponent
> xComp( xLoader
->loadComponentFromURL( maExportRecentFile
, aFrame
, 0, aArguments
) );
455 DBG_ERROR("XMLFilterTestDialog::onExportBrowse exception caught!");
461 void XMLFilterTestDialog::onExportCurrentDocument()
463 doExport( getFrontMostDocument( mpFilterInfo
->maDocumentService
) );
466 void XMLFilterTestDialog::doExport( Reference
< XComponent
> xComp
)
470 Reference
< XStorable
> xStorable( xComp
, UNO_QUERY
);
473 utl::TempFile aTempFile
;
474 OUString
aTempFileURL( aTempFile
.GetURL() );
476 const application_info_impl
* pAppInfo
= getApplicationInfo( mpFilterInfo
->maExportService
);
479 File
aOutputFile( aTempFileURL
);
480 /* File::RC rc = */ aOutputFile
.open( OpenFlag_Write
);
482 // create xslt exporter
483 Reference
< XOutputStream
> xIS( new comphelper::OSLOutputStreamWrapper( aOutputFile
) );
485 int bUseDTD
= (mpFilterInfo
->maDTD
.getLength() != 0) ? 1 : 0 ;
486 int bUseDocType
= (mpFilterInfo
->maDocType
.getLength() != 0 ) ? 1 : 0;
487 Sequence
< PropertyValue
> aSourceData( 2 + bUseDTD
+ bUseDocType
);
490 aSourceData
[i
].Name
= OUString( RTL_CONSTASCII_USTRINGPARAM( "OutputStream" ) );
491 aSourceData
[i
++].Value
<<= xIS
;
493 aSourceData
[i
].Name
= OUString( RTL_CONSTASCII_USTRINGPARAM( "Indent" ) );
494 aSourceData
[i
++].Value
<<= (sal_Bool
)sal_True
;
498 aSourceData
[i
].Name
= OUString(RTL_CONSTASCII_USTRINGPARAM("DocType_System"));
499 aSourceData
[i
++].Value
<<= mpFilterInfo
->maDTD
;
504 aSourceData
[i
].Name
= OUString(RTL_CONSTASCII_USTRINGPARAM("DocType_Public"));
505 aSourceData
[i
++].Value
<<= mpFilterInfo
->maDocType
;
508 Reference
< XExportFilter
> xExporter( mxMSF
->createInstance( OUString::createFromAscii( "com.sun.star.documentconversion.XSLTFilter" ) ), UNO_QUERY
);
509 Reference
< XDocumentHandler
> xHandler( xExporter
, UNO_QUERY
);
512 Sequence
< OUString
> aFilterUserData( mpFilterInfo
->getFilterUserData() );
513 xExporter
->exporter( aSourceData
, aFilterUserData
);
515 Reference
< XMultiServiceFactory
> xDocFac( xComp
, UNO_QUERY
);
517 Reference
< XEmbeddedObjectResolver
> xObjectResolver
;
518 Reference
< XGraphicObjectResolver
> xGrfResolver
;
524 xGrfResolver
= Reference
< XGraphicObjectResolver
>::query( xDocFac
->createInstance( OUString::createFromAscii("com.sun.star.document.ExportGraphicObjectResolver") ) );
525 xObjectResolver
= Reference
< XEmbeddedObjectResolver
>::query( xDocFac
->createInstance( OUString::createFromAscii("com.sun.star.document.ExportEmbeddedObjectResolver") ) );
532 Sequence
< Any
> aArgs( 1 + ( xGrfResolver
.is() ? 1 : 0 ) + ( xObjectResolver
.is() ? 1 : 0 ) );
533 Any
* pArgs
= aArgs
.getArray();
534 if( xGrfResolver
.is() ) *pArgs
++ <<= xGrfResolver
;
535 if( xObjectResolver
.is() ) *pArgs
++ <<= xObjectResolver
;
537 // *pArgs++ <<= xInfoSet;
540 Reference
< XFilter
> xFilter( mxMSF
->createInstanceWithArguments( pAppInfo
->maXMLExporter
, aArgs
), UNO_QUERY
);
543 Reference
< XExporter
> xExporter2( xFilter
, UNO_QUERY
);
544 if( xExporter2
.is() )
546 xExporter2
->setSourceDocument( xComp
);
548 Sequence
< PropertyValue
> aDescriptor( 1 );
549 aDescriptor
[0].Name
= OUString( RTL_CONSTASCII_USTRINGPARAM( "FileName" ) );
550 aDescriptor
[0].Value
<<= aTempFileURL
;
552 if( xFilter
->filter( aDescriptor
) )
553 displayXMLFile( aTempFileURL
);
562 DBG_ERROR( "XMLFilterTestDialog::doExport exception catched!" );
566 void XMLFilterTestDialog::displayXMLFile( const OUString
& rURL
)
568 if( NULL
== mpSourceDLG
)
569 mpSourceDLG
= new XMLSourceFileDialog( NULL
, mrResMgr
, mxMSF
);
571 mpSourceDLG
->ShowWindow( rURL
, mpFilterInfo
);
574 void XMLFilterTestDialog::onImportBrowse()
576 // Open Fileopen-Dialog
577 ::sfx2::FileDialogHelper
aDlg(
578 com::sun::star::ui::dialogs::TemplateDescription::FILEOPEN_SIMPLE
, 0 );
579 String
aFilterName( mpFilterInfo
->maInterfaceName
);
583 int nCurrentIndex
= 0;
584 for( int i
= 0; nLastIndex
!= -1; i
++ )
586 nLastIndex
= mpFilterInfo
->maExtension
.indexOf( sal_Unicode( ';' ), nLastIndex
);
591 aExtensions
+= String( RTL_CONSTASCII_STRINGPARAM("*.") );
593 if( nLastIndex
== -1 )
596 aExtensions
+= String( mpFilterInfo
->maExtension
.copy( nCurrentIndex
) );
600 aExtensions
+= String( mpFilterInfo
->maExtension
.copy( nCurrentIndex
, nLastIndex
- nCurrentIndex
) );
601 nCurrentIndex
= nLastIndex
+ 1;
602 nLastIndex
= nCurrentIndex
;
606 aFilterName
+= String( RTL_CONSTASCII_USTRINGPARAM( " (" ) );
607 aFilterName
+= aExtensions
;
608 aFilterName
+= sal_Unicode(')');
610 aDlg
.AddFilter( aFilterName
, aExtensions
);
611 aDlg
.SetDisplayDirectory( maImportRecentFile
);
613 if ( aDlg
.Execute() == ERRCODE_NONE
)
615 maImportRecentFile
= aDlg
.GetPath();
616 import( maImportRecentFile
);
622 void XMLFilterTestDialog::onImportRecentDocument()
624 import( maImportRecentFile
);
627 void XMLFilterTestDialog::import( const OUString
& rURL
)
631 Reference
< XComponentLoader
> xLoader( mxMSF
->createInstance( OUString::createFromAscii( "com.sun.star.frame.Desktop" ) ), UNO_QUERY
);
632 Reference
< XInteractionHandler
> xInter( mxMSF
->createInstance( OUString::createFromAscii( "com.sun.star.task.InteractionHandler" ) ), UNO_QUERY
);
633 if( xLoader
.is() && xInter
.is() )
636 OUString
aFrame( RTL_CONSTASCII_USTRINGPARAM( "_default" ) );
637 Sequence
< PropertyValue
> aArguments(2);
638 aArguments
[0].Name
= OUString::createFromAscii( "FilterName" );
639 aArguments
[0].Value
<<= mpFilterInfo
->maFilterName
;
640 aArguments
[1].Name
= OUString::createFromAscii( "InteractionHandler" );
641 aArguments
[1].Value
<<= xInter
;
643 xLoader
->loadComponentFromURL( rURL
, aFrame
, 0, aArguments
);
646 if( maCBXDisplaySource
.IsChecked() )
649 OUString
aTempFileURL( aTempFile
.GetURL() );
651 Reference
< XImportFilter
> xImporter( mxMSF
->createInstance( OUString::createFromAscii( "com.sun.star.documentconversion.XSLTFilter" ) ), UNO_QUERY
);
654 osl::File
aInputFile( rURL
);
655 osl::File::RC rc
= aInputFile
.open( OpenFlag_Read
);
657 Reference
< XInputStream
> xIS( new comphelper::OSLInputStreamWrapper( aInputFile
) );
659 Sequence
< PropertyValue
> aSourceData( 5 );
662 aSourceData
[i
].Name
= OUString::createFromAscii( "InputStream" );
663 aSourceData
[i
++].Value
<<= xIS
;
665 aSourceData
[i
].Name
= OUString::createFromAscii( "FileName" );
666 aSourceData
[i
++].Value
<<= rURL
;
668 aSourceData
[i
].Name
= OUString::createFromAscii( "Indent" );
669 aSourceData
[i
++].Value
<<= (sal_Bool
)sal_True
;
671 aSourceData
[i
].Name
= OUString::createFromAscii("DocType_Public");
672 aSourceData
[i
++].Value
<<= OUString::createFromAscii("-//OpenOffice.org//DTD OfficeDocument 1.0//EN");
674 aSourceData
[i
].Name
= OUString::createFromAscii("DocType_System");
675 aSourceData
[i
++].Value
<<= sDTDPath
;
677 Reference
< XDocumentHandler
> xWriter( mxMSF
->createInstance( OUString::createFromAscii( "com.sun.star.xml.sax.Writer" ) ), UNO_QUERY
);
679 File
aOutputFile( aTempFileURL
);
680 rc
= aOutputFile
.open( OpenFlag_Write
);
682 Reference
< XOutputStream
> xOS( new OSLOutputStreamWrapper( aOutputFile
) );
683 Reference
< XActiveDataSource
> xDocSrc( xWriter
, UNO_QUERY
);
684 xDocSrc
->setOutputStream( xOS
);
686 Sequence
< OUString
> aFilterUserData( mpFilterInfo
->getFilterUserData() );
687 xImporter
->importer( aSourceData
, xWriter
, aFilterUserData
);
690 displayXMLFile( aTempFileURL
);
695 DBG_ERROR("XMLFilterTestDialog::import catched an exception" );
699 IMPL_LINK(XMLFilterTestDialog
, ClickHdl_Impl
, PushButton
*, pButton
)
701 if( &maPBExportBrowse
== pButton
)
705 else if( &maPBCurrentDocument
== pButton
)
707 onExportCurrentDocument();
709 else if( &maPBImportBrowse
== pButton
)
713 else if( &maPBRecentDocument
== pButton
)
715 onImportRecentDocument();
717 else if( &maPBClose
== pButton
)
725 /** returns the front most open component that supports the given service */
726 Reference
< XComponent
> XMLFilterTestDialog::getFrontMostDocument( const OUString
& rServiceName
)
728 Reference
< XComponent
> xRet
;
732 Reference
< XDesktop
> xDesktop( mxMSF
->createInstance( OUString::createFromAscii( "com.sun.star.frame.Desktop" ) ), UNO_QUERY
);
735 Reference
< XComponent
> xTest( mxLastFocusModel
);
736 if( checkComponent( xTest
, rServiceName
) )
742 xTest
= (Reference
< XComponent
>)xDesktop
->getCurrentComponent();
744 if( checkComponent( xTest
, rServiceName
) )
750 Reference
< XEnumerationAccess
> xAccess( xDesktop
->getComponents() );
753 Reference
< XEnumeration
> xEnum( xAccess
->createEnumeration() );
756 while( xEnum
->hasMoreElements() )
758 if( (xEnum
->nextElement() >>= xTest
) && xTest
.is() )
760 if( checkComponent( xTest
, rServiceName
) )
775 DBG_ERROR( "XMLFilterTestDialog::getFrontMostDocument exception catched!" );
781 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */