diff options
-rw-r--r-- | comphelper/inc/comphelper/documentconstants.hxx | 38 | ||||
-rw-r--r-- | comphelper/inc/comphelper/mimeconfighelper.hxx | 15 | ||||
-rw-r--r-- | comphelper/source/misc/mimeconfighelper.cxx | 200 | ||||
-rw-r--r-- | unotools/source/ucbhelper/tempfile.cxx | 2 |
4 files changed, 222 insertions, 33 deletions
diff --git a/comphelper/inc/comphelper/documentconstants.hxx b/comphelper/inc/comphelper/documentconstants.hxx index b78150586e28..73b90d72cc8a 100644 --- a/comphelper/inc/comphelper/documentconstants.hxx +++ b/comphelper/inc/comphelper/documentconstants.hxx @@ -111,3 +111,41 @@ #define ODFVER_012_TEXT ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ODFVER_012_TEXT_ASCII ) ) #endif +// filter flags +// TODO/LATER: The flags should be part of the UNO specification +#define SFX_FILTER_IMPORT 0x00000001L +#define SFX_FILTER_EXPORT 0x00000002L +#define SFX_FILTER_TEMPLATE 0x00000004L +#define SFX_FILTER_INTERNAL 0x00000008L +#define SFX_FILTER_TEMPLATEPATH 0x00000010L +#define SFX_FILTER_OWN 0x00000020L +#define SFX_FILTER_ALIEN 0x00000040L +#define SFX_FILTER_USESOPTIONS 0x00000080L + +#define SFX_FILTER_DEFAULT 0x00000100L +#define SFX_FILTER_EXECUTABLE 0x00000200L +#define SFX_FILTER_SUPPORTSSELECTION 0x00000400L +#define SFX_FILTER_MAPTOAPPPLUG 0x00000800L +#define SFX_FILTER_NOTINFILEDLG 0x00001000L +#define SFX_FILTER_NOTINCHOOSER 0x00002000L +#define SFX_FILTER_ASYNC 0x00004000L +#define SFX_FILTER_CREATOR 0x00008000L +#define SFX_FILTER_OPENREADONLY 0x00010000L +#define SFX_FILTER_MUSTINSTALL 0x00020000L +#define SFX_FILTER_CONSULTSERVICE 0x00040000L + +#define SFX_FILTER_STARONEFILTER 0x00080000L +#define SFX_FILTER_PACKED 0x00100000L +#define SFX_FILTER_SILENTEXPORT 0x00200000L + +#define SFX_FILTER_BROWSERPREFERED 0x00400000L + +#define SFX_FILTER_ENCRYPTION 0x01000000L +#define SFX_FILTER_PASSWORDTOMODIFY 0x02000000L + +#define SFX_FILTER_PREFERED 0x10000000L + +#define SFX_FILTER_VERSION_NONE 0 +#define SFX_FILTER_NOTINSTALLED SFX_FILTER_MUSTINSTALL | SFX_FILTER_CONSULTSERVICE + + diff --git a/comphelper/inc/comphelper/mimeconfighelper.hxx b/comphelper/inc/comphelper/mimeconfighelper.hxx index 5e02d4761cb1..16a0a159d5a4 100644 --- a/comphelper/inc/comphelper/mimeconfighelper.hxx +++ b/comphelper/inc/comphelper/mimeconfighelper.hxx @@ -32,6 +32,7 @@ #include <com/sun/star/uno/Sequence.hxx> #include <com/sun/star/lang/XMultiServiceFactory.hpp> #include <com/sun/star/container/XNameAccess.hpp> +#include <com/sun/star/container/XContainerQuery.hpp> #include <com/sun/star/beans/NamedValue.hpp> #include <com/sun/star/beans/PropertyValue.hpp> #include <com/sun/star/embed/VerbDescriptor.hpp> @@ -50,6 +51,8 @@ class COMPHELPER_DLLPUBLIC MimeConfigurationHelper ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameAccess > m_xVerbsConfig; ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameAccess > m_xMediaTypeConfig; + ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameAccess > m_xFilterFactory; + public: MimeConfigurationHelper( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& xFactory ); @@ -106,6 +109,10 @@ public: ::rtl::OUString GetFactoryNameByMediaType( const ::rtl::OUString& aMediaType ); // typedetection related + ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameAccess > GetFilterFactory(); + + sal_Int32 GetFilterFlags( const ::rtl::OUString& aFilterName ); + ::rtl::OUString UpdateMediaDescriptorWithFilterName( ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& aMediaDescr, sal_Bool bIgnoreType ); @@ -117,6 +124,14 @@ public: ::rtl::OUString GetDefaultFilterFromServiceName( const ::rtl::OUString& aServName, sal_Int32 nVersion ); + ::rtl::OUString GetExportFilterFromImportFilter( const ::rtl::OUString& aImportFilterName ); + + static ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue > SearchForFilter( + const ::com::sun::star::uno::Reference< ::com::sun::star::container::XContainerQuery >& xFilterQuery, + const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::NamedValue >& aSearchRequest, + sal_Int32 nMustFlags, + sal_Int32 nDontFlags ); + static sal_Bool ClassIDsEqual( const ::com::sun::star::uno::Sequence< sal_Int8 >& aClassID1, const ::com::sun::star::uno::Sequence< sal_Int8 >& aClassID2 ); static ::com::sun::star::uno::Sequence< sal_Int8 > GetSequenceClassID( sal_uInt32 n1, sal_uInt16 n2, sal_uInt16 n3, diff --git a/comphelper/source/misc/mimeconfighelper.cxx b/comphelper/source/misc/mimeconfighelper.cxx index b677c977739e..5be9df3d61b6 100644 --- a/comphelper/source/misc/mimeconfighelper.cxx +++ b/comphelper/source/misc/mimeconfighelper.cxx @@ -35,6 +35,7 @@ #include <comphelper/mimeconfighelper.hxx> #include <comphelper/classids.hxx> #include <comphelper/sequenceashashmap.hxx> +#include <comphelper/documentconstants.hxx> using namespace ::com::sun::star; @@ -187,6 +188,46 @@ uno::Reference< container::XNameAccess > MimeConfigurationHelper::GetMediaTypeCo return m_xMediaTypeConfig; } + +//----------------------------------------------------------------------- +uno::Reference< container::XNameAccess > MimeConfigurationHelper::GetFilterFactory() +{ + osl::MutexGuard aGuard( m_aMutex ); + + if ( !m_xFilterFactory.is() ) + m_xFilterFactory.set( + m_xFactory->createInstance( ::rtl::OUString::createFromAscii( "com.sun.star.document.FilterFactory" ) ), + uno::UNO_QUERY ); + + return m_xFilterFactory; +} + +//----------------------------------------------------------------------- +sal_Int32 MimeConfigurationHelper::GetFilterFlags( const ::rtl::OUString& aFilterName ) +{ + sal_Int32 nFlags = 0; + try + { + if ( aFilterName.getLength() ) + { + uno::Reference< container::XNameAccess > xFilterFactory( + GetFilterFactory(), + uno::UNO_SET_THROW ); + + uno::Any aFilterAny = xFilterFactory->getByName( aFilterName ); + uno::Sequence< beans::PropertyValue > aData; + if ( aFilterAny >>= aData ) + { + SequenceAsHashMap aFilterHM( aData ); + nFlags = aFilterHM.getUnpackedValueOrDefault( ::rtl::OUString::createFromAscii( "Flags" ), (sal_Int32)0 ); + } + } + } catch( uno::Exception& ) + {} + + return nFlags; +} + //------------------------------------------------------------------------- ::rtl::OUString MimeConfigurationHelper::GetDocServiceNameFromFilter( const ::rtl::OUString& aFilterName ) { @@ -195,8 +236,8 @@ uno::Reference< container::XNameAccess > MimeConfigurationHelper::GetMediaTypeCo try { uno::Reference< container::XNameAccess > xFilterFactory( - m_xFactory->createInstance( ::rtl::OUString::createFromAscii( "com.sun.star.document.FilterFactory" ) ), - uno::UNO_QUERY_THROW ); + GetFilterFactory(), + uno::UNO_SET_THROW ); uno::Any aFilterAnyData = xFilterFactory->getByName( aFilterName ); uno::Sequence< beans::PropertyValue > aFilterData; @@ -668,36 +709,17 @@ uno::Sequence< beans::NamedValue > MimeConfigurationHelper::GetObjectPropsByDocu sal_Bool MimeConfigurationHelper::AddFilterNameCheckOwnFile( uno::Sequence< beans::PropertyValue >& aMediaDescr ) { + sal_Bool bResult = sal_False; + ::rtl::OUString aFilterName = UpdateMediaDescriptorWithFilterName( aMediaDescr, sal_False ); if ( aFilterName.getLength() ) { - try - { - uno::Reference< container::XNameAccess > xFilterFactory( - m_xFactory->createInstance( ::rtl::OUString::createFromAscii( "com.sun.star.document.FilterFactory" ) ), - uno::UNO_QUERY_THROW ); - - uno::Any aFilterAnyData = xFilterFactory->getByName( aFilterName ); - uno::Sequence< beans::PropertyValue > aFilterData; - if ( aFilterAnyData >>= aFilterData ) - { - for ( sal_Int32 nInd = 0; nInd < aFilterData.getLength(); nInd++ ) - if ( aFilterData[nInd].Name.equalsAscii( "Flags" ) ) - { - uno::Any aVal = aFilterData[nInd].Value; - sal_Int32 nFlags = 0; - // check the OWN flag - if ( ( aFilterData[nInd].Value >>= nFlags ) && ( nFlags & 0x20 ) ) - return sal_True; - break; - } - } - } - catch( uno::Exception& ) - {} + sal_Int32 nFlags = GetFilterFlags( aFilterName ); + // check the OWN flag + bResult = ( nFlags & SFX_FILTER_OWN ); } - return sal_False; + return bResult; } //----------------------------------------------------------- @@ -709,7 +731,7 @@ sal_Bool MimeConfigurationHelper::AddFilterNameCheckOwnFile( try { uno::Reference< container::XContainerQuery > xFilterQuery( - m_xFactory->createInstance( ::rtl::OUString::createFromAscii( "com.sun.star.document.FilterFactory" ) ), + GetFilterFactory(), uno::UNO_QUERY_THROW ); uno::Sequence< beans::NamedValue > aSearchRequest( 2 ); @@ -734,14 +756,15 @@ sal_Bool MimeConfigurationHelper::AddFilterNameCheckOwnFile( (sal_Int32)0 ); // that should be import, export, own filter and not a template filter ( TemplatePath flag ) - if ( ( ( nFlags & 0x23L ) == 0x23L ) && !( nFlags & 0x10 ) ) + sal_Int32 nRequired = ( SFX_FILTER_OWN | SFX_FILTER_EXPORT | SFX_FILTER_IMPORT ); + if ( ( ( nFlags & nRequired ) == nRequired ) && !( nFlags & SFX_FILTER_TEMPLATEPATH ) ) { // if there are more than one filter the preffered one should be used // if there is no preffered filter the first one will be used - if ( !aResult.getLength() || ( nFlags & 0x10000000L ) ) + if ( !aResult.getLength() || ( nFlags & SFX_FILTER_PREFERED ) ) aResult = aPropsHM.getUnpackedValueOrDefault( ::rtl::OUString::createFromAscii( "Name" ), ::rtl::OUString() ); - if ( nFlags & 0x10000000L ) + if ( nFlags & SFX_FILTER_PREFERED ) break; // the preffered filter was found } } @@ -752,6 +775,116 @@ sal_Bool MimeConfigurationHelper::AddFilterNameCheckOwnFile( return aResult; } + +//------------------------------------------------------------------------- +::rtl::OUString MimeConfigurationHelper::GetExportFilterFromImportFilter( const ::rtl::OUString& aImportFilterName ) +{ + ::rtl::OUString aExportFilterName; + + try + { + if ( aImportFilterName.getLength() ) + { + uno::Reference< container::XNameAccess > xFilterFactory( + GetFilterFactory(), + uno::UNO_SET_THROW ); + + uno::Any aImpFilterAny = xFilterFactory->getByName( aImportFilterName ); + uno::Sequence< beans::PropertyValue > aImpData; + if ( aImpFilterAny >>= aImpData ) + { + SequenceAsHashMap aImpFilterHM( aImpData ); + sal_Int32 nFlags = aImpFilterHM.getUnpackedValueOrDefault( ::rtl::OUString::createFromAscii( "Flags" ), + (sal_Int32)0 ); + + if ( !( nFlags & SFX_FILTER_IMPORT ) ) + { + OSL_ENSURE( sal_False, "This is no import filter!" ); + throw uno::Exception(); + } + + if ( nFlags & SFX_FILTER_EXPORT ) + { + aExportFilterName = aImportFilterName; + } + else + { + ::rtl::OUString aDocumentServiceName = aImpFilterHM.getUnpackedValueOrDefault( ::rtl::OUString::createFromAscii( "DocumentService" ), ::rtl::OUString() ); + ::rtl::OUString aTypeName = aImpFilterHM.getUnpackedValueOrDefault( ::rtl::OUString::createFromAscii( "Type" ), ::rtl::OUString() ); + + OSL_ENSURE( aDocumentServiceName.getLength() && aTypeName.getLength(), "Incomplete filter data!" ); + if ( aDocumentServiceName.getLength() && aTypeName.getLength() ) + { + uno::Sequence< beans::NamedValue > aSearchRequest( 2 ); + aSearchRequest[0].Name = ::rtl::OUString::createFromAscii( "Type" ); + aSearchRequest[0].Value <<= aTypeName; + aSearchRequest[1].Name = ::rtl::OUString::createFromAscii( "DocumentService" ); + aSearchRequest[1].Value <<= aDocumentServiceName; + + uno::Sequence< beans::PropertyValue > aExportFilterProps = SearchForFilter( + uno::Reference< container::XContainerQuery >( xFilterFactory, uno::UNO_QUERY_THROW ), + aSearchRequest, + SFX_FILTER_EXPORT, + SFX_FILTER_INTERNAL ); + + if ( aExportFilterProps.getLength() ) + { + SequenceAsHashMap aExpPropsHM( aExportFilterProps ); + aExportFilterName = aExpPropsHM.getUnpackedValueOrDefault( ::rtl::OUString::createFromAscii( "Name" ), ::rtl::OUString() ); + } + } + } + } + } + } + catch( uno::Exception& ) + {} + + return aExportFilterName; +} + +//------------------------------------------------------------------------- +// static +uno::Sequence< beans::PropertyValue > MimeConfigurationHelper::SearchForFilter( + const uno::Reference< container::XContainerQuery >& xFilterQuery, + const uno::Sequence< beans::NamedValue >& aSearchRequest, + sal_Int32 nMustFlags, + sal_Int32 nDontFlags ) +{ + uno::Sequence< beans::PropertyValue > aFilterProps; + uno::Reference< container::XEnumeration > xFilterEnum = + xFilterQuery->createSubSetEnumerationByProperties( aSearchRequest ); + + // the first default filter will be taken, + // if there is no filter with flag default the first acceptable filter will be taken + if ( xFilterEnum.is() ) + { + while ( xFilterEnum->hasMoreElements() ) + { + uno::Sequence< beans::PropertyValue > aProps; + if ( xFilterEnum->nextElement() >>= aProps ) + { + SequenceAsHashMap aPropsHM( aProps ); + sal_Int32 nFlags = aPropsHM.getUnpackedValueOrDefault( ::rtl::OUString::createFromAscii( "Flags" ), + (sal_Int32)0 ); + if ( ( ( nFlags & nMustFlags ) == nMustFlags ) && !( nFlags & nDontFlags ) ) + { + if ( ( nFlags & SFX_FILTER_DEFAULT ) == SFX_FILTER_DEFAULT ) + { + aFilterProps = aProps; + break; + } + else if ( !aFilterProps.getLength() ) + aFilterProps = aProps; + } + } + } + } + + return aFilterProps; +} + + //------------------------------------------------------------------------- sal_Bool MimeConfigurationHelper::ClassIDsEqual( const uno::Sequence< sal_Int8 >& aClassID1, const uno::Sequence< sal_Int8 >& aClassID2 ) { @@ -764,7 +897,8 @@ sal_Bool MimeConfigurationHelper::ClassIDsEqual( const uno::Sequence< sal_Int8 > return sal_True; } -//---------------------------------------------- + +//------------------------------------------------------------------------- uno::Sequence< sal_Int8 > MimeConfigurationHelper::GetSequenceClassID( sal_uInt32 n1, sal_uInt16 n2, sal_uInt16 n3, sal_uInt8 b8, sal_uInt8 b9, sal_uInt8 b10, sal_uInt8 b11, sal_uInt8 b12, sal_uInt8 b13, sal_uInt8 b14, sal_uInt8 b15 ) @@ -789,6 +923,8 @@ uno::Sequence< sal_Int8 > MimeConfigurationHelper::GetSequenceClassID( sal_uInt3 return aResult; } + +//------------------------------------------------------------------------- uno::Sequence<sal_Int8> MimeConfigurationHelper::GetSequenceClassIDFromObjectName(const ::rtl::OUString& _sObjectName) { uno::Sequence<sal_Int8> aClassId; diff --git a/unotools/source/ucbhelper/tempfile.cxx b/unotools/source/ucbhelper/tempfile.cxx index 87fddc0c65cd..26742151ee3d 100644 --- a/unotools/source/ucbhelper/tempfile.cxx +++ b/unotools/source/ucbhelper/tempfile.cxx @@ -237,7 +237,7 @@ void CreateTempName_Impl( String& rName, sal_Bool bKeep, sal_Bool bDir = sal_Tru /* RW permission for the user only! */ mode_t old_mode = umask(077); #endif - FileBase::RC err = aFile.open(osl_File_OpenFlag_Create); + FileBase::RC err = aFile.open( osl_File_OpenFlag_Create | osl_File_OpenFlag_NoLock ); #ifdef UNX umask(old_mode); #endif |