1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: xmlfiltertestdialog.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_filter.hxx"
33 #include <com/sun/star/frame/XConfigManager.hpp>
34 #include <com/sun/star/xml/sax/XDocumentHandler.hpp>
35 #ifndef _COM_SUN_STAR_DOCUMENT_XGRAPHICOBJECTRESOLVER_HXX_
36 #include <com/sun/star/document/XGraphicObjectResolver.hpp>
38 #ifndef _COM_SUN_STAR_DOCUMENT_XEMBEDDEDOBJECTRESOLVER_HXX_
39 #include <com/sun/star/document/XEmbeddedObjectResolver.hpp>
41 #include <com/sun/star/xml/XImportFilter.hpp>
42 #include <com/sun/star/xml/XExportFilter.hpp>
43 #include <com/sun/star/io/XActiveDataSource.hpp>
44 #include <com/sun/star/document/XDocumentPropertiesSupplier.hpp>
45 #include <com/sun/star/frame/XComponentLoader.hpp>
46 #include <com/sun/star/frame/XStorable.hpp>
47 #include <com/sun/star/beans/XPropertySet.hpp>
48 #include <com/sun/star/frame/XDesktop.hpp>
49 #include <com/sun/star/document/XFilter.hpp>
50 #include <comphelper/oslfile2streamwrap.hxx>
51 #include <com/sun/star/document/XExporter.hpp>
52 #include <com/sun/star/task/XInteractionHandler.hpp>
54 #include "com/sun/star/ui/dialogs/TemplateDescription.hpp"
55 #include <vcl/svapp.hxx>
56 #include <vos/mutex.hxx>
57 #include <sfx2/filedlghelper.hxx>
58 #include <osl/file.hxx>
59 #include <unotools/tempfile.hxx>
60 #include <tools/urlobj.hxx>
62 #include "xmlfilterdialogstrings.hrc"
63 #include "xmlfiltersettingsdialog.hxx"
64 #include "xmlfiltertestdialog.hxx"
65 #include "xmlfiltertestdialog.hrc"
66 #include "xmlfileview.hxx"
73 using namespace comphelper
;
74 using namespace com::sun::star::lang
;
75 using namespace com::sun::star::beans
;
76 using namespace com::sun::star::container
;
77 using namespace com::sun::star::document
;
78 using namespace com::sun::star::frame
;
79 using namespace com::sun::star::task
;
80 using namespace com::sun::star::uno
;
81 using namespace com::sun::star::io
;
82 using namespace com::sun::star::xml
;
83 using namespace com::sun::star::xml::sax
;
85 class GlobalEventListenerImpl
: public ::cppu::WeakImplHelper1
< com::sun::star::document::XEventListener
>
88 GlobalEventListenerImpl( XMLFilterTestDialog
* pDialog
);
91 virtual void SAL_CALL
notifyEvent( const com::sun::star::document::EventObject
& Event
) throw (RuntimeException
);
93 // lang::XEventListener
94 virtual void SAL_CALL
disposing( const com::sun::star::lang::EventObject
& Source
) throw (RuntimeException
);
96 XMLFilterTestDialog
* mpDialog
;
99 GlobalEventListenerImpl::GlobalEventListenerImpl( XMLFilterTestDialog
* pDialog
)
100 : mpDialog( pDialog
)
104 void SAL_CALL
GlobalEventListenerImpl::notifyEvent( const com::sun::star::document::EventObject
& Event
) throw (RuntimeException
)
106 OGuard
aGuard( Application::GetSolarMutex() );
107 if( (Event
.EventName
.compareToAscii( RTL_CONSTASCII_STRINGPARAM("OnFocus") ) == 0) ||
108 (Event
.EventName
.compareToAscii( RTL_CONSTASCII_STRINGPARAM("OnUnload") ) == 0) )
110 Reference
< XComponent
> xComp( Event
.Source
, UNO_QUERY
);
111 mpDialog
->updateCurrentDocumentButtonState( &xComp
);
115 void SAL_CALL
GlobalEventListenerImpl::disposing( const com::sun::star::lang::EventObject
& /* Source */ ) throw (RuntimeException
)
119 /** returns true if the given component supports the given service */
120 static bool checkComponent( Reference
< XComponent
>& rxComponent
, const OUString
& rServiceName
)
124 Reference
< XServiceInfo
> xInfo( rxComponent
, UNO_QUERY
);
127 if( xInfo
->supportsService( rServiceName
) )
129 // special case for impress documents which supports same service as draw documents
130 if( rServiceName
.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "com.sun.star.drawing.DrawingDocument" ) ) )
132 // so if we want a draw we need to check if its not an impress
133 if( !xInfo
->supportsService( OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.presentation.PresentationDocument") ) ) )
145 DBG_ERROR( "checkComponent exception catched!" );
151 XMLFilterTestDialog::XMLFilterTestDialog( Window
* pParent
, ResMgr
& rResMgr
, const com::sun::star::uno::Reference
< com::sun::star::lang::XMultiServiceFactory
>& rxMSF
) :
152 ModalDialog( pParent
, ResId( DLG_XML_FILTER_TEST_DIALOG
, rResMgr
) ),
156 maFLExport( this, ResId( FL_EXPORT
, rResMgr
) ),
157 maFTExportXSLT( this, ResId( FT_EXPORT_XSLT
, rResMgr
) ),
158 maFTExportXSLTFile( this, ResId( FT_EXPORT_XSLT_FILE
, rResMgr
) ),
159 maFTTransformDocument( this, ResId( FT_TRANSFORM_DOCUMENT
, rResMgr
) ),
160 maPBExportBrowse( this, ResId( PB_EXPORT_BROWSE
, rResMgr
) ),
161 maPBCurrentDocument( this, ResId( PB_CURRENT_DOCUMENT
, rResMgr
) ),
162 maFTNameOfCurentFile( this, ResId( FT_NAME_OF_CURRENT_FILE
, rResMgr
) ),
163 maFLImport( this, ResId( FL_IMPORT
, rResMgr
) ),
164 maFTImportXSLT( this, ResId( FT_IMPORT_XSLT
, rResMgr
) ),
165 maFTImportXSLTFile( this, ResId( FT_IMPORT_XSLT_FILE
, rResMgr
) ),
166 maFTImportTemplate( this, ResId( FT_IMPORT_TEMPLATE
, rResMgr
) ),
167 maFTImportTemplateFile( this, ResId( FT_IMPORT_TEMPLATE_FILE
, rResMgr
) ),
168 maFTTransformFile( this, ResId( FT_TRANSFORM_FILE
, rResMgr
) ),
169 maCBXDisplaySource( this, ResId( CBX_DISPLAY_SOURCE
, rResMgr
) ),
170 maPBImportBrowse( this, ResId( PB_IMPORT_BROWSE
, rResMgr
) ),
171 maPBRecentDocument( this, ResId( PB_RECENT_DOCUMENT
, rResMgr
) ),
172 maFTNameOfRecentFile( this, ResId( FT_NAME_OF_RECENT_FILE
, rResMgr
) ),
173 maPBClose( this, ResId( PB_CLOSE
, rResMgr
) ),
174 maPBHelp( this, ResId( PB_HELP
, rResMgr
) ),
176 mpFilterInfo( NULL
),
177 sDTDPath( RTL_CONSTASCII_USTRINGPARAM( "$(inst)/share/dtd/officedocument/1_0/office.dtd" ) )
181 maPBExportBrowse
.SetClickHdl(LINK( this, XMLFilterTestDialog
, ClickHdl_Impl
) );
182 maPBCurrentDocument
.SetClickHdl(LINK( this, XMLFilterTestDialog
, ClickHdl_Impl
) );
183 maPBImportBrowse
.SetClickHdl(LINK( this, XMLFilterTestDialog
, ClickHdl_Impl
) );
184 maPBRecentDocument
.SetClickHdl(LINK( this, XMLFilterTestDialog
, ClickHdl_Impl
) );
185 maPBClose
.SetClickHdl(LINK( this, XMLFilterTestDialog
, ClickHdl_Impl
) );
187 maDialogTitle
= GetText();
191 Reference
< XConfigManager
> xCfgMgr( mxMSF
->createInstance( OUString::createFromAscii("com.sun.star.config.SpecialConfigManager")), UNO_QUERY
);
193 sDTDPath
= xCfgMgr
->substituteVariables( sDTDPath
);
195 mxGlobalBroadcaster
= Reference
< XEventBroadcaster
>::query( mxMSF
->createInstance(::rtl::OUString::createFromAscii("com.sun.star.frame.GlobalEventBroadcaster") ) );
196 if ( mxGlobalBroadcaster
.is() )
198 mxGlobalEventListener
= new GlobalEventListenerImpl( this );
199 mxGlobalBroadcaster
->addEventListener( mxGlobalEventListener
);
204 DBG_ERROR( "XMLFilterTestDialog::XMLFilterTestDialog exception catched!" );
208 XMLFilterTestDialog::~XMLFilterTestDialog()
212 if( mxGlobalBroadcaster
.is() )
213 mxGlobalBroadcaster
->removeEventListener( mxGlobalEventListener
);
217 DBG_ERROR( "XMLFilterTestDialog::~XMLFilterTestDialog exception catched!" );
224 void XMLFilterTestDialog::test( const filter_info_impl
& rFilterInfo
)
227 mpFilterInfo
= new filter_info_impl( rFilterInfo
);
229 maImportRecentFile
= OUString();
236 static OUString
getFileNameFromURL( OUString
& rURL
)
238 INetURLObject
aURL( rURL
);
239 OUString
aName( aURL
.getName(INetURLObject::LAST_SEGMENT
, sal_True
, INetURLObject::DECODE_WITH_CHARSET
) );
243 void XMLFilterTestDialog::updateCurrentDocumentButtonState( Reference
< XComponent
> * pRef
/* = NULL */ )
245 if( pRef
&& pRef
->is() )
247 if( checkComponent( *pRef
, mpFilterInfo
->maDocumentService
) )
248 mxLastFocusModel
= *pRef
;
251 bool bExport
= (mpFilterInfo
->maFlags
& 2) == 2;
252 Reference
< XComponent
> xCurrentDocument
;
254 xCurrentDocument
= getFrontMostDocument( mpFilterInfo
->maDocumentService
);
255 maPBCurrentDocument
.Enable( bExport
&& xCurrentDocument
.is() );
256 maFTNameOfCurentFile
.Enable( bExport
&& xCurrentDocument
.is() );
258 if( xCurrentDocument
.is() )
261 Reference
< XDocumentPropertiesSupplier
> xDPS( xCurrentDocument
, UNO_QUERY
);
264 Reference
< XDocumentProperties
> xProps( xDPS
->getDocumentProperties() );
267 aTitle
= xProps
->getTitle();
271 if( 0 == aTitle
.getLength() )
273 Reference
< XStorable
> xStorable( xCurrentDocument
, UNO_QUERY
);
276 if( xStorable
->hasLocation() )
278 OUString
aURL( xStorable
->getLocation() );
279 aTitle
= getFileNameFromURL( aURL
);
284 maFTNameOfCurentFile
.SetText( aTitle
);
288 void XMLFilterTestDialog::initDialog()
290 DBG_ASSERT( mpFilterInfo
, "i need a filter I can test!" );
291 if( NULL
== mpFilterInfo
)
294 String
aTitle( maDialogTitle
);
295 aTitle
.SearchAndReplace( String( RTL_CONSTASCII_USTRINGPARAM("%s") ), mpFilterInfo
->maFilterName
);
299 bool bImport
= (mpFilterInfo
->maFlags
& 1) == 1;
300 bool bExport
= (mpFilterInfo
->maFlags
& 2) == 2;
302 updateCurrentDocumentButtonState();
304 maFLExport
.Enable( bExport
);
305 maFTExportXSLT
.Enable( bExport
);
306 maFTExportXSLTFile
.Enable( bExport
);
307 maFTTransformDocument
.Enable( bExport
);
308 maPBExportBrowse
.Enable( bExport
);
310 maFTExportXSLTFile
.SetText( getFileNameFromURL( mpFilterInfo
->maExportXSLT
) );
314 maFLImport
.Enable( bImport
);
315 maFTImportXSLT
.Enable( bImport
);
316 maFTImportXSLTFile
.Enable( bImport
);
317 maFTImportTemplate
.Enable( bImport
&& mpFilterInfo
->maImportTemplate
.getLength() );
318 maFTImportTemplateFile
.Enable( bImport
&& mpFilterInfo
->maImportTemplate
.getLength() );
319 maFTTransformFile
.Enable( bImport
);
320 maCBXDisplaySource
.Enable( bImport
);
321 maPBImportBrowse
.Enable( bImport
);
322 maPBRecentDocument
.Enable( bImport
&& maImportRecentFile
.getLength() );
323 maFTNameOfRecentFile
.Enable( bImport
&& maImportRecentFile
.getLength() );
325 maFTImportXSLTFile
.SetText( getFileNameFromURL( mpFilterInfo
->maImportXSLT
) );
326 maFTImportTemplateFile
.SetText( getFileNameFromURL( mpFilterInfo
->maImportTemplate
) );
327 maFTNameOfRecentFile
.SetText( getFileNameFromURL( maImportRecentFile
) );
330 void XMLFilterTestDialog::onExportBrowse()
334 // Open Fileopen-Dialog
335 ::sfx2::FileDialogHelper
aDlg(
336 com::sun::star::ui::dialogs::TemplateDescription::FILEOPEN_SIMPLE
,
339 Reference
< XNameAccess
> xFilterContainer( mxMSF
->createInstance( OUString::createFromAscii("com.sun.star.document.FilterFactory" ) ), UNO_QUERY
);
340 Reference
< XNameAccess
> xTypeDetection( mxMSF
->createInstance( OUString::createFromAscii("com.sun.star.document.TypeDetection" ) ), UNO_QUERY
);
341 if( xFilterContainer
.is() && xTypeDetection
.is() )
343 Sequence
< OUString
> aFilterNames( xFilterContainer
->getElementNames() );
344 OUString
* pFilterName
= aFilterNames
.getArray();
346 for( sal_Int32 nFilter
= 0; nFilter
< aFilterNames
.getLength(); nFilter
++, pFilterName
++ )
348 Sequence
< PropertyValue
> aValues
;
350 Any
aAny( xFilterContainer
->getByName( *pFilterName
) );
351 if( !(aAny
>>= aValues
) )
354 OUString aInterfaceName
;
355 PropertyValue
* pValues
= aValues
.getArray();
356 OUString aType
, aService
;
357 sal_Int32
nFlags( 0 );
361 for( sal_Int32 nValue
= 0; (nValue
< aValues
.getLength()) && (nFound
!= 15); nValue
++, pValues
++ )
363 if( pValues
->Name
.equalsAscii( "Type" ) )
365 pValues
->Value
>>= aType
;
368 else if( pValues
->Name
.equalsAscii( "DocumentService" ) )
370 pValues
->Value
>>= aService
;
373 else if( pValues
->Name
.equalsAscii( "Flags" ) )
375 pValues
->Value
>>= nFlags
;
378 if( pValues
->Name
.equalsAscii( "UIName" ) )
380 pValues
->Value
>>= aInterfaceName
;
386 if( (nFound
== 15) && (aType
.getLength() && aService
== mpFilterInfo
->maDocumentService
) )
388 // see if this filter is not supressed in dialog
389 if( (nFlags
& 0x1000) == 0 )
391 aAny
= xTypeDetection
->getByName( aType
);
392 Sequence
< PropertyValue
> aValues2
;
394 if( aAny
>>= aValues2
)
396 PropertyValue
* pValues2
= aValues2
.getArray();
400 for( nValue
= 0; nValue
< aValues2
.getLength(); nValue
++, pValues2
++ )
402 if( pValues2
->Name
.equalsAscii( "Extensions" ) )
404 Sequence
< OUString
> aExtensions
;
405 if( pValues2
->Value
>>= aExtensions
)
407 const sal_Int32
nCount( aExtensions
.getLength() );
408 OUString
* pExtensions
= aExtensions
.getArray();
410 for( n
= 0; n
< nCount
; n
++ )
413 aExtension
+= OUString( sal_Unicode(';') );
414 aExtension
+= OUString::createFromAscii("*.");
415 aExtension
+= (*pExtensions
++);
421 String
aExtensions( aExtension
);
422 String
aFilterName( aInterfaceName
);
423 aFilterName
+= String( RTL_CONSTASCII_USTRINGPARAM(" (") );
424 aFilterName
+= aExtensions
;
425 aFilterName
+= sal_Unicode(')');
427 aDlg
.AddFilter( aFilterName
, aExtensions
);
429 if( (nFlags
& 0x100) == 0x100 )
430 aDlg
.SetCurrentFilter( aFilterName
);
438 aDlg
.SetDisplayDirectory( maExportRecentFile
);
440 if ( aDlg
.Execute() == ERRCODE_NONE
)
442 maExportRecentFile
= aDlg
.GetPath();
444 Reference
< XComponentLoader
> xLoader( mxMSF
->createInstance( OUString::createFromAscii( "com.sun.star.frame.Desktop" ) ), UNO_QUERY
);
445 Reference
< XInteractionHandler
> xInter( mxMSF
->createInstance( OUString::createFromAscii( "com.sun.star.task.InteractionHandler" ) ), UNO_QUERY
);
446 if( xLoader
.is() && xInter
.is() )
448 OUString
aFrame( RTL_CONSTASCII_USTRINGPARAM( "_default" ) );
449 Sequence
< PropertyValue
> aArguments(1);
450 aArguments
[0].Name
= OUString::createFromAscii( "InteractionHandler" );
451 aArguments
[0].Value
<<= xInter
;
452 Reference
< XComponent
> xComp( xLoader
->loadComponentFromURL( maExportRecentFile
, aFrame
, 0, aArguments
) );
462 DBG_ERROR("XMLFilterTestDialog::onExportBrowse exception caught!");
468 void XMLFilterTestDialog::onExportCurrentDocument()
470 doExport( getFrontMostDocument( mpFilterInfo
->maDocumentService
) );
473 void XMLFilterTestDialog::doExport( Reference
< XComponent
> xComp
)
477 Reference
< XStorable
> xStorable( xComp
, UNO_QUERY
);
480 utl::TempFile aTempFile
;
481 OUString
aTempFileURL( aTempFile
.GetURL() );
483 const application_info_impl
* pAppInfo
= getApplicationInfo( mpFilterInfo
->maExportService
);
486 File
aOutputFile( aTempFileURL
);
487 /* File::RC rc = */ aOutputFile
.open( OpenFlag_Write
);
489 // create xslt exporter
490 Reference
< XOutputStream
> xIS( new comphelper::OSLOutputStreamWrapper( aOutputFile
) );
492 int bUseDTD
= (mpFilterInfo
->maDTD
.getLength() != 0) ? 1 : 0 ;
493 int bUseDocType
= (mpFilterInfo
->maDocType
.getLength() != 0 ) ? 1 : 0;
494 Sequence
< PropertyValue
> aSourceData( 2 + bUseDTD
+ bUseDocType
);
497 aSourceData
[i
].Name
= OUString( RTL_CONSTASCII_USTRINGPARAM( "OutputStream" ) );
498 aSourceData
[i
++].Value
<<= xIS
;
500 aSourceData
[i
].Name
= OUString( RTL_CONSTASCII_USTRINGPARAM( "Indent" ) );
501 aSourceData
[i
++].Value
<<= (sal_Bool
)sal_True
;
505 aSourceData
[i
].Name
= OUString(RTL_CONSTASCII_USTRINGPARAM("DocType_System"));
506 aSourceData
[i
++].Value
<<= mpFilterInfo
->maDTD
;
511 aSourceData
[i
].Name
= OUString(RTL_CONSTASCII_USTRINGPARAM("DocType_Public"));
512 aSourceData
[i
++].Value
<<= mpFilterInfo
->maDocType
;
515 Reference
< XExportFilter
> xExporter( mxMSF
->createInstance( OUString::createFromAscii( "com.sun.star.documentconversion.XSLTFilter" ) ), UNO_QUERY
);
516 Reference
< XDocumentHandler
> xHandler( xExporter
, UNO_QUERY
);
519 Sequence
< OUString
> aFilterUserData( mpFilterInfo
->getFilterUserData() );
520 xExporter
->exporter( aSourceData
, aFilterUserData
);
522 Reference
< XMultiServiceFactory
> xDocFac( xComp
, UNO_QUERY
);
524 Reference
< XEmbeddedObjectResolver
> xObjectResolver
;
525 Reference
< XGraphicObjectResolver
> xGrfResolver
;
531 xGrfResolver
= Reference
< XGraphicObjectResolver
>::query( xDocFac
->createInstance( OUString::createFromAscii("com.sun.star.document.ExportGraphicObjectResolver") ) );
532 xObjectResolver
= Reference
< XEmbeddedObjectResolver
>::query( xDocFac
->createInstance( OUString::createFromAscii("com.sun.star.document.ExportEmbeddedObjectResolver") ) );
539 Sequence
< Any
> aArgs( 1 + ( xGrfResolver
.is() ? 1 : 0 ) + ( xObjectResolver
.is() ? 1 : 0 ) );
540 Any
* pArgs
= aArgs
.getArray();
541 if( xGrfResolver
.is() ) *pArgs
++ <<= xGrfResolver
;
542 if( xObjectResolver
.is() ) *pArgs
++ <<= xObjectResolver
;
544 // *pArgs++ <<= xInfoSet;
547 Reference
< XFilter
> xFilter( mxMSF
->createInstanceWithArguments( pAppInfo
->maXMLExporter
, aArgs
), UNO_QUERY
);
550 Reference
< XExporter
> xExporter2( xFilter
, UNO_QUERY
);
551 if( xExporter2
.is() )
553 xExporter2
->setSourceDocument( xComp
);
555 Sequence
< PropertyValue
> aDescriptor( 1 );
556 aDescriptor
[0].Name
= OUString( RTL_CONSTASCII_USTRINGPARAM( "FileName" ) );
557 aDescriptor
[0].Value
<<= aTempFileURL
;
559 if( xFilter
->filter( aDescriptor
) )
560 displayXMLFile( aTempFileURL
);
569 DBG_ERROR( "XMLFilterTestDialog::doExport exception catched!" );
573 void XMLFilterTestDialog::displayXMLFile( const OUString
& rURL
)
575 if( NULL
== mpSourceDLG
)
576 mpSourceDLG
= new XMLSourceFileDialog( NULL
, mrResMgr
, mxMSF
);
578 mpSourceDLG
->ShowWindow( rURL
, mpFilterInfo
);
581 void XMLFilterTestDialog::onImportBrowse()
583 // Open Fileopen-Dialog
584 ::sfx2::FileDialogHelper
aDlg(
585 com::sun::star::ui::dialogs::TemplateDescription::FILEOPEN_SIMPLE
, 0 );
586 String
aFilterName( mpFilterInfo
->maInterfaceName
);
590 int nCurrentIndex
= 0;
591 for( int i
= 0; nLastIndex
!= -1; i
++ )
593 nLastIndex
= mpFilterInfo
->maExtension
.indexOf( sal_Unicode( ';' ), nLastIndex
);
598 aExtensions
+= String( RTL_CONSTASCII_STRINGPARAM("*.") );
600 if( nLastIndex
== -1 )
603 aExtensions
+= String( mpFilterInfo
->maExtension
.copy( nCurrentIndex
) );
607 aExtensions
+= String( mpFilterInfo
->maExtension
.copy( nCurrentIndex
, nLastIndex
- nCurrentIndex
) );
608 nCurrentIndex
= nLastIndex
+ 1;
609 nLastIndex
= nCurrentIndex
;
613 aFilterName
+= String( RTL_CONSTASCII_USTRINGPARAM( " (" ) );
614 aFilterName
+= aExtensions
;
615 aFilterName
+= sal_Unicode(')');
617 aDlg
.AddFilter( aFilterName
, aExtensions
);
618 aDlg
.SetDisplayDirectory( maImportRecentFile
);
620 if ( aDlg
.Execute() == ERRCODE_NONE
)
622 maImportRecentFile
= aDlg
.GetPath();
623 import( maImportRecentFile
);
629 void XMLFilterTestDialog::onImportRecentDocument()
631 import( maImportRecentFile
);
634 void XMLFilterTestDialog::import( const OUString
& rURL
)
638 Reference
< XComponentLoader
> xLoader( mxMSF
->createInstance( OUString::createFromAscii( "com.sun.star.frame.Desktop" ) ), UNO_QUERY
);
639 Reference
< XInteractionHandler
> xInter( mxMSF
->createInstance( OUString::createFromAscii( "com.sun.star.task.InteractionHandler" ) ), UNO_QUERY
);
640 if( xLoader
.is() && xInter
.is() )
643 OUString
aFrame( RTL_CONSTASCII_USTRINGPARAM( "_default" ) );
644 Sequence
< PropertyValue
> aArguments(2);
645 aArguments
[0].Name
= OUString::createFromAscii( "FilterName" );
646 aArguments
[0].Value
<<= mpFilterInfo
->maFilterName
;
647 aArguments
[1].Name
= OUString::createFromAscii( "InteractionHandler" );
648 aArguments
[1].Value
<<= xInter
;
650 xLoader
->loadComponentFromURL( rURL
, aFrame
, 0, aArguments
);
653 if( maCBXDisplaySource
.IsChecked() )
656 OUString
aTempFileURL( aTempFile
.GetURL() );
658 Reference
< XImportFilter
> xImporter( mxMSF
->createInstance( OUString::createFromAscii( "com.sun.star.documentconversion.XSLTFilter" ) ), UNO_QUERY
);
661 osl::File
aInputFile( rURL
);
662 osl::File::RC rc
= aInputFile
.open( OpenFlag_Read
);
664 Reference
< XInputStream
> xIS( new comphelper::OSLInputStreamWrapper( aInputFile
) );
666 Sequence
< PropertyValue
> aSourceData( 5 );
669 aSourceData
[i
].Name
= OUString::createFromAscii( "InputStream" );
670 aSourceData
[i
++].Value
<<= xIS
;
672 aSourceData
[i
].Name
= OUString::createFromAscii( "FileName" );
673 aSourceData
[i
++].Value
<<= rURL
;
675 aSourceData
[i
].Name
= OUString::createFromAscii( "Indent" );
676 aSourceData
[i
++].Value
<<= (sal_Bool
)sal_True
;
678 aSourceData
[i
].Name
= OUString::createFromAscii("DocType_Public");
679 aSourceData
[i
++].Value
<<= OUString::createFromAscii("-//OpenOffice.org//DTD OfficeDocument 1.0//EN");
681 aSourceData
[i
].Name
= OUString::createFromAscii("DocType_System");
682 aSourceData
[i
++].Value
<<= sDTDPath
;
684 Reference
< XDocumentHandler
> xWriter( mxMSF
->createInstance( OUString::createFromAscii( "com.sun.star.xml.sax.Writer" ) ), UNO_QUERY
);
686 File
aOutputFile( aTempFileURL
);
687 rc
= aOutputFile
.open( OpenFlag_Write
);
689 Reference
< XOutputStream
> xOS( new OSLOutputStreamWrapper( aOutputFile
) );
690 Reference
< XActiveDataSource
> xDocSrc( xWriter
, UNO_QUERY
);
691 xDocSrc
->setOutputStream( xOS
);
693 Sequence
< OUString
> aFilterUserData( mpFilterInfo
->getFilterUserData() );
694 xImporter
->importer( aSourceData
, xWriter
, aFilterUserData
);
697 displayXMLFile( aTempFileURL
);
702 DBG_ERROR("XMLFilterTestDialog::import catched an exception" );
706 IMPL_LINK(XMLFilterTestDialog
, ClickHdl_Impl
, PushButton
*, pButton
)
708 if( &maPBExportBrowse
== pButton
)
712 else if( &maPBCurrentDocument
== pButton
)
714 onExportCurrentDocument();
716 else if( &maPBImportBrowse
== pButton
)
720 else if( &maPBRecentDocument
== pButton
)
722 onImportRecentDocument();
724 else if( &maPBClose
== pButton
)
732 /** returns the front most open component that supports the given service */
733 Reference
< XComponent
> XMLFilterTestDialog::getFrontMostDocument( const OUString
& rServiceName
)
735 Reference
< XComponent
> xRet
;
739 Reference
< XDesktop
> xDesktop( mxMSF
->createInstance( OUString::createFromAscii( "com.sun.star.frame.Desktop" ) ), UNO_QUERY
);
742 Reference
< XComponent
> xTest( mxLastFocusModel
);
743 if( checkComponent( xTest
, rServiceName
) )
749 xTest
= (Reference
< XComponent
>)xDesktop
->getCurrentComponent();
751 if( checkComponent( xTest
, rServiceName
) )
757 Reference
< XEnumerationAccess
> xAccess( xDesktop
->getComponents() );
760 Reference
< XEnumeration
> xEnum( xAccess
->createEnumeration() );
763 while( xEnum
->hasMoreElements() )
765 if( (xEnum
->nextElement() >>= xTest
) && xTest
.is() )
767 if( checkComponent( xTest
, rServiceName
) )
782 DBG_ERROR( "XMLFilterTestDialog::getFrontMostDocument exception catched!" );