Kaydet (Commit) 3d96b1e0 authored tarafından Caolán McNamara's avatar Caolán McNamara

coverity#737139 Uncaught exception

Change-Id: I75fc43e365afa44b54c27aeb8887f9e37954f03b
üst 5adc8214
...@@ -305,65 +305,71 @@ static OUString getMimetypeForDocument( const Reference< XComponentContext >& xC ...@@ -305,65 +305,71 @@ static OUString getMimetypeForDocument( const Reference< XComponentContext >& xC
const Reference< XComponent >& xDoc ) throw() const Reference< XComponent >& xDoc ) throw()
{ {
OUString aDocMimetype; OUString aDocMimetype;
// get document service name try
Reference< com::sun::star::frame::XStorable > xStore( xDoc, UNO_QUERY );
Reference< frame::XModuleManager2 > xModuleManager = frame::ModuleManager::create(xContext);
if( xStore.is() )
{ {
OUString aDocServiceName = xModuleManager->identify( Reference< XInterface >( xStore, uno::UNO_QUERY ) ); // get document service name
if ( !aDocServiceName.isEmpty() ) Reference< com::sun::star::frame::XStorable > xStore( xDoc, UNO_QUERY );
Reference< frame::XModuleManager2 > xModuleManager = frame::ModuleManager::create(xContext);
if( xStore.is() )
{ {
// get the actual filter name OUString aDocServiceName = xModuleManager->identify( Reference< XInterface >( xStore, uno::UNO_QUERY ) );
OUString aFilterName; if ( !aDocServiceName.isEmpty() )
Reference< lang::XMultiServiceFactory > xConfigProvider =
configuration::theDefaultProvider::get( xContext );
uno::Sequence< uno::Any > aArgs( 1 );
beans::NamedValue aPathProp;
aPathProp.Name = "nodepath";
aPathProp.Value <<= OUString( "/org.openoffice.Setup/Office/Factories/" );
aArgs[0] <<= aPathProp;
Reference< container::XNameAccess > xSOFConfig(
xConfigProvider->createInstanceWithArguments(
"com.sun.star.configuration.ConfigurationAccess", aArgs ),
uno::UNO_QUERY );
Reference< container::XNameAccess > xApplConfig;
xSOFConfig->getByName( aDocServiceName ) >>= xApplConfig;
if ( xApplConfig.is() )
{ {
xApplConfig->getByName( "ooSetupFactoryActualFilter" ) >>= aFilterName; // get the actual filter name
if( !aFilterName.isEmpty() ) OUString aFilterName;
Reference< lang::XMultiServiceFactory > xConfigProvider =
configuration::theDefaultProvider::get( xContext );
uno::Sequence< uno::Any > aArgs( 1 );
beans::NamedValue aPathProp;
aPathProp.Name = "nodepath";
aPathProp.Value <<= OUString( "/org.openoffice.Setup/Office/Factories/" );
aArgs[0] <<= aPathProp;
Reference< container::XNameAccess > xSOFConfig(
xConfigProvider->createInstanceWithArguments(
"com.sun.star.configuration.ConfigurationAccess", aArgs ),
uno::UNO_QUERY );
Reference< container::XNameAccess > xApplConfig;
xSOFConfig->getByName( aDocServiceName ) >>= xApplConfig;
if ( xApplConfig.is() )
{ {
// find the related type name xApplConfig->getByName( "ooSetupFactoryActualFilter" ) >>= aFilterName;
OUString aTypeName; if( !aFilterName.isEmpty() )
Reference< container::XNameAccess > xFilterFactory(
xContext->getServiceManager()->createInstanceWithContext("com.sun.star.document.FilterFactory", xContext),
uno::UNO_QUERY );
Sequence< beans::PropertyValue > aFilterData;
xFilterFactory->getByName( aFilterName ) >>= aFilterData;
for ( sal_Int32 nInd = 0; nInd < aFilterData.getLength(); nInd++ )
if ( aFilterData[nInd].Name == "Type" )
aFilterData[nInd].Value >>= aTypeName;
if ( !aTypeName.isEmpty() )
{ {
// find the mediatype // find the related type name
Reference< container::XNameAccess > xTypeDetection( OUString aTypeName;
xContext->getServiceManager()->createInstanceWithContext("com.sun.star.document.TypeDetection", xContext), Reference< container::XNameAccess > xFilterFactory(
UNO_QUERY ); xContext->getServiceManager()->createInstanceWithContext("com.sun.star.document.FilterFactory", xContext),
uno::UNO_QUERY );
Sequence< beans::PropertyValue > aTypeData;
xTypeDetection->getByName( aTypeName ) >>= aTypeData; Sequence< beans::PropertyValue > aFilterData;
for ( sal_Int32 nInd = 0; nInd < aTypeData.getLength(); nInd++ ) xFilterFactory->getByName( aFilterName ) >>= aFilterData;
if ( aTypeData[nInd].Name == "MediaType" ) for ( sal_Int32 nInd = 0; nInd < aFilterData.getLength(); nInd++ )
aTypeData[nInd].Value >>= aDocMimetype; if ( aFilterData[nInd].Name == "Type" )
aFilterData[nInd].Value >>= aTypeName;
if ( !aTypeName.isEmpty() )
{
// find the mediatype
Reference< container::XNameAccess > xTypeDetection(
xContext->getServiceManager()->createInstanceWithContext("com.sun.star.document.TypeDetection", xContext),
UNO_QUERY );
Sequence< beans::PropertyValue > aTypeData;
xTypeDetection->getByName( aTypeName ) >>= aTypeData;
for ( sal_Int32 nInd = 0; nInd < aTypeData.getLength(); nInd++ )
if ( aTypeData[nInd].Name == "MediaType" )
aTypeData[nInd].Value >>= aDocMimetype;
}
} }
} }
} }
} }
} }
catch (...)
{
}
return aDocMimetype; return aDocMimetype;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment