LibreOffice Module filter (master) 1
|
implements the service <type scope="com.sun.star.document">TypeDetection</type>. More...
#include <typedetection.hxx>
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< TerminateDetection > | m_xTerminateListener |
bool | m_bCancel |
implements the service <type scope="com.sun.star.document">TypeDetection</type>.
Definition at line 35 of file typedetection.hxx.
|
explicit |
standard ctor to connect this interface wrapper to the global filter cache instance ...
rxContext | reference 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.
|
overridevirtual |
standard dtor.
Definition at line 65 of file typedetection.cxx.
References m_xContext, and m_xTerminateListener.
|
inline |
Definition at line 58 of file typedetection.hxx.
References m_bCancel.
Referenced by filter::config::TerminateDetection::queryTermination().
|
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.
sDetectService | uno service name of the detect service. |
rDescriptor | a 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().
|
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!
rDescriptor | a stl representation of the MediaDescriptor as in/out parameter. |
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().
|
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 !
rDescriptor | reference to the MediaDescriptor (represented by an easy-to-use stl interface!), which should be patched. |
sType | the internal type name, where we search a filter for. Used as IN/OUT parameter so we can overrule the detection result for types too ! |
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().
|
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 :-)
rDescriptor | provides 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. |
lFlatTypes | a list of all flat detected types, which should be checked here. No other types are allowed here! |
rLastChance | the 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. |
bAllowDeep | enable/disable using of a might existing deep detection service. |
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().
|
staticprivate |
Get all format types that we handle.
Definition at line 760 of file typedetection.cxx.
References filter::config::FlatDetectionInfo::bMatchByExtension, filter::config::FlatDetectionInfo::bMatchByPattern, filter::config::FlatDetectionInfo::bPreselectedByDocumentService, filter::config::FilterCache::detectFlatForURL(), filter::config::FilterCache::E_CONTAINS_FILTERS, filter::config::FilterCache::E_FILTER, filter::config::GetTheFilterCache(), impl_getPreselectionForDocumentService(), impl_getPreselectionForType(), impl_getTypeFromFilter(), last, utl::MediaDescriptor::PROP_DOCUMENTSERVICE, utl::MediaDescriptor::PROP_TYPENAME, and filter::config::FlatDetectionInfo::sType.
Referenced by queryTypeByDescriptor().
|
staticprivate |
Definition at line 705 of file typedetection.cxx.
References filter::config::FilterCache::E_CONTAINS_FILTERS, filter::config::FilterCache::E_FILTER, filter::config::GetTheFilterCache(), impl_getPreselectionForType(), impl_getTypeFromFilter(), and PROPNAME_DOCUMENTSERVICE.
Referenced by impl_getAllFormatTypes().
|
staticprivate |
Definition at line 606 of file typedetection.cxx.
References filter::config::FilterCache::E_TYPE, INetURLObject::getExtension(), filter::config::FilterCache::getItem(), filter::config::GetTheFilterCache(), INetURLObject::LAST_SEGMENT, WildCard::Matches(), PROPNAME_EXTENSIONS, PROPNAME_URLPATTERN, sType, and INetURLObject::WithCharset.
Referenced by impl_getAllFormatTypes(), and impl_getPreselectionForDocumentService().
|
staticprivate |
Definition at line 743 of file typedetection.cxx.
References filter::config::FilterCache::E_FILTER, filter::config::FilterCache::getItem(), filter::config::GetTheFilterCache(), and PROPNAME_TYPE.
Referenced by impl_getAllFormatTypes(), and impl_getPreselectionForDocumentService().
|
private |
check if an input stream is already part of the given MediaDescriptor and creates a new one if necessary.
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 ...).
rDescriptor | provides 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. |
Any | suitable 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().
|
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.
rDescriptor | reference 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().
|
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.
rDescriptor | a 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().
|
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
rDescriptor | provides access to the outside MediaDescriptor. |
sFilter | the name of the filter, which should be set on the descriptor. Can be empty to remove any related value from 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().
|
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
rDescriptor | provides access to the outside MediaDescriptor. |
sType | the name of the type, which should be set on the descriptor. Can be empty to remove any related value from 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().
|
overridevirtual |
Definition at line 372 of file typedetection.cxx.
References aURL, impl_askUserForTypeAndFilterIfAllowed(), impl_checkResultsAndAddBestFilter(), impl_detectTypeFlatAndDeep(), impl_getAllFormatTypes(), impl_validateAndSetFilterOnDescriptor(), impl_validateAndSetTypeOnDescriptor(), last, m_aMutex, m_bCancel, m_xContext, utl::MediaDescriptor::PROP_FILTERNAME, utl::MediaDescriptor::PROP_TYPENAME, utl::MediaDescriptor::PROP_URL, sType, and TOOLS_WARN_EXCEPTION.
|
overridevirtual |
Definition at line 71 of file typedetection.cxx.
References aURL, filter::config::FilterCache::E_CONTAINS_TYPES, filter::config::GetTheFilterCache(), m_aMutex, m_xContext, sType, and filter::config::FlatDetectionInfo::sType.
|
private |
Definition at line 43 of file typedetection.hxx.
Referenced by cancel(), impl_detectTypeFlatAndDeep(), and queryTypeByDescriptor().
|
private |
Definition at line 41 of file typedetection.hxx.
Referenced by impl_askDetectService(), queryTypeByDescriptor(), queryTypeByURL(), TypeDetection(), and ~TypeDetection().
|
private |
Definition at line 42 of file typedetection.hxx.
Referenced by TypeDetection(), and ~TypeDetection().