diff options
author | Caolán McNamara <caolanm@redhat.com> | 2015-10-01 12:04:25 +0100 |
---|---|---|
committer | Caolán McNamara <caolanm@redhat.com> | 2015-10-02 09:09:39 +0100 |
commit | 4afbd0292e09d9850a3cd0d1f169c73c5a3296db (patch) | |
tree | 6a58d14e4fdb71b14ac83eb0d22bf8439371d5f6 | |
parent | d4b43fa1e146ca11dcd53acae5eb20944d3cbc94 (diff) |
vcl event filter
Change-Id: Ib10dccec244f3168f1ac4a892a09012adf38a839
-rw-r--r-- | Repository.mk | 1 | ||||
-rw-r--r-- | filter/Configuration_filter.mk | 1 | ||||
-rw-r--r-- | filter/Library_vcleventfilter.mk | 36 | ||||
-rw-r--r-- | filter/Module_filter.mk | 1 | ||||
-rw-r--r-- | filter/source/config/fragments/filters/VclEventDocument.xcu | 19 | ||||
-rw-r--r-- | filter/source/config/fragments/types/filters_Vcl_Event_Document.xcu | 18 | ||||
-rw-r--r-- | filter/source/vcleventfilter/vcleventfilter.component | 15 | ||||
-rw-r--r-- | filter/source/vcleventfilter/vcleventfilter.cxx | 137 | ||||
-rw-r--r-- | filter/source/vcleventfilter/vcleventfilter.hxx | 66 |
9 files changed, 294 insertions, 0 deletions
diff --git a/Repository.mk b/Repository.mk index 7e39aab690c1..efc7cadb11f2 100644 --- a/Repository.mk +++ b/Repository.mk @@ -428,6 +428,7 @@ $(eval $(call gb_Helper_register_libraries_for_install,OOOLIBS,ooo, \ vclplug_gen \ $(if $(ENABLE_TDE),vclplug_tde) \ ) \ + vcleventfilter \ writerperfect \ xmlscript \ xmlfa \ diff --git a/filter/Configuration_filter.mk b/filter/Configuration_filter.mk index 5fe58b0e3aca..3e126b3af42b 100644 --- a/filter/Configuration_filter.mk +++ b/filter/Configuration_filter.mk @@ -312,6 +312,7 @@ $(eval $(call filter_Configuration_add_types,fcfg_langpack,fcfg_writer_types.xcu calc_MS_Excel_40 \ calc_MS_Excel_5095 \ calc_MS_Excel_95 \ + filters_Vcl_Event_Document \ writer_MS_WinWord_5 \ writer_MS_WinWord_60 \ writer_MS_Word_95 \ diff --git a/filter/Library_vcleventfilter.mk b/filter/Library_vcleventfilter.mk new file mode 100644 index 000000000000..0009312691be --- /dev/null +++ b/filter/Library_vcleventfilter.mk @@ -0,0 +1,36 @@ +# -*- Mode: makefile-gmake; tab-width: 4; indent-tabs-mode: t -*- +#************************************************************************* +# +# This file is part of the LibreOffice project. +# +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. +# +#************************************************************************* + +$(eval $(call gb_Library_Library,vcleventfilter)) + +$(eval $(call gb_Library_set_componentfile,vcleventfilter,filter/source/vcleventfilter/vcleventfilter)) + +$(eval $(call gb_Library_use_external,vcleventfilter,boost_headers)) + +$(eval $(call gb_Library_use_sdk_api,vcleventfilter)) + +$(eval $(call gb_Library_use_libraries,vcleventfilter,\ + comphelper \ + ucbhelper \ + cppuhelper \ + cppu \ + sal \ + tl \ + utl \ + svt \ + $(gb_UWINAPI) \ +)) + +$(eval $(call gb_Library_add_exception_objects,vcleventfilter,\ + filter/source/vcleventfilter/vcleventfilter \ +)) + +# vim: set noet sw=4 ts=4: diff --git a/filter/Module_filter.mk b/filter/Module_filter.mk index 4af530cd9130..668bd545bdab 100644 --- a/filter/Module_filter.mk +++ b/filter/Module_filter.mk @@ -55,6 +55,7 @@ $(eval $(call gb_Module_add_targets,filter,\ Library_graphicfilter \ Library_t602filter \ Library_textfd \ + Library_vcleventfilter \ Library_xmlfa \ Library_xmlfd \ Library_xsltdlg \ diff --git a/filter/source/config/fragments/filters/VclEventDocument.xcu b/filter/source/config/fragments/filters/VclEventDocument.xcu new file mode 100644 index 000000000000..d58a11376d49 --- /dev/null +++ b/filter/source/config/fragments/filters/VclEventDocument.xcu @@ -0,0 +1,19 @@ +<!-- + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. +--> + <node oor:name="T602Document" oor:op="replace"> + <prop oor:name="Flags"><value>IMPORT ALIEN 3RDPARTYFILTER PREFERRED</value></prop> + <prop oor:name="UIComponent"/> + <prop oor:name="FilterService"><value>com.sun.star.comp.filters.VclEventFilter</value></prop> + <prop oor:name="UIName"> + <value xml:lang="en-US">VclEvent Document</value> + </prop> + <prop oor:name="FileFormatVersion"><value>0</value></prop> + <prop oor:name="Type"><value>filters_Vcl_Event_Document</value></prop> + <prop oor:name="TemplateName"/> + <prop oor:name="DocumentService"><value>com.sun.star.text.TextDocument</value></prop> + </node> diff --git a/filter/source/config/fragments/types/filters_Vcl_Event_Document.xcu b/filter/source/config/fragments/types/filters_Vcl_Event_Document.xcu new file mode 100644 index 000000000000..683464a0a48c --- /dev/null +++ b/filter/source/config/fragments/types/filters_Vcl_Event_Document.xcu @@ -0,0 +1,18 @@ +<!-- + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. +--> + <node oor:name="filters_Vcl_Event_Document" oor:op="replace" > + <prop oor:name="DetectService"><value>com.sun.star.comp.filters.VclEventFilter</value></prop> + <prop oor:name="URLPattern"/> + <prop oor:name="Extensions"><value>vcl</value></prop> + <prop oor:name="Preferred"><value>true</value></prop> + <prop oor:name="PreferredFilter"><value>VclEventDocument</value></prop> + <prop oor:name="UIName"> + <value>VCL Event Document</value> + </prop> + <prop oor:name="ClipboardFormat"/> + </node> diff --git a/filter/source/vcleventfilter/vcleventfilter.component b/filter/source/vcleventfilter/vcleventfilter.component new file mode 100644 index 000000000000..aa1d9db430f4 --- /dev/null +++ b/filter/source/vcleventfilter/vcleventfilter.component @@ -0,0 +1,15 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + --> +<component loader="com.sun.star.loader.SharedLibrary" environment="@CPPU_ENV@" + prefix="vcleventfilter" xmlns="http://openoffice.org/2010/uno-components"> + <implementation name="com.sun.star.comp.filters.VclEventFilter"> + <service name="com.sun.star.document.ExtendedTypeDetection"/> + <service name="com.sun.star.document.ImportFilter"/> + </implementation> +</component> diff --git a/filter/source/vcleventfilter/vcleventfilter.cxx b/filter/source/vcleventfilter/vcleventfilter.cxx new file mode 100644 index 000000000000..485fa6d6f301 --- /dev/null +++ b/filter/source/vcleventfilter/vcleventfilter.cxx @@ -0,0 +1,137 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + */ + +#include "vcleventfilter.hxx" + +#include <cppuhelper/factory.hxx> +#include <cppuhelper/bootstrap.hxx> +#include <cppuhelper/supportsservice.hxx> +#include <com/sun/star/ucb/XSimpleFileAccess.hpp> + +OUString VclEventFilter_getImplementationName() + throw (css::uno::RuntimeException) +{ + return OUString ( "com.sun.star.comp.filters.VclEventFilter" ); +} + +css::uno::Sequence<OUString> SAL_CALL VclEventFilter_getSupportedServiceNames() + throw (css::uno::RuntimeException) +{ + css::uno::Sequence<OUString> aRet(2); + OUString* pArray = aRet.getArray(); + pArray[0] = "com.sun.star.document.ImportFilter"; + pArray[1] = "com.sun.star.document.ExtendedTypeDetection"; + return aRet; +} + +css::uno::Reference<css::uno::XInterface> SAL_CALL VclEventFilter_createInstance(const css::uno::Reference<css::lang::XMultiServiceFactory> & rSMgr) + throw (css::uno::Exception) +{ + return static_cast<cppu::OWeakObject*>(new VclEventFilter( rSMgr )); +} + +extern "C" +{ + SAL_DLLPUBLIC_EXPORT void * SAL_CALL vcleventfilter_component_getFactory( + const sal_Char * pImplName, void * pServiceManager, void * /* pRegistryKey */ ) + { + void * pRet = 0; + + OUString implName = OUString::createFromAscii( pImplName ); + if ( pServiceManager && implName.equals(VclEventFilter_getImplementationName()) ) + { + css::uno::Reference<css::lang::XSingleServiceFactory> xFactory( + cppu::createSingleFactory( + static_cast<css::lang::XMultiServiceFactory*>(pServiceManager), + OUString::createFromAscii( pImplName ), + VclEventFilter_createInstance, VclEventFilter_getSupportedServiceNames())); + + if (xFactory.is()) + { + xFactory->acquire(); + pRet = xFactory.get(); + } + } + + return pRet; + } +} + +VclEventFilter::VclEventFilter(const css::uno::Reference<css::lang::XMultiServiceFactory> &r) + : mxMSF(r) +{ +} + +VclEventFilter::~VclEventFilter() +{ +} + +// XExtendedTypeDetection +OUString VclEventFilter::detect(css::uno::Sequence<css::beans::PropertyValue>& rDescriptor) + throw (css::uno::RuntimeException, std::exception) +{ + fprintf(stderr, "trying detect\n"); + + sal_Int32 nLength = rDescriptor.getLength(); + const css::beans::PropertyValue *pValue = rDescriptor.getConstArray(); + for (sal_Int32 i = 0 ; i < nLength; ++i) + { + if (pValue[i].Name == "InputStream") + pValue[i].Value >>= mxInputStream; + } + + if (!mxInputStream.is()) + return OUString(); + + css::uno::Sequence< sal_Int8 > aData; + const size_t numBytes = 3; + size_t numBytesRead = mxInputStream->readSomeBytes(aData, numBytes); + + if (numBytesRead != numBytes || aData[0] != 'V' || aData[1] != 'C' || aData[2] != 'L') + return OUString(); + + return OUString("filters_Vcl_Event_Document"); +} + +// XFilter +sal_Bool SAL_CALL VclEventFilter::filter(const css::uno::Sequence<css::beans::PropertyValue>& /*rDescriptor*/) + throw (css::uno::RuntimeException, std::exception) +{ + fprintf(stderr, "ta-da"); + return true; +} + +// XImporter +void SAL_CALL VclEventFilter::setTargetDocument(const css::uno::Reference<css::lang::XComponent>& xDoc) + throw (css::lang::IllegalArgumentException, css::uno::RuntimeException, std::exception) +{ + mxDoc = xDoc; +} + +// XServiceInfo +OUString SAL_CALL VclEventFilter::getImplementationName() + throw (css::uno::RuntimeException, std::exception) +{ + return VclEventFilter_getImplementationName(); +} + +sal_Bool SAL_CALL VclEventFilter::supportsService(const OUString& rServiceName) + throw (css::uno::RuntimeException, std::exception) +{ + return cppu::supportsService( this, rServiceName ); +} + +css::uno::Sequence< OUString > SAL_CALL VclEventFilter::getSupportedServiceNames( ) + throw (css::uno::RuntimeException, std::exception) +{ + return VclEventFilter_getSupportedServiceNames(); +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/filter/source/vcleventfilter/vcleventfilter.hxx b/filter/source/vcleventfilter/vcleventfilter.hxx new file mode 100644 index 000000000000..7d6f2ee3da2e --- /dev/null +++ b/filter/source/vcleventfilter/vcleventfilter.hxx @@ -0,0 +1,66 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + */ + +#ifndef INCLUDED_FILTER_SOURCE_VCLEVENT_VCLEVENTFILTER_HXX +#define INCLUDED_FILTER_SOURCE_VCLEVENT_VCLEVENTFILTER_HXX + +#include <com/sun/star/document/XFilter.hpp> +#include <com/sun/star/document/XImporter.hpp> +#include <com/sun/star/document/XExtendedFilterDetection.hpp> +#include <com/sun/star/io/XInputStream.hpp> +#include <com/sun/star/lang/XMultiServiceFactory.hpp> +#include <com/sun/star/lang/XServiceInfo.hpp> +#include <cppuhelper/implbase.hxx> + +class VclEventFilter : public cppu::WeakImplHelper + < css::document::XFilter, + css::document::XImporter, + css::document::XExtendedFilterDetection, + css::lang::XServiceInfo > +{ +private: + css::uno::Reference< css::lang::XMultiServiceFactory > mxMSF; + css::uno::Reference< css::lang::XComponent > mxDoc; + css::uno::Reference < css::io::XInputStream > mxInputStream; + + bool SAL_CALL importImpl( const css::uno::Sequence< css::beans::PropertyValue >& aDescriptor ) + throw (css::uno::RuntimeException); + + public: + VclEventFilter(const css::uno::Reference<css::lang::XMultiServiceFactory > &r ); + virtual ~VclEventFilter(); + + // XFilter + virtual sal_Bool SAL_CALL filter( const css::uno::Sequence< css::beans::PropertyValue >& aDescriptor ) + throw (css::uno::RuntimeException, std::exception) SAL_OVERRIDE; + virtual void SAL_CALL cancel( ) + throw (css::uno::RuntimeException, std::exception) SAL_OVERRIDE {}; + + // XImporter + virtual void SAL_CALL setTargetDocument( const css::uno::Reference< css::lang::XComponent >& xDoc ) + throw (css::lang::IllegalArgumentException, css::uno::RuntimeException, std::exception) SAL_OVERRIDE; + + // XExtendedTypeDetection + virtual OUString SAL_CALL detect( + css::uno::Sequence< css::beans::PropertyValue >& Descriptor ) + throw( css::uno::RuntimeException, std::exception ) SAL_OVERRIDE; + + // XServiceInfo + virtual OUString SAL_CALL getImplementationName( ) + throw (css::uno::RuntimeException, std::exception) SAL_OVERRIDE; + virtual sal_Bool SAL_CALL supportsService( const OUString& ServiceName ) + throw (css::uno::RuntimeException, std::exception) SAL_OVERRIDE; + virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames( ) + throw (css::uno::RuntimeException, std::exception) SAL_OVERRIDE; +}; + +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |