LibreOffice Module framework (master) 1
Public Types | Public Member Functions | Private Member Functions | Private Attributes | List of all members
framework::PresetHandler Class Reference

TODO document me. More...

#include <presethandler.hxx>

Collaboration diagram for framework::PresetHandler:
[legend]

Public Types

enum  EConfigType {
  E_GLOBAL ,
  E_MODULES ,
  E_DOCUMENT
}
 this handler can provide different types of configuration. More...
 

Public Member Functions

 PresetHandler (css::uno::Reference< css::uno::XComponentContext > xContext)
 does nothing real. More...
 
 PresetHandler (const PresetHandler &rCopy)
 copy ctor More...
 
 ~PresetHandler ()
 closes all open storages ... if user forgot that . More...
 
void forgetCachedStorages ()
 free all currently cache(!) storages. More...
 
css::uno::Reference< css::embed::XStorage > getOrCreateRootStorageShare ()
 return access to the internally used and cached root storage. More...
 
css::uno::Reference< css::embed::XStorage > getOrCreateRootStorageUser ()
 
css::uno::Reference< css::embed::XStorage > getWorkingStorageUser () const
 provides access to the current working storages. More...
 
css::uno::Reference< css::embed::XStorage > getParentStorageShare ()
 check if there is a parent storage well known for the specified child storage and return it. More...
 
css::uno::Reference< css::embed::XStorage > getParentStorageUser ()
 
void connectToResource (EConfigType eConfigType, std::u16string_view sResourceType, std::u16string_view sModule, const css::uno::Reference< css::embed::XStorage > &xDocumentRoot, const LanguageTag &rLanguageTag=LanguageTag(LANGUAGE_USER_PRIV_NOTRANSLATE))
 free all internal structures and let this handler work on a new type of configuration sets. More...
 
void copyPresetToTarget (std::u16string_view sPreset, std::u16string_view sTarget)
 try to copy the specified preset from the share layer to the user layer and establish it as the specified target. More...
 
css::uno::Reference< css::io::XStream > openPreset (std::u16string_view sPreset)
 open the specified preset as stream object and return it. More...
 
css::uno::Reference< css::io::XStream > openTarget (std::u16string_view sTarget, sal_Int32 nMode)
 open the specified target as stream object and return it. More...
 
void commitUserChanges ()
 do anything which is necessary to flush all changes back to disk. More...
 
void addStorageListener (XMLBasedAcceleratorConfiguration *pListener)
 TODO. More...
 
void removeStorageListener (XMLBasedAcceleratorConfiguration *pListener)
 

Private Member Functions

css::uno::Reference< css::embed::XStorage > impl_openPathIgnoringErrors (const OUString &sPath, sal_Int32 eMode, bool bShare)
 open a config path ignoring errors (catching exceptions). More...
 
::std::vector< OUString >::const_iterator impl_findMatchingLocalizedValue (const ::std::vector< OUString > &lLocalizedValues, OUString &rLanguageTag, bool bAllowFallbacks)
 try to find the specified locale inside list of possible ones. More...
 
css::uno::Reference< css::embed::XStorage > impl_openLocalizedPathIgnoringErrors (OUString &sPath, sal_Int32 eMode, bool bShare, OUString &rLanguageTag, bool bAllowFallback)
 open a config path ignoring errors (catching exceptions). More...
 
::std::vector< OUString > impl_getSubFolderNames (const css::uno::Reference< css::embed::XStorage > &xFolder)
 returns the names of all sub storages of specified storage. More...
 

Private Attributes

css::uno::Reference< css::uno::XComponentContext > m_xContext
 can be used to create on needed uno resources. More...
 
EConfigType m_eConfigType
 knows the type of provided configuration. More...
 
StorageHolder m_lDocumentStorages
 if we run in document mode, we can't use the global root storages! We have to use a special document storage explicitly. More...
 
css::uno::Reference< css::embed::XStorage > m_xWorkingStorageShare
 holds the folder storage of the share layer alive, where the current configuration set exists. More...
 
css::uno::Reference< css::embed::XStorage > m_xWorkingStorageNoLang
 global language-independent storage More...
 
css::uno::Reference< css::embed::XStorage > m_xWorkingStorageUser
 holds the folder storage of the user layer alive, where the current configuration set exists. More...
 
OUString m_sRelPathShare
 knows the relative path from the root. More...
 
OUString m_sRelPathUser
 

Detailed Description

TODO document me.

<layer>/global/<resourcetype>/<preset>.xml
<layer>/modules/<moduleid>/<resourcetype>/<preset>.xml

RESOURCETYPE        PRESET        TARGET
                    (share)       (user)
"accelerator"       "default"     "current"
                    "word"
                    "excel"

"menubar"           "default"     "menubar"

Definition at line 51 of file presethandler.hxx.

Member Enumeration Documentation

◆ EConfigType

this handler can provide different types of configuration.

@descr Means: a global or a module dependent or ... configuration.

Enumerator
E_GLOBAL 
E_MODULES 
E_DOCUMENT 

Definition at line 61 of file presethandler.hxx.

Constructor & Destructor Documentation

◆ PresetHandler() [1/2]

framework::PresetHandler::PresetHandler ( css::uno::Reference< css::uno::XComponentContext >  xContext)

does nothing real.

Parameters
xContextpoints to a uno service manager, which is used internally to create own needed uno resources.

Definition at line 76 of file presethandler.cxx.

◆ PresetHandler() [2/2]

framework::PresetHandler::PresetHandler ( const PresetHandler rCopy)

◆ ~PresetHandler()

framework::PresetHandler::~PresetHandler ( )

Member Function Documentation

◆ addStorageListener()

void framework::PresetHandler::addStorageListener ( XMLBasedAcceleratorConfiguration pListener)

◆ commitUserChanges()

void framework::PresetHandler::commitUserChanges ( )

do anything which is necessary to flush all changes back to disk.

@descr We have to call commit on all cached sub storages on the path from the root storage upside down to the working storage (which are not really used, but required to be holded alive!).

Definition at line 524 of file presethandler.cxx.

References framework::StorageHolder::commitPath(), E_DOCUMENT, E_GLOBAL, E_MODULES, framework::StorageHolder::getPathOfStorage(), m_eConfigType, m_lDocumentStorages, m_xWorkingStorageUser, and framework::StorageHolder::notifyPath().

Referenced by copyPresetToTarget(), and framework::XMLBasedAcceleratorConfiguration::store().

◆ connectToResource()

void framework::PresetHandler::connectToResource ( PresetHandler::EConfigType  eConfigType,
std::u16string_view  sResourceType,
std::u16string_view  sModule,
const css::uno::Reference< css::embed::XStorage > &  xDocumentRoot,
const LanguageTag rLanguageTag = LanguageTag(LANGUAGE_USER_PRIV_NOTRANSLATE) 
)

free all internal structures and let this handler work on a new type of configuration sets.

Parameters
eConfigTypediffer between global or module dependent configuration.
sResourceTypediffer between menubar/toolbar/accelerator/... configuration.
sModuleif sResourceType is set to a module dependent configuration, it address the current application module.
xDocumentRootif sResourceType is set to E_DOCUMENT, this value points to the root storage inside the document, where we can save our configuration files. Note: that's not the real root of the document... its only a sub storage. But we interpret it as our root storage.
rLanguageTagin case this configuration supports localized entries, the current locale must be set.

Localization will be represented as directory structure of provided presets. Means: you call us with a preset name "default"; and we use e.g. "/en-US/default.xml" internally.

If no localization exists for this preset set, this class will work in default mode - means "no locale" - automatically. e.g. "/default.xml"

Exceptions
css::uno::RuntimeException(!)if the specified resource couldn't be located.

Definition at line 308 of file presethandler.cxx.

References E_DOCUMENT, E_GLOBAL, E_MODULES, ex, LanguageTag::getBcp47(), cppu::getCaughtException(), getOrCreateRootStorageShare(), getOrCreateRootStorageUser(), ID_CORRUPT_UICONFIG_GENERAL, impl_openLocalizedPathIgnoringErrors(), impl_openPathIgnoringErrors(), LANGUAGE_USER_PRIV_NOTRANSLATE, m_eConfigType, m_lDocumentStorages, m_sRelPathShare, m_sRelPathUser, m_xWorkingStorageNoLang, m_xWorkingStorageShare, m_xWorkingStorageUser, framework::StorageHolder::openPath(), and framework::StorageHolder::setRootStorage().

◆ copyPresetToTarget()

void framework::PresetHandler::copyPresetToTarget ( std::u16string_view  sPreset,
std::u16string_view  sTarget 
)

try to copy the specified preset from the share layer to the user layer and establish it as the specified target.

@descr Means: copy share/.../<preset>.xml user/.../<target>.xml Note: The target will be overwritten completely or created as new by this operation!

Parameters
sPresetthe ALIAS name of an existing preset.
sTargetthe ALIAS name of the target.
Exceptions
css::container::NoSuchElementExceptionif the specified preset does not exists.
css::io::IOExceptionif copying failed.

Definition at line 446 of file presethandler.cxx.

References commitUserChanges(), m_xWorkingStorageNoLang, m_xWorkingStorageShare, and m_xWorkingStorageUser.

Referenced by framework::XMLBasedAcceleratorConfiguration::reset().

◆ forgetCachedStorages()

void framework::PresetHandler::forgetCachedStorages ( )

◆ getOrCreateRootStorageShare()

css::uno::Reference< css::embed::XStorage > framework::PresetHandler::getOrCreateRootStorageShare ( )

return access to the internally used and cached root storage.

@descr These root storages are the base of all further opened presets and targets. They are provided here only, to support older implementations, which base on them ...

getOrCreate...() - What does it mean? Such root storage will be created one times only and cached then internally till the last instance of such PresetHandler dies.

Returns
css::embed::XStorage which represent a root storage.

Definition at line 174 of file presethandler.cxx.

References ex, cppu::getCaughtException(), ID_CORRUPT_UICONFIG_SHARE, m_xContext, and nPos.

Referenced by connectToResource().

◆ getOrCreateRootStorageUser()

css::uno::Reference< css::embed::XStorage > framework::PresetHandler::getOrCreateRootStorageUser ( )

Definition at line 233 of file presethandler.cxx.

References ex, cppu::getCaughtException(), ID_CORRUPT_UICONFIG_USER, m_xContext, and nPos.

Referenced by connectToResource().

◆ getParentStorageShare()

css::uno::Reference< css::embed::XStorage > framework::PresetHandler::getParentStorageShare ( )

check if there is a parent storage well known for the specified child storage and return it.

Parameters
xChildthe child storage where a paranet storage should be searched for.
Returns
css::embed::XStorage A valid storage if a paranet exists. NULL otherwise.

Definition at line 286 of file presethandler.cxx.

References m_xWorkingStorageShare.

◆ getParentStorageUser()

css::uno::Reference< css::embed::XStorage > framework::PresetHandler::getParentStorageUser ( )

Definition at line 297 of file presethandler.cxx.

References m_xWorkingStorageUser.

◆ getWorkingStorageUser()

css::uno::Reference< css::embed::XStorage > framework::PresetHandler::getWorkingStorageUser ( ) const

provides access to the current working storages.

@descr Working storages are the "lowest" storages, where the preset and target files exists.

Returns
css::embed::XStorage which the current working storage.

Definition at line 280 of file presethandler.cxx.

References m_xWorkingStorageUser.

◆ impl_findMatchingLocalizedValue()

std::vector< OUString >::const_iterator framework::PresetHandler::impl_findMatchingLocalizedValue ( const ::std::vector< OUString > &  lLocalizedValues,
OUString &  rLanguageTag,
bool  bAllowFallbacks 
)
private

try to find the specified locale inside list of possible ones.

@descr The list of possible locale values was e.g. retrieved from the system (configuration, directory listing etcpp). The locale normally represent the current office locale. This method search for a suitable item by using different algorithm. a) exact search b) search with using fallbacks

Parameters
lLocalizedValueslist of BCP47 language tags / locale codes
rLanguageTag[IN ] the current office locale, which should be searched inside lLocalizedValues. [OUT] in case fallbacks was allowed, it contains afterwards the fallback locale.
bAllowFallbacksenable/disable using of fallbacks
Returns
An iterator, which points directly into lLocalizedValue list. As a negative result the special iterator lLocalizedValues.end() will be returned.

Definition at line 641 of file presethandler.cxx.

References LanguageTag::getFallback().

Referenced by impl_openLocalizedPathIgnoringErrors().

◆ impl_getSubFolderNames()

std::vector< OUString > framework::PresetHandler::impl_getSubFolderNames ( const css::uno::Reference< css::embed::XStorage > &  xFolder)
private

returns the names of all sub storages of specified storage.

Parameters
xFolderthe base storage for this operation.
Returns
[vector< string >] a list of folder names.

Definition at line 702 of file presethandler.cxx.

References i.

Referenced by impl_openLocalizedPathIgnoringErrors().

◆ impl_openLocalizedPathIgnoringErrors()

css::uno::Reference< css::embed::XStorage > framework::PresetHandler::impl_openLocalizedPathIgnoringErrors ( OUString &  sPath,
sal_Int32  eMode,
bool  bShare,
OUString &  rLanguageTag,
bool  bAllowFallback 
)
private

open a config path ignoring errors (catching exceptions).

@descr We catch only normal exceptions here - no runtime exceptions. Further the path itself is tries in different versions (using locale specific attributes). e.g. "path/e-US" => "path/en" => "path/de"

Parameters
sPaththe configuration path, which should be opened. It's further used as out parameter too, so we can return the localized path!
eModethe open mode (READ/READWRITE)
bShareforce using of the share layer instead of the user layer.
rLanguageTag[IN ] contains the start locale for searching localized sub dirs. [OUT] contains the locale of a found localized sub dir
bAllowFallbackenable/disable fallback handling for locales
Returns
An opened storage in case method was successful - null otherwise.

Definition at line 665 of file presethandler.cxx.

References eMode, impl_findMatchingLocalizedValue(), impl_getSubFolderNames(), and impl_openPathIgnoringErrors().

Referenced by connectToResource().

◆ impl_openPathIgnoringErrors()

css::uno::Reference< css::embed::XStorage > framework::PresetHandler::impl_openPathIgnoringErrors ( const OUString &  sPath,
sal_Int32  eMode,
bool  bShare 
)
private

open a config path ignoring errors (catching exceptions).

@descr We catch only normal exceptions here - no runtime exceptions.

Parameters
sPaththe configuration path, which should be opened.
eModethe open mode (READ/READWRITE)
bShareforce using of the share layer instead of the user layer.
Returns
An opened storage in case method was successful - null otherwise.

Definition at line 622 of file presethandler.cxx.

References eMode.

Referenced by connectToResource(), and impl_openLocalizedPathIgnoringErrors().

◆ openPreset()

css::uno::Reference< css::io::XStream > framework::PresetHandler::openPreset ( std::u16string_view  sPreset)

open the specified preset as stream object and return it.

@descr Note: Because presets resist inside the share layer, they will be opened readonly every time.

Parameters
sPresetthe ALIAS name of an existing preset.

Accesses the global language-independent storage instead of the preset storage

Returns
The opened preset stream ... or NULL if the preset does not exists.

Definition at line 487 of file presethandler.cxx.

References m_xWorkingStorageNoLang, and xStream.

Referenced by framework::XMLBasedAcceleratorConfiguration::reload().

◆ openTarget()

css::uno::Reference< css::io::XStream > framework::PresetHandler::openTarget ( std::u16string_view  sTarget,
sal_Int32  nMode 
)

open the specified target as stream object and return it.

@descr Note: Targets resist inside the user layer. Normally they are opened in read/write mode. But it will be opened readonly automatically if that isn't possible (may be the file is write protected on the system ...).

Parameters
sTargetthe ALIAS name of the target.
Returns
The opened target stream ... or NULL if the target does not exists or couldn't be created as new one.

Definition at line 506 of file presethandler.cxx.

References m_xWorkingStorageUser.

Referenced by framework::XMLBasedAcceleratorConfiguration::isReadOnly(), framework::XMLBasedAcceleratorConfiguration::reload(), and framework::XMLBasedAcceleratorConfiguration::store().

◆ removeStorageListener()

void framework::PresetHandler::removeStorageListener ( XMLBasedAcceleratorConfiguration pListener)

Member Data Documentation

◆ m_eConfigType

EConfigType framework::PresetHandler::m_eConfigType
private

knows the type of provided configuration.

@descr e.g. global, modules, ...

Definition at line 77 of file presethandler.hxx.

Referenced by addStorageListener(), commitUserChanges(), connectToResource(), forgetCachedStorages(), PresetHandler(), and removeStorageListener().

◆ m_lDocumentStorages

StorageHolder framework::PresetHandler::m_lDocumentStorages
private

if we run in document mode, we can't use the global root storages! We have to use a special document storage explicitly.

Definition at line 81 of file presethandler.hxx.

Referenced by addStorageListener(), commitUserChanges(), connectToResource(), forgetCachedStorages(), PresetHandler(), removeStorageListener(), and ~PresetHandler().

◆ m_sRelPathShare

OUString framework::PresetHandler::m_sRelPathShare
private

knows the relative path from the root.

Definition at line 112 of file presethandler.hxx.

Referenced by connectToResource(), PresetHandler(), and ~PresetHandler().

◆ m_sRelPathUser

OUString framework::PresetHandler::m_sRelPathUser
private

◆ m_xContext

css::uno::Reference< css::uno::XComponentContext > framework::PresetHandler::m_xContext
private

can be used to create on needed uno resources.

Definition at line 71 of file presethandler.hxx.

Referenced by getOrCreateRootStorageShare(), getOrCreateRootStorageUser(), and PresetHandler().

◆ m_xWorkingStorageNoLang

css::uno::Reference< css::embed::XStorage > framework::PresetHandler::m_xWorkingStorageNoLang
private

global language-independent storage

Definition at line 97 of file presethandler.hxx.

Referenced by connectToResource(), copyPresetToTarget(), forgetCachedStorages(), openPreset(), PresetHandler(), and ~PresetHandler().

◆ m_xWorkingStorageShare

css::uno::Reference< css::embed::XStorage > framework::PresetHandler::m_xWorkingStorageShare
private

holds the folder storage of the share layer alive, where the current configuration set exists.

@descr Note: If this preset handler works in document mode this member is meant relative to the document root... not to the share layer root!

Further is defined, that m_xWorkingStorageUser is equals to m_xWorkingStorageShare then!

Definition at line 93 of file presethandler.hxx.

Referenced by connectToResource(), copyPresetToTarget(), forgetCachedStorages(), getParentStorageShare(), PresetHandler(), and ~PresetHandler().

◆ m_xWorkingStorageUser

css::uno::Reference< css::embed::XStorage > framework::PresetHandler::m_xWorkingStorageUser
private

holds the folder storage of the user layer alive, where the current configuration set exists.

@descr Note: If this preset handler works in document mode this member is meant relative to the document root... not to the user layer root!

Further is defined, that m_xWorkingStorageUser is equals to m_xWorkingStorageShare then!

Definition at line 109 of file presethandler.hxx.

Referenced by commitUserChanges(), connectToResource(), copyPresetToTarget(), forgetCachedStorages(), getParentStorageUser(), getWorkingStorageUser(), openTarget(), PresetHandler(), and ~PresetHandler().


The documentation for this class was generated from the following files: