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/XGraphicStorageHandler.hpp>
26#include <com/sun/star/document/XEmbeddedObjectResolver.hpp>
27#include <com/sun/star/frame/theGlobalEventBroadcaster.hpp>
28#include <com/sun/star/frame/Desktop.hpp>
29#include <com/sun/star/frame/XStorable.hpp>
30#include <com/sun/star/lang/XMultiServiceFactory.hpp>
31#include <com/sun/star/lang/XServiceInfo.hpp>
32#include <com/sun/star/system/SystemShellExecute.hpp>
33#include <com/sun/star/system/SystemShellExecuteFlags.hpp>
34#include <com/sun/star/task/InteractionHandler.hpp>
35#include <com/sun/star/ui/dialogs/TemplateDescription.hpp>
36#include <com/sun/star/xml/XImportFilter.hpp>
37#include <com/sun/star/xml/XExportFilter.hpp>
38#include <com/sun/star/xml/sax/Writer.hpp>
44#include <osl/file.hxx>
66using namespace com::sun::star::system;
72class GlobalEventListenerImpl :
public ::cppu::WeakImplHelper< css::document::XDocumentEventListener >
78 virtual void SAL_CALL documentEventOccured(
const css::document::DocumentEvent& Event )
override;
81 virtual void SAL_CALL disposing(
const css::lang::EventObject& Source )
override;
93void SAL_CALL GlobalEventListenerImpl::documentEventOccured(
const css::document::DocumentEvent& Event )
96 if( Event.EventName ==
"OnFocus" || Event.EventName ==
"OnUnload" )
99 mpDialog->updateCurrentDocumentButtonState( &xComp );
103void SAL_CALL GlobalEventListenerImpl::disposing(
const css::lang::EventObject& )
115 if( xInfo->supportsService( rServiceName ) )
118 if ( rServiceName ==
"com.sun.star.drawing.DrawingDocument" )
121 if( !xInfo->supportsService(
"com.sun.star.presentation.PresentationDocument") )
141 : GenericDialogController(pParent,
"filter/ui/testxmlfilter.ui",
"TestXMLFilterDialog")
143 , m_xExport(m_xBuilder->weld_widget(
"export"))
144 , m_xFTExportXSLTFile(m_xBuilder->weld_label(
"exportxsltfile"))
145 , m_xPBExportBrowse(m_xBuilder->weld_button(
"exportbrowse"))
146 , m_xPBCurrentDocument(m_xBuilder->weld_button(
"currentdocument"))
147 , m_xFTNameOfCurrentFile(m_xBuilder->weld_label(
"currentfilename"))
148 , m_xImport(m_xBuilder->weld_widget(
"import"))
149 , m_xFTImportXSLTFile(m_xBuilder->weld_label(
"importxsltfile"))
150 , m_xFTImportTemplate(m_xBuilder->weld_label(
"templateimport"))
151 , m_xFTImportTemplateFile(m_xBuilder->weld_label(
"importxslttemplate"))
152 , m_xCBXDisplaySource(m_xBuilder->weld_check_button(
"displaysource"))
153 , m_xPBImportBrowse(m_xBuilder->weld_button(
"importbrowse"))
154 , m_xPBRecentFile(m_xBuilder->weld_button(
"recentfile"))
155 , m_xFTNameOfRecentFile(m_xBuilder->weld_label(
"recentfilename"))
156 , m_xPBClose(m_xBuilder->weld_button(
"close"))
211 if( pRef && pRef->is() )
224 if( !xCurrentDocument.is() )
234 aTitle = xProps->getTitle();
238 if( aTitle.isEmpty() )
243 if( xStorable->hasLocation() )
245 OUString
aURL( xStorable->getLocation() );
261 aTitle = aTitle.replaceFirst(
"%s",
m_xFilterInfo->maFilterName );
290 css::ui::dialogs::TemplateDescription::FILEOPEN_SIMPLE,
295 if( xFilterContainer.is() && xTypeDetection.is() )
299 for( OUString
const & filterName : aFilterNames )
303 Any aAny( xFilterContainer->getByName( filterName ) );
304 if( !(aAny >>= aValues) )
307 OUString aInterfaceName;
308 OUString aType, aService;
309 sal_Int32 nFlags( 0 );
313 for(
const PropertyValue& rValue : std::as_const(aValues) )
315 if ( rValue.Name ==
"Type" )
317 rValue.Value >>= aType;
320 else if ( rValue.Name ==
"DocumentService" )
322 rValue.Value >>= aService;
325 else if ( rValue.Name ==
"Flags" )
327 rValue.Value >>= nFlags;
330 else if ( rValue.Name ==
"UIName" )
332 rValue.Value >>= aInterfaceName;
340 if( (nFound == 15) && (!aType.isEmpty() && aService ==
m_xFilterInfo->maDocumentService) )
343 if( (nFlags & 0x1000) == 0 )
345 aAny = xTypeDetection->getByName( aType );
348 if( aAny >>= aValues2 )
351 for(
const PropertyValue& rProp : std::as_const(aValues2) )
353 if ( rProp.Name ==
"Extensions" )
356 if( rProp.Value >>= aExtensions )
358 const sal_Int32
nCount( aExtensions.getLength() );
359 OUString* pExtensions = aExtensions.getArray();
365 aExtension +=
"*." + *pExtensions++;
371 OUString aFilterName( aInterfaceName +
" (" + aExtension +
")" );
373 aDlg.
AddFilter( aFilterName, aExtension );
375 if( (nFlags & 0x100) == 0x100 )
422 OUString aTempFileURL( aTempFile.
GetURL() );
427 File aOutputFile( aTempFileURL );
428 (void)aOutputFile.open( osl_File_OpenFlag_Write );
432 int bUseDocType =
m_xFilterInfo->maDocType.isEmpty() ? 0 : 1;
434 auto pSourceData = aSourceData.getArray();
438 pSourceData[
i ].Name =
"OutputStream";
439 pSourceData[
i++].Value <<= xIS;
441 pSourceData[
i].Name =
"Indent";
442 pSourceData[
i++].Value <<=
true;
446 pSourceData[
i ].Name =
"DocType_Public";
455 xExporter->exporter( aSourceData, aFilterUserData );
466 xGraphicStorageHandler.set(xDocFac->createInstance(
"com.sun.star.document.ExportGraphicStorageHandler"), UNO_QUERY);
467 xObjectResolver.set( xDocFac->createInstance(
"com.sun.star.document.ExportEmbeddedObjectResolver"), UNO_QUERY );
474 Sequence< Any > aArgs( 1 + ( xGraphicStorageHandler.is() ? 1 : 0 ) + ( xObjectResolver.is() ? 1 : 0 ) );
475 Any* pArgs = aArgs.getArray();
476 if (xGraphicStorageHandler.is())
477 *pArgs++ <<= xGraphicStorageHandler;
479 if (xObjectResolver.is())
480 *pArgs++ <<= xObjectResolver;
489 if( xExporter2.is() )
491 xExporter2->setSourceDocument( xComp );
494 "FileName", aTempFileURL) };
496 if( xFilter->filter( aDescriptor ) )
514 xSystemShellExecute->execute( rURL, OUString(), SystemShellExecuteFlags::URIS_ONLY );
521 css::ui::dialogs::TemplateDescription::FILEOPEN_SIMPLE,
524 OUString aExtensions;
527 int nCurrentIndex = 0;
528 for(
int i = 0; nLastIndex != -1;
i++ )
530 nLastIndex =
m_xFilterInfo->maExtension.indexOf(
';', nLastIndex );
537 if( nLastIndex == -1 )
540 aExtensions +=
m_xFilterInfo->maExtension.subView( nCurrentIndex );
544 aExtensions +=
m_xFilterInfo->maExtension.subView( nCurrentIndex, nLastIndex - nCurrentIndex );
545 nCurrentIndex = nLastIndex + 1;
546 nLastIndex = nCurrentIndex;
550 aFilterName +=
" (" + aExtensions +
")";
552 aDlg.
AddFilter( aFilterName, aExtensions );
576 xLoader->loadComponentFromURL( rURL,
"_default", 0,
aArguments );
581 OUString aTempFileURL( aTempFile.
GetURL() );
586 osl::File aInputFile( rURL );
587 (void)aInputFile.open( osl_File_OpenFlag_Read );
599 File aOutputFile( aTempFileURL );
600 (void)aOutputFile.open( osl_File_OpenFlag_Write );
603 xWriter->setOutputStream( xOS );
606 xImporter->importer( aSourceData, xWriter, aFilterUserData );
620 if (m_xPBExportBrowse.get() == &rButton)
624 else if (m_xPBCurrentDocument.get() == &rButton)
626 onExportCurrentDocument();
628 else if (m_xPBImportBrowse.get() == &rButton)
632 else if (m_xPBRecentFile.get() == &rButton)
634 import( m_sImportRecentFile );
636 else if (m_xPBClose.get() == &rButton)
657 xTest = xDesktop->getCurrentComponent();
671 while( xEnum->hasMoreElements() )
673 if( (xEnum->nextElement() >>= xTest) && xTest.is() )
Reference< XExecutableDialog > m_xDialog
std::unique_ptr< weld::Widget > m_xExport
std::unique_ptr< weld::Label > m_xFTImportTemplateFile
std::unique_ptr< weld::Widget > m_xImport
std::unique_ptr< weld::Button > m_xPBRecentFile
void test(const filter_info_impl &rFilterInfo)
void updateCurrentDocumentButtonState(css::uno::Reference< css::lang::XComponent > const *pRef=nullptr)
static void displayXMLFile(const OUString &rURL)
std::unique_ptr< weld::Button > m_xPBImportBrowse
std::unique_ptr< weld::Button > m_xPBExportBrowse
void onExportCurrentDocument()
css::uno::Reference< css::document::XDocumentEventListener > mxGlobalEventListener
OUString m_sExportRecentFile
std::unique_ptr< weld::Label > m_xFTImportXSLTFile
XMLFilterTestDialog(weld::Window *pParent, const css::uno::Reference< css::uno::XComponentContext > &rxContext)
OUString m_sImportRecentFile
css::uno::Reference< css::lang::XComponent > getFrontMostDocument(const OUString &rServiceName)
returns the front most open component that supports the given service
virtual ~XMLFilterTestDialog() override
std::unique_ptr< weld::Label > m_xFTExportXSLTFile
css::uno::WeakReference< css::lang::XComponent > mxLastFocusModel
std::unique_ptr< filter_info_impl > m_xFilterInfo
css::uno::Reference< css::document::XDocumentEventBroadcaster > mxGlobalBroadcaster
void import(const OUString &rURL)
void doExport(const css::uno::Reference< css::lang::XComponent > &xComp)
std::unique_ptr< weld::Label > m_xFTNameOfRecentFile
std::unique_ptr< weld::CheckButton > m_xCBXDisplaySource
std::unique_ptr< weld::Button > m_xPBCurrentDocument
std::unique_ptr< weld::Label > m_xFTNameOfCurrentFile
css::uno::Reference< css::uno::XComponentContext > mxContext
std::unique_ptr< weld::Button > m_xPBClose
std::unique_ptr< weld::Label > m_xFTImportTemplate
void AddFilter(const OUString &rFilterName, const OUString &rExtension)
void SetDisplayDirectory(const OUString &rPath)
void SetCurrentFilter(const OUString &rFilter)
OUString const & GetURL() const
std::shared_ptr< weld::Dialog > m_xDialog
#define DBG_ASSERT(sCon, aError)
#define TOOLS_WARN_EXCEPTION(area, stream)
Sequence< PropertyValue > aArguments
#define LINK(Instance, Class, Member)
Reference< XComponentContext > getProcessComponentContext()
css::beans::PropertyValue makePropertyValue(const OUString &rName, T &&rValue)
const application_info_impl * getApplicationInfo(std::u16string_view rServiceName)
IMPL_LINK(XMLFilterTestDialog, ClickHdl_Impl, weld::Button &, rButton, void)
static bool checkComponent(Reference< XComponent > const &rxComponent, const OUString &rServiceName)
returns true if the given component supports the given service
static OUString getFileNameFromURL(std::u16string_view rURL)