bump product version to 4.1.6.2
[LibreOffice.git] / filter / source / xsltdialog / xmlfiltertestdialog.cxx
blob099aec7933d67b16c040082eeebd8377f2418f21
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/GlobalEventBroadcaster.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::XEventListener >
73 public:
74 GlobalEventListenerImpl( XMLFilterTestDialog* pDialog );
76 // XEventListener
77 virtual void SAL_CALL notifyEvent( const com::sun::star::document::EventObject& Event ) throw (RuntimeException);
79 // lang::XEventListener
80 virtual void SAL_CALL disposing( const com::sun::star::lang::EventObject& Source ) throw (RuntimeException);
81 private:
82 XMLFilterTestDialog* mpDialog;
85 GlobalEventListenerImpl::GlobalEventListenerImpl( XMLFilterTestDialog* pDialog )
86 : mpDialog( pDialog )
90 void SAL_CALL GlobalEventListenerImpl::notifyEvent( const com::sun::star::document::EventObject& Event ) throw (RuntimeException)
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)
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( OUString( "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(Window* pParent,
137 const Reference<XMultiServiceFactory>& rxMSF)
138 : ModalDialog(pParent, "TestXMLFilterDialog", "filter/ui/testxmlfilter.ui")
139 , mxMSF(rxMSF)
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 = Reference < XEventBroadcaster >( GlobalEventBroadcaster::create(comphelper::getComponentContext(mxMSF)), UNO_QUERY_THROW );
170 mxGlobalEventListener = new GlobalEventListenerImpl( this );
171 mxGlobalBroadcaster->addEventListener( mxGlobalEventListener );
173 catch( const Exception& )
175 OSL_FAIL( "XMLFilterTestDialog::XMLFilterTestDialog exception catched!" );
179 XMLFilterTestDialog::~XMLFilterTestDialog()
183 if( mxGlobalBroadcaster.is() )
184 mxGlobalBroadcaster->removeEventListener( mxGlobalEventListener );
186 catch( const Exception& )
188 OSL_FAIL( "XMLFilterTestDialog::~XMLFilterTestDialog exception catched!" );
191 delete m_pFilterInfo;
194 void XMLFilterTestDialog::test( const filter_info_impl& rFilterInfo )
196 delete m_pFilterInfo;
197 m_pFilterInfo = new filter_info_impl( rFilterInfo );
199 m_sImportRecentFile = OUString();
201 initDialog();
203 Execute();
206 static OUString getFileNameFromURL( OUString& rURL )
208 INetURLObject aURL( rURL );
209 OUString aName( aURL.getName(INetURLObject::LAST_SEGMENT, sal_True, INetURLObject::DECODE_WITH_CHARSET) );
210 return aName;
213 void XMLFilterTestDialog::updateCurrentDocumentButtonState( Reference< XComponent > * pRef /* = NULL */ )
215 if( pRef && pRef->is() )
217 if( checkComponent( *pRef, m_pFilterInfo->maDocumentService ) )
218 mxLastFocusModel = *pRef;
221 bool bExport = (m_pFilterInfo->maFlags & 2) == 2;
222 Reference< XComponent > xCurrentDocument;
223 if( bExport )
224 xCurrentDocument = getFrontMostDocument( m_pFilterInfo->maDocumentService );
225 m_pPBCurrentDocument->Enable( bExport && xCurrentDocument.is() );
226 m_pFTNameOfCurrentFile->Enable( bExport && xCurrentDocument.is() );
228 if( xCurrentDocument.is() )
230 OUString aTitle;
231 Reference< XDocumentPropertiesSupplier > xDPS( xCurrentDocument, UNO_QUERY );
232 if( xDPS.is() )
234 Reference< XDocumentProperties > xProps( xDPS->getDocumentProperties() );
235 if( xProps.is() )
237 aTitle = xProps->getTitle();
241 if( aTitle.isEmpty() )
243 Reference< XStorable > xStorable( xCurrentDocument, UNO_QUERY );
244 if( xStorable.is() )
246 if( xStorable->hasLocation() )
248 OUString aURL( xStorable->getLocation() );
249 aTitle = getFileNameFromURL( aURL );
254 m_pFTNameOfCurrentFile->SetText( aTitle );
258 void XMLFilterTestDialog::initDialog()
260 DBG_ASSERT( m_pFilterInfo, "i need a filter I can test!" );
261 if( NULL == m_pFilterInfo )
262 return;
264 String aTitle( m_sDialogTitle );
265 aTitle.SearchAndReplace( String( RTL_CONSTASCII_USTRINGPARAM("%s") ), m_pFilterInfo->maFilterName );
266 SetText( aTitle );
268 bool bImport = (m_pFilterInfo->maFlags & 1) == 1;
269 bool bExport = (m_pFilterInfo->maFlags & 2) == 2;
271 updateCurrentDocumentButtonState();
273 m_pExport->Enable(bExport);
274 m_pFTExportXSLTFile->SetText( getFileNameFromURL( m_pFilterInfo->maExportXSLT ) );
276 // ---
278 m_pImport->Enable(bImport);
279 m_pFTImportTemplate->Enable(bImport && !m_pFilterInfo->maImportTemplate.isEmpty());
280 m_pFTImportTemplateFile->Enable(bImport && !m_pFilterInfo->maImportTemplate.isEmpty());
281 m_pPBRecentFile->Enable(bImport && !m_sImportRecentFile.isEmpty());
282 m_pFTNameOfRecentFile->Enable(bImport && !m_sImportRecentFile.isEmpty());
284 m_pFTImportXSLTFile->SetText( getFileNameFromURL( m_pFilterInfo->maImportXSLT ) );
285 m_pFTImportTemplateFile->SetText( getFileNameFromURL( m_pFilterInfo->maImportTemplate ) );
286 m_pFTNameOfRecentFile->SetText( getFileNameFromURL( m_sImportRecentFile ) );
289 void XMLFilterTestDialog::onExportBrowse()
293 // Open Fileopen-Dialog
294 ::sfx2::FileDialogHelper aDlg(
295 com::sun::star::ui::dialogs::TemplateDescription::FILEOPEN_SIMPLE,
296 0 );
298 Reference< XNameAccess > xFilterContainer( mxMSF->createInstance( OUString( "com.sun.star.document.FilterFactory" ) ), UNO_QUERY );
299 Reference< XNameAccess > xTypeDetection( mxMSF->createInstance( OUString( "com.sun.star.document.TypeDetection" ) ), UNO_QUERY );
300 if( xFilterContainer.is() && xTypeDetection.is() )
302 Sequence< OUString > aFilterNames( xFilterContainer->getElementNames() );
303 OUString* pFilterName = aFilterNames.getArray();
305 for( sal_Int32 nFilter = 0; nFilter < aFilterNames.getLength(); nFilter++, pFilterName++ )
307 Sequence< PropertyValue > aValues;
309 Any aAny( xFilterContainer->getByName( *pFilterName ) );
310 if( !(aAny >>= aValues) )
311 continue;
313 OUString aInterfaceName;
314 PropertyValue* pValues = aValues.getArray();
315 OUString aType, aService;
316 sal_Int32 nFlags( 0 );
318 int nFound = 0;
320 for( sal_Int32 nValue = 0; (nValue < aValues.getLength()) && (nFound != 15); nValue++, pValues++ )
322 if ( pValues->Name == "Type" )
324 pValues->Value >>= aType;
325 nFound |= 1;
327 else if ( pValues->Name == "DocumentService" )
329 pValues->Value >>= aService;
330 nFound |= 2;
332 else if ( pValues->Name == "Flags" )
334 pValues->Value >>= nFlags;
335 nFound |= 4;
337 if ( pValues->Name == "UIName" )
339 pValues->Value >>= aInterfaceName;
340 nFound |= 8;
345 if( (nFound == 15) && (!aType.isEmpty() && aService == m_pFilterInfo->maDocumentService) )
347 // see if this filter is not supressed in dialog
348 if( (nFlags & 0x1000) == 0 )
350 aAny = xTypeDetection->getByName( aType );
351 Sequence< PropertyValue > aValues2;
353 if( aAny >>= aValues2 )
355 PropertyValue* pValues2 = aValues2.getArray();
356 sal_Int32 nValue;
358 OUString aExtension;
359 for( nValue = 0; nValue < aValues2.getLength(); nValue++, pValues2++ )
361 if ( pValues2->Name == "Extensions" )
363 Sequence< OUString > aExtensions;
364 if( pValues2->Value >>= aExtensions )
366 const sal_Int32 nCount( aExtensions.getLength() );
367 OUString* pExtensions = aExtensions.getArray();
368 sal_Int32 n;
369 for( n = 0; n < nCount; n++ )
371 if( n > 0 )
372 aExtension += OUString( sal_Unicode(';') );
373 aExtension += "*.";
374 aExtension += (*pExtensions++);
380 String aExtensions( aExtension );
381 String aFilterName( aInterfaceName );
382 aFilterName += String( RTL_CONSTASCII_USTRINGPARAM(" (") );
383 aFilterName += aExtensions;
384 aFilterName += sal_Unicode(')');
386 aDlg.AddFilter( aFilterName, aExtensions );
388 if( (nFlags & 0x100) == 0x100 )
389 aDlg.SetCurrentFilter( aFilterName );
397 aDlg.SetDisplayDirectory( m_sExportRecentFile );
399 if ( aDlg.Execute() == ERRCODE_NONE )
401 m_sExportRecentFile = aDlg.GetPath();
403 Reference< XDesktop2 > xLoader = Desktop::create( comphelper::getComponentContext(mxMSF) );
404 Reference< XInteractionHandler2 > xInter( InteractionHandler::createWithParent(comphelper::getComponentContext(mxMSF), 0) );
405 OUString aFrame( "_default" );
406 Sequence< PropertyValue > aArguments(1);
407 aArguments[0].Name = OUString( "InteractionHandler" );
408 aArguments[0].Value <<= xInter;
409 Reference< XComponent > xComp( xLoader->loadComponentFromURL( m_sExportRecentFile, aFrame, 0, aArguments ) );
410 if( xComp.is() )
412 doExport( xComp );
416 catch(const Exception&)
418 OSL_FAIL("XMLFilterTestDialog::onExportBrowse exception caught!");
421 initDialog();
424 void XMLFilterTestDialog::onExportCurrentDocument()
426 doExport( getFrontMostDocument( m_pFilterInfo->maDocumentService ) );
429 void XMLFilterTestDialog::doExport( Reference< XComponent > xComp )
433 Reference< XStorable > xStorable( xComp, UNO_QUERY );
434 if( xStorable.is() )
436 String leadingChars;
437 String ext(RTL_CONSTASCII_USTRINGPARAM(".xml"));
438 utl::TempFile aTempFile(leadingChars, &ext);
439 OUString aTempFileURL( aTempFile.GetURL() );
441 const application_info_impl* pAppInfo = getApplicationInfo( m_pFilterInfo->maExportService );
442 if( pAppInfo )
444 File aOutputFile( aTempFileURL );
445 /* File::RC rc = */ aOutputFile.open( osl_File_OpenFlag_Write );
447 // create xslt exporter
448 Reference< XOutputStream > xIS( new comphelper::OSLOutputStreamWrapper( aOutputFile ) );
449 int bUseDocType = m_pFilterInfo->maDocType.isEmpty() ? 0 : 1;
450 Sequence< PropertyValue > aSourceData( 2 + bUseDocType );
451 int i = 0;
454 aSourceData[i ].Name = OUString( "OutputStream" );
455 aSourceData[i++].Value <<= xIS;
457 aSourceData[i].Name = OUString( "Indent" );
458 aSourceData[i++].Value <<= (sal_Bool)sal_True;
460 if( bUseDocType )
462 aSourceData[i ].Name = OUString("DocType_Public");
463 aSourceData[i++].Value <<= m_pFilterInfo->maDocType;
466 Reference< XExportFilter > xExporter( mxMSF->createInstance( OUString( "com.sun.star.documentconversion.XSLTFilter" ) ), UNO_QUERY );
467 Reference< XDocumentHandler > xHandler( xExporter, UNO_QUERY );
468 if( xHandler.is() )
470 Sequence< OUString > aFilterUserData( m_pFilterInfo->getFilterUserData() );
471 xExporter->exporter( aSourceData, aFilterUserData );
473 Reference< XMultiServiceFactory > xDocFac( xComp, UNO_QUERY );
475 Reference< XEmbeddedObjectResolver > xObjectResolver;
476 Reference< XGraphicObjectResolver > xGrfResolver;
478 if( xDocFac.is() )
482 xGrfResolver = Reference< XGraphicObjectResolver >::query( xDocFac->createInstance( OUString( "com.sun.star.document.ExportGraphicObjectResolver" ) ) );
483 xObjectResolver = Reference< XEmbeddedObjectResolver >::query( xDocFac->createInstance( OUString( "com.sun.star.document.ExportEmbeddedObjectResolver" ) ) );
485 catch( const Exception& )
490 Sequence< Any > aArgs( 1 + ( xGrfResolver.is() ? 1 : 0 ) + ( xObjectResolver.is() ? 1 : 0 ) );
491 Any* pArgs = aArgs.getArray();
492 if( xGrfResolver.is() ) *pArgs++ <<= xGrfResolver;
493 if( xObjectResolver.is() ) *pArgs++ <<= xObjectResolver;
495 // *pArgs++ <<= xInfoSet;
496 *pArgs <<= xHandler;
498 Reference< XFilter > xFilter( mxMSF->createInstanceWithArguments( pAppInfo->maXMLExporter, aArgs ), UNO_QUERY );
499 if( xFilter.is() )
501 Reference< XExporter > xExporter2( xFilter, UNO_QUERY );
502 if( xExporter2.is() )
504 xExporter2->setSourceDocument( xComp );
506 Sequence< PropertyValue > aDescriptor( 1 );
507 aDescriptor[0].Name = OUString( "FileName" );
508 aDescriptor[0].Value <<= aTempFileURL;
510 if( xFilter->filter( aDescriptor ) )
511 displayXMLFile( aTempFileURL );
518 catch( const Exception& )
520 OSL_FAIL( "XMLFilterTestDialog::doExport exception catched!" );
524 void XMLFilterTestDialog::displayXMLFile( const OUString& rURL )
526 Reference< XSystemShellExecute > xSystemShellExecute(
527 SystemShellExecute::create(comphelper::getProcessComponentContext()) );
528 xSystemShellExecute->execute( rURL, OUString(), SystemShellExecuteFlags::URIS_ONLY );
531 void XMLFilterTestDialog::onImportBrowse()
533 // Open Fileopen-Dialog
534 ::sfx2::FileDialogHelper aDlg(
535 com::sun::star::ui::dialogs::TemplateDescription::FILEOPEN_SIMPLE, 0 );
536 String aFilterName( m_pFilterInfo->maInterfaceName );
537 String aExtensions;
539 int nLastIndex = 0;
540 int nCurrentIndex = 0;
541 for( int i = 0; nLastIndex != -1; i++ )
543 nLastIndex = m_pFilterInfo->maExtension.indexOf( sal_Unicode( ';' ), nLastIndex );
545 if( i > 0 )
546 aExtensions += ';';
548 aExtensions += String( RTL_CONSTASCII_USTRINGPARAM("*.") );
550 if( nLastIndex == -1 )
553 aExtensions += String( m_pFilterInfo->maExtension.copy( nCurrentIndex ) );
555 else
557 aExtensions += String( m_pFilterInfo->maExtension.copy( nCurrentIndex, nLastIndex - nCurrentIndex ) );
558 nCurrentIndex = nLastIndex + 1;
559 nLastIndex = nCurrentIndex;
563 aFilterName += String( RTL_CONSTASCII_USTRINGPARAM( " (" ) );
564 aFilterName += aExtensions;
565 aFilterName += sal_Unicode(')');
567 aDlg.AddFilter( aFilterName, aExtensions );
568 aDlg.SetDisplayDirectory( m_sImportRecentFile );
570 if ( aDlg.Execute() == ERRCODE_NONE )
572 m_sImportRecentFile = aDlg.GetPath();
573 import( m_sImportRecentFile );
576 initDialog();
579 void XMLFilterTestDialog::onImportRecentDocument()
581 import( m_sImportRecentFile );
584 void XMLFilterTestDialog::import( const OUString& rURL )
588 Reference< XDesktop2 > xLoader = Desktop::create( comphelper::getComponentContext(mxMSF) );
589 Reference< XInteractionHandler2 > xInter( InteractionHandler::createWithParent(comphelper::getComponentContext(mxMSF), 0) );
591 OUString aFrame( "_default" );
592 Sequence< PropertyValue > aArguments(2);
593 aArguments[0].Name = OUString( "FilterName" );
594 aArguments[0].Value <<= m_pFilterInfo->maFilterName;
595 aArguments[1].Name = OUString( "InteractionHandler" );
596 aArguments[1].Value <<= xInter;
598 xLoader->loadComponentFromURL( rURL, aFrame, 0, aArguments );
600 if( m_pCBXDisplaySource->IsChecked() )
602 String lead;
603 String ext(RTL_CONSTASCII_USTRINGPARAM(".xml"));
604 TempFile aTempFile(lead, &ext);
605 OUString aTempFileURL( aTempFile.GetURL() );
607 Reference< XImportFilter > xImporter( mxMSF->createInstance( OUString( "com.sun.star.documentconversion.XSLTFilter" ) ), UNO_QUERY );
608 if( xImporter.is() )
610 osl::File aInputFile( rURL );
611 aInputFile.open( osl_File_OpenFlag_Read );
613 Reference< XInputStream > xIS( new comphelper::OSLInputStreamWrapper( aInputFile ) );
615 Sequence< PropertyValue > aSourceData( 3 );
616 int i = 0;
618 aSourceData[i ].Name = OUString( "InputStream" );
619 aSourceData[i++].Value <<= xIS;
621 aSourceData[i ].Name = OUString( "FileName" );
622 aSourceData[i++].Value <<= rURL;
624 aSourceData[i ].Name = OUString( "Indent" );
625 aSourceData[i++].Value <<= (sal_Bool)sal_True;
627 Reference< XWriter > xWriter = Writer::create( comphelper::getComponentContext(mxMSF) );
629 File aOutputFile( aTempFileURL );
630 aOutputFile.open( osl_File_OpenFlag_Write );
632 Reference< XOutputStream > xOS( new OSLOutputStreamWrapper( aOutputFile ) );
633 Reference< XActiveDataSource > xDocSrc( xWriter, UNO_QUERY );
634 xDocSrc->setOutputStream( xOS );
636 Sequence< OUString > aFilterUserData( m_pFilterInfo->getFilterUserData() );
637 xImporter->importer( aSourceData, Reference<XDocumentHandler>(xWriter, UNO_QUERY_THROW), aFilterUserData );
640 displayXMLFile( aTempFileURL );
643 catch(const Exception&)
645 OSL_FAIL("XMLFilterTestDialog::import catched an exception" );
649 IMPL_LINK(XMLFilterTestDialog, ClickHdl_Impl, PushButton *, pButton )
651 if (m_pPBExportBrowse == pButton)
653 onExportBrowse();
655 else if (m_pPBCurrentDocument == pButton)
657 onExportCurrentDocument();
659 else if (m_pPBImportBrowse == pButton)
661 onImportBrowse();
663 else if (m_pPBRecentFile == pButton)
665 onImportRecentDocument();
667 else if (m_pPBClose == pButton)
669 Close();
672 return 0;
675 /** returns the front most open component that supports the given service */
676 Reference< XComponent > XMLFilterTestDialog::getFrontMostDocument( const OUString& rServiceName )
678 Reference< XComponent > xRet;
682 Reference< XDesktop2 > xDesktop = Desktop::create( comphelper::getComponentContext(mxMSF) );
683 Reference< XComponent > xTest( mxLastFocusModel );
684 if( checkComponent( xTest, rServiceName ) )
686 xRet = xTest;
688 else
690 xTest = (Reference< XComponent >)xDesktop->getCurrentComponent();
692 if( checkComponent( xTest, rServiceName ) )
694 xRet = xTest;
696 else
698 Reference< XEnumerationAccess > xAccess( xDesktop->getComponents() );
699 if( xAccess.is() )
701 Reference< XEnumeration > xEnum( xAccess->createEnumeration() );
702 if( xEnum.is() )
704 while( xEnum->hasMoreElements() )
706 if( (xEnum->nextElement() >>= xTest) && xTest.is() )
708 if( checkComponent( xTest, rServiceName ) )
710 xRet = xTest;
711 break;
720 catch( const Exception& )
722 OSL_FAIL( "XMLFilterTestDialog::getFrontMostDocument exception catched!" );
725 return xRet;
728 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */