Bump version to 5.0-14
[LibreOffice.git] / filter / source / xsltdialog / xmlfiltertestdialog.cxx
blob2563cadada86e59b2742d8efc2b58e0721295b89
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
21 #include <com/sun/star/beans/XPropertySet.hpp>
22 #include <com/sun/star/document/XFilter.hpp>
23 #include <com/sun/star/document/XExporter.hpp>
24 #include <com/sun/star/document/XDocumentPropertiesSupplier.hpp>
25 #include <com/sun/star/document/XGraphicObjectResolver.hpp>
26 #include <com/sun/star/document/XEmbeddedObjectResolver.hpp>
27 #include <com/sun/star/frame/theGlobalEventBroadcaster.hpp>
28 #include <com/sun/star/frame/XConfigManager.hpp>
29 #include <com/sun/star/frame/Desktop.hpp>
30 #include <com/sun/star/frame/XComponentLoader.hpp>
31 #include <com/sun/star/frame/XStorable.hpp>
32 #include <com/sun/star/io/XActiveDataSource.hpp>
33 #include <com/sun/star/system/SystemShellExecute.hpp>
34 #include <com/sun/star/system/SystemShellExecuteFlags.hpp>
35 #include <com/sun/star/task/InteractionHandler.hpp>
36 #include <com/sun/star/ui/dialogs/TemplateDescription.hpp>
37 #include <com/sun/star/xml/XImportFilter.hpp>
38 #include <com/sun/star/xml/XExportFilter.hpp>
39 #include <com/sun/star/xml/sax/Writer.hpp>
41 #include <comphelper/oslfile2streamwrap.hxx>
42 #include <vcl/svapp.hxx>
43 #include <osl/mutex.hxx>
44 #include <sfx2/filedlghelper.hxx>
45 #include <osl/file.hxx>
46 #include <unotools/tempfile.hxx>
47 #include <tools/urlobj.hxx>
48 #include <comphelper/processfactory.hxx>
50 #include "xmlfilterdialogstrings.hrc"
51 #include "xmlfiltersettingsdialog.hxx"
52 #include "xmlfiltertestdialog.hxx"
55 using namespace utl;
56 using namespace osl;
57 using namespace comphelper;
58 using namespace com::sun::star::lang;
59 using namespace com::sun::star::beans;
60 using namespace com::sun::star::container;
61 using namespace com::sun::star::document;
62 using namespace com::sun::star::frame;
63 using namespace com::sun::star::task;
64 using namespace com::sun::star::uno;
65 using namespace com::sun::star::io;
66 using namespace com::sun::star::system;
67 using namespace com::sun::star::xml;
68 using namespace com::sun::star::xml::sax;
71 class GlobalEventListenerImpl : public ::cppu::WeakImplHelper1< com::sun::star::document::XDocumentEventListener >
73 public:
74 GlobalEventListenerImpl( XMLFilterTestDialog* pDialog );
76 // XDocumentEventListener
77 virtual void SAL_CALL documentEventOccured( const com::sun::star::document::DocumentEvent& Event ) throw (RuntimeException, std::exception) SAL_OVERRIDE;
79 // lang::XEventListener
80 virtual void SAL_CALL disposing( const com::sun::star::lang::EventObject& Source ) throw (RuntimeException, std::exception) SAL_OVERRIDE;
81 private:
82 VclPtr<XMLFilterTestDialog> mpDialog;
85 GlobalEventListenerImpl::GlobalEventListenerImpl( XMLFilterTestDialog* pDialog )
86 : mpDialog( pDialog )
90 void SAL_CALL GlobalEventListenerImpl::documentEventOccured( const com::sun::star::document::DocumentEvent& Event ) throw (RuntimeException, std::exception)
92 ::SolarMutexGuard aGuard;
93 if( Event.EventName == "OnFocus" || Event.EventName == "OnUnload" )
95 Reference< XComponent > xComp( Event.Source, UNO_QUERY );
96 mpDialog->updateCurrentDocumentButtonState( &xComp );
100 void SAL_CALL GlobalEventListenerImpl::disposing( const com::sun::star::lang::EventObject& /* Source */ ) throw (RuntimeException, std::exception)
104 /** returns true if the given component supports the given service */
105 static bool checkComponent( Reference< XComponent >& rxComponent, const OUString& rServiceName )
109 Reference< XServiceInfo > xInfo( rxComponent, UNO_QUERY );
110 if( xInfo.is() )
112 if( xInfo->supportsService( rServiceName ) )
114 // special case for impress documents which supports same service as draw documents
115 if ( rServiceName == "com.sun.star.drawing.DrawingDocument" )
117 // so if we want a draw we need to check if its not an impress
118 if( !xInfo->supportsService("com.sun.star.presentation.PresentationDocument") )
119 return true;
121 else
123 return true;
128 catch( const Exception& )
130 OSL_FAIL( "checkComponent exception catched!" );
133 return false;
136 XMLFilterTestDialog::XMLFilterTestDialog(vcl::Window* pParent,
137 const Reference<XComponentContext>& rxContext)
138 : ModalDialog(pParent, "TestXMLFilterDialog", "filter/ui/testxmlfilter.ui")
139 , mxContext(rxContext)
140 , m_pFilterInfo(NULL)
142 get(m_pExport, "export");
143 get(m_pFTExportXSLTFile, "exportxsltfile");
144 get(m_pPBExportBrowse, "exportbrowse");
145 get(m_pPBCurrentDocument, "currentdocument");
146 get(m_pFTNameOfCurrentFile, "currentfilename");
148 get(m_pImport, "import");
149 get(m_pFTImportXSLTFile, "importxsltfile");
150 get(m_pFTImportTemplate, "templateimport");
151 get(m_pFTImportTemplateFile, "importxslttemplate");
152 get(m_pCBXDisplaySource, "displaysource");
153 get(m_pPBImportBrowse, "importbrowse");
154 get(m_pPBRecentFile, "recentfile");
155 get(m_pFTNameOfRecentFile, "recentfilename");
157 get(m_pPBClose, "close");
159 m_pPBExportBrowse->SetClickHdl(LINK( this, XMLFilterTestDialog, ClickHdl_Impl ) );
160 m_pPBCurrentDocument->SetClickHdl(LINK( this, XMLFilterTestDialog, ClickHdl_Impl ) );
161 m_pPBImportBrowse->SetClickHdl(LINK( this, XMLFilterTestDialog, ClickHdl_Impl ) );
162 m_pPBRecentFile->SetClickHdl(LINK( this, XMLFilterTestDialog, ClickHdl_Impl ) );
163 m_pPBClose->SetClickHdl(LINK( this, XMLFilterTestDialog, ClickHdl_Impl ) );
165 m_sDialogTitle = GetText();
169 mxGlobalBroadcaster = theGlobalEventBroadcaster::get(mxContext);
170 mxGlobalEventListener = new GlobalEventListenerImpl( this );
171 mxGlobalBroadcaster->addDocumentEventListener( mxGlobalEventListener );
173 catch( const Exception& )
175 OSL_FAIL( "XMLFilterTestDialog::XMLFilterTestDialog exception catched!" );
179 XMLFilterTestDialog::~XMLFilterTestDialog()
181 disposeOnce();
184 void XMLFilterTestDialog::dispose()
188 if( mxGlobalBroadcaster.is() )
189 mxGlobalBroadcaster->removeDocumentEventListener( mxGlobalEventListener );
191 catch( const Exception& )
193 OSL_FAIL( "XMLFilterTestDialog::~XMLFilterTestDialog exception catched!" );
196 delete m_pFilterInfo;
197 m_pExport.clear();
198 m_pFTExportXSLTFile.clear();
199 m_pPBExportBrowse.clear();
200 m_pPBCurrentDocument.clear();
201 m_pFTNameOfCurrentFile.clear();
202 m_pImport.clear();
203 m_pFTImportXSLTFile.clear();
204 m_pFTImportTemplate.clear();
205 m_pFTImportTemplateFile.clear();
206 m_pCBXDisplaySource.clear();
207 m_pPBImportBrowse.clear();
208 m_pPBRecentFile.clear();
209 m_pFTNameOfRecentFile.clear();
210 m_pPBClose.clear();
211 ModalDialog::dispose();
214 void XMLFilterTestDialog::test( const filter_info_impl& rFilterInfo )
216 delete m_pFilterInfo;
217 m_pFilterInfo = new filter_info_impl( rFilterInfo );
219 m_sImportRecentFile.clear();
221 initDialog();
223 Execute();
226 static OUString getFileNameFromURL( OUString& rURL )
228 INetURLObject aURL( rURL );
229 OUString aName( aURL.getName(INetURLObject::LAST_SEGMENT, true, INetURLObject::DECODE_WITH_CHARSET) );
230 return aName;
233 void XMLFilterTestDialog::updateCurrentDocumentButtonState( Reference< XComponent > * pRef /* = NULL */ )
235 if( pRef && pRef->is() )
237 if( checkComponent( *pRef, m_pFilterInfo->maDocumentService ) )
238 mxLastFocusModel = *pRef;
241 bool bExport = (m_pFilterInfo->maFlags & 2) == 2;
242 Reference< XComponent > xCurrentDocument;
243 if( bExport )
244 xCurrentDocument = getFrontMostDocument( m_pFilterInfo->maDocumentService );
245 m_pPBCurrentDocument->Enable( bExport && xCurrentDocument.is() );
246 m_pFTNameOfCurrentFile->Enable( bExport && xCurrentDocument.is() );
248 if( xCurrentDocument.is() )
250 OUString aTitle;
251 Reference< XDocumentPropertiesSupplier > xDPS( xCurrentDocument, UNO_QUERY );
252 if( xDPS.is() )
254 Reference< XDocumentProperties > xProps( xDPS->getDocumentProperties() );
255 if( xProps.is() )
257 aTitle = xProps->getTitle();
261 if( aTitle.isEmpty() )
263 Reference< XStorable > xStorable( xCurrentDocument, UNO_QUERY );
264 if( xStorable.is() )
266 if( xStorable->hasLocation() )
268 OUString aURL( xStorable->getLocation() );
269 aTitle = getFileNameFromURL( aURL );
274 m_pFTNameOfCurrentFile->SetText( aTitle );
278 void XMLFilterTestDialog::initDialog()
280 DBG_ASSERT( m_pFilterInfo, "i need a filter I can test!" );
281 if( NULL == m_pFilterInfo )
282 return;
284 OUString aTitle( m_sDialogTitle );
285 aTitle = aTitle.replaceFirst( "%s", m_pFilterInfo->maFilterName );
286 SetText( aTitle );
288 bool bImport = (m_pFilterInfo->maFlags & 1) == 1;
289 bool bExport = (m_pFilterInfo->maFlags & 2) == 2;
291 updateCurrentDocumentButtonState();
293 m_pExport->Enable(bExport);
294 m_pFTExportXSLTFile->SetText( getFileNameFromURL( m_pFilterInfo->maExportXSLT ) );
298 m_pImport->Enable(bImport);
299 m_pFTImportTemplate->Enable(bImport && !m_pFilterInfo->maImportTemplate.isEmpty());
300 m_pFTImportTemplateFile->Enable(bImport && !m_pFilterInfo->maImportTemplate.isEmpty());
301 m_pPBRecentFile->Enable(bImport && !m_sImportRecentFile.isEmpty());
302 m_pFTNameOfRecentFile->Enable(bImport && !m_sImportRecentFile.isEmpty());
304 m_pFTImportXSLTFile->SetText( getFileNameFromURL( m_pFilterInfo->maImportXSLT ) );
305 m_pFTImportTemplateFile->SetText( getFileNameFromURL( m_pFilterInfo->maImportTemplate ) );
306 m_pFTNameOfRecentFile->SetText( getFileNameFromURL( m_sImportRecentFile ) );
309 void XMLFilterTestDialog::onExportBrowse()
313 // Open Fileopen-Dialog
314 ::sfx2::FileDialogHelper aDlg(
315 com::sun::star::ui::dialogs::TemplateDescription::FILEOPEN_SIMPLE,
316 0 );
318 Reference< XNameAccess > xFilterContainer( mxContext->getServiceManager()->createInstanceWithContext( "com.sun.star.document.FilterFactory", mxContext ), UNO_QUERY );
319 Reference< XNameAccess > xTypeDetection( mxContext->getServiceManager()->createInstanceWithContext( "com.sun.star.document.TypeDetection", mxContext ), UNO_QUERY );
320 if( xFilterContainer.is() && xTypeDetection.is() )
322 Sequence< OUString > aFilterNames( xFilterContainer->getElementNames() );
323 OUString* pFilterName = aFilterNames.getArray();
325 for( sal_Int32 nFilter = 0; nFilter < aFilterNames.getLength(); nFilter++, pFilterName++ )
327 Sequence< PropertyValue > aValues;
329 Any aAny( xFilterContainer->getByName( *pFilterName ) );
330 if( !(aAny >>= aValues) )
331 continue;
333 OUString aInterfaceName;
334 PropertyValue* pValues = aValues.getArray();
335 OUString aType, aService;
336 sal_Int32 nFlags( 0 );
338 int nFound = 0;
340 for( sal_Int32 nValue = 0; (nValue < aValues.getLength()) && (nFound != 15); nValue++, pValues++ )
342 if ( pValues->Name == "Type" )
344 pValues->Value >>= aType;
345 nFound |= 1;
347 else if ( pValues->Name == "DocumentService" )
349 pValues->Value >>= aService;
350 nFound |= 2;
352 else if ( pValues->Name == "Flags" )
354 pValues->Value >>= nFlags;
355 nFound |= 4;
357 if ( pValues->Name == "UIName" )
359 pValues->Value >>= aInterfaceName;
360 nFound |= 8;
365 if( (nFound == 15) && (!aType.isEmpty() && aService == m_pFilterInfo->maDocumentService) )
367 // see if this filter is not suppressed in dialog
368 if( (nFlags & 0x1000) == 0 )
370 aAny = xTypeDetection->getByName( aType );
371 Sequence< PropertyValue > aValues2;
373 if( aAny >>= aValues2 )
375 PropertyValue* pValues2 = aValues2.getArray();
376 sal_Int32 nValue;
378 OUString aExtension;
379 for( nValue = 0; nValue < aValues2.getLength(); nValue++, pValues2++ )
381 if ( pValues2->Name == "Extensions" )
383 Sequence< OUString > aExtensions;
384 if( pValues2->Value >>= aExtensions )
386 const sal_Int32 nCount( aExtensions.getLength() );
387 OUString* pExtensions = aExtensions.getArray();
388 sal_Int32 n;
389 for( n = 0; n < nCount; n++ )
391 if( n > 0 )
392 aExtension += ";";
393 aExtension += "*.";
394 aExtension += (*pExtensions++);
400 OUString aFilterName( aInterfaceName + " (" + aExtension + ")" );
402 aDlg.AddFilter( aFilterName, aExtension );
404 if( (nFlags & 0x100) == 0x100 )
405 aDlg.SetCurrentFilter( aFilterName );
413 aDlg.SetDisplayDirectory( m_sExportRecentFile );
415 if ( aDlg.Execute() == ERRCODE_NONE )
417 m_sExportRecentFile = aDlg.GetPath();
419 Reference< XDesktop2 > xLoader = Desktop::create( mxContext );
420 Reference< XInteractionHandler2 > xInter = InteractionHandler::createWithParent(mxContext, 0);
421 OUString aFrame( "_default" );
422 Sequence< PropertyValue > aArguments(1);
423 aArguments[0].Name = "InteractionHandler";
424 aArguments[0].Value <<= xInter;
425 Reference< XComponent > xComp( xLoader->loadComponentFromURL( m_sExportRecentFile, aFrame, 0, aArguments ) );
426 if( xComp.is() )
428 doExport( xComp );
432 catch(const Exception&)
434 OSL_FAIL("XMLFilterTestDialog::onExportBrowse exception caught!");
437 initDialog();
440 void XMLFilterTestDialog::onExportCurrentDocument()
442 doExport( getFrontMostDocument( m_pFilterInfo->maDocumentService ) );
445 void XMLFilterTestDialog::doExport( Reference< XComponent > xComp )
449 Reference< XStorable > xStorable( xComp, UNO_QUERY );
450 if( xStorable.is() )
452 OUString const ext(".xml");
453 utl::TempFile aTempFile(OUString(), true, &ext);
454 OUString aTempFileURL( aTempFile.GetURL() );
456 const application_info_impl* pAppInfo = getApplicationInfo( m_pFilterInfo->maExportService );
457 if( pAppInfo )
459 File aOutputFile( aTempFileURL );
460 /* File::RC rc = */ aOutputFile.open( osl_File_OpenFlag_Write );
462 // create xslt exporter
463 Reference< XOutputStream > xIS( new comphelper::OSLOutputStreamWrapper( aOutputFile ) );
464 int bUseDocType = m_pFilterInfo->maDocType.isEmpty() ? 0 : 1;
465 Sequence< PropertyValue > aSourceData( 2 + bUseDocType );
466 int i = 0;
469 aSourceData[i ].Name = "OutputStream";
470 aSourceData[i++].Value <<= xIS;
472 aSourceData[i].Name = "Indent";
473 aSourceData[i++].Value <<= true;
475 if( bUseDocType )
477 aSourceData[i ].Name = "DocType_Public";
478 aSourceData[i++].Value <<= m_pFilterInfo->maDocType;
481 Reference< XExportFilter > xExporter( mxContext->getServiceManager()->createInstanceWithContext( "com.sun.star.documentconversion.XSLTFilter", mxContext ), UNO_QUERY );
482 Reference< XDocumentHandler > xHandler( xExporter, UNO_QUERY );
483 if( xHandler.is() )
485 Sequence< OUString > aFilterUserData( m_pFilterInfo->getFilterUserData() );
486 xExporter->exporter( aSourceData, aFilterUserData );
488 Reference< XMultiServiceFactory > xDocFac( xComp, UNO_QUERY );
490 Reference< XEmbeddedObjectResolver > xObjectResolver;
491 Reference< XGraphicObjectResolver > xGrfResolver;
493 if( xDocFac.is() )
497 xGrfResolver = Reference< XGraphicObjectResolver >::query( xDocFac->createInstance("com.sun.star.document.ExportGraphicObjectResolver") );
498 xObjectResolver = Reference< XEmbeddedObjectResolver >::query( xDocFac->createInstance("com.sun.star.document.ExportEmbeddedObjectResolver") );
500 catch( const Exception& )
505 Sequence< Any > aArgs( 1 + ( xGrfResolver.is() ? 1 : 0 ) + ( xObjectResolver.is() ? 1 : 0 ) );
506 Any* pArgs = aArgs.getArray();
507 if( xGrfResolver.is() ) *pArgs++ <<= xGrfResolver;
508 if( xObjectResolver.is() ) *pArgs++ <<= xObjectResolver;
510 // *pArgs++ <<= xInfoSet;
511 *pArgs <<= xHandler;
513 Reference< XFilter > xFilter( mxContext->getServiceManager()->createInstanceWithArgumentsAndContext( pAppInfo->maXMLExporter, aArgs, mxContext ), UNO_QUERY );
514 if( xFilter.is() )
516 Reference< XExporter > xExporter2( xFilter, UNO_QUERY );
517 if( xExporter2.is() )
519 xExporter2->setSourceDocument( xComp );
521 Sequence< PropertyValue > aDescriptor( 1 );
522 aDescriptor[0].Name = "FileName";
523 aDescriptor[0].Value <<= aTempFileURL;
525 if( xFilter->filter( aDescriptor ) )
526 displayXMLFile( aTempFileURL );
533 catch( const Exception& )
535 OSL_FAIL( "XMLFilterTestDialog::doExport exception catched!" );
539 void XMLFilterTestDialog::displayXMLFile( const OUString& rURL )
541 Reference< XSystemShellExecute > xSystemShellExecute(
542 SystemShellExecute::create(comphelper::getProcessComponentContext()) );
543 xSystemShellExecute->execute( rURL, OUString(), SystemShellExecuteFlags::URIS_ONLY );
546 void XMLFilterTestDialog::onImportBrowse()
548 // Open Fileopen-Dialog
549 ::sfx2::FileDialogHelper aDlg(
550 com::sun::star::ui::dialogs::TemplateDescription::FILEOPEN_SIMPLE, 0 );
551 OUString aFilterName( m_pFilterInfo->maInterfaceName );
552 OUString aExtensions;
554 int nLastIndex = 0;
555 int nCurrentIndex = 0;
556 for( int i = 0; nLastIndex != -1; i++ )
558 nLastIndex = m_pFilterInfo->maExtension.indexOf( ';', nLastIndex );
560 if( i > 0 )
561 aExtensions += ";";
563 aExtensions += "*.";
565 if( nLastIndex == -1 )
568 aExtensions += m_pFilterInfo->maExtension.copy( nCurrentIndex );
570 else
572 aExtensions += m_pFilterInfo->maExtension.copy( nCurrentIndex, nLastIndex - nCurrentIndex );
573 nCurrentIndex = nLastIndex + 1;
574 nLastIndex = nCurrentIndex;
578 aFilterName += " (" + aExtensions + ")";
580 aDlg.AddFilter( aFilterName, aExtensions );
581 aDlg.SetDisplayDirectory( m_sImportRecentFile );
583 if ( aDlg.Execute() == ERRCODE_NONE )
585 m_sImportRecentFile = aDlg.GetPath();
586 import( m_sImportRecentFile );
589 initDialog();
592 void XMLFilterTestDialog::onImportRecentDocument()
594 import( m_sImportRecentFile );
597 void XMLFilterTestDialog::import( const OUString& rURL )
601 Reference< XDesktop2 > xLoader = Desktop::create( mxContext );
602 Reference< XInteractionHandler2 > xInter = InteractionHandler::createWithParent(mxContext, 0);
604 OUString aFrame( "_default" );
605 Sequence< PropertyValue > aArguments(2);
606 aArguments[0].Name = "FilterName";
607 aArguments[0].Value <<= m_pFilterInfo->maFilterName;
608 aArguments[1].Name = "InteractionHandler";
609 aArguments[1].Value <<= xInter;
611 xLoader->loadComponentFromURL( rURL, aFrame, 0, aArguments );
613 if( m_pCBXDisplaySource->IsChecked() )
615 OUString const ext(".xml");
616 TempFile aTempFile(OUString(), true, &ext);
617 OUString aTempFileURL( aTempFile.GetURL() );
619 Reference< XImportFilter > xImporter( mxContext->getServiceManager()->createInstanceWithContext( "com.sun.star.documentconversion.XSLTFilter", mxContext ), UNO_QUERY );
620 if( xImporter.is() )
622 osl::File aInputFile( rURL );
623 aInputFile.open( osl_File_OpenFlag_Read );
625 Reference< XInputStream > xIS( new comphelper::OSLInputStreamWrapper( aInputFile ) );
627 Sequence< PropertyValue > aSourceData( 3 );
628 int i = 0;
630 aSourceData[i ].Name = "InputStream";
631 aSourceData[i++].Value <<= xIS;
633 aSourceData[i ].Name = "FileName";
634 aSourceData[i++].Value <<= rURL;
636 aSourceData[i ].Name = "Indent";
637 aSourceData[i++].Value <<= true;
639 Reference< XWriter > xWriter = Writer::create( mxContext );
641 File aOutputFile( aTempFileURL );
642 aOutputFile.open( osl_File_OpenFlag_Write );
644 Reference< XOutputStream > xOS( new OSLOutputStreamWrapper( aOutputFile ) );
645 xWriter->setOutputStream( xOS );
647 Sequence< OUString > aFilterUserData( m_pFilterInfo->getFilterUserData() );
648 xImporter->importer( aSourceData, xWriter, aFilterUserData );
651 displayXMLFile( aTempFileURL );
654 catch(const Exception&)
656 OSL_FAIL("XMLFilterTestDialog::import catched an exception" );
660 IMPL_LINK(XMLFilterTestDialog, ClickHdl_Impl, PushButton *, pButton )
662 if (m_pPBExportBrowse == pButton)
664 onExportBrowse();
666 else if (m_pPBCurrentDocument == pButton)
668 onExportCurrentDocument();
670 else if (m_pPBImportBrowse == pButton)
672 onImportBrowse();
674 else if (m_pPBRecentFile == pButton)
676 onImportRecentDocument();
678 else if (m_pPBClose == pButton)
680 Close();
683 return 0;
686 /** returns the front most open component that supports the given service */
687 Reference< XComponent > XMLFilterTestDialog::getFrontMostDocument( const OUString& rServiceName )
689 Reference< XComponent > xRet;
693 Reference< XDesktop2 > xDesktop = Desktop::create( mxContext );
694 Reference< XComponent > xTest( mxLastFocusModel );
695 if( checkComponent( xTest, rServiceName ) )
697 xRet = xTest;
699 else
701 xTest = xDesktop->getCurrentComponent();
703 if( checkComponent( xTest, rServiceName ) )
705 xRet = xTest;
707 else
709 Reference< XEnumerationAccess > xAccess( xDesktop->getComponents() );
710 if( xAccess.is() )
712 Reference< XEnumeration > xEnum( xAccess->createEnumeration() );
713 if( xEnum.is() )
715 while( xEnum->hasMoreElements() )
717 if( (xEnum->nextElement() >>= xTest) && xTest.is() )
719 if( checkComponent( xTest, rServiceName ) )
721 xRet = xTest;
722 break;
731 catch( const Exception& )
733 OSL_FAIL( "XMLFilterTestDialog::getFrontMostDocument exception catched!" );
736 return xRet;
739 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */