1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <sal/config.h>
28 #include <com/sun/star/beans/Optional.hpp>
29 #include <com/sun/star/beans/UnknownPropertyException.hpp>
30 #include <com/sun/star/beans/XPropertySet.hpp>
31 #include <com/sun/star/container/NoSuchElementException.hpp>
32 #include <com/sun/star/lang/WrappedTargetException.hpp>
33 #include <com/sun/star/lang/WrappedTargetRuntimeException.hpp>
34 #include <com/sun/star/uno/Any.hxx>
35 #include <com/sun/star/uno/Exception.hpp>
36 #include <com/sun/star/uno/Reference.hxx>
37 #include <com/sun/star/uno/RuntimeException.hpp>
38 #include <com/sun/star/uno/XComponentContext.hpp>
39 #include <com/sun/star/uno/XInterface.hpp>
40 #include <cppuhelper/exc_hlp.hxx>
41 #include <config_dconf.h>
42 #include <config_folders.h>
43 #include <osl/conditn.hxx>
44 #include <osl/file.hxx>
45 #include <osl/mutex.hxx>
46 #include <rtl/bootstrap.hxx>
47 #include <rtl/ref.hxx>
48 #include <rtl/ustrbuf.hxx>
49 #include <rtl/ustring.hxx>
50 #include <sal/log.hxx>
51 #include <sal/types.h>
52 #include <salhelper/thread.hxx>
53 #include <comphelper/diagnose_ex.hxx>
54 #include <comphelper/backupfilehelper.hxx>
55 #include <o3tl/string_view.hxx>
57 #include "additions.hxx"
58 #include "components.hxx"
61 #include "modifications.hxx"
63 #include "nodemap.hxx"
64 #include "parsemanager.hxx"
65 #include "partial.hxx"
66 #include "rootaccess.hxx"
67 #include "writemodfile.hxx"
68 #include "xcdparser.hxx"
69 #include "xcuparser.hxx"
70 #include "xcsparser.hxx"
84 struct UnresolvedVectorItem
{
86 rtl::Reference
< ParseManager
> manager
;
90 rtl::Reference
< ParseManager
> theManager
):
91 name(std::move(theName
)), manager(std::move(theManager
)) {}
94 typedef std::vector
< UnresolvedVectorItem
> UnresolvedVector
;
97 OUString
const & url
, int layer
, Data
& data
, Partial
const * partial
,
98 Modifications
* modifications
, Additions
* additions
)
100 assert(partial
== nullptr && modifications
== nullptr && additions
== nullptr);
101 (void) partial
; (void) modifications
; (void) additions
;
102 bool ok
= rtl::Reference
< ParseManager
>(
103 new ParseManager(url
, new XcsParser(layer
, data
)))->parse(nullptr);
105 (void) ok
; // avoid warnings
109 OUString
const & url
, int layer
, Data
& data
, Partial
const * partial
,
110 Modifications
* modifications
, Additions
* additions
)
112 bool ok
= rtl::Reference
< ParseManager
>(
115 new XcuParser(layer
, data
, partial
, modifications
, additions
)))->
118 (void) ok
; // avoid warnings
121 OUString
expand(OUString
const & str
) {
123 rtl::Bootstrap::expandMacros(s
); //TODO: detect failure
127 bool canRemoveFromLayer(int layer
, rtl::Reference
< Node
> const & node
) {
129 if (node
->getLayer() > layer
&& node
->getLayer() < Data::NO_LAYER
) {
132 switch (node
->kind()) {
133 case Node::KIND_LOCALIZED_PROPERTY
:
134 case Node::KIND_GROUP
:
135 for (auto const& member
: node
->getMembers())
137 if (!canRemoveFromLayer(layer
, member
.second
)) {
143 return node
->getMembers().empty();
144 default: // Node::KIND_PROPERTY, Node::KIND_LOCALIZED_VALUE
151 class Components::WriteThread
: public salhelper::Thread
{
154 rtl::Reference
< WriteThread
> * reference
, Components
& components
,
155 OUString url
, Data
const & data
);
157 void flush() { delay_
.set(); }
160 virtual ~WriteThread() override
{}
162 virtual void execute() override
;
164 rtl::Reference
< WriteThread
> * reference_
;
165 Components
& components_
;
168 osl::Condition delay_
;
169 std::shared_ptr
<osl::Mutex
> lock_
;
172 Components::WriteThread::WriteThread(
173 rtl::Reference
< WriteThread
> * reference
, Components
& components
,
174 OUString url
, Data
const & data
):
175 Thread("configmgrWriter"), reference_(reference
), components_(components
),
176 url_(std::move(url
)), data_(data
),
179 assert(reference
!= nullptr);
182 void Components::WriteThread::execute() {
183 delay_
.wait(std::chrono::seconds(1)); // must not throw; result_error is harmless and ignored
184 osl::MutexGuard
g(*lock_
); // must not throw
187 writeModFile(components_
, url_
, data_
);
188 } catch (css::uno::RuntimeException
&) {
189 // Ignore write errors, instead of aborting:
190 TOOLS_WARN_EXCEPTION("configmgr", "error writing modifications");
199 Components
& Components::getSingleton(
200 css::uno::Reference
< css::uno::XComponentContext
> const & context
)
202 assert(context
.is());
203 static Components
singleton(context
);
207 bool Components::allLocales(std::u16string_view locale
) {
208 return locale
== u
"*";
211 rtl::Reference
< Node
> Components::resolvePathRepresentation(
212 OUString
const & pathRepresentation
,
213 OUString
* canonicRepresentation
, std::vector
<OUString
> * path
, int * finalizedLayer
)
216 return data_
.resolvePathRepresentation(
217 pathRepresentation
, canonicRepresentation
, path
, finalizedLayer
);
220 rtl::Reference
< Node
> Components::getTemplate(OUString
const & fullName
) const
222 return data_
.getTemplate(Data::NO_LAYER
, fullName
);
225 void Components::addRootAccess(rtl::Reference
< RootAccess
> const & access
) {
226 roots_
.insert(access
.get());
229 void Components::removeRootAccess(RootAccess
* access
) {
230 roots_
.erase(access
);
233 void Components::initGlobalBroadcaster(
234 Modifications
const & modifications
,
235 rtl::Reference
< RootAccess
> const & exclude
, Broadcaster
* broadcaster
)
237 //TODO: Iterate only over roots w/ listeners:
238 for (auto const& elemRoot
: roots_
)
240 rtl::Reference
< RootAccess
> root
;
241 if (elemRoot
->acquireCounting() > 1) {
242 root
.set(elemRoot
); // must not throw
244 elemRoot
->releaseNondeleting();
246 if (root
!= exclude
) {
247 std::vector
<OUString
> path(root
->getAbsolutePath());
248 Modifications::Node
const * mods
= &modifications
.getRoot();
249 for (auto const& pathElem
: path
)
251 Modifications::Node::Children::const_iterator
k(
252 mods
->children
.find(pathElem
));
253 if (k
== mods
->children
.end()) {
259 //TODO: If the complete tree of which root is a part is deleted,
260 // or replaced, mods will be null, but some of the listeners
261 // from within root should probably fire nonetheless:
262 if (mods
!= nullptr) {
263 root
->initBroadcaster(*mods
, broadcaster
);
270 void Components::addModification(std::vector
<OUString
> const & path
) {
271 data_
.modifications
.add(path
);
274 void Components::writeModifications() {
276 if (data_
.modifications
.empty())
279 switch (modificationTarget_
) {
280 case ModificationTarget::None
:
282 case ModificationTarget::File
:
283 if (!writeThread_
.is()) {
284 writeThread_
= new WriteThread(
285 &writeThread_
, *this, modificationFileUrl_
, data_
);
286 writeThread_
->launch();
289 case ModificationTarget::Dconf
:
291 dconf::writeModifications(*this, data_
);
297 void Components::flushModifications() {
298 rtl::Reference
< WriteThread
> thread
;
300 osl::MutexGuard
g(*lock_
);
301 thread
= writeThread_
;
309 void Components::insertExtensionXcsFile(
310 bool shared
, OUString
const & fileUri
)
312 int layer
= getExtensionLayer(shared
);
314 parseXcsFile(fileUri
, layer
, data_
, nullptr, nullptr, nullptr);
315 } catch (css::container::NoSuchElementException
& e
) {
316 throw css::uno::RuntimeException(
317 "insertExtensionXcsFile does not exist: " + e
.Message
);
321 void Components::insertExtensionXcuFile(
322 bool shared
, OUString
const & fileUri
, Modifications
* modifications
)
324 assert(modifications
!= nullptr);
325 int layer
= getExtensionLayer(shared
) + 1;
326 Additions
* adds
= data_
.addExtensionXcuAdditions(fileUri
, layer
);
328 parseXcuFile(fileUri
, layer
, data_
, nullptr, modifications
, adds
);
329 } catch (css::container::NoSuchElementException
& e
) {
330 data_
.removeExtensionXcuAdditions(fileUri
);
331 throw css::uno::RuntimeException(
332 "insertExtensionXcuFile does not exist: " + e
.Message
);
336 void Components::removeExtensionXcuFile(
337 OUString
const & fileUri
, Modifications
* modifications
)
339 //TODO: Ideally, exactly the data coming from the specified xcu file would
340 // be removed. However, not enough information is recorded in the in-memory
341 // data structures to do so. So, as a workaround, all those set elements
342 // that were freshly added by the xcu and have afterwards been left
343 // unchanged or have only had their properties changed in the user layer are
344 // removed (and nothing else). The heuristic to determine
345 // whether a node has been left unchanged is to check the layer ID (as
346 // usual) and additionally to check that the node does not recursively
347 // contain any non-empty sets (multiple extension xcu files are merged into
348 // one layer, so checking layer ID alone is not enough). Since
349 // item->additions records all additions of set members in textual order,
350 // the latter check works well when iterating through item->additions in
352 assert(modifications
!= nullptr);
353 rtl::Reference
< Data::ExtensionXcu
> item(
354 data_
.removeExtensionXcuAdditions(fileUri
));
358 for (Additions::reverse_iterator
i(item
->additions
.rbegin());
359 i
!= item
->additions
.rend(); ++i
)
361 rtl::Reference
< Node
> parent
;
362 NodeMap
const * map
= &data_
.getComponents();
363 rtl::Reference
< Node
> node
;
364 for (auto const& j
: *i
)
367 node
= map
->findNode(Data::NO_LAYER
, j
);
371 map
= &node
->getMembers();
375 if (parent
->kind() == Node::KIND_SET
) {
377 node
->kind() == Node::KIND_GROUP
||
378 node
->kind() == Node::KIND_SET
);
379 if (canRemoveFromLayer(item
->layer
, node
)) {
380 parent
->getMembers().erase(i
->back());
381 data_
.modifications
.remove(*i
);
382 modifications
->add(*i
);
387 writeModifications();
390 void Components::insertModificationXcuFile(
391 OUString
const & fileUri
,
392 std::set
< OUString
> const & includedPaths
,
393 std::set
< OUString
> const & excludedPaths
,
394 Modifications
* modifications
)
396 assert(modifications
!= nullptr);
397 Partial
part(includedPaths
, excludedPaths
);
400 &parseXcuFile
, fileUri
, Data::NO_LAYER
, &part
, modifications
, nullptr);
401 } catch (const css::container::NoSuchElementException
&) {
402 TOOLS_WARN_EXCEPTION(
404 "error inserting non-existing \"" << fileUri
<< "\"");
408 css::beans::Optional
< css::uno::Any
> Components::getExternalValue(
409 std::u16string_view descriptor
)
411 size_t i
= descriptor
.find(' ');
412 if (i
== 0 || i
== std::u16string_view::npos
) {
413 throw css::uno::RuntimeException(
414 OUString::Concat("bad external value descriptor ") + descriptor
);
416 //TODO: Do not make calls with mutex locked:
417 OUString
name(descriptor
.substr(0, i
));
418 ExternalServices::iterator
j(externalServices_
.find(name
));
419 if (j
== externalServices_
.end()) {
420 css::uno::Reference
< css::uno::XInterface
> service
;
422 service
= context_
->getServiceManager()->createInstanceWithContext(
424 } catch (const css::uno::RuntimeException
&) {
425 // Assuming these exceptions are real errors:
427 } catch (const css::uno::Exception
&) {
428 // Assuming these exceptions indicate that the service is not
430 TOOLS_WARN_EXCEPTION(
432 "createInstance(" << name
<< ") failed");
434 css::uno::Reference
< css::beans::XPropertySet
> propset
;
436 propset
.set( service
, css::uno::UNO_QUERY_THROW
);
438 j
= externalServices_
.emplace(name
, propset
).first
;
440 css::beans::Optional
< css::uno::Any
> value
;
441 if (j
->second
.is()) {
443 if (!(j
->second
->getPropertyValue(OUString(descriptor
.substr(i
+ 1))) >>=
446 throw css::uno::RuntimeException(
447 OUString::Concat("cannot obtain external value through ") + descriptor
);
449 } catch (css::beans::UnknownPropertyException
& e
) {
450 throw css::uno::RuntimeException(
451 "unknown external value descriptor ID: " + e
.Message
);
452 } catch (css::lang::WrappedTargetException
& e
) {
453 css::uno::Any anyEx
= cppu::getCaughtException();
454 throw css::lang::WrappedTargetRuntimeException(
455 "cannot obtain external value: " + e
.Message
,
462 Components::Components(
463 css::uno::Reference
< css::uno::XComponentContext
> const & context
):
464 context_(context
), sharedExtensionLayer_(-1), userExtensionLayer_(-1),
465 modificationTarget_(ModificationTarget::None
)
467 assert(context
.is());
469 OUString
conf(expand("${CONFIGURATION_LAYERS}"));
471 for (sal_Int32 i
= 0;;) {
472 while (i
!= conf
.getLength() && conf
[i
] == ' ') {
475 if (i
== conf
.getLength()) {
478 if (modificationTarget_
!= ModificationTarget::None
) {
479 throw css::uno::RuntimeException(
480 "CONFIGURATION_LAYERS: modification target layer followed by"
485 if (c
== conf
.getLength() || conf
[c
] == ' ') {
486 throw css::uno::RuntimeException(
487 "CONFIGURATION_LAYERS: missing ':' in \"" + conf
+ "\"");
489 if (conf
[c
] == ':') {
493 sal_Int32 n
= conf
.indexOf(' ', c
+ 1);
495 n
= conf
.getLength();
497 OUString
type(conf
.copy(i
, c
- i
));
498 OUString
url(conf
.copy(c
+ 1, n
- c
- 1));
499 if (type
== "xcsxcu") {
500 sal_uInt32 nStartTime
= osl_getGlobalTimer();
501 parseXcsXcuLayer(layer
, url
);
502 SAL_INFO("configmgr", "parseXcsXcuLayer() took " << (osl_getGlobalTimer() - nStartTime
) << " ms");
503 layer
+= 2; //TODO: overflow
504 } else if (type
== "bundledext") {
505 parseXcsXcuIniLayer(layer
, url
, false);
506 layer
+= 2; //TODO: overflow
507 } else if (type
== "sharedext") {
508 if (sharedExtensionLayer_
!= -1) {
509 throw css::uno::RuntimeException(
510 "CONFIGURATION_LAYERS: multiple \"sharedext\" layers");
512 sharedExtensionLayer_
= layer
;
513 parseXcsXcuIniLayer(layer
, url
, true);
514 layer
+= 2; //TODO: overflow
515 } else if (type
== "userext") {
516 if (userExtensionLayer_
!= -1) {
517 throw css::uno::RuntimeException(
518 "CONFIGURATION_LAYERS: multiple \"userext\" layers");
520 userExtensionLayer_
= layer
;
521 parseXcsXcuIniLayer(layer
, url
, true);
522 layer
+= 2; //TODO: overflow
523 } else if (type
== "res") {
524 sal_uInt32 nStartTime
= osl_getGlobalTimer();
525 parseResLayer(layer
, url
);
526 SAL_INFO("configmgr", "parseResLayer() took " << (osl_getGlobalTimer() - nStartTime
) << " ms");
527 ++layer
; //TODO: overflow
529 } else if (type
== "dconf") {
531 modificationTarget_
= ModificationTarget::Dconf
;
532 dconf::readLayer(data_
, Data::NO_LAYER
);
533 } else if (url
== "*") {
534 dconf::readLayer(data_
, layer
);
536 throw css::uno::RuntimeException(
537 "CONFIGURATION_LAYERS: unknown \"dconf\" kind \"" + url
540 ++layer
; //TODO: overflow
543 } else if (type
== "winreg") {
545 if (url
== "LOCAL_MACHINE" || url
.isEmpty()/*backwards comp.*/) {
546 eType
= WinRegType::LOCAL_MACHINE
;
547 } else if (url
== "CURRENT_USER") {
548 eType
= WinRegType::CURRENT_USER
;
550 throw css::uno::RuntimeException(
551 "CONFIGURATION_LAYERS: unknown \"winreg\" kind \"" + url
554 OUString aTempFileURL
;
555 if (dumpWindowsRegistry(&aTempFileURL
, eType
)) {
556 parseFileLeniently(&parseXcuFile
, aTempFileURL
, layer
, nullptr, nullptr, nullptr);
557 if (!getenv("SAL_CONFIG_WINREG_RETAIN_TMP"))
558 osl::File::remove(aTempFileURL
);
560 ++layer
; //TODO: overflow
562 } else if (type
== "user") {
564 if (url
.startsWith("!", &url
)) {
566 } else if (url
.startsWith("*", &url
)) {
569 write
= true; // for backwards compatibility
572 throw css::uno::RuntimeException(
573 "CONFIGURATION_LAYERS: empty \"user\" URL");
579 expand("${SYSUSERCONFIG}/libreoffice/dconfwrite"));
580 osl::DirectoryItem it
;
581 osl::FileBase::RC e
= osl::DirectoryItem::get(token
, it
);
582 ignore
= e
== osl::FileBase::E_None
;
585 "dconf write (<" << token
<< "> " << +e
<< "): "
588 modificationTarget_
= ModificationTarget::Dconf
;
594 modificationTarget_
= ModificationTarget::File
;
595 modificationFileUrl_
= url
;
597 parseModificationLayer(write
? Data::NO_LAYER
: layer
, url
);
599 ++layer
; //TODO: overflow
601 throw css::uno::RuntimeException(
602 "CONFIGURATION_LAYERS: unknown layer type \"" + type
+ "\"");
608 Components::~Components()
610 // get flag if _exit was already called which is a sign to not secure user config.
611 // this is used for win only currently where calling _exit() unfortunately still
612 // calls destructors (what is not wanted). May be needed for other systems, too
613 // (unknown yet) but can do no harm
614 const bool bExitWasCalled(comphelper::BackupFileHelper::getExitWasCalled());
617 // we can add a SAL_WARN here for other systems where the destructor gets called after
618 // an _exit() call. Still safe - the getExitWasCalled() is used, but a hint that _exit
619 // behaves different on a system
620 SAL_WARN_IF(bExitWasCalled
, "configmgr", "Components::~Components() called after _exit() call");
625 // do not write, re-join threads
626 osl::MutexGuard
g(*lock_
);
628 if (writeThread_
.is())
630 writeThread_
->join();
636 flushModifications();
639 for (auto const& rootElem
: roots_
)
641 rootElem
->setAlive(false);
645 void Components::parseFileLeniently(
646 FileParser
* parseFile
, OUString
const & url
, int layer
,
647 Partial
const * partial
, Modifications
* modifications
,
648 Additions
* additions
)
650 assert(parseFile
!= nullptr);
652 (*parseFile
)(url
, layer
, data_
, partial
, modifications
, additions
);
653 } catch (const css::container::NoSuchElementException
&) {
655 } catch (const css::uno::Exception
&) { //TODO: more specific exception catching
656 // Ignore invalid XML files, instead of completely preventing OOo from
658 TOOLS_WARN_EXCEPTION(
660 "error reading \"" << url
<< "\"");
664 void Components::parseFiles(
665 int layer
, OUString
const & extension
, FileParser
* parseFile
,
666 OUString
const & url
, bool recursive
)
668 osl::Directory
dir(url
);
669 switch (dir
.open()) {
670 case osl::FileBase::E_None
:
672 case osl::FileBase::E_NOENT
:
678 throw css::uno::RuntimeException(
679 "cannot open directory " + url
);
682 osl::DirectoryItem i
;
683 osl::FileBase::RC rc
= dir
.getNextItem(i
, SAL_MAX_UINT32
);
684 if (rc
== osl::FileBase::E_NOENT
) {
687 if (rc
!= osl::FileBase::E_None
) {
688 throw css::uno::RuntimeException(
689 "cannot iterate directory " + url
);
691 osl::FileStatus
stat(
692 osl_FileStatus_Mask_Type
| osl_FileStatus_Mask_FileName
|
693 osl_FileStatus_Mask_FileURL
);
694 if (i
.getFileStatus(stat
) != osl::FileBase::E_None
) {
695 throw css::uno::RuntimeException(
696 "cannot stat in directory " + url
);
698 if (stat
.getFileType() == osl::FileStatus::Directory
) { //TODO: symlinks
699 parseFiles(layer
, extension
, parseFile
, stat
.getFileURL(), true);
701 OUString
file(stat
.getFileName());
702 if (file
.endsWith(extension
)) {
705 parseFile
, stat
.getFileURL(), layer
, nullptr, nullptr, nullptr);
706 } catch (css::container::NoSuchElementException
& e
) {
707 if (stat
.getFileType() == osl::FileStatus::Link
) {
708 SAL_WARN("configmgr", "dangling link <" << stat
.getFileURL() << ">");
711 throw css::uno::RuntimeException(
712 "stat'ed file does not exist: " + e
.Message
);
719 void Components::parseFileList(
720 int layer
, FileParser
* parseFile
, std::u16string_view urls
,
721 bool recordAdditions
)
723 for (sal_Int32 i
= 0;;) {
724 OUString
url(o3tl::getToken(urls
, 0, ' ', i
));
725 if (!url
.isEmpty()) {
726 Additions
* adds
= nullptr;
727 if (recordAdditions
) {
728 adds
= data_
.addExtensionXcuAdditions(url
, layer
);
731 parseFileLeniently(parseFile
, url
, layer
, nullptr, nullptr, adds
);
732 } catch (const css::container::NoSuchElementException
&) {
733 TOOLS_WARN_EXCEPTION("configmgr", "file does not exist");
734 if (adds
!= nullptr) {
735 data_
.removeExtensionXcuAdditions(url
);
745 void Components::parseXcdFiles(int layer
, OUString
const & url
) {
746 osl::Directory
dir(url
);
747 switch (dir
.open()) {
748 case osl::FileBase::E_None
:
750 case osl::FileBase::E_NOENT
:
753 throw css::uno::RuntimeException(
754 "cannot open directory " + url
);
756 UnresolvedVector unres
;
757 std::set
< OUString
> existingDeps
;
758 std::set
< OUString
> processedDeps
;
760 osl::DirectoryItem i
;
761 osl::FileBase::RC rc
= dir
.getNextItem(i
, SAL_MAX_UINT32
);
762 if (rc
== osl::FileBase::E_NOENT
) {
765 if (rc
!= osl::FileBase::E_None
) {
766 throw css::uno::RuntimeException(
767 "cannot iterate directory " + url
);
769 osl::FileStatus
stat(
770 osl_FileStatus_Mask_Type
| osl_FileStatus_Mask_FileName
|
771 osl_FileStatus_Mask_FileURL
);
772 if (i
.getFileStatus(stat
) != osl::FileBase::E_None
) {
773 throw css::uno::RuntimeException(
774 "cannot stat in directory " + url
);
776 if (stat
.getFileType() != osl::FileStatus::Directory
) { //TODO: symlinks
777 OUString
file(stat
.getFileName());
779 if (file
.endsWith(".xcd", &name
)) {
780 existingDeps
.insert(name
);
781 rtl::Reference
< ParseManager
> manager
;
783 manager
= new ParseManager(
785 new XcdParser(layer
, processedDeps
, data_
));
786 } catch (css::container::NoSuchElementException
& e
) {
787 if (stat
.getFileType() == osl::FileStatus::Link
) {
788 SAL_WARN("configmgr", "dangling link <" << stat
.getFileURL() << ">");
791 throw css::uno::RuntimeException(
792 "stat'ed file does not exist: " + e
.Message
);
794 if (manager
->parse(nullptr)) {
795 processedDeps
.insert(name
);
797 unres
.emplace_back(name
, manager
);
802 while (!unres
.empty()) {
803 bool resolved
= false;
804 for (UnresolvedVector::iterator
i(unres
.begin()); i
!= unres
.end();) {
805 if (i
->manager
->parse(&existingDeps
)) {
806 processedDeps
.insert(i
->name
);
814 throw css::uno::RuntimeException(
815 "xcd: unresolved dependencies in " + url
);
820 void Components::parseXcsXcuLayer(int layer
, OUString
const & url
) {
821 parseXcdFiles(layer
, url
);
822 parseFiles(layer
, ".xcs", &parseXcsFile
, url
+ "/schema", false);
823 parseFiles(layer
+ 1, ".xcu", &parseXcuFile
, url
+ "/data", false);
826 void Components::parseXcsXcuIniLayer(
827 int layer
, OUString
const & url
, bool recordAdditions
)
829 // Check if ini file exists (otherwise .override would still read global
830 // SCHEMA/DATA variables, which could interfere with unrelated environment
832 if (rtl::Bootstrap(url
).getHandle() == nullptr) return;
834 OUStringBuffer
prefix("${.override:");
835 for (sal_Int32 i
= 0; i
!= url
.getLength(); ++i
) {
836 sal_Unicode c
= url
[i
];
848 OUString
urls(prefix
+ "SCHEMA}");
849 rtl::Bootstrap::expandMacros(urls
);
850 if (!urls
.isEmpty()) {
851 parseFileList(layer
, &parseXcsFile
, urls
, false);
853 urls
= prefix
+ "DATA}";
854 rtl::Bootstrap::expandMacros(urls
);
855 if (!urls
.isEmpty()) {
856 parseFileList(layer
+ 1, &parseXcuFile
, urls
, recordAdditions
);
860 void Components::parseResLayer(int layer
, std::u16string_view url
) {
861 OUString
resUrl(OUString::Concat(url
) + "/res");
862 parseXcdFiles(layer
, resUrl
);
863 parseFiles(layer
, ".xcu", &parseXcuFile
, resUrl
, false);
866 void Components::parseModificationLayer(int layer
, OUString
const & url
) {
868 parseFileLeniently(&parseXcuFile
, url
, layer
, nullptr, nullptr, nullptr);
869 } catch (css::container::NoSuchElementException
&) {
871 "configmgr", "user registrymodifications.xcu does not (yet) exist");
872 // Migrate old user layer data (can be removed once migration is no
873 // longer relevant, probably OOo 4; also see hack for xsi namespace in
874 // xmlreader::XmlReader::registerNamespaceIri):
876 layer
, ".xcu", &parseXcuFile
,
878 "${$BRAND_BASE_DIR/" LIBO_ETC_FOLDER
"/" SAL_CONFIGFILE("bootstrap")
879 ":UserInstallation}/user/registry/data"),
884 int Components::getExtensionLayer(bool shared
) const {
885 int layer
= shared
? sharedExtensionLayer_
: userExtensionLayer_
;
887 throw css::uno::RuntimeException(
888 "insert extension xcs/xcu file into undefined layer");
895 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */