21#include <com/sun/star/uno/Exception.hpp>
22#include <com/sun/star/beans/PropertyValue.hpp>
23#include <com/sun/star/beans/NamedValue.hpp>
24#include <com/sun/star/container/XNameAccess.hpp>
25#include <com/sun/star/container/XEnumeration.hpp>
26#include <com/sun/star/document/XTypeDetection.hpp>
27#include <com/sun/star/container/XContainerQuery.hpp>
28#include <com/sun/star/io/XInputStream.hpp>
29#include <com/sun/star/task/XInteractionHandler.hpp>
30#include <com/sun/star/lang/XMultiServiceFactory.hpp>
38#include <rtl/ustring.hxx>
39#include <rtl/ustrbuf.hxx>
46#include <com/sun/star/uno/Reference.hxx>
58#include <sfx2/strings.hrc>
61#include <sfx2/sfxsids.hrc>
167 !pFilter->GetServiceName().equalsIgnoreAsciiCase(
sServiceName)
180 for (
const std::shared_ptr<const SfxFilter>& pCheckFilter : *
pFilterArr)
182 if ( pCheckFilter->GetServiceName().equalsIgnoreAsciiCase(
sServiceName) )
184 pFilter = pCheckFilter;
220 std::vector<std::unique_ptr<SfxFilterMatcher_Impl> > aImplArr;
221 int nSfxFilterMatcherCount;
227 if (!rName.isEmpty())
232 for (std::unique_ptr<SfxFilterMatcher_Impl>& aImpl : aImplArr)
233 if (aImpl->aName == aName)
237 aImplArr.push_back(std::make_unique<SfxFilterMatcher_Impl>(aName));
238 return *aImplArr.back();
243 : m_rImpl( getSfxFilterMatcher_Impl(rName) )
245 ++nSfxFilterMatcherCount;
249 : m_rImpl( getSfxFilterMatcher_Impl(OUString()) )
253 ++nSfxFilterMatcherCount;
258 --nSfxFilterMatcherCount;
259 if (nSfxFilterMatcherCount == 0)
269 for (
const std::shared_ptr<const SfxFilter>& pFilter : *
pFilterArr)
271 if ( pFilter->GetServiceName() ==
aName )
272 pList->push_back( pFilter );
286 if ( !
aName.isEmpty() )
302 for (
const std::shared_ptr<const SfxFilter>& pFilter : *
m_rImpl.
pList)
305 if ( (nFlags & nMust) == nMust && !(nFlags & nDont ) )
315 std::shared_ptr<const SfxFilter>& rpFilter )
const
317 uno::Reference<document::XTypeDetection> xDetection(
325 catch (uno::Exception&)
330 if ( !sTypeName.isEmpty() )
349 std::shared_ptr<const SfxFilter> pOldFilter = rpFilter;
352 uno::Reference<document::XTypeDetection> xDetection(
355 if (!xDetection.is())
364 uno::Reference< io::XInputStream > xInStream = rMedium.
GetInputStream();
365 OUString aFilterName;
391 uno::Sequence< beans::PropertyValue > lDescriptor = aDescriptor.getAsConstPropertyValueList();
392 sTypeName = xDetection->queryTypeByDescriptor(lDescriptor,
true);
394 for (
const auto& rProp : std::as_const(lDescriptor))
396 if (rProp.Name ==
"FilterName")
398 aFilterName = rProp.Value.get<OUString>();
403 sTypeName = xDetection->queryTypeByURL(sURL);
405 if (!sTypeName.isEmpty())
407 std::shared_ptr<const SfxFilter> pNewFilter;
408 if (!aFilterName.isEmpty())
421 uno::Sequence< beans::NamedValue > lQuery { {
"Name", css::uno::Any(sTypeName) } };
428 rpFilter = pNewFilter;
433 catch (
const uno::Exception&)
442 if ( pFilter->GetFilterFlags() & SfxFilterFlags::MUSTINSTALL )
445 OUString aText(
SfxResId(STR_FILTER_NOT_INSTALLED) );
446 aText = aText.replaceFirst(
"$(FILTER)", pFilter->GetUIName() );
448 VclMessageType::Question, VclButtonsType::YesNo,
450 xQueryBox->set_default_response(
RET_YES);
452 short nRet = xQueryBox->run();
458 VclMessageType::Info, VclButtonsType::Ok,
459 "Here should the Setup now be starting!"));
466 return ( !(pFilter->GetFilterFlags() & SfxFilterFlags::MUSTINSTALL) );
468 else if ( pFilter->GetFilterFlags() & SfxFilterFlags::CONSULTSERVICE )
470 OUString aText(
SfxResId(STR_FILTER_CONSULT_SERVICE) );
471 aText = aText.replaceFirst(
"$(FILTER)", pFilter->GetUIName() );
473 VclMessageType::Info, VclButtonsType::Ok,
490 std::shared_ptr<const SfxFilter> pOldFilter = rMedium.GetFilter();
493 if( !IsFilterInstalled_Impl( pOldFilter ) )
494 pOldFilter =
nullptr;
497 const SfxStringItem* pSalvageItem = rMedium.GetItemSet().GetItem(SID_DOC_SALVAGE,
false);
498 if ( ( pOldFilter->GetFilterFlags() & SfxFilterFlags::PACKED ) && pSalvageItem )
500 pOldFilter =
nullptr;
504 std::shared_ptr<const SfxFilter> pFilter = pOldFilter;
506 bool bPreview = rMedium.IsPreview_Impl();
507 const SfxStringItem* pReferer = rMedium.GetItemSet().GetItem(SID_REFERER,
false);
508 if ( bPreview && rMedium.IsRemote() && ( !pReferer || !pReferer->
GetValue().match(
"private:searchfolder:") ) )
511 ErrCode nErr = GuessFilter( rMedium, pFilter );
523 std::shared_ptr<const SfxFilter> pInstallFilter;
526 GuessFilter( rMedium, pInstallFilter, SfxFilterFlags::IMPORT, SfxFilterFlags::CONSULTSERVICE );
527 if ( pInstallFilter )
529 if ( IsFilterInstalled_Impl( pInstallFilter ) )
531 pFilter = pInstallFilter;
537 GuessFilter( rMedium, pInstallFilter, SfxFilterFlags::IMPORT, SfxFilterFlags::NONE );
538 if ( pInstallFilter )
539 IsFilterInstalled_Impl( pInstallFilter );
543 bool bHidden = bPreview;
544 const SfxStringItem* pFlags = rMedium.GetItemSet().GetItem(SID_OPTIONS,
false);
545 if ( !bHidden && pFlags )
547 OUString aFlags( pFlags->
GetValue() );
548 aFlags = aFlags.toAsciiUpperCase();
549 if( -1 != aFlags.indexOf(
'H' ) )
561 uno::Reference< lang::XMultiServiceFactory > xServiceManager = ::comphelper::getProcessServiceFactory();
562 if( !xServiceManager )
565 static constexpr OUStringLiteral sTypeDetection =
u"com.sun.star.document.TypeDetection";
566 uno::Reference< container::XContainerQuery > xTypeCFG( xServiceManager->createInstance( sTypeDetection ), uno::UNO_QUERY );
571 uno::Reference < css::container::XEnumeration > xEnum = xTypeCFG->createSubSetEnumerationByProperties(
aSeq );
572 uno::Sequence<beans::PropertyValue> aProps;
573 while ( xEnum->hasMoreElements() )
575 static constexpr OUStringLiteral sPreferredFilter =
u"PreferredFilter";
576 static constexpr OUStringLiteral
sName =
u"Name";
578 xEnum->nextElement() >>= aProps;
579 OUString aValue,
aName;
580 for(
const auto & rPropVal : aProps)
582 if (rPropVal.Name == sPreferredFilter)
583 rPropVal.Value >>= aValue;
584 else if (rPropVal.Name ==
sName)
585 rPropVal.Value >>=
aName;
589 if ( !aValue.isEmpty() )
592 if ( !pFilter || (pFilter->GetFilterFlags() & nMust) != nMust || (pFilter->GetFilterFlags() & nDont ) )
623 for (
const std::shared_ptr<const SfxFilter>& pFilter : *
m_rImpl.
pList)
626 if ( (nFlags & nMust) == nMust && !(nFlags & nDont ) && pFilter->GetMimeType() == rMediaType )
633 css::uno::Sequence < css::beans::NamedValue >
aSeq { {
"MediaType", css::uno::Any(rMediaType) } };
641 std::shared_ptr<const SfxFilter> pFirst;
642 for (
const std::shared_ptr<const SfxFilter>& pFilter : *
m_rImpl.
pList)
645 if ( (nFlags & nMust) == nMust && !(nFlags & nDont ) && pFilter->GetTypeName() == rType )
647 if (nFlags & SfxFilterFlags::PREFERED)
659 css::uno::Sequence < css::beans::NamedValue >
aSeq { {
"Name", css::uno::Any(rType) } };
667 if (OUString sExt =
ToUpper_Impl(rExt); !sExt.isEmpty())
672 for (
const std::shared_ptr<const SfxFilter>& pFilter : *
m_rImpl.
pList)
675 if ((nFlags & nMust) == nMust && !(nFlags & nDont))
677 OUString sWildCard =
ToUpper_Impl(pFilter->GetWildcard().getGlob());
690 OUString sExt( rExt );
691 if ( sExt.startsWith(
".") )
694 css::uno::Sequence < css::beans::NamedValue >
aSeq
695 { {
"Extensions", css::uno::Any(uno::Sequence < OUString > { sExt } ) } };
701 if (
nId == SotClipboardFormatId::NONE)
704 css::uno::Sequence < css::beans::NamedValue >
aSeq
712 std::shared_ptr<const SfxFilter> pFirstFilter;
713 for (
const std::shared_ptr<const SfxFilter>& pFilter : *
m_rImpl.
pList)
716 if ( (nFlags & nMust) == nMust &&
717 !(nFlags & nDont ) && pFilter->GetUIName() == rName )
719 if ( pFilter->GetFilterFlags() & SfxFilterFlags::PREFERED )
721 else if ( !pFirstFilter )
722 pFirstFilter = pFilter;
730 std::u16string_view
aName( rName );
731 sal_Int32
nIndex = rName.indexOf(
": ");
734 SAL_WARN(
"sfx.bastyp",
"Old filter name used!");
740 uno::Reference< lang::XMultiServiceFactory > xServiceManager = ::comphelper::getProcessServiceFactory();
741 uno::Reference< container::XNameAccess > xFilterCFG ;
742 uno::Reference< container::XNameAccess > xTypeCFG ;
743 if( xServiceManager.is() )
745 static constexpr OUStringLiteral sFilterFactory =
u"com.sun.star.document.FilterFactory";
746 static constexpr OUStringLiteral sTypeDetection =
u"com.sun.star.document.TypeDetection";
747 xFilterCFG.set( xServiceManager->createInstance( sFilterFactory ), uno::UNO_QUERY );
748 xTypeCFG.set( xServiceManager->createInstance( sTypeDetection ), uno::UNO_QUERY );
751 if( xFilterCFG.is() && xTypeCFG.is() )
757 for (
const std::shared_ptr<const SfxFilter>& pFilter : *
pFilterArr)
760 if ((nFlags & nMust) == nMust && !(nFlags & nDont) && pFilter->GetFilterName().equalsIgnoreAsciiCase(
aName))
773 for (
const std::shared_ptr<const SfxFilter>& pFilter : *pList)
776 if ( (nFlags & nMust) == nMust && !(nFlags & nDont ) && pFilter->GetFilterName().equalsIgnoreAsciiCase(
aName))
785 std::shared_ptr<const SfxFilter> pFilter = GetFilter4Extension( *pString );
787 !pFilter->GetWildcard().Matches(
u"") &&
788 !pFilter->GetWildcard().Matches(
u"*.*") &&
789 !pFilter->GetWildcard().Matches(
u"*");
796 : nOrMask( nOrMaskP ), nAndMask( nAndMaskP ),
797 nCurrent(0), m_rMatch(rMatcher.m_rImpl)
800 nOrMask = SfxFilterFlags::NONE;
807 std::shared_ptr<const SfxFilter> pFilter;
808 while( nCurrent < m_rMatch.pList->
size() )
840 OUStringBuffer sString ( 1000 ) ;
841 sal_Int32
nCount = lList.getLength();
842 sal_Int32 nItem = 0 ;
843 for( nItem=0; nItem<
nCount; ++nItem )
849 sString.append( lList[nItem] );
852 sString.append( cSeparator );
855 return sString.makeStringAndClear();
860 const OUString& rName,
861 const uno::Reference< container::XNameAccess >& xTypeCFG,
862 const uno::Reference< container::XNameAccess >& xFilterCFG,
866 OUString sFilterName( rName );
868 uno::Sequence< beans::PropertyValue > lFilterProperties;
872 aResult = xFilterCFG->getByName( sFilterName );
874 catch( container::NoSuchElementException& )
879 if( !(aResult >>= lFilterProperties) )
886 sal_Int32 nFormatVersion = 0 ;
890 OUString sHumanName ;
891 OUString sDefaultTemplate ;
893 OUString sExtension ;
895 bool bEnabled = true ;
898 for(
const auto& rFilterProperty : std::as_const(lFilterProperties) )
900 if ( rFilterProperty.Name ==
"FileFormatVersion" )
902 rFilterProperty.Value >>= nFormatVersion;
904 else if ( rFilterProperty.Name ==
"TemplateName" )
906 rFilterProperty.Value >>= sDefaultTemplate;
908 else if ( rFilterProperty.Name ==
"Flags" )
911 rFilterProperty.Value >>= nTmp;
915 else if ( rFilterProperty.Name ==
"UIName" )
917 rFilterProperty.Value >>= sUIName;
919 else if ( rFilterProperty.Name ==
"UserData" )
921 uno::Sequence< OUString > lUserData;
922 rFilterProperty.Value >>= lUserData;
925 else if ( rFilterProperty.Name ==
"DocumentService" )
929 else if (rFilterProperty.Name ==
"ExportExtension")
933 rFilterProperty.Value >>= sExtension;
934 sExtension =
"*." + sExtension;
936 else if ( rFilterProperty.Name ==
"Type" )
938 rFilterProperty.Value >>=
sType;
943 aResult = xTypeCFG->getByName(
sType );
945 catch (
const container::NoSuchElementException&)
950 uno::Sequence< beans::PropertyValue > lTypeProperties;
951 if( aResult >>= lTypeProperties )
954 for(
const auto& rTypeProperty : std::as_const(lTypeProperties) )
956 if ( rTypeProperty.Name ==
"ClipboardFormat" )
958 rTypeProperty.Value >>= sHumanName;
960 else if ( rTypeProperty.Name ==
"MediaType" )
962 rTypeProperty.Value >>= sMimeType;
964 else if ( rTypeProperty.Name ==
"Extensions" )
966 if (sExtension.isEmpty())
968 uno::Sequence< OUString > lExtensions;
969 rTypeProperty.Value >>= lExtensions;
976 else if ( rFilterProperty.Name ==
"Enabled" )
978 rFilterProperty.Value >>= bEnabled;
987 if( !sHumanName.isEmpty() )
992 if(nFlags & SfxFilterFlags::STARONEFILTER)
994 nClipboardId = SotClipboardFormatId::NONE;
1000 sal_Int32 nStartRealName = sFilterName.indexOf(
": " );
1001 if( nStartRealName != -1 )
1003 SAL_WARN(
"sfx.bastyp",
"Old format, not supported!");
1004 sFilterName = sFilterName.copy( nStartRealName+2 );
1010 pFilter = std::make_shared<SfxFilter>( sFilterName ,
1019 rList.push_back( pFilter );
1027 pFilt->
lFormat = nClipboardId;
1041 if( nFormatVersion )
1058 uno::Reference< lang::XMultiServiceFactory > xServiceManager = ::comphelper::getProcessServiceFactory();
1059 uno::Reference< container::XNameAccess > xFilterCFG ;
1060 uno::Reference< container::XNameAccess > xTypeCFG ;
1061 if( xServiceManager.is() )
1063 xFilterCFG.set( xServiceManager->createInstance(
"com.sun.star.document.FilterFactory" ), uno::UNO_QUERY );
1064 xTypeCFG.set( xServiceManager->createInstance(
"com.sun.star.document.TypeDetection" ), uno::UNO_QUERY );
1067 if( xFilterCFG.is() && xTypeCFG.is() )
1070 const uno::Sequence< OUString > lFilterNames = xFilterCFG->getElementNames();
1071 if ( lFilterNames.hasElements() )
1077 if( !rList.empty() )
1080 for (
const std::shared_ptr<const SfxFilter>& pFilter : rList)
1088 for(
const OUString& sFilterName : lFilterNames )
1097 catch(
const uno::Exception&)
1099 SAL_WARN(
"sfx.bastyp",
"SfxFilterContainer::ReadFilter()\nException detected. Possible not all filters could be cached." );
1106 for (
const auto& aImpl : aImplArr)
HRESULT createInstance(REFIID iid, Ifc **ppIfc)
constexpr OUStringLiteral sServiceName
::std::vector< std::shared_ptr< const SfxFilter > > SfxFilterList_Impl
static weld::MessageDialog * CreateMessageDialog(weld::Widget *pParent, VclMessageType eMessageType, VclButtonsType eButtonType, const OUString &rPrimaryMessage, const ILibreOfficeKitNotifier *pNotifier=nullptr)
OUString uppercase(const OUString &rStr, sal_Int32 nPos, sal_Int32 nCount) const
const OUString & GetValue() const
OUString GetMainURL(DecodeMechanism eMechanism, rtl_TextEncoding eCharset=RTL_TEXTENCODING_UTF8) const
SfxFilterContainer_Impl(OUString _aName)
static SAL_DLLPRIVATE void ReadSingleFilter_Impl(const OUString &rName, const css::uno::Reference< css::container::XNameAccess > &xTypeCFG, const css::uno::Reference< css::container::XNameAccess > &xFilterCFG, bool bUpdate)
std::shared_ptr< const SfxFilter > GetFilter4FilterName(const OUString &rName, SfxFilterFlags nMust=SfxFilterFlags::NONE, SfxFilterFlags nDont=SFX_FILTER_NOTINSTALLED) const
OUString const & GetName() const
static SAL_DLLPRIVATE std::shared_ptr< const SfxFilter > GetDefaultFilter_Impl(std::u16string_view)
std::shared_ptr< const SfxFilter > GetFilter4EA(const OUString &rEA, SfxFilterFlags nMust=SfxFilterFlags::IMPORT, SfxFilterFlags nDont=SFX_FILTER_NOTINSTALLED) const
std::shared_ptr< const SfxFilter > GetFilter4Extension(const OUString &rExt, SfxFilterFlags nMust=SfxFilterFlags::IMPORT, SfxFilterFlags nDont=SFX_FILTER_NOTINSTALLED) const
static SAL_DLLPRIVATE void ReadFilters_Impl(bool bUpdate=false)
std::shared_ptr< const SfxFilter > GetAnyFilter(SfxFilterFlags nMust=SfxFilterFlags::IMPORT, SfxFilterFlags nDont=SFX_FILTER_NOTINSTALLED) const
SfxFilterContainer(const OUString &rName)
std::unique_ptr< SfxFilterContainer_Impl > pImpl
SfxFilterMatcherIter(const SfxFilterMatcher &rMatcher, SfxFilterFlags nMask=SfxFilterFlags::NONE, SfxFilterFlags nNotMask=SFX_FILTER_NOTINSTALLED)
std::shared_ptr< const SfxFilter > First()
const SfxFilterMatcher_Impl & m_rMatch
SAL_DLLPRIVATE std::shared_ptr< const SfxFilter > Find_Impl()
std::shared_ptr< const SfxFilter > Next()
void InitForIterating() const
SfxFilterMatcher_Impl(OUString _aName)
SfxFilterList_Impl * pList
ErrCode GuessFilterIgnoringContent(SfxMedium const &rMedium, std::shared_ptr< const SfxFilter > &) const
SfxFilterMatcher_Impl & m_rImpl
std::shared_ptr< const SfxFilter > GetAnyFilter(SfxFilterFlags nMustg=SfxFilterFlags::NONE, SfxFilterFlags nDont=SFX_FILTER_NOTINSTALLED) const
ErrCode GuessFilter(SfxMedium &rMedium, std::shared_ptr< const SfxFilter > &, SfxFilterFlags nMust=SfxFilterFlags::IMPORT, SfxFilterFlags nDont=SFX_FILTER_NOTINSTALLED) const
std::shared_ptr< const SfxFilter > GetFilter4FilterName(const OUString &rName, SfxFilterFlags nMust=SfxFilterFlags::NONE, SfxFilterFlags nDont=SFX_FILTER_NOTINSTALLED) const
std::shared_ptr< const SfxFilter > GetFilter4ClipBoardId(SotClipboardFormatId nId, SfxFilterFlags nMust=SfxFilterFlags::IMPORT, SfxFilterFlags nDont=SFX_FILTER_NOTINSTALLED) const
std::shared_ptr< const SfxFilter > GetFilter4UIName(std::u16string_view rName, SfxFilterFlags nMust=SfxFilterFlags::NONE, SfxFilterFlags nDont=SFX_FILTER_NOTINSTALLED) const
std::shared_ptr< const SfxFilter > GetFilter4EA(const OUString &rEA, SfxFilterFlags nMust=SfxFilterFlags::IMPORT, SfxFilterFlags nDont=SFX_FILTER_NOTINSTALLED) const
ErrCode DetectFilter(SfxMedium &rMedium, std::shared_ptr< const SfxFilter > &) const
std::shared_ptr< const SfxFilter > GetFilterForProps(const css::uno::Sequence< css::beans::NamedValue > &aSeq, SfxFilterFlags nMust=SfxFilterFlags::NONE, SfxFilterFlags nDont=SFX_FILTER_NOTINSTALLED) const
ErrCode GuessFilterControlDefaultUI(SfxMedium &rMedium, std::shared_ptr< const SfxFilter > &, SfxFilterFlags nMust=SfxFilterFlags::IMPORT, SfxFilterFlags nDont=SFX_FILTER_NOTINSTALLED) const
std::shared_ptr< const SfxFilter > GetFilter4Extension(const OUString &rExt, SfxFilterFlags nMust=SfxFilterFlags::IMPORT, SfxFilterFlags nDont=SFX_FILTER_NOTINSTALLED) const
static SAL_DLLPRIVATE bool IsFilterInstalled_Impl(const std::shared_ptr< const SfxFilter > &pFilter)
std::shared_ptr< const SfxFilter > GetFilter4Mime(const OUString &rMime, SfxFilterFlags nMust=SfxFilterFlags::IMPORT, SfxFilterFlags nDont=SFX_FILTER_NOTINSTALLED) const
SfxFilterFlags nFormatType
void SetDefaultTemplate(const OUString &rStr)
static std::shared_ptr< const SfxFilter > GetFilterByName(const OUString &rName)
void SetVersion(sal_Int32 nVersionP)
SotClipboardFormatId lFormat
void SetUIName(const OUString &rName)
const SfxPoolItem * GetItem(sal_uInt16 nWhich, bool bSearchInParent=true) const
const INetURLObject & GetURLObject() const
SfxItemSet & GetItemSet() const
css::uno::Reference< css::io::XInputStream > const & GetInputStream()
css::uno::Reference< css::task::XInteractionHandler > GetInteractionHandler(bool bGetAlways=false)
static OUString GetServiceNameFromFactory(const OUString &rFact)
static OUString GetFormatName(SotClipboardFormatId nFormat)
static SotClipboardFormatId RegisterFormatName(const OUString &rName)
const OUString & GetFactoryName(EFactory eFactory) const
static EFactory ClassifyFactoryByShortName(std::u16string_view sName)
OUString GetFactoryDefaultFilter(EFactory eFactory) const
static EFactory ClassifyFactoryByServiceName(std::u16string_view sName)
const CharClass & GetCharClass() const
bool Matches(std::u16string_view rStr) const
#define SFX_FILTER_NOTINSTALLED
#define ERRCODE_IO_PENDING
static SfxFilterList_Impl * pFilterArr
static OUString implc_convertStringlistToString(const uno::Sequence< OUString > &lList, sal_Unicode cSeparator, std::u16string_view sPrefix)
IMPL_LINK(SfxFilterMatcher, MaybeFileHdl_Impl, OUString *, pString, bool)
static void CreateFilterArr()
static OUString ToUpper_Impl(const OUString &rStr)
Sequence< sal_Int8 > aSeq
#define SAL_WARN(area, stream)
Reference< XMultiServiceFactory > getProcessServiceFactory()
OUString SfxResId(TranslateId aId)