LibreOffice Module filter (master) 1
Public Member Functions | Private Member Functions | Static Private Member Functions | Private Attributes | List of all members
filter::config::TypeDetection Class Reference

implements the service <type scope="com.sun.star.document">TypeDetection</type>. More...

#include <typedetection.hxx>

Inheritance diagram for filter::config::TypeDetection:
[legend]
Collaboration diagram for filter::config::TypeDetection:
[legend]

Public Member Functions

 TypeDetection (const css::uno::Reference< css::uno::XComponentContext > &rxContext)
 standard ctor to connect this interface wrapper to the global filter cache instance ... More...
 
void cancel ()
 
virtual ~TypeDetection () override
 standard dtor. More...
 
virtual OUString SAL_CALL queryTypeByURL (const OUString &sURL) override
 
virtual OUString SAL_CALL queryTypeByDescriptor (css::uno::Sequence< css::beans::PropertyValue > &lDescriptor, sal_Bool bAllowDeep) override
 

Private Member Functions

OUString impl_detectTypeFlatAndDeep (utl::MediaDescriptor &rDescriptor, const FlatDetection &lFlatTypes, bool bAllowDeep, OUString &rLastChance)
 make a combined flat/deep type detection More...
 
OUString impl_askDetectService (const OUString &sDetectService, utl::MediaDescriptor &rDescriptor)
 make deep type detection for a specified detect service (threadsafe!). More...
 
void impl_openStream (utl::MediaDescriptor &rDescriptor)
 check if an input stream is already part of the given MediaDescriptor and creates a new one if necessary. More...
 
void impl_checkResultsAndAddBestFilter (utl::MediaDescriptor &rDescriptor, OUString &sType)
 search the best suitable filter for the given type and add it into the media descriptor. More...
 

Static Private Member Functions

static bool impl_getPreselectionForType (std::unique_lock< std::mutex > &rGuard, const OUString &sPreSelType, const css::util::URL &aParsedURL, FlatDetection &rFlatTypes, bool bDocService)
 
static void impl_getPreselectionForDocumentService (std::unique_lock< std::mutex > &rGuard, const OUString &sPreSelDocumentService, const css::util::URL &aParsedURL, FlatDetection &rFlatTypes)
 
static OUString impl_getTypeFromFilter (std::unique_lock< std::mutex > &rGuard, const OUString &rFilterName)
 
static void impl_getAllFormatTypes (std::unique_lock< std::mutex > &rGuard, const css::util::URL &aParsedURL, utl::MediaDescriptor const &rDescriptor, FlatDetection &rFlatTypes)
 Get all format types that we handle. More...
 
static void impl_seekStreamToZero (utl::MediaDescriptor const &rDescriptor)
 seek a might existing stream to position 0. More...
 
static OUString impl_askUserForTypeAndFilterIfAllowed (utl::MediaDescriptor &rDescriptor)
 try to find an interaction handler and ask him to select a possible filter for this unknown format. More...
 
static bool impl_validateAndSetTypeOnDescriptor (utl::MediaDescriptor &rDescriptor, const OUString &sType)
 validate the specified type and its relationships and set all needed information related to this type in the specified descriptor. More...
 
static bool impl_validateAndSetFilterOnDescriptor (utl::MediaDescriptor &rDescriptor, const OUString &sFilter)
 validate the specified filter and its relationships and set all needed information related to this filter in the specified descriptor. More...
 
static void impl_removeTypeFilterFromDescriptor (utl::MediaDescriptor &rDescriptor)
 remove anything related to a TYPE/FILTER entry from the specified MediaDescriptor. More...
 

Private Attributes

css::uno::Reference< css::uno::XComponentContext > m_xContext
 
rtl::Reference< TerminateDetectionm_xTerminateListener
 
bool m_bCancel
 

Detailed Description

implements the service <type scope="com.sun.star.document">TypeDetection</type>.

Definition at line 35 of file typedetection.hxx.

Constructor & Destructor Documentation

◆ TypeDetection()

filter::config::TypeDetection::TypeDetection ( const css::uno::Reference< css::uno::XComponentContext > &  rxContext)
explicit

standard ctor to connect this interface wrapper to the global filter cache instance ...

Parameters
rxContextreference to the uno service manager, which created this service instance.

Definition at line 53 of file typedetection.cxx.

References filter::config::FilterCache::E_TYPE, filter::config::BaseContainer::init(), m_xContext, and m_xTerminateListener.

◆ ~TypeDetection()

filter::config::TypeDetection::~TypeDetection ( )
overridevirtual

standard dtor.

Definition at line 65 of file typedetection.cxx.

References m_xContext, and m_xTerminateListener.

Member Function Documentation

◆ cancel()

void filter::config::TypeDetection::cancel ( )
inline

Definition at line 58 of file typedetection.hxx.

References m_bCancel.

Referenced by filter::config::TerminateDetection::queryTermination().

◆ impl_askDetectService()

OUString filter::config::TypeDetection::impl_askDetectService ( const OUString &  sDetectService,
utl::MediaDescriptor rDescriptor 
)
private

make deep type detection for a specified detect service (threadsafe!).

@descr It creates the right uno service, prepare the needed MediaDescriptor, call the right interfaces, and return the results.

Attention: \n The results (means type and corresponding filter)
are already part of the in/out parameter pDescriptor. (in case they were valid).
Parameters
sDetectServiceuno service name of the detect service.
rDescriptora stl representation of the MediaDescriptor as in/out parameter.

Definition at line 938 of file typedetection.cxx.

References impl_openStream(), impl_seekStreamToZero(), impl_validateAndSetTypeOnDescriptor(), m_aMutex, and m_xContext.

Referenced by impl_detectTypeFlatAndDeep().

◆ impl_askUserForTypeAndFilterIfAllowed()

OUString filter::config::TypeDetection::impl_askUserForTypeAndFilterIfAllowed ( utl::MediaDescriptor rDescriptor)
staticprivate

try to find an interaction handler and ask him to select a possible filter for this unknown format.

@descr If the user select a filter, it will be used as return value without further checking against the given file content!

Parameters
rDescriptora stl representation of the MediaDescriptor as in/out parameter.
Returns
[string] a valid type name or an empty string if user canceled interaction.

Definition at line 1025 of file typedetection.cxx.

References impl_validateAndSetFilterOnDescriptor(), utl::MediaDescriptor::PROP_INPUTSTREAM, utl::MediaDescriptor::PROP_INTERACTIONHANDLER, utl::MediaDescriptor::PROP_TYPENAME, utl::MediaDescriptor::PROP_URL, sType, and xStream.

Referenced by queryTypeByDescriptor().

◆ impl_checkResultsAndAddBestFilter()

void filter::config::TypeDetection::impl_checkResultsAndAddBestFilter ( utl::MediaDescriptor rDescriptor,
OUString &  sType 
)
private

search the best suitable filter for the given type and add it into the media descriptor.

@descr Normally this is a type detection only ... but for some special features we must overwrite our detection because a file must be loaded into a special (means preselected) application.

E.g. CSV/TXT format are sometimes ugly to handle .-)

Note: If the descriptor already include a filter (may be selected by a FilterSelect interaction or preselected by the user itself) ... we don't change that here !

Parameters
rDescriptorreference to the MediaDescriptor (represented by an easy-to-use stl interface!), which should be patched.
sTypethe internal type name, where we search a filter for. Used as IN/OUT parameter so we can overrule the detection result for types too !
Note
#i60158# sometimes our text ascii and our csv filter can't work together. Then we overwrite our detection hardly. sType param is used as out parameter then too ... and rDescriptor will be changed by selecting another filter. (see code)

Definition at line 466 of file typedetection.cxx.

References comphelper::SequenceAsHashMap::clear(), filter::config::FilterCache::E_CONTAINS_FILTERS, filter::config::FilterCache::E_FILTER, filter::config::FilterCache::E_TYPE, filter::config::GetTheFilterCache(), m_aMutex, utl::MediaDescriptor::PROP_DOCUMENTSERVICE, utl::MediaDescriptor::PROP_FILTERNAME, utl::MediaDescriptor::PROP_TYPENAME, PROPNAME_DOCUMENTSERVICE, PROPNAME_FLAGS, PROPNAME_PREFERREDFILTER, PROPNAME_TYPE, sDocumentService, and sType.

Referenced by queryTypeByDescriptor().

◆ impl_detectTypeFlatAndDeep()

OUString filter::config::TypeDetection::impl_detectTypeFlatAndDeep ( utl::MediaDescriptor rDescriptor,
const FlatDetection lFlatTypes,
bool  bAllowDeep,
OUString &  rLastChance 
)
private

make a combined flat/deep type detection

@descr It steps over all flat detected types (given by the parameter lFlatTypes), try it and search for most suitable one. The specified MediaDescriptor will be patched, so it contain the right values every time. Using of any deep detection service can be enabled/disabled. And last but not least: If the results won't be really clear (because a flat detected type has no deep detection service), a "suggested" type name will be returned as "rLastChance". It can be used after e.g. all well known deep detection services was used without getting any result. Then this "last-chance-type" should be returned. Of course using of it can fail too ... but it's a try :-)

Parameters
rDescriptorprovides any easy-to-use stl interface to the MediaDescriptor. Note : Its content will be adapted to returned result of this method. Means: The type/filter entries of it will be actualized or removed from it.
lFlatTypesa list of all flat detected types, which should be checked here. No other types are allowed here!
rLastChancethe internal name of a "suggested type" ... (see before) Note: it will be reset to an empty string every time. So a set value of "rLastChance" can be detected outside very easy.
bAllowDeepenable/disable using of a might existing deep detection service.
Returns
The internal name of a detected type. An empty value if detection failed. ... but see rLastChance for additional returns!

Definition at line 834 of file typedetection.cxx.

References filter::config::FilterCache::E_TYPE, filter::config::FilterCache::getItem(), filter::config::GetTheFilterCache(), impl_askDetectService(), impl_validateAndSetTypeOnDescriptor(), m_aMutex, m_bCancel, and PROPNAME_DETECTSERVICE.

Referenced by queryTypeByDescriptor().

◆ impl_getAllFormatTypes()

void filter::config::TypeDetection::impl_getAllFormatTypes ( std::unique_lock< std::mutex > &  rGuard,
const css::util::URL &  aParsedURL,
utl::MediaDescriptor const &  rDescriptor,
FlatDetection rFlatTypes 
)
staticprivate

◆ impl_getPreselectionForDocumentService()

void filter::config::TypeDetection::impl_getPreselectionForDocumentService ( std::unique_lock< std::mutex > &  rGuard,
const OUString &  sPreSelDocumentService,
const css::util::URL &  aParsedURL,
FlatDetection rFlatTypes 
)
staticprivate

◆ impl_getPreselectionForType()

bool filter::config::TypeDetection::impl_getPreselectionForType ( std::unique_lock< std::mutex > &  rGuard,
const OUString &  sPreSelType,
const css::util::URL &  aParsedURL,
FlatDetection rFlatTypes,
bool  bDocService 
)
staticprivate

◆ impl_getTypeFromFilter()

OUString filter::config::TypeDetection::impl_getTypeFromFilter ( std::unique_lock< std::mutex > &  rGuard,
const OUString &  rFilterName 
)
staticprivate

◆ impl_openStream()

void filter::config::TypeDetection::impl_openStream ( utl::MediaDescriptor rDescriptor)
private

check if an input stream is already part of the given MediaDescriptor and creates a new one if necessary.

Attention: \n This method does further something special!
  • If the given URL seem to be a streamable content, but creation of the stream failed (might by an IOException), this method throws an exception. (May be an existing interaction handler must be called here too ...) The whole detection must be interrupted then and the interface method queryTypeByDescriptor() must return an empty type name value.

    That prevent us against multiple handling of the same error more than ones (e.g. if we ask all detect services as fallback ...).

  • In case the stream already exists inside the descriptor this method does nothing.
  • In case the stream does not exists but can be created successfully, the stream will be added to the descriptor.
Parameters
rDescriptorprovides any easy-to-use stl interface to the MediaDescriptor. Note : Its content will be adapted to returned result of this method. Means: The stream will be added to it.
Exceptions
Anysuitable exception if stream should be opened but operation was not successful. Note: If an interactionHandler is part of the given descriptor too, it was already used. Means: let the exception pass through the top most interface method!

Definition at line 1084 of file typedetection.cxx.

References utl::MediaDescriptor::addInputStream(), utl::MediaDescriptor::addInputStreamOwnLock(), comphelper::isFileUrl(), utl::MediaDescriptor::PROP_READONLY, and utl::MediaDescriptor::PROP_URL.

Referenced by impl_askDetectService().

◆ impl_removeTypeFilterFromDescriptor()

void filter::config::TypeDetection::impl_removeTypeFilterFromDescriptor ( utl::MediaDescriptor rDescriptor)
staticprivate

remove anything related to a TYPE/FILTER entry from the specified MediaDescriptor.

@descr This method works together with impl_validateAndSetTypeOnDescriptor()/ impl_validateAndSetFilterOnDescriptor(). All information, which can be set by these two operations must be "removable" by this method.

Parameters
rDescriptorreference to the MediaDescriptor (represented by an easy-to-use stl interface!), which should be patched.

Definition at line 1113 of file typedetection.cxx.

References utl::MediaDescriptor::PROP_FILTERNAME, and utl::MediaDescriptor::PROP_TYPENAME.

Referenced by impl_validateAndSetFilterOnDescriptor(), and impl_validateAndSetTypeOnDescriptor().

◆ impl_seekStreamToZero()

void filter::config::TypeDetection::impl_seekStreamToZero ( utl::MediaDescriptor const &  rDescriptor)
staticprivate

seek a might existing stream to position 0.

@descr This is an optional action to be more robust in case any detect service doesn't make this seek... Normally it's part of any called detect service or filter... but sometimes it's not done there.

Parameters
rDescriptora stl representation of the MediaDescriptor as in/out parameter.

Definition at line 914 of file typedetection.cxx.

References utl::MediaDescriptor::PROP_INPUTSTREAM, and xStream.

Referenced by impl_askDetectService().

◆ impl_validateAndSetFilterOnDescriptor()

bool filter::config::TypeDetection::impl_validateAndSetFilterOnDescriptor ( utl::MediaDescriptor rDescriptor,
const OUString &  sFilter 
)
staticprivate

validate the specified filter and its relationships and set all needed information related to this filter in the specified descriptor.

@descr Related information are: - corresponding type

  • ...
Parameters
rDescriptorprovides access to the outside MediaDescriptor.
sFilterthe name of the filter, which should be set on the descriptor. Can be empty to remove any related value from the descriptor!
Returns
TRUE the specified type and its registrations was valid(!) and could be set on the descriptor.

Definition at line 1139 of file typedetection.cxx.

References filter::config::FilterCache::E_FILTER, filter::config::GetTheFilterCache(), impl_removeTypeFilterFromDescriptor(), utl::MediaDescriptor::PROP_FILTERNAME, utl::MediaDescriptor::PROP_TYPENAME, PROPNAME_TYPE, and sType.

Referenced by impl_askUserForTypeAndFilterIfAllowed(), and queryTypeByDescriptor().

◆ impl_validateAndSetTypeOnDescriptor()

bool filter::config::TypeDetection::impl_validateAndSetTypeOnDescriptor ( utl::MediaDescriptor rDescriptor,
const OUString &  sType 
)
staticprivate

validate the specified type and its relationships and set all needed information related to this type in the specified descriptor.

@descr Related information are: - corresponding filter

  • media type
  • ...
Parameters
rDescriptorprovides access to the outside MediaDescriptor.
sTypethe name of the type, which should be set on the descriptor. Can be empty to remove any related value from the descriptor!
Returns
TRUE the specified type and its registrations was valid(!) and could be set on the descriptor.

Definition at line 1124 of file typedetection.cxx.

References filter::config::FilterCache::E_TYPE, filter::config::GetTheFilterCache(), impl_removeTypeFilterFromDescriptor(), utl::MediaDescriptor::PROP_TYPENAME, and sType.

Referenced by impl_askDetectService(), impl_detectTypeFlatAndDeep(), and queryTypeByDescriptor().

◆ queryTypeByDescriptor()

OUString SAL_CALL filter::config::TypeDetection::queryTypeByDescriptor ( css::uno::Sequence< css::beans::PropertyValue > &  lDescriptor,
sal_Bool  bAllowDeep 
)
overridevirtual

◆ queryTypeByURL()

OUString SAL_CALL filter::config::TypeDetection::queryTypeByURL ( const OUString &  sURL)
overridevirtual

Member Data Documentation

◆ m_bCancel

bool filter::config::TypeDetection::m_bCancel
private

Definition at line 43 of file typedetection.hxx.

Referenced by cancel(), impl_detectTypeFlatAndDeep(), and queryTypeByDescriptor().

◆ m_xContext

css::uno::Reference< css::uno::XComponentContext > filter::config::TypeDetection::m_xContext
private

◆ m_xTerminateListener

rtl::Reference<TerminateDetection> filter::config::TypeDetection::m_xTerminateListener
private

Definition at line 42 of file typedetection.hxx.

Referenced by TypeDetection(), and ~TypeDetection().


The documentation for this class was generated from the following files: