20#include <com/sun/star/container/XNameAccess.hpp>
21#include <com/sun/star/ucb/SimpleFileAccess.hpp>
22#include <com/sun/star/document/XTypeDetection.hpp>
23#include <com/sun/star/frame/ModuleManager.hpp>
24#include <com/sun/star/frame/XLoadable.hpp>
25#include <com/sun/star/frame/XStorable.hpp>
26#include <com/sun/star/lang/XMultiServiceFactory.hpp>
39#include <osl/file.hxx>
40#include <osl/security.hxx>
68 return pImpl->pFilterContainer;
75) : m_sFactoryName(
std::move(
sName )),
79 pImpl->aClassName = rName;
84 delete pImpl->pFilterContainer;
93#if OSL_DEBUG_LEVEL > 0
96 for (
auto const& viewFactory :
pImpl->aViewFactoryArr)
98 if ( viewFactory->GetAPIViewName() != sViewName )
100 SAL_WARN(
"sfx",
"SfxObjectFactory::RegisterViewFactory: duplicate view name: " << sViewName );
105 auto it = std::find_if(
pImpl->aViewFactoryArr.begin(),
pImpl->aViewFactoryArr.end(),
106 [&rFactory](
SfxViewFactory* pFactory) { return pFactory->GetOrdinal() > rFactory.GetOrdinal(); });
107 pImpl->aViewFactoryArr.insert(it, &rFactory);
113 return pImpl->aViewFactoryArr.size();
119 return *
pImpl->aViewFactoryArr[
i];
125 return pImpl->pModule;
130 pImpl->pModule = pMod;
135 static const int nMaxPathSize = 16000;
137 const OUString sConfPath =
"Office/Factories/" + rServiceName;
138 static constexpr OUStringLiteral PROP_DEF_TEMPL_CHANGED
139 =
u"ooSetupFactorySystemDefaultTemplateChanged";
141 static const char DEF_TPL_STR[] =
"/soffice.";
143 OUString sUserTemplateURL;
147 sPath = OUString( aPathBuffer );
148 osl::FileBase::getFileURLFromSystemPath( sPath, sUserTemplateURL );
150 if ( sUserTemplateURL.isEmpty())
155 uno::Reference< lang::XMultiServiceFactory >
xFactory = ::comphelper::getProcessServiceFactory();
159 OUString aActualFilter;
161 bool bChanged(
false);
164 uno::Reference< container::XNameAccess > xFilterFactory(
165 xFactory->createInstance(
"com.sun.star.document.FilterFactory" ), uno::UNO_QUERY_THROW );
166 uno::Reference< container::XNameAccess > xTypeDetection(
167 xFactory->createInstance(
"com.sun.star.document.TypeDetection" ), uno::UNO_QUERY_THROW );
169 OUString aActualFilterTypeName;
170 uno::Sequence< beans::PropertyValue > aActuralFilterData;
171 xFilterFactory->getByName( aActualFilter ) >>= aActuralFilterData;
172 for (
const auto& rProp : std::as_const(aActuralFilterData) )
173 if ( rProp.Name ==
"Type" )
174 rProp.Value >>= aActualFilterTypeName;
176 uno::Sequence< OUString > aAllExt =
179 const OUString aExt = DEF_TPL_STR + aAllExt[0];
181 sUserTemplateURL += aExt;
183 uno::Reference<ucb::XSimpleFileAccess3> xSimpleFileAccess(
184 ucb::SimpleFileAccess::create( ::comphelper::getComponentContext(
xFactory) ) );
187 ::osl::Security().getConfigDir(aBackupURL);
188 aBackupURL +=
"/temp";
190 if ( !xSimpleFileAccess->exists( aBackupURL ) )
191 xSimpleFileAccess->createFolder( aBackupURL );
195 if ( !rTemplateName.isEmpty() )
197 if ( xSimpleFileAccess->exists( sUserTemplateURL ) && !bChanged )
198 xSimpleFileAccess->copy( sUserTemplateURL, aBackupURL );
200 uno::Reference< document::XTypeDetection > xTypeDetector( xTypeDetection, uno::UNO_QUERY );
202 OUString aFilterName =
205 uno::Sequence< beans::PropertyValue > aArgs{
211 uno::Reference< frame::XLoadable > xLoadable(
xFactory->createInstance( rServiceName ), uno::UNO_QUERY );
212 xLoadable->load( aArgs );
215 auto pArgs = aArgs.getArray();
216 pArgs[1].Name =
"Overwrite";
217 pArgs[1].Value <<=
true;
219 uno::Reference< frame::XStorable > xStorable( xLoadable, uno::UNO_QUERY );
220 xStorable->storeToURL( sUserTemplateURL, aArgs );
226 DBG_ASSERT( bChanged,
"invalid ooSetupFactorySystemDefaultTemplateChanged value!" );
228 xSimpleFileAccess->copy( aBackupURL, sUserTemplateURL );
229 xSimpleFileAccess->kill( aBackupURL );
234 catch(
const uno::Exception&)
268 std::shared_ptr<const SfxFilter> pFilter;
269 std::shared_ptr<const SfxFilter> pTemp = aIter.
First();
272 if( pTemp->IsOwnFormat() && pTemp->IsOwnTemplateFormat() && ( pTemp->GetVersion() >
nVersion ) )
275 nVersion =
static_cast<sal_uInt16
>(pTemp->GetVersion());
278 pTemp = aIter.
Next();
286 pImpl->aServiceName = rServiceName;
291 return pImpl->aServiceName;
296 return pImpl->aClassName;
308 css::uno::Reference< css::uno::XComponentContext > xContext = ::comphelper::getProcessComponentContext();
310 css::uno::Reference< css::frame::XModuleManager2 > xModuleManager(
311 css::frame::ModuleManager::create(xContext));
316 catch(
const css::uno::RuntimeException&)
320 catch(
const css::uno::Exception&)
333 if ( i_nViewId == curViewId )
341 for ( sal_uInt16 nViewNo = 0;
const sal_uInt16 nVersion
std::shared_ptr< const SfxFilter > First()
std::shared_ptr< const SfxFilter > Next()
OUString GetFactoryURL() const
static void SetStandardTemplate(const OUString &rServiceName, const OUString &rTemplateName)
void RegisterViewFactory(SfxViewFactory &rFactory)
SfxModule * GetModule() const
SfxFilterContainer * GetFilterContainer() const
static OUString GetStandardTemplate(std::u16string_view rServiceName)
OUString GetModuleName() const
SfxViewFactory * GetViewFactoryByViewName(std::u16string_view i_rViewName) const
returns the view factory whose GetAPIViewName or GetLegacyViewName delivers the requested logical nam...
SfxViewFactory & GetViewFactory(sal_uInt16 i=0) const
std::shared_ptr< const SfxFilter > GetTemplateFilter() const
SAL_DLLPRIVATE sal_uInt16 GetViewNo_Impl(const SfxInterfaceId i_nViewId, const sal_uInt16 i_nFallback) const
static void SetSystemTemplate(const OUString &rServiceName, const OUString &rTemplateName)
const OUString & GetDocumentServiceName() const
const SvGlobalName & GetClassId() const
SfxObjectFactory(const SvGlobalName &rName, OUString sFactoryName)
const OUString m_sFactoryName
std::unique_ptr< SfxObjectFactory_Impl > pImpl
SAL_DLLPRIVATE void SetModule_Impl(SfxModule *)
sal_uInt16 GetViewFactoryCount() const
void SetDocumentServiceName(const OUString &rServiceName)
OUString GetLegacyViewName() const
returns a legacy view name. This is "view" with an appended ordinal/ID.
OUString GetAPIViewName() const
returns an API-compatible view name.
SfxInterfaceId GetOrdinal() const
OUString GetFactoryStandardTemplate(EFactory eFactory) const
void SetFactoryStandardTemplate(EFactory eFactory, const OUString &sTemplate)
static EFactory ClassifyFactoryByShortName(std::u16string_view sName)
static EFactory ClassifyFactoryByServiceName(std::u16string_view sName)
static css::uno::Any readRelativeKey(const css::uno::Reference< css::uno::XInterface > &xCFG, const OUString &sRelPath, const OUString &sKey)
static css::uno::Reference< css::uno::XInterface > openConfig(const css::uno::Reference< css::uno::XComponentContext > &rxContext, const OUString &sPackage, EConfigurationModes eMode)
static void flush(const css::uno::Reference< css::uno::XInterface > &xCFG)
static void writeRelativeKey(const css::uno::Reference< css::uno::XInterface > &xCFG, const OUString &sRelPath, const OUString &sKey, const css::uno::Any &aValue)
TValueType getUnpackedValueOrDefault(const OUString &sKey, const TValueType &aDefault) const
#define DBG_ASSERT(sCon, aError)
Reference< XSingleServiceFactory > xFactory
#define SAL_WARN(area, stream)
bool GetUserTemplateLocation(sal_Unicode *pFolder, int nSize)
css::beans::PropertyValue makePropertyValue(const OUString &rName, T &&rValue)
SfxFilterContainer * pFilterContainer
std::vector< SfxViewFactory * > aViewFactoryArr