20#include <osl/mutex.hxx>
24#include <rtl/ustring.hxx>
38#include <com/sun/star/beans/IllegalTypeException.hpp>
39#include <com/sun/star/beans/PropertyAttribute.hpp>
40#include <com/sun/star/beans/PropertyExistException.hpp>
41#include <com/sun/star/beans/XPropertySetInfo.hpp>
42#include <com/sun/star/beans/XPropertyContainer.hpp>
43#include <com/sun/star/beans/StringPair.hpp>
44#include <com/sun/star/ucb/SimpleFileAccess.hpp>
45#include <com/sun/star/util/theMacroExpander.hpp>
46#include <com/sun/star/util/theOfficeInstallationDirectories.hpp>
47#include <com/sun/star/configuration/theDefaultProvider.hpp>
48#include <com/sun/star/document/XTypeDetection.hpp>
49#include <com/sun/star/document/DocumentProperties.hpp>
50#include <com/sun/star/io/TempFile.hpp>
51#include <com/sun/star/sdbc/XResultSet.hpp>
52#include <com/sun/star/sdbc/XRow.hpp>
53#include <com/sun/star/ucb/ContentCreationException.hpp>
54#include <com/sun/star/ucb/NameClash.hpp>
55#include <com/sun/star/ucb/NameClashException.hpp>
56#include <com/sun/star/ucb/XCommandEnvironment.hpp>
57#include <com/sun/star/ucb/XContentAccess.hpp>
58#include <com/sun/star/frame/ModuleManager.hpp>
59#include <com/sun/star/uno/Exception.hpp>
60#include <com/sun/star/task/InteractionHandler.hpp>
61#include <com/sun/star/ucb/XProgressHandler.hpp>
62#include <com/sun/star/container/XNameAccess.hpp>
63#include <com/sun/star/frame/XDocumentTemplates.hpp>
64#include <com/sun/star/frame/XStorable.hpp>
65#include <com/sun/star/lang/Locale.hpp>
66#include <com/sun/star/lang/XLocalizable.hpp>
67#include <com/sun/star/lang/XServiceInfo.hpp>
68#include <com/sun/star/lang/XMultiServiceFactory.hpp>
69#include <com/sun/star/ucb/XContent.hpp>
70#include <com/sun/star/beans/PropertyValue.hpp>
71#include <com/sun/star/uno/RuntimeException.hpp>
72#include <com/sun/star/uno/XComponentContext.hpp>
73#include <com/sun/star/util/thePathSettings.hpp>
86#include <sfx2/strings.hrc>
87#include <doctempl.hrc>
95constexpr OUStringLiteral
TITLE =
u"Title";
101constexpr OUStringLiteral
TYPE_FOLDER =
u"application/vnd.sun.star.hier-folder";
102constexpr OUStringLiteral
TYPE_LINK =
u"application/vnd.sun.star.hier-link";
104constexpr OUStringLiteral
TYPE_FSYS_FILE =
u"application/vnd.sun.staroffice.fsys-file";
139 static constexpr DrawTextFlags gnTextStyle = DrawTextFlags::Center | DrawTextFlags::VCenter | DrawTextFlags::WordBreak | DrawTextFlags::MultiLine;
143 virtual ~WaitWindow_Impl()
override;
144 virtual void dispose()
override;
154 OUString maShortName;
158class DocTemplates_EntryData_Impl;
161typedef vector< std::unique_ptr<GroupData_Impl> > GroupList_Impl;
164class TplTaskEnvironment :
public ::cppu::WeakImplHelper< ucb::XCommandEnvironment >
169 explicit TplTaskEnvironment( uno::Reference< task::XInteractionHandler> xInteractionHandler )
173 virtual uno::Reference<task::XInteractionHandler> SAL_CALL getInteractionHandler()
override
176 virtual uno::Reference<ucb::XProgressHandler> SAL_CALL getProgressHandler()
override
177 {
return uno::Reference<ucb::XProgressHandler>(); }
180class SfxDocTplService :
public ::cppu::WeakImplHelper< css::lang::XLocalizable, css::frame::XDocumentTemplates, css::lang::XServiceInfo >
183 explicit SfxDocTplService(
const css::uno::Reference < uno::XComponentContext >& xContext );
184 virtual ~SfxDocTplService()
override;
188 return "com.sun.star.comp.sfx2.DocumentTemplates";
198 css::uno::Sequence< OUString >
aSeq {
"com.sun.star.frame.DocumentTemplates" };
204 void SAL_CALL
setLocale(
const css::lang::Locale & eLocale )
override;
205 css::lang::Locale SAL_CALL
getLocale()
override;
208 css::uno::Reference< css::ucb::XContent > SAL_CALL getContent()
override;
209 sal_Bool SAL_CALL storeTemplate(
const OUString& GroupName,
210 const OUString& TemplateName,
211 const css::uno::Reference< css::frame::XStorable >& Storable )
override;
212 sal_Bool SAL_CALL addTemplate(
const OUString& GroupName,
213 const OUString& TemplateName,
214 const OUString& SourceURL )
override;
215 sal_Bool SAL_CALL removeTemplate(
const OUString& GroupName,
216 const OUString& TemplateName )
override;
217 sal_Bool SAL_CALL renameTemplate(
const OUString& GroupName,
218 const OUString& OldTemplateName,
219 const OUString& NewTemplateName )
override;
220 sal_Bool SAL_CALL addGroup(
const OUString& GroupName )
override;
221 sal_Bool SAL_CALL removeGroup(
const OUString& GroupName )
override;
222 sal_Bool SAL_CALL renameGroup(
const OUString& OldGroupName,
223 const OUString& NewGroupName )
override;
224 void SAL_CALL
update()
override;
227 bool init() {
if ( !mbIsInitialized ) init_Impl();
return mbIsInitialized; }
231 uno::Reference< XComponentContext >
mxContext;
232 uno::Reference< XCommandEnvironment > maCmdEnv;
233 uno::Reference< XDocumentProperties> m_xDocProps;
234 uno::Reference< XTypeDetection > mxType;
237 Sequence< OUString > maTemplateDirs;
238 Sequence< OUString > maInternalTemplateDirs;
240 std::vector< NamePair_Impl > maNames;
241 lang::Locale maLocale;
243 bool mbIsInitialized : 1;
244 bool mbLocaleSet : 1;
249 void getDefaultLocale();
251 void readFolderList();
253 OUString getLongName(
const OUString& rShortName );
254 bool setTitleForURL(
const OUString& rURL,
const OUString& aTitle );
255 void getTitleFromURL(
const OUString& rURL, OUString& aTitle, OUString& aType,
bool& bDocHasTitle );
257 bool addEntry( Content& rParentFolder,
258 const OUString& rTitle,
259 const OUString& rTargetURL,
260 const OUString& rType );
262 bool createFolder(
const OUString& rNewFolderURL,
265 Content &rNewFolder );
267 static bool CreateNewUniqueFolderWithPrefix( std::u16string_view aPath,
268 const OUString& aPrefix,
269 OUString& aNewFolderName,
270 OUString& aNewFolderURL,
271 Content& aNewFolder );
272 static OUString CreateNewUniqueFileWithPrefix( std::u16string_view aPath,
273 const OUString& aPrefix,
274 std::u16string_view aExt );
276 std::vector< beans::StringPair > ReadUINamesForTemplateDir_Impl( std::u16string_view aUserPath );
277 bool UpdateUINamesForTemplateDir_Impl( std::u16string_view aUserPath,
278 const OUString& aGroupName,
279 const OUString& aNewFolderName );
280 bool ReplaceUINamesForTemplateDir_Impl( std::u16string_view aUserPath,
281 const OUString& aFsysGroupName,
282 std::u16string_view aOldGroupName,
283 const OUString& aNewGroupName );
284 void RemoveUINamesForTemplateDir_Impl( std::u16string_view aUserPath,
285 std::u16string_view aGroupName );
286 bool WriteUINamesForTemplateDir_Impl( std::u16string_view aUserPath,
287 const std::vector< beans::StringPair >& aUINames );
289 OUString CreateNewGroupFsys(
const OUString& rGroupName, Content& aGroup );
291 static bool removeContent( Content& rContent );
292 bool removeContent(
const OUString& rContentURL );
294 bool setProperty( Content& rContent,
295 const OUString& rPropName,
296 const Any& rPropValue );
298 const OUString& rPropName,
301 void createFromContent( GroupList_Impl& rList,
304 bool bWriteableContent );
305 void addHierGroup( GroupList_Impl& rList,
306 const OUString& rTitle,
307 const OUString& rOwnURL );
308 void addFsysGroup( GroupList_Impl& rList,
309 const OUString& rTitle,
310 const OUString& rUITitle,
311 const OUString& rOwnURL,
312 bool bWriteableGroup );
313 void removeFromHierarchy( DocTemplates_EntryData_Impl
const *pData );
314 void addToHierarchy( GroupData_Impl
const *pGroup,
315 DocTemplates_EntryData_Impl
const *pData );
317 void removeFromHierarchy( GroupData_Impl
const *pGroup );
318 void addGroupToHierarchy( GroupData_Impl *pGroup );
320 void updateData( DocTemplates_EntryData_Impl
const *pData );
324 OUString findParentTemplateDir(
const OUString& rURL)
const;
329 bool isInternalTemplateDir(
const OUString& rURL)
const;
333class DocTemplates_EntryData_Impl
338 OUString maHierarchyURL;
340 bool mbInHierarchy : 1;
342 bool mbUpdateType : 1;
343 bool mbUpdateLink : 1;
346 explicit DocTemplates_EntryData_Impl( OUString aTitle );
348 void setInUse() { mbInUse =
true; }
349 void setHierarchy(
bool bInHierarchy ) { mbInHierarchy = bInHierarchy; }
350 void setUpdateLink(
bool bUpdateLink ) { mbUpdateLink = bUpdateLink; }
351 void setUpdateType(
bool bUpdateType ) { mbUpdateType = bUpdateType; }
353 bool getInUse()
const {
return mbInUse; }
354 bool getInHierarchy()
const {
return mbInHierarchy; }
355 bool getUpdateLink()
const {
return mbUpdateLink; }
356 bool getUpdateType()
const {
return mbUpdateType; }
358 const OUString& getHierarchyURL()
const {
return maHierarchyURL; }
359 const OUString& getTargetURL()
const {
return maTargetURL; }
363 void setHierarchyURL(
const OUString& rURL ) { maHierarchyURL = rURL; }
364 void setTargetURL(
const OUString& rURL ) {
maTargetURL = rURL; }
365 void setType(
const OUString& rType ) {
maType = rType; }
371 std::vector< std::unique_ptr<DocTemplates_EntryData_Impl> > maEntries;
373 OUString maHierarchyURL;
376 bool mbInHierarchy : 1;
379 explicit GroupData_Impl( OUString aTitle );
381 void setInUse() { mbInUse =
true; }
382 void setHierarchy(
bool bInHierarchy ) { mbInHierarchy = bInHierarchy; }
383 void setHierarchyURL(
const OUString& rURL ) { maHierarchyURL = rURL; }
384 void setTargetURL(
const OUString& rURL ) {
maTargetURL = rURL; }
386 bool getInUse()
const {
return mbInUse; }
387 bool getInHierarchy()
const {
return mbInHierarchy; }
388 const OUString& getHierarchyURL()
const {
return maHierarchyURL; }
389 const OUString& getTargetURL()
const {
return maTargetURL; }
392 DocTemplates_EntryData_Impl* addEntry(
const OUString& rTitle,
393 const OUString& rTargetURL,
394 const OUString& rType,
395 const OUString& rHierURL );
396 size_t count() {
return maEntries.size(); }
397 DocTemplates_EntryData_Impl* getEntry(
size_t nPos ) {
return maEntries[
nPos ].get(); }
403void SfxDocTplService::init_Impl()
405 uno::Reference< uno::XComponentContext > xContext = ::comphelper::getProcessComponentContext();
406 uno::Reference < task::XInteractionHandler > xInteractionHandler(
407 task::InteractionHandler::createWithParent(xContext,
nullptr), uno::UNO_QUERY_THROW );
408 maCmdEnv =
new TplTaskEnvironment( xInteractionHandler );
410 ::osl::ClearableMutexGuard aGuard( maMutex );
411 bool bIsInitialized =
false;
412 bool bNeedsUpdate =
false;
429 if (
getProperty( maRootContent, aTemplVersPropName, aValue )
430 && ( aValue >>= aPropValue )
431 && aPropValue == aTemplVers )
433 bIsInitialized =
true;
436 removeContent( maRootContent );
439 if ( !bIsInitialized )
441 if ( createFolder( maRootURL,
true,
false, maRootContent )
442 && setProperty( maRootContent, aTemplVersPropName,
uno::Any( aTemplVers ) ) )
443 bIsInitialized =
true;
448 if ( bIsInitialized )
451 m_xDocProps.set(document::DocumentProperties::create(
452 ::comphelper::getProcessComponentContext()));
453 }
catch (uno::RuntimeException
const&) {
454 TOOLS_WARN_EXCEPTION(
"sfx.doc",
"SfxDocTplService_Impl::init_Impl: cannot create DocumentProperties service:");
470 osl::MutexGuard anotherGuard(maMutex);
477 else if ( needsUpdate() )
483 SAL_WARN(
"sfx.doc",
"init_Impl(): Could not create root" );
486 mbIsInitialized = bIsInitialized;
490void SfxDocTplService::getDefaultLocale()
494 ::osl::MutexGuard aGuard( maMutex );
503const char* TEMPLATE_SHORT_NAMES_ARY[] =
515void SfxDocTplService::readFolderList()
524 aPair.maShortName = OUString::createFromAscii(TEMPLATE_SHORT_NAMES_ARY[i]);
525 aPair.maLongName =
SfxResId(TEMPLATE_LONG_NAMES_ARY[i]);
527 maNames.push_back( aPair );
532OUString SfxDocTplService::getLongName(
const OUString& rShortName )
536 for (
auto const & rPair : maNames)
538 if ( rPair.maShortName == rShortName )
540 aRet = rPair.maLongName;
545 if ( aRet.isEmpty() )
552void SfxDocTplService::getDirList()
562 maTemplateDirs = Sequence< OUString >( nCount );
564 uno::Reference< util::XMacroExpander > xExpander = util::theMacroExpander::get(mxContext);
567 for (
auto& rTemplateDir : asNonConstRange(maTemplateDirs))
569 aURL.SetSmartProtocol( INetProtocol::File );
573 if (xExpander && rTemplateDir.startsWithIgnoreAsciiCase(
"vnd.sun.star.expand:", &rTemplateDir))
576 = rtl::Uri::decode(rTemplateDir, rtl_UriDecodeStrict, RTL_TEXTENCODING_UTF8);
577 rTemplateDir = xExpander->expandMacros( rTemplateDir );
581 aValue <<= maTemplateDirs;
583 css::uno::Reference< css::util::XPathSettings > xPathSettings =
584 css::util::thePathSettings::get(mxContext);
587 Any aAny = xPathSettings->getPropertyValue(
"Template_internal" );
588 aAny >>= maInternalTemplateDirs;
590 for (
auto& rInternalTemplateDir : asNonConstRange(maInternalTemplateDirs))
594 maRelocator.makeRelocatableURL(rInternalTemplateDir);
595 maRelocator.makeAbsoluteURL(rInternalTemplateDir);
603bool SfxDocTplService::needsUpdate()
605 bool bNeedsUpdate =
true;
612 aValue >>= bNeedsUpdate;
616 ::svt::TemplateFolderCache aTempCache;
618 bNeedsUpdate = aTempCache.needsUpdate();
621 aTempCache.storeState();
627bool SfxDocTplService::setTitleForURL(
const OUString& rURL,
const OUString& aTitle )
629 if (m_xDocProps.is())
633 m_xDocProps->loadFromMedium(rURL, Sequence<PropertyValue>());
634 m_xDocProps->setTitle(aTitle);
637 rURL, embed::ElementModes::READWRITE);
640 {
"DocumentBaseURL",
Any(rURL) },
644 m_xDocProps->storeToStorage(xStorage, medium);
655void SfxDocTplService::getTitleFromURL(
const OUString& rURL, OUString& aTitle, OUString& aType,
bool& bDocHasTitle )
657 bDocHasTitle =
false;
659 if (m_xDocProps.is())
663 m_xDocProps->loadFromMedium(rURL, Sequence<PropertyValue>());
664 aTitle = m_xDocProps->getTitle();
671 if ( aType.isEmpty() && mxType.is() )
673 const OUString aDocType {mxType->queryTypeByURL( rURL )};
674 if ( !aDocType.isEmpty() )
677 uno::Reference< container::XNameAccess > xTypeDetection( mxType, uno::UNO_QUERY_THROW );
678 SequenceAsHashMap aTypeProps( xTypeDetection->getByName( aDocType ) );
679 aType = aTypeProps.getUnpackedValueOrDefault(
683 catch( uno::Exception& )
687 if ( aTitle.isEmpty() )
699bool SfxDocTplService::addEntry( Content& rParentFolder,
700 const OUString& rTitle,
701 const OUString& rTargetURL,
702 const OUString& rType )
704 bool bAddedEntry =
false;
707 aLinkObj.insertName( rTitle,
false,
716 Sequence< Any > aValues{
Any(rTitle),
Any(
false),
Any(rTargetURL) };
731bool SfxDocTplService::createFolder(
const OUString& rNewFolderURL,
734 Content &rNewFolder )
737 bool bCreatedFolder =
false;
745 aParentURL.removeSegment();
746 if ( aParentURL.getSegmentCount() >= 1 )
747 aParentURL.removeFinalSlash();
756 Sequence< Any > aValues{
Any(aFolderName),
Any(
true) };
764 aParent.insertNewContent( aType, {
TITLE,
IS_FOLDER }, aValues, rNewFolder );
765 bCreatedFolder =
true;
767 catch( Exception
const & )
772 else if ( bCreateParent )
778 if ( ( aParentURL.getSegmentCount() >= 1 ) &&
781 bCreatedFolder = createFolder( rNewFolderURL,
false, bFsysFolder, rNewFolder );
785 return bCreatedFolder;
789bool SfxDocTplService::CreateNewUniqueFolderWithPrefix( std::u16string_view aPath,
790 const OUString& aPrefix,
791 OUString& aNewFolderName,
792 OUString& aNewFolderURL,
793 Content& aNewFolder )
795 bool bCreated =
false;
799 uno::Reference< XCommandEnvironment > aQuietEnv;
802 for ( sal_Int32 nInd = 0; nInd < 32000; nInd++ )
804 OUString aTryName = aPrefix;
806 aTryName += OUString::number( nInd );
810 Sequence< Any > aValues{
Any(aTryName),
Any(
true) };
813 catch( ucb::NameClashException& )
820 aObjPath.insertName( aTryName,
false,
831 aNewFolderName = aTryName;
832 aNewFolderURL = aNewFolder.get()->getIdentifier()->getContentIdentifier();
842OUString SfxDocTplService::CreateNewUniqueFileWithPrefix( std::u16string_view aPath,
843 const OUString& aPrefix,
844 std::u16string_view aExt )
846 OUString aNewFileURL;
851 uno::Reference< XCommandEnvironment > aQuietEnv;
854 for ( sal_Int32 nInd = 0; nInd < 32000; nInd++ )
857 bool bCreated =
false;
858 OUString aTryName = aPrefix;
860 aTryName += OUString::number( nInd );
861 if ( aExt.empty() || aExt[0] !=
'.' )
867 Sequence< Any > aValues{
Any(aTryName),
Any(
true) };
870 catch( ucb::NameClashException& )
877 aObjPath.insertName( aTryName,
false,
888 aNewFileURL = aNewFile.get()->getIdentifier()->getContentIdentifier();
898bool SfxDocTplService::removeContent( Content& rContent )
900 bool bRemoved =
false;
909 catch ( Exception& ) {}
915bool SfxDocTplService::removeContent(
const OUString& rContentURL )
920 return removeContent( aContent );
925bool SfxDocTplService::setProperty( Content& rContent,
926 const OUString& rPropName,
927 const Any& rPropValue )
929 bool bPropertySet =
false;
934 Any aPropValue( rPropValue );
935 uno::Reference< XPropertySetInfo > aPropInfo = rContent.getProperties();
938 if ( !aPropInfo.is() || !aPropInfo->hasPropertyByName( rPropName ) )
940 uno::Reference< XPropertyContainer > xProperties( rContent.get(), UNO_QUERY );
941 if ( xProperties.is() )
945 xProperties->addProperty( rPropName, PropertyAttribute::MAYBEVOID, rPropValue );
947 catch( PropertyExistException& ) {}
948 catch( IllegalTypeException& ) {
951 catch( IllegalArgumentException& ) {
962 if ( rPropValue >>= aValue )
964 maRelocator.makeRelocatableURL( aValue );
965 aPropValue <<= aValue;
969 Sequence< OUString > aValues;
970 if ( rPropValue >>= aValues )
972 for (
auto& rValue : asNonConstRange(aValues) )
974 maRelocator.makeRelocatableURL( rValue );
976 aPropValue <<= aValues;
980 OSL_FAIL(
"Unsupported property value type" );
987 rContent.setPropertyValue( rPropName, aPropValue );
991 catch ( Exception& ) {}
997bool SfxDocTplService::getProperty(Content& rContent,
const OUString& rPropName, Any& rPropValue)
999 bool bGotProperty =
false;
1004 uno::Reference< XPropertySetInfo > aPropInfo = rContent.getProperties();
1007 if ( !aPropInfo.is() || !aPropInfo->hasPropertyByName( rPropName ) )
1014 rPropValue = rContent.getPropertyValue( rPropName );
1021 if ( rPropValue >>= aValue )
1023 maRelocator.makeAbsoluteURL( aValue );
1024 rPropValue <<= aValue;
1028 Sequence< OUString > aValues;
1029 if ( rPropValue >>= aValues )
1031 for (
auto& rValue : asNonConstRange(aValues) )
1033 maRelocator.makeAbsoluteURL( rValue );
1035 rPropValue <<= aValues;
1039 OSL_FAIL(
"Unsupported property value type" );
1044 bGotProperty =
true;
1047 catch ( Exception& ) {}
1049 return bGotProperty;
1052SfxDocTplService::SfxDocTplService(
const uno::Reference< XComponentContext > & xContext )
1053 :
mxContext(xContext), mbIsInitialized(false), mbLocaleSet(false), maRelocator(xContext)
1058SfxDocTplService::~SfxDocTplService()
1060 ::osl::MutexGuard aGuard( maMutex );
1065lang::Locale SfxDocTplService::getLocale()
1067 ::osl::MutexGuard aGuard( maMutex );
1076void SfxDocTplService::setLocale(
const lang::Locale &rLocale )
1078 ::osl::MutexGuard aGuard( maMutex );
1080 if ( mbLocaleSet && (
1081 ( maLocale.Language != rLocale.Language ) ||
1082 ( maLocale.Country != rLocale.Country ) ||
1083 ( maLocale.Variant != rLocale.Variant ) ) )
1084 mbIsInitialized =
false;
1091void SfxDocTplService::update()
1100void SfxDocTplService::doUpdate()
1102 ::osl::MutexGuard aGuard( maMutex );
1108 setProperty( maRootContent, aPropName, aValue );
1110 GroupList_Impl aGroupList;
1113 createFromContent( aGroupList, maRootContent,
true,
false );
1116 sal_Int32 nCountDir = maTemplateDirs.getLength();
1117 const OUString* pDirs = maTemplateDirs.getConstArray();
1121 bool bWriteableDirectory =
true;
1124 uno::Reference< XCommandEnvironment > aQuietEnv;
1131 createFromContent( aGroupList, aDirContent,
false, bWriteableDirectory );
1134 bWriteableDirectory =
false;
1138 for(std::unique_ptr<GroupData_Impl>& pGroup : aGroupList)
1140 if ( pGroup->getInUse() )
1142 if ( pGroup->getInHierarchy() )
1146 setProperty( aGroup,
1148 Any( pGroup->getTargetURL() ) );
1150 size_t nCount = pGroup->count();
1153 DocTemplates_EntryData_Impl *
pData = pGroup->getEntry( i );
1154 if ( !
pData->getInUse() )
1156 if (
pData->getInHierarchy() )
1157 removeFromHierarchy( pData );
1159 addToHierarchy( pGroup.get(), pData );
1161 else if (
pData->getUpdateType() ||
1162 pData->getUpdateLink() )
1164 updateData( pData );
1170 addGroupToHierarchy( pGroup.get() );
1174 removeFromHierarchy( pGroup.get() );
1179 setProperty( maRootContent, aPropName, aValue );
1183std::vector< beans::StringPair > SfxDocTplService::ReadUINamesForTemplateDir_Impl( std::u16string_view aUserPath )
1186 aLocObj.insertName( u
"groupuinames.xml",
false,
1192 std::vector< beans::StringPair > aUINames;
1197 uno::Reference< io::XInputStream > xLocStream = aLocContent.openStream();
1198 if ( xLocStream.is() )
1201 catch( uno::Exception& )
1209bool SfxDocTplService::UpdateUINamesForTemplateDir_Impl( std::u16string_view aUserPath,
1210 const OUString& aGroupName,
1211 const OUString& aNewFolderName )
1213 std::vector< beans::StringPair > aUINames = ReadUINamesForTemplateDir_Impl( aUserPath );
1214 sal_Int32 nLen = aUINames.size();
1217 for ( sal_Int32 nInd = 0; nInd < nLen; nInd++ )
1218 if ( aUINames[nInd].First == aNewFolderName )
1221 aUINames.resize( ++nLen );
1222 aUINames[nLen-1].First = aNewFolderName;
1223 aUINames[nLen-1].Second = aGroupName;
1225 return WriteUINamesForTemplateDir_Impl( aUserPath, aUINames );
1229bool SfxDocTplService::ReplaceUINamesForTemplateDir_Impl( std::u16string_view aUserPath,
1230 const OUString& aDefaultFsysGroupName,
1231 std::u16string_view aOldGroupName,
1232 const OUString& aNewGroupName )
1234 std::vector< beans::StringPair > aUINames = ReadUINamesForTemplateDir_Impl( aUserPath );
1235 sal_Int32 nLen = aUINames.size();
1237 bool bChanged =
false;
1238 for ( sal_Int32 nInd = 0; nInd < nLen; nInd++ )
1239 if ( aUINames[nInd].Second == aOldGroupName )
1241 aUINames[nInd].Second = aNewGroupName;
1247 aUINames.resize( ++nLen );
1248 aUINames[nLen-1].First = aDefaultFsysGroupName;
1249 aUINames[nLen-1].Second = aNewGroupName;
1251 return WriteUINamesForTemplateDir_Impl( aUserPath, aUINames );
1255void SfxDocTplService::RemoveUINamesForTemplateDir_Impl( std::u16string_view aUserPath,
1256 std::u16string_view aGroupName )
1258 std::vector< beans::StringPair > aUINames = ReadUINamesForTemplateDir_Impl( aUserPath );
1259 sal_Int32 nLen = aUINames.size();
1260 std::vector< beans::StringPair > aNewUINames( nLen );
1261 sal_Int32 nNewLen = 0;
1263 bool bChanged =
false;
1264 for ( sal_Int32 nInd = 0; nInd < nLen; nInd++ )
1265 if ( aUINames[nInd].Second == aGroupName )
1270 aNewUINames[nNewLen-1].First = aUINames[nInd].First;
1271 aNewUINames[nNewLen-1].Second = aUINames[nInd].Second;
1274 aNewUINames.resize( nNewLen );
1277 WriteUINamesForTemplateDir_Impl( aUserPath, aNewUINames );
1281bool SfxDocTplService::WriteUINamesForTemplateDir_Impl( std::u16string_view aUserPath,
1282 const std::vector< beans::StringPair >& aUINames )
1284 bool bResult =
false;
1286 uno::Reference< io::XTempFile > xTempFile(
1287 io::TempFile::create(mxContext),
1288 uno::UNO_SET_THROW );
1290 uno::Reference< io::XOutputStream > xOutStream = xTempFile->getOutputStream();
1291 if ( !xOutStream.is() )
1292 throw uno::RuntimeException();
1297 xOutStream->closeOutput();
1298 }
catch( uno::Exception& )
1303 aTargetContent.transferContent( aSourceContent,
1304 InsertOperation::Copy,
1306 ucb::NameClash::OVERWRITE,
1311 catch ( uno::Exception& )
1320OUString SfxDocTplService::CreateNewGroupFsys(
const OUString& rGroupName, Content& aGroup )
1322 OUString aResultURL;
1324 if ( maTemplateDirs.hasElements() )
1326 OUString aTargetPath = maTemplateDirs[ maTemplateDirs.getLength() - 1 ];
1330 OUString aNewFolderName;
1333 if ( !CreateNewUniqueFolderWithPrefix( aTargetPath,
1338 && !CreateNewUniqueFolderWithPrefix( aTargetPath,
1346 if ( !UpdateUINamesForTemplateDir_Impl( aTargetPath, rGroupName, aNewFolderName ) )
1350 removeContent( aNewFolder );
1355 Any aValue( aResultURL );
1359 removeContent( aNewFolder );
1368sal_Bool SfxDocTplService::addGroup(
const OUString& rGroupName )
1373 ::osl::MutexGuard aGuard( maMutex );
1377 OUString aNewGroupURL;
1380 aNewGroupObj.insertName( rGroupName,
false,
1387 ! createFolder( aNewGroupURL,
false,
false, aNewGroup ) )
1399 nIndex = maTemplateDirs.getLength();
1405 aUserPath = maTemplateDirs[
nIndex ];
1409 OUString aNewFolderName;
1410 OUString aNewFolderURL;
1413 if ( !CreateNewUniqueFolderWithPrefix( aUserPath,
1418 && !CreateNewUniqueFolderWithPrefix( aUserPath,
1426 removeContent( aNewGroup );
1430 if ( !UpdateUINamesForTemplateDir_Impl( aUserPath, rGroupName, aNewFolderName ) )
1434 removeContent( aNewGroup );
1435 removeContent( aNewFolder );
1440 Any aValue( aNewFolderURL );
1444 removeContent( aNewGroup );
1445 removeContent( aNewFolder );
1453sal_Bool SfxDocTplService::removeGroup(
const OUString& rGroupName )
1461 ::osl::MutexGuard aGuard( maMutex );
1463 bool bResult =
false;
1467 aGroupObj.insertName( rGroupName,
false,
1480 OUString aGroupTargetURL;
1482 aValue >>= aGroupTargetURL;
1484 if ( aGroupTargetURL.isEmpty() )
1487 if ( !maTemplateDirs.hasElements() )
1492 if (!aGroupParentFolder.removeSegment())
1495 OUString aGeneralTempPath = findParentTemplateDir(
1498 if (aGeneralTempPath.isEmpty())
1502 uno::Reference< XResultSet > xResultSet;
1507 xResultSet = aGroup.createCursor( aProps, INCLUDE_DOCUMENTS_ONLY );
1509 if ( xResultSet.is() )
1511 bool bHasNonRemovable =
false;
1512 bool bHasShared =
false;
1514 uno::Reference< XContentAccess > xContentAccess( xResultSet, UNO_QUERY_THROW );
1515 uno::Reference< XRow > xRow( xResultSet, UNO_QUERY_THROW );
1517 while ( xResultSet->next() )
1519 OUString aTemplTargetURL( xRow->getString( 1 ) );
1520 OUString aHierURL = xContentAccess->queryContentIdentifierString();
1522 if ( ::utl::UCBContentHelper::IsSubPath( aGroupTargetURL, aTemplTargetURL ) )
1525 if ( removeContent( aTemplTargetURL ) )
1526 removeContent( aHierURL );
1528 bHasNonRemovable =
true;
1534 if ( !bHasNonRemovable && !bHasShared )
1536 if ( removeContent( aGroupTargetURL )
1537 || !::utl::UCBContentHelper::Exists( aGroupTargetURL ) )
1539 removeContent( aGroupURL );
1540 RemoveUINamesForTemplateDir_Impl( aGeneralTempPath, rGroupName );
1544 else if ( !bHasNonRemovable )
1546 if ( removeContent( aGroupTargetURL )
1547 || !::utl::UCBContentHelper::Exists( aGroupTargetURL ) )
1549 RemoveUINamesForTemplateDir_Impl( aGeneralTempPath, rGroupName );
1550 setProperty( aGroup, aPropName,
uno::Any( OUString() ) );
1555 catch ( Exception& ) {}
1562sal_Bool SfxDocTplService::renameGroup(
const OUString& rOldName,
1563 const OUString& rNewName )
1565 if ( rOldName == rNewName )
1571 ::osl::MutexGuard aGuard( maMutex );
1576 aGroupObj.insertName( rNewName,
false,
1586 aGroupObj.removeSegment();
1587 aGroupObj.insertName( rOldName,
false,
1596 OUString aGroupTargetURL;
1601 aValue >>= aGroupTargetURL;
1603 if ( aGroupTargetURL.isEmpty() )
1606 if ( !maTemplateDirs.hasElements() )
1611 if (!aGroupParentFolder.removeSegment() ||
1618 bool bCanBeRenamed =
false;
1621 uno::Reference< XResultSet > xResultSet;
1623 xResultSet = aGroup.createCursor( aProps, INCLUDE_DOCUMENTS_ONLY );
1625 if ( xResultSet.is() )
1627 uno::Reference< XContentAccess > xContentAccess( xResultSet, UNO_QUERY_THROW );
1628 uno::Reference< XRow > xRow( xResultSet, UNO_QUERY_THROW );
1630 while ( xResultSet->next() )
1632 if ( !::utl::UCBContentHelper::IsSubPath( aGroupTargetURL, xRow->getString( 1 ) ) )
1633 throw uno::Exception(
"not sub path",
nullptr);
1636 bCanBeRenamed =
true;
1639 catch ( Exception& ) {}
1641 if ( bCanBeRenamed )
1646 if ( aGroupTargetObj.removeSegment()
1654 aTitleValue <<= rNewName;
1656 return setProperty( aGroup,
TITLE, aTitleValue );
1664sal_Bool SfxDocTplService::storeTemplate(
const OUString& rGroupName,
1665 const OUString& rTemplateName,
1666 const uno::Reference< frame::XStorable >& rStorable )
1671 ::osl::MutexGuard aGuard( maMutex );
1675 Content aGroup, aTemplateToRemove;
1677 bool bRemoveOldTemplateContent =
false;
1679 aGroupObj.insertName( rGroupName,
false,
1687 OUString aGroupTargetURL;
1690 aValue >>= aGroupTargetURL;
1697 aGroupObj.insertName( rTemplateName,
false,
1702 OUString aTemplateToRemoveTargetURL;
1706 bRemoveOldTemplateContent =
true;
1708 aValue >>= aTemplateToRemoveTargetURL;
1710 if ( aGroupTargetURL.isEmpty() || !maTemplateDirs.hasElements()
1711 || (!aTemplateToRemoveTargetURL.isEmpty() && isInternalTemplateDir(aTemplateToRemoveTargetURL)) )
1717 uno::Reference< uno::XComponentContext > xContext = ::comphelper::getProcessComponentContext();
1720 uno::Reference< frame::XModuleManager2 > xModuleManager( frame::ModuleManager::create(xContext) );
1721 const OUString sDocServiceName {xModuleManager->identify( uno::Reference< uno::XInterface >( rStorable, uno::UNO_QUERY ) )};
1722 if ( sDocServiceName.isEmpty() )
1723 throw uno::RuntimeException();
1726 uno::Reference< lang::XMultiServiceFactory > xConfigProvider =
1727 configuration::theDefaultProvider::get( xContext );
1731 {
"nodepath",
uno::Any(OUString(
"/org.openoffice.Setup/Office/Factories/" ))}
1733 uno::Reference< container::XNameAccess > xSOFConfig(
1734 xConfigProvider->createInstanceWithArguments(
1735 "com.sun.star.configuration.ConfigurationAccess",
1737 uno::UNO_QUERY_THROW );
1739 uno::Reference< container::XNameAccess > xApplConfig;
1740 xSOFConfig->getByName( sDocServiceName ) >>= xApplConfig;
1741 if ( !xApplConfig.is() )
1742 throw uno::RuntimeException();
1744 OUString aFilterName;
1745 xApplConfig->getByName(
"ooSetupFactoryActualTemplateFilter") >>= aFilterName;
1746 if ( aFilterName.isEmpty() )
1747 throw uno::RuntimeException();
1750 uno::Reference< container::XNameAccess > xFilterFactory(
1751 mxContext->getServiceManager()->createInstanceWithContext(
"com.sun.star.document.FilterFactory", mxContext),
1752 uno::UNO_QUERY_THROW );
1754 uno::Sequence< beans::PropertyValue > aFilterData;
1755 xFilterFactory->getByName( aFilterName ) >>= aFilterData;
1757 for (
const auto& rProp : std::as_const(aFilterData) )
1758 if ( rProp.Name ==
"Type" )
1759 rProp.Value >>= aTypeName;
1761 if ( aTypeName.isEmpty() )
1762 throw uno::RuntimeException();
1765 uno::Reference< container::XNameAccess > xTypeDetection =
1767 uno::Reference< container::XNameAccess >( mxType, uno::UNO_QUERY_THROW ) :
1769 mxContext->getServiceManager()->createInstanceWithContext(
"com.sun.star.document.TypeDetection",
mxContext),
1770 uno::UNO_QUERY_THROW );
1772 SequenceAsHashMap aTypeProps( xTypeDetection->getByName( aTypeName ) );
1773 uno::Sequence< OUString > aAllExt =
1774 aTypeProps.getUnpackedValueOrDefault(
"Extensions", Sequence< OUString >() );
1775 if ( !aAllExt.hasElements() )
1776 throw uno::RuntimeException();
1778 const OUString aMediaType {aTypeProps.getUnpackedValueOrDefault(
"MediaType", OUString() )};
1779 const OUString aExt {aAllExt[0]};
1781 if ( aMediaType.isEmpty() || aExt.isEmpty() )
1782 throw uno::RuntimeException();
1785 if ( aGroupTargetURL.isEmpty() )
1787 aGroupTargetURL = CreateNewGroupFsys( rGroupName, aGroup );
1789 if ( aGroupTargetURL.isEmpty() )
1790 throw uno::RuntimeException();
1793 OUString aNewTemplateTargetURL = CreateNewUniqueFileWithPrefix( aGroupTargetURL, rTemplateName, aExt );
1794 if ( aNewTemplateTargetURL.isEmpty() )
1796 aNewTemplateTargetURL = CreateNewUniqueFileWithPrefix( aGroupTargetURL,
"UserTemplate", aExt );
1798 if ( aNewTemplateTargetURL.isEmpty() )
1799 throw uno::RuntimeException();
1803 uno::Sequence< PropertyValue > aStoreArgs{
1808 if( !::utl::UCBContentHelper::EqualURLs( aNewTemplateTargetURL, rStorable->getLocation() ))
1809 rStorable->storeToURL( aNewTemplateTargetURL, aStoreArgs );
1814 if ( !aTemplateToRemoveTargetURL.isEmpty() )
1816 removeContent( aTemplateToRemoveTargetURL );
1830 if ( bRemoveOldTemplateContent )
1831 removeContent( aTemplateToRemove );
1834 return addEntry( aGroup, rTemplateName, aNewTemplateTargetURL, aMediaType );
1844sal_Bool SfxDocTplService::addTemplate(
const OUString& rGroupName,
1845 const OUString& rTemplateName,
1846 const OUString& rSourceURL )
1851 ::osl::MutexGuard aGuard( maMutex );
1855 Content aGroup, aTemplate, aTargetGroup;
1858 aGroupObj.insertName( rGroupName,
false,
1868 aGroupObj.insertName( rTemplateName,
false,
1885 aTargetURL = CreateNewGroupFsys( rGroupName, aGroup );
1892 OUString aTitle, aType;
1894 bool bDocHasTitle =
false;
1895 getTitleFromURL( rSourceURL, aTitle, aType, bDocHasTitle );
1898 if ( rTemplateName == aTitle )
1907 aTargetObj.insertName( rTemplateName,
false,
1910 aTargetObj.setExtension( aSourceObj.getExtension() );
1914 if ( aTargetURL2 == rSourceURL )
1915 return addEntry( aGroup, rTemplateName, aTargetURL2, aType );
1921 aTmpURL.CutExtension();
1924 const OUString aNewTemplateTargetURL {CreateNewUniqueFileWithPrefix( aTargetURL, aPattern, aSourceObj.getExtension() )};
1925 INetURLObject aNewTemplateTargetObj( aNewTemplateTargetURL );
1927 if ( aNewTemplateTargetURL.isEmpty() || aNewTemplateTargetName.isEmpty() )
1932 uno::Reference < ucb::XCommandEnvironment > xEnv;
1943 aTargetGroup.transferContent( aSourceContent,
1944 InsertOperation::Copy,
1945 aNewTemplateTargetName,
1946 NameClash::OVERWRITE,
1953 static constexpr OUStringLiteral aPropertyName( u
"IsReadOnly" );
1956 if (
getProperty( aResultContent, aPropertyName, aProperty ) && ( aProperty >>= bReadOnly ) && bReadOnly )
1957 setProperty( aResultContent, aPropertyName,
uno::Any(
false ) );
1960 catch ( ContentCreationException& )
1962 catch ( Exception& )
1967 bool bCorrectTitle = ( bDocHasTitle && aTitle == rTemplateName );
1968 if ( !bCorrectTitle )
1970 if ( !bDocHasTitle )
1973 aNewTmpObj.CutExtension();
1977 if ( !bCorrectTitle )
1978 bCorrectTitle = setTitleForURL( aNewTemplateTargetURL, rTemplateName );
1981 if ( bCorrectTitle )
1984 return addEntry( aGroup, rTemplateName, aNewTemplateTargetURL, aType );
1989 addEntry( aGroup, aTitle, aNewTemplateTargetURL, aType );
1993bool SfxDocTplService::isInternalTemplateDir(
const OUString& rURL)
const
1995 return std::any_of(maInternalTemplateDirs.begin(), maInternalTemplateDirs.end(),
1996 [&rURL](
const OUString& rDir) { return ::utl::UCBContentHelper::IsSubPath(rDir, rURL); });
1999OUString SfxDocTplService::findParentTemplateDir(
const OUString& rURL)
const
2001 const OUString* pDirs = std::find_if(maTemplateDirs.begin(), maTemplateDirs.end(),
2002 [&rURL](
const OUString& rDir) { return ::utl::UCBContentHelper::IsSubPath(rDir, rURL); });
2003 if (pDirs != maTemplateDirs.end())
2008sal_Bool SfxDocTplService::removeTemplate(
const OUString& rGroupName,
2009 const OUString& rTemplateName )
2013 ::osl::MutexGuard aGuard( maMutex );
2020 aGroupObj.insertName( rGroupName,
false,
2030 aGroupObj.insertName( rTemplateName,
false,
2048 if (isInternalTemplateDir(aTargetURL))
2051 removeContent( aTargetURL );
2055 return removeContent( aTemplate );
2059sal_Bool SfxDocTplService::renameTemplate(
const OUString& rGroupName,
2060 const OUString& rOldName,
2061 const OUString& rNewName )
2063 if ( rOldName == rNewName )
2068 ::osl::MutexGuard aGuard( maMutex );
2075 aGroupObj.insertName( rGroupName,
false,
2085 aGroupObj.insertName( rNewName,
false,
2095 aGroupObj.removeSegment();
2096 aGroupObj.insertName( rOldName,
false,
2104 OUString aTemplateTargetURL;
2108 aTargetValue >>= aTemplateTargetURL;
2110 if ( !setTitleForURL( aTemplateTargetURL, rNewName ) )
2115 aTitleValue <<= rNewName;
2117 return setProperty( aTemplate,
TITLE, aTitleValue );
2124uno::Reference< ucb::XContent > SAL_CALL SfxDocTplService::getContent()
2127 return maRootContent.get();
2136 maRect = GetTextRect(aRect, maText, gnTextStyle);
2141 SetOutputSizePixel(aRect.GetSize());
2145 GetOutDev()->Flush();
2149WaitWindow_Impl::~WaitWindow_Impl()
2154void WaitWindow_Impl::dispose()
2163 rRenderContext.
DrawText(maRect, maText, gnTextStyle);
2166void SfxDocTplService::addHierGroup( GroupList_Impl& rList,
2167 const OUString& rTitle,
2168 const OUString& rOwnURL )
2172 uno::Reference<XResultSet> xResultSet;
2179 catch (ContentCreationException&)
2183 catch (Exception&) {}
2185 if ( !xResultSet.is() )
2188 GroupData_Impl *pGroup =
new GroupData_Impl( rTitle );
2189 pGroup->setHierarchy(
true );
2190 pGroup->setHierarchyURL( rOwnURL );
2191 rList.push_back( std::unique_ptr<GroupData_Impl>(pGroup) );
2193 uno::Reference< XContentAccess > xContentAccess( xResultSet, UNO_QUERY );
2194 uno::Reference< XRow > xRow( xResultSet, UNO_QUERY );
2198 while ( xResultSet->next() )
2200 bool bUpdateType =
false;
2201 DocTemplates_EntryData_Impl *
pData;
2203 const OUString aTitle( xRow->getString( 1 ) );
2204 const OUString aTargetDir( xRow->getString( 2 ) );
2205 OUString aType( xRow->getString( 3 ) );
2206 const OUString aHierURL {xContentAccess->queryContentIdentifierString()};
2208 if ( aType.isEmpty() )
2212 bool bDocHasTitle =
false;
2213 getTitleFromURL( aTargetDir, aTmpTitle, aType, bDocHasTitle );
2215 if ( !aType.isEmpty() )
2219 pData = pGroup->addEntry( aTitle, aTargetDir, aType, aHierURL );
2220 pData->setUpdateType( bUpdateType );
2223 catch ( Exception& ) {}
2227void SfxDocTplService::addFsysGroup( GroupList_Impl& rList,
2228 const OUString& rTitle,
2229 const OUString& rUITitle,
2230 const OUString& rOwnURL,
2231 bool bWriteableGroup )
2235 if ( rUITitle.isEmpty() )
2238 if ( rTitle ==
"wizard" )
2240 else if ( rTitle ==
"internal" )
2243 aTitle = getLongName( rTitle );
2248 if ( aTitle.isEmpty() )
2251 GroupData_Impl* pGroup =
nullptr;
2252 for (
const std::unique_ptr<GroupData_Impl>& i : rList)
2254 if (
i->getTitle() == aTitle )
2263 pGroup =
new GroupData_Impl( aTitle );
2264 rList.push_back( std::unique_ptr<GroupData_Impl>(pGroup) );
2267 if ( bWriteableGroup )
2268 pGroup->setTargetURL( rOwnURL );
2274 uno::Reference< XResultSet > xResultSet;
2275 Sequence< OUString > aProps {
TITLE };
2281 uno::Reference< XCommandEnvironment > aQuietEnv;
2283 xResultSet = aContent.createCursor( aProps, INCLUDE_DOCUMENTS_ONLY );
2285 catch ( Exception& ) {}
2287 if ( !xResultSet.is() )
2290 uno::Reference< XContentAccess > xContentAccess( xResultSet, UNO_QUERY );
2291 uno::Reference< XRow > xRow( xResultSet, UNO_QUERY );
2295 while ( xResultSet->next() )
2297 OUString aChildTitle( xRow->getString( 1 ) );
2298 const OUString
aTargetURL {xContentAccess->queryContentIdentifierString()};
2301 if ( aChildTitle ==
"sfx.tlx" || aChildTitle ==
"groupuinames.xml" )
2304 bool bDocHasTitle =
false;
2305 getTitleFromURL( aTargetURL, aChildTitle, aType, bDocHasTitle );
2307 pGroup->addEntry( aChildTitle, aTargetURL, aType, OUString() );
2310 catch ( Exception& ) {}
2314void SfxDocTplService::createFromContent( GroupList_Impl& rList,
2317 bool bWriteableContent )
2319 const OUString
aTargetURL {rContent.get()->getIdentifier()->getContentIdentifier()};
2325 addFsysGroup( rList, OUString(), aUIStdTitle, aTargetURL, bWriteableContent );
2332 std::vector< beans::StringPair > aUINames;
2336 uno::Reference< XResultSet > xResultSet;
2337 Sequence< OUString > aProps {
TITLE };
2341 xResultSet = rContent.createCursor( aProps, INCLUDE_FOLDERS_ONLY );
2343 catch ( Exception& ) {}
2345 if ( !xResultSet.is() )
2348 uno::Reference< XContentAccess > xContentAccess( xResultSet, UNO_QUERY );
2349 uno::Reference< XRow > xRow( xResultSet, UNO_QUERY );
2353 while ( xResultSet->next() )
2356 const OUString aTitle( xRow->getString( 1 ) );
2357 const OUString aTargetSubfolderURL( xContentAccess->queryContentIdentifierString() );
2360 addHierGroup( rList, aTitle, aTargetSubfolderURL );
2364 for (
const beans::StringPair & rUIName : aUINames)
2365 if ( rUIName.First == aTitle )
2367 aUITitle = rUIName.Second;
2371 addFsysGroup( rList, aTitle, aUITitle, aTargetSubfolderURL, bWriteableContent );
2375 catch ( Exception& ) {}
2379void SfxDocTplService::removeFromHierarchy( DocTemplates_EntryData_Impl
const *pData )
2385 removeContent( aTemplate );
2390void SfxDocTplService::addToHierarchy( GroupData_Impl
const *pGroup,
2391 DocTemplates_EntryData_Impl
const *pData )
2402 aGroupObj.insertName(
pData->getTitle(),
false,
2411 addEntry( aGroup,
pData->getTitle(),
2412 pData->getTargetURL(),
2417void SfxDocTplService::updateData( DocTemplates_EntryData_Impl
const *pData )
2424 if (
pData->getUpdateType() )
2429 if (
pData->getUpdateLink() )
2436void SfxDocTplService::addGroupToHierarchy( GroupData_Impl *pGroup )
2441 aNewGroupObj.insertName( pGroup->getTitle(),
false,
2447 if ( createFolder( aNewGroupURL,
false,
false, aGroup ) )
2450 pGroup->setHierarchyURL( aNewGroupURL );
2452 size_t nCount = pGroup->count();
2453 for (
size_t i = 0;
i <
nCount;
i++ )
2455 DocTemplates_EntryData_Impl *
pData = pGroup->getEntry( i );
2456 addToHierarchy( pGroup, pData );
2462void SfxDocTplService::removeFromHierarchy( GroupData_Impl
const *pGroup )
2468 removeContent( aGroup );
2473GroupData_Impl::GroupData_Impl( OUString aTitle )
2474 :
maTitle(
std::move(aTitle)), mbInUse(false), mbInHierarchy(false)
2479DocTemplates_EntryData_Impl* GroupData_Impl::addEntry(
const OUString& rTitle,
2480 const OUString& rTargetURL,
2481 const OUString& rType,
2482 const OUString& rHierURL )
2484 DocTemplates_EntryData_Impl*
pData =
nullptr;
2485 bool EntryFound =
false;
2487 for (
auto const & p : maEntries)
2490 if (
pData->getTitle() == rTitle )
2499 pData =
new DocTemplates_EntryData_Impl( rTitle );
2500 pData->setTargetURL( rTargetURL );
2501 pData->setType( rType );
2502 if ( !rHierURL.isEmpty() )
2504 pData->setHierarchyURL( rHierURL );
2505 pData->setHierarchy(
true );
2507 maEntries.emplace_back( pData );
2511 if ( !rHierURL.isEmpty() )
2513 pData->setHierarchyURL( rHierURL );
2514 pData->setHierarchy(
true );
2517 if (
pData->getInHierarchy() )
2520 if ( rTargetURL !=
pData->getTargetURL() )
2522 pData->setTargetURL( rTargetURL );
2523 pData->setUpdateLink(
true );
2531DocTemplates_EntryData_Impl::DocTemplates_EntryData_Impl( OUString aTitle )
2532 :
maTitle(
std::move(aTitle)), mbInHierarchy(false), mbInUse(false), mbUpdateType(false), mbUpdateLink(false)
2540 std::u16string_view rPropName )
2565 std::scoped_lock aGuard(
maMutex );
2568 OSL_ENSURE(
mxContext.is(),
"No service manager!" );
2579 if ( aParser.
GetProtocol() != INetProtocol::VndSunStarExpand )
2600 if ( !rURL.isEmpty() )
2611 if ( !rURL.isEmpty() )
2619extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface *
2621 css::uno::XComponentContext *context,
2622 css::uno::Sequence<css::uno::Any>
const &)
2624 return cppu::acquire(
new SfxDocTplService(context));
2629 return SfxResId(TEMPLATE_LONG_NAMES_ARY[0]);
2634 std::vector<OUString> aGroups;
2635 for(
auto const & aGroupName : TEMPLATE_LONG_NAMES_ARY)
2636 aGroups.push_back(
SfxResId(aGroupName));
static std::vector< css::beans::StringPair > ReadGroupLocalizationSequence(const css::uno::Reference< css::io::XInputStream > &xInStream, const css::uno::Reference< css::uno::XComponentContext > &xContext)
static std::vector< OUString > GetBuiltInGroupNames()
static void WriteGroupLocalizationSequence(const css::uno::Reference< css::io::XOutputStream > &xOutStream, const std::vector< css::beans::StringPair > &aSequence, const css::uno::Reference< css::uno::XComponentContext > &xContext)
static OUString GetStandardGroupString()
OUString GetURLPath(DecodeMechanism eMechanism=DecodeMechanism::ToIUri, rtl_TextEncoding eCharset=RTL_TEXTENCODING_UTF8) const
INetProtocol GetProtocol() const
static css::lang::Locale convertToLocale(LanguageType nLangID, bool bResolveSystem=true)
static OUString convertToBcp47(LanguageType nLangID)
void DrawText(const Point &rStartPt, const OUString &rStr, sal_Int32 nIndex=0, sal_Int32 nLen=-1, std::vector< tools::Rectangle > *pVector=nullptr, OUString *pDisplayText=nullptr, const SalLayoutGlyphs *pLayoutCache=nullptr)
static void SetStandardTemplate(const OUString &rServiceName, const OUString &rTemplateName)
static OUString GetStandardTemplate(std::u16string_view rServiceName)
void implExpandURL(OUString &io_url)
void makeAbsoluteURL(OUString &rURL)
SfxURLRelocator_Impl(css::uno::Reference< css::uno::XComponentContext > xContext)
css::uno::Reference< css::util::XMacroExpander > mxMacroExpander
static bool propertyCanContainOfficeDir(std::u16string_view rPropName)
void initOfficeInstDirs()
css::uno::Reference< css::uno::XComponentContext > mxContext
css::uno::Reference< css::util::XOfficeInstallationDirectories > mxOfficeInstDirs
void makeRelocatableURL(OUString &rURL)
const OUString & GetTemplatePath() const
virtual void dispose() override
static css::uno::Reference< css::embed::XStorage > GetStorageFromURL(const OUString &aURL, sal_Int32 nStorageMode, const css::uno::Reference< css::uno::XComponentContext > &rxContext=css::uno::Reference< css::uno::XComponentContext >())
static OUString getUILocale()
virtual void Paint(vcl::RenderContext &rRenderContext, const tools::Rectangle &rRect)
Reference< XInteractionHandler2 > m_xInteractionHandler
#define TOOLS_WARN_EXCEPTION(area, stream)
#define DBG_UNHANDLED_EXCEPTION(...)
constexpr OUStringLiteral PROPERTY_DIRLIST
constexpr OUStringLiteral TEMPLATE_VERSION
constexpr OUStringLiteral PROPERTY_TYPE
SAL_DLLPUBLIC_EXPORT css::uno::XInterface * com_sun_star_comp_sfx2_DocumentTemplates_get_implementation(css::uno::XComponentContext *context, css::uno::Sequence< css::uno::Any > const &)
constexpr OUStringLiteral TEMPLATE_ROOT_URL
constexpr OUStringLiteral IS_DOCUMENT
constexpr OUStringLiteral TITLE
constexpr OUStringLiteral TYPE_FSYS_FILE
constexpr OUStringLiteral TYPE_FSYS_FOLDER
constexpr OUStringLiteral TEMPLATE_VERSION_VALUE
constexpr OUStringLiteral PROPERTY_NEEDSUPDATE
constexpr OUStringLiteral IS_FOLDER
constexpr OUStringLiteral TARGET_DIR_URL
constexpr OUStringLiteral TYPE_FOLDER
constexpr OUStringLiteral TYPE_LINK
constexpr OUStringLiteral SERVICENAME_TYPEDETECTION
constexpr OUStringLiteral STANDARD_FOLDER
constexpr OUStringLiteral COMMAND_DELETE
constexpr OUStringLiteral TARGET_URL
Sequence< sal_Int8 > aSeq
#define SAL_WARN(area, stream)
#define SAL_N_ELEMENTS(arr)
std::unique_ptr< sal_Int32[]> pData
const LanguageTag & getLocale()
void setLocale(const LanguageTag &languageTag)
sal_Int32 getTokenCount(std::string_view rIn, char cTok)
css::uno::Sequence< css::uno::Any > InitAnyPropertySequence(::std::initializer_list< ::std::pair< OUString, css::uno::Any > > vInit)
Reference< XComponentContext > getProcessComponentContext()
css::uno::Sequence< css::beans::PropertyValue > InitPropertySequence(::std::initializer_list< ::std::pair< OUString, css::uno::Any > > vInit)
css::beans::PropertyValue makePropertyValue(const OUString &rName, T &&rValue)
css::uno::Sequence< OUString > getSupportedServiceNames()
OUString getImplementationName()
bool CPPUHELPER_DLLPUBLIC supportsService(css::lang::XServiceInfo *implementation, rtl::OUString const &name)
std::u16string_view getTitle(std::u16string_view aPath)
std::basic_string_view< charT, traits > getToken(std::basic_string_view< charT, traits > sv, charT delimiter, std::size_t &position)
static void init(struct DocumentMetadataAccess_Impl &i_rImpl)
init Impl struct
SVX_DLLPUBLIC OUString getProperty(css::uno::Reference< css::beans::XPropertyContainer > const &rxPropertyContainer, OUString const &rName)
bool getType(BSTR name, Type &type)
OUString SfxResId(TranslateId aId)